[PATCH] D120000: [1/2] TLS loads opimization (hoist)

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 3 16:04:54 PST 2022


efriedma added a comment.

In D120000#3357639 <https://reviews.llvm.org/D120000#3357639>, @nlopes wrote:

> In D120000#3357413 <https://reviews.llvm.org/D120000#3357413>, @craig.topper wrote:
>
>>> Anyway, this transformation works by creating some artificial bitcasts that you expect to be carried over to the backend so the lowering can share the calls to the TLS function.
>>>
>>> This strategy seems very brittle to me. If some later optimization decides to remove the bitcast, your optimization will stop working. It's very likely that will be the case once opaque pointers take over.
>>
>> Is this much different than the artificial bitcast we use in ConstantHoisting?
>
> Didn't know there was a precedent of using this technique. Seems fragile to me, but...

This is running late enough in the pipeline that it's probably fine.  Optimization passes that are part of of the codegen pipeline, like ConstantHoisting/CodeGenPrepare/etc. have an implicit contract with each other and SelectionDAG to make this sort of thing work.

Really, this transform should handled by some sort of general LICM, but we can't use IR LICM because the operations aren't visible in IR, and we can't use MachineLICM because we can't really hoist calls after isel.  (Making MachineLICM handle this isn't impossible, but it gets messy because you're dealing with target-specific call sequences.)

More generally, the current representation of constants in IR isn't ideal, but improving constant expressions isn't really anyone's priority at the moment.  Maybe someone will look at it once the opaque pointers are done.

--------------------

Would it make sense to do this transform as part of ConstantHoisting, instead of as a separate transform?  Most of the necessary infrastructure is already there.

I don't understand why you'd want a clang flag to control this. The backend knows when it's going to generate a call to get the tls pointer.  And when we generate a call, hoisting that call is pretty obviously profitable.


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

https://reviews.llvm.org/D120000



More information about the llvm-commits mailing list