Skip to content

Commit bea172c

Browse files
[AArch64][GlobalISel] Fix incorrect codegen for FPR16/FPR8 to GPR copies (#171499)
Fixes #171494
1 parent ad8d9e1 commit bea172c

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
570570
return Query.Types[0] == s128 &&
571571
Query.MMODescrs[0].Ordering != AtomicOrdering::NotAtomic;
572572
})
573+
.widenScalarIf(
574+
all(scalarNarrowerThan(0, 32),
575+
atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Release)),
576+
changeTo(0, s32))
573577
.legalForTypesWithMemDesc(
574578
{{s8, p0, s8, 8}, {s16, p0, s8, 8}, // truncstorei8 from s16
575579
{s32, p0, s8, 8}, // truncstorei8 from s32

llvm/test/CodeGen/AArch64/Atomics/aarch64-atomic-store-rcpc_immo.ll

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,10 @@ define void @store_atomic_i128_unaligned_seq_cst(i128 %value, ptr %ptr) {
357357
ret void
358358
}
359359

360-
; TODO: missed opportunity to emit a stlurb w/ GISel
361360
define void @store_atomic_i8_from_gep() {
362361
; GISEL-LABEL: store_atomic_i8_from_gep:
363362
; GISEL: bl init
364-
; GISEL: add x9, x8, #1
365-
; GISEL: stlrb w8, [x9]
363+
; GISEL: stlurb w8, [x9, #1]
366364
;
367365
; SDAG-LABEL: store_atomic_i8_from_gep:
368366
; SDAG: bl init
@@ -374,12 +372,10 @@ define void @store_atomic_i8_from_gep() {
374372
ret void
375373
}
376374

377-
; TODO: missed opportunity to emit a stlurh w/ GISel
378375
define void @store_atomic_i16_from_gep() {
379376
; GISEL-LABEL: store_atomic_i16_from_gep:
380377
; GISEL: bl init
381-
; GISEL: add x9, x8, #2
382-
; GISEL: stlrh w8, [x9]
378+
; GISEL: stlurh w8, [x9, #2]
383379
;
384380
; SDAG-LABEL: store_atomic_i16_from_gep:
385381
; SDAG: bl init
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -mtriple=arm64-apple-ios -global-isel -global-isel-abort=1 | FileCheck %s --check-prefix=CHECK-NOFP16
3+
; RUN: llc < %s -mtriple=arm64-apple-ios -mattr=+fullfp16 -global-isel -global-isel-abort=1 | FileCheck %s --check-prefix=CHECK-FP16
4+
5+
; Test for https://github.com/llvm/llvm-project/issues/171494
6+
; Atomic store of bitcast half to i16 was generating incorrect code (mrs instead of fmov).
7+
8+
define void @atomic_store_half(ptr %addr, half %val) {
9+
; CHECK-NOFP16-LABEL: atomic_store_half:
10+
; CHECK-NOFP16: ; %bb.0:
11+
; CHECK-NOFP16-NEXT: ; kill: def $h0 killed $h0 def $s0
12+
; CHECK-NOFP16-NEXT: fmov w8, s0
13+
; CHECK-NOFP16-NEXT: stlrh w8, [x0]
14+
; CHECK-NOFP16-NEXT: ret
15+
;
16+
; CHECK-FP16-LABEL: atomic_store_half:
17+
; CHECK-FP16: ; %bb.0:
18+
; CHECK-FP16-NEXT: ; kill: def $h0 killed $h0 def $s0
19+
; CHECK-FP16-NEXT: fmov w8, s0
20+
; CHECK-FP16-NEXT: stlrh w8, [x0]
21+
; CHECK-FP16-NEXT: ret
22+
%ival = bitcast half %val to i16
23+
store atomic i16 %ival, ptr %addr release, align 2
24+
ret void
25+
}
26+
27+
define void @atomic_store_bfloat(ptr %addr, bfloat %val) {
28+
; CHECK-NOFP16-LABEL: atomic_store_bfloat:
29+
; CHECK-NOFP16: ; %bb.0:
30+
; CHECK-NOFP16-NEXT: ; kill: def $h0 killed $h0 def $s0
31+
; CHECK-NOFP16-NEXT: fmov w8, s0
32+
; CHECK-NOFP16-NEXT: stlrh w8, [x0]
33+
; CHECK-NOFP16-NEXT: ret
34+
;
35+
; CHECK-FP16-LABEL: atomic_store_bfloat:
36+
; CHECK-FP16: ; %bb.0:
37+
; CHECK-FP16-NEXT: ; kill: def $h0 killed $h0 def $s0
38+
; CHECK-FP16-NEXT: fmov w8, s0
39+
; CHECK-FP16-NEXT: stlrh w8, [x0]
40+
; CHECK-FP16-NEXT: ret
41+
%ival = bitcast bfloat %val to i16
42+
store atomic i16 %ival, ptr %addr release, align 2
43+
ret void
44+
}

0 commit comments

Comments
 (0)