diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-04 20:46:52 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-04 20:46:52 +0000 |
commit | a8e894405c445b797963e0b75a0e8f2955fec0b5 (patch) | |
tree | 5d634cb957264ee09545b5b521a2d78aaa49d9a5 /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | 243140f2fde9deb26712087618beb7e989be0d2f (diff) | |
download | bcm5719-llvm-a8e894405c445b797963e0b75a0e8f2955fec0b5.tar.gz bcm5719-llvm-a8e894405c445b797963e0b75a0e8f2955fec0b5.zip |
Fix another constant folding address space place I missed.
This fixes an assertion failure with a different sized address space.
llvm-svn: 194014
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 22f36e56bcf..e093631d8f1 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -224,7 +224,8 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, APInt &Offset, const DataLayout &TD) { // Trivial case, constant is the global. if ((GV = dyn_cast<GlobalValue>(C))) { - Offset.clearAllBits(); + unsigned BitWidth = TD.getPointerTypeSizeInBits(GV->getType()); + Offset = APInt(BitWidth, 0); return true; } @@ -238,16 +239,23 @@ static bool IsConstantOffsetFromGlobal(Constant *C, GlobalValue *&GV, return IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, TD); // i32* getelementptr ([5 x i32]* @a, i32 0, i32 5) - if (GEPOperator *GEP = dyn_cast<GEPOperator>(CE)) { - // If the base isn't a global+constant, we aren't either. - if (!IsConstantOffsetFromGlobal(CE->getOperand(0), GV, Offset, TD)) - return false; + GEPOperator *GEP = dyn_cast<GEPOperator>(CE); + if (!GEP) + return false; - // Otherwise, add any offset that our operands provide. - return GEP->accumulateConstantOffset(TD, Offset); - } + unsigned BitWidth = TD.getPointerTypeSizeInBits(GEP->getType()); + APInt TmpOffset(BitWidth, 0); - return false; + // If the base isn't a global+constant, we aren't either. + if (!IsConstantOffsetFromGlobal(CE->getOperand(0), GV, TmpOffset, TD)) + return false; + + // Otherwise, add any offset that our operands provide. + if (!GEP->accumulateConstantOffset(TD, TmpOffset)) + return false; + + Offset = TmpOffset; + return true; } /// ReadDataFromGlobal - Recursive helper to read bits out of global. C is the @@ -416,7 +424,7 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C, return 0; GlobalValue *GVal; - APInt Offset(TD.getPointerTypeSizeInBits(PTy), 0); + APInt Offset; if (!IsConstantOffsetFromGlobal(C, GVal, Offset, TD)) return 0; @@ -585,8 +593,7 @@ static Constant *SymbolicallyEvaluateBinop(unsigned Opc, Constant *Op0, // constant. This happens frequently when iterating over a global array. if (Opc == Instruction::Sub && DL) { GlobalValue *GV1, *GV2; - unsigned PtrSize = DL->getPointerSizeInBits(); - APInt Offs1(PtrSize, 0), Offs2(PtrSize, 0); + APInt Offs1, Offs2; if (IsConstantOffsetFromGlobal(Op0, GV1, Offs1, *DL)) if (IsConstantOffsetFromGlobal(Op1, GV2, Offs2, *DL) && |