This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] Fix p2align in assembler.
ClosedPublic

Authored by aardappel on Jun 20 2019, 4:56 PM.

Details

Summary
  • Match the syntax output by InstPrinter.
  • Fix it always emitting 0 for align. Had to work around fact that opcode is not available for GetDefaultP2Align while parsing.
  • Updated tests that were erroneously happy with a p2align=0

Fixes https://bugs.llvm.org/show_bug.cgi?id=40752

Diff Detail

Repository
rL LLVM

Event Timeline

aardappel created this revision.Jun 20 2019, 4:56 PM

Nice!

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
716 ↗(On Diff #205925)

Does llvm style allow this? clang-format?

Is there some way we can tell if an opcode requires alignment? Calling GetDefaultP2AlignAny and checking for -1 seems bit hacky. Assuming I understand what happing I think this code would be more readable as:

if (requiresAlignment() && !hasAlignment) {
  setImm(getDefaultAlign())
}

clang-format

aardappel marked an inline comment as done.Jun 24 2019, 11:36 AM
aardappel added inline comments.
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
716 ↗(On Diff #205925)

Clang-formatted.
It is mildly-hacky, but I didn't want to duplicate the gigantic switch in GetDefaultP2AlignAny. Right now GetDefaultP2AlignAny is the source of truth for alignment in one place, which is also kinda nice.

Thanks!

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

Can atomic operations take p2align? Looks like alignments for atomic instructions are predefined.

sbc100 added inline comments.Jun 24 2019, 2:53 PM
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
716 ↗(On Diff #205925)

On I didn't see that we have already calculated IsLoadStore.. can we just use that?

aardappel updated this revision to Diff 206324.Jun 24 2019, 4:29 PM
aardappel marked 2 inline comments as done.

Atomics only use default alignment.

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

They are still stored in the encoding, and the tablegen def doesn't seem to make a difference between atomic and normal loads as to wether p2align can be changed, but yeah, the spec seems to indicate they are fixed. I can force atomics to use natural alignment for now.

716 ↗(On Diff #205925)

IsLoadStore is a bit of a hack that I would prefer to remove, rather than rely more on. I'd also have the get the instruction name in MatchAndEmitInstruction and repeat the same parsing there, so I think that will make the code generally worse.

aheejin accepted this revision.Jun 25 2019, 3:53 PM

LGTM, as long as @sbc100 is ok

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

You're right, we don't distinguish it in Tablegen... maybe we should.

This revision is now accepted and ready to land.Jun 25 2019, 3:53 PM
sbc100 accepted this revision.Jun 25 2019, 3:56 PM
aardappel marked an inline comment as done.Jun 27 2019, 10:19 AM
aardappel added inline comments.
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

Well, I presume they're in the encoding because we want to be able to relax the fixed alignment later.. if these instructions alignment is meant to be always fixed, they shouldn't be in the encoding.

This revision was automatically updated to reflect the committed changes.
aheejin added inline comments.Jun 27 2019, 2:02 PM
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

What do you mean by encoding, you mean TableGen? I wrote that and I just copy-pasted that from normal memory instruction :$

aardappel marked an inline comment as done.Jun 27 2019, 2:07 PM
aardappel added inline comments.
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
353 ↗(On Diff #206271)

I mean the actual encoded bytes in the binary format.