[llvm] r245638 - [InstSimplify] add nuw %x, C2 must be at least C2

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 16:01:41 PDT 2015


Author: majnemer
Date: Thu Aug 20 18:01:41 2015
New Revision: 245638

URL: http://llvm.org/viewvc/llvm-project?rev=245638&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Analysis/InstructionSimplify.cpp
    llvm/trunk/test/Transforms/InstSimplify/compare.ll

Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=245638&r1=245637&r2=245638&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Thu Aug 20 18:01:41 2015
@@ -2360,6 +2360,9 @@ static Value *SimplifyICmpInst(unsigned
     } 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);

Modified: llvm/trunk/test/Transforms/InstSimplify/compare.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/compare.ll?rev=245638&r1=245637&r2=245638&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/compare.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/compare.ll Thu Aug 20 18:01:41 2015
@@ -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
+}




More information about the llvm-commits mailing list