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

[FXML-4770] TosaToLinalg: fix tosa.cast INT_MAX overflow constant #206

Merged
merged 2 commits into from
Jun 21, 2024

Conversation

cferry-AMD
Copy link
Collaborator

In lowering a tosa.cast op from float to signed int, the float is compared against INT_MAX to check for overflow. The 1 + INT_MAX(width) constant is converted to floating-point, and comparison with it is done in FP.

However, an intermediate int64_t type is used, which overflows and turns 1 + INT_MAX(64) negative when the destination type is i64. This PR uses uint64_t instead (with getZExtValue) so that 1 + INT_MAX stays in bounds and is correctly represented as floating-point.

Copy link
Collaborator

@mgehre-amd mgehre-amd left a comment

Choose a reason for hiding this comment

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

Good find!

@mgehre-amd
Copy link
Collaborator

Please open the same PR to the release branch

Copy link

@TinaAMD TinaAMD left a comment

Choose a reason for hiding this comment

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

LGTM

@cferry-AMD cferry-AMD enabled auto-merge (squash) June 21, 2024 13:27
@cferry-AMD cferry-AMD merged commit 3e76eaa into feature/fused-ops Jun 21, 2024
7 checks passed
@cferry-AMD cferry-AMD deleted the corentin.tosa_cast_linalg_i64 branch June 21, 2024 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants