Index: llvm/include/llvm/CodeGen/MachineRegisterInfo.h =================================================================== --- llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -448,6 +448,19 @@ return ++DI == def_end(); } + /// Returns the defining operand if there is exactly one operand defining the + /// specified register, otherwise nullptr. + MachineOperand *getOneDef(Register Reg) const { + def_iterator DI = def_begin(Reg); + if (DI == def_end()) // No defs. + return nullptr; + + def_iterator OneDef = DI; + if (++DI == def_end()) + return &*OneDef; + return nullptr; // Multiple defs. + } + /// use_iterator/use_begin/use_end - Walk all uses of the specified register. using use_iterator = defusechain_iterator; Index: llvm/lib/CodeGen/MIRParser/MIRParser.cpp =================================================================== --- llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -322,9 +322,15 @@ static bool isSSA(const MachineFunction &MF) { const MachineRegisterInfo &MRI = MF.getRegInfo(); for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) { - unsigned Reg = Register::index2VirtReg(I); + Register Reg = Register::index2VirtReg(I); if (!MRI.hasOneDef(Reg) && !MRI.def_empty(Reg)) return false; + + // FIXME: def_empty should count as an SSA violation. + // Subregister defs are invalid in SSA. + const MachineOperand *RegDef = MRI.getOneDef(Reg); + if (RegDef && RegDef->getSubReg() != 0) + return false; } return true; } Index: llvm/test/CodeGen/MIR/AMDGPU/subreg-def-is-not-ssa.mir =================================================================== --- /dev/null +++ llvm/test/CodeGen/MIR/AMDGPU/subreg-def-is-not-ssa.mir @@ -0,0 +1,16 @@ +# REQUIRES: asserts +# RUN: not --crash llc -march=amdgcn -mcpu=gfx900 -run-pass=instruction-select -verify-machineinstrs -o /dev/null %s 2>&1 | FileCheck %s + +# CHECK: MachineFunctionProperties required by InstructionSelect pass are not met by function subreg_def_is_not_ssa. +# CHECK-NEXT: Required properties: IsSSA +# CHECK-NEXT: Current properties: NoPHIs +# CHECK-NEXT: MachineFunctionProperties check failed + +--- +name: subreg_def_is_not_ssa + +body: | + bb.0: + %0.sub0:vreg_64 = V_MOV_B32_e32 0, implicit $exec + +...