diff options
author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-10-06 17:54:30 +0000 |
---|---|---|
committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2016-10-06 17:54:30 +0000 |
commit | c2ee42cd16213e896947b9e1ee1c30defa006f99 (patch) | |
tree | 2aff178ca11ab25f3514ccb5d081ec0d7b0ed16c /llvm/lib | |
parent | 11f740207561c27fb1301e5eba00ba869696bbd0 (diff) | |
download | bcm5719-llvm-c2ee42cd16213e896947b9e1ee1c30defa006f99.tar.gz bcm5719-llvm-c2ee42cd16213e896947b9e1ee1c30defa006f99.zip |
AMDGPU: Remove leftover implicit operands when folding immediates
When constant folding an operation to a copy or an immediate
mov, the implicit uses/defs of the old instruction were left behind,
e.g. replacing v_or_b32 left the implicit exec use on the new copy.
llvm-svn: 283471
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp index 39eaf75568c..f16efcd3af5 100644 --- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp +++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp @@ -343,6 +343,24 @@ static unsigned getMovOpc(bool IsScalar) { return IsScalar ? AMDGPU::S_MOV_B32 : AMDGPU::V_MOV_B32_e32; } +/// Remove any leftover implicit operands from mutating the instruction. e.g. +/// if we replace an s_and_b32 with a copy, we don't need the implicit scc def +/// anymore. +static void stripExtraCopyOperands(MachineInstr &MI) { + const MCInstrDesc &Desc = MI.getDesc(); + unsigned NumOps = Desc.getNumOperands() + + Desc.getNumImplicitUses() + + Desc.getNumImplicitDefs(); + + for (unsigned I = MI.getNumOperands() - 1; I >= NumOps; --I) + MI.RemoveOperand(I); +} + +static void mutateCopyOp(MachineInstr &MI, const MCInstrDesc &NewDesc) { + MI.setDesc(NewDesc); + stripExtraCopyOperands(MI); +} + // Try to simplify operations with a constant that may appear after instruction // selection. static bool tryConstantFoldOp(MachineRegisterInfo &MRI, @@ -355,7 +373,7 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI, MachineOperand &Src0 = MI->getOperand(1); if (Src0.isImm()) { Src0.setImm(~Src0.getImm()); - MI->setDesc(TII->get(getMovOpc(Opc == AMDGPU::S_NOT_B32))); + mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_NOT_B32))); return true; } @@ -386,7 +404,7 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI, Src0->setImm(NewImm); MI->RemoveOperand(Src1Idx); - MI->setDesc(TII->get(getMovOpc(IsSGPR))); + mutateCopyOp(*MI, TII->get(getMovOpc(IsSGPR))); return true; } @@ -400,11 +418,11 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI, if (Src1Val == 0) { // y = or x, 0 => y = copy x MI->RemoveOperand(Src1Idx); - MI->setDesc(TII->get(AMDGPU::COPY)); + mutateCopyOp(*MI, TII->get(AMDGPU::COPY)); } else if (Src1Val == -1) { // y = or x, -1 => y = v_mov_b32 -1 MI->RemoveOperand(Src1Idx); - MI->setDesc(TII->get(getMovOpc(Opc == AMDGPU::S_OR_B32))); + mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_OR_B32))); } else return false; @@ -416,11 +434,12 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI, if (Src1Val == 0) { // y = and x, 0 => y = v_mov_b32 0 MI->RemoveOperand(Src0Idx); - MI->setDesc(TII->get(getMovOpc(Opc == AMDGPU::S_AND_B32))); + mutateCopyOp(*MI, TII->get(getMovOpc(Opc == AMDGPU::S_AND_B32))); } else if (Src1Val == -1) { // y = and x, -1 => y = copy x MI->RemoveOperand(Src1Idx); - MI->setDesc(TII->get(AMDGPU::COPY)); + mutateCopyOp(*MI, TII->get(AMDGPU::COPY)); + stripExtraCopyOperands(*MI); } else return false; @@ -432,7 +451,7 @@ static bool tryConstantFoldOp(MachineRegisterInfo &MRI, if (Src1Val == 0) { // y = xor x, 0 => y = copy x MI->RemoveOperand(Src1Idx); - MI->setDesc(TII->get(AMDGPU::COPY)); + mutateCopyOp(*MI, TII->get(AMDGPU::COPY)); } } |