Skip to content

Commit 609ff1f

Browse files
krystian-andrzejewskiigcbot
authored andcommitted
Fix scalarizing out of bounds insertelement
This change is to fix the issue with out of bounds insertlement in the scalarizer.
1 parent 54cee5d commit 609ff1f

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

IGC/Compiler/Optimizer/Scalarizer.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -855,16 +855,6 @@ void ScalarizeFunction::scalarizeInstruction(InsertElementInst* II)
855855
// If the index is not a constant - we cannot statically remove this inst
856856
if (!isa<ConstantInt>(scalarIndexVal)) return recoverNonScalarizableInst(II);
857857

858-
// Prepare empty SCM entry for the instruction
859-
SCMEntry* newEntry = getSCMEntry(II);
860-
861-
IGC_ASSERT_MESSAGE(isa<ConstantInt>(scalarIndexVal), "inst arguments error");
862-
uint64_t scalarIndex = cast<ConstantInt>(scalarIndexVal)->getZExtValue();
863-
IGC_ASSERT_MESSAGE(
864-
scalarIndex <
865-
dyn_cast<IGCLLVM::FixedVectorType>(II->getType())->getNumElements(),
866-
"index error");
867-
868858
// Obtain breakdown of input vector
869859
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH>scalarValues;
870860
if (isa<UndefValue>(sourceVectorValue))
@@ -881,16 +871,26 @@ void ScalarizeFunction::scalarizeInstruction(InsertElementInst* II)
881871
{
882872
scalarValues[j] = undefVal;
883873
}
884-
scalarValues[static_cast<unsigned int>(scalarIndex)] = sourceScalarValue;
885874
}
886875
else
887876
{
888877
// Obtain the scalar values of the input vector
889878
obtainScalarizedValues(scalarValues, NULL, sourceVectorValue, II);
879+
}
880+
881+
IGC_ASSERT_MESSAGE(isa<ConstantInt>(scalarIndexVal), "inst arguments error");
882+
uint64_t scalarIndex = cast<ConstantInt>(scalarIndexVal)->getZExtValue();
883+
884+
if (scalarIndex <
885+
dyn_cast<IGCLLVM::FixedVectorType>(II->getType())->getNumElements())
886+
{
890887
// Add the new element
891888
scalarValues[static_cast<unsigned int>(scalarIndex)] = sourceScalarValue;
892889
}
893890

891+
// Prepare empty SCM entry for the instruction
892+
SCMEntry* newEntry = getSCMEntry(II);
893+
894894
// Add new value/s to SCM
895895
updateSCMEntryWithValues(newEntry, &(scalarValues[0]), II, true, false);
896896

0 commit comments

Comments
 (0)