[llvm] ff6a23d - [RISCV] Return false for Zalasr load/store in isWorthFoldingAdd. (#136799)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 23 14:47:45 PDT 2025
Author: Craig Topper
Date: 2025-04-23T14:47:42-07:00
New Revision: ff6a23d65eccba0991244c4127506452e1030393
URL: https://github.com/llvm/llvm-project/commit/ff6a23d65eccba0991244c4127506452e1030393
DIFF: https://github.com/llvm/llvm-project/commit/ff6a23d65eccba0991244c4127506452e1030393.diff
LOG: [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.
Added:
llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll
Modified:
llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
index 4de93d5d5abde..ad77106d386c9 100644
--- a/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
@@ -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;
diff --git a/llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll b/llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll
new file mode 100644
index 0000000000000..78653ba3b78ef
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/zalasr-offset-folding.ll
@@ -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
+}
More information about the llvm-commits
mailing list