InstCombine: factor code better.
authorBenjamin Kramer <benny.kra@googlemail.com>
Mon, 11 Jun 2012 08:01:25 +0000 (08:01 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Mon, 11 Jun 2012 08:01:25 +0000 (08:01 +0000)
No functionality change.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158301 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp

index 3fa0aba012945162701119c9bceca488aed1c0a1..7076d88554d90933bc1c114552831b5683c01f3d 100644 (file)
@@ -2581,21 +2581,14 @@ Instruction *InstCombiner::visitICmpInst(ICmpInst &I) {
     }
 
     // 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())