-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[RISCV] Add LD_RV32/SD_RV32 to RISCVInstrInfo::canFoldIntoAddrMode. #140631
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140631.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
index e9e5fa8d8042a..2f152305e2ae0 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.cpp
@@ -2935,6 +2935,7 @@ bool RISCVInstrInfo::canFoldIntoAddrMode(const MachineInstr &MemI, Register Reg,
case RISCV::LW_INX:
case RISCV::LWU:
case RISCV::LD:
+ case RISCV::LD_RV32:
case RISCV::FLH:
case RISCV::FLW:
case RISCV::FLD:
@@ -2944,6 +2945,7 @@ bool RISCVInstrInfo::canFoldIntoAddrMode(const MachineInstr &MemI, Register Reg,
case RISCV::SW:
case RISCV::SW_INX:
case RISCV::SD:
+ case RISCV::SD_RV32:
case RISCV::FSH:
case RISCV::FSW:
case RISCV::FSD:
diff --git a/llvm/test/CodeGen/RISCV/fold-addi-loadstore-zilsd.ll b/llvm/test/CodeGen/RISCV/fold-addi-loadstore-zilsd.ll
index e34c5272ebaeb..fce42cb7a46f7 100644
--- a/llvm/test/CodeGen/RISCV/fold-addi-loadstore-zilsd.ll
+++ b/llvm/test/CodeGen/RISCV/fold-addi-loadstore-zilsd.ll
@@ -28,3 +28,111 @@ entry:
store double 0.0, ptr @g_0
ret void
}
+
+%struct.S = type { double, double }
+
+define double @fold_addi_from_different_bb(i64 %k, i64 %n, ptr %a) nounwind {
+; CHECK-LABEL: fold_addi_from_different_bb:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: addi sp, sp, -48
+; CHECK-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s0, 40(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s1, 36(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s2, 32(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s3, 28(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s4, 24(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s5, 20(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s6, 16(sp) # 4-byte Folded Spill
+; CHECK-NEXT: sw s7, 12(sp) # 4-byte Folded Spill
+; CHECK-NEXT: mv s0, a4
+; CHECK-NEXT: mv s1, a3
+; CHECK-NEXT: mv s2, a2
+; CHECK-NEXT: beqz a3, .LBB2_3
+; CHECK-NEXT: # %bb.1: # %entry
+; CHECK-NEXT: slti a1, s1, 0
+; CHECK-NEXT: beqz a1, .LBB2_4
+; CHECK-NEXT: .LBB2_2:
+; CHECK-NEXT: fcvt.d.w s4, zero
+; CHECK-NEXT: j .LBB2_6
+; CHECK-NEXT: .LBB2_3:
+; CHECK-NEXT: seqz a1, s2
+; CHECK-NEXT: bnez a1, .LBB2_2
+; CHECK-NEXT: .LBB2_4: # %for.body.lr.ph
+; CHECK-NEXT: li s3, 0
+; CHECK-NEXT: li s6, 0
+; CHECK-NEXT: slli a0, a0, 4
+; CHECK-NEXT: add s7, s0, a0
+; CHECK-NEXT: fcvt.d.w s4, zero
+; CHECK-NEXT: .LBB2_5: # %for.body
+; CHECK-NEXT: # =>This Inner Loop Header: Depth=1
+; CHECK-NEXT: mv a0, s0
+; CHECK-NEXT: call f
+; CHECK-NEXT: ld a0, 8(s7)
+; CHECK-NEXT: addi s3, s3, 1
+; CHECK-NEXT: seqz a2, s3
+; CHECK-NEXT: add s6, s6, a2
+; CHECK-NEXT: xor a2, s3, s2
+; CHECK-NEXT: xor a3, s6, s1
+; CHECK-NEXT: or a2, a2, a3
+; CHECK-NEXT: fadd.d s4, a0, s4
+; CHECK-NEXT: bnez a2, .LBB2_5
+; CHECK-NEXT: .LBB2_6: # %for.cond.cleanup
+; CHECK-NEXT: mv a0, s4
+; CHECK-NEXT: mv a1, s5
+; CHECK-NEXT: lw ra, 44(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s0, 40(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s1, 36(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s2, 32(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s3, 28(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s4, 24(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s5, 20(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s6, 16(sp) # 4-byte Folded Reload
+; CHECK-NEXT: lw s7, 12(sp) # 4-byte Folded Reload
+; CHECK-NEXT: addi sp, sp, 48
+; CHECK-NEXT: ret
+entry:
+ %cmp4 = icmp sgt i64 %n, 0
+ br i1 %cmp4, label %for.body.lr.ph, label %for.cond.cleanup
+
+for.body.lr.ph: ; preds = %entry
+ %y = getelementptr inbounds %struct.S, ptr %a, i64 %k, i32 1
+ br label %for.body
+
+for.cond.cleanup: ; preds = %for.body, %entry
+ %s.0.lcssa = phi double [ 0.0, %entry ], [ %add, %for.body ]
+ ret double %s.0.lcssa
+
+for.body: ; preds = %for.body.lr.ph, %for.body
+ %i.06 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
+ %s.05 = phi double [ 0.0, %for.body.lr.ph ], [ %add, %for.body ]
+ call void @f(ptr %a)
+ %0 = load double, ptr %y, align 8
+ %add = fadd double %0, %s.05
+ %inc = add nuw nsw i64 %i.06, 1
+ %exitcond.not = icmp eq i64 %inc, %n
+ br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
+}
+
+declare void @f(ptr)
+
+define void @split_offset(ptr %dest, double %x) {
+; CHECK-LABEL: split_offset:
+; CHECK: # %bb.0:
+; CHECK-NEXT: mv a3, a2
+; CHECK-NEXT: addi a0, a0, 2047
+; CHECK-NEXT: mv a2, a1
+; CHECK-NEXT: sd a2, 1(a0)
+; CHECK-NEXT: sd a2, 9(a0)
+; CHECK-NEXT: sd a2, 17(a0)
+; CHECK-NEXT: sd a2, 25(a0)
+; CHECK-NEXT: ret
+ %p1 = getelementptr double, ptr %dest, i32 256
+ store double %x, ptr %p1
+ %p2 = getelementptr double, ptr %dest, i32 257
+ store double %x, ptr %p2
+ %p3 = getelementptr double, ptr %dest, i32 258
+ store double %x, ptr %p3
+ %p4 = getelementptr double, ptr %dest, i32 259
+ store double %x, ptr %p4
+ ret void
+}
|
c8806fa
to
5148669
Compare
preames
approved these changes
May 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lenary
approved these changes
May 19, 2025
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Jun 3, 2025
ajaden-codes
pushed a commit
to Jaddyen/llvm-project
that referenced
this pull request
Jun 6, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.