[PATCH] D104801: [MemCpyOpt] Enable memcpy optimization for NVPTX back-end.

Artem Belevich via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 28 09:45:49 PDT 2021


tra added a comment.

In D104801#2843821 <https://reviews.llvm.org/D104801#2843821>, @fhahn wrote:

> Perhaps an alternative to the TLI check would be to provide a generic lowering for `llvm.memcpy` intrinsics when lib calls are not available?  (One thing to note is that I think both Clang and GCC require memcpy and a few others to be available, even in freestanding environments)

I'm not ready to bite that much.

I wonder if we could use existing int_memcpy_inline in cases where libcals are not available. It's supposed to  guarantee that it does not call external functions.
https://github.com/llvm/llvm-project/blob/44826ecd929bdd33b3c86650198a5f8a57965cc7/llvm/include/llvm/IR/Intrinsics.td#L616

>>> I'm not sure about having a dedicated TTI hook to specifically enable/disable the pass.
>>
>> IMO TTI is the standard mechanism to make target-specific information available to otherwise generic passes. There are ~50 passes under lib/Transforms that utilize it.
>
> Yes, but at the moment, I don't think there's much precedence for backends specifically disabling certain passes.  This could get messy very quickly, e.g. even if we add only hooks for some of the available passes. Those hooks are also not composable. IMO it would be preferable to model this in a way so other passes that may want to introduce `llvm.memcpy` calls also benefit.

In this case the knob only *allows* using the pass in wider range of cases. Passes that don't want or don't need it are not affected.
In a way enabling/disabling libcalls already acts as such external enable/disable knob already. So do the various other existing knobs provided by TTI, if you squint just right. E.g. setting inlining threshold very low would effectively disable inlining pass. I don't think this pass introduces anything conceptually new.

> Generalizing the hook to whether the intrinsics can be lowered without lib calls seems a step in the right direction to me and this could be helpful for other passes as well (as you suggested in a later comment). If backends could easily lower any `llvm.memcpy` call without needing to fall back to library calls, that would also be compelling.

OK. Let me try to see if I can make MemCpyOpt pass fall back to inline version of memcpy intrinsic if libcalls are not available.

If that does not pan out, plan B would be to provide  a generic TTI knob (e.g. `optional<bool> canLowerIntrinsic()`) and then change MemOptPass to use that, instead of checking libcalls.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D104801



More information about the llvm-commits mailing list