Skip to content

Commit fe28217

Browse files
committed
[RISCV] atomic_store_nn have a different layout to regular store
We cannot directy reuse the patterns of StPat because for some reason the store DAG node and the atomic_store_nn DAG nodes put the ptr and the value in different positions. Currently we attempt to store the address to an address formed by the value. Differential Revision: https://reviews.llvm.org/D51217 llvm-svn: 340722
1 parent be4a549 commit fe28217

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoA.td

+15-4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ multiclass AMO_rr_aq_rl<bits<5> funct5, bits<3> funct3, string opcodestr> {
4444
def _AQ_RL : AMO_rr<funct5, 1, 1, funct3, opcodestr # ".aqrl">;
4545
}
4646

47+
multiclass AtomicStPat<PatFrag StoreOp, RVInst Inst, RegisterClass StTy> {
48+
def : Pat<(StoreOp GPR:$rs1, StTy:$rs2), (Inst StTy:$rs2, GPR:$rs1, 0)>;
49+
def : Pat<(StoreOp AddrFI:$rs1, StTy:$rs2), (Inst StTy:$rs2, AddrFI:$rs1, 0)>;
50+
def : Pat<(StoreOp (add GPR:$rs1, simm12:$imm12), StTy:$rs2),
51+
(Inst StTy:$rs2, GPR:$rs1, simm12:$imm12)>;
52+
def : Pat<(StoreOp (add AddrFI:$rs1, simm12:$imm12), StTy:$rs2),
53+
(Inst StTy:$rs2, AddrFI:$rs1, simm12:$imm12)>;
54+
def : Pat<(StoreOp (IsOrAdd AddrFI:$rs1, simm12:$imm12), StTy:$rs2),
55+
(Inst StTy:$rs2, AddrFI:$rs1, simm12:$imm12)>;
56+
}
57+
4758
//===----------------------------------------------------------------------===//
4859
// Instructions
4960
//===----------------------------------------------------------------------===//
@@ -91,7 +102,7 @@ defm : LdPat<atomic_load_8, LB>;
91102
defm : LdPat<atomic_load_16, LH>;
92103
defm : LdPat<atomic_load_32, LW>;
93104

94-
defm : StPat<atomic_store_8, SB, GPR>;
95-
defm : StPat<atomic_store_16, SH, GPR>;
96-
defm : StPat<atomic_store_32, SW, GPR>;
97-
} // Predicates = [HasStdExtF]
105+
defm : AtomicStPat<atomic_store_8, SB, GPR>;
106+
defm : AtomicStPat<atomic_store_16, SH, GPR>;
107+
defm : AtomicStPat<atomic_store_32, SW, GPR>;
108+
} // Predicates = [HasStdExtA]

llvm/test/CodeGen/RISCV/atomic-load-store.ll

