Skip to content

Commit d30269f

Browse files
committed
[Coalescer] Consider NewMI's subreg index when updating lanemask.
The code added in #116191 that updated the lanemasks for rematerialized values, checked if DefMI's destination reg had a subreg index. This seems to have missed the following case: %0:gpr32 = MOVi32imm 1 %1:gpr64 = SUBREG_TO_REG 0, %0:gpr32, %subreg.sub_32 which during rematerialization would have the following variables set: DefMI = %0:gpr32 = MOVi32imm 1 NewMI = %3.sub_32:gpr64 = MOVi32imm 1 (rematerialized value) When checking whether the lanemasks need to be generated, considering whether DefMI's destination has a subreg index is insufficient, we should look at DefMI's subreg index instead. The added tests are a bit more involved, because I was not able to reconstruct the issue without having some control flow in the test. These tests come from actual reproducers.
1 parent 5a1c186 commit d30269f

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

llvm/lib/CodeGen/RegisterCoalescer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,14 +1529,14 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
15291529
// undef %2.subreg:reg = INST %1:reg ; DefMI (rematerializable),
15301530
// ; DefSubIdx = subreg
15311531
// %3:reg = COPY %2 ; SrcIdx = DstIdx = 0
1532-
// .... = SOMEINSTR %3:reg
1532+
// .... = SOMEINSTR %3:reg, %2
15331533
//
15341534
// there are no subranges for %3 so after rematerialization we need
15351535
// to explicitly create them. Undefined subranges are removed later on.
1536-
if (DefSubIdx && !CP.getSrcIdx() && !CP.getDstIdx() &&
1537-
MRI->shouldTrackSubRegLiveness(DstReg) && !DstInt.hasSubRanges()) {
1536+
if (NewIdx && !DstInt.hasSubRanges() &&
1537+
MRI->shouldTrackSubRegLiveness(DstReg)) {
15381538
LaneBitmask FullMask = MRI->getMaxLaneMaskForVReg(DstReg);
1539-
LaneBitmask UsedLanes = TRI->getSubRegIndexLaneMask(DefSubIdx);
1539+
LaneBitmask UsedLanes = TRI->getSubRegIndexLaneMask(NewIdx);
15401540
LaneBitmask UnusedLanes = FullMask & ~UsedLanes;
15411541
VNInfo::Allocator &Alloc = LIS->getVNInfoAllocator();
15421542
DstInt.createSubRangeFrom(Alloc, UsedLanes, DstInt);

llvm/test/CodeGen/AArch64/register-coalesce-update-subranges-remat.mir

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ body: |
4343
# CHECK-DBG: %1 [32r,48B:2)[48B,320r:0)[320r,368B:1) 0@48B-phi 1@320r 2@32r
4444
# CHECK-DBG-SAME: weight:0.000000e+00
4545
# CHECK-DBG: %3 [80r,160B:2)[240r,272B:1)[288r,304B:0)[304B,320r:3) 0@288r 1@240r 2@80r 3@304B-phi
46-
# CHECK-DBG-SAME: L0000000000000080 [80r,160B:2)[288r,304B:0)[304B,320r:3) 0@288r 1@x 2@80r 3@304B-phi
46+
# CHECK-DBG-SAME: L0000000000000080 [288r,304B:0)[304B,320r:3) 0@288r 1@x 2@x 3@304B-phi
4747
# CHECK-DBG-SAME: L0000000000000040 [80r,160B:2)[240r,272B:1)[288r,304B:0)[304B,320r:3) 0@288r 1@240r 2@80r 3@304B-phi
4848
# CHECK-DBG-SAME: weight:0.000000e+00
4949
---
@@ -89,6 +89,8 @@ body: |
8989
# CHECK-DBG: %1 [32r,48B:2)[48B,304r:0)[304r,352B:1) 0@48B-phi 1@304r 2@32r
9090
# CHECK-DBG-SAME: weight:0.000000e+00
9191
# CHECK-DBG: %3 [80r,160B:2)[224r,256B:1)[272r,288B:0)[288B,304r:3) 0@272r 1@224r 2@80r 3@288B-phi
92+
# CHECK-DBG-SAME: L0000000000000080 [224r,256B:1)[272r,288B:0)[288B,304r:3) 0@272r 1@224r 2@x 3@288B-phi
93+
# CHECK-DBG-SAME: L0000000000000040 [80r,160B:2)[224r,256B:1)[272r,288B:0)[288B,304r:3) 0@272r 1@224r 2@80r 3@288B-phi
9294
# CHECK-DBG-SAME: weight:0.000000e+00
9395
---
9496
name: reproducer2

0 commit comments

Comments
 (0)