Fix comparison in match.pd pattern for bit extraction and shift
Correctly handles constants of different precisions in bit manipulation pattern matching.
A bug in the match.pd pattern matching for bit extraction and shift operations has been fixed. The issue occurred when constants C1 and C3 in the ((X >> C1) & C2) << C3 pattern had different data precisions, leading to an assertion failure. The fix involves converting these constants to widest_int instead of a common type, resolving the ICE reported in PR127552.
In Details
The simplification rule in match.pd for the pattern ((X >> C1) & C2) << C3 previously assumed C1 and C3 had identical wide_int types when performing the wi::leu_p comparison. This commit corrects this by ensuring widest_int is used for the comparison, thus handling cases where C1 and C3 have different precisions and preventing the assertion failure seen in PR127552. The test case match-bit-extract-shift.c has been updated to exercise this fix.
- match.pd
- A file containing pattern matching rules used by GCC's optimization passes, particularly for recognizing and simplifying specific code structures.
- wide_int
- An arbitrary-precision integer type used within GCC to represent constant values that may exceed the range of standard machine integer types.
- widest_int
- A specific type of
wide_intthat accommodates the largest possible precision, ensuring comparisons and operations between constants of varying sizes are handled correctly. - ICE
- Internal Compiler Error, a crash within the compiler during compilation, often indicating a bug in the compiler itself.