diff options
| author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-15 01:34:59 +0000 |
|---|---|---|
| committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-11-15 01:34:59 +0000 |
| commit | b03bd4d96bfa6fe58afd7e4c238fad354b701ecd (patch) | |
| tree | 187df4c6d831f6521192e03afdc4a16fc259c50e /llvm/lib/Analysis/ConstantFolding.cpp | |
| parent | 08c0b1a1bd345aadf2755358e4463b2c1047c616 (diff) | |
| download | bcm5719-llvm-b03bd4d96bfa6fe58afd7e4c238fad354b701ecd.tar.gz bcm5719-llvm-b03bd4d96bfa6fe58afd7e4c238fad354b701ecd.zip | |
Add addrspacecast instruction.
Patch by Michele Scandale!
llvm-svn: 194760
Diffstat (limited to 'llvm/lib/Analysis/ConstantFolding.cpp')
| -rw-r--r-- | llvm/lib/Analysis/ConstantFolding.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp index e093631d8f1..3d32232dacf 100644 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -663,7 +663,7 @@ static Constant* StripPtrCastKeepAS(Constant* Ptr) { if (NewPtrTy->getAddressSpace() != OldPtrTy->getAddressSpace()) { NewPtrTy = NewPtrTy->getElementType()->getPointerTo( OldPtrTy->getAddressSpace()); - Ptr = ConstantExpr::getBitCast(Ptr, NewPtrTy); + Ptr = ConstantExpr::getPointerCast(Ptr, NewPtrTy); } return Ptr; } @@ -995,8 +995,9 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, 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. + // the int size is >= the ptr size and the address spaces are the same. + // 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) { Constant *SrcPtr = CE->getOperand(0); @@ -1004,8 +1005,8 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, unsigned MidIntSize = CE->getType()->getScalarSizeInBits(); if (MidIntSize >= SrcPtrSize) { - unsigned DestPtrSize = TD->getPointerTypeSizeInBits(DestTy); - if (SrcPtrSize == DestPtrSize) + unsigned SrcAS = SrcPtr->getType()->getPointerAddressSpace(); + if (SrcAS == DestTy->getPointerAddressSpace()) return FoldBitCast(CE->getOperand(0), DestTy, *TD); } } @@ -1021,6 +1022,7 @@ Constant *llvm::ConstantFoldInstOperands(unsigned Opcode, Type *DestTy, case Instruction::SIToFP: case Instruction::FPToUI: case Instruction::FPToSI: + case Instruction::AddrSpaceCast: return ConstantExpr::getCast(Opcode, Ops[0], DestTy); case Instruction::BitCast: if (TD) |

