[llvm] 5e9522c - [InstSimplify] Odd - X ==/!= X -> false/true
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 5 08:51:54 PDT 2022
Author: LiaoChunyu
Date: 2022-09-05T23:51:45+08:00
New Revision: 5e9522c311ddbdf1a6bb41bdd705f50d4d9b0771
URL: https://github.com/llvm/llvm-project/commit/5e9522c311ddbdf1a6bb41bdd705f50d4d9b0771
DIFF: https://github.com/llvm/llvm-project/commit/5e9522c311ddbdf1a6bb41bdd705f50d4d9b0771.diff
LOG: [InstSimplify] Odd - X ==/!= X -> false/true
Reviewed By: spatel
Differential Revision: https://reviews.llvm.org/D132989
Added:
Modified:
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/icmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index 8b08d7c9228fd..aad8acfad8390 100644
--- a/llvm/lib/Analysis/InstructionSimplify.cpp
+++ b/llvm/lib/Analysis/InstructionSimplify.cpp
@@ -3126,6 +3126,17 @@ static Value *simplifyICmpWithBinOpOnLHS(CmpInst::Predicate Pred,
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;
}
diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
index b967198dd6c94..c6d2f3c03beba 100644
--- a/llvm/test/Transforms/InstSimplify/icmp.ll
+++ b/llvm/test/Transforms/InstSimplify/icmp.ll
@@ -214,9 +214,7 @@ loop:
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_false(i32 %x) {
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 i1 @sub_swap(i8 %x) {
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
More information about the llvm-commits
mailing list