[VPlan] Replace uses with new value in VPInstructionsToVPRecipe (NFC).
authorFlorian Hahn <flo@fhahn.com>
Mon, 25 Jan 2021 19:34:59 +0000 (19:34 +0000)
committerFlorian Hahn <flo@fhahn.com>
Mon, 25 Jan 2021 19:38:08 +0000 (19:38 +0000)
Now that VPRecipeBase inherits from VPDef, we can always use the new
VPValue for replacement, if the recipe defines one. Given the recipes
that are supported at the moment, all new recipes must have either 0 or
1 defined values.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

index f5565c1..1a54603 100644 (file)
@@ -35,7 +35,6 @@ void VPlanTransforms::VPInstructionsToVPRecipes(
       Plan->addCBV(NCondBit);
     }
   }
-  VPValue DummyValue;
   for (VPBlockBase *Base : RPOT) {
     // Do not widen instructions in pre-header and exit blocks.
     if (Base->getNumPredecessors() == 0 || Base->getNumSuccessors() == 0)
@@ -49,6 +48,7 @@ void VPlanTransforms::VPInstructionsToVPRecipes(
       VPInstruction *VPInst = cast<VPInstruction>(Ingredient);
       Instruction *Inst = cast<Instruction>(VPInst->getUnderlyingValue());
       if (DeadInstructions.count(Inst)) {
+        VPValue DummyValue;
         VPInst->replaceAllUsesWith(&DummyValue);
         Ingredient->eraseFromParent();
         continue;
@@ -80,7 +80,11 @@ void VPlanTransforms::VPInstructionsToVPRecipes(
             new VPWidenRecipe(*Inst, Plan->mapToVPValues(Inst->operands()));
 
       NewRecipe->insertBefore(Ingredient);
-      VPInst->replaceAllUsesWith(&DummyValue);
+      if (NewRecipe->getNumDefinedValues() == 1)
+        VPInst->replaceAllUsesWith(NewRecipe->getVPValue());
+      else
+        assert(NewRecipe->getNumDefinedValues() == 0 &&
+               "Only recpies with zero or one defined values expected");
       Ingredient->eraseFromParent();
     }
   }