This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Produce error when encountering unlowerable Wasm global accesses
ClosedPublic

Authored by asb on Aug 8 2022, 3:13 AM.

Details

Summary

WebAssembly globals are represented as IR globals with the wasm_var
address space (AS1). Prior to this patch, a wasm global load that isn't
lowerable will produce a failure to select, while a wasm global store
will produced incorrect code. This patch ensures we consistently produce
a clear error.

As noted in the test cases, it's conceivable that a frontend or an
optimisation pass could produce similar IR even in the presence of the
semantic restrictions on pointers to Wasm globals in the frontend, which
is a separate problem to address.

Diff Detail

Event Timeline

asb created this revision.Aug 8 2022, 3:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 3:13 AM
asb requested review of this revision.Aug 8 2022, 3:13 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2022, 3:13 AM
sbc100 added inline comments.Aug 8 2022, 9:11 AM
llvm/test/CodeGen/WebAssembly/global-set-unlowerable.ll
23

Do these examples need to be this complex? Can you just elide of the branching? Why do we need to to different globals?

asb updated this revision to Diff 450867.Aug 8 2022, 10:34 AM
asb marked an inline comment as done.

Simplify test cases

asb added inline comments.Aug 8 2022, 10:37 AM
llvm/test/CodeGen/WebAssembly/global-set-unlowerable.ll
23

I've simplified from phi to select. The reason for two globals is the test case needs to demonstrate a case where the current ISel code won't match. Loading/storing a single global will work fine.

Arguably we should have coverage for loading/storing a global after getelementptr on it for completeness, but unlike these test cases that code _shouldn't_ occur unless the frontend fails to obey the semantic restrictions.

pmatos accepted this revision.Aug 9 2022, 11:31 PM

LGTM

Indeed the tests for these are not comprehensive and these bugs haven't been found before as this sort of code hasn't been used in anger. I think the error message is fine for now but once the clang work is finished, we should refactor and improve this code.

This revision is now accepted and ready to land.Aug 9 2022, 11:31 PM