Issue 243649
Summary [RISCV] "Cannot scavenge register" for inline asm with two memory operands
Labels new issue
Assignees
Reporter cakgok
    Reproducer

```llvm
define i32 @f(i32 %a, i32 %b) {
  %x = alloca i32
  %big = alloca [4096 x i8]
  call void asm sideeffect "", "*m,*m,~{x1},~{x5},~{x6},~{x7},~{x8},~{x9},~{x12},~{x13},~{x14},~{x15},~{x16},~{x17},~{x18},~{x19},~{x20},~{x21},~{x22},~{x23},~{x24},~{x25},~{x26},~{x27},~{x28},~{x29},~{x30},~{x31}"(ptr elementtype(i32) %x, ptr elementtype(i32) %x)
  %s = add i32 %a, %b
  ret i32 %s
}
```

or https://godbolt.org/z/YKKd6rfPG

```sh
llc -mtriple=riscv32 repro.ll
llc -mtriple=riscv64 repro.ll
```

```
LLVM ERROR: Error while trying to spill X11 from class GPR: Cannot scavenge register without an emergency spill slot!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: llc -mtriple=riscv32 repro.ll
1.	Running pass 'Function Pass Manager' on module 'repro.ll'.
2.	Running pass 'Prologue/Epilogue Insertion & Frame Finalization' on function '@f'
...
#7 0x00007f85d996d34c llvm::report_fatal_error(llvm::Twine const&, bool) /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/Support/ErrorHandling.cpp:135:10
 #8 0x00007f85da5cb722 llvm::RegScavenger::spill(llvm::Register, llvm::MCRegisterClass const&, int, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/RegisterScavenging.cpp:304:1
 #9 0x00007f85da5cbc8c llvm::RegScavenger::scavengeRegisterBackwards(llvm::MCRegisterClass const&, llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>, bool, int, bool) /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/RegisterScavenging.cpp:335:35
#10 0x00007f85da5cc24d scavengeVReg /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/RegisterScavenging.cpp:393:21
#11 0x00007f85da5cc5ec scavengeFrameVirtualRegsInBlock /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/RegisterScavenging.cpp:431:29
#12 0x00007f85da5cc748 llvm::scavengeFrameVirtualRegs(llvm::MachineFunction&, llvm::RegScavenger&) /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/RegisterScavenging.cpp:490:5
#13 0x00007f85da531091 run /usr/src/debug/llvm/llvm-project-23.1.5.src/llvm/lib/CodeGen/PrologEpilogInserter.cpp:286:29
```

- Reproduces on trunk and on 23.1.5
- Compiles fine with a single *m operand.
- This IR should be valid. asm only accesses %x itself, it's in bounds. %big only pushes %x beyond the reach of the 12-bit offset
- Then, each of the *m 's need a scratch register (since a0/a1), but there is only one.
- The clobbers are only here to make every register except a0/a1 unavailable

It's constructed crash (wasn't fuzzed), but it didn't come from an actual program either. So, feel free to treat it as low prio fuzzer generated. 

Can crash Mips similarly too, with 3 *m's instead and a bigger alloca. Maybe it's a shared issue.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to