154 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \3; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN4; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \5; RUN: -verify-machineinstrs | FileCheck %s --check-prefixes=CHECK,VLENUNKNOWN6; RUN: sed 's/iXLen/i32/g' %s | llc -mtriple=riscv32 -mattr=+v \7; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \8; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN1289; RUN: sed 's/iXLen/i64/g' %s | llc -mtriple=riscv64 -mattr=+v \10; RUN: -riscv-v-vector-bits-max=128 -verify-machineinstrs \11; RUN: | FileCheck %s --check-prefixes=CHECK,VLEN12812 13define iXLen @test_vsetvli_e8m1(iXLen %avl) nounwind {14; CHECK-LABEL: test_vsetvli_e8m1:15; CHECK: # %bb.0:16; CHECK-NEXT: vsetvli a0, a0, e8, m1, ta, ma17; CHECK-NEXT: ret18 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 0, iXLen 0)19 ret iXLen %vl20}21 22define iXLen @test_vsetvli_e16mf4(iXLen %avl) nounwind {23; CHECK-LABEL: test_vsetvli_e16mf4:24; CHECK: # %bb.0:25; CHECK-NEXT: vsetvli a0, a0, e16, mf4, ta, ma26; CHECK-NEXT: ret27 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 1, iXLen 6)28 ret iXLen %vl29}30 31define iXLen @test_vsetvli_e64mf8(iXLen %avl) nounwind {32; CHECK-LABEL: test_vsetvli_e64mf8:33; CHECK: # %bb.0:34; CHECK-NEXT: vsetvli a0, a0, e64, mf8, ta, ma35; CHECK-NEXT: ret36 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 3, iXLen 5)37 ret iXLen %vl38}39 40define iXLen @test_vsetvli_e8mf2_zero_avl() nounwind {41; CHECK-LABEL: test_vsetvli_e8mf2_zero_avl:42; CHECK: # %bb.0:43; CHECK-NEXT: vsetivli a0, 0, e8, mf2, ta, ma44; CHECK-NEXT: ret45 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 0, iXLen 0, iXLen 7)46 ret iXLen %vl47}48 49define iXLen @test_vsetvli_e32mf8_zero_avl() nounwind {50; CHECK-LABEL: test_vsetvli_e32mf8_zero_avl:51; CHECK: # %bb.0:52; CHECK-NEXT: vsetivli a0, 0, e16, mf4, ta, ma53; CHECK-NEXT: ret54 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 0, iXLen 1, iXLen 6)55 ret iXLen %vl56}57 58define iXLen @test_vsetvlimax_e32m2() nounwind {59; CHECK-LABEL: test_vsetvlimax_e32m2:60; CHECK: # %bb.0:61; CHECK-NEXT: vsetvli a0, zero, e32, m2, ta, ma62; CHECK-NEXT: ret63 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 2, iXLen 1)64 ret iXLen %vl65}66 67define iXLen @test_vsetvlimax_e64m4() nounwind {68; CHECK-LABEL: test_vsetvlimax_e64m4:69; CHECK: # %bb.0:70; CHECK-NEXT: vsetvli a0, zero, e64, m4, ta, ma71; CHECK-NEXT: ret72 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 3, iXLen 2)73 ret iXLen %vl74}75 76define iXLen @test_vsetvlimax_e64m8() nounwind {77; CHECK-LABEL: test_vsetvlimax_e64m8:78; CHECK: # %bb.0:79; CHECK-NEXT: vsetvli a0, zero, e64, m8, ta, ma80; CHECK-NEXT: ret81 %vl = call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 3, iXLen 3)82 ret iXLen %vl83}84 85; Check that we remove the intrinsic if it's unused.86define void @test_vsetvli_e8m1_nouse(iXLen %avl) nounwind {87; CHECK-LABEL: test_vsetvli_e8m1_nouse:88; CHECK: # %bb.0:89; CHECK-NEXT: ret90 call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 0, iXLen 0)91 ret void92}93 94define void @test_vsetvlimax_e32m2_nouse() nounwind {95; CHECK-LABEL: test_vsetvlimax_e32m2_nouse:96; CHECK: # %bb.0:97; CHECK-NEXT: ret98 call iXLen @llvm.riscv.vsetvlimax.iXLen(iXLen 2, iXLen 1)99 ret void100}101 102; Check that we remove the redundant vsetvli when followed by another operation103define <vscale x 4 x i32> @redundant_vsetvli(iXLen %avl, ptr %ptr) nounwind {104; CHECK-LABEL: redundant_vsetvli:105; CHECK: # %bb.0:106; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma107; CHECK-NEXT: vle32.v v8, (a1)108; CHECK-NEXT: ret109 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 2, iXLen 1)110 %x = call <vscale x 4 x i32> @llvm.riscv.vle.nxv4i32.iXLen(<vscale x 4 x i32> poison, ptr %ptr, iXLen %vl)111 ret <vscale x 4 x i32> %x112}113 114; Check that we remove the repeated/redundant vsetvli when followed by another115; operation116; FIXME: We don't catch the second vsetvli because it has a use of its output.117; We could replace it with the output of the first vsetvli.118define <vscale x 4 x i32> @repeated_vsetvli(iXLen %avl, ptr %ptr) nounwind {119; CHECK-LABEL: repeated_vsetvli:120; CHECK: # %bb.0:121; CHECK-NEXT: vsetvli a0, a0, e32, m2, ta, ma122; CHECK-NEXT: vsetvli zero, a0, e32, m2, ta, ma123; CHECK-NEXT: vle32.v v8, (a1)124; CHECK-NEXT: ret125 %vl0 = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %avl, iXLen 2, iXLen 1)126 %vl1 = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen %vl0, iXLen 2, iXLen 1)127 %x = call <vscale x 4 x i32> @llvm.riscv.vle.nxv4i32.iXLen(<vscale x 4 x i32> poison, ptr %ptr, iXLen %vl1)128 ret <vscale x 4 x i32> %x129}130 131define iXLen @test_vsetvli_negone_e8m1(iXLen %avl) nounwind {132; CHECK-LABEL: test_vsetvli_negone_e8m1:133; CHECK: # %bb.0:134; CHECK-NEXT: vsetvli a0, zero, e8, m1, ta, ma135; CHECK-NEXT: ret136 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen -1, iXLen 0, iXLen 0)137 ret iXLen %vl138}139 140define iXLen @test_vsetvli_eqvlmax_e8m8(iXLen %avl) nounwind {141; VLENUNKNOWN-LABEL: test_vsetvli_eqvlmax_e8m8:142; VLENUNKNOWN: # %bb.0:143; VLENUNKNOWN-NEXT: li a0, 128144; VLENUNKNOWN-NEXT: vsetvli a0, a0, e8, m8, ta, ma145; VLENUNKNOWN-NEXT: ret146;147; VLEN128-LABEL: test_vsetvli_eqvlmax_e8m8:148; VLEN128: # %bb.0:149; VLEN128-NEXT: vsetvli a0, zero, e8, m8, ta, ma150; VLEN128-NEXT: ret151 %vl = call iXLen @llvm.riscv.vsetvli.iXLen(iXLen 128, iXLen 0, iXLen 3)152 ret iXLen %vl153}154