This is an archive of the discontinued LLVM Phabricator instance.

InstSimplify: Fold fdiv nnan nsz x, 0 -> inf
AbandonedPublic

Authored by arsenm on Oct 17 2022, 11:17 AM.

Details

Diff Detail

Event Timeline

arsenm created this revision.Oct 17 2022, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 11:17 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
arsenm requested review of this revision.Oct 17 2022, 11:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 17 2022, 11:17 AM
Herald added a subscriber: wdng. · View Herald Transcript
kpn accepted this revision.Oct 17 2022, 11:51 AM

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

This revision is now accepted and ready to land.Oct 17 2022, 11:51 AM

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

That's what I would expect. alive2 has been giving me some nsz results that puzzle me https://alive2.llvm.org/ce/z/v-9wqk

kpn requested changes to this revision.Oct 17 2022, 12:11 PM

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

English is fun! Yes, I think you are correct. With D136098 is this patch needed, especially if that patch's TODO is completed?

This revision now requires changes to proceed.Oct 17 2022, 12:11 PM
nlopes added a subscriber: nlopes.Oct 17 2022, 1:15 PM

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

It's documented as ignoring the sign of a zero argument or a zero result.
Thus, when nsw is involved, we should consider the result of -42.0 / 0.0 and -42.0 / -0.0. This case the 0.0 is a constant, but that doesn't matter.

Alive2 is correct here AFAICT.

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

It's documented as ignoring the sign of a zero argument or a zero result.
Thus, when nsw is involved, we should consider the result of -42.0 / 0.0 and -42.0 / -0.0. This case the 0.0 is a constant, but that doesn't matter.

Alive2 is correct here AFAICT.

Ah, thanks for clearing that up. The "nsz" wording has always been a less solid than I'd like, but I'm not sure how to change it.
I suspect this transform would cause some fallout with users because it's a stretch to go from -0.0 isn't different than 0.0, therefore, -Inf isn't different than +Inf. There was a suggestion in a previous discussion that we really need entirely new FP types to use with fast-math-flags, so it's clear that -0.0, Inf, or NaN values simply do not exist when the corresponding compile flag is used, but I don't think anyone has looked seriously at implementing that. There's more discussion about the general problem here:
https://github.com/llvm/llvm-project/issues/51601

It looks like by 754 sec 7.3 a (-x)/(+0) == -Inf, but the nsz is documented as saying the sign of the result is "insignificant", so I think we're good here.

LGTM

"nsz" means the sign of a zero result is insignificant, not any result. -42.0 / 0.0 should be -Inf, not +Inf?

It's documented as ignoring the sign of a zero argument or a zero result.
Thus, when nsw is involved, we should consider the result of -42.0 / 0.0 and -42.0 / -0.0. This case the 0.0 is a constant, but that doesn't matter.

Alive2 is correct here AFAICT.

Ah, thanks for clearing that up. The "nsz" wording has always been a less solid than I'd like, but I'm not sure how to change it.
I suspect this transform would cause some fallout with users because it's a stretch to go from -0.0 isn't different than 0.0, therefore, -Inf isn't different than +Inf. There was a suggestion in a previous discussion that we really need entirely new FP types to use with fast-math-flags, so it's clear that -0.0, Inf, or NaN values simply do not exist when the corresponding compile flag is used, but I don't think anyone has looked seriously at implementing that. There's more discussion about the general problem here:
https://github.com/llvm/llvm-project/issues/51601

That bug report seems to be a bit orthogonal. The issue there is that the fmath flags are attached to some instructions, but not all. Since values can't have fmath flags themselves, things like function arguments, when flowing directly to instructions without fmath flags make clang lose information when generating IR. Hence the proposal to add fmath to loads (I don't think you need fmath in store).

Regarding the semantics of nsz, I don't have any opinion as I'm clueless about FP. I'm just reading the current semantics to the letter, but I'm happy to implement whatever semantics you want in Alive2.

kpn added a comment.Oct 18 2022, 7:59 AM

Ah, thanks for clearing that up. The "nsz" wording has always been a less solid than I'd like, but I'm not sure how to change it.
I suspect this transform would cause some fallout with users because it's a stretch to go from -0.0 isn't different than 0.0, therefore, -Inf isn't different than +Inf. There was a suggestion in a previous discussion that we really need entirely new FP types to use with fast-math-flags, so it's clear that -0.0, Inf, or NaN values simply do not exist when the corresponding compile flag is used, but I don't think anyone has looked seriously at implementing that. There's more discussion about the general problem here:
https://github.com/llvm/llvm-project/issues/51601

I just pushed a change to the LangRef that will hopefully avoid misreadings like the one I made: 1b06307aa43c3d366843866985abcd95aedb78a2

I just pushed a change to the LangRef that will hopefully avoid misreadings like the one I made: 1b06307aa43c3d366843866985abcd95aedb78a2

Thanks!

https://github.com/llvm/llvm-project/issues/51601

That bug report seems to be a bit orthogonal.

Oops, I pasted the wrong link.
https://github.com/llvm/llvm-project/issues/51117
...this bug report has a bunch of links back to the old dev-lists where there were threads about what to do about NaN/Inf constants referenced in source built with -ffinite-math-only. I don't think we reached a conclusion.