llvm-project
1d35b66c - [GlobalISel] Don't fold saturating shifts in shift_of_shifted_logic_chain (#241191)

Commit
6 days ago
[GlobalISel] Don't fold saturating shifts in shift_of_shifted_logic_chain (#241191) Fixes #241100 `shift_of_shifted_logic_chain` rewrote ``` SHIFT (LOGIC (SHIFT X, C0), Y), C1 -> LOGIC (SHIFT X, C0+C1), (SHIFT Y, C1) ``` for every opcode in `shift_chain_frags`, including `G_USHLSAT`/`G_SSHLSAT`. This is wrong for saturating shifts, since saturation depends on bits the logic op can clear or flip. 32-bit `ushl.sat(ushl.sat(8, 20) & 15, 11)`: original = 0, combined = `ushl.sat(8, 31) & ushl.sat(15, 11)` = 30720. Add `plain_shift_chain_frags` (`[G_SHL, G_ASHR, G_LSHR]`) and use it for this combine only. `shift_immed_chain` keeps `shift_chain_frags`; it is valid for saturating shifts because `matchShiftImmedChain` requires matching opcodes. This matches `DAGCombiner::combineShiftOfShiftedLogic`, which only handles SHL/SRA/SRL. Tests: updated `combine-shift-of-shifted-logic-shlsat.mir` (sat shifts now preserved), added plain-shift positive controls, and RISC-V regression tests using the values from the issue. Assisted-by: Antigravity (reviewed and tested by the author)
Author
Parents
Loading