diff options
author | Duncan Sands <baldrick@free.fr> | 2008-08-13 20:20:35 +0000 |
---|---|---|
committer | Duncan Sands <baldrick@free.fr> | 2008-08-13 20:20:35 +0000 |
commit | 81b06be055e74a3c23a1c8f17ead97f9f76335ee (patch) | |
tree | e196776a9c44683654f382a48dc44d5a61854e1d /lib/Analysis/ConstantFolding.cpp | |
parent | b0cf29c5cfff797284b3660dc233e135feb65d9a (diff) | |
download | external_llvm-81b06be055e74a3c23a1c8f17ead97f9f76335ee.zip external_llvm-81b06be055e74a3c23a1c8f17ead97f9f76335ee.tar.gz external_llvm-81b06be055e74a3c23a1c8f17ead97f9f76335ee.tar.bz2 |
Teach constant folding that an inttoptr of a
ptrtoint can be turned into a bitcast if the
integer is at least as wide as a pointer.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54752 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ConstantFolding.cpp')
-rw-r--r-- | lib/Analysis/ConstantFolding.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp index 1a0e4b4..d3d0eb6 100644 --- a/lib/Analysis/ConstantFolding.cpp +++ b/lib/Analysis/ConstantFolding.cpp @@ -378,6 +378,19 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy, } return ConstantExpr::getCast(Opcode, Ops[0], DestTy); case Instruction::IntToPtr: + // If the input is a ptrtoint, turn the pair into a ptr to ptr bitcast if + // the int size is >= the ptr size. This requires knowing the width of a + // pointer, so it can't be done in ConstantExpr::getCast. + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ops[0])) { + if (TD && CE->getOpcode() == Instruction::PtrToInt && + TD->getPointerSizeInBits() <= + CE->getType()->getPrimitiveSizeInBits()) { + Constant *Input = CE->getOperand(0); + Constant *C = FoldBitCast(Input, DestTy, *TD); + return C ? C : ConstantExpr::getBitCast(Input, DestTy); + } + } + return ConstantExpr::getCast(Opcode, Ops[0], DestTy); case Instruction::Trunc: case Instruction::ZExt: case Instruction::SExt: |