[llvm-commits] [llvm] r158301 - /llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp

Benjamin Kramer benny.kra at googlemail.com
Mon Jun 11 01:01:25 PDT 2012


Author: d0k
Date: Mon Jun 11 03:01:25 2012
New Revision: 158301

URL: http://llvm.org/viewvc/llvm-project?rev=158301&view=rev
Log:
InstCombine: factor code better.

No functionality change.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=158301&r1=158300&r2=158301&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Mon Jun 11 03:01:25 2012
@@ -2581,21 +2581,14 @@
     }
 
     // Transform (zext A) == (B & (1<<X)-1) --> A == (trunc B)
+    // and       (B & (1<<X)-1) == (zext A) --> A == (trunc B)
     ConstantInt *Cst1;
-    if (Op0->hasOneUse() &&
-        match(Op0, m_ZExt(m_Value(A))) &&
-        match(Op1, m_And(m_Value(B), m_ConstantInt(Cst1)))) {
-      APInt Pow2 = Cst1->getValue() + 1;
-      if (Pow2.isPowerOf2() && isa<IntegerType>(A->getType()) &&
-          Pow2.logBase2() == cast<IntegerType>(A->getType())->getBitWidth())
-        return new ICmpInst(I.getPredicate(), A,
-                            Builder->CreateTrunc(B, A->getType()));
-    }
-
-    // Transform (B & (1<<X)-1) == (zext A) --> A == (trunc B)
-    if (Op1->hasOneUse() &&
-        match(Op0, m_And(m_Value(B), m_ConstantInt(Cst1))) &&
-        match(Op1, m_ZExt(m_Value(A)))) {
+    if ((Op0->hasOneUse() &&
+         match(Op0, m_ZExt(m_Value(A))) &&
+         match(Op1, m_And(m_Value(B), m_ConstantInt(Cst1)))) ||
+        (Op1->hasOneUse() &&
+         match(Op0, m_And(m_Value(B), m_ConstantInt(Cst1))) &&
+         match(Op1, m_ZExt(m_Value(A))))) {
       APInt Pow2 = Cst1->getValue() + 1;
       if (Pow2.isPowerOf2() && isa<IntegerType>(A->getType()) &&
           Pow2.logBase2() == cast<IntegerType>(A->getType())->getBitWidth())





More information about the llvm-commits mailing list