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
This commit is contained in:
Anders Carlsson
2011-02-06 20:11:56 +00:00
parent dd70cd8933
commit 6475d9434f
2 changed files with 28 additions and 0 deletions
+11
View File
@@ -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;
}