[llvm-commits] CVS: llvm/lib/Transforms/Utils/Local.cpp

Robert L. Bocchino Jr. bocchino at persephone.cs.uiuc.edu
Thu Jan 19 15:53:54 PST 2006



Changes in directory llvm/lib/Transforms/Utils:

Local.cpp updated: 1.51 -> 1.52
---
Log message:

ConstantFoldLoadThroughGEPConstantExpr wasn't handling pointers to
packed types correctly.



---
Diffs of the changes:  (+22 -9)

 Local.cpp |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)


Index: llvm/lib/Transforms/Utils/Local.cpp
diff -u llvm/lib/Transforms/Utils/Local.cpp:1.51 llvm/lib/Transforms/Utils/Local.cpp:1.52
--- llvm/lib/Transforms/Utils/Local.cpp:1.51	Tue Jan 17 14:07:07 2006
+++ llvm/lib/Transforms/Utils/Local.cpp	Thu Jan 19 17:53:23 2006
@@ -267,16 +267,29 @@
         return 0;
       }
     } else if (ConstantInt *CI = dyn_cast<ConstantInt>(I.getOperand())) {
-      const ArrayType *ATy = cast<ArrayType>(*I);
-      if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0;
-      if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
-        C = CA->getOperand((unsigned)CI->getRawValue());
-      else if (isa<ConstantAggregateZero>(C))
-        C = Constant::getNullValue(ATy->getElementType());
-      else if (isa<UndefValue>(C))
-        C = UndefValue::get(ATy->getElementType());
-      else
+      if (const ArrayType *ATy = dyn_cast<ArrayType>(*I)) {
+        if ((uint64_t)CI->getRawValue() >= ATy->getNumElements()) return 0;
+        if (ConstantArray *CA = dyn_cast<ConstantArray>(C))
+          C = CA->getOperand((unsigned)CI->getRawValue());
+        else if (isa<ConstantAggregateZero>(C))
+          C = Constant::getNullValue(ATy->getElementType());
+        else if (isa<UndefValue>(C))
+          C = UndefValue::get(ATy->getElementType());
+        else
+          return 0;
+      } else if (const PackedType *PTy = dyn_cast<PackedType>(*I)) {
+        if ((uint64_t)CI->getRawValue() >= PTy->getNumElements()) return 0;
+        if (ConstantPacked *CP = dyn_cast<ConstantPacked>(C))
+          C = CP->getOperand((unsigned)CI->getRawValue());
+        else if (isa<ConstantAggregateZero>(C))
+          C = Constant::getNullValue(PTy->getElementType());
+        else if (isa<UndefValue>(C))
+          C = UndefValue::get(PTy->getElementType());
+        else
+          return 0;
+      } else {
         return 0;
+      }
     } else {
       return 0;
     }






More information about the llvm-commits mailing list