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

ISLE: aarch64: fix narrow sdiv on intmin/-1 #9541

Merged
merged 2 commits into from
Nov 1, 2024

Conversation

avanhatt
Copy link
Member

@avanhatt avanhatt commented Nov 1, 2024

Fixes #9537

Clif's semantics (inherited from Wasm) specify are that divides should trap on intmin/-1. The manual check for intmin in this case in ISLE is to add 1 to the dividend and check for overflow, however, the rule was not previously catching that an 8- or 16-bit intmin - 1 does not overflow with a 32-bit ARM instruction. This PR adds a left-shift of the dividend before feeding into the intmin check, such that e.g. 0x00000080 is checked as 0x80000000. A ported version of this has been verified as correct by our prototype.

Note this adds 1 additional instruction (lsl) in the 8- and 16-bit cases of sdiv. An alternative would be to check against hard-coded constants for those cases, but we think this would require adding a new conditional compare to the aarch64 assembler.

This PR also adds a file test for the new instruction sequence.

…e checking for intmin

Co-authored-by: Michael McLoughlin <[email protected]>
@avanhatt avanhatt requested a review from a team as a code owner November 1, 2024 16:54
@avanhatt avanhatt requested review from cfallin and removed request for a team November 1, 2024 16:54
;; instructions.
(decl diff_from_32 (Type) u8)
(rule (diff_from_32 $I8) 24)
(rule (diff_from_32 $I16) 16)
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this because this same pattern is used enough that a helper seems warranted (cls, clz, bitrev) but saving changing those for another PR.

@@ -3664,24 +3670,18 @@

;; Check for signed overflow. The only case is min_value / -1.
;; The following checks must be done in 32-bit or 64-bit, depending
;; on the input type.
(spec (trap_if_div_overflow ty x y)
Copy link
Member Author

Choose a reason for hiding this comment

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

This spec is now stale, but the changes needed to verify the code correctly are ones we still need to upstream. Just removing for now?

Copy link
Member

Choose a reason for hiding this comment

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

Sure -- no problem to re-add this when the rest is upstreamed.

Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

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

Looks great, thanks!

@@ -3664,24 +3670,18 @@

;; Check for signed overflow. The only case is min_value / -1.
;; The following checks must be done in 32-bit or 64-bit, depending
;; on the input type.
(spec (trap_if_div_overflow ty x y)
Copy link
Member

Choose a reason for hiding this comment

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

Sure -- no problem to re-add this when the rest is upstreamed.

@cfallin cfallin added this pull request to the merge queue Nov 1, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 1, 2024
* Fix a missing trap on narrow sdiv of intmin/-1 by left-shifting before checking for intmin

Co-authored-by: Michael McLoughlin <[email protected]>

* Remove non-upstreamed verifier attributes

---------

Co-authored-by: Michael McLoughlin <[email protected]>
Merged via the queue into bytecodealliance:main with commit 196a0d2 Nov 1, 2024
40 checks passed
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.

Cranelift: incorrect narrow sdiv lowering on AArch64
2 participants