[llvm] [InstCombine] Fold `sext(A < B) + zext(A > B)` into `ucmp/scmp(A, B)` (PR #103833)
Volodymyr Vasylkun via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 15 10:37:33 PDT 2024
https://github.com/Poseydon42 updated https://github.com/llvm/llvm-project/pull/103833
>From 25a60ece9694bb993b910b5b4625bd711588c964 Mon Sep 17 00:00:00 2001
From: Poseydon42 <vvmposeydon at gmail.com>
Date: Wed, 14 Aug 2024 12:16:23 +0100
Subject: [PATCH 1/3] Precommit tests
---
.../sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll | 208 ++++++++++++++++++
1 file changed, 208 insertions(+)
create mode 100644 llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
diff --git a/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll b/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
new file mode 100644
index 00000000000000..ba519c379349c6
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
@@ -0,0 +1,208 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=instcombine -S | FileCheck %s
+
+; sext(A s< B) + zext(A s> B) => scmp(A, B)
+define i8 @signed_add(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+; Unsigned version
+define i8 @unsigned_add(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @unsigned_add(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp ult i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp ugt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+; Commuted operands
+define i8 @signed_add_commuted1(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_commuted1(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = zext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = sext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = zext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = sext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+define i8 @signed_add_commuted2(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_commuted2(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp sgt i32 [[B]], [[A]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp sgt i32 %b, %a
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+; zext(A s> B) - zext(A s< B) => scmp(A, B)
+define i8 @signed_sub(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_sub(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8_NEG:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8_NEG]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = zext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = sub i8 %gt8, %lt8
+ ret i8 %r
+}
+
+; Unsigned version
+define i8 @unsigned_sub(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @unsigned_sub(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8_NEG:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8_NEG]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp ult i32 %a, %b
+ %lt8 = zext i1 %lt to i8
+ %gt = icmp ugt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = sub i8 %gt8, %lt8
+ ret i8 %r
+}
+
+; Negative test: incorrect predicates
+define i8 @signed_add_neg1(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_neg1(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp sgt i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+define i8 @signed_add_neg2(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_neg2(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp ne i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp ne i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+; Negative test: mismatched signedness of predicates
+define i8 @signed_add_neg3(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_neg3(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp ugt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+; Negative test: zext instead of sext or vice-versa (NOT commuted operands)
+define i8 @signed_add_neg4(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_neg4(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = sext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = sext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = sext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
+
+define i8 @signed_add_neg5(i32 %a, i32 %b) {
+; CHECK-LABEL: define i8 @signed_add_neg5(
+; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
+; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
+; CHECK-NEXT: [[LT8:%.*]] = zext i1 [[LT]] to i8
+; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
+; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
+; CHECK-NEXT: [[R:%.*]] = add nuw nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: ret i8 [[R]]
+;
+ %lt = icmp slt i32 %a, %b
+ %lt8 = zext i1 %lt to i8
+ %gt = icmp sgt i32 %a, %b
+ %gt8 = zext i1 %gt to i8
+ %r = add i8 %lt8, %gt8
+ ret i8 %r
+}
>From 3ee9426619e8cc1a41877723a49b057ec767a359 Mon Sep 17 00:00:00 2001
From: Poseydon42 <vvmposeydon at gmail.com>
Date: Wed, 14 Aug 2024 12:48:28 +0100
Subject: [PATCH 2/3] Implement the fold and update tests
---
.../InstCombine/InstCombineAddSub.cpp | 19 ++++++++++
llvm/test/Transforms/InstCombine/add.ll | 4 +--
.../sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll | 36 ++++---------------
3 files changed, 27 insertions(+), 32 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index 3bd086230cbec5..a42a7aadbeb27d 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -1622,6 +1622,25 @@ Instruction *InstCombinerImpl::visitAdd(BinaryOperator &I) {
A->getType()->isIntOrIntVectorTy(1))
return replaceInstUsesWith(I, Constant::getNullValue(I.getType()));
+ // sext(A < B) + zext(A > B) => ucmp/scmp(A, B)
+ ICmpInst::Predicate LTPred, GTPred;
+ if (match(&I,
+ m_c_Add(m_SExt(m_c_ICmp(LTPred, m_Value(A), m_Value(B))),
+ m_ZExt(m_c_ICmp(GTPred, m_Deferred(A), m_Deferred(B)))))) {
+ if (ICmpInst::isGT(LTPred)) {
+ std::swap(LTPred, GTPred);
+ std::swap(A, B);
+ }
+
+ if (ICmpInst::isLT(LTPred) && ICmpInst::isGT(GTPred) &&
+ ICmpInst::isSigned(LTPred) == ICmpInst::isSigned(GTPred))
+ return replaceInstUsesWith(
+ I, Builder.CreateIntrinsic(
+ Ty,
+ ICmpInst::isSigned(LTPred) ? Intrinsic::scmp : Intrinsic::ucmp,
+ {A, B}));
+ }
+
// A+B --> A|B iff A and B have no bits set in common.
WithCache<const Value *> LHSCache(LHS), RHSCache(RHS);
if (haveNoCommonBitsSet(LHSCache, RHSCache, SQ.getWithInstruction(&I)))
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index adb61cd4b9692f..053975fe3e8a5c 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -1277,8 +1277,8 @@ define <2 x i8> @ashr_add_commute(<2 x i1> %x, <2 x i1> %y) {
define i32 @cmp_math(i32 %x, i32 %y) {
; CHECK-LABEL: @cmp_math(
-; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
-; CHECK-NEXT: [[R:%.*]] = zext i1 [[LT]] to i32
+; CHECK-NEXT: [[S:%.*]] = call i32 @llvm.ucmp.i32.i32(i32 [[X:%.*]], i32 [[Y:%.*]])
+; CHECK-NEXT: [[R:%.*]] = lshr i32 [[S]], 31
; CHECK-NEXT: ret i32 [[R]]
;
%gt = icmp ugt i32 %x, %y
diff --git a/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll b/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
index ba519c379349c6..02ae7ce82f13ce 100644
--- a/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
+++ b/llvm/test/Transforms/InstCombine/sext-a-lt-b-plus-zext-a-gt-b-to-uscmp.ll
@@ -5,11 +5,7 @@
define i8 @signed_add(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @signed_add(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
-; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[A]], i32 [[B]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp slt i32 %a, %b
@@ -24,11 +20,7 @@ define i8 @signed_add(i32 %a, i32 %b) {
define i8 @unsigned_add(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @unsigned_add(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A]], [[B]]
-; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[A]], i32 [[B]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp ult i32 %a, %b
@@ -43,11 +35,7 @@ define i8 @unsigned_add(i32 %a, i32 %b) {
define i8 @signed_add_commuted1(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @signed_add_commuted1(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
-; CHECK-NEXT: [[LT8:%.*]] = zext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = sext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[B]], i32 [[A]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp slt i32 %a, %b
@@ -61,11 +49,7 @@ define i8 @signed_add_commuted1(i32 %a, i32 %b) {
define i8 @signed_add_commuted2(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @signed_add_commuted2(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp sgt i32 [[B]], [[A]]
-; CHECK-NEXT: [[LT8:%.*]] = sext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[A]], i32 [[B]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp sgt i32 %b, %a
@@ -80,11 +64,7 @@ define i8 @signed_add_commuted2(i32 %a, i32 %b) {
define i8 @signed_sub(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @signed_sub(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp slt i32 [[A]], [[B]]
-; CHECK-NEXT: [[LT8_NEG:%.*]] = sext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp sgt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8_NEG]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.scmp.i8.i32(i32 [[A]], i32 [[B]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp slt i32 %a, %b
@@ -99,11 +79,7 @@ define i8 @signed_sub(i32 %a, i32 %b) {
define i8 @unsigned_sub(i32 %a, i32 %b) {
; CHECK-LABEL: define i8 @unsigned_sub(
; CHECK-SAME: i32 [[A:%.*]], i32 [[B:%.*]]) {
-; CHECK-NEXT: [[LT:%.*]] = icmp ult i32 [[A]], [[B]]
-; CHECK-NEXT: [[LT8_NEG:%.*]] = sext i1 [[LT]] to i8
-; CHECK-NEXT: [[GT:%.*]] = icmp ugt i32 [[A]], [[B]]
-; CHECK-NEXT: [[GT8:%.*]] = zext i1 [[GT]] to i8
-; CHECK-NEXT: [[R:%.*]] = add nsw i8 [[LT8_NEG]], [[GT8]]
+; CHECK-NEXT: [[R:%.*]] = call i8 @llvm.ucmp.i8.i32(i32 [[A]], i32 [[B]])
; CHECK-NEXT: ret i8 [[R]]
;
%lt = icmp ult i32 %a, %b
>From 4563927d331d71efd67fcd5c1ec958f358cdc282 Mon Sep 17 00:00:00 2001
From: Poseydon42 <vvmposeydon at gmail.com>
Date: Thu, 15 Aug 2024 18:37:10 +0100
Subject: [PATCH 3/3] Fix tests
---
llvm/test/Transforms/InstCombine/add.ll | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/add.ll b/llvm/test/Transforms/InstCombine/add.ll
index 053975fe3e8a5c..f0eb0f175f5083 100644
--- a/llvm/test/Transforms/InstCombine/add.ll
+++ b/llvm/test/Transforms/InstCombine/add.ll
@@ -1277,8 +1277,8 @@ define <2 x i8> @ashr_add_commute(<2 x i1> %x, <2 x i1> %y) {
define i32 @cmp_math(i32 %x, i32 %y) {
; CHECK-LABEL: @cmp_math(
-; CHECK-NEXT: [[S:%.*]] = call i32 @llvm.ucmp.i32.i32(i32 [[X:%.*]], i32 [[Y:%.*]])
-; CHECK-NEXT: [[R:%.*]] = lshr i32 [[S]], 31
+; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[X:%.*]], [[Y:%.*]]
+; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i32
; CHECK-NEXT: ret i32 [[R]]
;
%gt = icmp ugt i32 %x, %y
More information about the llvm-commits
mailing list