@@ -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