Skip to content

Commit c9fa319

Browse files
authored
[RISCV] Use LiveIntervals to determine if AVL dominates when coalescing (#118285)
In order to coalesce a vsetvli with a register AVL into a previous vsetvli, we need to make sure that the AVL register is reachable at the previous vsetvli. Back in pre-RA vsetvli insertion we just checked to see if the two virtual registers were the same virtual register, and then this was hacked around in the move to post-RA. We can instead use live intervals to check that the reaching definition is the same at both instructions. On its own this doesn't have much of an impact, but helps a lot in #118283 and enables coalescing in about 60 of the test cases from that PR.
1 parent c16c0e2 commit c9fa319

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,14 +1619,15 @@ bool RISCVInsertVSETVLI::canMutatePriorConfig(
16191619
}
16201620

16211621
auto &AVL = MI.getOperand(1);
1622-
auto &PrevAVL = PrevMI.getOperand(1);
16231622

1624-
// If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
1625-
// For now just check that PrevMI uses the same virtual register.
1626-
if (AVL.isReg() && AVL.getReg() != RISCV::X0 &&
1627-
(!MRI->hasOneDef(AVL.getReg()) || !PrevAVL.isReg() ||
1628-
PrevAVL.getReg() != AVL.getReg()))
1629-
return false;
1623+
// If the AVL is a register, we need to make sure its definition is the same
1624+
// at PrevMI as it was at MI.
1625+
if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
1626+
VNInfo *VNI = getVNInfoFromReg(AVL.getReg(), MI, LIS);
1627+
VNInfo *PrevVNI = getVNInfoFromReg(AVL.getReg(), PrevMI, LIS);
1628+
if (!VNI || !PrevVNI || VNI != PrevVNI)
1629+
return false;
1630+
}
16301631
}
16311632

16321633
assert(PrevMI.getOperand(2).isImm() && MI.getOperand(2).isImm());

llvm/test/CodeGen/RISCV/rvv/compressstore.ll

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -652,15 +652,14 @@ define void @test_compresstore_v64i32(ptr %p, <64 x i1> %mask, <64 x i32> %data)
652652
; RV64-NEXT: vse32.v v24, (a0)
653653
; RV64-NEXT: vsetivli zero, 4, e8, mf2, ta, ma
654654
; RV64-NEXT: vslidedown.vi v8, v0, 4
655-
; RV64-NEXT: vsetvli zero, zero, e32, m2, ta, ma
656-
; RV64-NEXT: vmv.x.s a2, v0
657655
; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
656+
; RV64-NEXT: vmv.x.s a1, v0
658657
; RV64-NEXT: vcompress.vm v24, v16, v8
659-
; RV64-NEXT: vcpop.m a1, v8
660-
; RV64-NEXT: cpopw a2, a2
661-
; RV64-NEXT: slli a2, a2, 2
662-
; RV64-NEXT: add a0, a0, a2
663-
; RV64-NEXT: vsetvli zero, a1, e32, m8, ta, ma
658+
; RV64-NEXT: vcpop.m a2, v8
659+
; RV64-NEXT: cpopw a1, a1
660+
; RV64-NEXT: slli a1, a1, 2
661+
; RV64-NEXT: add a0, a0, a1
662+
; RV64-NEXT: vsetvli zero, a2, e32, m8, ta, ma
664663
; RV64-NEXT: vse32.v v24, (a0)
665664
; RV64-NEXT: ret
666665
;

0 commit comments

Comments
 (0)