Skip to content

Commit f24450c

Browse files
committed
[SelectionDAG][RISCV] Use TypeSize version of ComputeValueVTs in TargetLowering::LowerCallTo.
This is needed to support non-intrinsic functions returning tuple types which are represented as structs with scalable vector types in IR. I suspect this may have been broken since https://reviews.llvm.org/D158115
1 parent 4bf8dc1 commit f24450c

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10500,14 +10500,14 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
1050010500
CLI.Ins.clear();
1050110501
Type *OrigRetTy = CLI.RetTy;
1050210502
SmallVector<EVT, 4> RetTys;
10503-
SmallVector<uint64_t, 4> Offsets;
10503+
SmallVector<TypeSize, 4> Offsets;
1050410504
auto &DL = CLI.DAG.getDataLayout();
10505-
ComputeValueVTs(*this, DL, CLI.RetTy, RetTys, &Offsets, 0);
10505+
ComputeValueVTs(*this, DL, CLI.RetTy, RetTys, &Offsets);
1050610506

1050710507
if (CLI.IsPostTypeLegalization) {
1050810508
// If we are lowering a libcall after legalization, split the return type.
1050910509
SmallVector<EVT, 4> OldRetTys;
10510-
SmallVector<uint64_t, 4> OldOffsets;
10510+
SmallVector<TypeSize, 4> OldOffsets;
1051110511
RetTys.swap(OldRetTys);
1051210512
Offsets.swap(OldOffsets);
1051310513

@@ -10519,7 +10519,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
1051910519
unsigned RegisterVTByteSZ = RegisterVT.getSizeInBits() / 8;
1052010520
RetTys.append(NumRegs, RegisterVT);
1052110521
for (unsigned j = 0; j != NumRegs; ++j)
10522-
Offsets.push_back(Offset + j * RegisterVTByteSZ);
10522+
Offsets.push_back(TypeSize::getFixed(Offset + j * RegisterVTByteSZ));
1052310523
}
1052410524
}
1052510525

llvm/test/CodeGen/RISCV/rvv/calling-conv.ll

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,59 @@ define <vscale x 32 x i32> @caller_scalable_vector_split_indirect(<vscale x 32 x
8686
%a = call <vscale x 32 x i32> @callee_scalable_vector_split_indirect(<vscale x 32 x i32> zeroinitializer, <vscale x 32 x i32> %x)
8787
ret <vscale x 32 x i32> %a
8888
}
89+
90+
define {<vscale x 4 x i32>, <vscale x 4 x i32>} @caller_tuple_return() {
91+
; RV32-LABEL: caller_tuple_return:
92+
; RV32: # %bb.0:
93+
; RV32-NEXT: addi sp, sp, -16
94+
; RV32-NEXT: .cfi_def_cfa_offset 16
95+
; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
96+
; RV32-NEXT: .cfi_offset ra, -4
97+
; RV32-NEXT: call callee_tuple_return
98+
; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
99+
; RV32-NEXT: addi sp, sp, 16
100+
; RV32-NEXT: ret
101+
;
102+
; RV64-LABEL: caller_tuple_return:
103+
; RV64: # %bb.0:
104+
; RV64-NEXT: addi sp, sp, -16
105+
; RV64-NEXT: .cfi_def_cfa_offset 16
106+
; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
107+
; RV64-NEXT: .cfi_offset ra, -8
108+
; RV64-NEXT: call callee_tuple_return
109+
; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
110+
; RV64-NEXT: addi sp, sp, 16
111+
; RV64-NEXT: ret
112+
%a = call {<vscale x 4 x i32>, <vscale x 4 x i32>} @callee_tuple_return()
113+
ret {<vscale x 4 x i32>, <vscale x 4 x i32>} %a
114+
}
115+
116+
declare {<vscale x 4 x i32>, <vscale x 4 x i32>} @callee_tuple_return()
117+
118+
define void @caller_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>} %x) {
119+
; RV32-LABEL: caller_tuple_argument:
120+
; RV32: # %bb.0:
121+
; RV32-NEXT: addi sp, sp, -16
122+
; RV32-NEXT: .cfi_def_cfa_offset 16
123+
; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
124+
; RV32-NEXT: .cfi_offset ra, -4
125+
; RV32-NEXT: call callee_tuple_argument
126+
; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
127+
; RV32-NEXT: addi sp, sp, 16
128+
; RV32-NEXT: ret
129+
;
130+
; RV64-LABEL: caller_tuple_argument:
131+
; RV64: # %bb.0:
132+
; RV64-NEXT: addi sp, sp, -16
133+
; RV64-NEXT: .cfi_def_cfa_offset 16
134+
; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
135+
; RV64-NEXT: .cfi_offset ra, -8
136+
; RV64-NEXT: call callee_tuple_argument
137+
; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
138+
; RV64-NEXT: addi sp, sp, 16
139+
; RV64-NEXT: ret
140+
call void @callee_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>} %x)
141+
ret void
142+
}
143+
144+
declare void @callee_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>})

0 commit comments

Comments
 (0)