Skip to content

Commit

Permalink
Revert: New vectorization pattern for IGCVectorizer
Browse files Browse the repository at this point in the history
.
  • Loading branch information
esukhov authored and igcbot committed Nov 19, 2024
1 parent af7dd19 commit 26c11d9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 275 deletions.
77 changes: 9 additions & 68 deletions IGC/Compiler/CISACodeGen/IGCVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ SPDX-License-Identifier: MIT
char IGCVectorizer::ID = 0;

#define PASS_FLAG2 "igc-vectorizer"
#define PASS_DESCRIPTION2 "Vectorizes scalar path around igc vector intrinsics like dpas"
#define PASS_DESCRIPTION2 "prints register pressure estimation"
#define PASS_CFG_ONLY2 false
#define PASS_ANALYSIS2 false
IGC_INITIALIZE_PASS_BEGIN(IGCVectorizer, PASS_FLAG2, PASS_DESCRIPTION2,
Expand All @@ -91,12 +91,11 @@ IGC_INITIALIZE_PASS_DEPENDENCY(CodeGenContextWrapper)
IGC_INITIALIZE_PASS_END(IGCVectorizer, PASS_FLAG2, PASS_DESCRIPTION2,
PASS_CFG_ONLY2, PASS_ANALYSIS2)

#define OutputLogStreamM OutputLogStream
#define DEBUG IGC_IS_FLAG_ENABLED(VectorizerLog)
#define PRINT_LOG(Str) if (DEBUG) OutputLogStreamM << Str;
#define PRINT_LOG_NL(Str) if (DEBUG) OutputLogStreamM << Str << "\n";
#define PRINT_INST(I) if (DEBUG) { I->print(OutputLogStreamM, false); }
#define PRINT_INST_NL(I) if (DEBUG) { I->print(OutputLogStreamM, false); OutputLogStreamM << "\n"; }
#define PRINT_LOG(Str) if (DEBUG) OutputLogStream << Str;
#define PRINT_LOG_NL(Str) if (DEBUG) OutputLogStream << Str << "\n";
#define PRINT_INST(I) if (DEBUG) { I->print(OutputLogStream, false); }
#define PRINT_INST_NL(I) if (DEBUG) { I->print(OutputLogStream, false); OutputLogStream << "\n"; }
#define PRINT_DS(Str, DS) if (DEBUG) { for (auto DS_EL : DS) { { PRINT_LOG(Str); } { PRINT_INST_NL(DS_EL); } } }

IGCVectorizer::IGCVectorizer() : FunctionPass(ID) {
Expand Down Expand Up @@ -181,41 +180,29 @@ unsigned int getVectorSize(Instruction *I) {
bool isSafeToVectorize(Instruction *I) {
// this is a very limited approach for vectorizing
// but it's safe
bool Result =
llvm::isa<PHINode>(I) ||
llvm::isa<ExtractElementInst>(I) ||
llvm::isa<InsertElementInst>(I) ||
llvm::isa<CastInst>(I);
bool Result = llvm::isa<PHINode>(I) || llvm::isa<ExtractElementInst>(I) ||
llvm::isa<InsertElementInst>(I);

return Result;
}

bool IGCVectorizer::compareOperands(Value *A, Value *B) {

PRINT_INST(A); PRINT_LOG(" & "); PRINT_INST(B);
Constant *ConstA = llvm::dyn_cast<Constant>(A);
Constant *ConstB = llvm::dyn_cast<Constant>(B);

Instruction *InstA = llvm::dyn_cast<Instruction>(A);
Instruction *InstB = llvm::dyn_cast<Instruction>(B);

if (ConstA && ConstB) {

PRINT_LOG(" --> Const ");
bool BothZero = ConstA->isZeroValue() && ConstB->isZeroValue();
PRINT_LOG(" --> " << BothZero << " ");
// negative zero value returns true for 0 int
BothZero &= llvm::isa<ConstantInt>(ConstA) || !(ConstA->isNegativeZeroValue() || ConstB->isNegativeZeroValue());
PRINT_LOG_NL(" Negative Zero --> " << BothZero << " ");
BothZero &= !(ConstA->isNegativeZeroValue() || ConstB->isNegativeZeroValue());
return BothZero;
} else if (InstA && InstB) {
if (!ScalarToVector.count(InstA)) {
PRINT_LOG_NL("some elements weren't even vectorized");
return false;
}
bool Same = ScalarToVector[InstA] == ScalarToVector[InstB];
PRINT_LOG("A: "); PRINT_INST_NL(ScalarToVector[InstA]);
PRINT_LOG("B: "); PRINT_INST_NL(ScalarToVector[InstB]);
return Same;
}
return false;
Expand Down Expand Up @@ -275,48 +262,6 @@ bool IGCVectorizer::handleInsertElement(VecArr &Slice, Instruction* Final) {
return true;
}


bool IGCVectorizer::handleCastInstruction(VecArr &Slice) {

Instruction *First = Slice.front();

if (!ScalarToVector.count(First->getOperand(0))) {
PRINT_LOG_NL("some elements weren't even vectorized");
return false;
}

Value *Compare = ScalarToVector[First->getOperand(0)];
for (auto &El : Slice) {
Value *Val = El->getOperand(0);
Value *ValCompare = ScalarToVector[Val];
if (ValCompare != Compare) {
PRINT_LOG("UnaryCompare: "); PRINT_INST_NL(Compare);
PRINT_LOG("UnaryVal: "); PRINT_INST_NL(ValCompare);
PRINT_LOG_NL("Insert Element, operands do not converge");
return false;
}
}

auto VectorSize = getVectorSize((Instruction* )Compare);
auto Type = IGCLLVM::FixedVectorType::get(First->getType(), VectorSize);
auto CastOpcode = llvm::cast<CastInst>(First)->getOpcode();

CastInst* CreatedCast = CastInst::Create(CastOpcode, Compare, Type);
CreatedCast->setName("vectorized_cast");

CreatedCast->setDebugLoc(First->getDebugLoc());
CreatedCast->insertBefore(First);
CreatedVectorInstructions.push_back(CreatedCast);

PRINT_LOG("Cast instruction created: ");
PRINT_INST_NL(CreatedCast);

for (auto &el : Slice)
ScalarToVector[el] = CreatedCast;

return true;
}

// this basicaly seeds the chain
bool IGCVectorizer::handleExtractElement(VecArr &Slice) {
Instruction *First = Slice.front();
Expand All @@ -343,8 +288,6 @@ bool IGCVectorizer::processChain(InsertStruct &InSt) {
Instruction *First = Slice[0];
if (llvm::isa<PHINode>(First)) {
if (!handlePHI(Slice, InSt.Final->getType())) return false;
} else if (llvm::isa<CastInst>(First)) {
if (!handleCastInstruction(Slice)) return false;
} else if (llvm::isa<ExtractElementInst>(First)) {
if (!handleExtractElement(Slice)) return false;
} else if (llvm::isa<InsertElementInst>(First)) {
Expand Down Expand Up @@ -645,10 +588,8 @@ bool IGCVectorizer::runOnFunction(llvm::Function &F) {

CreatedVectorInstructions.clear();
if (!processChain(InSt)) {
writeLog();
std::reverse(CreatedVectorInstructions.begin(), CreatedVectorInstructions.end());
for (auto& el : CreatedVectorInstructions) {
PRINT_LOG("Cleaned: "); PRINT_INST_NL(el); writeLog();
PRINT_LOG("Cleaned: "); PRINT_INST_NL(el);
el->eraseFromParent();
}
}
Expand Down
1 change: 0 additions & 1 deletion IGC/Compiler/CISACodeGen/IGCVectorizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class IGCVectorizer : public llvm::FunctionPass {
bool handleInsertElement(VecArr& Slice, Instruction* Final);
bool checkExtractElement(Instruction* Compare, VecArr& Slice);
bool handleExtractElement(VecArr& Slice);
bool handleCastInstruction(VecArr& Slice);

bool compareOperands(Value* A, Value* B);

Expand Down
105 changes: 0 additions & 105 deletions IGC/Compiler/tests/IGCVectorizer/cast_test_vectorization.ll

This file was deleted.

Loading

0 comments on commit 26c11d9

Please sign in to comment.