This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Use new version of SelectionDAG::getLoad in NVPTX LowerFormalArguments
ClosedPublic

Authored by gchatelet on Jan 16 2023, 2:00 AM.

Details

Summary

I've stumbled upon this code while trying to remove the following deprecated function

inline SDValue SelectionDAG::getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr,
          MachinePointerInfo PtrInfo, unsigned Alignment,
          MachineMemOperand::Flags MMOFlags = MachineMemOperand::MONone,
          const AAMDNodes &AAInfo = AAMDNodes(),
          const MDNode *Ranges = nullptr);

I don't know if the current behavior is expected or not so the fix may change.

Diff Detail

Event Timeline

gchatelet created this revision.Jan 16 2023, 2:00 AM
gchatelet requested review of this revision.Jan 16 2023, 2:00 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 16 2023, 2:00 AM

In particular it seems dubious to use a boolean type to convey alignment. Was this intended ?
I tracked it up to https://reviews.llvm.org/D30011 so I've added @tra and @jlebar as potential reviewers, let me know if someone is a better fit for this review.

tra added a comment.Jan 18 2023, 3:54 PM

let me know if someone is a better fit for this review.

You've reached the right audience. :-)

I don't know if the current behavior is expected or not so the fix may change.

The original code looks OK to me. If the aggregate is packed, we request alignment of 1. If the bool aggregateIsPacked is true, it will undergo implicit integer conversion to 1, otherwise, we don't specify the alignment (0). AFAICT it should work exactly the same way before and after your patch and call exactly the same overload with exactly the same values. It's possible I'm missing something, but I do not see it at the moment.

It would help if you could provide more details about the problem you're trying to solve. A simple reproduced on godbolt.org would be very helpful.

Can you add a test that would demonstrate the issue with the current code and how the results would look like after the fix?

As things stand, I can't say I understand what exactly is the problem you want to fix, nor how the patch changes anything.

Thx for the response!
As of this revision the patch is absolutely useless, you're right. I wanted to be sure of the intended semantic before switching this call to the new getLoad function.

AFAIR there is a risk for a bool value to be true but hold a value that is not 1. Also it felt suspicious to pass a bool in lieu of an unsigned so I just wanted to be absolutely sure it was not a mistake.

I'll upload the real patch shortly.

gchatelet updated this revision to Diff 490401.Jan 19 2023, 1:05 AM
  • Transition to new API
gchatelet retitled this revision from Invalid alignment specification For NVPTX LowerFormalArguments to [NFC] Use new version of SelectionDAG::getLoad in NVPTX LowerFormalArguments.Jan 19 2023, 1:13 AM

I renamed the patch so it better matches the intent.

tra added a comment.Jan 19 2023, 3:01 PM

AFAIR there is a risk for a bool value to be true but hold a value that is not 1.

I do not think so. Integer promotion rules guarantee that 'true' converts to 1.

> §4.7/4 from the C++ 11 or 14 Standard, §7.8/4 from the C++ 17 Standard, §7.3.9/2 from the 20 Standard says (Integral Conversion)
> If the source type is bool, the value false is converted to zero and the value true is converted to one.

Also it felt suspicious to pass a bool in lieu of an unsigned so I just wanted to be absolutely sure it was not a mistake.

The last revision of the patch just explicitly does what the DAG.getLoad() oveload we've picked before did under the hood. We've intentionally provided an overload which acceps unsigned value for alignment. I do not see much of a point Creating Align() manually. For what it's worth your first patch variant was more readable.
Your diff still makes no functional changes.

Please do provide a test case illustrating that there's a problem that needs fixing.

The last revision of the patch just explicitly does what the DAG.getLoad() oveload we've picked before did under the hood. We've intentionally provided an overload which acceps unsigned value for alignment. I do not see much of a point Creating Align() manually. For what it's worth your first patch variant was more readable.
Your diff still makes no functional changes.

This patch is indeed NFC (as the updated title suggests). There is no problem to fix apart reducing the number of places where we use integer types to convey alignment (or lack thereof).
The Align and MaybeAligntypes convey the intent better (I originally thought that the bool promotion was a mistake). Align also guarantees that the alignment is a valid power of two and represents it tersely (one byte).
You can see the original RFC to see why this can be beneficial.

If you feel strongly about it I can abandon this patch but IMHO being more explicit doesn't hurt and tremendously helps with subsequent refactoring.

tra added a comment.Jan 20 2023, 10:30 AM

You can see the original RFC to see why this can be beneficial.

Ah. Now the patch does make sense. Sorry about the push back.

llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
2751–2752

I'd just fold it into the call itself.

SDValue P = DAG.getLoad(VecVT, dl, Root, VecAddr,
                                  MachinePointerInfo(srcValue), MaybeAlign(aggregateIsPacked ? 1 : 0),

You can see the original RFC to see why this can be beneficial.

Ah. Now the patch does make sense. Sorry about the push back.

No worries, I should have been clearer on the motivation of this patch from the very beginning.
Thx for the review!

gchatelet updated this revision to Diff 491250.Jan 23 2023, 1:25 AM
gchatelet marked an inline comment as done.
  • Fold declaration into function call
tra accepted this revision.Jan 23 2023, 11:07 AM
This revision is now accepted and ready to land.Jan 23 2023, 11:07 AM
This revision was landed with ongoing or failed builds.Jan 24 2023, 12:39 AM
This revision was automatically updated to reflect the committed changes.