diff --git a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp --- a/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp +++ b/mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp @@ -804,6 +804,8 @@ module.walk([&](Operation *op) { TypeSwitch(op) .Case([&](math::CountLeadingZerosOp op) { + if (!convertCtlz) + return; Type resultType = getElementTypeOrSelf(op.getResult().getType()); // Generate the software implementation of this operation, @@ -872,7 +874,8 @@ vector::VectorDialect>(); target.addIllegalOp(); - target.addIllegalOp(); + if (convertCtlz) + target.addIllegalOp(); target.addDynamicallyLegalOp( [this](math::FPowIOp op) { return !isFPowIConvertible(op); }); if (failed(applyPartialConversion(module, target, std::move(patterns)))) diff --git a/mlir/test/Conversion/MathToFuncs/ctlz.mlir b/mlir/test/Conversion/MathToFuncs/ctlz.mlir --- a/mlir/test/Conversion/MathToFuncs/ctlz.mlir +++ b/mlir/test/Conversion/MathToFuncs/ctlz.mlir @@ -1,4 +1,5 @@ // RUN: mlir-opt %s -split-input-file -pass-pipeline="builtin.module(convert-math-to-funcs{convert-ctlz})" | FileCheck %s +// RUN: mlir-opt %s -split-input-file -pass-pipeline="builtin.module(convert-math-to-funcs{convert-ctlz=false})" | FileCheck --check-prefix=NOCVT %s // Check a golden-path i32 conversion @@ -38,6 +39,7 @@ // CHECK: } // CHECK: return %[[OUT]] : i32 // CHECK: } +// NOCVT-NOT: __mlir_math_ctlz_i32 func.func @main(%arg0: i32) { %0 = math.ctlz %arg0 : i32 func.return @@ -83,6 +85,7 @@ // CHECK: } // CHECK: return %[[OUT]] : i8 // CHECK: } +// NOCVT-NOT: __mlir_math_ctlz_i32 func.func @main(%arg0: i8) { %0 = math.ctlz %arg0 : i8 func.return