Skip to content
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

[vmvx] Relax requirement on fptosi lowering #11553

Merged
merged 4 commits into from
Dec 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -926,11 +926,13 @@ class FPToSIOpConversion : public OpConversionPattern<arith::FPToSIOp> {
ConversionPatternRewriter &rewriter) const override {
auto srcType = srcOp.getIn().getType();
auto dstType = srcOp.getResult().getType();
auto resultType = getTypeConverter()->convertType(dstType);
if (srcType.isF32()) {
if (dstType.isSignlessInteger(32) || dstType.isSignedInteger(32)) {
auto resultType = getTypeConverter()->convertType(dstType);
rewriter.replaceOpWithNewOp<IREE::VM::CastF32SI32Op>(
srcOp, resultType, adaptor.getOperands()[0]);
// This uses the resultType rather than dstType as any truncation
// required will be handled via interpretation by consumer.
if (resultType.isSignlessInteger(32) || resultType.isSignedInteger(32)) {
rewriter.replaceOpWithNewOp<IREE::VM::CastF32SI32Op>(srcOp, resultType,
adaptor.getIn());
return success();
}
}
Expand All @@ -948,8 +950,8 @@ class FPToUIOpConversion : public OpConversionPattern<arith::FPToUIOp> {
auto resultType = getTypeConverter()->convertType(dstType);
if (srcType.isF32()) {
if (dstType.isSignlessInteger(32) || dstType.isUnsignedInteger(32)) {
rewriter.replaceOpWithNewOp<IREE::VM::CastF32UI32Op>(
srcOp, resultType, adaptor.getOperands()[0]);
rewriter.replaceOpWithNewOp<IREE::VM::CastF32UI32Op>(srcOp, resultType,
adaptor.getIn());
return success();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ module @my_module {
module @t006_fptosi_fp32_i8 {
module @my_module {
func.func @my_fn(%arg0 : f32) -> (i8) {
// expected-error@+1 {{failed to legalize}}
// CHECK: vm.cast.f32.si32 %[[ARG0]] : f32 -> i32
%1 = arith.fptosi %arg0 : f32 to i8
return %1 : i8
Comment on lines +80 to 82
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there other IRs that truncate i32 to i8? If so, should we check it as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

We checked the integer ones yesterday (8a3d270). At least for those individually the result wrt llvm and vmvx was the same.

}
Expand Down