@@ -781,6 +781,9 @@ struct ConvertMathToFuncsPass
781781 // or equal to minWidthOfFPowIExponent option value.
782782 bool isFPowIConvertible (math::FPowIOp op);
783783
784+ // Reture true, if operation is integer type.
785+ bool isConvertible (Operation *op);
786+
784787 // Generate outlined implementations for power operations
785788 // and store them in funcImpls map.
786789 void generateOpImplementations ();
@@ -798,13 +801,17 @@ bool ConvertMathToFuncsPass::isFPowIConvertible(math::FPowIOp op) {
798801 return (expTy && expTy.getWidth () >= minWidthOfFPowIExponent);
799802}
800803
804+ bool ConvertMathToFuncsPass::isConvertible (Operation *op) {
805+ return isa<IntegerType>(getElementTypeOrSelf (op->getResult (0 ).getType ()));
806+ }
807+
801808void ConvertMathToFuncsPass::generateOpImplementations () {
802809 ModuleOp module = getOperation ();
803810
804811 module .walk ([&](Operation *op) {
805812 TypeSwitch<Operation *>(op)
806813 .Case <math::CountLeadingZerosOp>([&](math::CountLeadingZerosOp op) {
807- if (!convertCtlz)
814+ if (!convertCtlz || ! isConvertible (op) )
808815 return ;
809816 Type resultType = getElementTypeOrSelf (op.getResult ().getType ());
810817
@@ -816,6 +823,9 @@ void ConvertMathToFuncsPass::generateOpImplementations() {
816823 entry.first ->second = createCtlzFunc (&module , resultType);
817824 })
818825 .Case <math::IPowIOp>([&](math::IPowIOp op) {
826+ if (!isConvertible (op))
827+ return ;
828+
819829 Type resultType = getElementTypeOrSelf (op.getResult ().getType ());
820830
821831 // Generate the software implementation of this operation,
@@ -873,9 +883,12 @@ void ConvertMathToFuncsPass::runOnOperation() {
873883 func::FuncDialect, scf::SCFDialect,
874884 vector::VectorDialect>();
875885
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+ }
879892 target.addDynamicallyLegalOp <math::FPowIOp>(
880893 [this ](math::FPowIOp op) { return !isFPowIConvertible (op); });
881894 if (failed (applyPartialConversion (module , target, std::move (patterns))))
0 commit comments