OSDN Git Service

PatternMatch: Matcher for (un)ordered floating point min/max
authorArnold Schwaighofer <aschwaighofer@apple.com>
Sun, 5 May 2013 01:54:46 +0000 (01:54 +0000)
committerArnold Schwaighofer <aschwaighofer@apple.com>
Sun, 5 May 2013 01:54:46 +0000 (01:54 +0000)
commite79d92c592d75e210dbe3abe1a975e859d17e953
tree6ea7c95b07fdeafb0b747d87f96c3e7ffd8e75d4
parentf852472823fd2182a3ca54bdf4d30ad8a6a6cd57
PatternMatch: Matcher for (un)ordered floating point min/max

Add support for matching 'ordered' and 'unordered' floating point min/max
constructs.

In LLVM we can express min/max functions as a combination of compare and select.
We have support for matching such constructs for integers but not for floating
point. In floating point math there is no total order because of the presence of
'NaN'. Therefore, we have to be careful to preserve the original fcmp semantics
when interpreting floating point compare select combinations as a minimum or
maximum function. The resulting 'ordered/unordered' floating point maximum
function has to select the same value as the select/fcmp combination it is based
on.

 ordered_max(x,y)   = max(x,y) iff x and y are not NaN, y otherwise
 unordered_max(x,y) = max(x,y) iff x and y are not NaN, x otherwise
 ordered_min(x,y)   = min(x,y) iff x and y are not NaN, y otherwise
 unordered_min(x,y) = min(x,y) iff x and y are not NaN, x otherwise

This matches the behavior of the underlying select(fcmp(olt/ult/.., L, R), L, R)
construct.

Any code using this predicate has to preserve this semantics.

A follow-up patch will use this to implement floating point min/max reductions
in the vectorizer.

radar://13723044

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@181143 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/PatternMatch.h
unittests/IR/PatternMatch.cpp [new file with mode: 0644]