This is an archive of the discontinued LLVM Phabricator instance.

[DAG] Add BuildVectorSDNode::getConstantRawBits helper
ClosedPublic

Authored by RKSimon on Nov 6 2021, 2:21 PM.

Details

Summary

We have several places where we need to extract the raw bits data from a BUILD_VECTOR node, so consolidate this to a single helper function that handles Undefs and Integer/FP constants, including implicit truncation.

This should make it easier to extend D113202 to handle more constant folding of bitcasted constant data.

Diff Detail

Event Timeline

RKSimon created this revision.Nov 6 2021, 2:21 PM
RKSimon requested review of this revision.Nov 6 2021, 2:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptNov 6 2021, 2:21 PM
craig.topper added inline comments.Nov 6 2021, 8:00 PM
llvm/include/llvm/CodeGen/SelectionDAGNodes.h
2056

IsLE could probably use some documentation or spell it out. I didn't read LE as little endian at first. I initially read it as "less than or equal" which didn't make any sense.

pengfei added inline comments.Nov 6 2021, 9:11 PM
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
10932–10933

Move ahead?

10942

Do we need to check IsLE for I?

10951

Do we need to zextOrTrunc it?

10973–10979

Maybe compiler can do so, but I think it's better to hoist the code outside the loop, e.g.

APInt SrcBits;
if (CInt)
  SrcBits = CInt->getAPIntValue();
else
  SrcBits = CFP->getValueAPF().bitcastToAPInt();

for (unsigned J = 0; J != Scale; ++J)
  RawBitElements[(I * Scale) + (IsLE ? J : (Scale - J - 1))] = SrcBits.extractBits(DstEltSizeInBits, J * DstEltSizeInBits);
RKSimon planned changes to this revision.Nov 7 2021, 1:58 AM
RKSimon added inline comments.
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
10932–10933

Yes I can do that - the BuildVectorSDNode methods are inconsistent as to whether the output variables are canonicalized or not on failure.

10942

Not AFAICT - we don't do that for other vectors-through-bitcasts (the DAG code this was pulled out of, shuffles-of-bitcasts, etc.) - its purely the elements that alias within the bitcast that need swapping..

10951

For integer - a truncOrSelf would suffice. For float the bitwidths should match. I'll add an assert to be sure.

RKSimon updated this revision to Diff 385347.Nov 7 2021, 8:09 AM

address comments

pengfei accepted this revision.Nov 7 2021, 4:50 PM

LGTM.

This revision is now accepted and ready to land.Nov 7 2021, 4:50 PM
This revision was landed with ongoing or failed builds.Nov 8 2021, 4:07 AM
This revision was automatically updated to reflect the committed changes.