@@ -114,8 +114,12 @@ void IGCVectorizer::initializeLogFile(Function &F) {
114114 if (!IGC_IS_FLAG_ENABLED (VectorizerLog))
115115 return ;
116116
117+ string FName = F.getName ().str ();
118+
119+ if (FName.size () > 128 ) FName.resize (128 );
120+
117121 std::stringstream ss;
118- ss << F. getName (). str () << " _"
122+ ss << FName << " _"
119123 << " Vectorizer" ;
120124 auto Name = Debug::DumpName (IGC::Debug::GetShaderOutputName ())
121125 .Hash (CGCtx->hash )
@@ -221,7 +225,7 @@ bool isSafeToVectorize(Instruction *I) {
221225 return Result;
222226}
223227
224- bool IGCVectorizer::handlePHI (VecArr &Slice, Type *VectorType ) {
228+ bool IGCVectorizer::handlePHI (VecArr &Slice) {
225229 PHINode *ScalarPhi = static_cast <PHINode *>(Slice[0 ]);
226230
227231 if (!checkPHI (ScalarPhi, Slice))
@@ -313,11 +317,6 @@ bool IGCVectorizer::handleInsertElement(VecArr &Slice, Instruction* Final) {
313317 if (!checkInsertElement (First, Slice))
314318 return false ;
315319
316- // we can handle case with more than 1 value
317- // but it wasn't tested
318- if (!Final->hasOneUse ())
319- return false ;
320-
321320 PRINT_LOG_NL (" InsertElement substituted with vectorized instruction" );
322321 PRINT_LOG_NL (" " );
323322 Value *Compare = ScalarToVector[First->getOperand (1 )];
@@ -471,7 +470,7 @@ bool IGCVectorizer::processChain(InsertStruct &InSt) {
471470
472471 Instruction *First = Slice[0 ];
473472 if (llvm::isa<PHINode>(First)) {
474- if (!handlePHI (Slice, InSt. Final -> getType () )) return false ;
473+ if (!handlePHI (Slice)) return false ;
475474 } else if (llvm::isa<CastInst>(First)) {
476475 if (!handleCastInstruction (Slice)) return false ;
477476 } else if (llvm::isa<BinaryOperator>(First)) {
@@ -487,10 +486,8 @@ bool IGCVectorizer::processChain(InsertStruct &InSt) {
487486 return true ;
488487}
489488
490- void IGCVectorizer::clusterInsertElement (
491- InsertElementInst* HeadInsertEl, InsertStruct &InSt) {
492- InSt.Final = HeadInsertEl;
493- Instruction *Head = HeadInsertEl;
489+ void IGCVectorizer::clusterInsertElement (InsertStruct &InSt) {
490+ Instruction *Head = InSt.Final ;
494491
495492 while (true ) {
496493 InSt.Vec .push_back (Head);
@@ -801,9 +798,20 @@ bool IGCVectorizer::runOnFunction(llvm::Function &F) {
801798
802799 // we process collected insert elements into a specific data structure
803800 // for convenience
804- for (auto el : VecOfInsert) {
805- InsertStruct InSt;
806- clusterInsertElement (static_cast <InsertElementInst*>(el), InSt);
801+ InsertStruct InSt;
802+ InSt.SlChain .reserve (128 );
803+ for (auto elFinal : VecOfInsert) {
804+
805+ InSt.SlChain .clear ();
806+ InSt.Vec .clear ();
807+
808+ if (!elFinal->hasOneUse ()) {
809+ PRINT_LOG_NL (" Final insert has more than one use -> rejected" );
810+ continue ;
811+ }
812+ InSt.Final = elFinal;
813+ clusterInsertElement (InSt);
814+
807815 if (InSt.Vec .size () != getVectorSize (InSt.Final )) {
808816 PRINT_LOG_NL (" partial insert -> rejected" );
809817 continue ;
0 commit comments