Skip to content

Commit 276056e

Browse files
[AArch64][GlobalISel] Alternative fix: widen atomic stores in legalizer
Per review suggestion from @xal-0, handle the atomic store issue in the legalizer instead of copyPhysReg. This adds a widenScalarIf rule for G_STORE that widens scalar types narrower than 32 bits to s32 for atomic stores with release ordering or stronger. This approach: - Fixes the original bug (mrs instead of fmov for half->i16 atomic store) - Enables stlurb/stlurh codegen for GISel (removes two TODOs) - Is a more appropriate place to handle type legalization Co-authored-by: Claude <noreply@anthropic.com>
1 parent c93d641 commit 276056e

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,10 @@ AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST)
568568
return Query.Types[0] == s128 &&
569569
Query.MMODescrs[0].Ordering != AtomicOrdering::NotAtomic;
570570
})
571+
.widenScalarIf(
572+
all(scalarNarrowerThan(0, 32),
573+
atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Release)),
574+
changeTo(0, s32))
571575
.legalForTypesWithMemDesc(
572576
{{s8, p0, s8, 8}, {s16, p0, s8, 8}, // truncstorei8 from s16
573577
{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

llvm/test/CodeGen/AArch64/GlobalISel/arm64-atomic-store-fp16.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ define void @atomic_store_half(ptr %addr, half %val) {
1414
;
1515
; CHECK-FP16-LABEL: atomic_store_half:
1616
; CHECK-FP16: ; %bb.0:
17-
; CHECK-FP16-NEXT: fmov w8, h0
17+
; CHECK-FP16-NEXT: fmov w8, s0
1818
; CHECK-FP16-NEXT: stlrh w8, [x0]
1919
; CHECK-FP16-NEXT: ret
2020
%ival = bitcast half %val to i16
@@ -50,7 +50,7 @@ define void @atomic_store_bfloat(ptr %addr, bfloat %val) {
5050
;
5151
; CHECK-FP16-LABEL: atomic_store_bfloat:
5252
; CHECK-FP16: ; %bb.0:
53-
; CHECK-FP16-NEXT: fmov w8, h0
53+
; CHECK-FP16-NEXT: fmov w8, s0
5454
; CHECK-FP16-NEXT: stlrh w8, [x0]
5555
; CHECK-FP16-NEXT: ret
5656
%ival = bitcast bfloat %val to i16

0 commit comments

Comments
 (0)