@@ -160,11 +160,15 @@ struct CachingVPExpander {
160
160
Value *convertEVLToMask (IRBuilder<> &Builder, Value *EVLParam,
161
161
ElementCount ElemCount);
162
162
163
- Value *foldEVLIntoMask (VPIntrinsic &VPI);
163
+ // / If needed, folds the EVL in the mask operand and discards the EVL
164
+ // / parameter. Returns a pair of the value of the intrinsic after the change
165
+ // / (if any) and whether the mask was actually folded.
166
+ std::pair<Value *, bool > foldEVLIntoMask (VPIntrinsic &VPI);
164
167
165
168
// / "Remove" the %evl parameter of \p PI by setting it to the static vector
166
- // / length of the operation.
167
- void discardEVLParameter (VPIntrinsic &PI);
169
+ // / length of the operation. Returns true if the %evl (if any) was effectively
170
+ // / changed.
171
+ bool discardEVLParameter (VPIntrinsic &PI);
168
172
169
173
// / Lower this VP binary operator to a unpredicated binary operator.
170
174
Value *expandPredicationInBinaryOperator (IRBuilder<> &Builder,
@@ -206,7 +210,9 @@ struct CachingVPExpander {
206
210
CachingVPExpander (const TargetTransformInfo &TTI)
207
211
: TTI(TTI), UsingTTIOverrides(anyExpandVPOverridesSet()) {}
208
212
209
- bool expandVectorPredication (VPIntrinsic &VPI);
213
+ // / Expand llvm.vp.* intrinsics as requested by \p TTI.
214
+ // / Returns the details of the expansion.
215
+ VPExpansionDetails expandVectorPredication (VPIntrinsic &VPI);
210
216
};
211
217
212
218
// // CachingVPExpander {
@@ -645,15 +651,15 @@ Value *CachingVPExpander::expandPredicationInComparison(IRBuilder<> &Builder,
645
651
return NewCmp;
646
652
}
647
653
648
- void CachingVPExpander::discardEVLParameter (VPIntrinsic &VPI) {
654
+ bool CachingVPExpander::discardEVLParameter (VPIntrinsic &VPI) {
649
655
LLVM_DEBUG (dbgs () << " Discard EVL parameter in " << VPI << " \n " );
650
656
651
657
if (VPI.canIgnoreVectorLengthParam ())
652
- return ;
658
+ return false ;
653
659
654
660
Value *EVLParam = VPI.getVectorLengthParam ();
655
661
if (!EVLParam)
656
- return ;
662
+ return false ;
657
663
658
664
ElementCount StaticElemCount = VPI.getStaticVectorLength ();
659
665
Value *MaxEVL = nullptr ;
@@ -672,16 +678,17 @@ void CachingVPExpander::discardEVLParameter(VPIntrinsic &VPI) {
672
678
MaxEVL = ConstantInt::get (Int32Ty, StaticElemCount.getFixedValue (), false );
673
679
}
674
680
VPI.setVectorLengthParam (MaxEVL);
681
+ return true ;
675
682
}
676
683
677
- Value *CachingVPExpander::foldEVLIntoMask (VPIntrinsic &VPI) {
684
+ std::pair< Value *, bool > CachingVPExpander::foldEVLIntoMask (VPIntrinsic &VPI) {
678
685
LLVM_DEBUG (dbgs () << " Folding vlen for " << VPI << ' \n ' );
679
686
680
687
IRBuilder<> Builder (&VPI);
681
688
682
689
// Ineffective %evl parameter and so nothing to do here.
683
690
if (VPI.canIgnoreVectorLengthParam ())
684
- return &VPI;
691
+ return { &VPI, false } ;
685
692
686
693
// Only VP intrinsics can have an %evl parameter.
687
694
Value *OldMaskParam = VPI.getMaskParam ();
@@ -704,7 +711,7 @@ Value *CachingVPExpander::foldEVLIntoMask(VPIntrinsic &VPI) {
704
711
" transformation did not render the evl param ineffective!" );
705
712
706
713
// Reassess the modified instruction.
707
- return &VPI;
714
+ return { &VPI, true } ;
708
715
}
709
716
710
717
Value *CachingVPExpander::expandPredication (VPIntrinsic &VPI) {
@@ -807,21 +814,27 @@ CachingVPExpander::getVPLegalizationStrategy(const VPIntrinsic &VPI) const {
807
814
return VPStrat;
808
815
}
809
816
810
- // / Expand llvm.vp.* intrinsics as requested by \p TTI.
811
- bool CachingVPExpander::expandVectorPredication (VPIntrinsic &VPI) {
817
+ VPExpansionDetails
818
+ CachingVPExpander::expandVectorPredication (VPIntrinsic &VPI) {
812
819
auto Strategy = getVPLegalizationStrategy (VPI);
813
820
sanitizeStrategy (VPI, Strategy);
814
821
822
+ VPExpansionDetails Changed = VPExpansionDetails::IntrinsicUnchanged;
823
+
815
824
// Transform the EVL parameter.
816
825
switch (Strategy.EVLParamStrategy ) {
817
826
case VPLegalization::Legal:
818
827
break ;
819
828
case VPLegalization::Discard:
820
- discardEVLParameter (VPI);
829
+ if (discardEVLParameter (VPI))
830
+ Changed = VPExpansionDetails::IntrinsicUpdated;
821
831
break ;
822
832
case VPLegalization::Convert:
823
- if (foldEVLIntoMask (VPI))
833
+ if (auto [NewVPI, Folded] = foldEVLIntoMask (VPI); Folded) {
834
+ (void )NewVPI;
835
+ Changed = VPExpansionDetails::IntrinsicUpdated;
824
836
++NumFoldedVL;
837
+ }
825
838
break ;
826
839
}
827
840
@@ -834,17 +847,17 @@ bool CachingVPExpander::expandVectorPredication(VPIntrinsic &VPI) {
834
847
case VPLegalization::Convert:
835
848
if (Value *V = expandPredication (VPI); V != &VPI) {
836
849
++NumLoweredVPOps;
837
- // Return true if and only if the intrinsic was actually removed.
838
- return true ;
850
+ Changed = VPExpansionDetails::IntrinsicReplaced;
839
851
}
840
852
break ;
841
853
}
842
854
843
- return false ;
855
+ return Changed ;
844
856
}
845
857
} // namespace
846
858
847
- bool llvm::expandVectorPredicationIntrinsic (VPIntrinsic &VPI,
848
- const TargetTransformInfo &TTI) {
859
+ VPExpansionDetails
860
+ llvm::expandVectorPredicationIntrinsic (VPIntrinsic &VPI,
861
+ const TargetTransformInfo &TTI) {
849
862
return CachingVPExpander (TTI).expandVectorPredication (VPI);
850
863
}
0 commit comments