@@ -2534,6 +2534,39 @@ bool GenXPatternMatch::simplifyWrRegion(CallInst *Inst) {
2534
2534
return true ;
2535
2535
}
2536
2536
}
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
+
2537
2570
return false ;
2538
2571
}
2539
2572
@@ -2722,7 +2755,7 @@ bool GenXPatternMatch::clearDeadInstructions(Function &F) {
2722
2755
ToErase.push_back (WeakTrackingVH (&Inst));
2723
2756
if (!ToErase.empty ()) {
2724
2757
Changed = true ;
2725
-
2758
+
2726
2759
IGCLLVM::RecursivelyDeleteTriviallyDeadInstructions (ToErase);
2727
2760
}
2728
2761
return Changed;
0 commit comments