Skip to content

Commit e879002

Browse files
authored
[RISCV] Allow vsetvlis with same register AVL in doLocalPostpass (#76801)
1 parent be76f16 commit e879002

File tree

3 files changed

+17
-29
lines changed

3 files changed

+17
-29
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,20 +1464,6 @@ static void doUnion(DemandedFields &A, DemandedFields B) {
14641464
A.MaskPolicy |= B.MaskPolicy;
14651465
}
14661466

1467-
static bool isNonZeroAVL(const MachineOperand &MO,
1468-
const MachineRegisterInfo &MRI) {
1469-
if (MO.isReg()) {
1470-
if (MO.getReg() == RISCV::X0)
1471-
return true;
1472-
if (MachineInstr *MI = MRI.getVRegDef(MO.getReg());
1473-
MI && isNonZeroLoadImmediate(*MI))
1474-
return true;
1475-
return false;
1476-
}
1477-
assert(MO.isImm());
1478-
return 0 != MO.getImm();
1479-
}
1480-
14811467
// Return true if we can mutate PrevMI to match MI without changing any the
14821468
// fields which would be observed.
14831469
static bool canMutatePriorConfig(const MachineInstr &PrevMI,
@@ -1491,21 +1477,26 @@ static bool canMutatePriorConfig(const MachineInstr &PrevMI,
14911477
if (Used.VLAny)
14921478
return false;
14931479

1494-
// We don't bother to handle the equally zero case here as it's largely
1495-
// uninteresting.
14961480
if (Used.VLZeroness) {
14971481
if (isVLPreservingConfig(PrevMI))
14981482
return false;
1499-
if (!isNonZeroAVL(MI.getOperand(1), MRI) ||
1500-
!isNonZeroAVL(PrevMI.getOperand(1), MRI))
1483+
if (!getInfoForVSETVLI(PrevMI).hasEquallyZeroAVL(getInfoForVSETVLI(MI),
1484+
MRI))
15011485
return false;
15021486
}
15031487

1504-
// TODO: Track whether the register is defined between
1505-
// PrevMI and MI.
1506-
if (MI.getOperand(1).isReg() &&
1507-
RISCV::X0 != MI.getOperand(1).getReg())
1508-
return false;
1488+
auto &AVL = MI.getOperand(1);
1489+
auto &PrevAVL = PrevMI.getOperand(1);
1490+
assert(MRI.isSSA());
1491+
1492+
// If the AVL is a register, we need to make sure MI's AVL dominates PrevMI.
1493+
// For now just check that PrevMI uses the same virtual register.
1494+
if (AVL.isReg() && AVL.getReg() != RISCV::X0) {
1495+
if (AVL.getReg().isPhysical())
1496+
return false;
1497+
if (!PrevAVL.isReg() || PrevAVL.getReg() != AVL.getReg())
1498+
return false;
1499+
}
15091500
}
15101501

15111502
if (!PrevMI.getOperand(2).isImm() || !MI.getOperand(2).isImm())

llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert.ll

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ define <32 x i32> @insertelt_v32i32_31(<32 x i32> %a, i32 %y) {
6363
; CHECK-LABEL: insertelt_v32i32_31:
6464
; CHECK: # %bb.0:
6565
; CHECK-NEXT: li a1, 32
66-
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
67-
; CHECK-NEXT: vmv.s.x v16, a0
6866
; CHECK-NEXT: vsetvli zero, a1, e32, m8, ta, ma
67+
; CHECK-NEXT: vmv.s.x v16, a0
6968
; CHECK-NEXT: vslideup.vi v8, v16, 31
7069
; CHECK-NEXT: ret
7170
%b = insertelement <32 x i32> %a, i32 %y, i32 31
@@ -101,9 +100,8 @@ define <64 x i32> @insertelt_v64i32_63(<64 x i32> %a, i32 %y) {
101100
; CHECK-LABEL: insertelt_v64i32_63:
102101
; CHECK: # %bb.0:
103102
; CHECK-NEXT: li a1, 32
104-
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
105-
; CHECK-NEXT: vmv.s.x v24, a0
106103
; CHECK-NEXT: vsetvli zero, a1, e32, m8, ta, ma
104+
; CHECK-NEXT: vmv.s.x v24, a0
107105
; CHECK-NEXT: vslideup.vi v16, v24, 31
108106
; CHECK-NEXT: ret
109107
%b = insertelement <64 x i32> %a, i32 %y, i32 63

llvm/test/CodeGen/RISCV/rvv/vsetvli-insert.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,9 +643,8 @@ define <vscale x 2 x float> @fp_reduction_vfmv_s_f(float %0, <vscale x 8 x float
643643
define dso_local <vscale x 2 x i32> @int_reduction_vmv_s_x(i32 signext %0, <vscale x 8 x i32> %1, i64 %2) {
644644
; CHECK-LABEL: int_reduction_vmv_s_x:
645645
; CHECK: # %bb.0:
646-
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
647-
; CHECK-NEXT: vmv.s.x v12, a0
648646
; CHECK-NEXT: vsetvli zero, a1, e32, m4, ta, ma
647+
; CHECK-NEXT: vmv.s.x v12, a0
649648
; CHECK-NEXT: vredsum.vs v8, v8, v12
650649
; CHECK-NEXT: ret
651650
%4 = tail call <vscale x 8 x i32> @llvm.riscv.vmv.s.x.nxv8i32.i64(<vscale x 8 x i32> poison, i32 %0, i64 %2)

0 commit comments

Comments
 (0)