From bdab9f9f82592215428e7991cc8713756ee39fd4 Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Thu, 20 Aug 2015 23:01:41 +0000 Subject: [PATCH] [InstSimplify] add nuw %x, C2 must be at least C2 Use the fact that add nuw always creates a larger bit pattern when trying to simplify comparisons. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245638 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/InstructionSimplify.cpp | 3 +++ test/Transforms/InstSimplify/compare.ll | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/Analysis/InstructionSimplify.cpp b/lib/Analysis/InstructionSimplify.cpp index ae9d6664fb8..b6d4c02a9eb 100644 --- a/lib/Analysis/InstructionSimplify.cpp +++ b/lib/Analysis/InstructionSimplify.cpp @@ -2360,6 +2360,9 @@ static Value *SimplifyICmpInst(unsigned Predicate, Value *LHS, Value *RHS, } else if (match(LHS, m_And(m_Value(), m_ConstantInt(CI2)))) { // 'and x, CI2' produces [0, CI2]. Upper = CI2->getValue() + 1; + } else if (match(LHS, m_NUWAdd(m_Value(), m_ConstantInt(CI2)))) { + // 'add nuw x, CI2' produces [CI2, UINT_MAX]. + Lower = CI2->getValue(); } if (Lower != Upper) { ConstantRange LHS_CR = ConstantRange(Lower, Upper); diff --git a/test/Transforms/InstSimplify/compare.ll b/test/Transforms/InstSimplify/compare.ll index 07c90d8f1eb..6e66fbfede9 100644 --- a/test/Transforms/InstSimplify/compare.ll +++ b/test/Transforms/InstSimplify/compare.ll @@ -1164,3 +1164,11 @@ define i1 @tautological8(i32 %A, i32 %B) { ; CHECK-LABEL: @tautological8( ; CHECK: ret i1 false } + +define i1 @tautological9(i32 %x) { + %add = add nuw i32 %x, 13 + %cmp = icmp ne i32 %add, 12 + ret i1 %cmp +; CHECK-LABEL: @tautological9( +; CHECK: ret i1 true +} -- 2.34.1