diff options
Diffstat (limited to 'llvm')
| -rw-r--r-- | llvm/lib/Analysis/ScalarEvolutionExpander.cpp | 5 | ||||
| -rw-r--r-- | llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp | 1 | ||||
| -rw-r--r-- | llvm/lib/Target/R600/AMDGPUPromoteAlloca.cpp | 6 | ||||
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp | 8 | ||||
| -rw-r--r-- | llvm/unittests/Linker/LinkModulesTest.cpp | 5 |
5 files changed, 15 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp index 86fc0a411a5..a73ec9ecc02 100644 --- a/llvm/lib/Analysis/ScalarEvolutionExpander.cpp +++ b/llvm/lib/Analysis/ScalarEvolutionExpander.cpp @@ -374,7 +374,8 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, PointerType *PTy, Type *Ty, Value *V) { - Type *ElTy = PTy->getElementType(); + Type *OriginalElTy = PTy->getElementType(); + Type *ElTy = OriginalElTy; SmallVector<Value *, 4> GepIndices; SmallVector<const SCEV *, 8> Ops(op_begin, op_end); bool AnyNonZeroIndices = false; @@ -558,7 +559,7 @@ Value *SCEVExpander::expandAddToGEP(const SCEV *const *op_begin, Value *Casted = V; if (V->getType() != PTy) Casted = InsertNoopCastOfTo(Casted, PTy); - Value *GEP = Builder.CreateGEP(Casted, + Value *GEP = Builder.CreateGEP(OriginalElTy, Casted, GepIndices, "scevgep"); Ops.push_back(SE.getUnknown(GEP)); diff --git a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp index 86d134baf5f..850c020edf3 100644 --- a/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXGenericToNVVM.cpp @@ -343,6 +343,7 @@ Value *GenericToNVVM::remapConstantExpr(Module *M, Function *F, ConstantExpr *C, // GetElementPtrConstantExpr return cast<GEPOperator>(C)->isInBounds() ? Builder.CreateGEP( + cast<GEPOperator>(C)->getSourceElementType(), NewOperands[0], makeArrayRef(&NewOperands[1], NumOperands - 1)) : Builder.CreateInBoundsGEP( diff --git a/llvm/lib/Target/R600/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/R600/AMDGPUPromoteAlloca.cpp index ca9ea51e0fb..175dcd89e52 100644 --- a/llvm/lib/Target/R600/AMDGPUPromoteAlloca.cpp +++ b/llvm/lib/Target/R600/AMDGPUPromoteAlloca.cpp @@ -295,9 +295,9 @@ void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) { DEBUG(dbgs() << "Promoting alloca to local memory\n"); LocalMemAvailable -= AllocaSize; + Type *GVTy = ArrayType::get(I.getAllocatedType(), 256); GlobalVariable *GV = new GlobalVariable( - *Mod, ArrayType::get(I.getAllocatedType(), 256), false, - GlobalValue::ExternalLinkage, 0, I.getName(), 0, + *Mod, GVTy, false, GlobalValue::ExternalLinkage, 0, I.getName(), 0, GlobalVariable::NotThreadLocal, AMDGPUAS::LOCAL_ADDRESS); FunctionType *FTy = FunctionType::get( @@ -333,7 +333,7 @@ void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) { Indices.push_back(Constant::getNullValue(Type::getInt32Ty(Mod->getContext()))); Indices.push_back(TID); - Value *Offset = Builder.CreateGEP(GV, Indices); + Value *Offset = Builder.CreateGEP(GVTy, GV, Indices); I.mutateType(Offset->getType()); I.replaceAllUsesWith(Offset); I.eraseFromParent(); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp index 0625d8deca0..fe544c2f065 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1473,9 +1473,11 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) { // If we were able to index down into an element, create the GEP // and bitcast the result. This eliminates one bitcast, potentially // two. - Value *NGEP = cast<GEPOperator>(GEP)->isInBounds() ? - Builder->CreateInBoundsGEP(OrigBase, NewIndices) : - Builder->CreateGEP(OrigBase, NewIndices); + Value *NGEP = cast<GEPOperator>(GEP)->isInBounds() + ? Builder->CreateInBoundsGEP(OrigBase, NewIndices) + : Builder->CreateGEP( + OrigBase->getType()->getPointerElementType(), + OrigBase, NewIndices); NGEP->takeName(GEP); if (isa<BitCastInst>(CI)) diff --git a/llvm/unittests/Linker/LinkModulesTest.cpp b/llvm/unittests/Linker/LinkModulesTest.cpp index 91f97d76c9e..fbd03639fa7 100644 --- a/llvm/unittests/Linker/LinkModulesTest.cpp +++ b/llvm/unittests/Linker/LinkModulesTest.cpp @@ -35,7 +35,7 @@ protected: SwitchCase2BB = BasicBlock::Create(Ctx, "switch.case.2", F); ExitBB = BasicBlock::Create(Ctx, "exit", F); - ArrayType *AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3); + AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3); GV = new GlobalVariable(*M.get(), AT, false /*=isConstant*/, GlobalValue::InternalLinkage, nullptr,"switch.bas"); @@ -61,6 +61,7 @@ protected: LLVMContext Ctx; std::unique_ptr<Module> M; Function *F; + ArrayType *AT; GlobalVariable *GV; BasicBlock *EntryBB; BasicBlock *SwitchCase1BB; @@ -75,7 +76,7 @@ TEST_F(LinkModuleTest, BlockAddress) { GEPIndices.push_back(ConstantInt::get(Type::getInt32Ty(Ctx), 0)); GEPIndices.push_back(F->arg_begin()); - Value *GEP = Builder.CreateGEP(GV, GEPIndices, "switch.gep"); + Value *GEP = Builder.CreateGEP(AT, GV, GEPIndices, "switch.gep"); Value *Load = Builder.CreateLoad(GEP, "switch.load"); Builder.CreateRet(Load); |

