Skip to content

Commit e972835

Browse files
committed
[RISCV] Return false for Zalasr load/store in isWorthFoldingAdd.
The Zalasr load/store don't support reg-imm addressing modes so they can't fold an ADDI.
1 parent dcfe7d4 commit e972835

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp

Lines changed: 2 additions & 0 deletions
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;

llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
22
; RUN: llc < %s -mtriple=riscv32 -mattr=+a,+experimental-zalasr | FileCheck %s
33

4-
; FIXME: We should not fold -1920 into the lw instruction because we still
4+
; Make sure we don't fold -1920 into the lw instruction because we still
55
; need it for the sw.rl.
66

77
define i32 @test(ptr %p) {
88
; CHECK-LABEL: test:
99
; CHECK: # %bb.0: # %entry
1010
; CHECK-NEXT: lui a1, 20
11-
; CHECK-NEXT: add a2, a0, a1
1211
; CHECK-NEXT: addi a1, a1, -1920
1312
; CHECK-NEXT: add a0, a0, a1
1413
; CHECK-NEXT: li a1, 2
1514
; CHECK-NEXT: sw.rl a1, (a0)
16-
; CHECK-NEXT: lw a0, -1920(a2)
15+
; CHECK-NEXT: lw a0, 0(a0)
1716
; CHECK-NEXT: ret
1817
entry:
1918
%gep0 = getelementptr [65536 x i32], ptr %p, i64 0, i32 20000

0 commit comments

Comments
 (0)