This is an archive of the discontinued LLVM Phabricator instance.

[InstSimplify] fold and/or of fcmp ord/uno when operand is known nnan

Authored by spatel on Nov 16 2017, 7:45 AM.



The 'ord' and 'uno' predicates have a logic operation for NAN built into their definitions:

FCMP_ORD   =  7,  ///< 0 1 1 1    True if ordered (no nans)
FCMP_UNO   =  8,  ///< 1 0 0 0    True if unordered: isnan(X) | isnan(Y)

So we can simplify patterns like this:

(fcmp ord NNAN, X) && (fcmp ord X, Y) --> fcmp ord X, Y
(fcmp uno NNAN, X) || (fcmp uno X, Y) --> fcmp uno X, Y

Diff Detail


Event Timeline

spatel created this revision.Nov 16 2017, 7:45 AM

For motivational reference, this is a continuation of D37427 with a goal of solving patterns as seen in PR27145:

efriedma edited edge metadata.Nov 17 2017, 4:49 PM

From the perspective of canonicalization, it seems kind of weird to have "%x uno %y" rather than "(%x uno 0) | (%y uno 0)". I mean, the former is probably cheaper to lower, but it leads to a lot of special-case logic to handle the equivalency.

efriedma accepted this revision.Nov 17 2017, 4:53 PM

That said, this transform seems straightforward enough. LGTM.

This revision is now accepted and ready to land.Nov 17 2017, 4:53 PM
This revision was automatically updated to reflect the committed changes.