Skip to content

Commit 97f61b4

Browse files
committed
[AArch64] Add TableGen patterns for truncstore of bitcasted FP values (f64/f32 → i32/i16/i8X)
1 parent 681ecae commit 97f61b4

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.td

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,6 +4706,30 @@ let Predicates = [IsLE] in {
47064706
(STRQui FPR128:$Rt, GPR64sp:$Rn, uimm12s16:$offset)>;
47074707
}
47084708

4709+
// truncstorei32 of f64 bitcasted to i64
4710+
def : Pat<(truncstorei32 (i64 (bitconvert (f64 FPR64:$Rt))), (am_indexed32 GPR64sp:$Rn, uimm12s4:$offset)),
4711+
(STRSui (EXTRACT_SUBREG FPR64:$Rt, ssub), GPR64sp:$Rn, uimm12s4:$offset)>;
4712+
4713+
// truncstorei16 of f64 bitcasted to i64
4714+
def : Pat<(truncstorei16 (i64 (bitconvert (f64 FPR64:$Rt))), (am_indexed16 GPR64sp:$Rn, uimm12s2:$offset)),
4715+
(STRHui (f16 (EXTRACT_SUBREG FPR64:$Rt, hsub)), GPR64sp:$Rn, uimm12s2:$offset)>;
4716+
4717+
let Predicates = [HasFullFP16] in {
4718+
// truncstorei16 of f32 bitcasted to i32
4719+
def : Pat<(truncstorei16 (i32 (bitconvert (f32 FPR32:$Rt))), (am_indexed16 GPR64sp:$Rn, uimm12s2:$off)),
4720+
(STRHui (f16 (EXTRACT_SUBREG FPR32:$Rt, hsub)), GPR64sp:$Rn, uimm12s2:$off)>;
4721+
}
4722+
4723+
let Predicates = [HasFPARMv8] in {
4724+
// truncstorei8 of f64 bitcasted to i64
4725+
def : Pat<(truncstorei8 (i64 (bitconvert (f64 FPR64:$Rt))), (am_indexed8 GPR64sp:$Rn, uimm12s1:$off)),
4726+
(STRBui (aarch64mfp8 (EXTRACT_SUBREG FPR64:$Rt, bsub)), GPR64sp:$Rn, uimm12s1:$off)>;
4727+
4728+
// truncstorei8 of f32 bitcasted to i32
4729+
def : Pat<(truncstorei8 (i32 (bitconvert (f32 FPR32:$Rt))), (am_indexed8 GPR64sp:$Rn, uimm12s1:$off)),
4730+
(STRBui (aarch64mfp8 (EXTRACT_SUBREG FPR32:$Rt, bsub)), GPR64sp:$Rn, uimm12s1:$off)>;
4731+
}
4732+
47094733
// truncstore i64
47104734
def : Pat<(truncstorei32 GPR64:$Rt,
47114735
(am_indexed32 GPR64sp:$Rn, uimm12s4:$offset)),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc -mtriple=aarch64-unknown-linux-gnu -mattr=+fp-armv8,+fullfp16 < %s | FileCheck %s
3+
4+
5+
define void @_Z10store_f64i32Pjd(ptr %n, double noundef %x){
6+
; CHECK-LABEL: _Z10store_f64i32Pjd:
7+
; CHECK: // %bb.0: // %entry
8+
; CHECK-NEXT: str s0, [x0]
9+
; CHECK-NEXT: ret
10+
entry:
11+
%0 = bitcast double %x to i64
12+
%conv = trunc i64 %0 to i32
13+
store i32 %conv, ptr %n, align 4
14+
ret void
15+
}
16+
17+
define void @_Z9store_f64i16Ptd(ptr %n, double noundef %x){
18+
; CHECK-LABEL: _Z9store_f64i16Ptd:
19+
; CHECK: // %bb.0: // %entry
20+
; CHECK-NEXT: str h0, [x0]
21+
; CHECK-NEXT: ret
22+
entry:
23+
%0 = bitcast double %x to i64
24+
%conv = trunc i64 %0 to i16
25+
store i16 %conv, ptr %n, align 2
26+
ret void
27+
}
28+
29+
define void @_Z13store_f64i8Phd(ptr %0, double noundef %1){
30+
; CHECK-LABEL: _Z13store_f64i8Phd:
31+
; CHECK: // %bb.0:
32+
; CHECK-NEXT: str b0, [x0]
33+
; CHECK-NEXT: ret
34+
%3 = bitcast double %1 to i64
35+
%4 = trunc i64 %3 to i8
36+
store i8 %4, ptr %0, align 1
37+
ret void
38+
}
39+
40+
define void @_Z17store_f32i16Ptf(ptr %0, float noundef %1){
41+
; CHECK-LABEL: _Z17store_f32i16Ptf:
42+
; CHECK: // %bb.0:
43+
; CHECK-NEXT: str h0, [x0]
44+
; CHECK-NEXT: ret
45+
%3 = bitcast float %1 to i32
46+
%4 = trunc i32 %3 to i16
47+
store i16 %4, ptr %0, align 2
48+
ret void
49+
}
50+
51+
define void @_Z16store_f32i8Phf(ptr %0, float noundef %1){
52+
; CHECK-LABEL: _Z16store_f32i8Phf:
53+
; CHECK: // %bb.0:
54+
; CHECK-NEXT: str b0, [x0]
55+
; CHECK-NEXT: ret
56+
%3 = bitcast float %1 to i32
57+
%4 = trunc i32 %3 to i8
58+
store i8 %4, ptr %0, align 1
59+
ret void
60+
}

0 commit comments

Comments
 (0)