mlir-runner crashes on X86 backend: assertion Cache.back() == Reg
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
# Description
When running an MLIR program through the standard lowering pipeline to LLVM and executing it with mlir-runner, LLVM crashes with an assertion failure inside the X86 backend (MCRegAliasIterator).
This appears to be a backend-level issue during the X86 DAG->DAG Instruction Selection phase, likely triggered by an invalid or corrupted register alias table entry.
# Reproduction steps
mlir input: [test.txt](https://github.com/user-attachments/files/23380410/test.txt)
lowered mlir input: [loweredTest.txt](https://github.com/user-attachments/files/23380667/loweredTest.txt)
mlir-opt version: LLVM version 21.1.2
mlir-runner version: LLVM version 21.1.2
## Commands used
```
/llvm-project-llvmorg-21.1.2/build/bin/mlir-opt \
--arith-expand \
--arith-unsigned-when-equivalent \
--canonicalize \
--lower-affine \
--finalize-memref-to-llvm \
--convert-vector-to-scf \
--convert-vector-to-llvm \
--convert-arith-to-llvm \
--convert-scf-to-cf \
--convert-arith-to-llvm \
--convert-func-to-llvm \
-convert-to-llvm \
--reconcile-unrealized-casts \
test.mlir \
| /llvm-project-llvmorg-21.1.2/build/bin/mlir-runner \
-e func1 \
--entry-point-result=void \
--shared-libs=/llvm-project-llvmorg-21.1.2/build/lib/libmlir_runner_utils.so,/llvm-project-llvmorg-21.1.2/build/lib/libmlir_c_runner_utils.so
```
Or you can directly execute the lowered MLIR.
```
/llvm-project-llvmorg-21.1.2/build/bin/mlir-runner -e func1 --entry-point-result=void --shared-libs=/llvm-project-llvmorg-21.1.2/build/lib/libmlir_runner_utils.so,/llvm-project-llvmorg-21.1.2/build/lib/libmlir_c_runner_utils.so loweredTest.mlir
```
## Execution result 1
Sometimes, it executes successfully.
```
( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )
( 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 )
·······
1
0
```
## Execution result 2
Sometimes, it crashes during execution.
```
·····
mlir-runner: /mnt/sdd1/sbw/mlir/tool/llvm-project-llvmorg-21.1.2/llvm/include/llvm/MC/MCRegisterInfo.h:757: llvm::MCRegAliasIterator::MCRegAliasIterator(llvm::MCRegister, const llvm::MCRegisterInfo*, bool): Assertion `Cache.back() == Reg' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /mnt/sdd1/sbw/mlir/tool/llvm-project-llvmorg-21.1.2/build/bin/mlir-runner -e func1 --entry-point-result=void --shared-libs=/mnt/sdd1/sbw/mlir/tool/llvm-project-llvmorg-21.1.2/build/lib/libmlir_runner_utils.so,/mnt/sdd1/sbw/mlir/tool/llvm-project-llvmorg-21.1.2/build/lib/libmlir_c_runner_utils.so
1. Running pass 'Function Pass Manager' on module '__standard_lib'.
2. Running pass 'X86 DAG->DAG Instruction Selection' on function '@__lljit_run_atexits'
#0 0x00005c6934ffeb52 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/mnt/sdd1/sbw/mlir/tool/llvm-project-llvmorg-21.1.2/build/bin/mlir-runner+0x599b52)
·····
```
Contributor guide
Research direction
Start by running the provided mlir-opt and mlir-runner commands with test.txt and loweredTest.txt on LLVM 21.1.2. Inspect the assertion at llvm/include/llvm/MC/MCRegisterInfo.h:757 and the X86 DAG->DAG Instruction Selection stack frame. Done means the reproducer no longer intermittently crashes during execution.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100