Skip to content

Commit ec4f2a0

Browse files
committed
AMDGPU: Support commuting a FrameIndex operand
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281369 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 470b8e4 commit ec4f2a0

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

include/llvm/CodeGen/MachineOperand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,9 @@ class MachineOperand {
593593
/// ChangeToMCSymbol - Replace this operand with a new MC symbol operand.
594594
void ChangeToMCSymbol(MCSymbol *Sym);
595595

596+
/// Replace this operand with a frame index.
597+
void ChangeToFrameIndex(int Idx);
598+
596599
/// ChangeToRegister - Replace this operand with a new register operand of
597600
/// the specified value. If an operand is known to be an register already,
598601
/// the setReg method should be used.

lib/CodeGen/MachineInstr.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,16 @@ void MachineOperand::ChangeToMCSymbol(MCSymbol *Sym) {
175175
Contents.Sym = Sym;
176176
}
177177

178+
void MachineOperand::ChangeToFrameIndex(int Idx) {
179+
assert((!isReg() || !isTied()) &&
180+
"Cannot change a tied operand into a FrameIndex");
181+
182+
removeRegFromUses();
183+
184+
OpKind = MO_FrameIndex;
185+
setIndex(Idx);
186+
}
187+
178188
/// ChangeToRegister - Replace this operand with a new register operand of
179189
/// the specified value. If an operand is known to be an register already,
180190
/// the setReg method should be used.

lib/Target/AMDGPU/SIInstrInfo.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -937,17 +937,24 @@ bool SIInstrInfo::swapSourceModifiers(MachineInstr &MI,
937937

938938
static MachineInstr *swapRegAndNonRegOperand(MachineInstr &MI,
939939
MachineOperand &RegOp,
940-
MachineOperand &ImmOp) {
941-
// TODO: Handle other immediate like types.
942-
if (!ImmOp.isImm())
940+
MachineOperand &NonRegOp) {
941+
unsigned Reg = RegOp.getReg();
942+
unsigned SubReg = RegOp.getSubReg();
943+
bool IsKill = RegOp.isKill();
944+
bool IsDead = RegOp.isDead();
945+
bool IsUndef = RegOp.isUndef();
946+
bool IsDebug = RegOp.isDebug();
947+
948+
if (NonRegOp.isImm())
949+
RegOp.ChangeToImmediate(NonRegOp.getImm());
950+
else if (NonRegOp.isFI())
951+
RegOp.ChangeToFrameIndex(NonRegOp.getIndex());
952+
else
943953
return nullptr;
944954

945-
int64_t ImmVal = ImmOp.getImm();
946-
ImmOp.ChangeToRegister(RegOp.getReg(), false, false,
947-
RegOp.isKill(), RegOp.isDead(), RegOp.isUndef(),
948-
RegOp.isDebug());
949-
ImmOp.setSubReg(RegOp.getSubReg());
950-
RegOp.ChangeToImmediate(ImmVal);
955+
NonRegOp.ChangeToRegister(Reg, false, false, IsKill, IsDead, IsUndef, IsDebug);
956+
NonRegOp.setSubReg(SubReg);
957+
951958
return &MI;
952959
}
953960

test/CodeGen/AMDGPU/commute-compares.ll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,5 +693,20 @@ define void @commute_uno_2.0_f64(i32 addrspace(1)* %out, double addrspace(1)* %i
693693
ret void
694694
}
695695

696+
; Without commuting the frame index in the pre-regalloc run of
697+
; SIShrinkInstructions, this was using the VOP3 compare.
698+
699+
; GCN-LABEL: {{^}}commute_frameindex:
700+
; GCN: v_cmp_eq_i32_e32 vcc, 0, v{{[0-9]+}}
701+
define void @commute_frameindex(i32 addrspace(1)* nocapture %out) #0 {
702+
entry:
703+
%stack0 = alloca i32
704+
%ptr0 = load volatile i32*, i32* addrspace(1)* undef
705+
%eq = icmp eq i32* %ptr0, %stack0
706+
%ext = zext i1 %eq to i32
707+
store volatile i32 %ext, i32 addrspace(1)* %out
708+
ret void
709+
}
710+
696711
attributes #0 = { nounwind readnone }
697712
attributes #1 = { nounwind }

0 commit comments

Comments
 (0)