diff options
author | Anders Carlsson <andersca@mac.com> | 2011-02-06 20:11:56 +0000 |
---|---|---|
committer | Anders Carlsson <andersca@mac.com> | 2011-02-06 20:11:56 +0000 |
commit | d21b06a0db5f48ec96ad5c6072e4c70ad4b9beca (patch) | |
tree | 5dc5865b4a2ec985ffdae910cc8b1f230cc29cca /llvm/lib/Analysis/ConstantFolding.cpp | |
parent | e866d44417a420a05d3ef9a04b6fd4a21b47a0e6 (diff) | |
download | bcm5719-llvm-d21b06a0db5f48ec96ad5c6072e4c70ad4b9beca.tar.gz bcm5719-llvm-d21b06a0db5f48ec96ad5c6072e4c70ad4b9beca.zip |
When loading from a constant, fold inttoptr if the integer type and the resulting pointer type both have the same size.
llvm-svn: 124987
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index 243611053c2..6c99ad32bbe 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -340,6 +340,17 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset, return true; } + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) { + if (CE->getOpcode() == Instruction::IntToPtr) { + uint64_t PtrSize = TD.getTypeAllocSize(C->getType()); + uint64_t IntSize = TD.getTypeAllocSize(C->getOperand(0)->getType()); + + if (PtrSize == IntSize) + return ReadDataFromGlobal(CE->getOperand(0), ByteOffset, CurPtr, + BytesLeft, TD); + } + } + // Otherwise, unknown initializer type. return false; } |