From bd861acf29bb49c6530870de2e05d4828eb1a9a2 Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Tue, 28 Jun 2016 04:02:47 +0000 Subject: [LLE] Don't hoist conditionally executed loads If the load is conditional we can't hoist its 0-iteration instance to the preheader because that would make it unconditional. Thus we would access a memory location that the original loop did not access. llvm-svn: 273991 --- llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'llvm/lib') diff --git a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp index a0c5798df05..1dd60995237 100644 --- a/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp +++ b/llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp @@ -119,6 +119,11 @@ bool doesStoreDominatesAllLatches(BasicBlock *StoreBlock, Loop *L, }); } +/// \brief Return true if the load is not executed on all paths in the loop. +static bool isLoadConditional(LoadInst *Load, Loop *L) { + return Load->getParent() != L->getHeader(); +} + /// \brief The per-loop class that does most of the work. class LoadEliminationForLoop { public: @@ -450,6 +455,12 @@ public: if (!doesStoreDominatesAllLatches(Cand.Store->getParent(), L, DT)) continue; + // If the load is conditional we can't hoist its 0-iteration instance to + // the preheader because that would make it unconditional. Thus we would + // access a memory location that the original loop did not access. + if (isLoadConditional(Cand.Load, L)) + continue; + // Check whether the SCEV difference is the same as the induction step, // thus we load the value in the next iteration. if (!Cand.isDependenceDistanceOfOne(PSE, L)) -- cgit v1.2.3