[llvm-commits] CVS: llvm/lib/VMCore/ConstantFolding.cpp

Chris Lattner sabre at nondot.org
Wed Jan 3 17:56:54 PST 2007



Changes in directory llvm/lib/VMCore:

ConstantFolding.cpp updated: 1.123 -> 1.124
---
Log message:

fix some bugs handling vectors, avoid host-specific handling of undefined shift results.


---
Diffs of the changes:  (+15 -5)

 ConstantFolding.cpp |   20 +++++++++++++++-----
 1 files changed, 15 insertions(+), 5 deletions(-)


Index: llvm/lib/VMCore/ConstantFolding.cpp
diff -u llvm/lib/VMCore/ConstantFolding.cpp:1.123 llvm/lib/VMCore/ConstantFolding.cpp:1.124
--- llvm/lib/VMCore/ConstantFolding.cpp:1.123	Sun Dec 31 15:43:30 2006
+++ llvm/lib/VMCore/ConstantFolding.cpp	Wed Jan  3 19:56:39 2007
@@ -444,6 +444,8 @@
         return Constant::getNullValue(C1->getType());
       return const_cast<Constant*>(C2);            // X / undef -> undef
     case Instruction::Or:                          // X | undef -> -1
+      if (const PackedType *PTy = dyn_cast<PackedType>(C1->getType()))
+        return ConstantPacked::getAllOnesValue(PTy);
       return ConstantInt::getAllOnesValue(C1->getType());
     case Instruction::LShr:
       if (isa<UndefValue>(C2) && isa<UndefValue>(C1))
@@ -496,8 +498,9 @@
             return Constant::getNullValue(CI->getType());         // X % 1 == 0
         break;
       case Instruction::And:
-        if (cast<ConstantIntegral>(C2)->isAllOnesValue())
-          return const_cast<Constant*>(C1);                       // X & -1 == X
+        if (const ConstantInt *CI = dyn_cast<ConstantInt>(C2))
+          if (CI->isAllOnesValue())
+            return const_cast<Constant*>(C1);                     // X & -1 == X
         if (C2->isNullValue()) return const_cast<Constant*>(C2);  // X & 0 == 0
         if (CE1->isCast() && isa<GlobalValue>(CE1->getOperand(0))) {
           GlobalValue *CPR = cast<GlobalValue>(CE1->getOperand(0));
@@ -511,8 +514,9 @@
         break;
       case Instruction::Or:
         if (C2->isNullValue()) return const_cast<Constant*>(C1);  // X | 0 == X
-        if (cast<ConstantIntegral>(C2)->isAllOnesValue())
-          return const_cast<Constant*>(C2);  // X | -1 == -1
+        if (const ConstantInt *CI = dyn_cast<ConstantInt>(C2))
+          if (CI->isAllOnesValue())
+            return const_cast<Constant*>(C2);  // X | -1 == -1
         break;
       case Instruction::Xor:
         if (C2->isNullValue()) return const_cast<Constant*>(C1);  // X ^ 0 == X
@@ -547,7 +551,7 @@
   }
 
   // At this point we know neither constant is an UndefValue nor a ConstantExpr
-  // so look at directly computing the 
+  // so look at directly computing the value.
   if (const ConstantBool *CB1 = dyn_cast<ConstantBool>(C1)) {
     if (const ConstantBool *CB2 = dyn_cast<ConstantBool>(C2)) {
       switch (Opcode) {
@@ -606,10 +610,16 @@
       case Instruction::Xor:
         return ConstantInt::get(C1->getType(), C1Val ^ C2Val);
       case Instruction::Shl:
+        if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
+          C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
         return ConstantInt::get(C1->getType(), C1Val << C2Val);
       case Instruction::LShr:
+        if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
+          C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
         return ConstantInt::get(C1->getType(), C1Val >> C2Val);
       case Instruction::AShr:
+        if (C2Val >= CI1->getType()->getPrimitiveSizeInBits())
+          C2Val = CI1->getType()->getPrimitiveSizeInBits() - 1;
         return ConstantInt::get(C1->getType(), 
                                 CI1->getSExtValue() >> C2Val);
       }






More information about the llvm-commits mailing list