Skip to content

Commit c67ed2f

Browse files
authored
[SelectionDAG][RISCV] Use TypeSize version of ComputeValueVTs in TargetLowering::LowerCallTo. (#86166)
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 4865dab commit c67ed2f

File tree

2 files changed

+80
-4
lines changed

2 files changed

+80
-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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,79 @@ 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: vmv2r.v v12, v8
99+
; RV32-NEXT: vmv2r.v v8, v10
100+
; RV32-NEXT: vmv2r.v v10, v12
101+
; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
102+
; RV32-NEXT: addi sp, sp, 16
103+
; RV32-NEXT: ret
104+
;
105+
; RV64-LABEL: caller_tuple_return:
106+
; RV64: # %bb.0:
107+
; RV64-NEXT: addi sp, sp, -16
108+
; RV64-NEXT: .cfi_def_cfa_offset 16
109+
; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
110+
; RV64-NEXT: .cfi_offset ra, -8
111+
; RV64-NEXT: call callee_tuple_return
112+
; RV64-NEXT: vmv2r.v v12, v8
113+
; RV64-NEXT: vmv2r.v v8, v10
114+
; RV64-NEXT: vmv2r.v v10, v12
115+
; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
116+
; RV64-NEXT: addi sp, sp, 16
117+
; RV64-NEXT: ret
118+
%a = call {<vscale x 4 x i32>, <vscale x 4 x i32>} @callee_tuple_return()
119+
%b = extractvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %a, 0
120+
%c = extractvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %a, 1
121+
%d = insertvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} poison, <vscale x 4 x i32> %c, 0
122+
%e = insertvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %d, <vscale x 4 x i32> %b, 1
123+
ret {<vscale x 4 x i32>, <vscale x 4 x i32>} %e
124+
}
125+
126+
declare {<vscale x 4 x i32>, <vscale x 4 x i32>} @callee_tuple_return()
127+
128+
define void @caller_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>} %x) {
129+
; RV32-LABEL: caller_tuple_argument:
130+
; RV32: # %bb.0:
131+
; RV32-NEXT: addi sp, sp, -16
132+
; RV32-NEXT: .cfi_def_cfa_offset 16
133+
; RV32-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
134+
; RV32-NEXT: .cfi_offset ra, -4
135+
; RV32-NEXT: vmv2r.v v12, v8
136+
; RV32-NEXT: vmv2r.v v8, v10
137+
; RV32-NEXT: vmv2r.v v10, v12
138+
; RV32-NEXT: call callee_tuple_argument
139+
; RV32-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
140+
; RV32-NEXT: addi sp, sp, 16
141+
; RV32-NEXT: ret
142+
;
143+
; RV64-LABEL: caller_tuple_argument:
144+
; RV64: # %bb.0:
145+
; RV64-NEXT: addi sp, sp, -16
146+
; RV64-NEXT: .cfi_def_cfa_offset 16
147+
; RV64-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
148+
; RV64-NEXT: .cfi_offset ra, -8
149+
; RV64-NEXT: vmv2r.v v12, v8
150+
; RV64-NEXT: vmv2r.v v8, v10
151+
; RV64-NEXT: vmv2r.v v10, v12
152+
; RV64-NEXT: call callee_tuple_argument
153+
; RV64-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
154+
; RV64-NEXT: addi sp, sp, 16
155+
; RV64-NEXT: ret
156+
%a = extractvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %x, 0
157+
%b = extractvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %x, 1
158+
%c = insertvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} poison, <vscale x 4 x i32> %b, 0
159+
%d = insertvalue {<vscale x 4 x i32>, <vscale x 4 x i32>} %c, <vscale x 4 x i32> %a, 1
160+
call void @callee_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>} %d)
161+
ret void
162+
}
163+
164+
declare void @callee_tuple_argument({<vscale x 4 x i32>, <vscale x 4 x i32>})

0 commit comments

Comments
 (0)