[llvm] r335588 - [IPSCCP] Change dead blocks to unreachable after visiting all executable blocks.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 26 03:15:02 PDT 2018
Author: fhahn
Date: Tue Jun 26 03:15:02 2018
New Revision: 335588
URL: http://llvm.org/viewvc/llvm-project?rev=335588&view=rev
Log:
[IPSCCP] Change dead blocks to unreachable after visiting all executable blocks.
changeToUnreachable may remove PHI nodes from executable blocks we found values
for and we would fail to replace them. By changing dead blocks to unreachable after
we replaced constants in all executable blocks, we ensure such PHI nodes are replaced
by their known value before.
Fixes PR37780.
Reviewers: efriedma, davide
Reviewed By: efriedma
Differential Revision: https://reviews.llvm.org/D48421
Added:
llvm/trunk/test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll
Modified:
llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
Modified: llvm/trunk/lib/Transforms/Scalar/SCCP.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SCCP.cpp?rev=335588&r1=335587&r2=335588&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/SCCP.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/SCCP.cpp Tue Jun 26 03:15:02 2018
@@ -1930,10 +1930,7 @@ bool llvm::runIPSCCP(Module &M, const Da
for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
if (!Solver.isBlockExecutable(&*BB)) {
LLVM_DEBUG(dbgs() << " BasicBlock Dead:" << *BB);
-
++NumDeadBlocks;
- NumInstRemoved +=
- changeToUnreachable(BB->getFirstNonPHI(), /*UseLLVMTrap=*/false);
MadeChanges = true;
@@ -1956,6 +1953,17 @@ bool llvm::runIPSCCP(Module &M, const Da
}
}
+ // Change dead blocks to unreachable. We do it after replacing constants in
+ // all executable blocks, because changeToUnreachable may remove PHI nodes
+ // in executable blocks we found values for. The function's entry block is
+ // not part of BlocksToErase, so we have to handle it separately.
+ for (BasicBlock *BB : BlocksToErase)
+ NumInstRemoved +=
+ changeToUnreachable(BB->getFirstNonPHI(), /*UseLLVMTrap=*/false);
+ if (!Solver.isBlockExecutable(&F.front()))
+ NumInstRemoved += changeToUnreachable(F.front().getFirstNonPHI(),
+ /*UseLLVMTrap=*/false);
+
// Now that all instructions in the function are constant folded, erase dead
// blocks, because we can now use ConstantFoldTerminator to get rid of
// in-edges.
Added: llvm/trunk/test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll?rev=335588&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll (added)
+++ llvm/trunk/test/Transforms/SCCP/ipsccp-phi-one-pred-dead.ll Tue Jun 26 03:15:02 2018
@@ -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
+}
More information about the llvm-commits
mailing list