Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
AMDGPU: Fix violating constant bus restriction
Browse files Browse the repository at this point in the history
You can't use madmk/madmk if it already uses an SGPR input.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313298 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
arsenm committed Sep 14, 2017
1 parent 028255f commit 11283fb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Target/AMDGPU/SIInstrInfo.cpp
Expand Up @@ -2150,9 +2150,8 @@ static int64_t getFoldableImm(const MachineOperand* MO) {
const MachineFunction *MF = MO->getParent()->getParent()->getParent();
const MachineRegisterInfo &MRI = MF->getRegInfo();
auto Def = MRI.getUniqueVRegDef(MO->getReg());
if (Def && (Def->getOpcode() == AMDGPU::S_MOV_B32 ||
Def->getOpcode() == AMDGPU::V_MOV_B32_e32) &&
Def->getOperand(1).isImm())
if (Def && Def->getOpcode() == AMDGPU::V_MOV_B32_e32 &&
Def->getOperand(1).isImm())
return Def->getOperand(1).getImm();
return AMDGPU::NoRegister;
}
Expand Down Expand Up @@ -2194,7 +2193,9 @@ MachineInstr *SIInstrInfo::convertToThreeAddress(MachineFunction::iterator &MBB,
const MachineOperand *Clamp = getNamedOperand(MI, AMDGPU::OpName::clamp);
const MachineOperand *Omod = getNamedOperand(MI, AMDGPU::OpName::omod);

if (!Src0Mods && !Src1Mods && !Clamp && !Omod) {
if (!Src0Mods && !Src1Mods && !Clamp && !Omod &&
// If we have an SGPR input, we will violate the constant bus restriction.
!RI.isSGPRReg(MBB->getParent()->getRegInfo(), Src0->getReg())) {
if (auto Imm = getFoldableImm(Src2)) {
return BuildMI(*MBB, MI, MI.getDebugLoc(),
get(IsF16 ? AMDGPU::V_MADAK_F16 : AMDGPU::V_MADAK_F32))
Expand Down
22 changes: 22 additions & 0 deletions test/CodeGen/AMDGPU/twoaddr-mad.mir
Expand Up @@ -108,3 +108,25 @@ body: |
%1 = V_MOV_B32_e32 1078523331, implicit %exec
%2 = V_MAC_F16_e32 killed %0.sub0, %0.sub1, %1, implicit %exec
...

# Make sure constant bus restriction isn't violated if src0 is an SGPR.

# GCN-LABEL: name: test_madak_sgpr_src0_f32
# GCN: %1 = V_MOV_B32_e32 1078523331, implicit %exec
# GCN: %2 = V_MAD_F32 0, killed %0, 0, %1, 0, %3, 0, 0, implicit %exec

---
name: test_madak_sgpr_src0_f32
registers:
- { id: 0, class: sreg_32_xm0 }
- { id: 1, class: vgpr_32}
- { id: 2, class: vgpr_32 }
- { id: 3, class: vgpr_32 }
body: |
bb.0:
%0 = IMPLICIT_DEF
%1 = V_MOV_B32_e32 1078523331, implicit %exec
%2 = V_MAC_F32_e32 killed %0, %1, %3, implicit %exec
...

0 comments on commit 11283fb

Please sign in to comment.