diff options
author | Adam Nemet <anemet@apple.com> | 2016-06-28 04:02:47 +0000 |
---|---|---|
committer | Adam Nemet <anemet@apple.com> | 2016-06-28 04:02:47 +0000 |
commit | bd861acf29bb49c6530870de2e05d4828eb1a9a2 (patch) | |
tree | da234c6a603e8458e9b5b967031a955a9075fdfc /llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp | |
parent | 55415f2565b9fd1c1033a9f0ad5551b39b3a9045 (diff) | |
download | bcm5719-llvm-bd861acf29bb49c6530870de2e05d4828eb1a9a2.tar.gz bcm5719-llvm-bd861acf29bb49c6530870de2e05d4828eb1a9a2.zip |
[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
Diffstat (limited to 'llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopLoadElimination.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
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)) |