Skip to content

Commit

Permalink
[mlir][math] Properly disable ctlz conversion in MathToFuncs.
Browse files Browse the repository at this point in the history
This fixes issues caused by D146261.
Differential Revision: https://reviews.llvm.org/D148477
  • Loading branch information
vzakhari committed Apr 16, 2023
1 parent c31fca1 commit ce47090
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mlir/lib/Conversion/MathToFuncs/MathToFuncs.cpp
Expand Up @@ -804,6 +804,8 @@ void ConvertMathToFuncsPass::generateOpImplementations() {
module.walk([&](Operation *op) {
TypeSwitch<Operation *>(op)
.Case<math::CountLeadingZerosOp>([&](math::CountLeadingZerosOp op) {
if (!convertCtlz)
return;
Type resultType = getElementTypeOrSelf(op.getResult().getType());

// Generate the software implementation of this operation,
Expand Down Expand Up @@ -872,7 +874,8 @@ void ConvertMathToFuncsPass::runOnOperation() {
vector::VectorDialect>();

target.addIllegalOp<math::IPowIOp>();
target.addIllegalOp<math::CountLeadingZerosOp>();
if (convertCtlz)
target.addIllegalOp<math::CountLeadingZerosOp>();
target.addDynamicallyLegalOp<math::FPowIOp>(
[this](math::FPowIOp op) { return !isFPowIConvertible(op); });
if (failed(applyPartialConversion(module, target, std::move(patterns))))
Expand Down
3 changes: 3 additions & 0 deletions 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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +85,7 @@ func.func @main(%arg0: i32) {
// CHECK: }
// CHECK: return %[[OUT]] : i8
// CHECK: }
// NOCVT-NOT: __mlir_math_ctlz_i32
func.func @main(%arg0: i8) {
%0 = math.ctlz %arg0 : i8
func.return
Expand Down

0 comments on commit ce47090

Please sign in to comment.