This is an archive of the discontinued LLVM Phabricator instance.

[LangRef] nnan and ninf produce poison.
ClosedPublic

Authored by efriedma on Jun 8 2018, 3:33 PM.

Details

Summary

Clarify that violating nnan and ninf can lead to undefined behavior. This allows more aggressive optimizations based on those assumptions.

Diff Detail

Repository
rL LLVM

Event Timeline

efriedma created this revision.Jun 8 2018, 3:33 PM
nlopes added inline comments.Jun 9 2018, 3:05 PM
docs/LangRef.rst
2347 ↗(On Diff #150579)

This is precisely the definition of undef: an arbitrary value that may yield a different value each time it's used. But the intention was to avoid undef and poison.
I'm not familiar enough with floats to make any concrete suggestion; I'm just type checking.

efriedma updated this revision to Diff 150850.Jun 11 2018, 2:43 PM

Clarify that the value produced isn't undef. (It's more like freeze(undef).)

This reads clearer to me by avoiding the potential to confuse with UB. Should the same blurb apply to nsz with -0.0?

I don't think this is right. Saying the result is undefined seems like what we intend. We might choose, as an implementation technique, to limit how we take advantage of that undefinedness in certain cases, but the violating the constraint still produces logical inconsistencies that can transfer to other parts of the code, and in general, turn into any other kind of undefined behavior (depending on the structure of the code).

It has to be one of undefined behavior, poison, undef, or an unspecified value as described here; there is no other way for something to be "undefined" in LLVM IR, unless you're proposing to introduce a new form of undefined-ness specifically for nnan/ninf.

sanjoy added a subscriber: sanjoy.Jun 16 2018, 11:49 AM

I think we should have these produce poison -- if we have them produce undef we'll have the same kinds of problems as we have with regular undef.

nnan and ninf affect fcmp

Only if the fcmp is marked with nnan or ninf right?

Only if the fcmp is marked with nnan or ninf right?

Yes, but it's inconvenient in C because fast-math flags work on a per-file basis.


If the consensus is that we need to produce poison for nnan/ninf instead of an unspecified value, I can change that. I guess it allows more aggressive fcmp transforms in some cases?

efriedma updated this revision to Diff 154461.Jul 6 2018, 2:53 PM
efriedma retitled this revision from [LangRef] Clarify that nnan and ninf don't produce undef or poison. to [LangRef] nnan and ninf produce poison..
efriedma edited the summary of this revision. (Show Details)

Okay, switched to poison.

hfinkel accepted this revision.Jul 13 2018, 7:57 PM

LGTM

This revision is now accepted and ready to land.Jul 13 2018, 7:57 PM
This revision was automatically updated to reflect the committed changes.