Skip to content

Commit 1034a6b

Browse files
kychendevigcbot
authored andcommitted
Improve pattern match optimization for WrRegion.
Improve pattern match optimization for WrRegion.
1 parent 8723db6 commit 1034a6b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

IGC/VectorCompiler/lib/GenXCodeGen/GenXPatternMatch.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2534,6 +2534,39 @@ bool GenXPatternMatch::simplifyWrRegion(CallInst *Inst) {
25342534
return true;
25352535
}
25362536
}
2537+
2538+
// Convert WrRegion to a matching Select instruction
2539+
// Also perform Min/Max optimization if enabled
2540+
if (R.isWhole(Inst->getType())) {
2541+
Value *OldV =
2542+
Inst->getOperand(GenXIntrinsic::GenXRegion::OldValueOperandNum);
2543+
Type *OldVTy = OldV->getType();
2544+
2545+
Value *MaskV =
2546+
Inst->getOperand(GenXIntrinsic::GenXRegion::PredicateOperandNum);
2547+
Type *MaskVTy = MaskV->getType();
2548+
2549+
if (!(isa<UndefValue>(OldV)) && OldVTy->isVectorTy() &&
2550+
NewVTy->isVectorTy() && MaskVTy->isVectorTy() &&
2551+
cast<VectorType>(OldVTy)->getNumElements() ==
2552+
cast<VectorType>(NewVTy)->getNumElements() &&
2553+
cast<VectorType>(OldVTy)->getNumElements() ==
2554+
cast<VectorType>(MaskVTy)->getNumElements()) {
2555+
Instruction *InsertBefore = Inst->getNextNode();
2556+
auto SelectInstruction =
2557+
SelectInst::Create(MaskV, NewV, OldV, "", InsertBefore, Inst);
2558+
SelectInstruction->setDebugLoc(Inst->getDebugLoc());
2559+
SelectInstruction->takeName(Inst);
2560+
Inst->replaceAllUsesWith(SelectInstruction);
2561+
Inst->eraseFromParent();
2562+
2563+
if (MinMaxMatcher::isEnabled())
2564+
MinMaxMatcher(SelectInstruction).matchMinMax();
2565+
2566+
return true;
2567+
}
2568+
}
2569+
25372570
return false;
25382571
}
25392572

@@ -2722,7 +2755,7 @@ bool GenXPatternMatch::clearDeadInstructions(Function &F) {
27222755
ToErase.push_back(WeakTrackingVH(&Inst));
27232756
if (!ToErase.empty()) {
27242757
Changed = true;
2725-
2758+
27262759
IGCLLVM::RecursivelyDeleteTriviallyDeadInstructions(ToErase);
27272760
}
27282761
return Changed;

0 commit comments

Comments
 (0)