[llvm] r267177 - [SimplifyCFG] Add final missing implications to isImpliedTrueByMatchingCmp.
Chad Rosier via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 22 10:57:35 PDT 2016
Author: mcrosier
Date: Fri Apr 22 12:57:34 2016
New Revision: 267177
URL: http://llvm.org/viewvc/llvm-project?rev=267177&view=rev
Log:
[SimplifyCFG] Add final missing implications to isImpliedTrueByMatchingCmp.
Summary: eq imply [u|s]ge and [u|s]le are true.
Remove redundant logic by implementing isImpliedFalseByMatchingCmp(Pred1, Pred2)
as isImpliedTrueByMatchingCmp(Pred1, getInversePredicate(Pred2)).
Modified:
llvm/trunk/lib/IR/Instructions.cpp
llvm/trunk/test/Transforms/SimplifyCFG/implied-cond-matching.ll
Modified: llvm/trunk/lib/IR/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Instructions.cpp?rev=267177&r1=267176&r2=267177&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Instructions.cpp (original)
+++ llvm/trunk/lib/IR/Instructions.cpp Fri Apr 22 12:57:34 2016
@@ -3562,6 +3562,10 @@ bool CmpInst::isImpliedTrueByMatchingCmp
switch (Pred1) {
default:
break;
+ case ICMP_EQ:
+ // A == B implies A >=u B, A <=u B, A >=u B, and A <=u B are true.
+ return Pred2 == ICMP_UGE || Pred2 == ICMP_ULE || Pred2 == ICMP_SGE ||
+ Pred2 == ICMP_SLE;
case ICMP_UGT: // A >u B implies A != B and A >=u B are true.
return Pred2 == ICMP_NE || Pred2 == ICMP_UGE;
case ICMP_ULT: // A <u B implies A != B and A <=u B are true.
@@ -3575,38 +3579,7 @@ bool CmpInst::isImpliedTrueByMatchingCmp
}
bool CmpInst::isImpliedFalseByMatchingCmp(Predicate Pred1, Predicate Pred2) {
- // If an inverted Pred1 matches Pred2, we can infer the second condition is
- // false.
- if (getInversePredicate(Pred1) == Pred2)
- return true;
-
- // If a swapped Pred1 matches Pred2, we can infer the second condition is
- // false in many cases.
- if (getSwappedPredicate(Pred1) == Pred2) {
- switch (Pred1) {
- default:
- break;
- case ICMP_UGT: // A >u B implies A <u B is false.
- case ICMP_ULT: // A <u B implies A >u B is false.
- case ICMP_SGT: // A >s B implies A <s B is false.
- case ICMP_SLT: // A <s B implies A >s B is false.
- return true;
- }
- }
- // A == B implies A > B and A < B are false.
- if (Pred1 == ICMP_EQ && isFalseWhenEqual(Pred2))
- return true;
-
- switch (Pred1) {
- default:
- break;
- case ICMP_UGT: // A >u B implies A == B is false.
- case ICMP_ULT: // A <u B implies A == B is false.
- case ICMP_SGT: // A >s B implies A == B is false.
- case ICMP_SLT: // A <s B implies A == B is false.
- return Pred2 == ICMP_EQ;
- }
- return false;
+ return isImpliedTrueByMatchingCmp(Pred1, getInversePredicate(Pred2));
}
//===----------------------------------------------------------------------===//
Modified: llvm/trunk/test/Transforms/SimplifyCFG/implied-cond-matching.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/implied-cond-matching.ll?rev=267177&r1=267176&r2=267177&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/implied-cond-matching.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/implied-cond-matching.ll Fri Apr 22 12:57:34 2016
@@ -140,10 +140,10 @@ untaken:
ret void
}
-; A == B implies A >=u B is unknown to be true or false.
+; A == B implies A >=u B is true.
; CHECK-LABEL: @test_eq_uge
; CHECK: call void @is(i1 true)
-; CHECK: call void @is(i1 false)
+; CHECK-NOT: call void @is(i1 false)
define void @test_eq_uge(i32 %a, i32 %b) {
%cmp1 = icmp eq i32 %a, %b
br i1 %cmp1, label %taken, label %untaken
@@ -188,10 +188,10 @@ untaken:
ret void
}
-; A == B implies A <=u B is unknown to be true or false.
+; A == B implies A <=u B is true.
; CHECK-LABEL: @test_eq_ule
; CHECK: call void @is(i1 true)
-; CHECK: call void @is(i1 false)
+; CHECK-NOT: call void @is(i1 false)
define void @test_eq_ule(i32 %a, i32 %b) {
%cmp1 = icmp eq i32 %a, %b
br i1 %cmp1, label %taken, label %untaken
@@ -236,10 +236,10 @@ untaken:
ret void
}
-; A == B implies A >=s B is unknown to be true or false.
+; A == B implies A >=s B is true.
; CHECK-LABEL: @test_eq_sge
; CHECK: call void @is(i1 true)
-; CHECK: call void @is(i1 false)
+; CHECK-NOT: call void @is(i1 false)
define void @test_eq_sge(i32 %a, i32 %b) {
%cmp1 = icmp eq i32 %a, %b
br i1 %cmp1, label %taken, label %untaken
@@ -284,10 +284,10 @@ untaken:
ret void
}
-; A == B implies A <=s B is unknown to be true or false.
+; A == B implies A <=s B is true.
; CHECK-LABEL: @test_eq_sle
; CHECK: call void @is(i1 true)
-; CHECK: call void @is(i1 false)
+; CHECK-NOT: call void @is(i1 false)
define void @test_eq_sle(i32 %a, i32 %b) {
%cmp1 = icmp eq i32 %a, %b
br i1 %cmp1, label %taken, label %untaken
More information about the llvm-commits
mailing list