[PATCH] D129726: [InstCombine] add a constraint for x <u minSigned --> x >s -1
Chenbing.Zheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 13 20:37:44 PDT 2022
Chenbing.Zheng created this revision.
Chenbing.Zheng added reviewers: spatel, RKSimon, benshi001.
Chenbing.Zheng added a project: LLVM.
Herald added a subscriber: hiraditya.
Herald added a project: All.
Chenbing.Zheng requested review of this revision.
Herald added subscribers: llvm-commits, jacquesguan.
Fold x <u minSigned --> x >s -1 will break some combine,
so we add a constraint for it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129726
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-shr.ll
Index: llvm/test/Transforms/InstCombine/icmp-shr.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-shr.ll
+++ llvm/test/Transforms/InstCombine/icmp-shr.ll
@@ -1146,12 +1146,9 @@
ret i1 %r
}
-; TODO: This should reduce to X != 0.
-
define i1 @lshr_pow2_ult_smin(i8 %x) {
; CHECK-LABEL: @lshr_pow2_ult_smin(
-; CHECK-NEXT: [[S:%.*]] = lshr i8 -128, [[X:%.*]]
-; CHECK-NEXT: [[R:%.*]] = icmp sgt i8 [[S]], -1
+; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[X:%.*]], 0
; CHECK-NEXT: ret i1 [[R]]
;
%s = lshr i8 128, %x
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -6169,8 +6169,10 @@
return new ICmpInst(ICmpInst::ICMP_SLT, Op0, Zero);
}
- // For i32: x <u 2147483648 -> x >s -1 -> true if sign bit clear
- if (Pred == ICmpInst::ICMP_ULT && C->isMinSignedValue()) {
+ // For i32: x <u 2147483648 -> x >s -1 -> true if sign bit clear,
+ // and exclude a case that can be matched by other patterns.
+ if (Pred == ICmpInst::ICMP_ULT && C->isMinSignedValue() &&
+ !match(Op0, m_LShr(m_SpecificInt(*C), m_Value()))) {
Constant *AllOnes = Constant::getAllOnesValue(Op0->getType());
return new ICmpInst(ICmpInst::ICMP_SGT, Op0, AllOnes);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129726.444508.patch
Type: text/x-patch
Size: 1475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220714/f60db53e/attachment-0001.bin>
More information about the llvm-commits
mailing list