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

miss-optimization for continuous add #6831

Open
HerrCai0907 opened this issue Aug 10, 2024 · 2 comments
Open

miss-optimization for continuous add #6831

HerrCai0907 opened this issue Aug 10, 2024 · 2 comments

Comments

@HerrCai0907
Copy link
Contributor

These assemblyscript code

 (func $assembly/index/_start (result i32)
  global.get $assembly/index/a0
  global.get $assembly/index/a1
  i32.add
  global.get $assembly/index/a2
  i32.add
  global.get $assembly/index/a3
  i32.add
  global.get $assembly/index/a4
  i32.add
  global.get $assembly/index/a5
  i32.add
  global.get $assembly/index/a6
  i32.add
  return
 )

will be optimized to

 (func $assembly/index/_start (result i32)
  global.get $assembly/index/a6
  global.get $assembly/index/a5
  global.get $assembly/index/a4
  global.get $assembly/index/a3
  global.get $assembly/index/a2
  global.get $assembly/index/a0
  global.get $assembly/index/a1
  i32.add
  i32.add
  i32.add
  i32.add
  i32.add
  i32.add
 )

Is there any benefit to exchange the operand of i32.add. the optimized version looks like cause higher register pressure for JIT / AOT wasm runtime.

@HerrCai0907 HerrCai0907 changed the title miss-optimization for miss-optimization for continuous addition Aug 10, 2024
@HerrCai0907 HerrCai0907 changed the title miss-optimization for continuous addition miss-optimization for continuous add Aug 10, 2024
@kripken
Copy link
Member

kripken commented Aug 12, 2024

See a related previous discussion here:

#5088 (comment)

Over there, we did not get a clear answer from VM people that one or the other order was better, so we did not change anything. But it may be worth revisiting this. If we have benchmarks that show another order is better, we can flip it.

@tlively
Copy link
Member

tlively commented Aug 13, 2024

See also llvm/llvm-project#98631 and llvm/llvm-project#97283 for discussions of a case where preferring a shallower stack has significant performance benefits.

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

No branches or pull requests

3 participants