[PATCH] D48421: [IPSCCP] Try to replace phis before they are removed by changeToUnreachable.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 21 05:01:06 PDT 2018
fhahn created this revision.
fhahn added reviewers: efriedma, davide.
If a successor of a dead block has a PHI node with 2 incoming values,
this PHI node will be replaced by the other incoming value by
changeToUnreachable. If we found a constant for the PHI node, we have to
replace it before changeToUnreachable.
Fixes PR37780.
https://reviews.llvm.org/D48421
Files:
lib/Transforms/Scalar/SCCP.cpp
test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll
Index: test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll
===================================================================
--- /dev/null
+++ test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll
@@ -0,0 +1,39 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt < %s -S -ipsccp | FileCheck %s
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @test() {
+; CHECK-LABEL: @test(
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %Flow5.pre
+; CHECK: Flow6:
+; CHECK-NEXT: br label %end2
+; CHECK: Flow5.pre:
+; CHECK-NEXT: br label %Flow5
+; CHECK: Flow5:
+; CHECK-NEXT: br label %Flow6
+; CHECK: end2:
+; CHECK-NEXT: unreachable
+;
+entry:
+ br i1 true, label %Flow5.pre, label %Flow5.pre.unreachable
+
+Flow5.pre.unreachable:
+ br label %Flow5
+
+Flow6:
+ br i1 %0, label %end1, label %end2
+
+Flow5.pre:
+ br label %Flow5
+
+Flow5:
+ %0 = phi i1 [ undef, %Flow5.pre ], [ false, %Flow5.pre.unreachable ]
+ br label %Flow6
+
+end1:
+ unreachable
+
+end2:
+ unreachable
+}
Index: lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- lib/Transforms/Scalar/SCCP.cpp
+++ lib/Transforms/Scalar/SCCP.cpp
@@ -2019,8 +2019,25 @@
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
if (!Solver.isBlockExecutable(&*BB)) {
LLVM_DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
-
++NumDeadBlocks;
+
+ // By using changeToUnreachable below, PHI nodes in successors of
+ // BB with 2 predecessors are replaced by the incoming value. Therefore
+ // we have to try and replace them with constants here, before they
+ // are removed.
+ for (BasicBlock *Successor : successors(&*BB)) {
+ for (PHINode &PN : Successor->phis()) {
+ if (PN.getNumIncomingValues() != 2 ||
+ !Solver.isBlockExecutable(Successor))
+ continue;
+
+ // There is no need to remove PN here, as changeToUnreachable will
+ // take care of that.
+ if (tryToReplaceWithConstant(Solver, &PN))
+ ++IPNumInstRemoved;
+ }
+ }
+
NumInstRemoved +=
changeToUnreachable(BB->getFirstNonPHI(), /*UseLLVMTrap=*/false);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48421.152252.patch
Type: text/x-patch
Size: 2308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180621/9b8b74c8/attachment.bin>
More information about the llvm-commits
mailing list