Skip to content

[RISCV] Return false for Zalasr load/store in isWorthFoldingAdd. #136799

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2599,6 +2599,8 @@ static bool isWorthFoldingAdd(SDValue Add) {
if (User->getOpcode() == ISD::ATOMIC_STORE &&
cast<AtomicSDNode>(User)->getVal() == Add)
return false;
if (isStrongerThanMonotonic(cast<MemSDNode>(User)->getSuccessOrdering()))
return false;
}

return true;
Expand Down
22 changes: 22 additions & 0 deletions llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
; RUN: llc < %s -mtriple=riscv32 -mattr=+a,+experimental-zalasr | FileCheck %s

; Make sure we don't fold -1920 into the lw instruction because we still
; need it for the sw.rl.

define i32 @test(ptr %p) {
; CHECK-LABEL: test:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: lui a1, 20
; CHECK-NEXT: addi a1, a1, -1920
; CHECK-NEXT: add a0, a0, a1
; CHECK-NEXT: li a1, 2
; CHECK-NEXT: sw.rl a1, (a0)
; CHECK-NEXT: lw a0, 0(a0)
; CHECK-NEXT: ret
entry:
%gep0 = getelementptr [65536 x i32], ptr %p, i64 0, i32 20000
store atomic i32 2, ptr %gep0 seq_cst, align 4
%a = load i32, ptr %gep0
ret i32 %a
}
Loading