Issue 166356
Summary [LoopFusion] Assert "Expecting guard block to have no predecessors"
Labels loopoptim, crash-on-valid
Assignees
Reporter sjoerdmeijer
    This IR:

```
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
target triple = "aarch64-unknown-linux-gnu"

define void @_Z1gb() {
entry:
 br i1 false, label %if.else.1, label %for.cond.cleanup13

for.cond.cleanup13:                               ; preds = %for.cond.cleanup13, %entry
  br i1 true, label %for.inc21, label %for.cond.cleanup13

for.inc21:                                        ; preds = %for.cond.cleanup13
  br label %if.then.1

if.then.1: ; preds = %for.inc21
  br label %if.else.1

if.else.1:                                        ; preds = %if.then.1, %entry
  br i1 false, label %if.else.2, label %for.cond.cleanup13.1

for.cond.cleanup13.1:                             ; preds = %for.cond.cleanup13.1, %if.else.1
  br i1 true, label %if.else.2, label %for.cond.cleanup13.1

if.else.2: ; preds = %for.cond.cleanup13.1, %if.else.1
  ret void
}
```

triggers this assert:

```
opt: /root/llvm-project/llvm/lib/Transforms/Scalar/LoopFuse.cpp:1945: llvm::Loop* {anonymous}::LoopFuser::fuseGuardedLoops(const {anonymous}::FusionCandidate&, const {anonymous}::FusionCandidate&): Assertion `pred_empty(FC1GuardBlock) && "Expecting guard block to have no predecessors"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -S -passes=loop-fusion <source>
1.	Running pass "function(loop-fusion)" on module "<source>"
2.	Running pass "loop-fusion" on function "_Z1gb"
 #0 0x0000000005989ef8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5989ef8)
 #1 0x0000000005986da4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007f6389e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007f6389e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007f6389e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007f6389e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x00007f6389e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #7 0x00007f6389e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #8 0x00000000046a310b (anonymous namespace)::LoopFuser::fuseGuardedLoops((anonymous namespace)::FusionCandidate const&, (anonymous namespace)::FusionCandidate const&) LoopFuse.cpp:0:0
 #9 0x00000000046a329a (anonymous namespace)::LoopFuser::performFusion((anonymous namespace)::FusionCandidate const&, (anonymous namespace)::FusionCandidate const&) LoopFuse.cpp:0:0
#10 0x00000000046a938e (anonymous namespace)::LoopFuser::fuseCandidates() LoopFuse.cpp:0:0
#11 0x00000000046aaef1 llvm::LoopFusePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x46aaef1)
```

when compiled with `-S -passes=loop-fusion`, see also: https://godbolt.org/z/v9ddvW1T6


The IR reproducer comes from this C reproducer:

```
int a;
short b;
char c, e, f;
long d;
void g(bool h) {
  for (int i; i < 20ULL; i += 4ULL)
    if (h)
      if (c)
        a = f;
      else if (e)
        for (int j(d); j; j++)
          for (int k(f); k; k += 4073709530269)
            b = 0;
}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to