[llvm] [InstCombine] Fold `(x == y) ? 0 : (x > y ? 1 : -1)` into `ucmp/scmp(x,y)` (PR #107314)
Volodymyr Vasylkun via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 5 10:20:30 PDT 2024
================
@@ -15,8 +15,7 @@ define void @test_low_sgt(i64 %a, i64 %b) {
; CHECK: normal:
; CHECK-NEXT: ret void
; CHECK: unreached:
-; CHECK-NEXT: [[EQ:%.*]] = icmp ne i64 [[A]], [[B]]
-; CHECK-NEXT: [[RESULT:%.*]] = zext i1 [[EQ]] to i32
+; CHECK-NEXT: [[RESULT:%.*]] = call i32 @llvm.scmp.i32.i64(i64 [[A]], i64 [[B]])
----------------
Poseydon42 wrote:
I think for this particular case we can improve the way `ucmp`/`scmp` is handled in ConstraintElimination. The branch implies that within the `unreached` block `a >= b`, so we can replace the call with `icmp + zext/sext`. I don't think it's worth adding extra checks in InstCombine for this.
https://github.com/llvm/llvm-project/pull/107314
More information about the llvm-commits
mailing list