[llvm] r252332 - [ValueTracking] De-pessimize isImpliedCondition around unsigned compares
Sanjoy Das via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 6 11:01:03 PST 2015
Author: sanjoy
Date: Fri Nov 6 13:01:03 2015
New Revision: 252332
URL: http://llvm.org/viewvc/llvm-project?rev=252332&view=rev
Log:
[ValueTracking] De-pessimize isImpliedCondition around unsigned compares
Summary:
Currently `isImpliedCondition` will optimize "I +_nuw C < L ==> I < L"
only if C is positive. This is an unnecessary restriction -- the
implication holds even if `C` is negative.
Reviewers: reames, majnemer
Subscribers: llvm-commits
Differential Revision: http://reviews.llvm.org/D14369
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstSimplify/implies.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=252332&r1=252331&r2=252332&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Fri Nov 6 13:01:03 2015
@@ -4109,12 +4109,12 @@ static bool isTruePredicate(CmpInst::Pre
case CmpInst::ICMP_ULE: {
ConstantInt *CI;
- // LHS u< LHS +_{nuw} C if C > 0
- // LHS u<= LHS +_{nuw} C if C >= 0
+ // LHS u< LHS +_{nuw} C if C != 0
+ // LHS u<= LHS +_{nuw} C
if (match(RHS, m_NUWAdd(m_Specific(LHS), m_ConstantInt(CI)))) {
if (Pred == CmpInst::ICMP_ULT)
- return CI->getValue().isStrictlyPositive();
- return !CI->isNegative();
+ return !CI->isZero();
+ return true;
}
return false;
}
Modified: llvm/trunk/test/Transforms/InstSimplify/implies.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/implies.ll?rev=252332&r1=252331&r2=252332&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/implies.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/implies.ll Fri Nov 6 13:01:03 2015
@@ -65,7 +65,7 @@ define i1 @test3(i32 %length.i, i32 %i)
ret i1 %res
}
-; i +_{nuw} C_{>0} <u L ==> i <u L
+; i +_{nuw} C <u L ==> i <u L
define i1 @test4(i32 %length.i, i32 %i) {
; CHECK-LABEL: @test4
; CHECK: ret i1 true
@@ -114,6 +114,17 @@ define i1 @test8(i32 %length.i, i32 %i)
%var30 = icmp ult i32 %iplus1, %length.i
%res = icmp ule i1 %var30, %var29
ret i1 %res
+}
+
+; i +_{nuw} C <s L ==> i < L, even if C is negative
+define i1 @test9(i32 %length.i, i32 %i) {
+; CHECK-LABEL: @test9(
+; CHECK: ret i1 true
+ %iplus1 = add nuw i32 %i, -100
+ %var29 = icmp ult i32 %i, %length.i
+ %var30 = icmp ult i32 %iplus1, %length.i
+ %res = icmp ule i1 %var30, %var29
+ ret i1 %res
}
; X >=(s) Y == X ==> Y (i1 1 becomes -1 for reasoning)
More information about the llvm-commits
mailing list