Skip to content

Check for side effects on descriptor in OptimizeInstructions::skipCast - #9190

Merged
kripken merged 2 commits into
WebAssembly:mainfrom
gkdn:skip-cast-desc
Oct 2, 2026
Merged

kripken merged 2 commits into
WebAssembly:mainfrom
gkdn:skip-cast-desc

Conversation

@gkdn

@gkdn gkdn commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

In traps-never-happen mode, skipCast removes casts whose type does not matter to the parent, which it does for the operands of ref.is_null (with no required type) and ref.eq (requiring eqref). When the cast is a descriptor cast (ref.cast_desc_eq), removing it also removes its descriptor operand, along with any side effects the operand has. For example:

(ref.is_null (ref.cast_desc_eq (ref null $A) (local.get $x) (call $get)))

was optimized to:

(ref.is_null (local.get $x))

dropping the call.

Check that the descriptor operand has no side effects before removing a descriptor cast in skipCast.

Note: we didn't hit this; it is a pass-by fix.

In traps-never-happen mode, skipCast removes casts whose type does not matter to the parent, which it does for the operands of ref.is_null (with no required type) and ref.eq (requiring eqref). When the cast is a descriptor cast (ref.cast_desc_eq), removing it also removes its descriptor operand, along with any side effects the operand has. For example:

  (ref.is_null (ref.cast_desc_eq (ref null $A) (local.get $x) (call $get)))

was optimized to:

  (ref.is_null (local.get $x))

dropping the call.

Skip descriptor casts in skipCast while still removing casts without a descriptor.
@gkdn
gkdn requested a review from a team as a code owner October 1, 2026 21:36
@gkdn
gkdn requested review from aheejin and removed request for a team October 1, 2026 21:36
Comment thread src/passes/OptimizeInstructions.cpp Outdated
Type::isSubType(cast->ref->type, requiredType)) {
// Removing a descriptor cast would also remove the descriptor operand,
// along with its side effects.
if (!cast->desc && (requiredType == Type::none ||

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.

How about checking if the descriptor has side effects? We can optimize if it doesn't, which is the common case.

@gkdn gkdn changed the title Do not remove descriptor casts in OptimizeInstructions::skipCast Check for side effects on descriptor in OptimizeInstructions::skipCast Oct 2, 2026
@kripken
kripken merged commit 9287962 into WebAssembly:main Oct 2, 2026
16 checks passed
@gkdn
gkdn deleted the skip-cast-desc branch October 2, 2026 22:54
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.

2 participants