[llvm] ecad53c - [InstCombine] Don't fold `uadd.sat` to `or` if it increase instruction count
Noah Goldstein via llvm-commits
llvm-commits at lists.llvm.org
Sat Apr 29 10:39:00 PDT 2023
Author: Noah Goldstein
Date: 2023-04-29T12:38:41-05:00
New Revision: ecad53c3f442df32149967a49803d22d98b2d2c7
URL: https://github.com/llvm/llvm-project/commit/ecad53c3f442df32149967a49803d22d98b2d2c7
DIFF: https://github.com/llvm/llvm-project/commit/ecad53c3f442df32149967a49803d22d98b2d2c7.diff
LOG: [InstCombine] Don't fold `uadd.sat` to `or` if it increase instruction count
In the `(cmp eq/ne (uadd.sat X, Y),0)` case, we where missing a
`hasOneUse` check.
Differential Revision: https://reviews.llvm.org/D149425
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index bd3000ada1f38..aeb1c53c555fe 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3386,7 +3386,7 @@ Instruction *InstCombinerImpl::foldICmpEqIntrinsicWithConstant(
case Intrinsic::uadd_sat: {
// uadd.sat(a, b) == 0 -> (a | b) == 0
- if (C.isZero()) {
+ if (C.isZero() && II->hasOneUse()) {
Value *Or = Builder.CreateOr(II->getArgOperand(0), II->getArgOperand(1));
return new ICmpInst(Pred, Or, Constant::getNullValue(Ty));
}
diff --git a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
index 529f107fafffc..078158729ef1b 100644
--- a/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
+++ b/llvm/test/Transforms/InstCombine/cmp-intrinsic.ll
@@ -872,8 +872,7 @@ define i1 @uadd_sat_ne_zero_fail_multiuse(i8 %x, i8 %y) {
; CHECK-LABEL: @uadd_sat_ne_zero_fail_multiuse(
; CHECK-NEXT: [[M:%.*]] = call i8 @llvm.uadd.sat.i8(i8 [[X:%.*]], i8 [[Y:%.*]])
; CHECK-NEXT: call void @use8(i8 [[M]])
-; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X]], [[Y]]
-; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[TMP1]], 0
+; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[M]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%m = call i8 @llvm.uadd.sat.i8(i8 %x, i8 %y)
More information about the llvm-commits
mailing list