This is an archive of the discontinued LLVM Phabricator instance.

[SCCP] Remove useless code in visitBinaryOperator (and add tests)
ClosedPublic

Authored by davide on Nov 19 2016, 5:51 PM.

Details

Summary

This code is very old, so I don't feel very confident touching it without a second opinion. I noticed this while I was trying to integrate undef into the solver.

The problem is that when we visit and/or, we try to derive a lattice value for the instruction even if one of the operands is overdefined.
My understanding is:
When we arrive at this point we already called getValueState() on the non-overdefined operand, so if the value is still in the 'unknown' state it means that it was found to be an 'undef' value.
I think the correct thing to do in this case is just return and wait for ResolvedUndefsIn to "plug in" the correct value, rather than calling markConstant as it's currently done.
While I was there, I added some tests for this code that were missing.

Diff Detail

Event Timeline

davide updated this revision to Diff 78647.Nov 19 2016, 5:51 PM
davide retitled this revision from to [SCCP] Remove (maybe?) wrong code in visitBinaryOperator.
davide updated this object.
davide added a reviewer: eli.friedman.
davide added a subscriber: llvm-commits.

This code was introduced by Chris in 2004 and never touched since then

commit a177c6747195f2abe5a0fc10e1a65d6c0afb85b5
Author: Chris Lattner <sabre@nondot.org>
Date:   Sat Dec 11 23:15:19 2004 +0000

    If one side of and/or is known to be 0/-1, it doesn't matter
    if the other side is overdefined.

    This allows us to fold conditions like:  if (X < Y || Y > Z) in some cases.

cc:ing him in case he remembers the details.

Slight correction:

When we arrive at this point we already called getValueState() on the non-overdefined operand, so if the value is still in the 'unknown' state it means that it was found to be an 'undef' value.

There are two cases:

  1. the one outlined above
  2. the operand hasn't been resolved yet, so we still need to wait for it.
efriedma added inline comments.
lib/Transforms/Scalar/SCCP.cpp
932

This is okay, I guess, but I don't think it fixes anything.

940

NonOverdefVal isn't guaranteed to be a ConstantInt here.

davide updated this revision to Diff 78648.Nov 19 2016, 7:14 PM
davide retitled this revision from [SCCP] Remove (maybe?) wrong code in visitBinaryOperator to [SCCP] Remove useless code in visitBinaryOperator (and add tests).
davide added inline comments.
lib/Transforms/Scalar/SCCP.cpp
932

Yes, but it was just weird to have all that logic there.

932

Renamed the revision accordingly

efriedma accepted this revision.Nov 21 2016, 12:01 PM
efriedma added a reviewer: efriedma.

LGTM.

This revision is now accepted and ready to land.Nov 21 2016, 12:01 PM

LGTM.

Thanks Eli.

lib/Transforms/Scalar/SCCP.cpp
932

Yes, but it was just weird to have all that logic there.

davide closed this revision.Nov 22 2016, 2:21 PM