Skip to content

[MLIR][EmitC] arith-to-emitc: Fix lowering of fptoui #118504

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 1 commit into from
Dec 5, 2024
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
2 changes: 1 addition & 1 deletion mlir/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ class FtoICastOpConversion : public OpConversionPattern<CastOp> {
Type actualResultType = dstType;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be wrong and only real quick at this but do we need the if clause at all if actualResultType is set to dstType here already?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't dstType signless? If I'm not mistaking, this condition is there so that the first cast actually goes to unsigned no matter what the signedness of dstType is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, what @cferry-AMD said is also my understanding.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying.

if (isa<arith::FPToUIOp>(castOp)) {
actualResultType =
rewriter.getIntegerType(operandType.getIntOrFloatBitWidth(),
rewriter.getIntegerType(dstType.getIntOrFloatBitWidth(),
/*isSigned=*/false);
}

Expand Down
4 changes: 4 additions & 0 deletions mlir/test/Conversion/ArithToEmitC/arith-to-emitc.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,10 @@ func.func @arith_float_to_int_cast_ops(%arg0: f32, %arg1: f64) {
// CHECK: emitc.cast %[[CAST0]] : ui32 to i32
%4 = arith.fptoui %arg0 : f32 to i32

// CHECK: %[[CAST0:.*]] = emitc.cast %arg0 : f32 to ui16
// CHECK: emitc.cast %[[CAST0]] : ui16 to i16
%5 = arith.fptoui %arg0 : f32 to i16

return
}

Expand Down
Loading