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

Chris Lattner lattner at cs.uiuc.edu
Mon Sep 27 12:29:29 PDT 2004



Changes in directory llvm/lib/Transforms/Scalar:

InstructionCombining.cpp updated: 1.250 -> 1.251
---
Log message:

Fix two bugs: one where a condition was mistakenly swapped, and another
where we folded (X & 254) -> X < 1 instead of X < 2.  These problems were
latent problems exposed by the latest patch.


---
Diffs of the changes:  (+11 -14)

Index: llvm/lib/Transforms/Scalar/InstructionCombining.cpp
diff -u llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.250 llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.251
--- llvm/lib/Transforms/Scalar/InstructionCombining.cpp:1.250	Mon Sep 27 11:18:50 2004
+++ llvm/lib/Transforms/Scalar/InstructionCombining.cpp	Mon Sep 27 14:29:18 2004
@@ -1522,7 +1522,7 @@
               unsigned ShiftOp = Shift->getOpcode() == Instruction::Shl
                 ? Instruction::Shr : Instruction::Shl;
               Constant *NewCst = ConstantExpr::get(ShiftOp, CI, ShAmt);
-              
+
               // Check to see if we are shifting out any of the bits being
               // compared.
               if (ConstantExpr::get(Shift->getOpcode(), NewCst, ShAmt) != CI){
@@ -1545,7 +1545,8 @@
           }
         }
         break;
-      case Instruction::Shr:         // shr: (setcc (shr X, ShAmt), CI)
+
+      case Instruction::Shr:         // (setcc (shr X, ShAmt), CI)
         if (ConstantUInt *ShAmt = dyn_cast<ConstantUInt>(LHSI->getOperand(1))) {
           unsigned ShAmtVal = ShAmt->getValue();
           
@@ -1721,31 +1722,27 @@
               // If 'X' is not signed, insert a cast now...
               if (!BOC->getType()->isSigned()) {
                 const Type *DestTy = BOC->getType()->getSignedVersion();
-                CastInst *NewCI = new CastInst(X,DestTy,X->getName()+".signed");
-                InsertNewInstBefore(NewCI, I);
-                X = NewCI;
+                X = InsertCastBefore(X, DestTy, I);
               }
               return new SetCondInst(isSetNE ? Instruction::SetLT :
                                          Instruction::SetGE, X,
                                      Constant::getNullValue(X->getType()));
             }
             
-            // ((X & ~7) == 0) --> X < 7
+            // ((X & ~7) == 0) --> X < 8
             if (CI->isNullValue() && isHighOnes(BOC)) {
               Value *X = BO->getOperand(0);
-              Constant *NotX = ConstantExpr::getNot(BOC);
+              Constant *NegX = ConstantExpr::getNeg(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);
+              if (NegX->getType()->isSigned()) {
+                const Type *DestTy = NegX->getType()->getUnsignedVersion();
+                X = InsertCastBefore(X, DestTy, I);
+                NegX = ConstantExpr::getCast(NegX, DestTy);
               }
 
               return new SetCondInst(isSetNE ? Instruction::SetGE :
-                                     Instruction::SetLT, X, NotX);
+                                     Instruction::SetLT, X, NegX);
             }
 
           }






More information about the llvm-commits mailing list