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

Chris Lattner lattner at cs.uiuc.edu
Sun Feb 12 00:07:49 PST 2006



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.431 -> 1.432
---
Log message:

remove some more dead special case code


---
Diffs of the changes:  (+8 -35)

 InstructionCombining.cpp |   43 ++++++++-----------------------------------
 1 files changed, 8 insertions(+), 35 deletions(-)


Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.431 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.432
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.431	Sun Feb 12 02:02:11 2006
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Sun Feb 12 02:07:37 2006
@@ -3940,7 +3940,7 @@
   if (Op1 == Constant::getNullValue(Type::UByteTy) ||
       Op0 == Constant::getNullValue(Op0->getType()))
     return ReplaceInstUsesWith(I, Op0);
-
+  
   if (isa<UndefValue>(Op0)) {            // undef >>s X -> undef
     if (!isLeftShift && I.getType()->isSigned())
       return ReplaceInstUsesWith(I, Op0);
@@ -3989,6 +3989,13 @@
   bool isSignedShift = Op0->getType()->isSigned();
   bool isUnsignedShift = !isSignedShift;
 
+  // See if we can simplify any instructions used by the instruction whose sole 
+  // purpose is to compute bits we don't care about.
+  uint64_t KnownZero, KnownOne;
+  if (SimplifyDemandedBits(&I, I.getType()->getIntegralTypeMask(),
+                           KnownZero, KnownOne))
+    return &I;
+  
   // shl uint X, 32 = 0 and shr ubyte Y, 9 = 0, ... just don't eliminate shr
   // of a signed value.
   //
@@ -4018,40 +4025,6 @@
       return NV;
   
   if (Op0->hasOneUse()) {
-    // If this is a SHL of a sign-extending cast, see if we can turn the input
-    // into a zero extending cast (a simple strength reduction).
-    if (CastInst *CI = dyn_cast<CastInst>(Op0)) {
-      const Type *SrcTy = CI->getOperand(0)->getType();
-      if (isLeftShift && SrcTy->isInteger() && SrcTy->isSigned() &&
-          SrcTy->getPrimitiveSizeInBits() <
-          CI->getType()->getPrimitiveSizeInBits()) {
-        // We can change it to a zero extension if we are shifting out all of
-        // the sign extended bits.  To check this, form a mask of all of the
-        // sign extend bits, then shift them left and see if we have anything
-        // left.
-        Constant *Mask = ConstantIntegral::getAllOnesValue(SrcTy); //     1111
-        Mask = ConstantExpr::getZeroExtend(Mask, CI->getType());   // 00001111
-        Mask = ConstantExpr::getNot(Mask);   // 1's in the sign bits: 11110000
-        if (ConstantExpr::getShl(Mask, Op1)->isNullValue()) {
-          // If the shift is nuking all of the sign bits, change this to a
-          // zero extension cast.  To do this, cast the cast input to
-          // unsigned, then to the requested size.
-          Value *CastOp = CI->getOperand(0);
-          Instruction *NC =
-            new CastInst(CastOp, CastOp->getType()->getUnsignedVersion(),
-                         CI->getName()+".uns");
-          NC = InsertNewInstBefore(NC, I);
-          // Finally, insert a replacement for CI.
-          NC = new CastInst(NC, CI->getType(), CI->getName());
-          CI->setName("");
-          NC = InsertNewInstBefore(NC, I);
-          WorkList.push_back(CI);  // Delete CI later.
-          I.setOperand(0, NC);
-          return &I;               // The SHL operand was modified.
-        }
-      }
-    }
-    
     if (BinaryOperator *Op0BO = dyn_cast<BinaryOperator>(Op0)) {
       // Turn ((X >> C) + Y) << C  ->  (X + (Y << C)) & (~0 << C)
       Value *V1, *V2;






More information about the llvm-commits mailing list