Skip to content

Commit d718c26

Browse files
ustachowigcbot
authored andcommitted
Handle Incorrect Alignment in MergeUniformLoad with Early Return
This commit refactors the `MergeUniformLoad` function in the `ConstantCoalescing` class to handle cases with incorrect alignment, such as structs marked with `__attribute__((packed))`. Assertions have been replaced with an early returns to exit the function when the alignment condition is not met. Only natural alignment is supported.
1 parent 547b3b2 commit d718c26

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

IGC/Compiler/CISACodeGen/ConstantCoalescing.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,10 @@ void ConstantCoalescing::MergeUniformLoad(Instruction* load,
10531053
const ExtensionKind &Extension,
10541054
std::vector<BufChunk*>& chunk_vec)
10551055
{
1056+
// Only natural alignment is supported
10561057
const alignment_t alignment = GetAlignment(load);
10571058

1058-
if (alignment == 0)
1059+
if (!isPowerOf2_64(alignment))
10591060
{
10601061
return;
10611062
}
@@ -1077,9 +1078,10 @@ void ConstantCoalescing::MergeUniformLoad(Instruction* load,
10771078
}
10781079
const uint scalarSizeInBytes = (const uint)(loadEltTy->getPrimitiveSizeInBits() / 8);
10791080

1080-
IGC_ASSERT(isPowerOf2_64(alignment));
1081-
IGC_ASSERT(0 != scalarSizeInBytes);
1082-
IGC_ASSERT((offsetInBytes % scalarSizeInBytes) == 0);
1081+
if (0 == scalarSizeInBytes || (offsetInBytes % scalarSizeInBytes) != 0)
1082+
{
1083+
return;
1084+
}
10831085

10841086
const uint eltid = offsetInBytes / scalarSizeInBytes;
10851087

0 commit comments

Comments
 (0)