This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] Add basic computeKnownBits support for llvm.abs intrinsic
ClosedPublic

Authored by craig.topper on Jul 30 2020, 11:29 AM.

Details

Summary

This includes basic support for computeKnownBits on abs. I've left FIXMEs for more complicated things we could do.

Diff Detail

Event Timeline

craig.topper created this revision.Jul 30 2020, 11:29 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 30 2020, 11:29 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
craig.topper requested review of this revision.Jul 30 2020, 11:29 AM
spatel accepted this revision.Jul 30 2020, 3:55 PM

LGTM

This revision is now accepted and ready to land.Jul 30 2020, 3:55 PM

The SelectionDAG version does the following, so it would make sense to adapt these here:

// If the source's MSB is zero then we know the rest of the bits already.
if (Known2.isNonNegative()) {
  Known.Zero = Known2.Zero;
  Known.One = Known2.One;
  break;
}

// We only know that the absolute values's MSB will be zero iff there is
// a set bit that isn't the sign bit (otherwise it could be INT_MIN).
Known2.One.clearSignBit();
if (Known2.One.getBoolValue()) {
  Known.Zero = APInt::getSignMask(BitWidth);
  break;
}

The SelectionDAG version does the following, so it would make sense to adapt these here:

// If the source's MSB is zero then we know the rest of the bits already.
if (Known2.isNonNegative()) {
  Known.Zero = Known2.Zero;
  Known.One = Known2.One;
  break;
}

// We only know that the absolute values's MSB will be zero iff there is
// a set bit that isn't the sign bit (otherwise it could be INT_MIN).
Known2.One.clearSignBit();
if (Known2.One.getBoolValue()) {
  Known.Zero = APInt::getSignMask(BitWidth);
  break;
}

I did think about doing the first change, but I wondered if we would likely end up just removing the ABS in instcombine in that case.