[llvm] r281369 - AMDGPU: Support commuting a FrameIndex operand
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 13 12:03:13 PDT 2016
Author: arsenm
Date: Tue Sep 13 14:03:12 2016
New Revision: 281369
URL: http://llvm.org/viewvc/llvm-project?rev=281369&view=rev
Log:
AMDGPU: Support commuting a FrameIndex operand
Modified:
llvm/trunk/include/llvm/CodeGen/MachineOperand.h
llvm/trunk/lib/CodeGen/MachineInstr.cpp
llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
llvm/trunk/test/CodeGen/AMDGPU/commute-compares.ll
Modified: llvm/trunk/include/llvm/CodeGen/MachineOperand.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/MachineOperand.h?rev=281369&r1=281368&r2=281369&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/MachineOperand.h (original)
+++ llvm/trunk/include/llvm/CodeGen/MachineOperand.h Tue Sep 13 14:03:12 2016
@@ -593,6 +593,9 @@ public:
/// ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
void ChangeToMCSymbol(MCSymbol *Sym);
+ /// Replace this operand with a frame index.
+ void ChangeToFrameIndex(int Idx);
+
/// ChangeToRegister - Replace this operand with a new register operand of
/// the specified value. If an operand is known to be an register already,
/// the setReg method should be used.
Modified: llvm/trunk/lib/CodeGen/MachineInstr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/MachineInstr.cpp?rev=281369&r1=281368&r2=281369&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/MachineInstr.cpp (original)
+++ llvm/trunk/lib/CodeGen/MachineInstr.cpp Tue Sep 13 14:03:12 2016
@@ -175,6 +175,16 @@ void MachineOperand::ChangeToMCSymbol(MC
Contents.Sym = Sym;
}
+void MachineOperand::ChangeToFrameIndex(int Idx) {
+ assert((!isReg() || !isTied()) &&
+ "Cannot change a tied operand into a FrameIndex");
+
+ removeRegFromUses();
+
+ OpKind = MO_FrameIndex;
+ setIndex(Idx);
+}
+
/// ChangeToRegister - Replace this operand with a new register operand of
/// the specified value. If an operand is known to be an register already,
/// the setReg method should be used.
Modified: llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp?rev=281369&r1=281368&r2=281369&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp (original)
+++ llvm/trunk/lib/Target/AMDGPU/SIInstrInfo.cpp Tue Sep 13 14:03:12 2016
@@ -937,17 +937,24 @@ bool SIInstrInfo::swapSourceModifiers(Ma
static MachineInstr *swapRegAndNonRegOperand(MachineInstr &MI,
MachineOperand &RegOp,
- MachineOperand &ImmOp) {
- // TODO: Handle other immediate like types.
- if (!ImmOp.isImm())
+ MachineOperand &NonRegOp) {
+ unsigned Reg = RegOp.getReg();
+ unsigned SubReg = RegOp.getSubReg();
+ bool IsKill = RegOp.isKill();
+ bool IsDead = RegOp.isDead();
+ bool IsUndef = RegOp.isUndef();
+ bool IsDebug = RegOp.isDebug();
+
+ if (NonRegOp.isImm())
+ RegOp.ChangeToImmediate(NonRegOp.getImm());
+ else if (NonRegOp.isFI())
+ RegOp.ChangeToFrameIndex(NonRegOp.getIndex());
+ else
return nullptr;
- int64_t ImmVal = ImmOp.getImm();
- ImmOp.ChangeToRegister(RegOp.getReg(), false, false,
- RegOp.isKill(), RegOp.isDead(), RegOp.isUndef(),
- RegOp.isDebug());
- ImmOp.setSubReg(RegOp.getSubReg());
- RegOp.ChangeToImmediate(ImmVal);
+ NonRegOp.ChangeToRegister(Reg, false, false, IsKill, IsDead, IsUndef, IsDebug);
+ NonRegOp.setSubReg(SubReg);
+
return &MI;
}
Modified: llvm/trunk/test/CodeGen/AMDGPU/commute-compares.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/commute-compares.ll?rev=281369&r1=281368&r2=281369&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/commute-compares.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/commute-compares.ll Tue Sep 13 14:03:12 2016
@@ -693,5 +693,20 @@ define void @commute_uno_2.0_f64(i32 add
ret void
}
+; Without commuting the frame index in the pre-regalloc run of
+; SIShrinkInstructions, this was using the VOP3 compare.
+
+; GCN-LABEL: {{^}}commute_frameindex:
+; GCN: v_cmp_eq_i32_e32 vcc, 0, v{{[0-9]+}}
+define void @commute_frameindex(i32 addrspace(1)* nocapture %out) #0 {
+entry:
+ %stack0 = alloca i32
+ %ptr0 = load volatile i32*, i32* addrspace(1)* undef
+ %eq = icmp eq i32* %ptr0, %stack0
+ %ext = zext i1 %eq to i32
+ store volatile i32 %ext, i32 addrspace(1)* %out
+ ret void
+}
+
attributes #0 = { nounwind readnone }
attributes #1 = { nounwind }
More information about the llvm-commits
mailing list