263 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=riscv32 -mattr=+v,+d,+zvfh -verify-machineinstrs < %s | FileCheck %s3; RUN: llc -mtriple=riscv64 -mattr=+v,+d,+zvfh -verify-machineinstrs < %s | FileCheck %s4 5define <vscale x 4 x i32> @splat_c3_nxv4i32(<vscale x 4 x i32> %v) {6; CHECK-LABEL: splat_c3_nxv4i32:7; CHECK: # %bb.0:8; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma9; CHECK-NEXT: vrgather.vi v10, v8, 310; CHECK-NEXT: vmv.v.v v8, v1011; CHECK-NEXT: ret12 %x = extractelement <vscale x 4 x i32> %v, i32 313 %ins = insertelement <vscale x 4 x i32> poison, i32 %x, i32 014 %splat = shufflevector <vscale x 4 x i32> %ins, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer15 ret <vscale x 4 x i32> %splat16}17 18define <vscale x 4 x i32> @splat_idx_nxv4i32(<vscale x 4 x i32> %v, i64 %idx) {19; CHECK-LABEL: splat_idx_nxv4i32:20; CHECK: # %bb.0:21; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma22; CHECK-NEXT: vrgather.vx v10, v8, a023; CHECK-NEXT: vmv.v.v v8, v1024; CHECK-NEXT: ret25 %x = extractelement <vscale x 4 x i32> %v, i64 %idx26 %ins = insertelement <vscale x 4 x i32> poison, i32 %x, i32 027 %splat = shufflevector <vscale x 4 x i32> %ins, <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer28 ret <vscale x 4 x i32> %splat29}30 31define <vscale x 8 x i16> @splat_c4_nxv8i16(<vscale x 8 x i16> %v) {32; CHECK-LABEL: splat_c4_nxv8i16:33; CHECK: # %bb.0:34; CHECK-NEXT: vsetvli a0, zero, e16, m2, ta, ma35; CHECK-NEXT: vrgather.vi v10, v8, 436; CHECK-NEXT: vmv.v.v v8, v1037; CHECK-NEXT: ret38 %x = extractelement <vscale x 8 x i16> %v, i32 439 %ins = insertelement <vscale x 8 x i16> poison, i16 %x, i32 040 %splat = shufflevector <vscale x 8 x i16> %ins, <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer41 ret <vscale x 8 x i16> %splat42}43 44define <vscale x 8 x i16> @splat_idx_nxv8i16(<vscale x 8 x i16> %v, i64 %idx) {45; CHECK-LABEL: splat_idx_nxv8i16:46; CHECK: # %bb.0:47; CHECK-NEXT: vsetvli a1, zero, e16, m2, ta, ma48; CHECK-NEXT: vrgather.vx v10, v8, a049; CHECK-NEXT: vmv.v.v v8, v1050; CHECK-NEXT: ret51 %x = extractelement <vscale x 8 x i16> %v, i64 %idx52 %ins = insertelement <vscale x 8 x i16> poison, i16 %x, i32 053 %splat = shufflevector <vscale x 8 x i16> %ins, <vscale x 8 x i16> poison, <vscale x 8 x i32> zeroinitializer54 ret <vscale x 8 x i16> %splat55}56 57define <vscale x 2 x half> @splat_c1_nxv2f16(<vscale x 2 x half> %v) {58; CHECK-LABEL: splat_c1_nxv2f16:59; CHECK: # %bb.0:60; CHECK-NEXT: vsetvli a0, zero, e16, mf2, ta, ma61; CHECK-NEXT: vrgather.vi v9, v8, 162; CHECK-NEXT: vmv1r.v v8, v963; CHECK-NEXT: ret64 %x = extractelement <vscale x 2 x half> %v, i32 165 %ins = insertelement <vscale x 2 x half> poison, half %x, i32 066 %splat = shufflevector <vscale x 2 x half> %ins, <vscale x 2 x half> poison, <vscale x 2 x i32> zeroinitializer67 ret <vscale x 2 x half> %splat68}69 70define <vscale x 2 x half> @splat_idx_nxv2f16(<vscale x 2 x half> %v, i64 %idx) {71; CHECK-LABEL: splat_idx_nxv2f16:72; CHECK: # %bb.0:73; CHECK-NEXT: vsetvli a1, zero, e16, mf2, ta, ma74; CHECK-NEXT: vrgather.vx v9, v8, a075; CHECK-NEXT: vmv1r.v v8, v976; CHECK-NEXT: ret77 %x = extractelement <vscale x 2 x half> %v, i64 %idx78 %ins = insertelement <vscale x 2 x half> poison, half %x, i32 079 %splat = shufflevector <vscale x 2 x half> %ins, <vscale x 2 x half> poison, <vscale x 2 x i32> zeroinitializer80 ret <vscale x 2 x half> %splat81}82 83define <vscale x 4 x float> @splat_c3_nxv4f32(<vscale x 4 x float> %v) {84; CHECK-LABEL: splat_c3_nxv4f32:85; CHECK: # %bb.0:86; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma87; CHECK-NEXT: vrgather.vi v10, v8, 388; CHECK-NEXT: vmv.v.v v8, v1089; CHECK-NEXT: ret90 %x = extractelement <vscale x 4 x float> %v, i64 391 %ins = insertelement <vscale x 4 x float> poison, float %x, i32 092 %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer93 ret <vscale x 4 x float> %splat94}95 96define <vscale x 4 x float> @splat_idx_nxv4f32(<vscale x 4 x float> %v, i64 %idx) {97; CHECK-LABEL: splat_idx_nxv4f32:98; CHECK: # %bb.0:99; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma100; CHECK-NEXT: vrgather.vx v10, v8, a0101; CHECK-NEXT: vmv.v.v v8, v10102; CHECK-NEXT: ret103 %x = extractelement <vscale x 4 x float> %v, i64 %idx104 %ins = insertelement <vscale x 4 x float> poison, float %x, i32 0105 %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer106 ret <vscale x 4 x float> %splat107}108 109define <vscale x 8 x float> @splat_idx_nxv4f32_nxv8f32(<vscale x 4 x float> %v, i64 %idx) {110; CHECK-LABEL: splat_idx_nxv4f32_nxv8f32:111; CHECK: # %bb.0:112; CHECK-NEXT: vsetvli a1, zero, e32, m4, ta, ma113; CHECK-NEXT: vrgather.vx v12, v8, a0114; CHECK-NEXT: vmv.v.v v8, v12115; CHECK-NEXT: ret116 %x = extractelement <vscale x 4 x float> %v, i64 %idx117 %ins = insertelement <vscale x 8 x float> poison, float %x, i32 0118 %splat = shufflevector <vscale x 8 x float> %ins, <vscale x 8 x float> poison, <vscale x 8 x i32> zeroinitializer119 ret <vscale x 8 x float> %splat120}121 122define <vscale x 4 x float> @splat_idx_v4f32_nxv4f32(<4 x float> %v, i64 %idx) {123; CHECK-LABEL: splat_idx_v4f32_nxv4f32:124; CHECK: # %bb.0:125; CHECK-NEXT: vsetvli a1, zero, e32, m2, ta, ma126; CHECK-NEXT: vrgather.vx v10, v8, a0127; CHECK-NEXT: vmv.v.v v8, v10128; CHECK-NEXT: ret129 %x = extractelement <4 x float> %v, i64 %idx130 %ins = insertelement <vscale x 4 x float> poison, float %x, i32 0131 %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer132 ret <vscale x 4 x float> %splat133}134 135; Negative test, scale could have a value > 2136define <8 x float> @splat_idx_nxv4f32_v8f32(<vscale x 4 x float> %v, i64 %idx) {137; CHECK-LABEL: splat_idx_nxv4f32_v8f32:138; CHECK: # %bb.0:139; CHECK-NEXT: vsetivli zero, 1, e32, m2, ta, ma140; CHECK-NEXT: vslidedown.vx v8, v8, a0141; CHECK-NEXT: vfmv.f.s fa5, v8142; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma143; CHECK-NEXT: vfmv.v.f v8, fa5144; CHECK-NEXT: ret145 %x = extractelement <vscale x 4 x float> %v, i64 %idx146 %ins = insertelement <8 x float> poison, float %x, i32 0147 %splat = shufflevector <8 x float> %ins, <8 x float> poison, <8 x i32> zeroinitializer148 ret <8 x float> %splat149}150 151define <vscale x 4 x float> @splat_idx_nxv8f32_nxv4f32_constant_0(<vscale x 8 x float> %v) {152; CHECK-LABEL: splat_idx_nxv8f32_nxv4f32_constant_0:153; CHECK: # %bb.0:154; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma155; CHECK-NEXT: vrgather.vi v10, v8, 0156; CHECK-NEXT: vmv.v.v v8, v10157; CHECK-NEXT: ret158 %x = extractelement <vscale x 8 x float> %v, i64 0159 %ins = insertelement <vscale x 4 x float> poison, float %x, i32 0160 %splat = shufflevector <vscale x 4 x float> %ins, <vscale x 4 x float> poison, <vscale x 4 x i32> zeroinitializer161 ret <vscale x 4 x float> %splat162}163 164define <vscale x 4 x i8> @splat_idx_nxv8i8_nxv4i8_constant_0(<vscale x 8 x i8> %v) {165; CHECK-LABEL: splat_idx_nxv8i8_nxv4i8_constant_0:166; CHECK: # %bb.0:167; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, ma168; CHECK-NEXT: vrgather.vi v9, v8, 0169; CHECK-NEXT: vmv1r.v v8, v9170; CHECK-NEXT: ret171 %x = extractelement <vscale x 8 x i8> %v, i64 0172 %ins = insertelement <vscale x 4 x i8> poison, i8 %x, i32 0173 %splat = shufflevector <vscale x 4 x i8> %ins, <vscale x 4 x i8> poison, <vscale x 4 x i32> zeroinitializer174 ret <vscale x 4 x i8> %splat175}176 177define <vscale x 4 x i8> @splat_idx_nxv8i8_nxv4i8_constant_3(<vscale x 8 x i8> %v) {178; CHECK-LABEL: splat_idx_nxv8i8_nxv4i8_constant_3:179; CHECK: # %bb.0:180; CHECK-NEXT: vsetvli a0, zero, e8, mf2, ta, ma181; CHECK-NEXT: vrgather.vi v9, v8, 3182; CHECK-NEXT: vmv1r.v v8, v9183; CHECK-NEXT: ret184 %x = extractelement <vscale x 8 x i8> %v, i64 3185 %ins = insertelement <vscale x 4 x i8> poison, i8 %x, i32 0186 %splat = shufflevector <vscale x 4 x i8> %ins, <vscale x 4 x i8> poison, <vscale x 4 x i32> zeroinitializer187 ret <vscale x 4 x i8> %splat188}189 190 191; Negative test, vscale coule be 2192define <vscale x 4 x i8> @splat_idx_nxv8i8_nxv4i8_constant_15(<vscale x 8 x i8> %v) {193; CHECK-LABEL: splat_idx_nxv8i8_nxv4i8_constant_15:194; CHECK: # %bb.0:195; CHECK-NEXT: vsetivli zero, 1, e8, m1, ta, ma196; CHECK-NEXT: vslidedown.vi v8, v8, 15197; CHECK-NEXT: vmv.x.s a0, v8198; CHECK-NEXT: vsetvli a1, zero, e8, mf2, ta, ma199; CHECK-NEXT: vmv.v.x v8, a0200; CHECK-NEXT: ret201 %x = extractelement <vscale x 8 x i8> %v, i64 15202 %ins = insertelement <vscale x 4 x i8> poison, i8 %x, i32 0203 %splat = shufflevector <vscale x 4 x i8> %ins, <vscale x 4 x i8> poison, <vscale x 4 x i32> zeroinitializer204 ret <vscale x 4 x i8> %splat205}206 207define <8 x float> @splat_idx_nxv4f32_v8f32_constant_0(<vscale x 4 x float> %v) {208; CHECK-LABEL: splat_idx_nxv4f32_v8f32_constant_0:209; CHECK: # %bb.0:210; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma211; CHECK-NEXT: vrgather.vi v10, v8, 0212; CHECK-NEXT: vmv.v.v v8, v10213; CHECK-NEXT: ret214 %x = extractelement <vscale x 4 x float> %v, i64 0215 %ins = insertelement <8 x float> poison, float %x, i32 0216 %splat = shufflevector <8 x float> %ins, <8 x float> poison, <8 x i32> zeroinitializer217 ret <8 x float> %splat218}219 220define <8 x float> @splat_idx_nxv4f32_v8f32_constant_7(<vscale x 4 x float> %v) {221; CHECK-LABEL: splat_idx_nxv4f32_v8f32_constant_7:222; CHECK: # %bb.0:223; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma224; CHECK-NEXT: vrgather.vi v10, v8, 7225; CHECK-NEXT: vmv.v.v v8, v10226; CHECK-NEXT: ret227 %x = extractelement <vscale x 4 x float> %v, i64 7228 %ins = insertelement <8 x float> poison, float %x, i32 0229 %splat = shufflevector <8 x float> %ins, <8 x float> poison, <8 x i32> zeroinitializer230 ret <8 x float> %splat231}232 233; This test shouldn't crash.234define <vscale x 2 x float> @splat_idx_illegal_type(<3 x float> %v) {235; CHECK-LABEL: splat_idx_illegal_type:236; CHECK: # %bb.0: # %entry237; CHECK-NEXT: vsetvli a0, zero, e32, m1, ta, ma238; CHECK-NEXT: vrgather.vi v9, v8, 0239; CHECK-NEXT: vmv.v.v v8, v9240; CHECK-NEXT: ret241entry:242 %x = extractelement <3 x float> %v, i64 0243 %ins = insertelement <vscale x 2 x float> poison, float %x, i64 0244 %splat = shufflevector <vscale x 2 x float> %ins, <vscale x 2 x float> poison, <vscale x 2 x i32> zeroinitializer245 ret <vscale x 2 x float> %splat246}247 248; Negative test, vscale might be 4249define <8 x float> @splat_idx_nxv4f32_v8f32_constant_8(<vscale x 4 x float> %v) {250; CHECK-LABEL: splat_idx_nxv4f32_v8f32_constant_8:251; CHECK: # %bb.0:252; CHECK-NEXT: vsetivli zero, 1, e32, m2, ta, ma253; CHECK-NEXT: vslidedown.vi v8, v8, 8254; CHECK-NEXT: vfmv.f.s fa5, v8255; CHECK-NEXT: vsetivli zero, 8, e32, m2, ta, ma256; CHECK-NEXT: vfmv.v.f v8, fa5257; CHECK-NEXT: ret258 %x = extractelement <vscale x 4 x float> %v, i64 8259 %ins = insertelement <8 x float> poison, float %x, i32 0260 %splat = shufflevector <8 x float> %ins, <8 x float> poison, <8 x i32> zeroinitializer261 ret <8 x float> %splat262}263