diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-10-03 18:15:57 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2013-10-03 18:15:57 +0000 |
commit | bfa37e546da18524c8038ecaf6c1ca29d8c7bd85 (patch) | |
tree | 686a1bbf73971a565345a47232838ad70c2a459d /llvm/lib/Transforms | |
parent | 245b3caa57f405fb4a901f754955de49eceaaffd (diff) | |
download | bcm5719-llvm-bfa37e546da18524c8038ecaf6c1ca29d8c7bd85.tar.gz bcm5719-llvm-bfa37e546da18524c8038ecaf6c1ca29d8c7bd85.zip |
Make gep i8* X, -(ptrtoint Y) transform work with address spaces
llvm-svn: 191920
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index fcb26ab82af..27f1a3eb699 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/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). |