Skip to content

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

@whileone-sk

Description

@whileone-sk

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

red.c

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 d63ca96)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions