This is an archive of the discontinued LLVM Phabricator instance.

ValueTracking: Teach CannotBeOrderedLessThanZero about copysign
ClosedPublic

Authored by arsenm on Dec 5 2022, 5:18 AM.

Diff Detail

Event Timeline

arsenm created this revision.Dec 5 2022, 5:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2022, 5:18 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Dec 5 2022, 5:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 5 2022, 5:18 AM
Herald added a subscriber: wdng. · View Herald Transcript
foad added a comment.Dec 5 2022, 5:43 AM

Seems reasonable. Can we get alive2 proofs for floating point things like this yet @nlopes?

arsenm added a comment.Dec 5 2022, 5:49 AM

Alive2 says this is ok and seems to understand copysign. For some of the other complex functions in other patches, it doesn’t complain but it also doesn’t complain when I try things that are obviously wrong

nlopes added a comment.Dec 5 2022, 6:07 AM

Seems reasonable. Can we get alive2 proofs for floating point things like this yet @nlopes?

Most FP stuff should be working now. Exceptions include: some fast-math flags (arcp/contract/reassoc/afn), exceptions, and some intrinsics. The rest should all be working; if not please file a bug report :)

Alive2 says this is ok and seems to understand copysign. For some of the other complex functions in other patches, it doesn’t complain but it also doesn’t complain when I try things that are obviously wrong

As noted above, most FP should be working. If Alive2 misses a bug, please do file a bug report. Alive2 is not supposed to miss (almost no) bugs.

spatel added inline comments.Dec 5 2022, 6:12 AM
llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
964

Something went wrong - this is a miscompile without 'nsz' on the sqrt (otherwise, it can return -0.0):
https://alive2.llvm.org/ce/z/yqXQmQ

arsenm added inline comments.Dec 5 2022, 7:21 AM
llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
964

But this is being consumed by an fcmp - the sign of the zero shouldn't matter for the final result. Alive bug?

spatel added inline comments.Dec 5 2022, 7:37 AM
llvm/test/Transforms/InstSimplify/floating-point-arithmetic.ll
964

No - the negative sign of the -0.0 is applied to the magnitude parameter (%unknown).
So the sequence could be something like:
copysign(42.0, sqrt(-0.0)) >= 0.0
-42.0 >= 0.0 --> false

arsenm updated this revision to Diff 480156.Dec 5 2022, 10:24 AM

The whole reason I used sqrt in the test was to test -0 and I still got it wrong

spatel accepted this revision.Dec 5 2022, 11:48 AM

LGTM

This revision is now accepted and ready to land.Dec 5 2022, 11:48 AM