Issue |
128600
|
Summary |
[Clang] Optimization LoopFuse.cpp crashes on valid LLVM IR. Assertion `!verifyFunction(*FC0.Header->getParent(), &errs())' failed.
|
Labels |
clang
|
Assignees |
|
Reporter |
zitongzhoueric
|
To reproduce: https://godbolt.org/z/zMEsM448G
`opt -passes=mem2reg,loop-rotate,loop-fusion {test}` crashes on the LLVMIR generated from `clang -O0` because of an assertion failure.
Stack Dump:
```
PHI node entries do not match predecessors!
%sum1.0.lcssa = phi i32 [ %add, %for.inc ]
label %for.inc
label %for.inc6
opt: /root/llvm-project/llvm/lib/Transforms/Scalar/LoopFuse.cpp:1759: llvm::Loop* {anonymous}::LoopFuser::performFusion(const {anonymous}::FusionCandidate&, const {anonymous}::FusionCandidate&): Assertion `!verifyFunction(*FC0.Header->getParent(), &errs())' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=mem2reg,loop-rotate,loop-fusion <source>
1. Running pass "function(mem2reg,loop(loop-rotate<header-duplication;no-prepare-for-lto>),loop-fusion)" on module "<source>"
2. Running pass "loop-fusion" on function "main"
#0 0x00000000054498e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x54498e8)
#1 0x00000000054472a4 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#2 0x0000704d50642520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#3 0x0000704d506969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
#4 0x0000704d50642476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
#5 0x0000704d506287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
#6 0x0000704d5062871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
#7 0x0000704d50639e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
#8 0x000000000402a593 (anonymous namespace)::LoopFuser::performFusion((anonymous namespace)::FusionCandidate const&, (anonymous namespace)::FusionCandidate const&) LoopFuse.cpp:0:0
#9 0x000000000402cab5 (anonymous namespace)::LoopFuser::fuseCandidates() LoopFuse.cpp:0:0
#10 0x000000000402e5c1 llvm::LoopFusePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x402e5c1)
#11 0x00000000031828ae llvm::detail::PassModel<llvm::Function, llvm::LoopFusePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x31828ae)
#12 0x0000000005243e40 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5243e40)
#13 0x0000000000e6e23e llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6e23e)
#14 0x000000000524275b llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x524275b)
#15 0x0000000000e6d54e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xe6d54e)
#16 0x0000000005242160 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5242160)
#17 0x0000000000935dda llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x935dda)
#18 0x000000000092944c optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x92944c)
#19 0x0000704d50629d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#20 0x0000704d50629e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#21 0x0000000000920d25 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x920d25)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```
The Test IR causing the failure:
```
@.str = private unnamed_addr constant [7 x i8] c"%d %d\0A\00", align 1
define dso_local i32 @main() #0 {
entry:
%retval = alloca i32, align 4
%sum1 = alloca i32, align 4
%sum2 = alloca i32, align 4
%i = alloca i32, align 4
%i1 = alloca i32, align 4
store i32 0, ptr %retval, align 4
store i32 0, ptr %sum1, align 4
store i32 0, ptr %sum2, align 4
store i32 0, ptr %i, align 4
br label %for.cond
for.cond:
%0 = load i32, ptr %i, align 4
%cmp = icmp slt i32 %0, 10
br i1 %cmp, label %for.body, label %for.end
for.body:
%1 = load i32, ptr %i, align 4
%2 = load i32, ptr %sum1, align 4
%add = add nsw i32 %2, %1
store i32 %add, ptr %sum1, align 4
br label %for.inc
for.inc:
%3 = load i32, ptr %i, align 4
%inc = add nsw i32 %3, 1
store i32 %inc, ptr %i, align 4
br label %for.cond
for.end:
store i32 0, ptr %i1, align 4
br label %for.cond2
for.cond2:
%4 = load i32, ptr %i1, align 4
%cmp3 = icmp slt i32 %4, 10
br i1 %cmp3, label %for.body4, label %for.end8
for.body4:
%5 = load i32, ptr %i1, align 4
%6 = load i32, ptr %i1, align 4
%mul = mul nsw i32 %5, %6
%7 = load i32, ptr %sum2, align 4
%add5 = add nsw i32 %7, %mul
store i32 %add5, ptr %sum2, align 4
br label %for.inc6
for.inc6:
%8 = load i32, ptr %i1, align 4
%inc7 = add nsw i32 %8, 1
store i32 %inc7, ptr %i1, align 4
br label %for.cond2
for.end8:
%9 = load i32, ptr %sum1, align 4
%10 = load i32, ptr %sum2, align 4
%call = call i32 (ptr, ...) @printf(ptr noundef @.str, i32 noundef %9, i32 noundef %10)
ret i32 0
}
declare i32 @printf(ptr noundef, ...) #1
attributes #0 = { noinline nounwind uwtable "frame-pointer"="all" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
```
It is generated from
```c
#include <stdio.h>
int main() {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < 10; i++) {
sum1 += i;
}
for (int i = 0; i < 10; i++) {
sum2 += i * i;
}
printf("%d %d\n", sum1, sum2);
return 0;
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs