[InstSimplify] fold and/or of fcmp ord/uno when operand is known nnan
authorSanjay Patel <spatel@rotateright.com>
Sun, 19 Nov 2017 15:34:27 +0000 (15:34 +0000)
committerSanjay Patel <spatel@rotateright.com>
Sun, 19 Nov 2017 15:34:27 +0000 (15:34 +0000)
commiteb731b09f3cbea16487d1abc63029d5fa2d899b2
tree726b0ff4495a502662e7ec77d2c27db93cee5ed5
parentd7ff94f0357b6c16e39ac39d0e336a2280d0d05b
[InstSimplify] fold and/or of fcmp ord/uno when operand is known nnan

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 (known NNAN), X) && (fcmp ord X, Y) --> fcmp ord X, Y
(fcmp uno (known NNAN), X) || (fcmp uno X, Y) --> fcmp uno X, Y

It might be better to split this into (X uno 0) | (Y uno 0) as a canonicalization, but that
would be another patch.

Differential Revision: https://reviews.llvm.org/D40130

llvm-svn: 318627
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/test/Transforms/InstSimplify/logic-of-fcmps.ll