[PATCH] D82763: MIR: Infer not-SSA for subregister defs
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 29 06:59:06 PDT 2020
arsenm created this revision.
arsenm added reviewers: thegameg, qcolombet.
Herald added subscribers: kerbowa, hiraditya, nhaehnle, wdng, jvesely.
Herald added a project: LLVM.
It's possible to have a single virtual register def with a subreg
index that would pass the previous check, but it's not possible to
have a subregister def in SSA.
This is in preparation for adding stricter checks for SSA MIR.
https://reviews.llvm.org/D82763
Files:
llvm/include/llvm/CodeGen/MachineRegisterInfo.h
llvm/lib/CodeGen/MIRParser/MIRParser.cpp
llvm/test/CodeGen/MIR/AMDGPU/subreg-def-is-not-ssa.mir
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
+
+...
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/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<true, false, false, true, false, false>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82763.274086.patch
Type: text/x-patch
Size: 2439 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200629/da5172b5/attachment-0001.bin>
More information about the llvm-commits
mailing list