[llvm] r341651 - [NewGVN] Mark function as changed if we erase instructions.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 7 04:41:34 PDT 2018
Author: fhahn
Date: Fri Sep 7 04:41:34 2018
New Revision: 341651
URL: http://llvm.org/viewvc/llvm-project?rev=341651&view=rev
Log:
[NewGVN] Mark function as changed if we erase instructions.
Currently eliminateInstructions only returns true if any instruction got
replaced. In the test case for this patch, we eliminate the trivially
dead calls, for which eliminateInstructions not do a replacement and the
function is not marked as changed, which is why the inliner crashes
while traversing the call graph.
Alternatively we could also change eliminateInstructions to return true
in case we mark instructions for deletion, but that's slightly more code
and doing it at the place where the replacement happens seems safer.
Fixes PR37517.
Reviewers: davide, mcrosier, efriedma, bjope
Reviewed By: bjope
Differential Revision: https://reviews.llvm.org/D51169
Added:
llvm/trunk/test/Transforms/NewGVN/eliminate-callsite-inline.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=341651&r1=341650&r2=341651&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Fri Sep 7 04:41:34 2018
@@ -3497,9 +3497,11 @@ bool NewGVN::runGVN() {
if (!ToErase->use_empty())
ToErase->replaceAllUsesWith(UndefValue::get(ToErase->getType()));
- if (ToErase->getParent())
- ToErase->eraseFromParent();
+ assert(ToErase->getParent() &&
+ "BB containing ToErase deleted unexpectedly!");
+ ToErase->eraseFromParent();
}
+ Changed |= !InstructionsToErase.empty();
// Delete all unreachable blocks.
auto UnreachableBlockPred = [&](const BasicBlock &BB) {
Added: llvm/trunk/test/Transforms/NewGVN/eliminate-callsite-inline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/NewGVN/eliminate-callsite-inline.ll?rev=341651&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/NewGVN/eliminate-callsite-inline.ll (added)
+++ llvm/trunk/test/Transforms/NewGVN/eliminate-callsite-inline.ll Fri Sep 7 04:41:34 2018
@@ -0,0 +1,18 @@
+; RUN: opt -inline -newgvn -S < %s | FileCheck %s
+
+; CHECK-LABEL: @f2()
+; CHECK-NEXT: ret void
+; CHECK-NOT: @f1
+
+define void @f2() {
+ call void @f1()
+ call void @f1()
+ ret void
+}
+
+define internal void @f1() #1 {
+entry:
+ ret void
+}
+
+attributes #1 = { noinline nounwind readnone }
More information about the llvm-commits
mailing list