[PPC, FastISel] Fix ordered/unordered fcmp
authorTim Shen <timshen91@gmail.com>
Thu, 17 Mar 2016 22:27:58 +0000 (22:27 +0000)
committerTim Shen <timshen91@gmail.com>
Thu, 17 Mar 2016 22:27:58 +0000 (22:27 +0000)
commit5cdf75084a6606b12ea08e0a1eb8e68714b4b75f
tree6aa23d9f91f652a51a2ab9f875b262b22b598cb0
parent34888f86ef0a27e070138050278a92573f015b2f
[PPC, FastISel] Fix ordered/unordered fcmp

For fcmp, major concern about the following 6 cases is NaN result. The
comparison result consists of 4 bits, indicating lt, eq, gt and un (unordered),
only one of which will be set. The result is generated by fcmpu
instruction. However, bc instruction only inspects one of the first 3
bits, so when un is set, bc instruction may jump to to an undesired
place.

More specifically, if we expect an unordered comparison and un is set, we
expect to always go to true branch; in such case UEQ, UGT and ULT still
give false, which are undesired; but UNE, UGE, ULE happen to give true,
since they are tested by inspecting !eq, !lt, !gt, respectively.

Similarly, for ordered comparison, when un is set, we always expect the
result to be false. In such case OGT, OLT and OEQ is good, since they are
actually testing GT, LT, and EQ respectively, which are false. OGE, OLE
and ONE are tested through !lt, !gt and !eq, and these are true.

llvm-svn: 263753
llvm/lib/Target/PowerPC/PPCFastISel.cpp
llvm/test/CodeGen/PowerPC/fast-isel-fcmp-nan.ll [new file with mode: 0644]