Skip to content

Commit 8392531

Browse files
esukhovpszymich
authored andcommitted
Vectorizer refactoring
Vectorizer now preallocates chain vector. And removes unnecessary parameters from functions. (cherry picked from commit d89764f)
1 parent 52ead21 commit 8392531

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

IGC/Compiler/CISACodeGen/IGCVectorizer.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

IGC/Compiler/CISACodeGen/IGCVectorizer.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class IGCVectorizer : public llvm::FunctionPass {
4747
// contains insert elements
4848
VecArr Vec;
4949
// contains slices of vector tree
50-
VectorSliceChain Chain;
5150
VecOfSlices SlChain;
5251
};
5352

@@ -72,18 +71,16 @@ class IGCVectorizer : public llvm::FunctionPass {
7271
void writeLog();
7372

7473
void findInsertElementsInDataFlow(llvm::Instruction* I, VecArr& Chain);
75-
void collectScalarPath(VecArr& V, VectorSliceChain& Chain);
76-
void canonicalizeSlices(VectorSliceChain& Chain);
7774
bool checkSlice(VecArr& Slice, InsertStruct& InSt);
7875
bool processChain(InsertStruct& InSt);
79-
void clusterInsertElement(InsertElementInst* VecOfInsert, InsertStruct& InSt);
76+
void clusterInsertElement(InsertStruct& InSt);
8077
void collectInstructionToProcess(VecArr& ToProcess, Function& F);
8178
void buildTree(VecArr &V, VecOfSlices& Chain);
8279
void printSlice(Slice* S);
8380

8481

8582
bool checkPHI(Instruction* Compare, VecArr& Slice);
86-
bool handlePHI(VecArr& Slice, Type* VectorType);
83+
bool handlePHI(VecArr& Slice);
8784
bool checkInsertElement(Instruction* First, VecArr& Slice);
8885
bool handleInsertElement(VecArr& Slice, Instruction* Final);
8986
bool checkExtractElement(Instruction* Compare, VecArr& Slice);

0 commit comments

Comments
 (0)