This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Put __stack_pointer in the offset field of loads and stores?
ClosedPublic

Authored by sunfish on May 18 2016, 9:30 PM.

Details

Summary

Currently prologue/epilogue code accesses __stack_pointer like this:

i32.const       $push10=, __stack_pointer
i32.load        $push11=, 0($pop10)

The patch here changes it to this:

i32.const       $push10=, 0
i32.load        $push11=, __stack_pointer($pop10)

It's not obvious which way is better though. Currently regular load isel prefers the second form in general, though that's arbitrary too. Thoughts?

Diff Detail

Repository
rL LLVM

Event Timeline

sunfish updated this revision to Diff 57732.May 18 2016, 9:30 PM
sunfish retitled this revision from to [WebAssembly] Put __stack_pointer in the offset field of loads and stores?.
sunfish updated this object.
sunfish set the repository for this revision to rL LLVM.
sunfish added a subscriber: dschuff.

Would the latter have smaller encoding if we have an opcode table that includes i32.const 0? I suppose i32.const __stack_pointer would also end up in the opcode table, but since 0 would likely still be in there anyway, we'd save one slot. I'll ask Ben when he comes in if V8 would have any appreciable codegen difference either way.

(I guess that assumes the "advanced" opcode table which encodes whole instructions not just opcodes)

Ben says he thought the second form would be more efficient, at least when bounds checking is used. Also I think having the prolog/epilog code match the general isel code is probably better anyway (and if we want to change it, change both), so that if engines implement optimizations based on common patterns, they will get everything at once with just one pattern. So maybe we should just land this.

This revision was automatically updated to reflect the committed changes.