[llvm-commits] CVS: llvm/lib/Transforms/Scalar/InstructionCombining.cpp

Chris Lattner lattner at cs.uiuc.edu
Thu Sep 23 14:46:51 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.246 -> 1.247
---
Log message:

Implement Transforms/InstCombine/and.ll:test18, a case that occurs 20 times
in perlbmk


---
Diffs of the changes:  (+45 -0)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.246 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.247
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.246	Thu Sep 23 10:46:00 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Thu Sep 23 16:46:38 2004
@@ -897,6 +897,32 @@
   return V && (V & (V-1)) == 0;
 }
 
+#if 0   // Currently unused
+// isLowOnes - Return true if the constant is of the form 0+1+.
+static bool isLowOnes(const ConstantInt *CI) {
+  uint64_t V = CI->getRawValue();
+
+  // There won't be bits set in parts that the type doesn't contain.
+  V &= ConstantInt::getAllOnesValue(CI->getType())->getRawValue();
+
+  uint64_t U = V+1;  // If it is low ones, this should be a power of two.
+  return U && V && (U & V) == 0;
+}
+#endif
+
+// isHighOnes - Return true if the constant is of the form 1+0+.
+// This is the same as lowones(~X).
+static bool isHighOnes(const ConstantInt *CI) {
+  uint64_t V = ~CI->getRawValue();
+
+  // There won't be bits set in parts that the type doesn't contain.
+  V &= ConstantInt::getAllOnesValue(CI->getType())->getRawValue();
+
+  uint64_t U = V+1;  // If it is low ones, this should be a power of two.
+  return U && V && (U & V) == 0;
+}
+
+
 /// getSetCondCode - Encode a setcc opcode into a three bit mask.  These bits
 /// are carefully arranged to allow folding of expressions such as:
 ///
@@ -1620,6 +1646,25 @@
                                          Instruction::SetGE, X,
                                      Constant::getNullValue(X->getType()));
             }
+            
+            // ((X & ~7) == 0) --> X < 7
+            if (CI->isNullValue() && isHighOnes(BOC)) {
+              Value *X = BO->getOperand(0);
+              Constant *NotX = ConstantExpr::getNot(BOC);
+
+              // If 'X' is signed, insert a cast now.
+              if (!NotX->getType()->isSigned()) {
+                const Type *DestTy = NotX->getType()->getUnsignedVersion();
+                CastInst *NewCI = new CastInst(X, DestTy, X->getName()+".uns");
+                InsertNewInstBefore(NewCI, I);
+                X = NewCI;
+                NotX = ConstantExpr::getCast(NotX, DestTy);
+              }
+
+              return new SetCondInst(isSetNE ? Instruction::SetGE :
+                                     Instruction::SetLT, X, NotX);
+            }
+
           }
         default: break;
         }






More information about the llvm-commits mailing list