Skip to content

Commit ff6a23d

Browse files
authored
[RISCV] Return false for Zalasr load/store in isWorthFoldingAdd. (#136799)
The Zalasr load/store don't support reg-imm addressing modes so they can't fold an ADDI.
1 parent f418981 commit ff6a23d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2599,6 +2599,8 @@ static bool isWorthFoldingAdd(SDValue Add) {
25992599
if (User->getOpcode() == ISD::ATOMIC_STORE &&
26002600
cast<AtomicSDNode>(User)->getVal() == Add)
26012601
return false;
2602+
if (isStrongerThanMonotonic(cast<MemSDNode>(User)->getSuccessOrdering()))
2603+
return false;
26022604
}
26032605

26042606
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
2+
; RUN: llc < %s -mtriple=riscv32 -mattr=+a,+experimental-zalasr | FileCheck %s
3+
4+
; Make sure we don't fold -1920 into the lw instruction because we still
5+
; need it for the sw.rl.
6+
7+
define i32 @test(ptr %p) {
8+
; CHECK-LABEL: test:
9+
; CHECK: # %bb.0: # %entry
10+
; CHECK-NEXT: lui a1, 20
11+
; CHECK-NEXT: addi a1, a1, -1920
12+
; CHECK-NEXT: add a0, a0, a1
13+
; CHECK-NEXT: li a1, 2
14+
; CHECK-NEXT: sw.rl a1, (a0)
15+
; CHECK-NEXT: lw a0, 0(a0)
16+
; CHECK-NEXT: ret
17+
entry:
18+
%gep0 = getelementptr [65536 x i32], ptr %p, i64 0, i32 20000
19+
store atomic i32 2, ptr %gep0 seq_cst, align 4
20+
%a = load i32, ptr %gep0
21+
ret i32 %a
22+
}

0 commit comments

Comments
 (0)