1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+v,+m -verify-machineinstrs < %s | FileCheck %s
3 ; RUN: llc -mtriple=riscv64 -mattr=+Zve64x,+m -verify-machineinstrs < %s | FileCheck %s
5 declare i64 @llvm.vscale.i64()
7 define i64 @vscale_lshr(i64 %TC) {
8 ; CHECK-LABEL: vscale_lshr:
10 ; CHECK-NEXT: csrr a1, vlenb
11 ; CHECK-NEXT: srli a1, a1, 6
12 ; CHECK-NEXT: addi a1, a1, -1
13 ; CHECK-NEXT: and a0, a0, a1
15 %vscale = call i64 @llvm.vscale.i64()
16 %shifted = lshr i64 %vscale, 3
17 %urem = urem i64 %TC, %shifted
21 define i64 @vscale(i64 %TC) {
22 ; CHECK-LABEL: vscale:
24 ; CHECK-NEXT: csrr a1, vlenb
25 ; CHECK-NEXT: srli a1, a1, 3
26 ; CHECK-NEXT: addi a1, a1, -1
27 ; CHECK-NEXT: and a0, a0, a1
29 %vscale = call i64 @llvm.vscale.i64()
30 %urem = urem i64 %TC, %vscale
34 define i64 @vscale_shl(i64 %TC) {
35 ; CHECK-LABEL: vscale_shl:
37 ; CHECK-NEXT: csrr a1, vlenb
38 ; CHECK-NEXT: addi a1, a1, -1
39 ; CHECK-NEXT: and a0, a0, a1
41 %vscale = call i64 @llvm.vscale.i64()
42 %shifted = shl i64 %vscale, 3
43 %urem = urem i64 %TC, %shifted
47 define i64 @TC_minus_rem(i64 %TC) {
48 ; CHECK-LABEL: TC_minus_rem:
50 ; CHECK-NEXT: csrr a1, vlenb
51 ; CHECK-NEXT: srli a1, a1, 3
52 ; CHECK-NEXT: neg a1, a1
53 ; CHECK-NEXT: and a0, a0, a1
55 %vscale = call i64 @llvm.vscale.i64()
56 %urem = urem i64 %TC, %vscale
57 %VTC = sub i64 %TC, %urem
61 define i64 @TC_minus_rem_shl(i64 %TC) {
62 ; CHECK-LABEL: TC_minus_rem_shl:
64 ; CHECK-NEXT: csrr a1, vlenb
65 ; CHECK-NEXT: neg a1, a1
66 ; CHECK-NEXT: and a0, a0, a1
68 %vscale = call i64 @llvm.vscale.i64()
69 %shifted = shl i64 %vscale, 3
70 %urem = urem i64 %TC, %shifted
71 %VTC = sub i64 %TC, %urem
75 define i64 @con1024_minus_rem() {
76 ; CHECK-LABEL: con1024_minus_rem:
78 ; CHECK-NEXT: csrr a0, vlenb
79 ; CHECK-NEXT: srli a0, a0, 3
80 ; CHECK-NEXT: negw a0, a0
81 ; CHECK-NEXT: andi a0, a0, 1024
83 %vscale = call i64 @llvm.vscale.i64()
84 %urem = urem i64 1024, %vscale
85 %VTC = sub i64 1024, %urem
89 ; Maximum VLEN=64k implies Maximum vscale=1024.
90 ; TODO: This should fold to 2048
91 define i64 @con2048_minus_rem() {
92 ; CHECK-LABEL: con2048_minus_rem:
94 ; CHECK-NEXT: csrr a0, vlenb
95 ; CHECK-NEXT: srli a0, a0, 3
96 ; CHECK-NEXT: neg a0, a0
97 ; CHECK-NEXT: li a1, 1
98 ; CHECK-NEXT: slli a1, a1, 11
99 ; CHECK-NEXT: and a0, a0, a1
101 %vscale = call i64 @llvm.vscale.i64()
102 %urem = urem i64 2048, %vscale
103 %VTC = sub i64 2048, %urem