[llvm] [InstCombine] Fold `icmp samesign u{gt/lt} (X +nsw C2), C` -> `icmp s{gt/lt} X, (C - C2)` (PR #169960)

Andreas Jonson via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 4 13:05:47 PST 2025


andjo403 wrote:

for the first I think it is ok with some duplication to make the code easier to read and for the second think that there have been some miscommunication it is the unsigned predicate that I and the other comment was talking about.
the sign of the predicate needs to match the sign of the of the sub you can see that by trying to use the unsigned sub in the proof.
think that it probably is easiest to leave the legacy fold as is and add a new fold after that will only handle the samesign case and that will result in preference for unsigned predicate as it will be handled in the legacy case and only ssub_ov needs to be handled in that case as we know that the predicate will be signed

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


More information about the llvm-commits mailing list