This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] SIMD conversions
ClosedPublic

Authored by tlively on Sep 21 2018, 11:57 AM.

Details

Summary

Lowers (s|u)itofp and fpto(s|u)i instructions for vectors. The fp to
int conversions produce poison values if their arguments are out of
the convertible range, so a future CL will have to add an LLVM
intrinsic to make the saturating behavior of this conversion usable.

Diff Detail

Repository
rL LLVM

Event Timeline

tlively created this revision.Sep 21 2018, 11:57 AM

The actual naming of these instructions is blocked on the bikeshedding discussion at https://github.com/WebAssembly/nontrapping-float-to-int-conversions/issues/4. For the time being, the instructions here have been renamed to avoid colons and slashes have been replaced with question marks to satisfy the lexer (lib/MC/MCParser/AsmLexer.cpp).

tlively planned changes to this revision.Sep 21 2018, 1:13 PM

Tests need fixing.

tlively updated this revision to Diff 166541.Sep 21 2018, 1:22 PM
  • Fix tests
aheejin added a comment.EditedSep 24 2018, 5:08 PM
  1. Is it correct to translate those llvm instructions to saturating versions of wasm instructions? For example, for scalars, we had a patch that implemented the saturating behavior. Don't we need a similar thing for vectors too?
  2. Is this behavior also dependent on [[ https://github.com/llvm-mirror/llvm/blob/59895038204bec7cb4f924acf25b91f3056ea492/lib/Target/WebAssembly/WebAssembly.td#L30-L33 | nontrapping-fptoint ]] feature, as the scalar instructions?
aheejin added inline comments.Sep 24 2018, 5:10 PM
lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
388 ↗(On Diff #166541)

It looks like after D52442 we can use the old names?

  1. Is it correct to translate those llvm instructions to saturating versions of wasm instructions? For example, for scalars, we had a patch that implemented the saturating behavior. Don't we need a similar thing for vectors too?

No: the extra lowering code in that patch is needed when using the trapping forms (which is what MVP wasm has). When -mnontrapping-fptoint is specified, the non-trapping forms are used, which don't need extra lowering code. For SIMD the plan is that we'll only have the saturating forms, so it doesn't need the extra lowering code.

  1. Is this behavior also dependent on [[ https://github.com/llvm-mirror/llvm/blob/59895038204bec7cb4f924acf25b91f3056ea492/lib/Target/WebAssembly/WebAssembly.td#L30-L33 | nontrapping-fptoint ]] feature, as the scalar instructions?

No, I don't think we need to do that. We need a flag for scalar because wasm MVP only has the trapping forms, but for SIMD, the plan is to only have the saturating ones, so I think it's safe to assume that if the subtarget has SIMD, it includes those.

@sunfish Oh I see. Thank you!

tlively marked an inline comment as done.Sep 25 2018, 11:11 AM
tlively added inline comments.
lib/Target/WebAssembly/WebAssemblyInstrSIMD.td
388 ↗(On Diff #166541)

Yep! Done in D52512 so we can get things in more incrementally.

aheejin accepted this revision.Sep 25 2018, 12:02 PM
This revision is now accepted and ready to land.Sep 25 2018, 12:02 PM
This revision was automatically updated to reflect the committed changes.
tlively marked an inline comment as done.