This is an archive of the discontinued LLVM Phabricator instance.

[ValueTracking] fix bug in maxnum case of cannotBeOrderedLessThanZeroImpl (PR46627)
ClosedPublic

Authored by spatel on Jul 10 2020, 5:39 PM.

Details

Summary

A miscompile with -0.0 is shown in:
https://bugs.llvm.org/show_bug.cgi?id=46627

This is because maxnum(-0.0, +0.0) does not specify a fixed result:
http://llvm.org/docs/LangRef.html#llvm-maxnum-intrinsic

So we need to tighten the constraints for when it is ok to say the result of maxnum is positive (including +0.0).

Diff Detail

Event Timeline

spatel created this revision.Jul 10 2020, 5:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2020, 5:39 PM
efriedma added inline comments.Jul 13 2020, 10:38 AM
llvm/lib/Analysis/ValueTracking.cpp
3383

Can you just pass false for "SignBitOnly", instead of doing a bunch of extra calls?

efriedma added inline comments.Jul 13 2020, 10:40 AM
llvm/lib/Analysis/ValueTracking.cpp
3383

Err, nevermind, that doesn't work; I need more coffee this morning.

efriedma added inline comments.Jul 13 2020, 10:44 AM
llvm/lib/Analysis/ValueTracking.cpp
3383

Hopefully correct this time:

If SignBitOnly is false, the current code is correct, I think. The sign bit of zero doesn't matter.

If SignBitOnly is true, there are two possible proof methods:

  1. Neither operand has the sign bit set.
  2. Either operand is strictly greater than zero.
spatel updated this revision to Diff 277587.Jul 13 2020, 3:20 PM

Patch updated:

  1. Salvage a bit more of the existing functionality by differentiating based on "SignBitOnly" (shown with the unchanged test code comments).
  2. Add another test (copysign) to show a miscompile.
efriedma accepted this revision.Jul 13 2020, 3:58 PM

LGTM

llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
1393

"the sign of the result"

This revision is now accepted and ready to land.Jul 13 2020, 3:58 PM
spatel marked 2 inline comments as done.Jul 14 2020, 4:47 AM
This revision was automatically updated to reflect the committed changes.