Skip to content

cranelift: lower i128 umin/umax/smin/smax on x86_64 - #14374

Merged
fitzgen merged 2 commits into
bytecodealliance:mainfrom
agourakis82:users/agourakis/cranelift-x64-umin-i128
Sep 25, 2026
Merged

fitzgen merged 2 commits into
bytecodealliance:mainfrom
agourakis82:users/agourakis/cranelift-x64-umin-i128

Conversation

@agourakis82

@agourakis82 agourakis82 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Mid-end select→minmax can produce umin/umax/smin/smax on i128. x64 only lowered those for fits_in_64, so optimized code hit an unsupported-ISLE trap (#13790).

Adds i128 lowerings through the existing emit_cmp + lower_select path.

Tests:

  • isa/x64/iminmax-i128.clif
  • runtests/issue-13790-umin-i128.clif
  • runtests/i128-min-max.clif now includes x86_64

Fixes #13790

Assisted-by: Claude

The mid-end rewrites `select(icmp ugt/ult/..., a, b)` into integer min/max.
On x86_64 those forms were only lowered for `fits_in_64`, so optimized i128
code hit an unsupported-ISLE trap (bytecodealliance#13790).

Lower i128 min/max through the existing i128 `emit_cmp` + `lower_select`
path, matching AArch64's scalar-int approach, and extend the i128 min/max
runtest to x86_64.

Assisted-by: Claude
@agourakis82
agourakis82 requested a review from a team as a code owner September 22, 2026 02:39
@agourakis82
agourakis82 requested review from fitzgen and removed request for a team September 22, 2026 02:39
@github-actions github-actions Bot added cranelift Issues related to the Cranelift code generator cranelift:area:x64 Issues related to x64 codegen labels Sep 22, 2026
@agourakis82

agourakis82 commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Independent of #14323.

x64 didn’t lower i128 umin/umax/smin/smax; mid-end select→minmax can produce them. Patch adds those lowerings via the existing i128 cmp/select path.

@agourakis82

Copy link
Copy Markdown
Contributor Author

@fitzgen gentle bump — this one’s unrelated to the region discussion on #14323. Happy to tweak if you’d rather expand mid-end-side instead of adding the i128 lowerings.

@alexcrichton

Copy link
Copy Markdown
Member

@agourakis82 please turn down the frequency to which you post and comment on things. It's been 13 hours since this PR was posted and for most of that we were asleep. This is an open source project and we can't respond to PRs immediately, so we ask for patience on your end while time is found to review things.

@agourakis82

Copy link
Copy Markdown
Contributor Author

Sorry about the noise — I’ll leave it alone and wait for review.

Comment on lines +1802 to +1805
;; `i128`: mid-end select→min/max rewrites can produce these (#13790). Lower via
;; the existing i128 compare + select path, matching AArch64's scalar-int
;; approach rather than leaving an unsupported ISLE hole.
;; Priority above the vector catch-alls so the overlap checker accepts both.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
;; `i128`: mid-end select→min/max rewrites can produce these (#13790). Lower via
;; the existing i128 compare + select path, matching AArch64's scalar-int
;; approach rather than leaving an unsupported ISLE hole.
;; Priority above the vector catch-alls so the overlap checker accepts both.

This comment is not really useful for code readers. The first part is a historical tidbit that is ultimately incidental, and the second is obvious for ISLE code.

@@ -0,0 +1,42 @@
test compile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's make this test compile precise-output and re-bless. As currently written this is doing nothing other than ensuring that the programs compile successfully. It is not actually checking that the relevant lowerings or rewrites happen and are reflected in the output.

Comment on lines +5 to +7
target x86_64

;; Mid-end select(ugt)->umin must remain lowerable on x64 (#13790).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you enable all runtest ISAs for this, since the test is not x86-64 specific? And maybe test it for a handful of different inputs (as function parameters) instead of hard-coding constants in the function body.

Also this comment is not really useful. It needs to be lowerable everywhere, not just x64, where there happened to be a bug. Please do a better job of cleaning up LLM comments, here and elsewhere, and now and in the future. Making maintainers do that for you is not a good use of maintainer time.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry...doing my best!

Drop incidental comments, bless precise-output for the x64 compile test,
and broaden the runtest across ISAs with parameterized inputs.

Assisted-by: Claude
@agourakis82

Copy link
Copy Markdown
Contributor Author

Addressed the review notes: removed the incidental comments, blessed precise-output on the x64 compile test, and broadened the runtest to the other ISAs with parameterized inputs.

@fitzgen fitzgen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@fitzgen
fitzgen added this pull request to the merge queue Sep 25, 2026
Merged via the queue into bytecodealliance:main with commit cf0673f Sep 25, 2026
81 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift:area:x64 Issues related to x64 codegen cranelift Issues related to the Cranelift code generator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cranelift: Optimization results in IR unsupported by x86_64 backend

3 participants