summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-23 06:50:36 +0000
committerChris Lattner <sabre@nondot.org>2009-10-23 06:50:36 +0000
commit59f94c01dd726f320382daded7f4e3bb09e81690 (patch)
tree1278459397813ef1266a93d6a095b70a9d2da5ec /llvm/lib/Analysis/ConstantFolding.cpp
parented00b80bf8409e200f5a713fca6cc5859c6140f6 (diff)
downloadbcm5719-llvm-59f94c01dd726f320382daded7f4e3bb09e81690.tar.gz
bcm5719-llvm-59f94c01dd726f320382daded7f4e3bb09e81690.zip
enhance FoldReinterpretLoadFromConstPtr to handle loads of up to 32
bytes (i256). llvm-svn: 84941
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r--llvm/lib/Analysis/ConstantFolding.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 3294865a10a..30305049614 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -232,7 +232,7 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
}
unsigned BytesLoaded = (IntType->getBitWidth() + 7) / 8;
- if (BytesLoaded > 8 || BytesLoaded == 0) return 0;
+ if (BytesLoaded > 32 || BytesLoaded == 0) return 0;
GlobalValue *GVal;
int64_t Offset;
@@ -253,16 +253,18 @@ static Constant *FoldReinterpretLoadFromConstPtr(Constant *C,
if (uint64_t(Offset) >= TD.getTypeAllocSize(GV->getInitializer()->getType()))
return UndefValue::get(IntType);
- unsigned char RawBytes[8] = {0};
+ unsigned char RawBytes[32] = {0};
if (!ReadDataFromGlobal(GV->getInitializer(), Offset, RawBytes,
BytesLoaded, TD))
return 0;
- uint64_t ResultVal = 0;
- for (unsigned i = 0; i != BytesLoaded; ++i)
- ResultVal |= (uint64_t)RawBytes[i] << (i * 8);
+ APInt ResultVal(IntType->getBitWidth(), 0);
+ for (unsigned i = 0; i != BytesLoaded; ++i) {
+ ResultVal <<= 8;
+ ResultVal |= APInt(IntType->getBitWidth(), RawBytes[BytesLoaded-1-i]);
+ }
- return ConstantInt::get(IntType, ResultVal);
+ return ConstantInt::get(IntType->getContext(), ResultVal);
}
/// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
OpenPOWER on IntegriCloud