From c01b4d2b28184d0a9efee934c8a5b7aab57984ab Mon Sep 17 00:00:00 2001 From: Sanjoy Das Date: Fri, 6 Nov 2015 19:01:03 +0000 Subject: [PATCH] [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 llvm-svn: 252332 --- llvm/lib/Analysis/ValueTracking.cpp | 8 ++++---- llvm/test/Transforms/InstSimplify/implies.ll | 13 ++++++++++++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 3dc9f3a10370..f4824aebe525 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -4109,12 +4109,12 @@ static bool isTruePredicate(CmpInst::Predicate Pred, Value *LHS, Value *RHS) { 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; } diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll index 8e5bbf2c8970..eb8db4224faf 100644 --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -65,7 +65,7 @@ define i1 @test3(i32 %length.i, i32 %i) { ret i1 %res } -; i +_{nuw} C_{>0} i i 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) define i1 @test_sge(i32 %length.i, i32 %i) { ; CHECK-LABEL: @test_sge