This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Mark constant xor %blah, %blah even if the lattice value is overdefined
AbandonedPublic

Authored by davide on Jul 20 2016, 3:00 PM.

Details

Reviewers
eli.friedman
Summary

I think this is OK, but there might be cases where this break I'm currently missing.
In general, it should be able to avoid some spurious overdefined values, which is good.

Diff Detail

Event Timeline

davide updated this revision to Diff 64774.Jul 20 2016, 3:00 PM
davide retitled this revision from to [SCCP] Mark constant xor %blah, %blah even if the lattice value is overdefined.
davide updated this object.
davide added a reviewer: eli.friedman.
davide added a subscriber: llvm-commits.
escha added a subscriber: escha.Jul 20 2016, 3:02 PM

This would work with 'sub' too, right?

This would work with 'sub' too, right?

Probably. I'll fix that if we agree this transform is actually valid.

eli.friedman edited edge metadata.Jul 21 2016, 12:52 PM

The transformation valid... but I don't think it makes sense to perform it here. SCCP doesn't add any power to the transformation over instsimplify.

The transformation valid... but I don't think it makes sense to perform it here. SCCP doesn't add any power to the transformation over instsimplify.

I was worried about that. We already do some similar transformations in visitBinaryOp()

if (I.getOpcode() == Instruction::And) {
  // X and 0 = 0
  if (NonOverdefVal->getConstant()->isNullValue())
    return markConstant(IV, &I, NonOverdefVal->getConstant());
} else {
  if (ConstantInt *CI = NonOverdefVal->getConstantInt())
    if (CI->isAllOnesValue())     // X or -1 = -1
      return markConstant(IV, &I, NonOverdefVal->getConstant());
}

maybe we should get rid of these?

There, SCCP actually does add power to the transformation; consider a construct like the following:

int f();
int g() { 
    int x = 0;
    for (int i = 0; i < 1000000; ++i) {
        x &= f();
    }
    return x;
}

SCCP can prove that this function returns zero.

davide abandoned this revision.Jul 21 2016, 1:19 PM

Oh, I see now. Thanks! Abandoning this then.