@@ -4486,46 +4486,46 @@ static void copyFlagsToImplicitVCC(MachineInstr &MI,
4486
4486
MachineInstr *SIInstrInfo::buildShrunkInst (MachineInstr &MI,
4487
4487
unsigned Op32) const {
4488
4488
MachineBasicBlock *MBB = MI.getParent ();
4489
+
4490
+ const MCInstrDesc &Op32Desc = get (Op32);
4489
4491
MachineInstrBuilder Inst32 =
4490
- BuildMI (*MBB, MI, MI.getDebugLoc (), get (Op32) )
4492
+ BuildMI (*MBB, MI, MI.getDebugLoc (), Op32Desc )
4491
4493
.setMIFlags (MI.getFlags ());
4492
4494
4493
4495
// Add the dst operand if the 32-bit encoding also has an explicit $vdst.
4494
4496
// For VOPC instructions, this is replaced by an implicit def of vcc.
4495
- if (AMDGPU::hasNamedOperand (Op32, AMDGPU::OpName::vdst)) {
4496
- // dst
4497
- Inst32.add (MI.getOperand (0 ));
4498
- } else if (AMDGPU::hasNamedOperand (Op32, AMDGPU::OpName::sdst)) {
4499
- // VOPCX instructions won't be writing to an explicit dst, so this should
4500
- // not fail for these instructions.
4501
- assert (((MI.getOperand (0 ).getReg () == AMDGPU::VCC) ||
4502
- (MI.getOperand (0 ).getReg () == AMDGPU::VCC_LO)) &&
4503
- " Unexpected case" );
4504
- }
4505
-
4506
- Inst32.add (*getNamedOperand (MI, AMDGPU::OpName::src0));
4507
4497
4508
- const MachineOperand *Src1 = getNamedOperand (MI, AMDGPU::OpName::src1);
4509
- if (Src1)
4510
- Inst32.add (*Src1);
4498
+ // We assume the defs of the shrunk opcode are in the same order, and the
4499
+ // shrunk opcode loses the last def (SGPR def, in the VOP3->VOPC case).
4500
+ for (int I = 0 , E = Op32Desc.getNumDefs (); I != E; ++I)
4501
+ Inst32.add (MI.getOperand (I));
4511
4502
4512
4503
const MachineOperand *Src2 = getNamedOperand (MI, AMDGPU::OpName::src2);
4513
4504
4514
- if (Src2) {
4515
- int Op32Src2Idx = AMDGPU::getNamedOperandIdx (Op32, AMDGPU::OpName::src2);
4516
- if (Op32Src2Idx != -1 ) {
4517
- Inst32.add (*Src2);
4518
- } else {
4519
- // In the case of V_CNDMASK_B32_e32, the explicit operand src2 is
4520
- // replaced with an implicit read of vcc or vcc_lo. The implicit read
4521
- // of vcc was already added during the initial BuildMI, but we
4522
- // 1) may need to change vcc to vcc_lo to preserve the original register
4523
- // 2) have to preserve the original flags.
4524
- fixImplicitOperands (*Inst32);
4525
- copyFlagsToImplicitVCC (*Inst32, *Src2);
4505
+ int Idx = MI.getNumExplicitDefs ();
4506
+ for (const MachineOperand &Use : MI.explicit_uses ()) {
4507
+ int OpTy = MI.getDesc ().operands ()[Idx++].OperandType ;
4508
+ if (OpTy == AMDGPU::OPERAND_INPUT_MODS || OpTy == MCOI::OPERAND_IMMEDIATE)
4509
+ continue ;
4510
+
4511
+ if (&Use == Src2) {
4512
+ if (AMDGPU::getNamedOperandIdx (Op32, AMDGPU::OpName::src2) == -1 ) {
4513
+ // In the case of V_CNDMASK_B32_e32, the explicit operand src2 is
4514
+ // replaced with an implicit read of vcc or vcc_lo. The implicit read
4515
+ // of vcc was already added during the initial BuildMI, but we
4516
+ // 1) may need to change vcc to vcc_lo to preserve the original register
4517
+ // 2) have to preserve the original flags.
4518
+ fixImplicitOperands (*Inst32);
4519
+ copyFlagsToImplicitVCC (*Inst32, *Src2);
4520
+ continue ;
4521
+ }
4526
4522
}
4523
+
4524
+ Inst32.add (Use);
4527
4525
}
4528
4526
4527
+ // FIXME: Losing implicit operands
4528
+
4529
4529
return Inst32;
4530
4530
}
4531
4531
0 commit comments