[llvm] r218527 - R600/SI: Fix using wrong operand indices when commuting
Matt Arsenault
Matthew.Arsenault at amd.com
Fri Sep 26 10:54:44 PDT 2014
Author: arsenm
Date: Fri Sep 26 12:54:43 2014
New Revision: 218527
URL: http://llvm.org/viewvc/llvm-project?rev=218527&view=rev
Log:
R600/SI: Fix using wrong operand indices when commuting
No test since the current SIISelLowering::legalizeOperands
effectively hides this, and the general uses seem to only fire
on SALU instructions which don't have modifiers between
the operands.
When trying to use legalizeOperands immediately after
instruction selection, it now sees a lot more patterns
it did not see before which break on this.
Modified:
llvm/trunk/lib/Target/R600/SIInstrInfo.cpp
llvm/trunk/test/CodeGen/R600/llvm.AMDGPU.clamp.ll
Modified: llvm/trunk/lib/Target/R600/SIInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/R600/SIInstrInfo.cpp?rev=218527&r1=218526&r2=218527&view=diff
==============================================================================
--- llvm/trunk/lib/Target/R600/SIInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/R600/SIInstrInfo.cpp Fri Sep 26 12:54:43 2014
@@ -684,19 +684,28 @@ bool SIInstrInfo::expandPostRAPseudo(Mac
MachineInstr *SIInstrInfo::commuteInstruction(MachineInstr *MI,
bool NewMI) const {
+ if (MI->getNumOperands() < 3)
+ return nullptr;
+
+ int Src0Idx = AMDGPU::getNamedOperandIdx(MI->getOpcode(),
+ AMDGPU::OpName::src0);
+ assert(Src0Idx != -1 && "Should always have src0 operand");
- if (MI->getNumOperands() < 3 || !MI->getOperand(1).isReg())
+ if (!MI->getOperand(Src0Idx).isReg())
return nullptr;
+ int Src1Idx = AMDGPU::getNamedOperandIdx(MI->getOpcode(),
+ AMDGPU::OpName::src1);
+
// Make sure it s legal to commute operands for VOP2.
- if (isVOP2(MI->getOpcode()) &&
- (!isOperandLegal(MI, 1, &MI->getOperand(2)) ||
- !isOperandLegal(MI, 2, &MI->getOperand(1))))
+ if ((Src1Idx != -1) && isVOP2(MI->getOpcode()) &&
+ (!isOperandLegal(MI, Src0Idx, &MI->getOperand(Src1Idx)) ||
+ !isOperandLegal(MI, Src1Idx, &MI->getOperand(Src0Idx))))
return nullptr;
- if (!MI->getOperand(2).isReg()) {
+ if (Src1Idx != -1 && !MI->getOperand(Src1Idx).isReg()) {
// XXX: Commute instructions with FPImm operands
- if (NewMI || MI->getOperand(2).isFPImm() ||
+ if (NewMI || MI->getOperand(Src1Idx).isFPImm() ||
(!isVOP2(MI->getOpcode()) && !isVOP3(MI->getOpcode()))) {
return nullptr;
}
@@ -716,11 +725,11 @@ MachineInstr *SIInstrInfo::commuteInstru
(Src2Mods && Src2Mods->getImm()))
return nullptr;
- unsigned Reg = MI->getOperand(1).getReg();
- unsigned SubReg = MI->getOperand(1).getSubReg();
- MI->getOperand(1).ChangeToImmediate(MI->getOperand(2).getImm());
- MI->getOperand(2).ChangeToRegister(Reg, false);
- MI->getOperand(2).setSubReg(SubReg);
+ unsigned Reg = MI->getOperand(Src0Idx).getReg();
+ unsigned SubReg = MI->getOperand(Src0Idx).getSubReg();
+ MI->getOperand(Src0Idx).ChangeToImmediate(MI->getOperand(Src1Idx).getImm());
+ MI->getOperand(Src1Idx).ChangeToRegister(Reg, false);
+ MI->getOperand(Src1Idx).setSubReg(SubReg);
} else {
MI = TargetInstrInfo::commuteInstruction(MI, NewMI);
}
Modified: llvm/trunk/test/CodeGen/R600/llvm.AMDGPU.clamp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/R600/llvm.AMDGPU.clamp.ll?rev=218527&r1=218526&r2=218527&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/R600/llvm.AMDGPU.clamp.ll (original)
+++ llvm/trunk/test/CodeGen/R600/llvm.AMDGPU.clamp.ll Fri Sep 26 12:54:43 2014
@@ -6,7 +6,7 @@ declare float @llvm.AMDIL.clamp.f32(floa
; FUNC-LABEL: @clamp_0_1_f32
; SI: S_LOAD_DWORD [[ARG:s[0-9]+]],
-; SI: V_ADD_F32_e64 [[RESULT:v[0-9]+]], [[ARG]], 0, 1, 0
+; SI: V_ADD_F32_e64 [[RESULT:v[0-9]+]], 0, [[ARG]], 1, 0
; SI: BUFFER_STORE_DWORD [[RESULT]]
; SI: S_ENDPGM
@@ -19,7 +19,7 @@ define void @clamp_0_1_f32(float addrspa
; FUNC-LABEL: @clamp_0_1_amdil_legacy_f32
; SI: S_LOAD_DWORD [[ARG:s[0-9]+]],
-; SI: V_ADD_F32_e64 [[RESULT:v[0-9]+]], [[ARG]], 0, 1, 0
+; SI: V_ADD_F32_e64 [[RESULT:v[0-9]+]], 0, [[ARG]], 1, 0
; SI: BUFFER_STORE_DWORD [[RESULT]]
define void @clamp_0_1_amdil_legacy_f32(float addrspace(1)* %out, float %src) nounwind {
%clamp = call float @llvm.AMDIL.clamp.f32(float %src, float 0.0, float 1.0) nounwind readnone
More information about the llvm-commits
mailing list