[llvm] r348457 - [LoopSimplifyCFG] Delete dead in-loop blocks
Maxim Kazantsev via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 6 20:56:02 PST 2018
Hi
Ilya, thanks for revert. Could you please check if it passes with this patch together with fix https://reviews.llvm.org/D55357 ? I don’t have a chance to build clang and check it on my side, at least not within reasonable amount of time.
Regards,
Max
From: Ilya Biryukov <ibiryukov at google.com>
Sent: Thursday, December 6, 2018 8:20 PM
To: Maxim Kazantsev <max.kazantsev at azul.com>
Cc: llvm-commits <llvm-commits at lists.llvm.org>
Subject: Re: [llvm] r348457 - [LoopSimplifyCFG] Delete dead in-loop blocks
Hi Max,
I ran into a crash caused by this change when compiling an instrumented version of clang. The crash happens when -fprofile-generate and -fexperimental-new-pass-manager are specified.
The reproduces reliably with:
LLVM_ROOT="$HOME/projects/llvm"
BUILD_ROOT="$HOME/projects/llvm/build-rel"
$BUILD_ROOT/bin/clang++ -fexperimental-new-pass-manager -O3 -I "$LLVM_ROOT/include" -I "$BUILD_ROOT/include" -std=gnu++17 -fprofile-generate=./profile -c "$LLVM_ROOT/lib/CodeGen/RegAllocPBQP.cpp" -o foo.o
I'll revert the change to unblock our integrate, but please let me know if need help reproducing this.
LLVM_ROOT="$HOME/projects/llvm"
BUILD_ROOT="$HOME/projects/llvm/build-rel"
./bin/clang++ -fexperimental-new-pass-manager -O3 -I "$LLVM_ROOT/include" -I "$BUILD_ROOT/include" -std=gnu++17 -fprofile-generate=./profile -c "$LLVM_ROOT/lib/CodeGen/RegAllocPBQP.cpp" -o foo.o
Crash stacktrace:
0. Program arguments: /home/ibiryukov/projects/llvm/build-rel/bin/clang-8 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -disable-free -main-file-name RegAllocPBQP.cpp -mrelocation-model static -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -fprofile-instrument=llvm -fprofile-instrument-path=./profile/default_%m.profraw -coverage-notes-file /home/ibiryukov/projects/llvm/build-rel/foo.gcno -resource-dir /home/ibiryukov/projects/llvm/build-rel/lib/clang/8.0.0 -I /home/ibiryukov/projects/llvm/include -I /home/ibiryukov/projects/llvm/build-rel/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/x86_64-linux-gnu/c++/8.0.1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/x86_64-linux-gnu/c++/8.0.1 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/backward -internal-isystem /usr/local/include -internal-isystem /home/ibiryukov/projects/llvm/build-rel/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -fdeprecated-macro -fdebug-compilation-dir /home/ibiryukov/projects/llvm/build-rel -ferror-limit 19 -fmessage-length 213 -fexperimental-new-pass-manager -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o foo.o -x c++ /home/ibiryukov/projects/llvm/lib/CodeGen/RegAllocPBQP.cpp -faddrsig
1. <eof> parser at end of file
2. Optimizer
#0 0x0000000003f63c84 PrintStackTrace /home/ibiryukov/projects/llvm/build-rel/../lib/Support/Unix/Signals.inc:495:13
#1 0x0000000003f63c84 PrintStackTraceSignalHandler(void*) /home/ibiryukov/projects/llvm/build-rel/../lib/Support/Unix/Signals.inc:558:0
#2 0x0000000003f619ee llvm::sys::RunSignalHandlers() /home/ibiryukov/projects/llvm/build-rel/../lib/Support/Signals.cpp:68:18
#3 0x0000000003f63e48 SignalHandler(int) /home/ibiryukov/projects/llvm/build-rel/../lib/Support/Unix/Signals.inc:358:1
#4 0x00007f3452c550c0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x110c0)
#5 0x00007f34517e6fcf gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x32fcf)
#6 0x00007f34517e83fa abort (/lib/x86_64-linux-gnu/libc.so.6+0x343fa)
#7 0x00007f34517dfe37 (/lib/x86_64-linux-gnu/libc.so.6+0x2be37)
#8 0x00007f34517dfee2 (/lib/x86_64-linux-gnu/libc.so.6+0x2bee2)
#9 0x0000000003f65888 (/home/ibiryukov/projects/llvm/build-rel/bin/clang-8+0x3f65888)
#10 0x0000000003da202a fetch_add /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/bits/atomic_base.h:514:16
#11 0x0000000003da202a operator++ /home/ibiryukov/projects/llvm/build-rel/../include/llvm/ADT/Statistic.h:80:0
#12 0x0000000003da202a ConstantTerminatorFoldingImpl::deleteDeadLoopBlocks() /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopSimplifyCFG.cpp:256:0
#13 0x0000000003da04b2 ConstantTerminatorFoldingImpl::run() /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopSimplifyCFG.cpp:384:5
#14 0x0000000003d9f38d constantFoldTerminators /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopSimplifyCFG.cpp:406:23
#15 0x0000000003d9f38d simplifyLoopCFG(llvm::Loop&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::ScalarEvolution&, llvm::MemorySSAUpdater*) /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopSimplifyCFG.cpp:442:0
#16 0x0000000003d9f15d llvm::LoopSimplifyCFGPass::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopSimplifyCFG.cpp:459:7
#17 0x0000000004af33ed llvm::detail::PassModel<llvm::Loop, llvm::LoopSimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManagerInternal.h:80:5
#18 0x0000000004b4a6e8 llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&>::run(llvm::Loop&, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>&, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&) /home/ibiryukov/projects/llvm/build-rel/../lib/Transforms/Scalar/LoopPassManager.cpp:45:38
#19 0x0000000004af676e runBeforePass<llvm::Function, llvm::PassManager<llvm::Function> > /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassInstrumentation.h:132:10
#20 0x0000000004af676e llvm::FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/Transforms/Scalar/LoopPassManager.h:284:0
#21 0x0000000004af5ddd llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor<llvm::PassManager<llvm::Loop, llvm::AnalysisManager<llvm::Loop, llvm::LoopStandardAnalysisResults&>, llvm::LoopStandardAnalysisResults&, llvm::LPMUpdater&> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManagerInternal.h:80:5
#22 0x0000000003978761 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManager.h:509:37
#23 0x0000000004afc960 runBeforePass<llvm::Function, llvm::PassManager<llvm::Function> > /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassInstrumentation.h:132:10
#24 0x0000000004afc960 llvm::CGSCCToFunctionPassAdaptor<llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> > >::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/Analysis/CGSCCPassManager.h:634:0
#25 0x0000000004afc47d llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::CGSCCToFunctionPassAdaptor<llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> > >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManagerInternal.h:80:5
#26 0x00000000039e4113 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) /home/ibiryukov/projects/llvm/build-rel/../lib/Analysis/CGSCCPassManager.cpp:80:38
#27 0x0000000004b090e9 llvm::DevirtSCCRepeatedPass<llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&> >::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/Analysis/CGSCCPassManager.h:763:39
#28 0x0000000004b08575 llvm::ModuleToPostOrderCGSCCPassAdaptor<llvm::DevirtSCCRepeatedPass<llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&> > >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/Analysis/CGSCCPassManager.h:442:45
#29 0x0000000004b0785d llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor<llvm::DevirtSCCRepeatedPass<llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&> > >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManagerInternal.h:80:5
#30 0x0000000003976c51 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManager.h:509:37
#31 0x0000000004b1140d llvm::detail::PassModel<llvm::Module, llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManagerInternal.h:80:5
#32 0x0000000003976c51 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManager.h:509:37
#33 0x0000000004137bc2 isSmall /home/ibiryukov/projects/llvm/build-rel/../include/llvm/ADT/SmallPtrSet.h:195:33
#34 0x0000000004137bc2 ~SmallPtrSetImplBase /home/ibiryukov/projects/llvm/build-rel/../include/llvm/ADT/SmallPtrSet.h:83:0
#35 0x0000000004137bc2 ~PreservedAnalyses /home/ibiryukov/projects/llvm/build-rel/../include/llvm/IR/PassManager.h:154:0
#36 0x0000000004137bc2 EmitAssemblyWithNewPassManager /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/CodeGen/BackendUtil.cpp:1097:0
#37 0x0000000004137bc2 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/CodeGen/BackendUtil.cpp:1299:0
#38 0x000000000477550a ~unique_ptr /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/bits/unique_ptr.h:273:6
#39 0x000000000477550a clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/CodeGen/CodeGenAction.cpp:293:0
#40 0x000000000523b5b3 __normal_iterator /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/bits/stl_iterator.h:781:20
#41 0x000000000523b5b3 begin /usr/bin/../lib/gcc/x86_64-linux-gnu/8.0.1/../../../../include/c++/8.0.1/bits/stl_vector.h:699:0
#42 0x000000000523b5b3 finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> >, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback> > > > > /home/ibiryukov/projects/llvm/build-rel/../tools/clang/include/clang/Sema/TemplateInstCallback.h:55:0
#43 0x000000000523b5b3 clang::ParseAST(clang::Sema&, bool, bool) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/Parse/ParseAST.cpp:177:0
#44 0x00000000046d4ac0 clang::FrontendAction::Execute() /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/Frontend/FrontendAction.cpp:921:10
#45 0x0000000004647dc1 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/Frontend/CompilerInstance.cpp:956:11
#46 0x000000000476fab4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:266:25
#47 0x0000000002544c97 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /home/ibiryukov/projects/llvm/build-rel/../tools/clang/tools/driver/cc1_main.cpp:219:13
#48 0x0000000002542db5 ExecuteCC1Tool /home/ibiryukov/projects/llvm/build-rel/../tools/clang/tools/driver/driver.cpp:310:12
#49 0x0000000002542db5 main /home/ibiryukov/projects/llvm/build-rel/../tools/clang/tools/driver/driver.cpp:382:0
#50 0x00007f34517d42b1 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b1)
#51 0x000000000254002a _start (/home/ibiryukov/projects/llvm/build-rel/bin/clang-8+0x254002a)
clang-8: error: unable to execute command: Aborted
clang-8: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 8.0.0 (trunk 348473) (llvm/trunk 348482)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/ibiryukov/projects/llvm/build-rel/./bin
On Thu, Dec 6, 2018 at 6:47 AM Max Kazantsev via llvm-commits <llvm-commits at lists.llvm.org<mailto:llvm-commits at lists.llvm.org>> wrote:
Author: mkazantsev
Date: Wed Dec 5 21:45:02 2018
New Revision: 348457
URL: http://llvm.org/viewvc/llvm-project?rev=348457&view=rev
Log:
[LoopSimplifyCFG] Delete dead in-loop blocks
This patch teaches LoopSimplifyCFG to delete loop blocks that have
become unreachable after terminator folding has been done.
Differential Revision: https://reviews.llvm.org/D54023
Reviewed By: anna
Modified:
llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll
Modified: llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp?rev=348457&r1=348456&r2=348457&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LoopSimplifyCFG.cpp Wed Dec 5 21:45:02 2018
@@ -46,6 +46,8 @@ static cl::opt<bool> EnableTermFolding("
STATISTIC(NumTerminatorsFolded,
"Number of terminators folded to unconditional branches");
+STATISTIC(NumLoopBlocksDeleted,
+ "Number of loop blocks deleted");
/// If \p BB is a switch or a conditional branch, but only one of its successors
/// can be reached from this block in runtime, return this successor. Otherwise,
@@ -234,6 +236,27 @@ private:
"All blocks that stay in loop should be live!");
}
+ /// Delete loop blocks that have become unreachable after folding. Make all
+ /// relevant updates to DT and LI.
+ void deleteDeadLoopBlocks() {
+ DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
+ if (MSSAU)
+ MSSAU->removeBlocks(DeadLoopBlocks);
+ for (auto *BB : DeadLoopBlocks) {
+ assert(BB != L.getHeader() &&
+ "Header of the current loop cannot be dead!");
+ LLVM_DEBUG(dbgs() << "Deleting dead loop block " << BB->getName()
+ << "\n");
+ if (LI.isLoopHeader(BB)) {
+ assert(LI.getLoopFor(BB) != &L && "Attempt to remove current loop!");
+ LI.erase(LI.getLoopFor(BB));
+ }
+ LI.removeBlock(BB);
+ DeleteDeadBlock(BB, &DTU);
+ ++NumLoopBlocksDeleted;
+ }
+ }
+
/// Constant-fold terminators of blocks acculumated in FoldCandidates into the
/// unconditional branches.
void foldTerminators() {
@@ -318,15 +341,6 @@ public:
return false;
}
- // TODO: Support deletion of dead loop blocks.
- if (!DeadLoopBlocks.empty()) {
- LLVM_DEBUG(dbgs() << "Give up constant terminator folding in loop "
- << L.getHeader()->getName()
- << ": we don't currently"
- " support deletion of dead in-loop blocks.\n");
- return false;
- }
-
// TODO: Support dead loop exits.
if (!DeadExitBlocks.empty()) {
LLVM_DEBUG(dbgs() << "Give up constant terminator folding in loop "
@@ -337,7 +351,8 @@ public:
// TODO: Support blocks that are not dead, but also not in loop after the
// folding.
- if (BlocksInLoopAfterFolding.size() != L.getNumBlocks()) {
+ if (BlocksInLoopAfterFolding.size() + DeadLoopBlocks.size() !=
+ L.getNumBlocks()) {
LLVM_DEBUG(
dbgs() << "Give up constant terminator folding in loop "
<< L.getHeader()->getName()
@@ -357,6 +372,13 @@ public:
// Make the actual transforms.
foldTerminators();
+ if (!DeadLoopBlocks.empty()) {
+ LLVM_DEBUG(dbgs() << "Deleting " << DeadLoopBlocks.size()
+ << " dead blocks in loop " << L.getHeader()->getName()
+ << "\n");
+ deleteDeadLoopBlocks();
+ }
+
#ifndef NDEBUG
// Make sure that we have preserved all data structures after the transform.
DT.verify();
Modified: llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll?rev=348457&r1=348456&r2=348457&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll (original)
+++ llvm/trunk/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll Wed Dec 5 21:45:02 2018
@@ -88,18 +88,12 @@ define i32 @dead_block_test_branch_loop(
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[DEAD:%.*]]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -129,22 +123,12 @@ define i32 @dead_block_test_switch_loop(
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: switch i32 1, label [[DEAD:%.*]] [
-; CHECK-NEXT: i32 0, label [[DEAD]]
-; CHECK-NEXT: i32 1, label [[BACKEDGE]]
-; CHECK-NEXT: i32 2, label [[DEAD]]
-; CHECK-NEXT: ]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -175,18 +159,12 @@ define i32 @dead_block_propogate_test_br
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[DEAD:%.*]]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -219,22 +197,12 @@ define i32 @dead_block_propogate_test_sw
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: switch i32 1, label [[DEAD:%.*]] [
-; CHECK-NEXT: i32 0, label [[DEAD]]
-; CHECK-NEXT: i32 1, label [[BACKEDGE]]
-; CHECK-NEXT: i32 2, label [[DEAD]]
-; CHECK-NEXT: ]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -463,32 +431,19 @@ define i32 @dead_sub_loop_test_branch_lo
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: br i1 true, label [[LIVE_PREHEADER:%.*]], label [[DEAD_PREHEADER:%.*]]
-; CHECK: live_preheader:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[EXIT_A:%.*]] ]
; CHECK-NEXT: br label [[LIVE_LOOP:%.*]]
; CHECK: live_loop:
-; CHECK-NEXT: [[A:%.*]] = phi i32 [ 0, [[LIVE_PREHEADER]] ], [ [[A_INC:%.*]], [[LIVE_LOOP]] ]
+; CHECK-NEXT: [[A:%.*]] = phi i32 [ 0, [[HEADER]] ], [ [[A_INC:%.*]], [[LIVE_LOOP]] ]
; CHECK-NEXT: [[A_INC]] = add i32 [[A]], 1
; CHECK-NEXT: [[CMP_A:%.*]] = icmp slt i32 [[A_INC]], [[END:%.*]]
-; CHECK-NEXT: br i1 [[CMP_A]], label [[LIVE_LOOP]], label [[EXIT_A:%.*]]
+; CHECK-NEXT: br i1 [[CMP_A]], label [[LIVE_LOOP]], label [[EXIT_A]]
; CHECK: exit.a:
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: dead_preheader:
-; CHECK-NEXT: br label [[DEAD_LOOP:%.*]]
-; CHECK: dead_loop:
-; CHECK-NEXT: [[B:%.*]] = phi i32 [ 0, [[DEAD_PREHEADER]] ], [ [[B_INC:%.*]], [[DEAD_LOOP]] ]
-; CHECK-NEXT: [[B_INC]] = add i32 [[B]], 1
-; CHECK-NEXT: [[CMP_B:%.*]] = icmp slt i32 [[B_INC]], [[END]]
-; CHECK-NEXT: br i1 [[CMP_B]], label [[DEAD_LOOP]], label [[EXIT_B:%.*]]
-; CHECK: exit.b:
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[EXIT_A]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -536,36 +491,19 @@ define i32 @dead_sub_loop_test_switch_lo
; CHECK-NEXT: preheader:
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: switch i32 1, label [[DEAD_PREHEADER:%.*]] [
-; CHECK-NEXT: i32 0, label [[DEAD_PREHEADER]]
-; CHECK-NEXT: i32 1, label [[LIVE_PREHEADER:%.*]]
-; CHECK-NEXT: i32 2, label [[DEAD_PREHEADER]]
-; CHECK-NEXT: ]
-; CHECK: live_preheader:
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[PREHEADER:%.*]] ], [ [[I_INC:%.*]], [[EXIT_A:%.*]] ]
; CHECK-NEXT: br label [[LIVE_LOOP:%.*]]
; CHECK: live_loop:
-; CHECK-NEXT: [[A:%.*]] = phi i32 [ 0, [[LIVE_PREHEADER]] ], [ [[A_INC:%.*]], [[LIVE_LOOP]] ]
+; CHECK-NEXT: [[A:%.*]] = phi i32 [ 0, [[HEADER]] ], [ [[A_INC:%.*]], [[LIVE_LOOP]] ]
; CHECK-NEXT: [[A_INC]] = add i32 [[A]], 1
; CHECK-NEXT: [[CMP_A:%.*]] = icmp slt i32 [[A_INC]], [[END:%.*]]
-; CHECK-NEXT: br i1 [[CMP_A]], label [[LIVE_LOOP]], label [[EXIT_A:%.*]]
+; CHECK-NEXT: br i1 [[CMP_A]], label [[LIVE_LOOP]], label [[EXIT_A]]
; CHECK: exit.a:
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: dead_preheader:
-; CHECK-NEXT: br label [[DEAD_LOOP:%.*]]
-; CHECK: dead_loop:
-; CHECK-NEXT: [[B:%.*]] = phi i32 [ 0, [[DEAD_PREHEADER]] ], [ [[B_INC:%.*]], [[DEAD_LOOP]] ]
-; CHECK-NEXT: [[B_INC]] = add i32 [[B]], 1
-; CHECK-NEXT: [[CMP_B:%.*]] = icmp slt i32 [[B_INC]], [[END]]
-; CHECK-NEXT: br i1 [[CMP_B]], label [[DEAD_LOOP]], label [[EXIT_B:%.*]]
-; CHECK: exit.b:
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[EXIT:%.*]]
; CHECK: exit:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[EXIT_A]] ]
; CHECK-NEXT: ret i32 [[I_INC_LCSSA]]
;
preheader:
@@ -898,18 +836,12 @@ define i32 @partial_sub_loop_test_branch
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[J_INC:%.*]], [[OUTER_BACKEDGE:%.*]] ]
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: br i1 true, label [[BACKEDGE]], label [[DEAD:%.*]]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[OUTER_BACKEDGE]]
; CHECK: outer_backedge:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: [[J_INC]] = add i32 [[J]], 1
; CHECK-NEXT: [[CMP_J:%.*]] = icmp slt i32 [[J_INC]], [[END]]
; CHECK-NEXT: br i1 [[CMP_J]], label [[OUTER_HEADER]], label [[EXIT:%.*]]
@@ -958,22 +890,12 @@ define i32 @partial_sub_loop_test_switch
; CHECK-NEXT: [[J:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[J_INC:%.*]], [[OUTER_BACKEDGE:%.*]] ]
; CHECK-NEXT: br label [[HEADER:%.*]]
; CHECK: header:
-; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[I_INC:%.*]], [[BACKEDGE:%.*]] ]
-; CHECK-NEXT: switch i32 1, label [[DEAD:%.*]] [
-; CHECK-NEXT: i32 0, label [[DEAD]]
-; CHECK-NEXT: i32 1, label [[BACKEDGE]]
-; CHECK-NEXT: i32 2, label [[DEAD]]
-; CHECK-NEXT: ]
-; CHECK: dead:
-; CHECK-NEXT: [[I_2:%.*]] = add i32 [[I]], 1
-; CHECK-NEXT: br label [[BACKEDGE]]
-; CHECK: backedge:
-; CHECK-NEXT: [[I_1:%.*]] = phi i32 [ [[I]], [[HEADER]] ], [ [[I_2]], [[DEAD]] ]
-; CHECK-NEXT: [[I_INC]] = add i32 [[I_1]], 1
+; CHECK-NEXT: [[I:%.*]] = phi i32 [ 0, [[OUTER_HEADER]] ], [ [[I_INC:%.*]], [[HEADER]] ]
+; CHECK-NEXT: [[I_INC]] = add i32 [[I]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[I_INC]], [[END:%.*]]
; CHECK-NEXT: br i1 [[CMP]], label [[HEADER]], label [[OUTER_BACKEDGE]]
; CHECK: outer_backedge:
-; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[BACKEDGE]] ]
+; CHECK-NEXT: [[I_INC_LCSSA:%.*]] = phi i32 [ [[I_INC]], [[HEADER]] ]
; CHECK-NEXT: [[J_INC]] = add i32 [[J]], 1
; CHECK-NEXT: [[CMP_J:%.*]] = icmp slt i32 [[J_INC]], [[END]]
; CHECK-NEXT: br i1 [[CMP_J]], label [[OUTER_HEADER]], label [[EXIT:%.*]]
_______________________________________________
llvm-commits mailing list
llvm-commits at lists.llvm.org<mailto:llvm-commits at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
--
Regards,
Ilya Biryukov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181207/81b6a400/attachment-0001.html>
More information about the llvm-commits
mailing list