Stream: cranelift

Topic: trapping arithmetic


view this post on Zulip Kirp (Apr 25 2024 at 20:02):

Hi, just came across Issue #5908 (https://github.com/bytecodealliance/wasmtime/issues/5908) regarding blockers for optimisations on trapping arithmetic, but couldn’t find any linked stream here: what’s the current status of the plan to include them for opts?

Feature We currently have simplification rules in opts/algebraic.isle to rewrite x/1 to x, and in opts/cprop.isle to constant-fold division when both operands are constant. But these rules can't fi...

view this post on Zulip fitzgen (he/him) (Apr 25 2024 at 21:40):

we will GVN instructions that have idempotent side effects, like trapping, but we don't support rewriting them in ISLE yet

view this post on Zulip Kirp (Apr 25 2024 at 22:19):

What would be needed to allow isle to rewrite them: is it a semantics thing (as in what way should isle be allowed to do the rewrites?) or an implementation thing?

view this post on Zulip fitzgen (he/him) (Apr 25 2024 at 23:27):

some combo of https://github.com/bytecodealliance/wasmtime/issues/6106 and https://github.com/bytecodealliance/wasmtime/issues/5908

Feature We should allow the egraph pass to rewrite instructions which have no result values. This resembles #5908, in that no-result instructions have side effects and that currently prevents us fr...
Feature We currently have simplification rules in opts/algebraic.isle to rewrite x/1 to x, and in opts/cprop.isle to constant-fold division when both operands are constant. But these rules can't fi...

view this post on Zulip fitzgen (he/him) (Apr 25 2024 at 23:28):

I realize this is a bit circular, but I guess the most precise answer to "what's the current status?" is that not too much has changed since those issues were filed

view this post on Zulip Kirp (Apr 29 2024 at 10:16):

What would the conditions need to be to simplify the operations? Looking at the list of idempotent ops, there’s div/rem (where I think it’s sufficient that the denominator is known at comp time), addition that traps on overflow where both operands would need to be known (or at least have some bounds on them) and FcvtToSint / Uint (I presume floating point conversions to integers?) (this is from side_effects_idempotent impl)

view this post on Zulip bjorn3 (Apr 29 2024 at 11:16):

I presume floating point conversions to integers?

Correct: https://docs.rs/cranelift-codegen/latest/cranelift_codegen/ir/trait.InstBuilder.html#method.fcvt_to_uint


Last updated: Dec 23 2024 at 13:07 UTC