Skip to content

Commit 6b09f73

Browse files
committed
[RISCV][test] Precommit test case showing opportunity to narrow loads for some shift then mask cases
Reviewed as part of #170483
1 parent 177072a commit 6b09f73

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
2+
; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s -check-prefix=RV32I
4+
; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5+
; RUN: | FileCheck %s -check-prefix=RV64I
6+
7+
; For each of these examples, it is fewer instructions to narrow the load and
8+
; then shift (which is an opportunity that can be exposed by doing the mask
9+
; before the shift).
10+
; TODO: Impement this optimisation.
11+
12+
define ptr @narrow_to_lbu(ptr %a, ptr %b) {
13+
; RV32I-LABEL: narrow_to_lbu:
14+
; RV32I: # %bb.0:
15+
; RV32I-NEXT: lhu a0, 0(a0)
16+
; RV32I-NEXT: slli a0, a0, 24
17+
; RV32I-NEXT: srli a0, a0, 20
18+
; RV32I-NEXT: add a0, a1, a0
19+
; RV32I-NEXT: ret
20+
;
21+
; RV64I-LABEL: narrow_to_lbu:
22+
; RV64I: # %bb.0:
23+
; RV64I-NEXT: lh a0, 0(a0)
24+
; RV64I-NEXT: slli a0, a0, 56
25+
; RV64I-NEXT: srli a0, a0, 52
26+
; RV64I-NEXT: add a0, a1, a0
27+
; RV64I-NEXT: ret
28+
%1 = load i16, ptr %a, align 2
29+
%2 = shl i16 %1, 1
30+
%3 = and i16 %2, 510
31+
%4 = zext nneg i16 %3 to i64
32+
%5 = getelementptr inbounds double, ptr %b, i64 %4
33+
ret ptr %5
34+
}
35+
36+
define ptr @narrow_to_lhu(ptr %a, ptr %b) {
37+
; RV32I-LABEL: narrow_to_lhu:
38+
; RV32I: # %bb.0:
39+
; RV32I-NEXT: lw a0, 0(a0)
40+
; RV32I-NEXT: slli a0, a0, 16
41+
; RV32I-NEXT: srli a0, a0, 12
42+
; RV32I-NEXT: add a0, a1, a0
43+
; RV32I-NEXT: ret
44+
;
45+
; RV64I-LABEL: narrow_to_lhu:
46+
; RV64I: # %bb.0:
47+
; RV64I-NEXT: lw a0, 0(a0)
48+
; RV64I-NEXT: slli a0, a0, 48
49+
; RV64I-NEXT: srli a0, a0, 44
50+
; RV64I-NEXT: add a0, a1, a0
51+
; RV64I-NEXT: ret
52+
%1 = load i32, ptr %a, align 4
53+
%2 = shl i32 %1, 1
54+
%3 = and i32 %2, 131070
55+
%4 = zext nneg i32 %3 to i64
56+
%5 = getelementptr inbounds double, ptr %b, i64 %4
57+
ret ptr %5
58+
}
59+
60+
define ptr @narrow_to_lwu(ptr %a, ptr %b) {
61+
; RV32I-LABEL: narrow_to_lwu:
62+
; RV32I: # %bb.0:
63+
; RV32I-NEXT: lw a0, 0(a0)
64+
; RV32I-NEXT: slli a0, a0, 4
65+
; RV32I-NEXT: add a0, a1, a0
66+
; RV32I-NEXT: ret
67+
;
68+
; RV64I-LABEL: narrow_to_lwu:
69+
; RV64I: # %bb.0:
70+
; RV64I-NEXT: ld a0, 0(a0)
71+
; RV64I-NEXT: slli a0, a0, 32
72+
; RV64I-NEXT: srli a0, a0, 28
73+
; RV64I-NEXT: add a0, a1, a0
74+
; RV64I-NEXT: ret
75+
%1 = load i64, ptr %a, align 8
76+
%2 = shl i64 %1, 1
77+
%3 = and i64 %2, 8589934590
78+
%4 = getelementptr inbounds double, ptr %b, i64 %3
79+
ret ptr %4
80+
}

0 commit comments

Comments
 (0)