R600/SI: Fix bug in SIInstrInfo::legalizeOpWithMove()
authorTom Stellard <thomas.stellard@amd.com>
Fri, 5 Sep 2014 14:08:01 +0000 (14:08 +0000)
committerTom Stellard <thomas.stellard@amd.com>
Fri, 5 Sep 2014 14:08:01 +0000 (14:08 +0000)
We must constrain the destination register class of legalized operands
to a VGPR class or else the illegal operand may be folded back into
the instruction by the register coalescer.

This fixes a bug in add.ll that will be uncovered by future commits.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217249 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/R600/SIInstrInfo.cpp

index 11aaf45fe3294f7000327a1e4c3e54b2b894b240..6875181a2e5685544f62d6b8001c6202d09df8d2 100644 (file)
@@ -984,17 +984,18 @@ void SIInstrInfo::legalizeOpWithMove(MachineInstr *MI, unsigned OpIdx) const {
   unsigned RCID = get(MI->getOpcode()).OpInfo[OpIdx].RegClass;
   const TargetRegisterClass *RC = RI.getRegClass(RCID);
   unsigned Opcode = AMDGPU::V_MOV_B32_e32;
-
   if (MO.isReg()) {
     Opcode = AMDGPU::COPY;
   } else if (RI.isSGPRClass(RC)) {
     Opcode = AMDGPU::S_MOV_B32;
-  } else if (MO.isImm()) {
-    if (RC == &AMDGPU::VSrc_32RegClass)
-      Opcode = AMDGPU::S_MOV_B32;
   }
 
   const TargetRegisterClass *VRC = RI.getEquivalentVGPRClass(RC);
+  if (RI.getCommonSubClass(&AMDGPU::VReg_64RegClass, VRC)) {
+    VRC = &AMDGPU::VReg_64RegClass;
+  } else {
+    VRC = &AMDGPU::VReg_32RegClass;
+  }
   unsigned Reg = MRI.createVirtualRegister(VRC);
   BuildMI(*MI->getParent(), I, MI->getParent()->findDebugLoc(I), get(Opcode),
           Reg).addOperand(MO);