Skip to content

[mlir][math] expand-math pass assumes the static shaped type #128299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions mlir/lib/Dialect/Math/Transforms/ExpandPatterns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ static LogicalResult convertFmaFOp(math::FmaOp op, PatternRewriter &rewriter) {
// if (x > y) then incr = 1 else incr = 0
// y = y + incr <= replace this op with the ceilf op.
static LogicalResult convertCeilOp(math::CeilOp op, PatternRewriter &rewriter) {
// Creating constants assumes the static shaped type.
auto shapedType = dyn_cast<ShapedType>(op.getType());
if (shapedType && !shapedType.hasStaticShape())
return failure();

ImplicitLocOpBuilder b(op->getLoc(), rewriter);
Value operand = op.getOperand();
Type opType = operand.getType();
Expand Down
26 changes: 26 additions & 0 deletions mlir/test/Dialect/Math/expand-math.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,29 @@ func.func @rsqrt_tns(%float: tensor<5x8xf32>) -> (tensor<5x8xf32>) {
%float_result = math.rsqrt %float : tensor<5x8xf32>
return %float_result : tensor<5x8xf32>
}

// -----

// CHECK-LABEL: func.func @non_static_shape_ceil_op
// CHECK-SAME: (%[[ARG:.*]]: tensor<?xf32>)
// CHECK-SAME: -> tensor<?xf32>
// CHECK: %[[CEIL:.*]] = math.ceil %[[ARG]] : tensor<?xf32>
// CHECK: return %[[CEIL]] : tensor<?xf32>

func.func @non_static_shape_ceil_op(%arg: tensor<?xf32>) -> tensor<?xf32>{
%a = math.ceil %arg : tensor<?xf32>
return %a: tensor<?xf32>
}

// -----

// CHECK-LABEL: func.func @unranked_ceil_op
// CHECK-SAME: (%[[ARG:.*]]: tensor<*xf32>)
// CHECK-SAME: -> tensor<*xf32>
// CHECK: %[[CEIL:.*]] = math.ceil %[[ARG]] : tensor<*xf32>
// CHECK: return %[[CEIL]] : tensor<*xf32>

func.func @unranked_ceil_op(%arg: tensor<*xf32>) -> tensor<*xf32>{
%a = math.ceil %arg : tensor<*xf32>
return %a: tensor<*xf32>
}