Skip to content

Commit 8a8d752

Browse files
ekochetkigcbot
authored andcommitted
Additional explicit SIMD16 checks have been implemented for
IGCVectorizer IGCVectorizer only supports simd16 as of now, explicit checks and asserts has been added
1 parent f8013c2 commit 8a8d752

9 files changed

+66
-13
lines changed

IGC/Compiler/CISACodeGen/EmitVISAPass.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4650,6 +4650,7 @@ void EmitPass::FPTrunc(const SSource sources[2], const DstModifier& modifier) {
46504650
if (IGC_IS_FLAG_ENABLED(EnableVectorEmitter) &&
46514651
sources[0].value->getType()->isVectorTy()) {
46524652

4653+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
46534654
unsigned VectorSize = getVectorSize(sources[0].value);
46544655

46554656
// float is 4 bytes --> divide by 4
@@ -4689,6 +4690,7 @@ void EmitPass::Add(const SSource sources[2], const DstModifier& modifier)
46894690
sources[0].value->getType()->isVectorTy() &&
46904691
sources[1].value->getType()->isVectorTy()) {
46914692

4693+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
46924694
unsigned VectorSize = getVectorSize(sources[0].value);
46934695

46944696
for (unsigned i = 0; i < VectorSize; ++i) {
@@ -4728,6 +4730,7 @@ void EmitPass::Mul(const SSource sources[2], const DstModifier& modifier)
47284730
sources[0].value->getType()->isVectorTy() &&
47294731
sources[1].value->getType()->isVectorTy()) {
47304732

4733+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
47314734
unsigned VectorSize = getVectorSize(sources[0].value);
47324735

47334736
for (unsigned i = 0; i < VectorSize; ++i) {
@@ -4785,6 +4788,8 @@ void EmitPass::Div(const SSource sources[2], const DstModifier& modifier)
47854788
sources[0].value->getType()->isVectorTy() &&
47864789
sources[1].value->getType()->isVectorTy()) {
47874790

4791+
llvm::errs() << numLanes(m_encoder->GetSimdSize()) << "\n";
4792+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
47884793
unsigned VectorSize = getVectorSize(sources[0].value);
47894794

47904795
for (unsigned i = 0; i < VectorSize; ++i) {
@@ -4812,6 +4817,7 @@ void EmitPass::Inv(const SSource sources[2], const DstModifier& modifier) {
48124817
sources[0].value->getType()->isVectorTy() &&
48134818
sources[1].value->getType()->isVectorTy()) {
48144819

4820+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
48154821
unsigned VectorSize = getVectorSize(sources[0].value);
48164822

48174823
CVariable* src[1];
@@ -4874,6 +4880,7 @@ void EmitPass::FDiv(const SSource sources[2], const DstModifier& modifier)
48744880
sources[0].value->getType()->isVectorTy() &&
48754881
sources[1].value->getType()->isVectorTy()) {
48764882

4883+
IGC_ASSERT_EXIT_MESSAGE(numLanes(m_encoder->GetSimdSize()) == 16, "As of now Vector Emission is only supported for SIMD16");
48774884
if (isVectorOfOnes(sources[0].value)) Inv(sources, modifier);
48784885
else Div(sources,modifier);
48794886

IGC/Compiler/CISACodeGen/IGCVectorizer.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,24 @@ void IGCVectorizer::collectInstructionToProcess(VecArr &ToProcess,
765765
}
766766
}
767767

768+
bool IGCVectorizer::checkIfSIMD16(llvm::Function &F) {
769+
770+
MDUtils = getAnalysis<MetaDataUtilsWrapper>().getMetaDataUtils();
771+
bool Result = false;
772+
if(MDUtils->findFunctionsInfoItem(&F) != MDUtils->end_FunctionsInfo()) {
773+
IGC::IGCMD::FunctionInfoMetaDataHandle funcInfoMD = MDUtils->getFunctionsInfoItem(&F);
774+
unsigned SimdSize = funcInfoMD->getSubGroupSize()->getSIMDSize();
775+
Result = SimdSize == 16;
776+
}
777+
778+
return Result;
779+
}
780+
768781
bool IGCVectorizer::runOnFunction(llvm::Function &F) {
782+
783+
// DPAS only allowed in simd16 mode + helps to reduce untested cases
784+
if (!checkIfSIMD16(F)) return false;
785+
769786
M = F.getParent();
770787
CGCtx = getAnalysis<CodeGenContextWrapper>().getCodeGenContext();
771788
initializeLogFile(F);

IGC/Compiler/CISACodeGen/IGCVectorizer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class IGCVectorizer : public llvm::FunctionPass {
5151
};
5252

5353
CodeGenContext *CGCtx = nullptr;
54+
IGCMD::MetaDataUtils* MDUtils = nullptr;
5455

5556
// when we vectorize, we build a new vector chain,
5657
// this map contains associations between scalar and vector
@@ -67,6 +68,7 @@ class IGCVectorizer : public llvm::FunctionPass {
6768
std::string LogStr;
6869
llvm::raw_string_ostream OutputLogStream = raw_string_ostream(LogStr);
6970
Module* M = nullptr;
71+
bool checkIfSIMD16(llvm::Function &F);
7072
void initializeLogFile(Function& F);
7173
void writeLog();
7274

@@ -104,6 +106,7 @@ class IGCVectorizer : public llvm::FunctionPass {
104106
virtual bool runOnFunction(llvm::Function &F) override;
105107
virtual void getAnalysisUsage(llvm::AnalysisUsage &AU) const override {
106108
AU.addRequired<CodeGenContextWrapper>();
109+
AU.addRequired<MetaDataUtilsWrapper>();
107110
}
108111
IGCVectorizer();
109112
IGCVectorizer(const std::string& FileName);

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-binary-fmul.ll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
; UNSUPPORTED: system-windows
2-
; REQUIRES: pvc-supported, regkeys
3-
41
; RUN: igc_opt -S --igc-vectorizer -dce < %s 2>&1 | FileCheck %s
52

63
; CHECK: %vectorized_phi
@@ -12,7 +9,7 @@
129
; CHECK: %vector5 = insertelement <8 x float> %vector4
1310
; CHECK: %vector6 = insertelement <8 x float> %vector5
1411
; CHECK: %vector7 = insertelement <8 x float> %vector6
15-
; CHECK: %vectorized_binary = fmul <8 x float> %vector7, %vectorized_phi
12+
; CHECK: %vectorized_binary = fmul fast <8 x float> %vector7, %vectorized_phi
1613
; CHECK: call <8 x float> @llvm.genx.GenISA.sub.group.dpas.v8f32.v8f32.v8i16.v8i32(<8 x float> %vectorized_binary
1714

1815
; ModuleID = 'reduced.ll'
@@ -21,7 +18,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
2118
target triple = "spir64-unknown-unknown"
2219

2320
; Function Attrs: convergent nounwind
24-
define spir_kernel void @_attn_fwd() #0 {
21+
define spir_kernel void @quux() {
2522
br label %._crit_edge
2623

2724
._crit_edge: ; preds = %._crit_edge, %0
@@ -83,3 +80,9 @@ uselistorder float (float)* @llvm.exp2.f32, { 7, 6, 5, 4, 3, 2, 1, 0 }
8380
attributes #0 = { convergent nounwind }
8481
attributes #1 = { convergent nounwind readnone willreturn }
8582
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
83+
84+
!igc.functions = !{!0}
85+
!0 = !{void ()* @quux, !1}
86+
!1 = !{!2, !3}
87+
!2 = !{!"function_type", i32 0}
88+
!3 = !{!"sub_group_size", i32 16}

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-dpas-incorrect.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ declare <8 x i32> @llvm.genx.GenISA.LSC2DBlockRead.v8i32(i64, i32, i32, i32, i32
106106

107107
declare void @llvm.genx.GenISA.LSC2DBlockWrite.v8i32(i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i1, i1, i32, <8 x i32>)
108108

109+
!igc.functions = !{!0}
110+
!0 = !{void ()* @quux, !1}
111+
!1 = !{!2, !3}
112+
!2 = !{!"function_type", i32 0}
113+
!3 = !{!"sub_group_size", i32 16}

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-dpas-phi.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,9 @@ declare <8 x i32> @llvm.genx.GenISA.LSC2DBlockRead.v8i32(i64, i32, i32, i32, i32
8383

8484
declare void @llvm.genx.GenISA.LSC2DBlockWrite.v8i32(i64, i32, i32, i32, i32, i32, i32, i32, i32, i32, i1, i1, i32, <8 x i32>)
8585

86+
!igc.functions = !{!0}
87+
!0 = !{void ()* @quux, !1}
88+
!1 = !{!2, !3}
89+
!2 = !{!"function_type", i32 0}
90+
!3 = !{!"sub_group_size", i32 16}
91+

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-dpas-unsupported-swizzle.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ declare void @llvm.genx.GenISA.LSC2DBlockWrite.v8i32(i64, i32, i32, i32, i32, i3
109109

110110
; uselistorder directives
111111
uselistorder <8 x float> (<8 x float>, <8 x i16>, <8 x i32>, i32, i32, i32, i32, i1)* @llvm.genx.GenISA.sub.group.dpas.v8f32.v8f32.v8i16.v8i32, { 1, 0 }
112+
113+
!igc.functions = !{!0}
114+
!0 = !{void ()* @quux, !1}
115+
!1 = !{!2, !3}
116+
!2 = !{!"function_type", i32 0}
117+
!3 = !{!"sub_group_size", i32 16}

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-fdiv-inv.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
; UNSUPPORTED: system-windows
2-
; REQUIRES: regkeys
3-
41
; RUN: igc_opt -S --igc-vectorizer -dce < %s 2>&1 | FileCheck %s
52

63
; CHECK: %vectorized_binary = fdiv fast <8 x float>
@@ -11,7 +8,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
118
target triple = "spir64-unknown-unknown"
129

1310
; Function Attrs: convergent nounwind
14-
define spir_kernel void @_attn_fwd() #0 {
11+
define spir_kernel void @quux() #0 {
1512
br label %._crit_edge
1613

1714
._crit_edge: ; preds = %._crit_edge, %0
@@ -73,3 +70,9 @@ uselistorder float (float)* @llvm.exp2.f32, { 7, 6, 5, 4, 3, 2, 1, 0 }
7370
attributes #0 = { convergent nounwind }
7471
attributes #1 = { convergent nounwind readnone willreturn }
7572
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
73+
74+
!igc.functions = !{!0}
75+
!0 = !{void ()* @quux, !1}
76+
!1 = !{!2, !3}
77+
!2 = !{!"function_type", i32 0}
78+
!3 = !{!"sub_group_size", i32 16}

IGC/Compiler/tests/IGCVectorizer/vectorizer-test-fdiv-not-inv.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
; UNSUPPORTED: system-windows
2-
; REQUIRES: regkeys
3-
41
; RUN: igc_opt -S --igc-vectorizer -dce < %s 2>&1 | FileCheck %s
52

63
; CHECK: %vectorized_binary = fdiv fast <8 x float>
@@ -11,7 +8,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f3
118
target triple = "spir64-unknown-unknown"
129

1310
; Function Attrs: convergent nounwind
14-
define spir_kernel void @_attn_fwd() #0 {
11+
define spir_kernel void @quux() #0 {
1512
br label %._crit_edge
1613

1714
._crit_edge: ; preds = %._crit_edge, %0
@@ -73,3 +70,9 @@ uselistorder float (float)* @llvm.exp2.f32, { 7, 6, 5, 4, 3, 2, 1, 0 }
7370
attributes #0 = { convergent nounwind }
7471
attributes #1 = { convergent nounwind readnone willreturn }
7572
attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }
73+
74+
!igc.functions = !{!0}
75+
!0 = !{void ()* @quux, !1}
76+
!1 = !{!2, !3}
77+
!2 = !{!"function_type", i32 0}
78+
!3 = !{!"sub_group_size", i32 16}

0 commit comments

Comments
 (0)