[flang-commits] [llvm] [flang] [clang-tools-extra] [clang] [compiler-rt] [VPlan] Replace VPRecipeOrVPValue with VP2VP recipe simplification. (PR #76090)
Florian Hahn via flang-commits
flang-commits at lists.llvm.org
Tue Jan 16 14:05:30 PST 2024
================
@@ -806,6 +806,38 @@ static unsigned getOpcodeForRecipe(VPRecipeBase &R) {
/// Try to simplify recipe \p R.
static void simplifyRecipe(VPRecipeBase &R, VPTypeAnalysis &TypeInfo) {
+ // Try to remove redundant blend recipes.
+ if (auto *Blend = dyn_cast<VPBlendRecipe>(&R)) {
+ if (Blend->getNumIncomingValues() == 1) {
+ Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
+ Blend->eraseFromParent();
+ return;
+ }
+
+ bool AllEqual = true;
+ for (unsigned I = 1; I != Blend->getNumIncomingValues(); ++I)
+ AllEqual &= Blend->getIncomingValue(0) == Blend->getIncomingValue(I);
+ if (AllEqual) {
+ Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
+ Blend->eraseFromParent();
+ return;
+ }
+ if (Blend->getNumIncomingValues() != 2)
+ return;
+ auto IsInLoopReduction = [](VPValue *VPV) {
+ auto *PhiR = dyn_cast<VPReductionPHIRecipe>(VPV);
+ return PhiR && PhiR->isInLoop();
+ };
+ if (IsInLoopReduction(Blend->getIncomingValue(0))) {
+ Blend->replaceAllUsesWith(Blend->getIncomingValue(1));
+ Blend->eraseFromParent();
+ } else if (IsInLoopReduction(Blend->getIncomingValue(1))) {
+ Blend->replaceAllUsesWith(Blend->getIncomingValue(0));
+ Blend->eraseFromParent();
+ }
----------------
fhahn wrote:
Moved as suggested, thanks!
https://github.com/llvm/llvm-project/pull/76090
More information about the flang-commits
mailing list