This is an archive of the discontinued LLVM Phabricator instance.

[DAGCombiner] Fix for PR37667
ClosedPublic

Authored by samparker on Jun 7 2018, 5:15 AM.

Details

Summary

While trying to propagate AND masks back to loads, we currently allow one non-load node to be included as a leaf in chain. This fix now limits that node to produce only a single data value.

Diff Detail

Repository
rL LLVM

Event Timeline

samparker created this revision.Jun 7 2018, 5:15 AM
spatel added a comment.Jun 7 2018, 7:19 AM

I'm not familiar with this transform, but the proposal makes sense. But I think it would be easier to follow the logic if it was written as:

// Also ensure that the node to be masked only produces one data result.
NodeToMask = Op.getNode();
unsigned DataValues = 0;
for (unsigned i = 0; i < NodeToMask->getNumValues(); ++i) {
  MVT VT = SDValue(NodeToMask, i).getSimpleValueType();
  if (VT != MVT::Glue && VT != MVT::Other)
    ++DataValues;
  if (DataValues > 1) {
    NodeToMask = nullptr;
    return false;
  }
}
assert(DataValues == 1 && "Node to be masked has no data result?");

Also, I added tests for both bugs (just in case there was logic difference there) with rL334199. Please use utils/update_llc_test_checks.py to update the assertions and rebase here.

niravd added a comment.Jun 7 2018, 8:22 AM

This also makes sense to me. Just to build on Sanjays comment, I think recasting DataValues as boolean is nicer.

NodeToMask = Op.getNode();
bool HasValue = false;
for (unsigned i = 0; i < NodeToMask->getNumValues(); ++i) {

MVT VT = SDValue(NodeToMask, i).getSimpleValueType();
if (VT != MVT::Glue && VT != MVT::Other){
  if(HasValue) {
    NodeToMask = nullptr;
    return false;
  }
  HasValue = true;

}

I'm not familiar with this transform, but the proposal makes sense. But I think it would be easier to follow the logic if it was written as:

// Also ensure that the node to be masked only produces one data result.
NodeToMask = Op.getNode();
unsigned DataValues = 0;
for (unsigned i = 0; i < NodeToMask->getNumValues(); ++i) {
  MVT VT = SDValue(NodeToMask, i).getSimpleValueType();
  if (VT != MVT::Glue && VT != MVT::Other)
    ++DataValues;
  if (DataValues > 1) {
    NodeToMask = nullptr;
    return false;
  }
}
assert(DataValues == 1 && "Node to be masked has no data result?");

Also, I added tests for both bugs (just in case there was logic difference there) with rL334199. Please use utils/update_llc_test_checks.py to update the assertions and rebase here.

I'm not familiar with this transform, but the proposal makes sense. But I think it would be easier to follow the logic if it was written as:

// Also ensure that the node to be masked only produces one data result.
NodeToMask = Op.getNode();
unsigned DataValues = 0;
for (unsigned i = 0; i < NodeToMask->getNumValues(); ++i) {
  MVT VT = SDValue(NodeToMask, i).getSimpleValueType();
  if (VT != MVT::Glue && VT != MVT::Other)
    ++DataValues;
  if (DataValues > 1) {
    NodeToMask = nullptr;
    return false;
  }
}
assert(DataValues == 1 && "Node to be masked has no data result?");

Also, I added tests for both bugs (just in case there was logic difference there) with rL334199. Please use utils/update_llc_test_checks.py to update the assertions and rebase here.

samparker updated this revision to Diff 150342.Jun 7 2018, 8:35 AM

Thanks for the feedback. I've removed my new test and updated the existed one. Also modified the code style.

niravd accepted this revision.Jun 7 2018, 8:40 AM

LGTM.

This revision is now accepted and ready to land.Jun 7 2018, 8:40 AM
spatel added inline comments.Jun 7 2018, 8:42 AM
test/CodeGen/X86/backpropmask.ll
4 ↗(On Diff #150342)

Please remove this FIXME when committing.

RKSimon added inline comments.
lib/CodeGen/SelectionDAG/DAGCombiner.cpp
4005 ↗(On Diff #150342)

Minor style issue:

for (unsigned i = 0, e = NodeToMask->getNumValues(); i < e; ++i) {
This revision was automatically updated to reflect the committed changes.