match.pd: Fix simplification for bit shifts and AND operations
Corrects a simplification rule for expressions involving bit shifts and bitwise AND.
This commit corrects a simplification rule in match.pd that handles expressions like ((C << A) & D) != 0. The previous rule incorrectly folded the expression to false or true based on a simple comparison of shift counts and mask values, without properly considering the type of the shift count. The fix ensures that if the difference between the constants (used in the shift comparison) does not fit within the type of the shift count operand, the simplification correctly deduces that the result is always false or true, preventing miscompilations.
In Details
The match.pd file contains pattern-matching rules for optimizing expressions. This change refines a simplification for ((C << A) & D) != 0 which was intended to fold to A == 0 or A != 0 based on constants C and D. The issue was that if the effective shift count difference (c1 - c2 or c2 - c1) did not fit within the TREE_TYPE of the shift count operand A, the previous logic incorrectly assumed zero or non-zero results. The fix now correctly handles this overflow case for the shift count, ensuring the simplification is always accurate.
- match.pd
- A file in GCC that defines pattern-matching rules used by the tree-ssa-ccp and other optimization passes to simplify and rewrite expressions.
- bit shift
- A bitwise operation that shifts the bits of a number to the left or right.
- bit and
- A bitwise operation that performs a logical AND operation on corresponding bits of two operands.
- TREE_TYPE
- In GCC's internal representation (tree), this refers to the type information associated with a particular node.