[AMDGPU] machine verifier "Using an undefined physical register" in `V_CNDMASK_B32` on irregular vector `extractelement`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Live Reproducer: https://godbolt.org/z/b4xP99MfK
Compiling the following LLVM IR with `llc -verify-machineinstrs` aborts with `LLVM ERROR: Found 1 machine code errors.` after the machine verifier reports `Using an undefined physical register` on a `V_CNDMASK_B32_e32` instr.
```llvm
target triple = "amdgcn-amd-amdhsa"
define i127 @repro(<7 x i127> %a, <7 x i127> %b, i3 %idx) {
entry:
%mix = xor <7 x i127> %b,
%elt = extractelement <7 x i127> %mix, i3 %idx
ret i127 %elt
}
```
llc command:
```sh
llc -verify-machineinstrs repro.ll
```
Error output:
```
*** Bad machine code: Using an undefined physical register ***
- function: repro
- basic block: %bb.0 entry
- instruction: renamable $vgpr5 = V_CNDMASK_B32_e32 killed $vgpr5, killed $vgpr13, implicit $vcc_lo, implicit $exec
- operand 2: killed $vgpr13
LLVM ERROR: Found 1 machine code errors.
Stack dump:
0. Program arguments: llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 -verify-machineinstrs reproducer.ll
1. Running pass 'CallGraph Pass Manager' on module 'reproducer.ll'.
2. Running pass 'Verify generated machine code' on function '@repro'
#0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
#1 PrintStackTraceSignalHandler(void*)
#2 llvm::sys::RunSignalHandlers()
#3 SignalHandler(int, siginfo_t*, void*)
#4 abort
#5 llvm::report_fatal_error(llvm::Twine const&, bool)
#6 (anonymous namespace)::MachineVerifier::ReportedErrors::~ReportedErrors() MachineVerifier.cpp
#7 (anonymous namespace)::MachineVerifier::~MachineVerifier() MachineVerifier.cpp
#8 (anonymous namespace)::MachineVerifierLegacyPass::runOnMachineFunction(llvm::MachineFunction&) MachineVerifier.cpp
#9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) MachineFunctionPass.cpp
```
Note: without the `-verify-machineinstrs`, it looks like it's silently miscompiled, where upper 63 bits are hard-zeroed.
Reproducer: https://godbolt.org/z/MM4oxYPc6
Contributor guide
Assessment
This issue has not been assessed yet.