[PATCH] D132989: [InstCombine] fold 1 - X == X to false
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 30 19:26:27 PDT 2022
liaolucy created this revision.
liaolucy added reviewers: spatel, RKSimon, lebedev.ri.
Herald added a subscriber: hiraditya.
Herald added a project: All.
liaolucy requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D132989
Files:
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/test/Transforms/InstCombine/icmp-sub.ll
Index: llvm/test/Transforms/InstCombine/icmp-sub.ll
===================================================================
--- llvm/test/Transforms/InstCombine/icmp-sub.ll
+++ llvm/test/Transforms/InstCombine/icmp-sub.ll
@@ -561,3 +561,14 @@
bb_exit:
ret void
}
+
+define i1 @sub_false(i32 %x) {
+; CHECK-LABEL: @sub_false(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ret i1 false
+;
+entry:
+ %sub = sub i32 1, %x
+ %cmp = icmp eq i32 %sub, %x
+ ret i1 %cmp
+}
Index: llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
===================================================================
--- llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -4384,6 +4384,11 @@
// icmp C, (C-D) -> icmp D, 0 for equalities or if there is no overflow.
if (C == Op0 && NoOp1WrapProblem)
return new ICmpInst(Pred, D, Constant::getNullValue(Op0->getType()));
+ // (1 - B) == B -> false(1 == 0) for equalities or if there is no overflow.
+ if (B == Op1 && NoOp0WrapProblem && Pred == CmpInst::ICMP_EQ &&
+ match(A, m_One()))
+ return new ICmpInst(CmpInst::ICMP_EQ, A,
+ Constant::getNullValue(B->getType()) /*Zero*/);
// Convert sub-with-unsigned-overflow comparisons into a comparison of args.
// (A - B) u>/u<= A --> B u>/u<= A
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132989.456843.patch
Type: text/x-patch
Size: 1338 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220831/de9d3c60/attachment.bin>
More information about the llvm-commits
mailing list