Skip to content

OptimizeInstructions: Do not remove abs of x * x or x / x without --fast-math - #9225

Merged
stevenfontanella merged 3 commits into
WebAssembly:mainfrom
tamaroning:fix-abs-mul-div-nan
Oct 20, 2026
Merged

stevenfontanella merged 3 commits into
WebAssembly:mainfrom
tamaroning:fix-abs-mul-div-nan

Conversation

@tamaroning

Copy link
Copy Markdown
Contributor

Fix #9179

@tamaroning
tamaroning requested a review from a team as a code owner October 7, 2026 16:20
@tamaroning
tamaroning requested review from stevenfontanella and removed request for a team October 7, 2026 16:20

@stevenfontanella stevenfontanella 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.

LGTM besides one nit

;; RUN: foreach %s %t wasm-opt --generate-global-effects --optimize-instructions --fast-math -all -S -o - \
;; RUN: | filecheck %s

;; A test here uses abs(x * x) ==> x * x, which requires fast-math.

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.

nit: since only one test makes use of the fast-math assumption, can we change that test to instead do a different optimization that doesn't need it and remove fast-math from this test?

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.

Thanks. Fixed!

(call $potent)
(call $potent)
)
(ref.eq

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.

nit: can the callee just return an i32, and we use i32.eq here? That seems a little simpler and seems like it would also be optimized by OptimizeInstructions.

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 for the delay. Done, thanks!

@stevenfontanella
stevenfontanella merged commit b8d8b29 into WebAssembly:main Oct 20, 2026
16 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.

OptimizeInstructions: abs(x*x) ==> x*x (and abs(x/x)) changes the NaN sign bit

2 participants