Skip to content

Commit 1cf998d

Browse files
ViacheslavRbigcbot
authored andcommitted
Fixing TypesLegalization pass
Fixing TypesLegalization pass to properly support structures as function arguments.
1 parent cdbe8d7 commit 1cf998d

2 files changed

Lines changed: 36 additions & 6 deletions

File tree

IGC/AdaptorCommon/TypesLegalizationPass.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ Value *TypesLegalizationPass::ResolveValue(Instruction *ip, Value *val, SmallVec
252252
auto evi = ev->getIndices();
253253
SmallVector<unsigned, 8> newIndices(evi.begin(), evi.end());
254254
newIndices.append(indices);
255-
256255
return ResolveValue(ev, ev->getAggregateOperand(), newIndices);
257256
} else if (auto *II = dyn_cast<IntrinsicInst>(val)) {
258257
switch (II->getIntrinsicID()) {
@@ -275,11 +274,7 @@ Value *TypesLegalizationPass::ResolveValue(Instruction *ip, Value *val, SmallVec
275274
IRBuilder<> builder(ip);
276275
return builder.CreateExtractValue(val, indices);
277276
} else if (isa<Argument>(val)) {
278-
279-
IGC_ASSERT_MESSAGE(!val->getType()->isStructTy(),
280-
"Illegal IR. Structures are passed as a pointer to a struct with the byval attribute.!");
281-
282-
if ((val->getType()->isArrayTy())) {
277+
if (val->getType()->isArrayTy() || val->getType()->isStructTy()) {
283278
IRBuilder<> builder(ip);
284279
return builder.CreateExtractValue(val, indices);
285280
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2026 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: igc_opt %s --opaque-pointers -S -o - -types-legalization-pass -dce | FileCheck %s
10+
; REQUIRES: llvm-14-plus
11+
12+
13+
; CHECK-LABEL: define spir_kernel void @test_ResolveStoreArgStruct(%nested.struct.type %in, ptr %out_ptr) {
14+
; CHECK: [[T1:%.*]] = extractvalue %nested.struct.type %in, 0, 0
15+
; CHECK-NEXT: [[T2:%.*]] = getelementptr %nested.struct.type, ptr %out_ptr, i32 0, i32 0, i32 0
16+
; CHECK-NEXT: store i32 [[T1]], ptr [[T2]], align 4
17+
; CHECK-NEXT: [[T3:%.*]] = extractvalue %nested.struct.type %in, 0, 1
18+
; CHECK-NEXT: [[T4:%.*]] = getelementptr %nested.struct.type, ptr %out_ptr, i32 0, i32 0, i32 1
19+
; CHECK-NEXT: store double [[T3]], ptr [[T4]], align 4
20+
; CHECK-NEXT: [[T5:%.*]] = extractvalue %nested.struct.type %in, 1, 0
21+
; CHECK-NEXT: [[T6:%.*]] = getelementptr %nested.struct.type, ptr %out_ptr, i32 0, i32 1, i32 0
22+
; CHECK-NEXT: store i32 [[T5]], ptr [[T6]], align 4
23+
; CHECK-NEXT: [[T7:%.*]] = extractvalue %nested.struct.type %in, 1, 1
24+
; CHECK-NEXT: [[T8:%.*]] = getelementptr %nested.struct.type, ptr %out_ptr, i32 0, i32 1, i32 1
25+
; CHECK-NEXT: store i32 [[T7]], ptr [[T8]], align 4
26+
27+
28+
%simple.struct.type = type { i32, double }
29+
%nested.struct.type = type { %simple.struct.type, [2 x i32] }
30+
31+
define spir_kernel void @test_ResolveStoreArgStruct(%nested.struct.type %in, ptr %out_ptr)
32+
{
33+
store %nested.struct.type %in, ptr %out_ptr, align 4
34+
ret void
35+
}

0 commit comments

Comments
 (0)