This is an archive of the discontinued LLVM Phabricator instance.

[NVPTX] Remove code duplication in LowerCall
ClosedPublic

Authored by kovdan01 on Mar 24 2022, 4:17 AM.

Details

Summary

In D120129 we enhanced vectorization options of byval parameters. This patch
removes code duplication when handling byval and non-byval cases.

Diff Detail

Unit TestsFailed

Event Timeline

kovdan01 created this revision.Mar 24 2022, 4:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2022, 4:17 AM
kovdan01 requested review of this revision.Mar 24 2022, 4:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2022, 4:17 AM
tra accepted this revision.Mar 24 2022, 10:57 AM

Nice. LGTM with few style nits.

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
1476

alway->always

1477

"whether it's naturally aligned or not."

1479–1490

This all could be folded:

ArgAlign = std::max(
   std::max(Outs[OIdx].Flags.getNonZeroByValAlign(), 
                   getFunctionParamOptimizedAlign(CB->getCalledFunction(), ETy, DL)),
   4
);

It could be further extended to incorporate the if (IsByVal) -> IsByVal ? ....

I think calculating ArgAlign in one place is a bit easier to follow than a series of conditional adjustments.

This revision is now accepted and ready to land.Mar 24 2022, 10:57 AM
kovdan01 updated this revision to Diff 418163.Mar 25 2022, 2:34 AM
kovdan01 added inline comments.
llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
1479–1490

Creating a one-liner here does not look very good as for me - after clang-format we get the following code:

Align ArgAlign =
        IsByVal
            ? std::max(std::max(
                           // The ByValAlign in the Outs[OIdx].Flags is always
                           // set at this point, so we don't need to worry
                           // whether it's naturally aligned or not. See
                           // TargetLowering::LowerCallTo().
                           Outs[OIdx].Flags.getNonZeroByValAlign(),
                           // Try to increase alignment to enhance vectorization
                           // options.
                           getFunctionParamOptimizedAlign(
                               CB->getCalledFunction(), ETy, DL)),
                       // Enforce minumum alignment of 4 to work around ptxas
                       // miscompile for sm_50+. See corresponding alignment
                       // adjustment in emitFunctionParamList() for details.
                       Align(4))
            : getArgumentAlignment(Callee, CB, Ty, ParamCount + 1, DL);

I just removed some intermediate variables and used temporary values instead. Looks clear enough IMHO, and there is no problem in reading code like

// ...
ArgAlign = ...;
// ...
ArgAlign = std::max(ArgAlign, ...);
// ...
ArgAlign = std::max(ArgAlign, ...);
kovdan01 marked 3 inline comments as done.Mar 25 2022, 2:35 AM
This revision was landed with ongoing or failed builds.Mar 25 2022, 2:43 AM
This revision was automatically updated to reflect the committed changes.