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

Cranelift: implement general select_spectre_guard fallbacks. #5420

Merged
merged 1 commit into from
Dec 13, 2022

Conversation

cfallin
Copy link
Member

@cfallin cfallin commented Dec 12, 2022

When adding some optimization rules for icmp in the egraph infrastructure, we ended up creating a path to legal CLIF but with patterns unsupported by three of our four backends: specifically, select_spectre_guard with a general truthy input, rather than an icmp.

In #5206 we discussed replacing select_spectre_guard with something more specific, and that could still be a long-term solution here, but doing so now would interfere with ongoing refactoring of heap access lowering, so I've opted not to do so. (In that issue I was concerned about complexity and didn't see the need but with this fuzzbug I'm starting to feel a bit differently; maybe we should remove this non-orthogonal op in the long run.)

Fixes #5417.

When adding some optimization rules for `icmp` in the egraph
infrastructure, we ended up creating a path to legal CLIF but with
patterns unsupported by three of our four backends: specifically,
`select_spectre_guard` with a general truthy input, rather than an
`icmp`.

In bytecodealliance#5206 we discussed replacing `select_spectre_guard` with something
more specific, and that could still be a long-term solution here, but
doing so now would interfere with ongoing refactoring of heap access
lowering, so I've opted not to do so. (In that issue I was concerned
about complexity and didn't see the need but with this fuzzbug I'm
starting to feel a bit differently; maybe we should remove this
non-orthogonal op in the long run.)

Fixes bytecodealliance#5417.
@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:area:aarch64 Issues related to AArch64 backend. cranelift:area:x64 Issues related to x64 codegen labels Dec 12, 2022
Copy link
Contributor

@jameysharp jameysharp left a comment

Choose a reason for hiding this comment

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

I'm glad to see select_spectre_guard implemented for the general case. I think what I'm seeing here is that you're choosing the most general, but not necessarily most efficient, implementation of select from each backend and copying that as the fallback for this instruction? That makes sense to me, at least for now. But I don't feel comfortable reviewing the actual implementations.

Maybe what we should learn from this particular fuzz-bug is that if we have any combination of CLIF instructions that we can't lower, we will eventually generate that combination, probably by accident. Given that, perhaps we should adopt the principle/goal that all combinations of CLIF which pass the validator should be implemented in any tier 1 backend? Whenever we fail that, it means we need to either change the instruction set, change the validator, or change the backend.

@cfallin
Copy link
Member Author

cfallin commented Dec 12, 2022

Yes, exactly, I took the fallback rules for select and duplicated them for x86-64, aarch64, and riscv64 (s390x already supported the general case).

perhaps we should adopt the principle/goal that all combinations of CLIF which pass the validator should be implemented in any tier 1 backend? Whenever we fail that, it means we need to either change the instruction set, change the validator, or change the backend.

That sounds like a reasonable principle to me!

@cfallin
Copy link
Member Author

cfallin commented Dec 13, 2022

@fitzgen or @elliottt, would either of you be willing to review this?

@fitzgen
Copy link
Member

fitzgen commented Dec 13, 2022

Ah I thought that Jamey already reviewed it so I didn't leave a comment. Unclear to me whether Jamey wants changes on this PR after their review or not?

@cfallin
Copy link
Member Author

cfallin commented Dec 13, 2022

I interpreted @jameysharp 's reply as: no changes needed, approach is fine, but:

That makes sense to me, at least for now. But I don't feel comfortable reviewing the actual implementations.

FWIW, the implementations are identical to the existing select cases in each backend, so hopefully these aren't too hard to review!

Copy link
Member

@elliottt elliottt left a comment

Choose a reason for hiding this comment

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

Looks good to me, thank you for adding this general case!

@cfallin cfallin merged commit 9397ea1 into bytecodealliance:main Dec 13, 2022
@cfallin cfallin deleted the issue-5417 branch December 13, 2022 01:13
cfallin added a commit that referenced this pull request Jan 19, 2023
This PR follows up on #5382 and #5391, which rebuilt the egraph-based optimization framework to be more performant, by enabling it by default.

Based on performance results in #5382 (my measurements on SpiderMonkey and bjorn3's independent confirmation with cg_clif), it seems that this is reasonable to enable. Now that we have been fuzzing compiler configurations with egraph opts (#5388) for 6 weeks, having fixed a few fuzzbugs that came up (#5409, #5420, #5438) and subsequently received no further reports from OSS-Fuzz, I believe it is stable enough to rely on.

This PR enables `use_egraphs`, and also normalizes its meaning: previously it forced optimization (it basically meant "turn on the egraph optimization machinery"), now it runs egraph opts if the opt level indicates (it means "use egraphs to optimize if we are going to optimize"). The conditionals in the top-level pass driver are a little subtle, but will get simpler once we can remove the non-egraph path (which we plan to do eventually!).

Fixes #5181.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:area:aarch64 Issues related to AArch64 backend. 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.

Unreachable ISLE assertion error on x86_64
4 participants