llvm / llvm/llvm-project

[Backend] Crash at -O3 when compiling with profile data using PGO: Instruction does not dominate all uses!

Open
#190,084 1 comment 0 reactions 0 assignees View on GitHub
crash PGO
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

small.c

```c
int a, c, d;
static char f3(char f) { return f < 0 || c >= 2 ? f : c; }
int e() { return a; }
static short f2(char f, int g, char) {
for (; f < c; f = 1)
for (int a; a < 2;) {
if (e())
goto c;
for (int b; b;) {
if (a || g)
c:
a = f3(0);
b ^= f3(1);
}
for (int b = 0; b < c; b++)
g = 0;
}
}
static int f1() {
for (;; a = 1)
if (a) {
f2(0, a & d, 0);
goto a;
}
a:;
}
void main() { f1(); }
```

profile.txt

```
small.c:f1
285922628673
1
0

small.c:f2
395980687368152383
1
67108864

small.c:f3
406124254
1
1
```

Clang crashes when compiling the above code at -O3 with profile data using PGO.

Generate the profile data with:
```
$ llvm-profdata merge -o test.profdata profile.txt
```

Compile at -O3 with PGO:

```
$ clang-trunk -O3 -fprofile-instr-use=test.profdata small.c
```

Crash:

```
Instruction does not dominate all uses!
%a.2 = phi i32 [ 0, %f3.exit33 ], [ %a.137, %for.body5.split ]
%5 = phi i32 [ %a.2, %for.cond18 ], [ %.ph, %for.cond18.preheader ]
in function f2
fatal error: error in backend: Broken function found, compilation aborted!
clang-trunk: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 23.0.0git (https://github.com/llvm/llvm-project.git b1f8c285597925428d1f110ad7c1accff70eb885)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /data/x27zhou/compiler-nightly/install/llvm/bin
Build config: +assertions
clang-trunk: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-trunk: note: diagnostic msg: /tmp/small-809943.c
clang-trunk: note: diagnostic msg: /tmp/small-809943.sh
clang-trunk: note: diagnostic msg:

********************
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the failure from small.c and profile.txt by merging the profile with llvm-profdata and compiling with clang-trunk -O3 -fprofile-instr-use=test.profdata. Start by investigating the f2 backend failure and the reported dominance violation. Done means the reproducer compiles without the broken-function or dominance error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.