This is an archive of the discontinued LLVM Phabricator instance.

[SDAG] clean up scalarizing load transform
ClosedPublic

Authored by spatel on Feb 11 2022, 7:55 AM.

Details

Summary

I have not found a way to expose a difference for this patch in a test because it only triggers for a one-use load, but this is the code that was adapted into D118376 and caused miscompiles. The new code pattern is the same as what we do in narrowExtractedVectorLoad() (reduces load width for a subvector extract).

This removes seemingly unnecessary manual worklist management and fixes the chain updating via:

SDValue SelectionDAG::makeEquivalentMemoryOrdering(SDValue OldChain,
                                                   SDValue NewMemOpChain) {
  assert(isa<MemSDNode>(NewMemOpChain) && "Expected a memop node");
  assert(NewMemOpChain.getValueType() == MVT::Other && "Expected a token VT");
  // The new memory operation must have the same position as the old load in
  // terms of memory dependency. Create a TokenFactor for the old load and new
  // memory operation and update uses of the old load's output chain to use that
  // TokenFactor.
  if (OldChain == NewMemOpChain || OldChain.use_empty())
    return NewMemOpChain;

  SDValue TokenFactor = getNode(ISD::TokenFactor, SDLoc(OldChain), MVT::Other,
                                OldChain, NewMemOpChain);
  ReplaceAllUsesOfValueWith(OldChain, TokenFactor);
  UpdateNodeOperands(TokenFactor.getNode(), OldChain, NewMemOpChain);
  return TokenFactor;
}

Diff Detail

Event Timeline

spatel created this revision.Feb 11 2022, 7:55 AM
spatel requested review of this revision.Feb 11 2022, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 11 2022, 7:55 AM
efriedma accepted this revision.Feb 11 2022, 10:31 AM

Sure, LGTM

This revision is now accepted and ready to land.Feb 11 2022, 10:31 AM
This revision was landed with ongoing or failed builds.Feb 12 2022, 8:45 AM
This revision was automatically updated to reflect the committed changes.