<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/138861>138861</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [WebAssembly] __table_base should not be optimized into locals (wasm locals or stack locals)
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mf-RDP
      </td>
    </tr>
</table>

<pre>
    __table_base is currently defined as a non mutable global. However, think of a specific implementation that works with BOTH native and wasm (integer) function pointers - just as an example.

For global_get & global_set, their implementations could do complex modifications of the returned value (mimicked __table_base) in conjunction with call_indirect.

This works well, I did actually implement such a thing.

However, it gets broken by the following compiler optimization:
global_get(__table_base)
local_tee(42) <<<<---
i32_add(142)
call_indirect()
local_get(42)
i32_add(143)
call_indirect()

I think, as __table_base can be a highly sophisticated, implementation specific thing, it would be good not to intern it into locals.

the code above should best look like this
global_get(__table_base)
i32_add(142)
call_indirect()
global_get(__table_base) <<<<---
i32_add(143)
call_indirect()

I would say that introduced overhead is none, or absolutely minimal.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMlEGP4jgThn-NuZRAaYdAOOTATAvNnL5Pq5H2iBy7klTjuJDtwLC_fmUTpuk5TK-EhBy7yu_7VLlUCNQ7xEZUX0T1ulBTHNg3Y7f86_X_i5bNrTkeo2otHlsVECiAnrxHF-0NDHbk0IAKoMCxg3HKR6G33Cq7gm98xQt6Ib9CHMidgDtQEM6oqSMNNJ4tjuiiisQO4qAiXNmfAlwpDvDlfz--gVORLgjKGbiqMIKQNbmIfcq6g25yOseeOX31AZbwNoWYJTnAnypdsRLFXhT7A_tZ2bHHCEJuHsuA8a4Ryf-mKoDmyRowDJrTzk8Y2ST58zZ3KQ48xsknGBdlJ0wyRxpJn9DAM8Akmhxodm8P6dmrVtYeyRnyqOOs98dA4cEDrU0Kv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