Skip to content

Commit 619efd7

Browse files
authored
[RISCV] Fix v[f]slide1down.vx having VL changed (llvm#106110)
v[f]slide1down.vx uses VL to determine where the element is inserted into, so changing the VL changes the result. This fixes this by setting ActiveElementsAffectsResult, but it's overly conservative. We should relax this later by modelling that it's ok to change the mask, just not VL. Fixes llvm#106109
1 parent 55cdb3c commit 619efd7

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,13 +1665,15 @@ defm VSLIDEUP_V : VSLD_IV_X_I<"vslideup", 0b001110, /*slidesUp=*/true>;
16651665
defm VSLIDE1UP_V : VSLD1_MV_X<"vslide1up", 0b001110>;
16661666
} // Constraints = "@earlyclobber $vd", RVVConstraint = SlideUp
16671667
defm VSLIDEDOWN_V : VSLD_IV_X_I<"vslidedown", 0b001111, /*slidesUp=*/false>;
1668+
let ActiveElementsAffectResult = 1 in
16681669
defm VSLIDE1DOWN_V : VSLD1_MV_X<"vslide1down", 0b001111>;
16691670
} // Predicates = [HasVInstructions]
16701671

16711672
let Predicates = [HasVInstructionsAnyF] in {
16721673
let Constraints = "@earlyclobber $vd", RVVConstraint = SlideUp in {
16731674
defm VFSLIDE1UP_V : VSLD1_FV_F<"vfslide1up", 0b001110>;
16741675
} // Constraints = "@earlyclobber $vd", RVVConstraint = SlideUp
1676+
let ActiveElementsAffectResult = 1 in
16751677
defm VFSLIDE1DOWN_V : VSLD1_FV_F<"vfslide1down", 0b001111>;
16761678
} // Predicates = [HasVInstructionsAnyF]
16771679

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v -verify-machineinstrs | FileCheck %s
3+
4+
define <vscale x 4 x float> @intrinsic_vfslide1down_vf_nxv4f32_nxv4f32_f32(<vscale x 4 x float> %0, <vscale x 4 x float> %false, float %1, <vscale x 4 x i1> %mask) {
5+
; CHECK-LABEL: intrinsic_vfslide1down_vf_nxv4f32_nxv4f32_f32:
6+
; CHECK: # %bb.0: # %entry
7+
; CHECK-NEXT: vsetivli zero, 4, e32, m2, ta, ma
8+
; CHECK-NEXT: vfslide1down.vf v8, v8, fa0
9+
; CHECK-NEXT: vsetivli zero, 1, e32, m2, ta, ma
10+
; CHECK-NEXT: vmerge.vvm v8, v10, v8, v0
11+
; CHECK-NEXT: ret
12+
entry:
13+
%a = call <vscale x 4 x float> @llvm.riscv.vfslide1down.nxv4f32.f32(<vscale x 4 x float> undef, <vscale x 4 x float> %0, float %1, i64 4)
14+
%b = call <vscale x 4 x float> @llvm.riscv.vmerge.nxv4f32(<vscale x 4 x float> undef, <vscale x 4 x float> %false, <vscale x 4 x float> %a, <vscale x 4 x i1> %mask, i64 1)
15+
ret <vscale x 4 x float> %b
16+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,12 +776,15 @@ define <vscale x 2 x i32> @vpselect_vslide1up(<vscale x 2 x i32> %passthru, <vsc
776776
ret <vscale x 2 x i32> %b
777777
}
778778

779+
; FIXME: We can still fold this given that the vmerge and the vslide1down have
780+
; the same vl.
779781
declare <vscale x 2 x i32> @llvm.riscv.vslide1down.nxv2i32.i32(<vscale x 2 x i32>, <vscale x 2 x i32>, i32, i64)
780782
define <vscale x 2 x i32> @vpselect_vslide1down(<vscale x 2 x i32> %passthru, <vscale x 2 x i32> %v, i32 %x, <vscale x 2 x i1> %m, i32 zeroext %vl) {
781783
; CHECK-LABEL: vpselect_vslide1down:
782784
; CHECK: # %bb.0:
783-
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, mu
784-
; CHECK-NEXT: vslide1down.vx v8, v9, a0, v0.t
785+
; CHECK-NEXT: vsetvli zero, a1, e32, m1, ta, ma
786+
; CHECK-NEXT: vslide1down.vx v9, v9, a0
787+
; CHECK-NEXT: vmerge.vvm v8, v8, v9, v0
785788
; CHECK-NEXT: ret
786789
%1 = zext i32 %vl to i64
787790
%a = call <vscale x 2 x i32> @llvm.riscv.vslide1down.nxv2i32.i32(<vscale x 2 x i32> undef, <vscale x 2 x i32> %v, i32 %x, i64 %1)

0 commit comments

Comments
 (0)