Skip to content

Commit 6f1974e

Browse files
lukel97tru
authored andcommitted
[RISCV] Don't relax policy to ta when vmerge's VL shrinks during folding
When folding a vmerge into its operands, if the resulting VL is smaller than what the vmerge had originally then what was previously in its body then gets moved to the tail. In that case, we can't relax the tail policy to agnostic when the merge operand is undefined, since we need to preserve these elements past the new VL. Fixes #64754 Reviewed By: craig.topper, reames Differential Revision: https://reviews.llvm.org/D158161 (cherry picked from commit 007b41b)
1 parent 993681f commit 6f1974e

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3414,6 +3414,7 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
34143414

34153415
// Because N and True must have the same merge operand (or True's operand is
34163416
// implicit_def), the "effective" body is the minimum of their VLs.
3417+
SDValue OrigVL = VL;
34173418
VL = GetMinVL(TrueVL, VL);
34183419
if (!VL)
34193420
return false;
@@ -3461,7 +3462,17 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
34613462
"Expected instructions with mask have a tied dest.");
34623463
#endif
34633464

3464-
uint64_t Policy = isImplicitDef(Merge) ? RISCVII::TAIL_AGNOSTIC : /*TUMU*/ 0;
3465+
// Use a tumu policy, relaxing it to tail agnostic provided that the merge
3466+
// operand is undefined.
3467+
//
3468+
// However, if the VL became smaller than what the vmerge had originally, then
3469+
// elements past VL that were previously in the vmerge's body will have moved
3470+
// to the tail. In that case we always need to use tail undisturbed to
3471+
// preserve them.
3472+
bool MergeVLShrunk = VL != OrigVL;
3473+
uint64_t Policy = (isImplicitDef(Merge) && !MergeVLShrunk)
3474+
? RISCVII::TAIL_AGNOSTIC
3475+
: /*TUMU*/ 0;
34653476
SDValue PolicyOp =
34663477
CurDAG->getTargetConstant(Policy, DL, Subtarget->getXLenVT());
34673478

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ define void @vselect_vv_v6i32(ptr %a, ptr %b, ptr %cc, ptr %z) {
2828
; RV32-NEXT: vslidedown.vi v10, v10, 2
2929
; RV32-NEXT: vand.vi v10, v10, 1
3030
; RV32-NEXT: vmsne.vi v0, v10, 0
31-
; RV32-NEXT: vsetivli zero, 6, e32, m2, ta, mu
31+
; RV32-NEXT: vsetivli zero, 6, e32, m2, tu, mu
3232
; RV32-NEXT: vle32.v v8, (a0), v0.t
3333
; RV32-NEXT: vse32.v v8, (a3)
3434
; RV32-NEXT: ret
@@ -58,7 +58,7 @@ define void @vselect_vv_v6i32(ptr %a, ptr %b, ptr %cc, ptr %z) {
5858
; RV64-NEXT: vslidedown.vi v10, v10, 2
5959
; RV64-NEXT: vand.vi v10, v10, 1
6060
; RV64-NEXT: vmsne.vi v0, v10, 0
61-
; RV64-NEXT: vsetivli zero, 6, e32, m2, ta, mu
61+
; RV64-NEXT: vsetivli zero, 6, e32, m2, tu, mu
6262
; RV64-NEXT: vle32.v v8, (a0), v0.t
6363
; RV64-NEXT: vse32.v v8, (a3)
6464
; RV64-NEXT: ret
@@ -239,7 +239,7 @@ define void @vselect_vv_v6f32(ptr %a, ptr %b, ptr %cc, ptr %z) {
239239
; RV32-NEXT: vslidedown.vi v10, v10, 2
240240
; RV32-NEXT: vand.vi v10, v10, 1
241241
; RV32-NEXT: vmsne.vi v0, v10, 0
242-
; RV32-NEXT: vsetivli zero, 6, e32, m2, ta, mu
242+
; RV32-NEXT: vsetivli zero, 6, e32, m2, tu, mu
243243
; RV32-NEXT: vle32.v v8, (a0), v0.t
244244
; RV32-NEXT: vse32.v v8, (a3)
245245
; RV32-NEXT: ret
@@ -269,7 +269,7 @@ define void @vselect_vv_v6f32(ptr %a, ptr %b, ptr %cc, ptr %z) {
269269
; RV64-NEXT: vslidedown.vi v10, v10, 2
270270
; RV64-NEXT: vand.vi v10, v10, 1
271271
; RV64-NEXT: vmsne.vi v0, v10, 0
272-
; RV64-NEXT: vsetivli zero, 6, e32, m2, ta, mu
272+
; RV64-NEXT: vsetivli zero, 6, e32, m2, tu, mu
273273
; RV64-NEXT: vle32.v v8, (a0), v0.t
274274
; RV64-NEXT: vse32.v v8, (a3)
275275
; RV64-NEXT: ret

llvm/test/CodeGen/RISCV/rvv/rvv-peephole-vmerge-vops.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,12 +1065,12 @@ define <vscale x 2 x i32> @vmerge_larger_vl_poison_passthru(<vscale x 2 x i32> %
10651065
ret <vscale x 2 x i32> %b
10661066
}
10671067

1068-
; FIXME: The vadd's new policy should be tail undisturbed since the false op of
1069-
; the vmerge moves from the the body to the tail, and we need to preserve it.
1068+
; The vadd's new policy should be tail undisturbed since the false op of the
1069+
; vmerge moves from the the body to the tail, and we need to preserve it.
10701070
define <vscale x 2 x i32> @vmerge_larger_vl_false_becomes_tail(<vscale x 2 x i32> %false, <vscale x 2 x i32> %x, <vscale x 2 x i32> %y, <vscale x 2 x i1> %m) {
10711071
; CHECK-LABEL: vmerge_larger_vl_false_becomes_tail:
10721072
; CHECK: # %bb.0:
1073-
; CHECK-NEXT: vsetivli zero, 2, e32, m1, ta, mu
1073+
; CHECK-NEXT: vsetivli zero, 2, e32, m1, tu, mu
10741074
; CHECK-NEXT: vadd.vv v8, v9, v10, v0.t
10751075
; CHECK-NEXT: ret
10761076
%a = call <vscale x 2 x i32> @llvm.riscv.vadd.nxv2i32.nxv2i32(<vscale x 2 x i32> poison, <vscale x 2 x i32> %x, <vscale x 2 x i32> %y, i64 2)

0 commit comments

Comments
 (0)