On Mon, Aug 17, 2026 at 7:07 AM Shreesh Adiga
<[email protected]> wrote:
>
> This change attempts to compute the various __builtin_crc and rev_crc
> functions when all the arguments are compile-time known constants using
> simple CRC loop calculation at compile-time and avoid emitting the table
> based computation.
>
> Architecture specific CRC builtin folding will be done later as a follow
> up.
>
> gcc/ChangeLog:
>
> * fold-const-call.cc (fold_const_crc): new function to fold crc
> (fold_const_call): invoke fold_const_crc to fold builtin crc
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/crc-builtin-rev-target32.c: modified test to avoid
> const fold.
> * gcc.dg/crc-builtin-rev-target64.c: modified test to avoid
> const fold.
> * gcc.dg/crc-builtin-target32.c: modified test to avoid const
> fold.
> * gcc.dg/crc-builtin-target64.c: modified test to avoid const
> fold.
> * gcc.target/aarch64/crc-builtin-pmul64.c: modified test to
> avoid const fold.
> * gcc.target/riscv/crc-builtin-zbc32.c: modified test to avoid
> const fold.
> * gcc.target/riscv/crc-builtin-zbc64.c: modified test to avoid
> const fold.
> * gcc.target/riscv/rvv/base/crc-builtin-zvbc.c: modified test to
> avoid const fold.
> * gcc.dg/crc-builtin-const-fold-target32.c: New test.
> * gcc.dg/crc-builtin-const-fold-target64.c: New test.
>
> Signed-off-by: Shreesh Adiga <[email protected]>
> ---
> gcc/fold-const-call.cc | 75 ++++++++++
> .../gcc.dg/crc-builtin-const-fold-target32.c | 80 +++++++++++
> .../gcc.dg/crc-builtin-const-fold-target64.c | 134 ++++++++++++++++++
> .../gcc.dg/crc-builtin-rev-target32.c | 25 ++--
> .../gcc.dg/crc-builtin-rev-target64.c | 45 +++---
> gcc/testsuite/gcc.dg/crc-builtin-target32.c | 25 ++--
> gcc/testsuite/gcc.dg/crc-builtin-target64.c | 43 +++---
> .../gcc.target/aarch64/crc-builtin-pmul64.c | 52 +++----
> .../gcc.target/riscv/crc-builtin-zbc32.c | 13 +-
> .../gcc.target/riscv/crc-builtin-zbc64.c | 49 +++----
> .../riscv/rvv/base/crc-builtin-zvbc.c | 49 +++----
> 11 files changed, 441 insertions(+), 149 deletions(-)
> create mode 100644 gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c
> create mode 100644 gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c
>
> diff --git a/gcc/fold-const-call.cc b/gcc/fold-const-call.cc
> index b3a9d7715d6..aadfc837469 100644
> --- a/gcc/fold-const-call.cc
> +++ b/gcc/fold-const-call.cc
> @@ -2044,6 +2044,58 @@ fold_const_call_1 (combined_fn fn, tree type, tree
> arg0, tree arg1, tree arg2)
> return NULL_TREE;
> }
>
> +static tree
> +fold_const_crc (internal_fn fn, tree type, tree crc_arg, tree data_arg,
> + tree polynomial_arg)
> +{
> + if (!integer_cst_p (crc_arg)
> + || !integer_cst_p (data_arg)
> + || !integer_cst_p (polynomial_arg))
> + return NULL_TREE;
> +
> + unsigned int crc_bits = TYPE_PRECISION (type);
> + unsigned int data_bits = TYPE_PRECISION (TREE_TYPE (data_arg));
> +
> + if ((data_bits != 8 && data_bits != 16 && data_bits != 32 && data_bits !=
> 64)
> + || (crc_bits != 8 && crc_bits != 16 && crc_bits != 32 && crc_bits !=
> 64)
> + || data_bits > crc_bits)
> + return NULL_TREE;
> +
> + unsigned HOST_WIDE_INT crc = wi::to_wide (crc_arg).to_uhwi ();
> + unsigned HOST_WIDE_INT data = wi::to_wide (data_arg).to_uhwi ();
> + unsigned HOST_WIDE_INT polynomial = wi::to_wide (polynomial_arg).to_uhwi
> ();
You should use tree_to_uhwi instead for all of these.
> +
> + if (fn == IFN_CRC_REV)
> + {
> + unsigned HOST_WIDE_INT rev_polynom = reflect_hwi (polynomial,
> crc_bits);
> + crc ^= data;
> + for (unsigned int n = 0; n < data_bits; n++)
> + {
> + if (crc & 1)
> + crc = (crc >> 1) ^ rev_polynom;
> + else
> + crc >>= 1;
> + }
> + }
> + else
> + {
> + unsigned HOST_WIDE_INT msb = HOST_WIDE_INT_1U << (crc_bits - 1);
> + crc ^= (data << (crc_bits - data_bits));
> + for (unsigned int n = 0; n < data_bits; n++)
> + {
> + if (crc & msb)
> + crc = (crc << 1) ^ polynomial;
> + else
> + crc <<= 1;
> + }
> + }
I was trying to think if there was a way to combine these two loops
but I can't think of a way since one does >> and the other does <<.
> +
> + /* Zero out bits in crc beyond the specified number of crc_bits. */
> + if (crc_bits < sizeof (crc) * CHAR_BIT)
You can just use HOST_BITS_PER_WIDE_INT.
> + crc &= (HOST_WIDE_INT_1U << crc_bits) - 1;
> + return wide_int_to_tree (type, wi::uhwi (crc, crc_bits));
You can use build_int_cstu instead.
> +}
> +
> /* Try to fold FN (ARG0, ARG1, ARG2) to a constant. Return the constant on
> success, otherwise return null. TYPE is the type of the return value. */
>
> @@ -2145,6 +2197,29 @@ fold_const_call (combined_fn fn, tree type, tree arg0,
> tree arg1, tree arg2)
> }
> return NULL_TREE;
>
> + case CFN_BUILT_IN_CRC8_DATA8:
> + case CFN_BUILT_IN_CRC16_DATA8:
> + case CFN_BUILT_IN_CRC16_DATA16:
> + case CFN_BUILT_IN_CRC32_DATA8:
> + case CFN_BUILT_IN_CRC32_DATA16:
> + case CFN_BUILT_IN_CRC32_DATA32:
> + case CFN_BUILT_IN_CRC64_DATA8:
> + case CFN_BUILT_IN_CRC64_DATA16:
> + case CFN_BUILT_IN_CRC64_DATA32:
> + case CFN_BUILT_IN_CRC64_DATA64:
> + case CFN_BUILT_IN_REV_CRC8_DATA8:
> + case CFN_BUILT_IN_REV_CRC16_DATA8:
> + case CFN_BUILT_IN_REV_CRC16_DATA16:
> + case CFN_BUILT_IN_REV_CRC32_DATA8:
> + case CFN_BUILT_IN_REV_CRC32_DATA16:
> + case CFN_BUILT_IN_REV_CRC32_DATA32:
> + case CFN_BUILT_IN_REV_CRC64_DATA8:
> + case CFN_BUILT_IN_REV_CRC64_DATA16:
> + case CFN_BUILT_IN_REV_CRC64_DATA32:
> + case CFN_BUILT_IN_REV_CRC64_DATA64:
> + return fold_const_crc (associated_internal_fn (fn, type),
> + type, arg0, arg1, arg2);
> +
> default:
> return fold_const_call_1 (fn, type, arg0, arg1, arg2);
> }
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c
> b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c
> new file mode 100644
> index 00000000000..f8c84c3abcb
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target32.c
> @@ -0,0 +1,80 @@
> +/* { dg-do compile } */
> +/* { dg-require-effective-target int32plus } */
> +/* { dg-additional-options "-fdump-tree-optimized" } */
> +
> +#include <stdint.h>
> +
> +int8_t crc8_data8 ()
> +{
> + return __builtin_crc8_data8 (0x34, 'a', 0x12);
> +}
> +
> +int16_t crc16_data8 ()
> +{
> + return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> +}
> +
> +int16_t crc16_data16 ()
> +{
> + return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> +}
> +
> +int32_t crc32_data8 ()
> +{
> + return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> +}
> +
> +int32_t crc32_data16 ()
> +{
> + return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> +}
> +
> +int32_t crc32_data32 ()
> +{
> + return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> +}
> +
> +int8_t rev_crc8_data8 ()
> +{
> + return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> +}
> +
> +int16_t rev_crc16_data8 ()
> +{
> + return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> +}
> +
> +int16_t rev_crc16_data16 ()
> +{
> + return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> +}
> +
> +int32_t rev_crc32_data8 ()
> +{
> + return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> +}
> +
> +int32_t rev_crc32_data16 ()
> +{
> + return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> +}
> +
> +int32_t rev_crc32_data32 ()
> +{
> + return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> +}
> +
> +
> +/* Test that builtin calls are optimized away and not present */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc8_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data16" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data16" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data32" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc8_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data16" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data16" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data32" "optimized"
> } } */
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c
> b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c
> new file mode 100644
> index 00000000000..7ba40fe3f6b
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-const-fold-target64.c
> @@ -0,0 +1,134 @@
> +/* { dg-do compile { target lp64 } } */
> +/* { dg-require-effective-target int32plus } */
> +/* { dg-additional-options "-fdump-tree-optimized" } */
> +
> +#include <stdint.h>
> +
> +int8_t crc8_data8 ()
> +{
> + return __builtin_crc8_data8 (0x34, 'a', 0x12);
> +}
> +
> +int16_t crc16_data8 ()
> +{
> + return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> +}
> +
> +int16_t crc16_data16 ()
> +{
> + return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> +}
> +
> +int32_t crc32_data8 ()
> +{
> + return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> +}
> +
> +int32_t crc32_data16 ()
> +{
> + return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> +}
> +
> +int32_t crc32_data32 ()
> +{
> + return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> +}
> +
> +int64_t crc64_data8 ()
> +{
> + return __builtin_crc64_data8 (0xffffffffffffffff, 0x32, 0x40021234002123);
> +}
> +
> +int64_t crc64_data16 ()
> +{
> + return __builtin_crc64_data16 (0xffffffffffffffff, 0x3232,
> 0x40021234002123);
> +}
> +
> +int64_t crc64_data32 ()
> +{
> + return __builtin_crc64_data32 (0xffffffffffffffff, 0x123546ff,
> + 0x40021234002123);
> +}
> +
> +int64_t crc64_data64 ()
> +{
> + return __builtin_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff,
> + 0x40021234002123);
> +}
> +
> +int8_t rev_crc8_data8 ()
> +{
> + return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> +}
> +
> +int16_t rev_crc16_data8 ()
> +{
> + return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> +}
> +
> +int16_t rev_crc16_data16 ()
> +{
> + return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> +}
> +
> +int32_t rev_crc32_data8 ()
> +{
> + return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> +}
> +
> +int32_t rev_crc32_data16 ()
> +{
> + return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> +}
> +
> +int32_t rev_crc32_data32 ()
> +{
> + return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> +}
> +
> +int64_t rev_crc64_data8 ()
> +{
> + return __builtin_rev_crc64_data8 (0xffffffffffffffff, 0x32,
> + 0x40021234002123);
> +}
> +
> +int64_t rev_crc64_data16 ()
> +{
> + return __builtin_rev_crc64_data16 (0xffffffffffffffff, 0x3232,
> + 0x40021234002123);
> +}
> +
> +int64_t rev_crc64_data32 ()
> +{
> + return __builtin_rev_crc64_data32 (0xffffffffffffffff, 0x123546ff,
> + 0x40021234002123);
> +}
> +
> +int64_t rev_crc64_data64 ()
> +{
> + return __builtin_rev_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff,
> + 0x40021234002123);
> +}
> +
> +
> +/* Test that builtin calls are optimized away and not present */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc8_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc16_data16" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data16" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc32_data32" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data8" "optimized" } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data16" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data32" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_crc64_data64" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc8_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc16_data16" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data16" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc32_data32" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data8" "optimized" }
> } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data16" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data32" "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "__builtin_rev_crc64_data64" "optimized"
> } } */
It would be a good idea to have a runtime testcase for these to make
sure the folding (and/or target implementation) is correct.
Otherwise this looks good.
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c
> b/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c
> index 25dc9a226c3..e729e9efb4b 100644
> --- a/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-rev-target32.c
> @@ -4,34 +4,35 @@
>
> #include <stdint.h>
>
> -int8_t rev_crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm crc table emitting
> */
> +int8_t rev_crc8_data8 (int8_t x)
> {
> - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_rev_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t rev_crc16_data8 ()
> +int16_t rev_crc16_data8 (int16_t x)
> {
> - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_rev_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t rev_crc16_data16 ()
> +int16_t rev_crc16_data16 (int16_t x)
> {
> - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t rev_crc32_data8 ()
> +int32_t rev_crc32_data8 (int32_t x)
> {
> - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t rev_crc32_data16 ()
> +int32_t rev_crc32_data16 (int32_t x)
> {
> - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t rev_crc32_data32 ()
> +int32_t rev_crc32_data32 (int32_t x)
> {
> - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting reversed crc
> table) crc_8_polynomial_0x12" "expand" } } */
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c
> b/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c
> index bc9dfa5b619..b6ef9696314 100644
> --- a/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-rev-target64.c
> @@ -4,58 +4,55 @@
>
> #include <stdint.h>
>
> -int8_t rev_crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm crc table emitting
> */
> +int8_t rev_crc8_data8 (int8_t x)
> {
> - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_rev_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t rev_crc16_data8 ()
> +int16_t rev_crc16_data8 (int16_t x)
> {
> - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_rev_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t rev_crc16_data16 ()
> +int16_t rev_crc16_data16 (int16_t x)
> {
> - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t rev_crc32_data8 ()
> +int32_t rev_crc32_data8 (int32_t x)
> {
> - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t rev_crc32_data16 ()
> +int32_t rev_crc32_data16 (int32_t x)
> {
> - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t rev_crc32_data32 ()
> +int32_t rev_crc32_data32 (int32_t x)
> {
> - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> -int64_t rev_crc64_data8 ()
> +int64_t rev_crc64_data8 (int64_t x)
> {
> - return __builtin_rev_crc64_data8 (0xffffffffffffffff, 0x32,
> - 0x40021234002123);
> + return __builtin_rev_crc64_data8 (x, 0x32, 0x40021234002123);
> }
>
> -int64_t rev_crc64_data16 ()
> +int64_t rev_crc64_data16 (int64_t x)
> {
> - return __builtin_rev_crc64_data16 (0xffffffffffffffff, 0x3232,
> - 0x40021234002123);
> + return __builtin_rev_crc64_data16 (x, 0x3232, 0x40021234002123);
> }
>
> -int64_t rev_crc64_data32 ()
> +int64_t rev_crc64_data32 (int64_t x)
> {
> - return __builtin_rev_crc64_data32 (0xffffffffffffffff, 0x123546ff,
> - 0x40021234002123);
> + return __builtin_rev_crc64_data32 (x, 0x123546ff, 0x40021234002123);
> }
>
> -int64_t rev_crc64_data64 ()
> +int64_t rev_crc64_data64 (int64_t x)
> {
> - return __builtin_rev_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff,
> - 0x40021234002123);
> + return __builtin_rev_crc64_data64 (x, 0x123546ff123546ff,
> 0x40021234002123);
> }
>
> /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting reversed crc
> table) crc_8_polynomial_0x12" "expand" } } */
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-target32.c
> b/gcc/testsuite/gcc.dg/crc-builtin-target32.c
> index 43db8c96e16..492f3209bbb 100644
> --- a/gcc/testsuite/gcc.dg/crc-builtin-target32.c
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-target32.c
> @@ -4,34 +4,35 @@
>
> #include <stdint.h>
>
> -int8_t crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm crc table emitting
> */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t crc32_data8 ()
> +int32_t crc32_data8 (int32_t x)
> {
> - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t crc32_data16 ()
> +int32_t crc32_data16 (int32_t x)
> {
> - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t crc32_data32 ()
> +int32_t crc32_data32 (int32_t x)
> {
> - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting crc table)
> crc_8_polynomial_0x12" "expand" } } */
> diff --git a/gcc/testsuite/gcc.dg/crc-builtin-target64.c
> b/gcc/testsuite/gcc.dg/crc-builtin-target64.c
> index 09aa39fcd86..d5040cfe1e0 100644
> --- a/gcc/testsuite/gcc.dg/crc-builtin-target64.c
> +++ b/gcc/testsuite/gcc.dg/crc-builtin-target64.c
> @@ -4,56 +4,55 @@
>
> #include <stdint.h>
>
> -int8_t crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm crc table emitting
> */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t crc32_data8 ()
> +int32_t crc32_data8 (int32_t x)
> {
> - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t crc32_data16 ()
> +int32_t crc32_data16 (int32_t x)
> {
> - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t crc32_data32 ()
> +int32_t crc32_data32 (int32_t x)
> {
> - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> -int64_t crc64_data8 ()
> +int64_t crc64_data8 (int64_t x)
> {
> - return __builtin_crc64_data8 (0xffffffffffffffff, 0x32, 0x40021234002123);
> + return __builtin_crc64_data8 (x, 0x32, 0x40021234002123);
> }
>
> -int64_t crc64_data16 ()
> +int64_t crc64_data16 (int64_t x)
> {
> - return __builtin_crc64_data16 (0xffffffffffffffff, 0x3232,
> 0x40021234002123);
> + return __builtin_crc64_data16 (x, 0x3232, 0x40021234002123);
> }
>
> -int64_t crc64_data32 ()
> +int64_t crc64_data32 (int64_t x)
> {
> - return __builtin_crc64_data32 (0xffffffffffffffff, 0x123546ff,
> - 0x40021234002123);
> + return __builtin_crc64_data32 (x, 0x123546ff, 0x40021234002123);
> }
>
> -int64_t crc64_data64 ()
> +int64_t crc64_data64 (int64_t x)
> {
> - return __builtin_crc64_data64 (0xffffffffffffffff, 0x123546ff123546ff,
> - 0x40021234002123);
> + return __builtin_crc64_data64 (x, 0x123546ff123546ff, 0x40021234002123);
> }
>
> /* { dg-final { scan-rtl-dump ";; (?:using optab for|emitting crc table)
> crc_16_polynomial_0x1021" "expand" } } */
> diff --git a/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c
> b/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c
> index cf2fa506981..3363562a5d0 100644
> --- a/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c
> +++ b/gcc/testsuite/gcc.target/aarch64/crc-builtin-pmul64.c
> @@ -1,61 +1,63 @@
> /* { dg-options "-march=armv8-a+crypto" } */
>
> #include <stdint.h>
> -int8_t crc8_data8 ()
> +
> +/* Due to constant folding, use a runtime arg to confirm pmull emitting */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 ('a', 0xff, 0x12);
> + return __builtin_crc8_data8 (x, 0xff, 0x12);
> }
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t crc32_data8 ()
> +int32_t crc32_data8 (int32_t x)
> {
> - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_crc32_data8 (x, 0x32, 0x4002123);
> }
> -int32_t crc32_data16 ()
> +int32_t crc32_data16 (int32_t x)
> {
> - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t crc32_data32 ()
> +int32_t crc32_data32 (int32_t x)
> {
> - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> -int8_t rev_crc8_data8 ()
> +int8_t rev_crc8_data8 (int8_t x)
> {
> - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_rev_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t rev_crc16_data8 ()
> +int16_t rev_crc16_data8 (int16_t x)
> {
> - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_rev_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t rev_crc16_data16 ()
> +int16_t rev_crc16_data16 (int16_t x)
> {
> - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t rev_crc32_data8 ()
> +int32_t rev_crc32_data8 (int32_t x)
> {
> - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t rev_crc32_data16 ()
> +int32_t rev_crc32_data16 (int32_t x)
> {
> - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t rev_crc32_data32 ()
> +int32_t rev_crc32_data32 (int32_t x)
> {
> - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> -}
> + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123);
> +}
> /* { dg-final { scan-assembler-times "pmull" 24 } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c
> b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c
> index d4e47608e33..8496555b93d 100644
> --- a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c
> +++ b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc32.c
> @@ -3,19 +3,20 @@
>
> #include <stdint-gcc.h>
>
> -int8_t crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm clmul emitting */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> /* { dg-final { scan-assembler-times "clmul\t" 6 } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c
> b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c
> index 298d47b802f..1f46300b140 100644
> --- a/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c
> +++ b/gcc/testsuite/gcc.target/riscv/crc-builtin-zbc64.c
> @@ -3,64 +3,65 @@
>
> #include <stdint-gcc.h>
>
> -int8_t crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm clmul emitting */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t crc32_data8 ()
> +int32_t crc32_data8 (int32_t x)
> {
> - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t crc32_data16 ()
> +int32_t crc32_data16 (int32_t x)
> {
> - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t crc32_data32 ()
> +int32_t crc32_data32 (int32_t x)
> {
> - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> -int8_t rev_crc8_data8 ()
> +int8_t rev_crc8_data8 (int8_t x)
> {
> - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_rev_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t rev_crc16_data8 ()
> +int16_t rev_crc16_data8 (int16_t x)
> {
> - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_rev_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t rev_crc16_data16 ()
> +int16_t rev_crc16_data16 (int16_t x)
> {
> - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t rev_crc32_data8 ()
> +int32_t rev_crc32_data8 (int32_t x)
> {
> - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t rev_crc32_data16 ()
> +int32_t rev_crc32_data16 (int32_t x)
> {
> - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t rev_crc32_data32 ()
> +int32_t rev_crc32_data32 (int32_t x)
> {
> - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
> /* { dg-final { scan-assembler-times "clmul\t" 18 } } */
> /* { dg-final { scan-assembler-times "clmulh" 6 } } */
> diff --git a/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c
> b/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c
> index 2d5fa88acc9..16c550e2e5a 100644
> --- a/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c
> +++ b/gcc/testsuite/gcc.target/riscv/rvv/base/crc-builtin-zvbc.c
> @@ -3,64 +3,65 @@
>
> #include <stdint-gcc.h>
>
> -int8_t crc8_data8 ()
> +/* Due to constant folding, use a runtime arg to confirm clmul emitting */
> +int8_t crc8_data8 (int8_t x)
> {
> - return __builtin_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t crc16_data8 ()
> +int16_t crc16_data8 (int16_t x)
> {
> - return __builtin_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t crc16_data16 ()
> +int16_t crc16_data16 (int16_t x)
> {
> - return __builtin_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t crc32_data8 ()
> +int32_t crc32_data8 (int32_t x)
> {
> - return __builtin_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t crc32_data16 ()
> +int32_t crc32_data16 (int32_t x)
> {
> - return __builtin_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t crc32_data32 ()
> +int32_t crc32_data32 (int32_t x)
> {
> - return __builtin_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
>
> -int8_t rev_crc8_data8 ()
> +int8_t rev_crc8_data8 (int8_t x)
> {
> - return __builtin_rev_crc8_data8 (0x34, 'a', 0x12);
> + return __builtin_rev_crc8_data8 (x, 'a', 0x12);
> }
>
> -int16_t rev_crc16_data8 ()
> +int16_t rev_crc16_data8 (int16_t x)
> {
> - return __builtin_rev_crc16_data8 (0x1234, 'a', 0x1021);
> + return __builtin_rev_crc16_data8 (x, 'a', 0x1021);
> }
>
> -int16_t rev_crc16_data16 ()
> +int16_t rev_crc16_data16 (int16_t x)
> {
> - return __builtin_rev_crc16_data16 (0x1234, 0x3214, 0x1021);
> + return __builtin_rev_crc16_data16 (x, 0x3214, 0x1021);
> }
>
> -int32_t rev_crc32_data8 ()
> +int32_t rev_crc32_data8 (int32_t x)
> {
> - return __builtin_rev_crc32_data8 (0xffffffff, 0x32, 0x4002123);
> + return __builtin_rev_crc32_data8 (x, 0x32, 0x4002123);
> }
>
> -int32_t rev_crc32_data16 ()
> +int32_t rev_crc32_data16 (int32_t x)
> {
> - return __builtin_rev_crc32_data16 (0xffffffff, 0x3232, 0x4002123);
> + return __builtin_rev_crc32_data16 (x, 0x3232, 0x4002123);
> }
>
> -int32_t rev_crc32_data32 ()
> +int32_t rev_crc32_data32 (int32_t x)
> {
> - return __builtin_rev_crc32_data32 (0xffffffff, 0x123546ff, 0x4002123);
> + return __builtin_rev_crc32_data32 (x, 0x123546ff, 0x4002123);
> }
> /* { dg-final { scan-assembler-times "vclmul.vx" 12 } } */
> /* { dg-final { scan-assembler-times "vclmulh.vx" 12 } } */
> --
> 2.54.0
>