diff options
| author | Aditya Kumar <hiraditya@msn.com> | 2017-12-13 19:40:07 +0000 |
|---|---|---|
| committer | Aditya Kumar <hiraditya@msn.com> | 2017-12-13 19:40:07 +0000 |
| commit | 49c03b11df5a6e0ddc065b706a0959361cf2e0de (patch) | |
| tree | 4fc1c95dfc29f2abb80743c6790ec22d37b177e5 | |
| parent | 46af7316ea1d584e3e17604a7720300b9569d257 (diff) | |
| download | bcm5719-llvm-49c03b11df5a6e0ddc065b706a0959361cf2e0de.tar.gz bcm5719-llvm-49c03b11df5a6e0ddc065b706a0959361cf2e0de.zip | |
[GVNHoist] Fix: PR35222 gvn-hoist incorrectly erases load
w.r.t. the paper
"A Practical Improvement to the Partial Redundancy Elimination in SSA Form"
(https://sites.google.com/site/jongsoopark/home/ssapre.pdf)
Proper dominance check was missing here, so having a loopinfo should not be required.
Committing this diff as this fixes the bug, if there are
further concerns, I'll be happy to work on them.
Differential Revision: https://reviews.llvm.org/D39781
llvm-svn: 320607
| -rw-r--r-- | llvm/lib/Transforms/Scalar/GVNHoist.cpp | 4 | ||||
| -rw-r--r-- | llvm/test/Transforms/GVNHoist/pr35222-hoist-load.ll | 25 |
2 files changed, 27 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Scalar/GVNHoist.cpp b/llvm/lib/Transforms/Scalar/GVNHoist.cpp index 3b551844dc2..c0cd1ea74a7 100644 --- a/llvm/lib/Transforms/Scalar/GVNHoist.cpp +++ b/llvm/lib/Transforms/Scalar/GVNHoist.cpp @@ -795,8 +795,8 @@ private: for (auto IDFB : IDFBlocks) { // TODO: Prune out useless CHI insertions. for (unsigned i = 0; i < V.size(); ++i) { CHIArg C = {VN, nullptr, nullptr}; - if (DT->dominates(IDFB, V[i]->getParent())) { // Ignore spurious PDFs. - // InValue[V[i]->getParent()].push_back(std::make_pair(VN, V[i])); + // Ignore spurious PDFs. + if (DT->properlyDominates(IDFB, V[i]->getParent())) { OutValue[IDFB].push_back(C); DEBUG(dbgs() << "\nInsertion a CHI for BB: " << IDFB->getName() << ", for Insn: " << *V[i]); diff --git a/llvm/test/Transforms/GVNHoist/pr35222-hoist-load.ll b/llvm/test/Transforms/GVNHoist/pr35222-hoist-load.ll new file mode 100644 index 00000000000..7e9c6200616 --- /dev/null +++ b/llvm/test/Transforms/GVNHoist/pr35222-hoist-load.ll @@ -0,0 +1,25 @@ +; RUN: opt -S -gvn-hoist < %s | FileCheck %s +; CHECK: load +; CHECK: load +; Check that the load is not hoisted because the call can potentially +; modify the global + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + +@heap = external global i32, align 4 + +define i32 @build_tree() unnamed_addr { +entry: + br label %do.body + +do.body: ; preds = %do.body, %entry + %tmp9 = load i32, i32* @heap, align 4 + %cmp = call i1 @pqdownheap(i32 %tmp9) + br i1 %cmp, label %do.body, label %do.end + +do.end: ; preds = %do.body + %tmp20 = load i32, i32* @heap, align 4 + ret i32 %tmp20 +} + +declare i1 @pqdownheap(i32) |

