[llvm] [InstCombine] Fix #163110: Fold icmp (shl X, L), (add (shl Y, L), 1<<L) to icmp X, (Y + 1) (PR #165975)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 6 01:11:36 PST 2026


================

----------------
Michael-Chen-NJU wrote:

Hi @nikic,
 
Regarding the `bool Lossless` parameter, I’m concerned that a single boolean might not be sufficient to define "lossless" for left shifts.Specifically, for a left shift to be lossless, its validity depends on the subsequent "reverse" operation: it would require `nuw` if we intend to shift it back via `lshr`, but `nsw` if we use `ashr`. Without knowing the specific opcode of the potential outer reverse shift, it’s difficult to perform an accurate lossless check for shl within this function.

Given that this might introduce significant complexity and require further refactoring of the function signature (e.g., adding an `OuterOpc`), would it be acceptable to stay conservative for now? We could explicitly update the doc comments to clarify the current asymmetric behavior: that `canEvaluateShifted` follows cost-modeling for left shifts but enforces lossless semantics for right shifts to ensure correctness for the current optimization?

https://github.com/llvm/llvm-project/pull/165975


More information about the llvm-commits mailing list