[PATCH] D132989: [InstSimplify] Odd - X ==/!= X -> false/true
Liao Chunyu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 5 08:29:33 PDT 2022
liaolucy updated this revision to Diff 458015.
liaolucy marked an inline comment as done.
liaolucy added a comment.
address comments , thanks spatel. rebase.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132989/new/
https://reviews.llvm.org/D132989
Files:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/icmp.ll
Index: llvm/test/Transforms/InstSimplify/icmp.ll
===================================================================
--- llvm/test/Transforms/InstSimplify/icmp.ll
+++ llvm/test/Transforms/InstSimplify/icmp.ll
@@ -214,9 +214,7 @@
define i1 @sub_false(i32 %x) {
; CHECK-LABEL: @sub_false(
-; CHECK-NEXT: [[SUB:%.*]] = sub i32 1, [[X:%.*]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[SUB]], [[X]]
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 false
;
%sub = sub i32 1, %x
%cmp = icmp eq i32 %sub, %x
@@ -225,9 +223,7 @@
define i1 @sub_swap(i8 %x) {
; CHECK-LABEL: @sub_swap(
-; CHECK-NEXT: [[SUB:%.*]] = sub i8 3, [[X:%.*]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne i8 [[X]], [[SUB]]
-; CHECK-NEXT: ret i1 [[CMP]]
+; CHECK-NEXT: ret i1 true
;
%sub = sub i8 3, %x
%cmp = icmp ne i8 %x, %sub
@@ -236,9 +232,7 @@
define <2 x i1> @sub_odd(<2 x i8> %x) {
; CHECK-LABEL: @sub_odd(
-; CHECK-NEXT: [[SUB:%.*]] = sub <2 x i8> <i8 3, i8 3>, [[X:%.*]]
-; CHECK-NEXT: [[CMP:%.*]] = icmp ne <2 x i8> [[SUB]], [[X]]
-; CHECK-NEXT: ret <2 x i1> [[CMP]]
+; CHECK-NEXT: ret <2 x i1> <i1 true, i1 true>
;
%sub = sub <2 x i8> <i8 3, i8 3>, %x
%cmp = icmp ne <2 x i8> %sub, %x
Index: llvm/lib/Analysis/InstructionSimplify.cpp
===================================================================
--- llvm/lib/Analysis/InstructionSimplify.cpp
+++ llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3126,6 +3126,17 @@
return getTrue(ITy);
}
+ // (sub C, X) == X, C is odd --> false
+ // (sub C, X) != X, C is odd --> true
+ if (match(LBO, m_Sub(m_APInt(C), m_Specific(RHS)))) {
+ if ((*C & 1) == 1) {
+ if (Pred == CmpInst::ICMP_EQ)
+ return ConstantInt::getFalse(getCompareTy(RHS));
+ if (Pred == CmpInst::ICMP_NE)
+ return ConstantInt::getTrue(getCompareTy(RHS));
+ }
+ }
+
return nullptr;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132989.458015.patch
Type: text/x-patch
Size: 1885 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220905/e5b74496/attachment.bin>
More information about the llvm-commits
mailing list