@@ -781,6 +781,9 @@ struct ConvertMathToFuncsPass
781
781
// or equal to minWidthOfFPowIExponent option value.
782
782
bool isFPowIConvertible (math::FPowIOp op);
783
783
784
+ // Reture true, if operation is integer type.
785
+ bool isConvertible (Operation *op);
786
+
784
787
// Generate outlined implementations for power operations
785
788
// and store them in funcImpls map.
786
789
void generateOpImplementations ();
@@ -798,13 +801,17 @@ bool ConvertMathToFuncsPass::isFPowIConvertible(math::FPowIOp op) {
798
801
return (expTy && expTy.getWidth () >= minWidthOfFPowIExponent);
799
802
}
800
803
804
+ bool ConvertMathToFuncsPass::isConvertible (Operation *op) {
805
+ return isa<IntegerType>(getElementTypeOrSelf (op->getResult (0 ).getType ()));
806
+ }
807
+
801
808
void ConvertMathToFuncsPass::generateOpImplementations () {
802
809
ModuleOp module = getOperation ();
803
810
804
811
module .walk ([&](Operation *op) {
805
812
TypeSwitch<Operation *>(op)
806
813
.Case <math::CountLeadingZerosOp>([&](math::CountLeadingZerosOp op) {
807
- if (!convertCtlz)
814
+ if (!convertCtlz || ! isConvertible (op) )
808
815
return ;
809
816
Type resultType = getElementTypeOrSelf (op.getResult ().getType ());
810
817
@@ -816,6 +823,9 @@ void ConvertMathToFuncsPass::generateOpImplementations() {
816
823
entry.first ->second = createCtlzFunc (&module , resultType);
817
824
})
818
825
.Case <math::IPowIOp>([&](math::IPowIOp op) {
826
+ if (!isConvertible (op))
827
+ return ;
828
+
819
829
Type resultType = getElementTypeOrSelf (op.getResult ().getType ());
820
830
821
831
// Generate the software implementation of this operation,
@@ -873,9 +883,12 @@ void ConvertMathToFuncsPass::runOnOperation() {
873
883
func::FuncDialect, scf::SCFDialect,
874
884
vector::VectorDialect>();
875
885
876
- target.addIllegalOp <math::IPowIOp>();
877
- if (convertCtlz)
878
- target.addIllegalOp <math::CountLeadingZerosOp>();
886
+ target.addDynamicallyLegalOp <math::IPowIOp>(
887
+ [this ](math::IPowIOp op) { return !isConvertible (op); });
888
+ if (convertCtlz) {
889
+ target.addDynamicallyLegalOp <math::CountLeadingZerosOp>(
890
+ [this ](math::CountLeadingZerosOp op) { return !isConvertible (op); });
891
+ }
879
892
target.addDynamicallyLegalOp <math::FPowIOp>(
880
893
[this ](math::FPowIOp op) { return !isFPowIConvertible (op); });
881
894
if (failed (applyPartialConversion (module , target, std::move (patterns))))
0 commit comments