[llvm] [InstCombine] Fold `icmp samesign u{gt/ge/lt/le} (X +nsw C2), C` -> `icmp s{gt/ge/lt/le} X, (C - C2)` (PR #169960)
Tirthankar Mazumder via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 30 03:32:21 PST 2025
wermos wrote:
I ran into an interesting problem wherein my implemented transform is interfering with the transform implemented in #95649 because that one deals with the specific case where `C == -C2` (and `C2` is a power of 2) and it opts to do `icmp ult (add X, C2), C -> icmp ne (and X, C), 2C`.
If I implement the transform where @andjo403 suggested, then tests like this:
https://github.com/llvm/llvm-project/blob/b22825631293c19f70ca9969bd9de6094c688430/llvm/test/Transforms/InstCombine/icmp-add.ll#L3048-L3057
will get optimized differently.
This happens because the add folding code is before the power-of-2 folding code.
So my question is, do we want to keep that power-of-2 behavior? If that is the case, then I will need to add extra conditions to the if-clause to prevent it from entering when `C == -C2` and `C2` is a power of 2.
https://github.com/llvm/llvm-project/pull/169960
More information about the llvm-commits
mailing list