diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -8024,12 +8024,17 @@ } case CmpInst::ICMP_ULE: { + const Value *V; const APInt *C; // LHS u<= LHS +_{nuw} C for any C if (match(RHS, m_NUWAdd(m_Specific(LHS), m_APInt(C)))) return true; + // RHS >> V u<= RHS for any V + if (match(LHS, m_LShr(m_Specific(RHS), m_Value(V)))) + return true; + // Match A to (X +_{nuw} CA) and B to (X +_{nuw} CB) auto MatchNUWAddsToSameValue = [&](const Value *A, const Value *B, const Value *&X, diff --git a/llvm/test/Transforms/InstSimplify/implies.ll b/llvm/test/Transforms/InstSimplify/implies.ll --- a/llvm/test/Transforms/InstSimplify/implies.ll +++ b/llvm/test/Transforms/InstSimplify/implies.ll @@ -449,9 +449,8 @@ ; CHECK-LABEL: @test_shift( ; CHECK-NEXT: [[LSHR:%.*]] = lshr i64 [[X:%.*]], [[SHIFT:%.*]] ; CHECK-NEXT: [[ICMP1:%.*]] = icmp ugt i64 [[LSHR]], [[Y:%.*]] -; CHECK-NEXT: [[ICMP2:%.*]] = icmp ugt i64 [[X]], [[Y]] ; CHECK-NEXT: call void @llvm.assume(i1 [[ICMP1]]) -; CHECK-NEXT: ret i1 [[ICMP2]] +; CHECK-NEXT: ret i1 true ; %lshr = lshr i64 %x, %shift %icmp1 = icmp ugt i64 %lshr, %y @@ -479,11 +478,7 @@ ; i i >> C i >> V