From: Jeff Law Date: Tue, 13 Jan 2026 14:16:05 +0000 (-0700) Subject: [PR tree-optimization/123530] Fix ICE in recently added match.pd pattern X-Git-Tag: basepoints/gcc-17~2060 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77ff7c2bb2240d64b8b03c87adc3d42957d59ae8;p=thirdparty%2Fgcc.git [PR tree-optimization/123530] Fix ICE in recently added match.pd pattern The gimple optimization passes can create negative shift counts and pass them into the simplification routines as seen by the code in pr123530. If we then call tree_to_uhwi on those values we get a nice little ICE. This guards the tree_to_uhwi calls on tree_fits_uhwi_p and resolves the ICE. I just protected them all in this recently added pattern. Bootstrapped and regression tested on x86 and riscv. Also tested on the rest of the embedded targets without any regressions. Pushing to the trunk. PR tree-optimization/123530 gcc/ * match.pd (reassociating xor to enable rotations): Verify constants fit into a uhwi before trying to extract them as a uhwi. gcc/testsuite/ * gcc.dg/torture/pr123530.c: New test. --- diff --git a/gcc/match.pd b/gcc/match.pd index f29f7638d66..cc33a972b98 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -12190,7 +12190,10 @@ and, (simplify (bit_ior:c (lshift @0 INTEGER_CST@1) (bit_xor (rshift @2 INTEGER_CST@3) INTEGER_CST@4)) - (if (((~((HOST_WIDE_INT_1U << tree_to_uhwi (@1)) - 1)) & tree_to_uhwi (@4)) == 0 + (if (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 && (tree_to_uhwi (@1) + tree_to_uhwi (@3)) == TYPE_PRECISION (type) && TYPE_UNSIGNED (type) && @0 == @2) @@ -12201,7 +12204,10 @@ and, (simplify (bit_ior:c (bit_xor (lshift @0 INTEGER_CST@1) INTEGER_CST@2) (rshift @3 INTEGER_CST@4)) - (if ((((((HOST_WIDE_INT_1U << tree_to_uhwi (@1)) - 1)) & tree_to_uhwi (@2)) == 0) + (if (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) && (tree_to_uhwi (@1) + tree_to_uhwi (@4)) == TYPE_PRECISION (type) && TYPE_UNSIGNED (type) && @0 == @3) diff --git a/gcc/testsuite/gcc.dg/torture/pr123530.c b/gcc/testsuite/gcc.dg/torture/pr123530.c new file mode 100644 index 00000000000..1012270098b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr123530.c @@ -0,0 +1,6 @@ +/* { dg-do compile } */ +int a, b, c; +void d() { + int e = -1; + (c >> e | ~(b << 1) ^ 1) & a; +}