This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Don't override default implementation of isOffsetFoldingLegal. NFC.
ClosedPublic

Authored by sbc100 on Nov 16 2018, 4:59 PM.

Details

Summary

The default implementation does what want and is going to more
compatible with dynamic linking / -fPIC support that is planned.

In particular it prevents constant folder of global addresses when
isPositionIndependent() .

This is NFC because currently we only build wasm with
-relocation-model=static which in turn means that
the default isOffsetFoldingLegal always returns true today.

Diff Detail

Repository
rL LLVM

Event Timeline

sbc100 created this revision.Nov 16 2018, 4:59 PM
sbc100 retitled this revision from [WebAssembly] Don't override default implementation of isOffsetFoldingLegal to [WebAssembly] Don't override default implementation of isOffsetFoldingLegal. NFC..Nov 16 2018, 5:00 PM
sbc100 added a reviewer: dschuff.

Not sure I am parsing your commit message right. So we fold if DSO local, and not otherwise?

Yes, this should have no effect unless we are compiling with -fPIC and have non-DSO-local symbols.

sbc100 edited the summary of this revision. (Show Details)Nov 19 2018, 4:34 PM

Not sure I am parsing your commit message right. So we fold if DSO local, and not otherwise?

Actually, even for DSO-local symbols we might not be able to do constant folding since we need to offset all accessed via get_global __memory_base.

Yeah I think for PIC code all globals need to be relative.

If I understand isOffsetFoldingLegal, currently we have i32.load addr($pop) where the addr is a constant and the offset comes from the stack (e.g. could be the result of a gep but is often i32.const 0) and the addr is the folded address of the global.

If there's no individual interposition we could use something like this in cases where it would have been const 0 before:

get_global __memoryBase
i32.load addr($pop)

If there's a constant gep, it should actually be legal to fold that into the address too: i32.load addr+n($pop).
If there's a variable gep, it has to be added to the memory base, but the addr can still be a constant relative to the memory base. Does that mean isOffsetFoldingLegal is true then? Not sure, I'd want to look at the code a bit more and also at e.g. our address-offsets.ll test.

sbc100 updated this revision to Diff 190174.Mar 11 2019, 3:58 PM
sbc100 edited the summary of this revision. (Show Details)
  • rebase
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2019, 3:58 PM
Herald added a subscriber: jdoerfert. · View Herald Transcript
sbc100 updated this revision to Diff 190176.Mar 11 2019, 4:01 PM
  • move to mono-repo

This is needed for my PIC change: https://reviews.llvm.org/D54647

It seems to do exactly what we want. It avoids folding the constant into access of the global address itself, but it still can fold the constant into the follow load. e.g.: from that CL:

global.get $push0=, g@GOT
i32.load  $push1=, 40($pop0)
sbc100 edited the summary of this revision. (Show Details)Mar 15 2019, 7:12 PM
sbc100 edited the summary of this revision. (Show Details)
sbc100 edited the summary of this revision. (Show Details)

@dschuff i updated the PR description and hopefully this a good to go now?

dschuff accepted this revision.Mar 18 2019, 2:17 PM
This revision is now accepted and ready to land.Mar 18 2019, 2:17 PM
This revision was automatically updated to reflect the committed changes.