Skip to content

Commit ad36cbf

Browse files
fda0igcbot
authored andcommitted
Fix emitting of phi values with structs
In function GetSymbol match with previously created CVariable if it's a struct value instead of creating a new value. In MovPhiSources copy the whole CVariable with all elements instead of copying only the first element.
1 parent af17e0f commit ad36cbf

File tree

3 files changed

+101
-12
lines changed

3 files changed

+101
-12
lines changed

IGC/Compiler/CISACodeGen/CShader.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -3194,6 +3194,14 @@ unsigned int CShader::EvaluateSIMDConstExpr(Value* C)
31943194
CVariable* CShader::GetSymbol(llvm::Value* value, bool fromConstantPool,
31953195
e_alignment MinAlign)
31963196
{
3197+
auto it = symbolMapping.find(value);
3198+
3199+
// mapping exists, return
3200+
if (it != symbolMapping.end())
3201+
{
3202+
return it->second;
3203+
}
3204+
31973205
CVariable* var = nullptr;
31983206

31993207
// Symbol mappings for struct types
@@ -3308,14 +3316,6 @@ CVariable* CShader::GetSymbol(llvm::Value* value, bool fromConstantPool,
33083316
}
33093317
}
33103318

3311-
auto it = symbolMapping.find(value);
3312-
3313-
// mapping exists, return
3314-
if (it != symbolMapping.end())
3315-
{
3316-
return it->second;
3317-
}
3318-
33193319
if (IGC_IS_FLAG_ENABLED(EnableDeSSA) &&
33203320
m_deSSA && value != m_deSSA->getNodeValue(value))
33213321
{

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1556,9 +1556,10 @@ void EmitPass::MovPhiSources(llvm::BasicBlock* aBB)
15561556
unsigned numElt;
15571557
bool isSplat;
15581558
uint64_t splatValue;
1559+
Type *type;
15591560

1560-
VTyInfo() : numElt(0), isSplat(false), splatValue(0) { }
1561-
explicit VTyInfo(Value * V) : numElt(0), isSplat(false), splatValue(0) {
1561+
VTyInfo() : numElt(0), isSplat(false), splatValue(0), type(nullptr) { }
1562+
explicit VTyInfo(Value * V) : numElt(0), isSplat(false), splatValue(0), type(V->getType()) {
15621563
if (IGCLLVM::FixedVectorType * vTy = dyn_cast<IGCLLVM::FixedVectorType>(V->getType())) {
15631564
numElt = vTy->getNumElements();
15641565
if (isa<ConstantAggregateZero>(V)) {
@@ -1751,8 +1752,7 @@ void EmitPass::MovPhiSources(llvm::BasicBlock* aBB)
17511752
emitVectorCopy(dst, src, vTyInfo.numElt);
17521753
}
17531754
else {
1754-
m_encoder->Copy(dst, src);
1755-
m_encoder->Push();
1755+
emitCopyAll(dst, src, vTyInfo.type);
17561756
}
17571757
}
17581758
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
;=========================== begin_copyright_notice ============================
2+
;
3+
; Copyright (C) 2025 Intel Corporation
4+
;
5+
; SPDX-License-Identifier: MIT
6+
;
7+
;============================ end_copyright_notice =============================
8+
9+
; REQUIRES: regkeys
10+
11+
; RUN: igc_opt --opaque-pointers -platformdg2 -simd-mode 8 -inputcs -igc-emit-visa %s -regkey DumpVISAASMToConsole | FileCheck %s
12+
13+
target datalayout = "e-p:32:32:32-p1:64:64:64-p2:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f16:16:16-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024-a0:0:32-n8:16:32-S32"
14+
15+
@ThreadGroupSize_X = constant i32 1
16+
@ThreadGroupSize_Y = constant i32 1
17+
@ThreadGroupSize_Z = constant i32 1
18+
19+
; CHECK: .kernel "entry"
20+
; CHECK: mov (M1_NM, 1) [[VECTOR:[A-z0-9]*]](0,0)<1> 0x3f800000:f
21+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,1)<1> 0x40000000:f
22+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,2)<1> 0x40400000:f
23+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,3)<1> 0x40800000:f
24+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,4)<1> 0x40a00000:f
25+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,5)<1> 0x40c00000:f
26+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,6)<1> 0x40e00000:f
27+
; CHECK: mov (M1_NM, 1) [[VECTOR]](0,7)<1> 0x41000000:f
28+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,0)<1> 0x41100000:f
29+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,1)<1> 0x41200000:f
30+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,2)<1> 0x41300000:f
31+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,3)<1> 0x41400000:f
32+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,4)<1> 0x41500000:f
33+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,5)<1> 0x41600000:f
34+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,6)<1> 0x41700000:f
35+
; CHECK: mov (M1_NM, 1) [[VECTOR]](1,7)<1> 0x41800000:f
36+
; Check if we emit movs that fill all elements of STRUCT (32 elements / simd 8 == 4 MOVs).
37+
; CHECK: mov (M1_NM, 8) [[STRUCT:[A-z0-9]*]](0,0)<1> [[VECTOR]](0,0)<1;1,0>
38+
; CHECK: mov (M1_NM, 8) [[STRUCT]](1,0)<1> [[VECTOR]](1,0)<1;1,0>
39+
; CHECK: mov (M1_NM, 8) [[STRUCT]](2,0)<1> [[VECTOR]](0,0)<1;1,0>
40+
; CHECK: mov (M1_NM, 8) [[STRUCT]](3,0)<1> [[VECTOR]](1,0)<1;1,0>
41+
; Check if we emit copies from STRUCT to STRUCT_PHI_COPY
42+
; CHECK: mov (M1_NM, 8) [[STRUCT_PHI_COPY:[A-z0-9]*]](0,0)<1> [[STRUCT]](0,0)<1;1,0>
43+
; CHECK: mov (M1_NM, 8) [[STRUCT_PHI_COPY]](1,0)<1> [[STRUCT]](1,0)<1;1,0>
44+
; CHECK: mov (M1_NM, 8) [[STRUCT_PHI_COPY]](2,0)<1> [[STRUCT]](2,0)<1;1,0>
45+
; CHECK: mov (M1_NM, 8) [[STRUCT_PHI_COPY]](3,0)<1> [[STRUCT]](3,0)<1;1,0>
46+
; Check if EXTRACT_VECTOR mov uses STRUCT_PHI_COPY variable.
47+
; CHECK: mov (M1_NM, 8) [[EXTRACT_VECTOR:[A-z0-9]*]](0,0)<1> [[STRUCT_PHI_COPY]](0,0)<1;1,0>
48+
; CHECK: mov (M1_NM, 8) [[EXTRACT_VECTOR]](1,0)<1> [[STRUCT_PHI_COPY]](1,0)<1;1,0>
49+
; Check if we extract scalar and store it.
50+
; CHECK: mov (M1_NM, 1) [[EXTRACT_SCALAR:[A-z0-9]*]](0,0)<1> [[EXTRACT_VECTOR]](0,3)<0;1,0>
51+
; CHECK: lsc_store.ugm.wb.wb (M1_NM, 1) {{.*}} [[EXTRACT_SCALAR]]
52+
53+
define void @entry(<8 x i32> %r0, float* %result) {
54+
head:
55+
%vector0 = insertelement <16 x float> undef, float 1.0, i32 0
56+
%vector1 = insertelement <16 x float> %vector0, float 2.0, i32 1
57+
%vector2 = insertelement <16 x float> %vector1, float 3.0, i32 2
58+
%vector3 = insertelement <16 x float> %vector2, float 4.0, i32 3
59+
%vector4 = insertelement <16 x float> %vector3, float 5.0, i32 4
60+
%vector5 = insertelement <16 x float> %vector4, float 6.0, i32 5
61+
%vector6 = insertelement <16 x float> %vector5, float 7.0, i32 6
62+
%vector7 = insertelement <16 x float> %vector6, float 8.0, i32 7
63+
%vector8 = insertelement <16 x float> %vector7, float 9.0, i32 8
64+
%vector9 = insertelement <16 x float> %vector8, float 10.0, i32 9
65+
%vector10 = insertelement <16 x float> %vector9, float 11.0, i32 10
66+
%vector11 = insertelement <16 x float> %vector10, float 12.0, i32 11
67+
%vector12 = insertelement <16 x float> %vector11, float 13.0, i32 12
68+
%vector13 = insertelement <16 x float> %vector12, float 14.0, i32 13
69+
%vector14 = insertelement <16 x float> %vector13, float 15.0, i32 14
70+
%vector15 = insertelement <16 x float> %vector14, float 16.0, i32 15
71+
72+
%vectorStruct0 = insertvalue { <16 x float>, <16 x float> } poison, <16 x float> %vector15, 0
73+
%vectorStruct1 = insertvalue { <16 x float>, <16 x float> } %vectorStruct0, <16 x float> %vector15, 1
74+
br label %body
75+
76+
body:
77+
%fromPhi = phi { <16 x float>, <16 x float> } [ %vectorStruct1, %head ]
78+
%extractVector0 = extractvalue { <16 x float>, <16 x float> } %fromPhi, 0
79+
%extractScalar3 = extractelement <16 x float> %extractVector0, i32 3
80+
store float %extractScalar3, float* %result, align 4
81+
ret void
82+
}
83+
84+
85+
!igc.functions = !{!1}
86+
87+
!1 = !{void (<8 x i32>, float*)* @entry, !2}
88+
!2 = !{!3}
89+
!3 = !{!"function_type", i32 0}

0 commit comments

Comments
 (0)