[llvm] r251996 - AMDGPU: Make findUsedSGPR more readable

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 3 14:30:15 PST 2015


Author: arsenm
Date: Tue Nov  3 16:30:15 2015
New Revision: 251996

URL: http://llvm.org/viewvc/llvm-project?rev=251996&view=rev
Log:
AMDGPU: Make findUsedSGPR more readable

Add more comments etc.

Modified:
    llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp

Modified: llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp?rev=251996&r1=251995&r2=251996&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp Tue Nov  3 16:30:15 2015
@@ -2665,6 +2665,7 @@ const TargetRegisterClass *SIInstrInfo::
   }
 }
 
+// Find the one SGPR operand we are allowed to use.
 unsigned SIInstrInfo::findUsedSGPR(const MachineInstr *MI,
                                    int OpIndices[3]) const {
   const MCInstrDesc &Desc = MI->getDesc();
@@ -2691,16 +2692,23 @@ unsigned SIInstrInfo::findUsedSGPR(const
       break;
 
     const MachineOperand &MO = MI->getOperand(Idx);
-    if (RI.isSGPRClassID(Desc.OpInfo[Idx].RegClass))
-      SGPRReg = MO.getReg();
+    if (!MO.isReg())
+      continue;
 
-    if (MO.isReg() && RI.isSGPRClass(MRI.getRegClass(MO.getReg())))
-      UsedSGPRs[i] = MO.getReg();
+    // Is this operand statically required to be an SGPR based on the operand
+    // constraints?
+    const TargetRegisterClass *OpRC = RI.getRegClass(Desc.OpInfo[Idx].RegClass);
+    bool IsRequiredSGPR = RI.isSGPRClass(OpRC);
+    if (IsRequiredSGPR)
+      return MO.getReg();
+
+    // If this could be a VGPR or an SGPR, Check the dynamic register class.
+    unsigned Reg = MO.getReg();
+    const TargetRegisterClass *RegRC = MRI.getRegClass(Reg);
+    if (RI.isSGPRClass(RegRC))
+      UsedSGPRs[i] = Reg;
   }
 
-  if (SGPRReg != AMDGPU::NoRegister)
-    return SGPRReg;
-
   // We don't have a required SGPR operand, so we have a bit more freedom in
   // selecting operands to move.
 
@@ -2711,6 +2719,9 @@ unsigned SIInstrInfo::findUsedSGPR(const
   // V_FMA_F32 v0, s0, s0, s0 -> No moves
   // V_FMA_F32 v0, s0, s1, s0 -> Move s1
 
+  // TODO: If some of the operands are 64-bit SGPRs and some 32, we should
+  // prefer those.
+
   if (UsedSGPRs[0] != AMDGPU::NoRegister) {
     if (UsedSGPRs[0] == UsedSGPRs[1] || UsedSGPRs[0] == UsedSGPRs[2])
       SGPRReg = UsedSGPRs[0];




More information about the llvm-commits mailing list