@@ -54,9 +54,11 @@ class VPRecipeBuilder {
5454 EdgeMaskCacheTy EdgeMaskCache;
5555 BlockMaskCacheTy BlockMaskCache;
5656
57+ using RecipeOrResult = PointerUnion<VPRecipeBase*, VPValue*>;
58+
5759 // VPlan construction support: Hold a mapping from ingredients to
5860 // their recipe.
59- DenseMap<Instruction *, VPRecipeBase * > Ingredient2Recipe;
61+ DenseMap<Instruction *, RecipeOrResult > Ingredient2Recipe;
6062
6163 // / Cross-iteration reduction & first-order recurrence phis for which we need
6264 // / to add the incoming value from the backedge after all recipes have been
@@ -132,6 +134,14 @@ class VPRecipeBuilder {
132134 Ingredient2Recipe[I] = R;
133135 }
134136
137+ // Set the recipe value for a given ingredient.
138+ void setRecipe (Instruction* I, VPValue* RecipeResult) {
139+ assert (!Ingredient2Recipe.contains (I) &&
140+ " Cannot reset recipe for instruction." );
141+ assert (RecipeResult->getDefiningRecipe () && " Value must be defined by a recipe." );
142+ Ingredient2Recipe[I] = RecipeResult;
143+ }
144+
135145 // / Create the mask for the vector loop header block.
136146 void createHeaderMask ();
137147
@@ -158,9 +168,12 @@ class VPRecipeBuilder {
158168 VPRecipeBase *getRecipe (Instruction *I) {
159169 assert (Ingredient2Recipe.count (I) &&
160170 " Recording this ingredients recipe was not requested" );
161- assert (Ingredient2Recipe[I] != nullptr &&
171+ assert (Ingredient2Recipe[I] &&
162172 " Ingredient doesn't have a recipe" );
163- return Ingredient2Recipe[I];
173+ auto RecipeInfo = Ingredient2Recipe[I];
174+ if (auto * R = RecipeInfo.dyn_cast <VPRecipeBase*>())
175+ return R;
176+ return RecipeInfo.get <VPValue*>()->getDefiningRecipe ();
164177 }
165178
166179 // / Build a VPReplicationRecipe for \p I. If it is predicated, add the mask as
@@ -179,17 +192,10 @@ class VPRecipeBuilder {
179192
180193 VPValue *getVPValueOrAddLiveIn (Value *V) {
181194 if (auto *I = dyn_cast<Instruction>(V)) {
182- if (auto *R = Ingredient2Recipe.lookup (I))
183- return R->getVPSingleValue ();
184- }
185- // Ugh: Not sure where to handle this :(
186- if (auto *EVI = dyn_cast<ExtractValueInst>(V)) {
187- Value *AggOp = EVI->getAggregateOperand ();
188- if (auto *R = getRecipe (cast<Instruction>(AggOp))) {
189- assert (R->getNumDefinedValues () ==
190- cast<StructType>(AggOp->getType ())->getNumElements ());
191- unsigned Idx = EVI->getIndices ()[0 ];
192- return R->getVPValue (Idx);
195+ if (auto RecipeInfo = Ingredient2Recipe.lookup (I)) {
196+ if (auto * R = RecipeInfo.dyn_cast <VPRecipeBase*>())
197+ return R->getVPSingleValue ();
198+ return RecipeInfo.get <VPValue*>();
193199 }
194200 }
195201 return Plan.getOrAddLiveIn (V);
0 commit comments