Skip to content

Commit d89d45c

Browse files
committed
[RISCV][InsertVSETVLI] Default to MA not MU
This changes the default value used for mask policy from mask undisturbed to mask agnostic. In hardware, there may be a minor preference for ta/ma, but since this is only going to apply to instructions which don't use the mask policy bit, this is functionally mostly a nop. The main value is to make future changes to using MA when legal for masked instructions easier to review by reducing test churn. The prior code was motivated by a desire to minimize state transitions between masked and unmasked code. This patch achieves the same effect using the demanded field logic (landed in afb45ff), and there are no regressions I spotted in the test diffs. (Given the size, I have only been able to skim.) I do want to call out that regressions are possible here; the demanded analysis only works on a block local scope right now, so e.g. a tight loop mixing masked and unmasked computation might see an extra vsetvli or two. Differential Revision: https://reviews.llvm.org/D133803
1 parent 79df8e1 commit d89d45c

File tree

696 files changed

+41605
-41602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

696 files changed

+41605
-41602
lines changed

llvm/lib/Target/RISCV/RISCVInsertVSETVLI.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -773,13 +773,7 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
773773
// destination is tied to a source. Unless the source is undef. In that case
774774
// the user would have some control over the policy values.
775775
bool TailAgnostic = true;
776-
bool UsesMaskPolicy = RISCVII::usesMaskPolicy(TSFlags);
777-
// FIXME: Could we look at the above or below instructions to choose the
778-
// matched mask policy to reduce vsetvli instructions? Default mask policy is
779-
// agnostic if instructions use mask policy, otherwise is undisturbed. Because
780-
// most mask operations are mask undisturbed, so we could possibly reduce the
781-
// vsetvli between mask and nomasked instruction sequence.
782-
bool MaskAgnostic = UsesMaskPolicy;
776+
bool MaskAgnostic = true;
783777
unsigned UseOpIdx;
784778
if (RISCVII::hasVecPolicyOp(TSFlags)) {
785779
const MachineOperand &Op = MI.getOperand(MI.getNumExplicitOperands() - 1);
@@ -794,22 +788,23 @@ static VSETVLIInfo computeInfoForInstr(const MachineInstr &MI, uint64_t TSFlags,
794788
MaskAgnostic = Policy & RISCVII::MASK_AGNOSTIC;
795789
} else if (MI.isRegTiedToUseOperand(0, &UseOpIdx)) {
796790
TailAgnostic = false;
797-
if (UsesMaskPolicy)
798-
MaskAgnostic = false;
791+
MaskAgnostic = false;
799792
// If the tied operand is an IMPLICIT_DEF we can keep TailAgnostic.
800793
const MachineOperand &UseMO = MI.getOperand(UseOpIdx);
801794
MachineInstr *UseMI = MRI->getVRegDef(UseMO.getReg());
802795
if (UseMI && UseMI->isImplicitDef()) {
803796
TailAgnostic = true;
804-
if (UsesMaskPolicy)
805-
MaskAgnostic = true;
797+
MaskAgnostic = true;
806798
}
807799
// Some pseudo instructions force a tail agnostic policy despite having a
808800
// tied def.
809801
if (RISCVII::doesForceTailAgnostic(TSFlags))
810802
TailAgnostic = true;
811803
}
812804

805+
if (!RISCVII::usesMaskPolicy(TSFlags))
806+
MaskAgnostic = true;
807+
813808
RISCVII::VLMUL VLMul = RISCVII::getLMul(TSFlags);
814809

815810
unsigned Log2SEW = MI.getOperand(getSEWOpNum(MI)).getImm();

llvm/test/CodeGen/RISCV/early-clobber-tied-def-subreg-liveness.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ define void @_Z3foov() {
2222
; CHECK-NEXT: sub sp, sp, a0
2323
; CHECK-NEXT: lui a0, %hi(.L__const._Z3foov.var_49)
2424
; CHECK-NEXT: addi a0, a0, %lo(.L__const._Z3foov.var_49)
25-
; CHECK-NEXT: vsetivli zero, 2, e16, m2, ta, mu
25+
; CHECK-NEXT: vsetivli zero, 2, e16, m2, ta, ma
2626
; CHECK-NEXT: vle16.v v8, (a0)
2727
; CHECK-NEXT: lui a0, %hi(.L__const._Z3foov.var_48)
2828
; CHECK-NEXT: addi a0, a0, %lo(.L__const._Z3foov.var_48)
@@ -52,7 +52,7 @@ define void @_Z3foov() {
5252
; CHECK-NEXT: #NO_APP
5353
; CHECK-NEXT: lui a0, %hi(.L__const._Z3foov.var_44)
5454
; CHECK-NEXT: addi a0, a0, %lo(.L__const._Z3foov.var_44)
55-
; CHECK-NEXT: vsetivli zero, 2, e16, m2, ta, mu
55+
; CHECK-NEXT: vsetivli zero, 2, e16, m2, ta, ma
5656
; CHECK-NEXT: addi a1, sp, 16
5757
; CHECK-NEXT: csrr a2, vlenb
5858
; CHECK-NEXT: slli a2, a2, 1

llvm/test/CodeGen/RISCV/fold-vector-cmp.ll

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ define i32 @test(i32 %call.i) {
1313
; CHECK-V-LABEL: test:
1414
; CHECK-V: # %bb.0:
1515
; CHECK-V-NEXT: lui a1, 524288
16-
; CHECK-V-NEXT: vsetivli zero, 2, e32, mf2, ta, mu
16+
; CHECK-V-NEXT: vsetivli zero, 2, e32, mf2, ta, ma
1717
; CHECK-V-NEXT: vmv.v.x v8, a1
18-
; CHECK-V-NEXT: vsetvli zero, zero, e32, mf2, tu, mu
18+
; CHECK-V-NEXT: vsetvli zero, zero, e32, mf2, tu, ma
1919
; CHECK-V-NEXT: vmv.s.x v8, a0
2020
; CHECK-V-NEXT: addiw a0, a1, 2
21-
; CHECK-V-NEXT: vsetvli zero, zero, e32, mf2, ta, mu
21+
; CHECK-V-NEXT: vsetvli zero, zero, e32, mf2, ta, ma
2222
; CHECK-V-NEXT: vmslt.vx v0, v8, a0
2323
; CHECK-V-NEXT: vmv.v.i v8, 0
2424
; CHECK-V-NEXT: vmerge.vim v8, v8, 1, v0
25-
; CHECK-V-NEXT: vsetivli zero, 1, e32, mf2, ta, mu
25+
; CHECK-V-NEXT: vsetivli zero, 1, e32, mf2, ta, ma
2626
; CHECK-V-NEXT: vslidedown.vi v8, v8, 1
2727
; CHECK-V-NEXT: vmv.x.s a0, v8
2828
; CHECK-V-NEXT: ret

0 commit comments

Comments
 (0)