[PATCH] D111154: [WebAssembly] Implementation of table.get/set for reftypes in LLVM IR
Thomas Lively via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 8 12:13:12 PDT 2021
tlively added inline comments.
================
Comment at: llvm/test/CodeGen/WebAssembly/externref-tableget.ll:8
+
+define %externref @get_externref_from_table(i32 %i) {
+ %p = getelementptr [0 x %externref], [0 x %externref] addrspace (1)* @externref_table, i32 0, i32 %i
----------------
pmatos wrote:
> tlively wrote:
> > It would be good to add tests with different access patterns as well like constant indices, base + offset indices, etc.
> This is a good point and I am looking at this at the moment. Adding a few tests, reveals a couple of issues with hardcoding how a table shows up in the DAG. For example, an access with an offset reveals that the DAG is way more complicated than it needs to be. For example, for:
>
> ```
> define %externref @get_externref_from_table_with_offset(i32 %i) {
> %off = add nsw i32 %i, 2
> %p = getelementptr [0 x %externref], [0 x %externref] addrspace (1)* @externref_table, i32 0, i32 %off
> %ref = load %externref, %externref addrspace(1)* %p
> ret %externref %ref
> }
> ```
>
> So, an access with a 2 offset from the argument index causes this dag to be generated for the access:
>
> ```
> t2: i32 = WebAssemblyISD::ARGUMENT TargetConstant:i32<0>
> t12: i32 = shl t2, Constant:i32<2>
> t15: i32 = add t12, GlobalAddress:i32<[0 x %extern addrspace(10)*] addrspace(1)* @externref_table> 0
> t16: i32 = add t15, Constant:i32<8>
> t10: externref,ch = load<(load (s0) from %ir.p, addrspace 1)> t0, t16, undef:i32
> ```
>
> Which looks like: `(add (add (shl arg 2) table) 8)`.
> I need to transform this back into a table load from `(add arg 2)` which seems suboptimal. I am trying to understand if it's possible to tell LLVM not to generate these address offsets for these types of accesses. It certainly seems cleaner than to reverse the computation to find the correct index to access.
I wonder if there is a way to tell LLVM that the width of an element in the table is just 1. That looks like it would simplify this a lot, if not completely.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D111154/new/
https://reviews.llvm.org/D111154
More information about the llvm-commits
mailing list