1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

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.

llvm-svn: 54752
This commit is contained in:
Duncan Sands 2008-08-13 20:20:35 +00:00
parent 4b1b033f89
commit 26e54f3570
2 changed files with 17 additions and 0 deletions

View File

@ -378,6 +378,19 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, const Type *DestTy,
} }
return ConstantExpr::getCast(Opcode, Ops[0], DestTy); return ConstantExpr::getCast(Opcode, Ops[0], DestTy);
case Instruction::IntToPtr: 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::Trunc:
case Instruction::ZExt: case Instruction::ZExt:
case Instruction::SExt: case Instruction::SExt:

View File

@ -0,0 +1,4 @@
-- RUN: %llvmgcc -S -emit-llvm %s -o - | not grep ptrtoint
package Constant_Fold is
Error : exception;
end;