Skip to content

Commit 3c14f88

Browse files
vsemenov368igcbot
authored andcommitted
Fix handling genx volatile ptr as a function argument in VC
.
1 parent b5d8422 commit 3c14f88

File tree

2 files changed

+96
-12
lines changed

2 files changed

+96
-12
lines changed

IGC/VectorCompiler/lib/Utils/GenX/TransformArgCopy.cpp

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*========================== begin_copyright_notice ============================
22
3-
Copyright (C) 2022-2024 Intel Corporation
3+
Copyright (C) 2022-2025 Intel Corporation
44
55
SPDX-License-Identifier: MIT
66
@@ -360,7 +360,7 @@ vc::OrigArgInfo::OrigArgInfo(Type *TyIn, ArgKind KindIn, int NewIdxIn)
360360
: TransformedOrigType{TyIn}, Kind{KindIn}, NewIdx{NewIdxIn} {
361361
IGC_ASSERT_MESSAGE(TyIn, "Bad type provided");
362362
IGC_ASSERT_MESSAGE(NewIdxIn == OmittedIdx || NewIdxIn >= 0,
363-
"Undexpected new index");
363+
"Unexpected new index");
364364
}
365365

366366
int vc::OrigArgInfo::getNewIdx() const {
@@ -573,10 +573,21 @@ getTransformedFuncCallArgs(CallInst &OrigCall,
573573
default: {
574574
IGC_ASSERT_MESSAGE(Kind == ArgKind::CopyIn || Kind == ArgKind::CopyInOut,
575575
"unexpected arg kind");
576-
LoadInst *Load =
577-
new LoadInst(OrigArgData.getTransformedOrigType(), OrigArg.get(),
578-
OrigArg.get()->getName() + ".val",
579-
/* isVolatile */ false, &OrigCall);
576+
577+
IRBuilder<> Builder(&OrigCall);
578+
579+
auto *Arg = OrigArg.get();
580+
Value *Load = nullptr;
581+
if (auto *G = dyn_cast<GlobalVariable>(Arg);
582+
G && G->hasAttribute("genx_volatile")) {
583+
auto *Fn = GenXIntrinsic::getGenXDeclaration(
584+
G->getParent(), GenXIntrinsic::genx_vload,
585+
{OrigArgData.getTransformedOrigType(), G->getType()});
586+
Load = Builder.CreateCall(Fn, G, Arg->getName() + ".val");
587+
} else {
588+
Load = Builder.CreateLoad(OrigArgData.getTransformedOrigType(), Arg,
589+
Arg->getName() + ".val");
590+
}
580591
NewCallOps.push_back(Load);
581592
break;
582593
}
@@ -645,15 +656,26 @@ static void handleRetValuePortion(int RetIdx, RetToArgLink ArgInfo,
645656
IGC_ASSERT_MESSAGE(
646657
Kind == GlobalArgKind::ByValueInOut,
647658
"only passed by value localized global should be copied-out");
648-
Builder.CreateStore(
649-
OutVal, NewFuncInfo.getGlobalArgsInfo().getGlobalForArgNo(NewIdx));
659+
auto *G = NewFuncInfo.getGlobalArgsInfo().getGlobalForArgNo(NewIdx);
660+
IGC_ASSERT_MESSAGE(!G->hasAttribute("genx_volatile"),
661+
"genx_volatile is not expected");
662+
Builder.CreateStore(OutVal, G);
650663
} else {
651664
// Use orig index: working with orig call's argument
652665
int OrigArgIdx = ArgInfo.getOrigIdx();
653666
auto Kind = NewFuncInfo.getOrigArgInfo()[OrigArgIdx].getKind();
654667
IGC_ASSERT_MESSAGE(Kind == ArgKind::CopyInOut || Kind == ArgKind::CopyOut,
655668
"only copy (in-)out args are expected");
656-
Builder.CreateStore(OutVal, OrigCall.getArgOperand(OrigArgIdx));
669+
auto *Arg = OrigCall.getArgOperand(OrigArgIdx);
670+
if (auto *G = dyn_cast<GlobalVariable>(Arg);
671+
G && G->hasAttribute("genx_volatile")) {
672+
auto *Fn = GenXIntrinsic::getGenXDeclaration(
673+
G->getParent(), GenXIntrinsic::genx_vstore,
674+
{OutVal->getType(), G->getType()});
675+
Builder.CreateCall(Fn, {OutVal, G});
676+
} else {
677+
Builder.CreateStore(OutVal, Arg);
678+
}
657679
}
658680
}
659681

@@ -782,7 +804,7 @@ static Value *passGlobalAsCallArg(GlobalArgInfo GAI, CallInst &OrigCall) {
782804
// No additional work when addrspaces match
783805
if (GVTy->getAddressSpace() == vc::AddrSpace::Private)
784806
return GAI.GV;
785-
// Need to add a temprorary cast inst to match types.
807+
// Need to add a temporary cast inst to match types.
786808
// When this switch to the caller, it'll remove this cast.
787809
return new AddrSpaceCastInst{
788810
GAI.GV, vc::changeAddrSpace(GVTy, vc::AddrSpace::Private),
@@ -961,9 +983,9 @@ std::vector<Value *> vc::FuncBodyTransfer::handleTransformedFuncArgs() {
961983
if (Replacement->getType() == OrigArg.getType())
962984
return Replacement;
963985
IGC_ASSERT_MESSAGE(isa<PointerType>(Replacement->getType()),
964-
"only pointers can posibly mismatch");
986+
"only pointers can possibly mismatch");
965987
IGC_ASSERT_MESSAGE(isa<PointerType>(OrigArg.getType()),
966-
"only pointers can posibly mismatch");
988+
"only pointers can possibly mismatch");
967989
IGC_ASSERT_MESSAGE(
968990
Replacement->getType()->getPointerAddressSpace() !=
969991
OrigArg.getType()->getPointerAddressSpace(),
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; RUN: %opt_typed_ptrs %use_old_pass_manager% -CMABILegacy -march=genx64 -mcpu=XeHPG -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-TYPED-PTRS
10+
; RUN: %opt_opaque_ptrs %use_old_pass_manager% -CMABILegacy -march=genx64 -mcpu=XeHPG -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-OPAQUE-PTRS
11+
12+
; RUN: %opt_new_pm_typed -passes=CMABI -march=genx64 -mcpu=XeHPG -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-TYPED-PTRS
13+
; RUN: %opt_new_pm_opaque -passes=CMABI -march=genx64 -mcpu=XeHPG -S < %s | FileCheck %s --check-prefixes=CHECK,CHECK-OPAQUE-PTRS
14+
15+
; CHECK: [[GV:@[^ ]+]] = internal global <32 x i8> undef #0
16+
; CHECK: [[G:@[^ ]+]] = internal global <32 x i8> undef #1
17+
@gv = internal global <32 x i8> undef #0
18+
@g = internal global <32 x i8> undef #1
19+
20+
; CHECK: define internal spir_func <32 x i8> @bar(<32 x i8> [[ARG:%[^ ]+]], <32 x i8> %data) {
21+
define internal spir_func void @bar(<32 x i8>* %arg, <32 x i8> %data) {
22+
; CHECK: [[ALLOCA:%[^ ]+]] = alloca <32 x i8>, align 32
23+
; CHECK-TYPED-PTRS: store <32 x i8> [[ARG]], <32 x i8>* [[ALLOCA]], align 32
24+
; CHECK-TYPED-PTRS: store <32 x i8> %data, <32 x i8>* [[ALLOCA]], align 1
25+
; CHECK-TYPED-PTRS: [[LOAD:%[^ ]+]] = load <32 x i8>, <32 x i8>* [[ALLOCA]], align 32
26+
; CHECK-OPAQUE-PTRS: store <32 x i8> [[ARG]], ptr [[ALLOCA]], align 32
27+
; CHECK-OPAQUE-PTRS: store <32 x i8> %data, ptr [[ALLOCA]], align 1
28+
; CHECK-OPAQUE-PTRS: [[LOAD:%[^ ]+]] = load <32 x i8>, ptr [[ALLOCA]], align 32
29+
; CHECK: ret <32 x i8> [[LOAD]]
30+
31+
store <32 x i8> %data, <32 x i8>* %arg, align 1
32+
ret void
33+
}
34+
35+
; CHECK-LABEL: @test_genx_volatile
36+
define void @test_genx_volatile(<32 x i8> %arg) {
37+
; CHECK-TYPED-PTRS: [[LOAD:%[^ ]+]] = call <32 x i8> @llvm.genx.vload.v32i8.p0v32i8(<32 x i8>* [[GV]])
38+
; CHECK-OPAQUE-PTRS: [[LOAD:%[^ ]+]] = call <32 x i8> @llvm.genx.vload.v32i8.p0(ptr [[GV]])
39+
; CHECK: [[RET:%[^ ]+]] = call spir_func <32 x i8> @bar(<32 x i8> [[LOAD]], <32 x i8> %arg)
40+
; CHECK-TYPED-PTRS: call void @llvm.genx.vstore.v32i8.p0v32i8(<32 x i8> [[RET]], <32 x i8>* [[GV]])
41+
; CHECK-OPAQUE-PTRS: call void @llvm.genx.vstore.v32i8.p0(<32 x i8> [[RET]], ptr [[GV]])
42+
43+
call spir_func void @bar(<32 x i8>* @gv, <32 x i8> %arg)
44+
ret void
45+
}
46+
47+
; CHECK-LABEL: @test_genx_none_volatile
48+
define void @test_genx_none_volatile(<32 x i8> %arg) {
49+
; CHECK: [[ALLOCA:%[^ ]+]] = alloca <32 x i8>, align 1
50+
; CHECK-TYPED-PTRS: [[LOAD:%[^ ]+]] = load <32 x i8>, <32 x i8>* [[ALLOCA]], align 32
51+
; CHECK-OPAQUE-PTRS: [[LOAD:%[^ ]+]] = load <32 x i8>, ptr [[ALLOCA]], align 32
52+
; CHECK: [[RET:%[^ ]+]] = call spir_func <32 x i8> @bar(<32 x i8> [[LOAD]], <32 x i8> %arg)
53+
; CHECK-TYPED-PTRS: store <32 x i8> [[RET]], <32 x i8>* [[ALLOCA]], align 32
54+
; CHECK-OPAQUE-PTRS: store <32 x i8> [[RET]], ptr [[ALLOCA]], align 32
55+
56+
call spir_func void @bar(<32 x i8>* @g, <32 x i8> %arg)
57+
ret void
58+
}
59+
60+
61+
attributes #0 = { "genx_volatile" }
62+
attributes #1 = { "VCGlobalVariable" }

0 commit comments

Comments
 (0)