Skip to content

Commit 007b41b

Browse files
committed
[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
1 parent 6e532f9 commit 007b41b

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
@@ -3453,6 +3453,7 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
34533453

34543454
// Because N and True must have the same merge operand (or True's operand is
34553455
// implicit_def), the "effective" body is the minimum of their VLs.
3456+
SDValue OrigVL = VL;
34563457
VL = GetMinVL(TrueVL, VL);
34573458
if (!VL)
34583459
return false;
@@ -3500,7 +3501,17 @@ bool RISCVDAGToDAGISel::performCombineVMergeAndVOps(SDNode *N) {
35003501
"Expected instructions with mask have a tied dest.");
35013502
#endif
35023503

3503-
uint64_t Policy = isImplicitDef(Merge) ? RISCVII::TAIL_AGNOSTIC : /*TUMU*/ 0;
3504+
// Use a tumu policy, relaxing it to tail agnostic provided that the merge
3505+
// operand is undefined.
3506+
//
3507+
// However, if the VL became smaller than what the vmerge had originally, then
3508+
// elements past VL that were previously in the vmerge's body will have moved
3509+
// to the tail. In that case we always need to use tail undisturbed to
3510+
// preserve them.
3511+
bool MergeVLShrunk = VL != OrigVL;
3512+
uint64_t Policy = (isImplicitDef(Merge) && !MergeVLShrunk)
3513+
? RISCVII::TAIL_AGNOSTIC
3514+
: /*TUMU*/ 0;
35043515
SDValue PolicyOp =
35053516
CurDAG->getTargetConstant(Policy, DL, Subtarget->getXLenVT());
35063517

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)