[llvm] 6c607cf - [RISCV] Preserve tail agnostic policy in foldVMV_V_V (#105788)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 3 21:57:13 PDT 2024
Author: Luke Lau
Date: 2024-09-04T12:57:09+08:00
New Revision: 6c607cfb2c2d8acd2b92d7ed8106ab1e4fc0d79d
URL: https://github.com/llvm/llvm-project/commit/6c607cfb2c2d8acd2b92d7ed8106ab1e4fc0d79d
DIFF: https://github.com/llvm/llvm-project/commit/6c607cfb2c2d8acd2b92d7ed8106ab1e4fc0d79d.diff
LOG: [RISCV] Preserve tail agnostic policy in foldVMV_V_V (#105788)
This patch helps avoid regressions in an upcoming patch by making sure
we don't accidentally lose a tail agnostic policy when folding a vmv.v.v
into its source.
The previous comment about RISCVInsertVSETVLI relaxing the policy didn't
take into account the fact that there's a policy operand on vmv.v.v,
which can be tail agnostic.
If the tail is agnostic (via either the policy operand or the passthru
being undef) and vmv.v.v's VL <= Src's VL, then Src's tail can be made
agnostic.
Added:
Modified:
llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.mir
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
index 412fd790061a37..35c3bc9708d91a 100644
--- a/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
+++ b/llvm/lib/Target/RISCV/RISCVVectorPeephole.cpp
@@ -529,10 +529,13 @@ bool RISCVVectorPeephole::foldVMV_V_V(MachineInstr &MI) {
*Src->getParent()->getParent()));
}
- // Use a conservative tu,mu policy, RISCVInsertVSETVLI will relax it if
- // passthru is undef.
- Src->getOperand(RISCVII::getVecPolicyOpNum(Src->getDesc()))
- .setImm(RISCVII::TAIL_UNDISTURBED_MASK_UNDISTURBED);
+ // If MI was tail agnostic and the VL didn't increase, preserve it.
+ int64_t Policy = RISCVII::TAIL_UNDISTURBED_MASK_UNDISTURBED;
+ bool TailAgnostic = (MI.getOperand(5).getImm() & RISCVII::TAIL_AGNOSTIC) ||
+ Passthru.getReg() == RISCV::NoRegister;
+ if (TailAgnostic && isVLKnownLE(MI.getOperand(3), SrcVL))
+ Policy |= RISCVII::TAIL_AGNOSTIC;
+ Src->getOperand(RISCVII::getVecPolicyOpNum(Src->getDesc())).setImm(Policy);
MRI->replaceRegWith(MI.getOperand(0).getReg(), Src->getOperand(0).getReg());
MI.eraseFromParent();
diff --git a/llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.mir b/llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.mir
index b2526c6df6939e..771b2073370e6c 100644
--- a/llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.mir
+++ b/llvm/test/CodeGen/RISCV/rvv/vmv.v.v-peephole.mir
@@ -18,3 +18,45 @@ body: |
%y:gpr = ADDI $x0, 1
%z:vr = PseudoVMV_V_V_M1 %passthru, %x, 4, 5 /* e32 */, 0 /* tu, mu */
...
+---
+name: tail_agnostic
+body: |
+ bb.0:
+ liveins: $v8
+ ; CHECK-LABEL: name: tail_agnostic
+ ; CHECK: liveins: $v8
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %passthru:vr = COPY $v8
+ ; CHECK-NEXT: %x:vr = PseudoVADD_VV_M1 %passthru, $noreg, $noreg, 4, 5 /* e32 */, 1 /* ta, mu */
+ %passthru:vr = COPY $v8
+ %x:vr = PseudoVADD_VV_M1 %passthru, $noreg, $noreg, 4, 5 /* e32 */, 0 /* tu, mu */
+ %y:vr = PseudoVMV_V_V_M1 %passthru, %x, 4, 5 /* e32 */, 1 /* ta, mu */
+...
+---
+name: tail_agnostic_larger_vl
+body: |
+ bb.0:
+ liveins: $v8
+ ; CHECK-LABEL: name: tail_agnostic_larger_vl
+ ; CHECK: liveins: $v8
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %passthru:vr = COPY $v8
+ ; CHECK-NEXT: %x:vr = PseudoVADD_VV_M1 %passthru, $noreg, $noreg, 4, 5 /* e32 */, 0 /* tu, mu */
+ %passthru:vr = COPY $v8
+ %x:vr = PseudoVADD_VV_M1 %passthru, $noreg, $noreg, 4, 5 /* e32 */, 0 /* tu, mu */
+ %y:vr = PseudoVMV_V_V_M1 %passthru, %x, 5, 5 /* e32 */, 1 /* ta, mu */
+...
+---
+name: undef_passthru_src_undef_passthru
+body: |
+ bb.0:
+ liveins: $v8
+ ; CHECK-LABEL: name: undef_passthru_src_undef_passthru
+ ; CHECK: liveins: $v8
+ ; CHECK-NEXT: {{ $}}
+ ; CHECK-NEXT: %passthru:vr = COPY $v8
+ ; CHECK-NEXT: %x:vr = PseudoVADD_VV_M1 $noreg, $noreg, $noreg, 4, 5 /* e32 */, 1 /* ta, mu */
+ %passthru:vr = COPY $v8
+ %x:vr = PseudoVADD_VV_M1 $noreg, $noreg, $noreg, 4, 5 /* e32 */, 0 /* tu, mu */
+ %y:vr = PseudoVMV_V_V_M1 $noreg, %x, 4, 5 /* e32 */, 0 /* tu, mu */
+...
More information about the llvm-commits
mailing list