Skip to content

Commit 478d093

Browse files
authored
[RISCV][GISel] Reverse the operands the buildStore created in legalizeVAStart. (llvm#73989)
We need to store the frame index to the location pointed to by the VASTART, not the other way around.
1 parent 3a38baa commit 478d093

File tree

3 files changed

+59
-1
lines changed

3 files changed

+59
-1
lines changed

llvm/lib/Target/RISCV/GISel/RISCVLegalizerInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ bool RISCVLegalizerInfo::legalizeVAStart(MachineInstr &MI,
406406
LLT AddrTy = MIRBuilder.getMRI()->getType(MI.getOperand(0).getReg());
407407
auto FINAddr = MIRBuilder.buildFrameIndex(AddrTy, FI);
408408
assert(MI.hasOneMemOperand());
409-
MIRBuilder.buildStore(MI.getOperand(0).getReg(), FINAddr,
409+
MIRBuilder.buildStore(FINAddr, MI.getOperand(0).getReg(),
410410
*MI.memoperands()[0]);
411411
MI.eraseFromParent();
412412
return true;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv32 -run-pass=legalizer %s -o - | FileCheck --check-prefix=RV32 %s
3+
4+
---
5+
name: test_va_start
6+
tracksRegLiveness: true
7+
fixedStack:
8+
- { id: 0, size: 4, alignment: 16, isImmutable: true }
9+
stack:
10+
- { id: 0, size: 4, alignment: 4 }
11+
machineFunctionInfo:
12+
varArgsFrameIndex: -1
13+
varArgsSaveSize: 0
14+
body: |
15+
bb.1:
16+
liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17
17+
18+
; RV32-LABEL: name: test_va_start
19+
; RV32: liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17
20+
; RV32-NEXT: {{ $}}
21+
; RV32-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0
22+
; RV32-NEXT: [[FRAME_INDEX1:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
23+
; RV32-NEXT: G_STORE [[FRAME_INDEX]](p0), [[FRAME_INDEX1]](p0) :: (store (s32))
24+
; RV32-NEXT: PseudoRET
25+
%8:_(p0) = G_FRAME_INDEX %stack.0
26+
G_VASTART %8(p0) :: (store (s32))
27+
PseudoRET
28+
29+
...
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2+
# RUN: llc -mtriple=riscv64 -run-pass=legalizer %s -o - | FileCheck --check-prefix=RV64 %s
3+
4+
---
5+
name: test_va_start
6+
tracksRegLiveness: true
7+
fixedStack:
8+
- { id: 0, size: 8, alignment: 16, isImmutable: true }
9+
stack:
10+
- { id: 0, size: 8, alignment: 8 }
11+
machineFunctionInfo:
12+
varArgsFrameIndex: -1
13+
varArgsSaveSize: 0
14+
body: |
15+
bb.1:
16+
liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17
17+
18+
; RV64-LABEL: name: test_va_start
19+
; RV64: liveins: $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17
20+
; RV64-NEXT: {{ $}}
21+
; RV64-NEXT: [[FRAME_INDEX:%[0-9]+]]:_(p0) = G_FRAME_INDEX %stack.0
22+
; RV64-NEXT: [[FRAME_INDEX1:%[0-9]+]]:_(p0) = G_FRAME_INDEX %fixed-stack.0
23+
; RV64-NEXT: G_STORE [[FRAME_INDEX]](p0), [[FRAME_INDEX1]](p0) :: (store (s64))
24+
; RV64-NEXT: PseudoRET
25+
%8:_(p0) = G_FRAME_INDEX %stack.0
26+
G_VASTART %8(p0) :: (store (s64))
27+
PseudoRET
28+
29+
...

0 commit comments

Comments
 (0)