llvm.org GIT mirror llvm / 63079f0
Fold comparisons against a constant nan, and optimize ORD/UNORD comparisons with a constant. This allows us to compile isnan to: _foo: fcmpu cr7, f1, f1 mfcr r2 rlwinm r3, r2, 0, 31, 31 blr instead of: LCPI1_0: ; float .space 4 _foo: lis r2, ha16(LCPI1_0) lfs f0, lo16(LCPI1_0)(r2) fcmpu cr7, f1, f0 mfcr r2 rlwinm r3, r2, 0, 31, 31 blr git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45405 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
3 changed file(s) with 33 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
12791279 // Constant fold or commute setcc.
12801280 SDOperand O = DAG.FoldSetCC(VT, N0, N1, Cond);
12811281 if (O.Val) return O;
1282 } else if (ConstantFPSDNode *CFP = dyn_cast(N1.Val)) {
1283 // If the RHS of an FP comparison is a constant, simplify it away in
1284 // some cases.
1285 if (CFP->getValueAPF().isNaN()) {
1286 // If an operand is known to be a nan, we can fold it.
1287 switch (ISD::getUnorderedFlavor(Cond)) {
1288 default: assert(0 && "Unknown flavor!");
1289 case 0: // Known false.
1290 return DAG.getConstant(0, VT);
1291 case 1: // Known true.
1292 return DAG.getConstant(1, VT);
1293 case 2: // undefind.
1294 return DAG.getNode(ISD::UNDEF, VT);
1295 }
1296 }
1297
1298 // Otherwise, we know the RHS is not a NaN. Simplify the node to drop the
1299 // constant if knowing that the operand is non-nan is enough. We prefer to
1300 // have SETO(x,x) instead of SETO(x, 0.0) because this avoids having to
1301 // materialize 0.0.
1302 if (Cond == ISD::SETO || Cond == ISD::SETUO)
1303 return DAG.getSetCC(VT, N0, N0, Cond);
12821304 }
12831305
12841306 if (N0 == N1) {
812812 cmovs %edx, %ecx
813813 movl %ecx, %eax
814814 ret
815
816 //===---------------------------------------------------------------------===//
817
818 This:
819 #include
820 int foo(double X) { return isnan(X); }
821
822 compiles to (-m64):
823
824 _foo:
825 pxor %xmm1, %xmm1
826 ucomisd %xmm1, %xmm0
827 setp %al
828 movzbl %al, %eax
829 ret
830
831 the pxor is not needed, we could compare the value against itself.
832815
833816 //===---------------------------------------------------------------------===//
834817
0 ; RUN: llvm-as < %s | llc -march=x86 -mcpu=yonah | not grep pxor
1
2 ; This should not need to materialize 0.0 to evaluate the condition.
3
4 define i32 @test(double %X) nounwind {
5 entry:
6 %tmp6 = fcmp uno double %X, 0.000000e+00 ; [#uses=1]
7 %tmp67 = zext i1 %tmp6 to i32 ; [#uses=1]
8 ret i32 %tmp67
9 }
10