@@ -87,39 +87,38 @@ IGC_INITIALIZE_PASS_BEGIN(IGCVectorizer, PASS_FLAG2, PASS_DESCRIPTION2, PASS_CFG
8787IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenContextWrapper)
8888IGC_INITIALIZE_PASS_END(IGCVectorizer, PASS_FLAG2, PASS_DESCRIPTION2, PASS_CFG_ONLY2, PASS_ANALYSIS2)
8989
90- #define OutputLogStreamM OutputLogStream
9190#define DEBUG IGC_IS_FLAG_ENABLED (VectorizerLog)
9291#define PRINT_LOG (Str ) \
9392 if (DEBUG) { \
94- OutputLogStreamM << Str; \
93+ OutputLogStream << Str; \
9594 writeLog (); \
9695 }
9796#define PRINT_LOG_NL (Str ) \
9897 if (DEBUG) { \
99- OutputLogStreamM << Str << " \n " ; \
98+ OutputLogStream << Str << " \n " ; \
10099 writeLog (); \
101100 }
102101#define PRINT_INST (I ) \
103102 if (DEBUG) { \
104- I->print (OutputLogStreamM , false ); \
103+ I->print (OutputLogStream , false ); \
105104 }
106105#define PRINT_INST_NL (I ) \
107106 if (DEBUG) { \
108107 if (I) { \
109- I->print (OutputLogStreamM , false ); \
108+ I->print (OutputLogStream , false ); \
110109 } else { \
111110 PRINT_LOG (" NULL" ); \
112111 } \
113- OutputLogStreamM << " \n " ; \
112+ OutputLogStream << " \n " ; \
114113 }
115114#define PRINT_DECL_NL (I ) \
116115 if (DEBUG) { \
117116 if (I) { \
118- I->print (OutputLogStreamM); \
117+ I->print (OutputLogStream); \
119118 } else { \
120119 PRINT_LOG (" NULL" ); \
121120 } \
122- OutputLogStreamM << " \n " ; \
121+ OutputLogStream << " \n " ; \
123122 }
124123#define PRINT_DS (Str, DS ) \
125124 if (DEBUG) { \
@@ -136,9 +135,13 @@ IGC_INITIALIZE_PASS_END(IGCVectorizer, PASS_FLAG2, PASS_DESCRIPTION2, PASS_CFG_O
136135IGCVectorizer::IGCVectorizer () : FunctionPass(ID) { initializeIGCVectorizerPass (*PassRegistry::getPassRegistry ()); };
137136
138137void IGCVectorizer::writeLog () {
139- if (IGC_IS_FLAG_ENABLED (VectorizerLog) && OutputLogFile->is_open ())
138+
139+ if (IGC_IS_FLAG_ENABLED (VectorizerLog) && IGC_IS_FLAG_DISABLED (VectorizerLogToErr) && OutputLogFile->is_open ())
140140 *OutputLogFile << OutputLogStream.str ();
141141
142+ if (IGC_IS_FLAG_ENABLED (VectorizerLog) && IGC_IS_FLAG_ENABLED (VectorizerLogToErr))
143+ llvm::errs () << OutputLogStream.str ();
144+
142145 OutputLogStream.str ().clear ();
143146}
144147
@@ -184,11 +187,12 @@ void IGCVectorizer::findInsertElementsInDataFlow(llvm::Instruction *I, VecArr &C
184187 bool IsConstant = llvm::isa<llvm::Constant>(Op);
185188 bool IsExplored = Explored.count (Op);
186189 bool IsInsertElement = llvm::isa<InsertElementInst>(Op);
190+ bool IsVectorTyped = Op->getType ()->isVectorTy ();
187191
188192 if (IsInsertElement)
189193 Chain.push_back (Op);
190194
191- bool Skip = IsConstant || IsExplored || IsInsertElement;
195+ bool Skip = IsConstant || IsExplored || IsInsertElement || !IsVectorTyped ;
192196 if (Skip)
193197 continue ;
194198
@@ -275,14 +279,17 @@ bool isIntrinsicSafe(Instruction *I) {
275279
276280bool isSafeToVectorize (Instruction *I) {
277281
282+ bool IsInsertOrExtract = llvm::isa<ExtractElementInst>(I) || llvm::isa<InsertElementInst>(I);
283+ // the only typed instructions we add to slices => Insert or Extract elements
284+ bool IsVectorTyped = I->getType ()->isVectorTy () && !IsInsertOrExtract;
278285 bool isFloat = isFloatTyped (I);
279286
280287 // this is a very limited approach for vectorizing but it's safe
281- bool Result = isPHISafe (I) || llvm::isa<ExtractElementInst>(I) || llvm::isa<InsertElementInst>(I) ||
288+ bool Result = isPHISafe (I) || IsInsertOrExtract ||
282289 (llvm::isa<FPTruncInst>(I) && IGC_GET_FLAG_VALUE (VectorizerAllowFPTRUNC)) || isBinarySafe (I) ||
283290 isIntrinsicSafe (I);
284291
285- return Result && isFloat;
292+ return Result && isFloat && !IsVectorTyped ;
286293}
287294
288295bool IGCVectorizer::handlePHI (VecArr &Slice) {
@@ -414,10 +421,13 @@ InsertElementInst *IGCVectorizer::createVector(VecArr &Slice, Instruction *Inser
414421 PRINT_LOG_NL (" insertPoint moved to FirstNonPHI" );
415422 }
416423
424+ InsertElementInst *CreatedInsert = nullptr ;
417425 llvm::Type *elementType = Slice[0 ]->getType ();
426+ if (elementType->isVectorTy ())
427+ return CreatedInsert;
428+
418429 llvm::VectorType *vectorType = llvm::FixedVectorType::get (elementType, Slice.size ());
419430 llvm::Value *UndefVector = llvm::UndefValue::get (vectorType);
420- InsertElementInst *CreatedInsert = nullptr ;
421431
422432 for (size_t i = 0 ; i < Slice.size (); i++) {
423433 llvm::Value *index = llvm::ConstantInt::get (llvm::Type::getInt32Ty (M->getContext ()), i);
@@ -1076,6 +1086,11 @@ bool IGCVectorizer::runOnFunction(llvm::Function &F) {
10761086 InSt.Final = elFinal;
10771087 clusterInsertElement (InSt);
10781088
1089+ if (getVectorSize (InSt.Final ) == 1 ) {
1090+ PRINT_LOG_NL (" degenerate insert of the type <1 x float> -> rejected" );
1091+ continue ;
1092+ }
1093+
10791094 if (InSt.Vec .size () != getVectorSize (InSt.Final )) {
10801095 PRINT_LOG_NL (" partial insert -> rejected" );
10811096 continue ;
0 commit comments