aboutsummaryrefslogtreecommitdiff
path: root/lib/Analysis/ConstantFolding.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-02-06 20:11:56 +0000
committerAnders Carlsson <andersca@mac.com>2011-02-06 20:11:56 +0000
commit6475d9434ff3e981160f85d3f1aa07c9e0ace6f2 (patch)
treea87806e11021dcbcada1095e936a1fdd9ed39f06 /lib/Analysis/ConstantFolding.cpp
parentdd70cd89330149c117d0660bab3952b73a973363 (diff)
When loading from a constant, fold inttoptr if the integer type and the resulting pointer type both have the same size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124987 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r--lib/Analysis/ConstantFolding.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 243611053c..6c99ad32bb 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/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;
}