This is an archive of the discontinued LLVM Phabricator instance.

DAGCombiner: Reduce truncated shl width
ClosedPublic

Authored by arsenm on Apr 22 2016, 8:57 PM.

Diff Detail

Event Timeline

arsenm updated this revision to Diff 54763.Apr 22 2016, 8:57 PM
arsenm retitled this revision from to DAGCombiner: Reduce truncated shl width.
arsenm updated this object.
escha added a subscriber: escha.Apr 28 2016, 10:53 AM

LGTM. We actually do this out of tree in our backend for ADD, SUB, MUL, SHL (since we'd rather truncate inputs than do a larger op and truncate that), so it seems more than reasonable to me.

LGTM. We actually do this out of tree in our backend for ADD, SUB, MUL, SHL (since we'd rather truncate inputs than do a larger op and truncate that), so it seems more than reasonable to me.

Can you post patches for these? I thought these were already generically done

arsenm accepted this revision.Apr 29 2016, 1:00 PM
arsenm added a reviewer: arsenm.

r268094

This revision is now accepted and ready to land.Apr 29 2016, 1:00 PM
arsenm closed this revision.Apr 29 2016, 1:00 PM
escha added a comment.Apr 29 2016, 1:00 PM

Some might be, as this code is fairly old. Here’s an extremely blind copy paste of our code:

// Truncate from an add should just reduce the size of the add and
// truncate the sources.  This is always a good idea for us as truncates
// are free while large adds/subs/muls are not.
switch (Source->getOpcode()) {
  case ISD::ADD:
  case ISD::SUB:
  case ISD::MUL:
  case ISD::SHL: {
    if (!AllUsersAreTruncate(Source))
      break;
    auto VT = N->getValueType(0);
    SDValue Trunc0 = DCI.DAG.getNode(ISD::TRUNCATE, dl, VT,
                                     Source->getOperand(0));
    SDValue Trunc1 = DCI.DAG.getNode(ISD::TRUNCATE, dl, VT,
                                     Source->getOperand(1));
    DCI.AddToWorklist(Trunc0.getNode());
    DCI.AddToWorklist(Trunc1.getNode());
    return DCI.DAG.getNode(Source->getOpcode(), dl, VT,
                           Trunc0, Trunc1);
  }
}

—escha