This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Fix alignment for arguments of function pointer calls
ClosedPublic

Authored by asavonic on Oct 11 2022, 1:20 PM.

Details

Summary

Alignment of function arguments can be increased only if we can do
this for all call sites. Therefore we do not increase it for external
functions, and now we skip functions that have address taken, to avoid
any issues with functions pointers.

Diff Detail

Event Timeline

asavonic created this revision.Oct 11 2022, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 1:20 PM
asavonic requested review of this revision.Oct 11 2022, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 11 2022, 1:20 PM

Without the patch, @callee has alignment of 16, while the call site uses alignment of 4 for param memory.
We also need D134548 to fix handling of bitcasts.

tra accepted this revision.Oct 11 2022, 1:55 PM

LGTM.

This revision is now accepted and ready to land.Oct 11 2022, 1:55 PM
ldrumm added subscribers: asavonic, kovdan01, tra.EditedOct 12 2022, 3:45 AM
> Index: llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
> ===================================================================
> --- llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
> +++ llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
> @@ -4326,8 +4326,13 @@
> const uint64_t ABITypeAlign = DL.getABITypeAlign(ArgTy).value();
>  
> // If a function has linkage different from internal or private, we
> - // must use default ABI alignment as external users rely on it.
> - if (!(F && F->hasLocalLinkage()))
> + // must use default ABI alignment as external users rely on it. Same
> + // for a function that may be called from a function pointer.
> + if (!F || !F->hasLocalLinkage()) ||
> + F->hasAddressTaken(/*Users=*/nullptr,
> + /*IgnoreCallbackUses=*/false,
> + /*IgnoreAssumeLikeCalls=*/true,
> + /*IngoreLLVMUsed=*/true))
> return Align(ABITypeAlign);
>  
> assert(!isKernelFunction(*F) && "Expect kernels to have non-local
> linkage");

s/IngoreLLVMUsed/IgnoreLLVMUsed/g
otherwise LGTM

ldrumm accepted this revision.Oct 12 2022, 6:27 AM
ldrumm requested changes to this revision.Oct 13 2022, 10:52 AM
ldrumm added inline comments.
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
4345

There's actually a syntax error here.

This revision now requires changes to proceed.Oct 13 2022, 10:52 AM
asavonic updated this revision to Diff 467713.Oct 14 2022, 1:39 AM
  • Fixed typos
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
4345

Right, I planned to fix this before landing, along with the typo below.

ldrumm accepted this revision.Oct 14 2022, 3:45 AM

Thanks. LGTM

This revision is now accepted and ready to land.Oct 14 2022, 3:45 AM