]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PR tree-optimization/124108] Verify type_has_mode_precision before reassociating...
authorjlaw <jeffreyalaw@gmail.com>
Thu, 19 Feb 2026 14:04:27 +0000 (07:04 -0700)
committerjlaw <jeffreyalaw@gmail.com>
Thu, 19 Feb 2026 14:04:27 +0000 (07:04 -0700)
As Andrew noted in pr124108, the two patterns that reassociate expressions to
expose a rotate hidden by an embedded XOR need to check
type_has_mode_precision_p to avoid an ICE during gimple->RTL expansion.

This adds the necessary checks.  Bootstrapped and regression tested on x86.

PR tree-optimization/124108
gcc/
* match.pd (reassociating XOR to expose rotations): Check
type_has_mode_precision_p before simplifying.

gcc/testsuite/
* gcc.dg/torture/pr124108.c: New test.

gcc/match.pd
gcc/testsuite/gcc.dg/torture/pr124108.c [new file with mode: 0644]

index 8910591a04b3751f72519a6c88330856bbdb1470..7f16fd4e0814e54ca6ac5ecf1babcc6b9211cbf7 100644 (file)
@@ -12227,7 +12227,8 @@ and,
 (simplify
   (bit_ior:c (lshift @0 INTEGER_CST@1)
             (bit_xor (rshift @2 INTEGER_CST@3) INTEGER_CST@4))
-   (if (tree_fits_uhwi_p (@1)
+   (if (type_has_mode_precision_p (type)
+       && tree_fits_uhwi_p (@1)
        && tree_fits_uhwi_p (@3)
        && tree_fits_uhwi_p (@4)
        && ((~((HOST_WIDE_INT_1U << tree_to_uhwi (@1)) - 1)) & tree_to_uhwi (@4)) == 0
@@ -12241,7 +12242,8 @@ and,
 (simplify
   (bit_ior:c (bit_xor (lshift @0 INTEGER_CST@1) INTEGER_CST@2)
             (rshift @3 INTEGER_CST@4))
-   (if (tree_fits_uhwi_p (@1)
+   (if (type_has_mode_precision_p (type)
+       && tree_fits_uhwi_p (@1)
        && tree_fits_uhwi_p (@2)
        && tree_fits_uhwi_p (@4)
        && (((((HOST_WIDE_INT_1U << tree_to_uhwi (@1)) - 1)) & tree_to_uhwi (@2)) == 0)
diff --git a/gcc/testsuite/gcc.dg/torture/pr124108.c b/gcc/testsuite/gcc.dg/torture/pr124108.c
new file mode 100644 (file)
index 0000000..dfdddec
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile { target bitint } } */
+/* { dg-options "-std=c23 -pedantic-errors" } */
+
+typedef unsigned _BitInt(4) B;
+
+B a, b;
+
+void
+foo()
+{
+  b *= (a ^ 2wbu) << 2 |
+       (a ^ 2wbu) >> 2;
+|