summaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2013-10-03 18:15:57 +0000
committerMatt Arsenault <Matthew.Arsenault@amd.com>2013-10-03 18:15:57 +0000
commit1df59ef1aa271a4e33cf8973e14bcaf55c585231 (patch)
tree64b86c57b32aa8d267f5eff9b1cb54305d562132 /lib/Transforms
parentd6370ad87d21402c0e2b1fef12d4a77fd1ead306 (diff)
downloadllvm-1df59ef1aa271a4e33cf8973e14bcaf55c585231.tar.gz
llvm-1df59ef1aa271a4e33cf8973e14bcaf55c585231.tar.bz2
llvm-1df59ef1aa271a4e33cf8973e14bcaf55c585231.tar.xz
Make gep i8* X, -(ptrtoint Y) transform work with address spaces
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191920 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/InstCombine/InstructionCombining.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
index fcb26ab82a..27f1a3eb69 100644
--- a/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1186,14 +1186,16 @@ Instruction *InstCombiner::visitGetElementPtrInst(GetElementPtrInst &GEP) {
// The GEP pattern is emitted by the SCEV expander for certain kinds of
// pointer arithmetic.
if (TD && GEP.getNumIndices() == 1 &&
- match(GEP.getOperand(1), m_Neg(m_PtrToInt(m_Value()))) &&
- GEP.getType() == Builder->getInt8PtrTy() &&
- GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
- TD->getPointerSizeInBits(GEP.getPointerAddressSpace())) {
- Operator *Index = cast<Operator>(GEP.getOperand(1));
- Value *PtrToInt = Builder->CreatePtrToInt(PtrOp, Index->getType());
- Value *NewSub = Builder->CreateSub(PtrToInt, Index->getOperand(1));
- return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
+ match(GEP.getOperand(1), m_Neg(m_PtrToInt(m_Value())))) {
+ unsigned AS = GEP.getPointerAddressSpace();
+ if (GEP.getType() == Builder->getInt8PtrTy(AS) &&
+ GEP.getOperand(1)->getType()->getScalarSizeInBits() ==
+ TD->getPointerSizeInBits(AS)) {
+ Operator *Index = cast<Operator>(GEP.getOperand(1));
+ Value *PtrToInt = Builder->CreatePtrToInt(PtrOp, Index->getType());
+ Value *NewSub = Builder->CreateSub(PtrToInt, Index->getOperand(1));
+ return CastInst::Create(Instruction::IntToPtr, NewSub, GEP.getType());
+ }
}
// Handle gep(bitcast x) and gep(gep x, 0, 0, 0).