+12-12
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ define void @atomic_store_i8_unordered(i8 *%a, i8 %b) nounwind {
350350
;
351351
; RV32IA-LABEL: atomic_store_i8_unordered:
352352
; RV32IA: # %bb.0:
353-
; RV32IA-NEXT: sb a0, 0(a1)
353+
; RV32IA-NEXT: sb a1, 0(a0)
354354
; RV32IA-NEXT: ret
355355
store atomic i8 %b, i8* %a unordered, align 1
356356
ret void
@@ -369,7 +369,7 @@ define void @atomic_store_i8_monotonic(i8 *%a, i8 %b) nounwind {
369369
;
370370
; RV32IA-LABEL: atomic_store_i8_monotonic:
371371
; RV32IA: # %bb.0:
372-
; RV32IA-NEXT: sb a0, 0(a1)
372+
; RV32IA-NEXT: sb a1, 0(a0)
373373
; RV32IA-NEXT: ret
374374
store atomic i8 %b, i8* %a monotonic, align 1
375375
ret void
@@ -389,7 +389,7 @@ define void @atomic_store_i8_release(i8 *%a, i8 %b) nounwind {
389389
; RV32IA-LABEL: atomic_store_i8_release:
390390
; RV32IA: # %bb.0:
391391
; RV32IA-NEXT: fence rw, w
392-
; RV32IA-NEXT: sb a0, 0(a1)
392+
; RV32IA-NEXT: sb a1, 0(a0)
393393
; RV32IA-NEXT: ret
394394
store atomic i8 %b, i8* %a release, align 1
395395
ret void
@@ -409,7 +409,7 @@ define void @atomic_store_i8_seq_cst(i8 *%a, i8 %b) nounwind {
409409
; RV32IA-LABEL: atomic_store_i8_seq_cst:
410410
; RV32IA: # %bb.0:
411411
; RV32IA-NEXT: fence rw, w
412-
; RV32IA-NEXT: sb a0, 0(a1)
412+
; RV32IA-NEXT: sb a1, 0(a0)
413413
; RV32IA-NEXT: ret
414414
store atomic i8 %b, i8* %a seq_cst, align 1
415415
ret void
@@ -428,7 +428,7 @@ define void @atomic_store_i16_unordered(i16 *%a, i16 %b) nounwind {
428428
;
429429
; RV32IA-LABEL: atomic_store_i16_unordered:
430430
; RV32IA: # %bb.0:
431-
; RV32IA-NEXT: sh a0, 0(a1)
431+
; RV32IA-NEXT: sh a1, 0(a0)
432432
; RV32IA-NEXT: ret
433433
store atomic i16 %b, i16* %a unordered, align 2
434434
ret void
@@ -447,7 +447,7 @@ define void @atomic_store_i16_monotonic(i16 *%a, i16 %b) nounwind {
447447
;
448448
; RV32IA-LABEL: atomic_store_i16_monotonic:
449449
; RV32IA: # %bb.0:
450-
; RV32IA-NEXT: sh a0, 0(a1)
450+
; RV32IA-NEXT: sh a1, 0(a0)
451451
; RV32IA-NEXT: ret
452452
store atomic i16 %b, i16* %a monotonic, align 2
453453
ret void
@@ -467,7 +467,7 @@ define void @atomic_store_i16_release(i16 *%a, i16 %b) nounwind {
467467
; RV32IA-LABEL: atomic_store_i16_release:
468468
; RV32IA: # %bb.0:
469469
; RV32IA-NEXT: fence rw, w
470-
; RV32IA-NEXT: sh a0, 0(a1)
470+
; RV32IA-NEXT: sh a1, 0(a0)
471471
; RV32IA-NEXT: ret
472472
store atomic i16 %b, i16* %a release, align 2
473473
ret void
@@ -487,7 +487,7 @@ define void @atomic_store_i16_seq_cst(i16 *%a, i16 %b) nounwind {
487487
; RV32IA-LABEL: atomic_store_i16_seq_cst:
488488
; RV32IA: # %bb.0:
489489
; RV32IA-NEXT: fence rw, w
490-
; RV32IA-NEXT: sh a0, 0(a1)
490+
; RV32IA-NEXT: sh a1, 0(a0)
491491
; RV32IA-NEXT: ret
492492
store atomic i16 %b, i16* %a seq_cst, align 2
493493
ret void
@@ -506,7 +506,7 @@ define void @atomic_store_i32_unordered(i32 *%a, i32 %b) nounwind {
506506
;
507507
; RV32IA-LABEL: atomic_store_i32_unordered:
508508
; RV32IA: # %bb.0:
509-
; RV32IA-NEXT: sw a0, 0(a1)
509+
; RV32IA-NEXT: sw a1, 0(a0)
510510
; RV32IA-NEXT: ret
511511
store atomic i32 %b, i32* %a unordered, align 4
512512
ret void
@@ -525,7 +525,7 @@ define void @atomic_store_i32_monotonic(i32 *%a, i32 %b) nounwind {
525525
;
526526
; RV32IA-LABEL: atomic_store_i32_monotonic:
527527
; RV32IA: # %bb.0:
528-
; RV32IA-NEXT: sw a0, 0(a1)
528+
; RV32IA-NEXT: sw a1, 0(a0)
529529
; RV32IA-NEXT: ret
530530
store atomic i32 %b, i32* %a monotonic, align 4
531531
ret void
@@ -545,7 +545,7 @@ define void @atomic_store_i32_release(i32 *%a, i32 %b) nounwind {
545545
; RV32IA-LABEL: atomic_store_i32_release:
546546
; RV32IA: # %bb.0:
547547
; RV32IA-NEXT: fence rw, w
548-
; RV32IA-NEXT: sw a0, 0(a1)
548+
; RV32IA-NEXT: sw a1, 0(a0)
549549
; RV32IA-NEXT: ret
550550
store atomic i32 %b, i32* %a release, align 4
551551
ret void
@@ -565,7 +565,7 @@ define void @atomic_store_i32_seq_cst(i32 *%a, i32 %b) nounwind {
565565
; RV32IA-LABEL: atomic_store_i32_seq_cst:
566566
; RV32IA: # %bb.0:
567567
; RV32IA-NEXT: fence rw, w
568-
; RV32IA-NEXT: sw a0, 0(a1)
568+
; RV32IA-NEXT: sw a1, 0(a0)
569569
; RV32IA-NEXT: ret
570570
store atomic i32 %b, i32* %a seq_cst, align 4
571571
ret void

0 commit comments

Comments
 (0)