Skip to content

failed assertion: Cannot split an edge from a CallBrInst #1161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nickdesaulniers opened this issue Sep 24, 2020 · 13 comments
Closed

failed assertion: Cannot split an edge from a CallBrInst #1161

nickdesaulniers opened this issue Sep 24, 2020 · 13 comments
Assignees
Labels
asm goto related to the implementation of asm goto [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 12 This bug was fixed in LLVM 12.0

Comments

@nickdesaulniers
Copy link
Member

testing #1160 w/ assertions enabled, I hit an assertion failure; cvised down:

f;
a(void);
b(void) {
  while (({
    long c;
    if (a()) {
      asm goto("" : : : : d);
      break;
    d:;
    }
    c;
  }))
    return 4;
  return 0;
}
e(int);
do_pages_move_nr_pages(void) {
  int g, a = 0;
  for (;; g++) {
    if (f) a = b();
    if (a) goto h;
  }
h:
  e(g);
}
clang-12: ../lib/Transforms/Utils/BasicBlockUtils.cpp:787: llvm::BasicBlock *llvm::SplitBlockPredecessors(llvm::BasicBlock *, ArrayRef<llvm::BasicBlock *>, const char *, llvm::DominatorTree *, llvm::LoopInfo *, llvm::MemorySSAUpdater *, bool): Assertion `!isa<CallBrInst>(Preds[i]->getTerminator()) && "Cannot split an edge from a CallBrInst"' failed.
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
...
3.      Running pass 'Function Pass Manager' on module 'mm/migrate.c'.
4.      Running pass 'Loop Pass Manager' on function '@do_pages_move'
5.      Running pass 'Loop Strength Reduction' on basic block '%for.body'
 #0 0x00000000040e75e4 PrintStackTraceSignalHandler(void*) (/android0/llvm-project/llvm/build/bin/clang-12+0x40e75e4)
 #1 0x00000000040e51ee llvm::sys::RunSignalHandlers() (/android0/llvm-project/llvm/build/bin/clang-12+0x40e51ee)
 #2 0x00000000040e7905 SignalHandler(int) (/android0/llvm-project/llvm/build/bin/clang-12+0x40e7905)
 #3 0x00007fe120692140 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14140)
 #4 0x00007fe12016adb1 raise ./signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007fe120154537 abort ./stdlib/abort.c:81:7
 #6 0x00007fe12015440f get_sysdep_segment_value ./intl/loadmsgcat.c:509:8
 #7 0x00007fe12015440f _nl_load_domain ./intl/loadmsgcat.c:970:34
 #8 0x00007fe1201635b2 (/lib/x86_64-linux-gnu/libc.so.6+0x345b2)
 #9 0x00000000040f5ab6 llvm::SplitBlockPredecessors(llvm::BasicBlock*, llvm::ArrayRef<llvm::BasicBlock*>, char const*, llvm::DominatorTree*, llvm::LoopInfo*, llvm::MemorySSAUpdater*, bool) (/android0/llvm-project/llvm/build/bin/clang-12+0x40f5ab6)
#10 0x00000000040fd53f llvm::SplitCriticalEdge(llvm::Instruction*, unsigned int, llvm::CriticalEdgeSplittingOptions const&) (/android0/llvm-project/llvm/build/bin/clang-12+0x40fd53f)
#11 0x0000000003f1c615 (anonymous namespace)::LSRInstance::LSRInstance(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSAUpdater*) (/android0/llvm-project/llvm/build/bin/clang-12+0x3f1c615)
#12 0x0000000003f151fe ReduceLoopStrength(llvm::Loop*, llvm::IVUsers&, llvm::ScalarEvolution&, llvm::DominatorTree&, llvm::LoopInfo&, llvm::TargetTransformInfo const&, llvm::AssumptionCache&, llvm::TargetLibraryInfo&, llvm::MemorySSA*) (/android0/llvm-project/llvm/build/bin/clang-12+0x3f151fe)
#13 0x0000000003f3bab6 (anonymous namespace)::LoopStrengthReduce::runOnLoop(llvm::Loop*, llvm::LPPassManager&) (/android0/llvm-project/llvm/build/bin/clang-12+0x3f3bab6)
#14 0x000000000338305b llvm::LPPassManager::runOnFunction(llvm::Function&) (/android0/llvm-project/llvm/build/bin/clang-12+0x338305b)
#15 0x0000000003a32a38 llvm::FPPassManager::runOnFunction(llvm::Function&) (/android0/llvm-project/llvm/build/bin/clang-12+0x3a32a38)
#16 0x0000000003a390f8 llvm::FPPassManager::runOnModule(llvm::Module&) (/android0/llvm-project/llvm/build/bin/clang-12+0x3a390f8)
#17 0x0000000003a330e7 llvm::legacy::PassManagerImpl::run(llvm::Module&) (/android0/llvm-project/llvm/build/bin/clang-12+0x3a330e7)
#18 0x000000000430d482 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> >) (/android0/llvm-project/llvm/build/bin/clang-12+0x430d482)
#19 0x0000000004b2b9e6 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/android0/llvm-project/llvm/build/bin/clang-12+0x4b2b9e6)
#20 0x0000000005b0e4e3 clang::ParseAST(clang::Sema&, bool, bool) (/android0/llvm-project/llvm/build/bin/clang-12+0x5b0e4e3)
#21 0x0000000004a78ce3 clang::FrontendAction::Execute() (/android0/llvm-project/llvm/build/bin/clang-12+0x4a78ce3)
#22 0x00000000049d56e3 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/android0/llvm-project/llvm/build/bin/clang-12+0x49d56e3)
#23 0x0000000004b26022 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/android0/llvm-project/llvm/build/bin/clang-12+0x4b26022)
#24 0x000000000287eecd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/android0/llvm-project/llvm/build/bin/clang-12+0x287eecd)
#25 0x000000000287cf7c ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&) (/android0/llvm-project/llvm/build/bin/clang-12+0x287cf7c)
#26 0x000000000287cce1 main (/android0/llvm-project/llvm/build/bin/clang-12+0x287cce1)
#27 0x00007fe120155cca __libc_start_main ./csu/../csu/libc-start.c:308:16
#28 0x0000000002879c3a _start (/android0/llvm-project/llvm/build/bin/clang-12+0x2879c3a)

cc @gwelymernans @jyknight

@nickdesaulniers
Copy link
Member Author

ah, need to add the command line flags to repro, let me pare those down.

@nickdesaulniers
Copy link
Member Author

$ clang -O2 migrate.i -ftrivial-auto-var-init=pattern --target=powerpc64le-linux-gnu

Might be able to drop -ftrivial-auto-var-init=pattern by initializing some things.

@nickdesaulniers
Copy link
Member Author

Yes, initializing c to 1 and g to -4 allows me to drop -ftrivial-auto-var-init=pattern. I still need --target=powerpc64le-linux-gnu though.

@bwendling
Copy link

Could you post the IR?

@nickdesaulniers
Copy link
Member Author

Somehow, if I dump the IR, I can't reproduce by invoking llc on it...

@bwendling
Copy link

Try invoking opt -O2

@nickdesaulniers
Copy link
Member Author

diff --git a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
index 39fb504cf7b7..e88bdc8bf476 100644
--- a/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
+++ b/llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
@@ -186,7 +186,8 @@ llvm::SplitCriticalEdge(Instruction *TI, unsigned SuccNum,
       // Loop-simplify form can be preserved, if we can split all in-loop
       // predecessors.
       if (any_of(LoopPreds, [](BasicBlock *Pred) {
-            return isa<IndirectBrInst>(Pred->getTerminator());
+            return isa<IndirectBrInst>(Pred->getTerminator()) ||
+              isa<CallBrInst>(Pred->getTerminator());
           })) {
         if (Options.PreserveLoopSimplify)
           return nullptr;

seems to fix this. Not sure yet about getting a work reproducer in IR, or what the consequences of that change precisely are.

@nickdesaulniers
Copy link
Member Author

this issue is reminiscent of #896

@nickdesaulniers nickdesaulniers self-assigned this Sep 25, 2020
@nickdesaulniers
Copy link
Member Author

Somehow, if I dump the IR, I can't reproduce by invoking llc on it...

Note to future self; use clang -mllvm -print-after-all -mllvm -print-module-scope, but use a dump of post-verification pass, not a post loop transform!

attaching minimal reproducer:

$ clang -O2 --target=powerpc64le reduced.ll

reduced.ll.txt

I haven't been able to figure out how to get it to crash by just invoking llc...

@bwendling
Copy link

llc generates asm code. opt performs the IR transformations. I think you want to use opt and not llc.

@nickdesaulniers
Copy link
Member Author

@nickdesaulniers nickdesaulniers added the [PATCH] Submitted A patch has been submitted for review label Sep 28, 2020
@nathanchance
Copy link
Member

Ha, I thought I remember that #1252 looked familiar... I assume Bill's patch will fix this one too?

@nickdesaulniers
Copy link
Member Author

oh, yeah, looks similar, cc @gwelymernans @MaskRay

@nickdesaulniers nickdesaulniers added [FIXED][LLVM] 12 This bug was fixed in LLVM 12.0 and removed [PATCH] Submitted A patch has been submitted for review labels Jan 15, 2021
arichardson pushed a commit to arichardson/llvm-project that referenced this issue Mar 29, 2021
…rect successor

Otherwise we'll fail the assertion in SplitBlockPredecessors() related
to splitting the edges from CallBr's.

Fixes: ClangBuiltLinux/linux#1161
Fixes: ClangBuiltLinux/linux#1252

Reviewed By: void, MaskRay, jyknight

Differential Revision: https://reviews.llvm.org/D88438
mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
…rect successor

Otherwise we'll fail the assertion in SplitBlockPredecessors() related
to splitting the edges from CallBr's.

Fixes: ClangBuiltLinux/linux#1161
Fixes: ClangBuiltLinux/linux#1252

Reviewed By: void, MaskRay, jyknight

Differential Revision: https://reviews.llvm.org/D88438
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
asm goto related to the implementation of asm goto [BUG] llvm A bug that should be fixed in upstream LLVM [FIXED][LLVM] 12 This bug was fixed in LLVM 12.0
Projects
None yet
Development

No branches or pull requests

3 participants