On Sat, Nov 15, 2025 at 4:26 AM <[email protected]> wrote:
>
> From: Pan Li <[email protected]>
>
> 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;

OK

> 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]>
> ---
>  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(+)
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.1.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.2.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.3.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.4.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.5.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.6.c
>  create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/bit_op_cvt.h
>
> 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 00000000000..c0da601f5f6
> --- /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 00000000000..38671d20ccf
> --- /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 00000000000..84393454746
> --- /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 00000000000..3f3356be8ce
> --- /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 00000000000..e746d6ec7c8
> --- /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 00000000000..a12dc88f47c
> --- /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 00000000000..87d67e67ebf
> --- /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
> --
> 2.43.0
>

Reply via email to