Skip to content

Commit 78fcf82

Browse files
jszt1igcbot
authored andcommitted
Revisit MismatchDetected for LowerGEPForPrivMem
MismatchDetected solved assert in the PrivateMemoryResolution pass caused by mismatched widths. LowerGEPForPrivMem solves that case but in case of alloca over the allowed size it will leave mismatched widths for the later PrivateMemoryResolution causing the assert to fail. Extended mismatch detection for cases with struct of array/struct of vector.
1 parent 009c253 commit 78fcf82

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ StatusPrivArr2Reg LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst *
282282

283283
allowedAllocaSizeInBytes = (allowedAllocaSizeInBytes * 8) / SIMDSize;
284284
}
285-
SOALayoutChecker checker(*pAlloca, m_ctx->type == ShaderType::OPENCL_SHADER);
285+
SOALayoutChecker checker(*pAlloca, m_ctx->type == ShaderType::OPENCL_SHADER, true);
286286
SOALayoutInfo SOAInfo = checker.getOrGatherInfo();
287287
if (!SOAInfo.canUseSOALayout) {
288288
return StatusPrivArr2Reg::CannotUseSOALayout;
@@ -357,7 +357,7 @@ StatusPrivArr2Reg LowerGEPForPrivMem::CheckIfAllocaPromotable(llvm::AllocaInst *
357357
return StatusPrivArr2Reg::OK;
358358
}
359359

360-
SOALayoutChecker::SOALayoutChecker(AllocaInst &allocaToCheck, bool isOCL) : allocaRef(allocaToCheck) {
360+
SOALayoutChecker::SOALayoutChecker(AllocaInst &allocaToCheck, bool isOCL, bool mismatchedWidthsSupport) : allocaRef(allocaToCheck), mismatchedWidthsSupport(mismatchedWidthsSupport) {
361361
auto F = allocaToCheck.getParent()->getParent();
362362
pDL = &F->getParent()->getDataLayout();
363363
newAlgoControl = IGC_GET_FLAG_VALUE(EnablePrivMemNewSOATranspose);
@@ -571,9 +571,12 @@ bool IGC::SOALayoutChecker::MismatchDetected(Instruction &I) {
571571
return false;
572572

573573
Type *allocaTy = allocaRef.getAllocatedType();
574-
bool allocaIsVecOrArr = allocaTy->isVectorTy() || allocaTy->isArrayTy();
574+
bool allocaIsVecOrArrOrStruct = allocaTy->isVectorTy() || allocaTy->isArrayTy() || allocaTy->isStructTy();
575575

576-
if (!allocaIsVecOrArr)
576+
if (!allocaIsVecOrArrOrStruct)
577+
return false;
578+
579+
if(mismatchedWidthsSupport)
577580
return false;
578581

579582
bool useOldAlgorithm = !useNewAlgo(pInfo->baseType);
@@ -593,12 +596,24 @@ bool IGC::SOALayoutChecker::MismatchDetected(Instruction &I) {
593596
allocaTy = arrTy->getElementType();
594597
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(allocaTy)) {
595598
allocaTy = vec->getElementType();
599+
} else if (auto *strct = dyn_cast<StructType>(allocaTy)){
600+
if (auto *arrTy = dyn_cast<ArrayType>(strct->getStructElementType(0))) {
601+
allocaTy = arrTy->getElementType();
602+
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(strct->getStructElementType(0))){
603+
allocaTy = vec->getElementType();
604+
}
596605
}
597606

598607
if (auto *arrTy = dyn_cast<ArrayType>(pUserTy)) {
599608
pUserTy = arrTy->getElementType();
600609
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(pUserTy)) {
601610
pUserTy = vec->getElementType();
611+
} else if (auto *strct = dyn_cast<StructType>(pUserTy)){
612+
if (auto *arrTy = dyn_cast<ArrayType>(strct->getStructElementType(0))) {
613+
pUserTy = arrTy->getElementType();
614+
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(strct->getStructElementType(0))){
615+
pUserTy = vec->getElementType();
616+
}
602617
}
603618
}
604619

IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class SOALayoutChecker : public llvm::InstVisitor<SOALayoutChecker, bool> {
7070
friend llvm::InstVisitor<SOALayoutChecker, bool>;
7171

7272
// isOCL is for testing, it will be removed once testing is done.
73-
SOALayoutChecker(llvm::AllocaInst &allocaToCheck, bool isOCL);
73+
SOALayoutChecker(llvm::AllocaInst &allocaToCheck, bool isOCL, bool mismatchedWidthsSupport=false);
7474
SOALayoutChecker() = delete;
7575
~SOALayoutChecker() = default;
7676
SOALayoutChecker(SOALayoutChecker &) = delete;
@@ -87,6 +87,10 @@ class SOALayoutChecker : public llvm::InstVisitor<SOALayoutChecker, bool> {
8787
const llvm::DataLayout *pDL;
8888
std::unique_ptr<SOALayoutInfo> pInfo;
8989

90+
// If mismatched widths reach PrivateMemoryResolution, it should turn off optimization
91+
// But if they reach LowerGEPForPrivMemPass they get resolved properly
92+
bool mismatchedWidthsSupport;
93+
9094
// ===== fields for new algo =====
9195
// todo: combine the new and old together
9296
//

IGC/Compiler/tests/PrivateMemoryResolution/SOA_promotion/soa-nested-load.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-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-n8:16:32"
1919
target triple = "spir64-unknown-unknown"
2020

21+
%g = type { [512 x i32] }
22+
2123
; Function Attrs: nofree nosync nounwind
2224
define spir_kernel void @test(ptr nocapture writeonly %d, <8 x i32> %r0, <8 x i32> %payloadHeader, <3 x i32> %enqueuedLocalSize, i16 %localIdX, i16 %localIdY, i16 %localIdZ, ptr nocapture readnone %privateBase) {
2325
entry:
@@ -43,6 +45,18 @@ exit:
4345
; CHECK: %load2 = load i8, ptr %arr3
4446
%arr3 = alloca [512 x i32]
4547
%load2 = load i8, ptr %arr3
48+
49+
; This case is valid because float and i32 have 32 bits
50+
; CHECK: insertelement <2 x float> {{.*}}, float {{.*}}, i32 0
51+
; CHECK: insertelement <2 x float> {{.*}}, float {{.*}}, i32 1
52+
%st = alloca %g
53+
%load3 = load <2 x float>, ptr %st
54+
55+
; This case is not valid because i32 and i8 have different sizes
56+
; CHECK: %load4 = load <2 x i8>, ptr %st2
57+
%st2 = alloca %g
58+
%load4 = load <2 x i8>, ptr %st2
59+
4660
ret void
4761
}
4862

0 commit comments

Comments
 (0)