[llvm] [AMDGPU] Add MachineVerifer check to detect illegal copies from VGPR to SGPR (PR #105494)
Christudasan Devadasan via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 06:52:34 PDT 2024
================
@@ -4613,15 +4613,41 @@ static bool isSubRegOf(const SIRegisterInfo &TRI,
SubReg.getReg() == SuperVec.getReg();
}
+// Verify the illgal copy from VGPR to SGPR for generic opcode COPY
+bool SIInstrInfo::verifyCopy(const MachineInstr &MI,
+ const MachineRegisterInfo &MRI,
+ StringRef &ErrInfo) const {
+ const MachineOperand &Dst = MI.getOperand(0);
+ const MachineOperand &Src = MI.getOperand(1);
+
+ if (Dst.isReg() && Src.isReg()) {
+ Register DstReg = Dst.getReg();
+ Register SrcReg = Src.getReg();
+ // This is a check for copy from an VGPR to SGPR
+ if (RI.isVGPR(MRI, SrcReg) && RI.isSGPRReg(MRI, DstReg)) {
+ ErrInfo = "illegal copy from VGPR to SGPR";
+ return false;
+ }
+ }
+ return true;
+}
+
bool SIInstrInfo::verifyInstruction(const MachineInstr &MI,
StringRef &ErrInfo) const {
uint16_t Opcode = MI.getOpcode();
- if (SIInstrInfo::isGenericOpcode(MI.getOpcode()))
- return true;
-
const MachineFunction *MF = MI.getParent()->getParent();
const MachineRegisterInfo &MRI = MF->getRegInfo();
+ if (SIInstrInfo::isGenericOpcode(MI.getOpcode())) {
+ // FIXME: At this point the COPY verify is done only for non-ssa forms.
+ // Find a better property to recognize the point where instruction selection
+ // is just done.
+ if (!MRI.isSSA() && MI.isCopy())
----------------
cdevadas wrote:
I was wondering; the existing ` MachineFunctionProperties::Property::Selected` currently set in the GISel pipeline when selection is completed, should be set in the SelectionDAG as well (mostly after finalize-isel) for consistency. MachineFunctions currently don't have this property set for SelectionDAG.
If this field is rightly set, we could catch the illegal copies soon after finalize-isel, by then SIFixSGPRCopies would have been invoked.
https://github.com/llvm/llvm-project/pull/105494
More information about the llvm-commits
mailing list