@@ -855,16 +855,6 @@ void ScalarizeFunction::scalarizeInstruction(InsertElementInst* II)
855
855
// If the index is not a constant - we cannot statically remove this inst
856
856
if (!isa<ConstantInt>(scalarIndexVal)) return recoverNonScalarizableInst (II);
857
857
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
-
868
858
// Obtain breakdown of input vector
869
859
SmallVector<Value*, MAX_INPUT_VECTOR_WIDTH>scalarValues;
870
860
if (isa<UndefValue>(sourceVectorValue))
@@ -881,16 +871,26 @@ void ScalarizeFunction::scalarizeInstruction(InsertElementInst* II)
881
871
{
882
872
scalarValues[j] = undefVal;
883
873
}
884
- scalarValues[static_cast <unsigned int >(scalarIndex)] = sourceScalarValue;
885
874
}
886
875
else
887
876
{
888
877
// Obtain the scalar values of the input vector
889
878
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
+ {
890
887
// Add the new element
891
888
scalarValues[static_cast <unsigned int >(scalarIndex)] = sourceScalarValue;
892
889
}
893
890
891
+ // Prepare empty SCM entry for the instruction
892
+ SCMEntry* newEntry = getSCMEntry (II);
893
+
894
894
// Add new value/s to SCM
895
895
updateSCMEntryWithValues (newEntry, &(scalarValues[0 ]), II, true , false );
896
896
0 commit comments