Index: include/polly/Support/ScopHelper.h =================================================================== --- include/polly/Support/ScopHelper.h +++ include/polly/Support/ScopHelper.h @@ -394,7 +394,8 @@ /// /// @return True if @p LInst can be hoisted in @p R. bool isHoistableLoad(llvm::LoadInst *LInst, llvm::Region &R, llvm::LoopInfo &LI, - llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT); + llvm::ScalarEvolution &SE, const llvm::DominatorTree &DT, + InvariantLoadsSetTy &RequiredILS); /// Return true iff @p V is an intrinsic that we ignore during code /// generation. Index: lib/Analysis/ScopDetection.cpp =================================================================== --- lib/Analysis/ScopDetection.cpp +++ lib/Analysis/ScopDetection.cpp @@ -484,7 +484,7 @@ if (Context.RequiredILS.count(Load)) continue; - if (!isHoistableLoad(Load, CurRegion, LI, SE, DT)) + if (!isHoistableLoad(Load, CurRegion, LI, SE, DT, RequiredILS)) return false; for (auto NonAffineRegion : Context.NonAffineSubRegionSet) { @@ -938,7 +938,7 @@ auto *V = dyn_cast(Unknown->getValue()); if (auto *Load = dyn_cast(V)) { if (Context.CurRegion.contains(Load) && - isHoistableLoad(Load, CurRegion, LI, SE, DT)) + isHoistableLoad(Load, CurRegion, LI, SE, DT, Context.RequiredILS)) Context.RequiredILS.insert(Load); continue; } @@ -1152,7 +1152,8 @@ Instruction *Inst = dyn_cast(Ptr.getValue()); if (Inst && Context.CurRegion.contains(Inst)) { auto *Load = dyn_cast(Inst); - if (Load && isHoistableLoad(Load, Context.CurRegion, LI, SE, DT)) { + if (Load && isHoistableLoad(Load, Context.CurRegion, LI, SE, DT, + Context.RequiredILS)) { Context.RequiredILS.insert(Load); continue; } Index: lib/Support/ScopHelper.cpp =================================================================== --- lib/Support/ScopHelper.cpp +++ lib/Support/ScopHelper.cpp @@ -442,9 +442,22 @@ } bool polly::isHoistableLoad(LoadInst *LInst, Region &R, LoopInfo &LI, - ScalarEvolution &SE, const DominatorTree &DT) { + ScalarEvolution &SE, const DominatorTree &DT, + InvariantLoadsSetTy &RequiredILS) { Loop *L = LI.getLoopFor(LInst->getParent()); auto *Ptr = LInst->getPointerOperand(); + + auto *ptr_operand = dyn_cast(Ptr); + if (ptr_operand && isa(ptr_operand)) { + auto *prev_inst = dyn_cast(ptr_operand->getOperand(0)); + if (prev_inst && isa(prev_inst)) { + auto *lt = dyn_cast(prev_inst); + for (int i = 0; i < RequiredILS.size(); i++) + if (RequiredILS[i] == lt) + return true; + } + } + const SCEV *PtrSCEV = SE.getSCEVAtScope(Ptr, L); while (L && R.contains(L)) { if (!SE.isLoopInvariant(PtrSCEV, L))