13
13
14
14
#include " VPlanTransforms.h"
15
15
#include " VPRecipeBuilder.h"
16
+ #include " VPlanAnalysis.h"
16
17
#include " VPlanCFG.h"
17
18
#include " VPlanDominatorTree.h"
18
19
#include " llvm/ADT/PostOrderIterator.h"
@@ -802,17 +803,8 @@ static unsigned getOpcodeForRecipe(VPRecipeBase &R) {
802
803
return 0 ;
803
804
}
804
805
805
- // / Return the scalar size in bits for \p VPV if possible.
806
- static Type *getTypeForVPValue (VPValue *VPV) {
807
- // TODO: Replace with VPlan type inference once ready.
808
- if (auto *VPC = dyn_cast<VPWidenCastRecipe>(VPV))
809
- return VPC->getResultType ();
810
- auto *UV = VPV->getUnderlyingValue ();
811
- return UV ? UV->getType () : nullptr ;
812
- }
813
-
814
806
// / Try to simplify recipe \p R.
815
- static void simplifyRecipe (VPRecipeBase &R) {
807
+ static void simplifyRecipe (VPRecipeBase &R, VPTypeAnalysis &TypeInfo ) {
816
808
switch (getOpcodeForRecipe (R)) {
817
809
case Instruction::Mul: {
818
810
VPValue *A = R.getOperand (0 );
@@ -829,9 +821,23 @@ static void simplifyRecipe(VPRecipeBase &R) {
829
821
break ;
830
822
VPValue *A = Zext->getOperand (0 );
831
823
VPValue *Trunc = R.getVPSingleValue ();
832
- Type *TruncToTy = getTypeForVPValue (Trunc);
833
- if (TruncToTy && TruncToTy == getTypeForVPValue (A))
824
+ Type *TruncToTy = TypeInfo. inferScalarType (Trunc);
825
+ if (TruncToTy && TruncToTy == TypeInfo. inferScalarType (A))
834
826
Trunc->replaceAllUsesWith (A);
827
+
828
+ #ifndef NDEBUG
829
+ // Verify that the cached type info is for both A and its users is still
830
+ // accurate by comparing it to freshly computed types.
831
+ VPTypeAnalysis TypeInfo2 (TypeInfo.getContext ());
832
+ assert (TypeInfo.inferScalarType (A) == TypeInfo2.inferScalarType (A));
833
+ for (VPUser *U : A->users ()) {
834
+ auto *R = dyn_cast<VPRecipeBase>(U);
835
+ if (!R)
836
+ continue ;
837
+ for (VPValue *VPV : R->definedValues ())
838
+ assert (TypeInfo.inferScalarType (VPV) == TypeInfo2.inferScalarType (VPV));
839
+ }
840
+ #endif
835
841
break ;
836
842
}
837
843
default :
@@ -840,12 +846,13 @@ static void simplifyRecipe(VPRecipeBase &R) {
840
846
}
841
847
842
848
// / Try to simplify the recipes in \p Plan.
843
- static void simplifyRecipes (VPlan &Plan) {
849
+ static void simplifyRecipes (VPlan &Plan, LLVMContext &Ctx ) {
844
850
ReversePostOrderTraversal<VPBlockDeepTraversalWrapper<VPBlockBase *>> RPOT (
845
851
Plan.getEntry ());
852
+ VPTypeAnalysis TypeInfo (Ctx);
846
853
for (VPBasicBlock *VPBB : VPBlockUtils::blocksOnly<VPBasicBlock>(RPOT)) {
847
854
for (VPRecipeBase &R : make_early_inc_range (*VPBB)) {
848
- simplifyRecipe (R);
855
+ simplifyRecipe (R, TypeInfo );
849
856
}
850
857
}
851
858
}
@@ -855,7 +862,7 @@ void VPlanTransforms::optimize(VPlan &Plan, ScalarEvolution &SE) {
855
862
removeRedundantInductionCasts (Plan);
856
863
857
864
optimizeInductions (Plan, SE);
858
- simplifyRecipes (Plan);
865
+ simplifyRecipes (Plan, SE. getContext () );
859
866
removeDeadRecipes (Plan);
860
867
861
868
createAndOptimizeReplicateRegions (Plan);
0 commit comments