Skip to content

Commit 6a423f9

Browse files
igorban-inteligcbot
authored andcommitted
Add fast exits in pattern match
.
1 parent bdb57da commit 6a423f9

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,9 @@ class MinMaxMatcher {
720720
} // namespace
721721

722722
void GenXPatternMatch::visitBinaryOperator(BinaryOperator &I) {
723+
if (I.use_empty())
724+
return;
725+
723726
if (Kind == PatternMatchKind::PreLegalization) {
724727
if (isPredNot(&I))
725728
Changed |= flipBoolNot(&I);
@@ -769,6 +772,9 @@ void GenXPatternMatch::visitBinaryOperator(BinaryOperator &I) {
769772
}
770773

771774
void GenXPatternMatch::visitCallInst(CallInst &I) {
775+
if (I.use_empty())
776+
return;
777+
772778
auto IID = vc::getAnyIntrinsicID(&I);
773779

774780
switch (IID) {
@@ -854,12 +860,8 @@ void GenXPatternMatch::visitCallInst(CallInst &I) {
854860
}
855861

856862
void GenXPatternMatch::visitICmpInst(ICmpInst &I) {
857-
if (Kind == PatternMatchKind::PostLegalization) {
858-
return;
859-
}
860-
861863
// Ignore dead comparison.
862-
if (I.use_empty())
864+
if (I.use_empty() || Kind == PatternMatchKind::PostLegalization)
863865
return;
864866

865867
Value *V0 = nullptr;
@@ -1343,6 +1345,8 @@ bool GenXPatternMatch::matchFloatAbs(BinaryOperator *I) {
13431345
auto *User = I->user_back();
13441346
if (!isa<BitCastInst>(User) || User->getType() != SrcTy)
13451347
return false;
1348+
if (User->use_empty())
1349+
return false;
13461350

13471351
uint64_t SplatV = 0;
13481352
auto *Op = I->getOperand(1);
@@ -1383,6 +1387,14 @@ bool GenXPatternMatch::foldBoolAnd(Instruction *Inst) {
13831387
if (!Inst->hasOneUse())
13841388
return false; // more than one use
13851389
auto user = cast<Instruction>(Inst->use_begin()->getUser());
1390+
if (user && user->getOperand(1)) {
1391+
auto *Ty = user->getOperand(1)->getType();
1392+
auto *DTy = dyn_cast<IGCLLVM::FixedVectorType>(Ty);
1393+
if (!DTy || (DTy->getNumElements() == 1))
1394+
return false;
1395+
} else
1396+
return false;
1397+
13861398
if (auto Sel = dyn_cast<SelectInst>(user)) {
13871399
// Fold and into sel.
13881400
auto NewSel1 = SelectInst::Create(Inst->getOperand(0), Sel->getOperand(1),
@@ -1419,6 +1431,8 @@ bool GenXPatternMatch::foldBoolAnd(Instruction *Inst) {
14191431
}
14201432

14211433
void GenXPatternMatch::visitSelectInst(SelectInst &I) {
1434+
if (I.use_empty())
1435+
return;
14221436
Changed |= (Kind == PatternMatchKind::PreLegalization) &&
14231437
MinMaxMatcher::isEnabled() && MinMaxMatcher(&I).matchMinMax();
14241438
}
@@ -2682,6 +2696,8 @@ bool GenXPatternMatch::simplifyRdRegion(CallInst *Inst) {
26822696

26832697
bool GenXPatternMatch::simplifyWrRegion(CallInst *Inst) {
26842698
IGC_ASSERT(GenXIntrinsic::isWrRegion(Inst));
2699+
if (Inst->use_empty())
2700+
return false;
26852701
Value *NewV = Inst->getOperand(GenXIntrinsic::GenXRegion::NewValueOperandNum);
26862702
Type *NewVTy = NewV->getType();
26872703

@@ -3114,9 +3130,8 @@ static void decomposeSDivPow2(BinaryOperator &SDivOp) {
31143130
}
31153131

31163132
void GenXPatternMatch::visitSDiv(BinaryOperator &I) {
3117-
if (Kind == PatternMatchKind::PostLegalization) {
3133+
if (I.use_empty() || Kind == PatternMatchKind::PostLegalization)
31183134
return;
3119-
}
31203135

31213136
auto CheckRes = isSuitableSDivSRemOperand(I.getOperand(1));
31223137
if (CheckRes == DivRemOptimize::Not)
@@ -3228,9 +3243,8 @@ static void decomposeUDivNotPow2(BinaryOperator &UDivOp) {
32283243
}
32293244

32303245
void GenXPatternMatch::visitUDiv(BinaryOperator &I) {
3231-
if (Kind == PatternMatchKind::PostLegalization) {
3246+
if (I.use_empty() || Kind == PatternMatchKind::PostLegalization)
32323247
return;
3233-
}
32343248

32353249
auto CheckRes = isSuitableUDivURemOperand(I.getOperand(1));
32363250
if (CheckRes == DivRemOptimize::Not)
@@ -3269,9 +3283,8 @@ static void decomposeSRemPow2(BinaryOperator &SRemOp) {
32693283
}
32703284

32713285
void GenXPatternMatch::visitSRem(BinaryOperator &I) {
3272-
if (Kind == PatternMatchKind::PostLegalization) {
3286+
if (I.use_empty() || Kind == PatternMatchKind::PostLegalization)
32733287
return;
3274-
}
32753288

32763289
auto CheckRes = isSuitableSDivSRemOperand(I.getOperand(1));
32773290
if (CheckRes == DivRemOptimize::Not)
@@ -3350,9 +3363,8 @@ static void decomposeURemNotPow2(BinaryOperator &URemOp) {
33503363
}
33513364

33523365
void GenXPatternMatch::visitURem(BinaryOperator &I) {
3353-
if (Kind == PatternMatchKind::PostLegalization) {
3366+
if (I.use_empty() || Kind == PatternMatchKind::PostLegalization)
33543367
return;
3355-
}
33563368

33573369
auto CheckRes = isSuitableUDivURemOperand(I.getOperand(1));
33583370
if (CheckRes == DivRemOptimize::Not)
@@ -3366,6 +3378,9 @@ void GenXPatternMatch::visitURem(BinaryOperator &I) {
33663378

33673379
// Clean up 'freeze' instances once dependent w/a's have been resolved.
33683380
void GenXPatternMatch::visitFreezeInst(FreezeInst &I) {
3381+
if (I.use_empty())
3382+
return;
3383+
33693384
Value *Op = I.getOperand(0);
33703385
I.replaceAllUsesWith(Op);
33713386
Changed = true;
@@ -4058,7 +4073,7 @@ bool GenXPatternMatch::extendMask(BinaryOperator *BO) {
40584073
}
40594074

40604075
void GenXPatternMatch::visitPHINode(PHINode &I) {
4061-
if (Kind != PatternMatchKind::PreLegalization)
4076+
if (I.use_empty() || Kind != PatternMatchKind::PreLegalization)
40624077
return;
40634078

40644079
std::unordered_set<PHINode *> Visited;

0 commit comments

Comments
 (0)