Skip to content

Commit 27f8e24

Browse files
committed
[TwoAddressInstruction] Propagate undef flags for partial defs
If part of a register (lowered from REG_SEQUENCE) is undefined then we should propagate undef flags to uses of those lanes. This is only performed when live intervals are present as it requires live intervals to correctly match uses to defs, and the primary goal is to allow precise computation of subrange intervals.
1 parent d1b473c commit 27f8e24

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

llvm/lib/CodeGen/TwoAddressInstructionPass.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,21 +1929,27 @@ eliminateRegSequence(MachineBasicBlock::iterator &MBBI) {
19291929
Register DstReg = MI.getOperand(0).getReg();
19301930

19311931
SmallVector<Register, 4> OrigRegs;
1932+
VNInfo *DefVN = nullptr;
19321933
if (LIS) {
19331934
OrigRegs.push_back(MI.getOperand(0).getReg());
19341935
for (unsigned i = 1, e = MI.getNumOperands(); i < e; i += 2)
19351936
OrigRegs.push_back(MI.getOperand(i).getReg());
1937+
if (LIS->hasInterval(DstReg)) {
1938+
DefVN = LIS->getInterval(DstReg)
1939+
.Query(LIS->getInstructionIndex(MI))
1940+
.valueOut();
1941+
}
19361942
}
19371943

1944+
LaneBitmask UndefLanes = LaneBitmask::getNone();
19381945
bool DefEmitted = false;
1939-
bool DefIsPartial = false;
19401946
for (unsigned i = 1, e = MI.getNumOperands(); i < e; i += 2) {
19411947
MachineOperand &UseMO = MI.getOperand(i);
19421948
Register SrcReg = UseMO.getReg();
19431949
unsigned SubIdx = MI.getOperand(i+1).getImm();
19441950
// Nothing needs to be inserted for undef operands.
19451951
if (UseMO.isUndef()) {
1946-
DefIsPartial = true;
1952+
UndefLanes |= TRI->getSubRegIndexLaneMask(SubIdx);
19471953
continue;
19481954
}
19491955

@@ -1991,11 +1997,25 @@ eliminateRegSequence(MachineBasicBlock::iterator &MBBI) {
19911997
MI.removeOperand(j);
19921998
} else {
19931999
if (LIS) {
1994-
// Force interval recomputation if we moved from full definition
1995-
// of register to partial.
1996-
if (DefIsPartial && LIS->hasInterval(DstReg) &&
1997-
MRI->shouldTrackSubRegLiveness(DstReg))
2000+
// Force live interval recomputation if we moved to a partial defintion
2001+
// of the register. Undef flags must be propagate to uses of undefined
2002+
// subregister for accurate interval computation.
2003+
if (UndefLanes.any() && DefVN && MRI->shouldTrackSubRegLiveness(DstReg)) {
2004+
auto &LI = LIS->getInterval(DstReg);
2005+
for (MachineOperand &UseOp : MRI->use_operands(DstReg)) {
2006+
unsigned SubReg = UseOp.getSubReg();
2007+
if (UseOp.isUndef() || !SubReg)
2008+
continue;
2009+
auto *VN =
2010+
LI.getVNInfoAt(LIS->getInstructionIndex(*UseOp.getParent()));
2011+
if (DefVN != VN)
2012+
continue;
2013+
LaneBitmask LaneMask = TRI->getSubRegIndexLaneMask(SubReg);
2014+
if ((UndefLanes & LaneMask).any())
2015+
UseOp.setIsUndef(true);
2016+
}
19982017
LIS->removeInterval(DstReg);
2018+
}
19992019
LIS->RemoveMachineInstrFromMaps(MI);
20002020
}
20012021

llvm/test/CodeGen/AMDGPU/GlobalISel/extractelement.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
22
; RUN: llc -global-isel -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GPRIDX %s
3+
; RUN: llc -global-isel -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -early-live-intervals -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,GPRIDX %s
34
; RUN: llc -global-isel -mtriple=amdgcn-mesa-mesa3d -mcpu=fiji -verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,MOVREL %s
45
; RUN: llc -global-isel -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX10PLUS,GFX10 %s
56
; RUN: llc -global-isel -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx1100 -amdgpu-enable-delay-alu=0 -verify-machineinstrs < %s | FileCheck -check-prefixes=GFX10PLUS,GFX11 %s

0 commit comments

Comments
 (0)