@@ -720,6 +720,9 @@ class MinMaxMatcher {
720
720
} // namespace
721
721
722
722
void GenXPatternMatch::visitBinaryOperator (BinaryOperator &I) {
723
+ if (I.use_empty ())
724
+ return ;
725
+
723
726
if (Kind == PatternMatchKind::PreLegalization) {
724
727
if (isPredNot (&I))
725
728
Changed |= flipBoolNot (&I);
@@ -769,6 +772,9 @@ void GenXPatternMatch::visitBinaryOperator(BinaryOperator &I) {
769
772
}
770
773
771
774
void GenXPatternMatch::visitCallInst (CallInst &I) {
775
+ if (I.use_empty ())
776
+ return ;
777
+
772
778
auto IID = vc::getAnyIntrinsicID (&I);
773
779
774
780
switch (IID) {
@@ -854,12 +860,8 @@ void GenXPatternMatch::visitCallInst(CallInst &I) {
854
860
}
855
861
856
862
void GenXPatternMatch::visitICmpInst (ICmpInst &I) {
857
- if (Kind == PatternMatchKind::PostLegalization) {
858
- return ;
859
- }
860
-
861
863
// Ignore dead comparison.
862
- if (I.use_empty ())
864
+ if (I.use_empty () || Kind == PatternMatchKind::PostLegalization )
863
865
return ;
864
866
865
867
Value *V0 = nullptr ;
@@ -1343,6 +1345,8 @@ bool GenXPatternMatch::matchFloatAbs(BinaryOperator *I) {
1343
1345
auto *User = I->user_back ();
1344
1346
if (!isa<BitCastInst>(User) || User->getType () != SrcTy)
1345
1347
return false ;
1348
+ if (User->use_empty ())
1349
+ return false ;
1346
1350
1347
1351
uint64_t SplatV = 0 ;
1348
1352
auto *Op = I->getOperand (1 );
@@ -1383,6 +1387,14 @@ bool GenXPatternMatch::foldBoolAnd(Instruction *Inst) {
1383
1387
if (!Inst->hasOneUse ())
1384
1388
return false ; // more than one use
1385
1389
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
+
1386
1398
if (auto Sel = dyn_cast<SelectInst>(user)) {
1387
1399
// Fold and into sel.
1388
1400
auto NewSel1 = SelectInst::Create (Inst->getOperand (0 ), Sel->getOperand (1 ),
@@ -1419,6 +1431,8 @@ bool GenXPatternMatch::foldBoolAnd(Instruction *Inst) {
1419
1431
}
1420
1432
1421
1433
void GenXPatternMatch::visitSelectInst (SelectInst &I) {
1434
+ if (I.use_empty ())
1435
+ return ;
1422
1436
Changed |= (Kind == PatternMatchKind::PreLegalization) &&
1423
1437
MinMaxMatcher::isEnabled () && MinMaxMatcher (&I).matchMinMax ();
1424
1438
}
@@ -2682,6 +2696,8 @@ bool GenXPatternMatch::simplifyRdRegion(CallInst *Inst) {
2682
2696
2683
2697
bool GenXPatternMatch::simplifyWrRegion (CallInst *Inst) {
2684
2698
IGC_ASSERT (GenXIntrinsic::isWrRegion (Inst));
2699
+ if (Inst->use_empty ())
2700
+ return false ;
2685
2701
Value *NewV = Inst->getOperand (GenXIntrinsic::GenXRegion::NewValueOperandNum);
2686
2702
Type *NewVTy = NewV->getType ();
2687
2703
@@ -3114,9 +3130,8 @@ static void decomposeSDivPow2(BinaryOperator &SDivOp) {
3114
3130
}
3115
3131
3116
3132
void GenXPatternMatch::visitSDiv (BinaryOperator &I) {
3117
- if (Kind == PatternMatchKind::PostLegalization) {
3133
+ if (I. use_empty () || Kind == PatternMatchKind::PostLegalization)
3118
3134
return ;
3119
- }
3120
3135
3121
3136
auto CheckRes = isSuitableSDivSRemOperand (I.getOperand (1 ));
3122
3137
if (CheckRes == DivRemOptimize::Not)
@@ -3228,9 +3243,8 @@ static void decomposeUDivNotPow2(BinaryOperator &UDivOp) {
3228
3243
}
3229
3244
3230
3245
void GenXPatternMatch::visitUDiv (BinaryOperator &I) {
3231
- if (Kind == PatternMatchKind::PostLegalization) {
3246
+ if (I. use_empty () || Kind == PatternMatchKind::PostLegalization)
3232
3247
return ;
3233
- }
3234
3248
3235
3249
auto CheckRes = isSuitableUDivURemOperand (I.getOperand (1 ));
3236
3250
if (CheckRes == DivRemOptimize::Not)
@@ -3269,9 +3283,8 @@ static void decomposeSRemPow2(BinaryOperator &SRemOp) {
3269
3283
}
3270
3284
3271
3285
void GenXPatternMatch::visitSRem (BinaryOperator &I) {
3272
- if (Kind == PatternMatchKind::PostLegalization) {
3286
+ if (I. use_empty () || Kind == PatternMatchKind::PostLegalization)
3273
3287
return ;
3274
- }
3275
3288
3276
3289
auto CheckRes = isSuitableSDivSRemOperand (I.getOperand (1 ));
3277
3290
if (CheckRes == DivRemOptimize::Not)
@@ -3350,9 +3363,8 @@ static void decomposeURemNotPow2(BinaryOperator &URemOp) {
3350
3363
}
3351
3364
3352
3365
void GenXPatternMatch::visitURem (BinaryOperator &I) {
3353
- if (Kind == PatternMatchKind::PostLegalization) {
3366
+ if (I. use_empty () || Kind == PatternMatchKind::PostLegalization)
3354
3367
return ;
3355
- }
3356
3368
3357
3369
auto CheckRes = isSuitableUDivURemOperand (I.getOperand (1 ));
3358
3370
if (CheckRes == DivRemOptimize::Not)
@@ -3366,6 +3378,9 @@ void GenXPatternMatch::visitURem(BinaryOperator &I) {
3366
3378
3367
3379
// Clean up 'freeze' instances once dependent w/a's have been resolved.
3368
3380
void GenXPatternMatch::visitFreezeInst (FreezeInst &I) {
3381
+ if (I.use_empty ())
3382
+ return ;
3383
+
3369
3384
Value *Op = I.getOperand (0 );
3370
3385
I.replaceAllUsesWith (Op);
3371
3386
Changed = true ;
@@ -4058,7 +4073,7 @@ bool GenXPatternMatch::extendMask(BinaryOperator *BO) {
4058
4073
}
4059
4074
4060
4075
void GenXPatternMatch::visitPHINode (PHINode &I) {
4061
- if (Kind != PatternMatchKind::PreLegalization)
4076
+ if (I. use_empty () || Kind != PatternMatchKind::PreLegalization)
4062
4077
return ;
4063
4078
4064
4079
std::unordered_set<PHINode *> Visited;
0 commit comments