[llvm-commits] [llvm] r54394 - in /llvm/trunk: lib/Transforms/Scalar/InstructionCombining.cpp test/Transforms/InstCombine/2008-07-08-AndICmp.ll

Nick Lewycky nicholas at mxc.ca
Tue Aug 5 21:54:04 PDT 2008


Author: nicholas
Date: Tue Aug  5 23:54:03 2008
New Revision: 54394

URL: http://llvm.org/viewvc/llvm-project?rev=54394&view=rev
Log:
Reinstate this optimization, but without the miscompile. Thanks to Bill for
tracking down that this was breaking llvm-gcc bootstrap on Linux.

Added:
    llvm/trunk/test/Transforms/InstCombine/2008-07-08-AndICmp.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=54394&r1=54393&r2=54394&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Tue Aug  5 23:54:03 2008
@@ -3586,6 +3586,21 @@
     }
   }
   
+  { // (icmp ult A, C) & (icmp ult B, C) --> (icmp ult (A|B), C)
+    // where C is a power of 2
+    Value *A, *B;
+    ConstantInt *C1, *C2;
+    ICmpInst::Predicate LHSCC, RHSCC;
+    if (match(&I, m_And(m_ICmp(LHSCC, m_Value(A), m_ConstantInt(C1)),
+                        m_ICmp(RHSCC, m_Value(B), m_ConstantInt(C2)))))
+      if (C1 == C2 && LHSCC == RHSCC && LHSCC == ICmpInst::ICMP_ULT &&
+          C1->getValue().isPowerOf2()) {
+        Instruction *NewOr = BinaryOperator::CreateOr(A, B);
+        InsertNewInstBefore(NewOr, I);
+        return new ICmpInst(LHSCC, NewOr, C1);
+      }
+  }
+  
   if (ICmpInst *RHS = dyn_cast<ICmpInst>(Op1)) {
     // (icmp1 A, B) & (icmp2 A, B) --> (icmp3 A, B)
     if (Instruction *R = AssociativeOpt(I, FoldICmpLogical(*this, RHS)))

Added: llvm/trunk/test/Transforms/InstCombine/2008-07-08-AndICmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2008-07-08-AndICmp.ll?rev=54394&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2008-07-08-AndICmp.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2008-07-08-AndICmp.ll Tue Aug  5 23:54:03 2008
@@ -0,0 +1,10 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep icmp | count 1
+; PR2330
+
+define i1 @foo(i32 %a, i32 %b) nounwind {
+entry:
+	icmp ult i32 %a, 8		; <i1>:0 [#uses=1]
+	icmp ult i32 %b, 8		; <i1>:1 [#uses=1]
+	and i1 %1, %0		; <i1>:2 [#uses=1]
+	ret i1 %2
+}





More information about the llvm-commits mailing list