[llvm] [InstCombine] Fold comparisons of llvm.usub.sat result with its LHS (PR #214108)

via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 19 01:09:52 PDT 2026


================
@@ -447,6 +447,17 @@ define i1 @icmp_eq_usub_sat_lhs_nonzero_constant_commuted(i64 %x) {
   ret i1 %cmp
 }
 
+define i1 @icmp_samesign_eq_usub_sat_lhs_nonzero_constant(i64 %x) {
----------------
ParkHanbum wrote:

Overall this looks correct. A few small suggestions:

* Please add a `samesign ult` test, since this path also matches `samesign` predicates and intentionally drops `samesign` when producing `icmp ne`.
* The current vector test is a splat; it would be good to add a non-splat positive case such as `<1, 10>` and a negative case containing a zero lane such as `<1, 0>`.
* Non-blocking: `usub.sat(X, C) uge X` with nonzero `C` is also equivalent to `X == 0`, which would cover the commuted `ule` case as well.
* Nit: since the fold is now restricted to constants, the comment could say `For a nonzero constant C:` rather than `For Y != 0:`.


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


More information about the llvm-commits mailing list