[PATCH] D51169: [NewGVN] Mark function as changed if we erase instructions.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 23 08:55:14 PDT 2018
fhahn created this revision.
fhahn added reviewers: davide, mcrosier, efriedma.
Herald added subscribers: eraman, Prazek.
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.
https://reviews.llvm.org/D51169
Files:
lib/Transforms/Scalar/NewGVN.cpp
test/Transforms/NewGVN/eliminate-callsite-inline.ll
Index: test/Transforms/NewGVN/eliminate-callsite-inline.ll
===================================================================
--- /dev/null
+++ test/Transforms/NewGVN/eliminate-callsite-inline.ll
@@ -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 }
Index: lib/Transforms/Scalar/NewGVN.cpp
===================================================================
--- lib/Transforms/Scalar/NewGVN.cpp
+++ lib/Transforms/Scalar/NewGVN.cpp
@@ -3494,11 +3494,15 @@
// Delete all instructions marked for deletion.
for (Instruction *ToErase : InstructionsToErase) {
- if (!ToErase->use_empty())
+ if (!ToErase->use_empty()) {
ToErase->replaceAllUsesWith(UndefValue::get(ToErase->getType()));
+ Changed = true;
+ }
- if (ToErase->getParent())
+ if (ToErase->getParent()) {
ToErase->eraseFromParent();
+ Changed = true;
+ }
}
// Delete all unreachable blocks.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51169.162193.patch
Type: text/x-patch
Size: 1175 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180823/81f42acd/attachment.bin>
More information about the llvm-commits
mailing list