https://gcc.gnu.org/g:22d6348957bb27f4c04f7ab47cd0d4543bb1de5c

commit r16-5529-g22d6348957bb27f4c04f7ab47cd0d4543bb1de5c
Author: Pan Li <[email protected]>
Date:   Sat Nov 15 11:21:37 2025 +0800

    Test: Add test case for bit_op convert folding
    
    Add test cases of all possible types of bit_op convert folding.
    To check there is no tree dump like below:
    
       _5 = (uint8_t) _2;
       return _5;
    
    gcc/testsuite/ChangeLog:
    
            * gcc.dg/tree-ssa/bit_op_cvt.1.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.2.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.3.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.4.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.5.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.6.c: New test.
            * gcc.dg/tree-ssa/bit_op_cvt.h: New test.
    
    Signed-off-by: Pan Li <[email protected]>

Diff:
---
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.1.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.2.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.3.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.4.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.5.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.6.c | 33 ++++++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.h   | 13 +++++++++++
 7 files changed, 211 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.1.c
new file mode 100644
index 000000000000..c0da601f5f65
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.1.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(uint8_t, int8_t, uint16_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint16_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int16_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, int8_t, int16_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, int8_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint8_t, int8_t, int64_t, |, bit_ior)
+
+DEF_BIT_CVT_0(uint16_t, int16_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, int16_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, int16_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, int16_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int64_t, |, bit_ior)
+
+DEF_BIT_CVT_0(uint32_t, int32_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint32_t, int32_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint32_t, uint32_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(uint32_t, uint32_t, int64_t, |, bit_ior)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.2.c
new file mode 100644
index 000000000000..38671d20ccf6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.2.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(int8_t, int8_t, uint16_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, int8_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, int8_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint16_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, int16_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, uint8_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, int8_t, int16_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, int8_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(int8_t, int8_t, int64_t, |, bit_ior)
+
+DEF_BIT_CVT_0(int16_t, int16_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, int16_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, int16_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, int16_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint32_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, uint16_t, int32_t, |, bit_ior)
+DEF_BIT_CVT_0(int16_t, uint16_t, int64_t, |, bit_ior)
+
+DEF_BIT_CVT_0(int32_t, int32_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int32_t, int32_t, int64_t, |, bit_ior)
+DEF_BIT_CVT_0(int32_t, uint32_t, uint64_t, |, bit_ior)
+DEF_BIT_CVT_0(int32_t, uint32_t, int64_t, |, bit_ior)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.3.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.3.c
new file mode 100644
index 000000000000..843934547468
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.3.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(uint8_t, int8_t, uint16_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint16_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int16_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, int8_t, int16_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, int8_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(uint8_t, int8_t, int64_t, &, bit_and)
+
+DEF_BIT_CVT_0(uint16_t, int16_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, int16_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, int16_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, int16_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int64_t, &, bit_and)
+
+DEF_BIT_CVT_0(uint32_t, int32_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint32_t, int32_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(uint32_t, uint32_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(uint32_t, uint32_t, int64_t, &, bit_and)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.4.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.4.c
new file mode 100644
index 000000000000..3f3356be8ce2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.4.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(int8_t, int8_t, uint16_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, int8_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, int8_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint16_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, int16_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, uint8_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, int8_t, int16_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, int8_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(int8_t, int8_t, int64_t, &, bit_and)
+
+DEF_BIT_CVT_0(int16_t, int16_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, int16_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, int16_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, int16_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint32_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, uint16_t, int32_t, &, bit_and)
+DEF_BIT_CVT_0(int16_t, uint16_t, int64_t, &, bit_and)
+
+DEF_BIT_CVT_0(int32_t, int32_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int32_t, int32_t, int64_t, &, bit_and)
+DEF_BIT_CVT_0(int32_t, uint32_t, uint64_t, &, bit_and)
+DEF_BIT_CVT_0(int32_t, uint32_t, int64_t, &, bit_and)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.5.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.5.c
new file mode 100644
index 000000000000..e746d6ec7c86
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.5.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(uint8_t, int8_t, uint16_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, int8_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint16_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int16_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, uint8_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, int8_t, int16_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, int8_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint8_t, int8_t, int64_t, ^, bit_xor)
+
+DEF_BIT_CVT_0(uint16_t, int16_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, int16_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, int16_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, int16_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, uint16_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint16_t, uint16_t, int64_t, ^, bit_xor)
+
+DEF_BIT_CVT_0(uint32_t, int32_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint32_t, int32_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint32_t, uint32_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(uint32_t, uint32_t, int64_t, ^, bit_xor)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.6.c 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.6.c
new file mode 100644
index 000000000000..a12dc88f47c8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.6.c
@@ -0,0 +1,33 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+#include "bit_op_cvt.h"
+
+DEF_BIT_CVT_0(int8_t, int8_t, uint16_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, int8_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, int8_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint16_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, int16_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, uint8_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, int8_t, int16_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, int8_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int8_t, int8_t, int64_t, ^, bit_xor)
+
+DEF_BIT_CVT_0(int16_t, int16_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, int16_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, int16_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, int16_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, uint16_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, uint16_t, int32_t, ^, bit_xor)
+DEF_BIT_CVT_0(int16_t, uint16_t, int64_t, ^, bit_xor)
+
+DEF_BIT_CVT_0(int32_t, int32_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int32_t, int32_t, int64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int32_t, uint32_t, uint64_t, ^, bit_xor)
+DEF_BIT_CVT_0(int32_t, uint32_t, int64_t, ^, bit_xor)
+
+/* { dg-final { scan-tree-dump-not "_\[0-9]\+ = \\(u?int\[0-9]\+_t\\) 
_\[0-9]\+;\\s+return _\[0-9]\+;" "optimized" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.h 
b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.h
new file mode 100644
index 000000000000..87d67e67ebf4
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.h
@@ -0,0 +1,13 @@
+#ifndef HAVE_DEFINED_BIT_OP_CVT
+#define HAVE_DEFINED_BIT_OP_CVT
+
+#include <stdint.h>
+
+#define DEF_BIT_CVT_0(T1, T2, T3, OP, NAME) \
+T1 test_bit_##NAME##_##T1##_##T2##_##T3##_0(T2 a, \
+                                           T3 b) \
+{ \
+  return (T1)(a OP (T3)b); \
+}
+
+#endif

Reply via email to