Skip to content

Commit 09c26bd

Browse files
bokrzesiigcbot
authored andcommitted
[LLVM16][PrivateMemoryResolution] Adding another case of mismatch detection
Current implementation of MismatchDetection was skipping cases due to algorithm version check. It prevented mismatched cases to be detected, so I'm removing that check.
1 parent bad3bca commit 09c26bd

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

IGC/Compiler/CISACodeGen/LowerGEPForPrivMem.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -576,40 +576,37 @@ bool IGC::SOALayoutChecker::MismatchDetected(Instruction &I) {
576576
if (!allocaIsVecOrArr)
577577
return false;
578578

579-
bool useOldAlgorithm = !useNewAlgo(pInfo->baseType);
579+
auto DL = I.getParent()->getParent()->getParent()->getDataLayout();
580580

581-
if (useOldAlgorithm) {
582-
auto DL = I.getParent()->getParent()->getParent()->getDataLayout();
581+
Type *pUserTy = I.getType();
583582

584-
Type *pUserTy = I.getType();
583+
if (auto *storeInst = dyn_cast<StoreInst>(&I))
584+
pUserTy = storeInst->getValueOperand()->getType();
585585

586-
if (auto *storeInst = dyn_cast<StoreInst>(&I))
587-
pUserTy = storeInst->getValueOperand()->getType();
588-
589-
if (auto *pgep = dyn_cast<GetElementPtrInst>(parentLevelInst)) {
590-
allocaTy = pgep->getResultElementType();
591-
} else {
592-
if (auto *arrTy = dyn_cast<ArrayType>(allocaTy)) {
593-
allocaTy = arrTy->getElementType();
594-
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(allocaTy)) {
595-
allocaTy = vec->getElementType();
596-
}
586+
if (auto *pgep = dyn_cast<GetElementPtrInst>(parentLevelInst)) {
587+
allocaTy = pgep->getResultElementType();
588+
} else {
589+
if (auto *arrTy = dyn_cast<ArrayType>(allocaTy)) {
590+
allocaTy = arrTy->getElementType();
591+
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(allocaTy)) {
592+
allocaTy = vec->getElementType();
593+
}
597594

598-
if (auto *arrTy = dyn_cast<ArrayType>(pUserTy)) {
599-
pUserTy = arrTy->getElementType();
600-
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(pUserTy)) {
601-
pUserTy = vec->getElementType();
602-
}
595+
if (auto *arrTy = dyn_cast<ArrayType>(pUserTy)) {
596+
pUserTy = arrTy->getElementType();
597+
} else if (auto *vec = dyn_cast<IGCLLVM::FixedVectorType>(pUserTy)) {
598+
pUserTy = vec->getElementType();
603599
}
600+
}
604601

605-
auto allocaSize = DL.getTypeAllocSize(allocaTy);
606-
auto vecTySize = DL.getTypeAllocSize(pUserTy);
602+
auto allocaSize = DL.getTypeAllocSize(allocaTy);
603+
auto vecTySize = DL.getTypeAllocSize(pUserTy);
607604

608-
if (vecTySize != allocaSize) {
609-
pInfo->canUseSOALayout = false;
610-
return true;
611-
}
605+
if (vecTySize != allocaSize) {
606+
pInfo->canUseSOALayout = false;
607+
return true;
612608
}
609+
613610
return false;
614611
}
615612

IGC/Compiler/tests/PrivateMemoryResolution/SOA_promotion/soa-nested-load.ll renamed to IGC/Compiler/tests/PrivateMemoryResolution/SOA_promotion/soa-mismatch-detection.ll

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
;
1111
; RUN: igc_opt --ocl --igc-private-mem-resolution --regkey "EnablePrivMemNewSOATranspose=1,EnableOpaquePointersBackend=1" -S %s | FileCheck %s
1212
;
13-
; In JointMatrix SYCL test
14-
; https://github.com/intel/llvm/blob/sycl/sycl/test-e2e/Matrix/joint_matrix_bf16_fill_k_cache_unroll.cpp
15-
; I've found that such assert was failing info: error, assertion failed: bits == elementSize
16-
; The purpose of this test is to validate whether alloca->gep->load is not crashing
13+
; This test is testing "MismatchDetected" algorithm in LowerGEPForPrivMem.cpp
14+
; The purpose of this test is to validate whether various combinations of allocas/geps/load/stores
15+
; are not mismatched and then failing due to asserts or causing miscalculations at runtime.
1716

1817
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"
1918
target triple = "spir64-unknown-unknown"
2019

20+
%"struct.ispc::vec_t" = type { i32, i32, i32 }
21+
2122
; Function Attrs: nofree nosync nounwind
2223
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) {
2324
entry:
@@ -43,6 +44,18 @@ exit:
4344
; CHECK: %load2 = load i8, ptr %arr3
4445
%arr3 = alloca [512 x i32]
4546
%load2 = load i8, ptr %arr3
47+
48+
; Case Alloca->Store->Gep->Store: This case is not valid due to different sizes
49+
50+
; CHECK: store <4 x i32> zeroinitializer, ptr %offset.i.i.i.i.privateBufferPTR
51+
; CHECK: %offset_gep = getelementptr i8, ptr %offset.i.i.i.i.privateBufferPTR, i32 16
52+
; CHECK: store i32 0, ptr %offset_gep, align 4
53+
54+
%offset.i.i.i.i = alloca [8 x %"struct.ispc::vec_t"], align 4
55+
store <4 x i32> zeroinitializer, ptr %offset.i.i.i.i, align 4
56+
%offset_gep = getelementptr i8, ptr %offset.i.i.i.i, i32 16
57+
store i32 0, ptr %offset_gep, align 4
58+
4659
ret void
4760
}
4861

0 commit comments

Comments
 (0)