Skip to content

Commit d89764f

Browse files
esukhovigcbot
authored andcommitted
Vectorizer refactoring
Vectorizer now preallocates chain vector. And removes unnecessary parameters from functions.
1 parent 7a96508 commit d89764f

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)
@@ -223,7 +227,7 @@ bool isSafeToVectorize(Instruction *I) {
223227
return Result;
224228
}
225229

226-
bool IGCVectorizer::handlePHI(VecArr &Slice, Type *VectorType) {
230+
bool IGCVectorizer::handlePHI(VecArr &Slice) {
227231
PHINode *ScalarPhi = static_cast<PHINode *>(Slice[0]);
228232

229233
if (!checkPHI(ScalarPhi, Slice))
@@ -315,11 +319,6 @@ bool IGCVectorizer::handleInsertElement(VecArr &Slice, Instruction* Final) {
315319
if (!checkInsertElement(First, Slice))
316320
return false;
317321

318-
// we can handle case with more than 1 value
319-
// but it wasn't tested
320-
if (!Final->hasOneUse())
321-
return false;
322-
323322
PRINT_LOG_NL("InsertElement substituted with vectorized instruction");
324323
PRINT_LOG_NL("");
325324
Value *Compare = ScalarToVector[First->getOperand(1)];
@@ -473,7 +472,7 @@ bool IGCVectorizer::processChain(InsertStruct &InSt) {
473472

474473
Instruction *First = Slice[0];
475474
if (llvm::isa<PHINode>(First)) {
476-
if (!handlePHI(Slice, InSt.Final->getType())) return false;
475+
if (!handlePHI(Slice)) return false;
477476
} else if (llvm::isa<CastInst>(First)) {
478477
if (!handleCastInstruction(Slice)) return false;
479478
} else if (llvm::isa<BinaryOperator>(First)) {
@@ -489,10 +488,8 @@ bool IGCVectorizer::processChain(InsertStruct &InSt) {
489488
return true;
490489
}
491490

492-
void IGCVectorizer::clusterInsertElement(
493-
InsertElementInst* HeadInsertEl, InsertStruct &InSt) {
494-
InSt.Final = HeadInsertEl;
495-
Instruction *Head = HeadInsertEl;
491+
void IGCVectorizer::clusterInsertElement(InsertStruct &InSt) {
492+
Instruction *Head = InSt.Final;
496493

497494
while (true) {
498495
InSt.Vec.push_back(Head);
@@ -803,9 +800,20 @@ bool IGCVectorizer::runOnFunction(llvm::Function &F) {
803800

804801
// we process collected insert elements into a specific data structure
805802
// for convenience
806-
for (auto el : VecOfInsert) {
807-
InsertStruct InSt;
808-
clusterInsertElement(static_cast<InsertElementInst*>(el), InSt);
803+
InsertStruct InSt;
804+
InSt.SlChain.reserve(128);
805+
for (auto elFinal : VecOfInsert) {
806+
807+
InSt.SlChain.clear();
808+
InSt.Vec.clear();
809+
810+
if (!elFinal->hasOneUse()) {
811+
PRINT_LOG_NL("Final insert has more than one use -> rejected");
812+
continue;
813+
}
814+
InSt.Final = elFinal;
815+
clusterInsertElement(InSt);
816+
809817
if (InSt.Vec.size() != getVectorSize(InSt.Final)) {
810818
PRINT_LOG_NL("partial insert -> rejected");
811819
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)