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.

Jeff
commit 1b8bbe4a3da10213a204d6f5aaab9807a4193102
Author: jlaw <[email protected]>
Date:   Thu Feb 19 07:04:27 2026 -0700

    [PR tree-optimization/124108] Verify type_has_mode_precision before 
reassociating expressions
    
    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.

diff --git a/gcc/match.pd b/gcc/match.pd
index 8910591a04b..7f16fd4e081 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -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
index 00000000000..dfdddecc824
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr124108.c
@@ -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;
+}

Reply via email to