llvm / llvm/llvm-project

[LLVM][RISCV] Full LTO + loop unrolling at -O3 triggers MachineVerifier failure on rv64gcv

Open
#199,020 0 comments 0 reactions 0 assignees View on GitHub
crash generated by fuzzer LTO
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Compiling the attached testcase for rv64gcv with `-flto -O3` triggers MachineVerifier failures in the RISC-V backend. The issue disappears with `-fno-unroll-loops`, suggesting an interaction between full LTO loop unrolling and RVV code generation.

Reproducer command:
```
.../sujayk/CIFUZZR/riscv-gnu-toolchain-build/bin/clang \
-I/compiler-fuzz-ci/csmith-build/include \
-fsigned-char -fno-strict-aliasing -fwrapv \
-march=rv64gcv -flto -O3 \
red.c -o rv64gcv.out -w
```

Attachments:

[compiler-opts.txt](https://github.com/user-attachments/files/28101314/compiler-opts.txt)

[red.c](https://github.com/user-attachments/files/28101320/red.c)

[verbose-log.txt](https://github.com/user-attachments/files/28101324/verbose-log.txt)

Verbose error logs:
```
*** Bad machine code: Virtual register killed in block, but needed live out. ***
- function: main
- basic block: %bb.149
Virtual register %987 is used after the block.

*** Bad machine code: Virtual register defs don't dominate all uses. ***
- function: main
- v. register: %850

*** Bad machine code: Virtual register defs don't dominate all uses. ***
- function: main
- v. register: %987

LLVM ERROR: Found 3 machine code errors.
clang: error: unable to execute command: Aborted (core dumped)
clang: error: linker command failed with exit code -2 (use -v to see invocation)
```

The crash does not reproduce with:
```
-flto=thin
-O2
-fno-unroll-loops
```

This issue is Found via fuzzer.

Verified on clang version 23.0.0git (https://github.com/llvm/llvm-project.git d63ca96ec35e963e651d1b8765283117ca83e1f9)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.