[PATCH] D69224: [InstCombine] Fold uadd.sat(a, b) == 0 and usub.sat(a, b) == 0
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 20 13:19:35 PDT 2019
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb1b7a2f7b63d: [InstCombine] Fold uadd.sat(a, b) == 0 and usub.sat(a, b) == 0 (authored by nikic).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69224/new/
https://reviews.llvm.org/D69224
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/saturating-add-sub.ll
Index: llvm/test/Transforms/InstCombine/saturating-add-sub.ll
===================================================================
--- llvm/test/Transforms/InstCombine/saturating-add-sub.ll
+++ llvm/test/Transforms/InstCombine/saturating-add-sub.ll
@@ -1158,9 +1158,9 @@
define i1 @scalar_uadd_eq_zero(i8 %a, i8 %b) {
; CHECK-LABEL: @scalar_uadd_eq_zero(
-; CHECK-NEXT: [[SAT:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SAT]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i8 [[TMP1]], 0
+; CHECK-NEXT: ret i1 [[TMP2]]
;
%sat = call i8 @llvm.uadd.sat.i8(i8 %a, i8 %b)
%cmp = icmp eq i8 %sat, 0
@@ -1169,9 +1169,9 @@
define i1 @scalar_uadd_ne_zero(i8 %a, i8 %b) {
; CHECK-LABEL: @scalar_uadd_ne_zero(
-; CHECK-NEXT: [[SAT:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[SAT]], 0
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[A:%.*]], [[B:%.*]]
+; CHECK-NEXT: [[TMP2:%.*]] = icmp ne i8 [[TMP1]], 0
+; CHECK-NEXT: ret i1 [[TMP2]]
;
%sat = call i8 @llvm.uadd.sat.i8(i8 %a, i8 %b)
%cmp = icmp ne i8 %sat, 0
@@ -1180,8 +1180,7 @@
define i1 @scalar_usub_eq_zero(i8 %a, i8 %b) {
; CHECK-LABEL: @scalar_usub_eq_zero(
-; CHECK-NEXT: [[SAT:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i8 [[SAT]], 0
+; CHECK-NEXT: [[CMP:%.*]] = icmp ule i8 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%sat = call i8 @llvm.usub.sat.i8(i8 %a, i8 %b)
@@ -1191,8 +1190,7 @@
define i1 @scalar_usub_ne_zero(i8 %a, i8 %b) {
; CHECK-LABEL: @scalar_usub_ne_zero(
-; CHECK-NEXT: [[SAT:%.*]] = call i8 @llvm.usub.sat.i8(i8 [[A:%.*]], i8 [[B:%.*]])
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[SAT]], 0
+; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i8 [[A:%.*]], [[B:%.*]]
; CHECK-NEXT: ret i1 [[CMP]]
;
%sat = call i8 @llvm.usub.sat.i8(i8 %a, i8 %b)
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3076,6 +3076,28 @@
}
break;
}
+
+ case Intrinsic::uadd_sat: {
+ // uadd.sat(a, b) == 0 -> (a | b) == 0
+ if (C.isNullValue()) {
+ Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1));
+ return replaceInstUsesWith(Cmp, Builder.CreateICmp(
+ Cmp.getPredicate(), Or, Constant::getNullValue(Ty)));
+
+ }
+ break;
+ }
+
+ case Intrinsic::usub_sat: {
+ // usub.sat(a, b) == 0 -> a <= b
+ if (C.isNullValue()) {
+ ICmpInst::Predicate NewPred = Cmp.getPredicate() == ICmpInst::ICMP_EQ
+ ? ICmpInst::ICMP_ULE : ICmpInst::ICMP_UGT;
+ return ICmpInst::Create(Instruction::ICmp, NewPred,
+ II->getArgOperand(0), II->getArgOperand(1));
+ }
+ break;
+ }
default:
break;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D69224.225802.patch
Type: text/x-patch
Size: 3136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191020/eba940af/attachment.bin>
More information about the llvm-commits
mailing list