[PATCH] D88591: [WebAssembly] Emulate v128.const efficiently

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 13:16:32 PDT 2020


efriedma added inline comments.


================
Comment at: llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp:1603
+        auto *Const = cast<ConstantSDNode>(Lane.getNode());
+        uint64_t Val = byte_swap(Const->getLimitedValue(), little);
+        uint8_t *ValPtr = reinterpret_cast<uint8_t *>(&Val);
----------------
I think this byte_swap isn't doing the right thing; it's in the wrong width.

There are a couple of reasonable ways to write this:

1. Construct an `std::array<uint8_t, 16>/std::array<ulittle16_t, 8>/std::array<ulittle32_t, 4>`, and memcpy from it to an `std::array<ulittle64_t, 2>`.
2. Don't type-pun at all; something like:


    for (int i = 0; i < NumElements; ++i)
      Result[i / (NumElements / 2)] |= Elements[i] << ElementWidth * (i  % (NumElements / 2);


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88591/new/

https://reviews.llvm.org/D88591



More information about the llvm-commits mailing list