[cfe-commits] r102598 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/CodeGen/const-unordered-compare.c

Mon P Wang wangmp at apple.com
Wed Apr 28 22:53:29 PDT 2010


Author: wangmp
Date: Thu Apr 29 00:53:29 2010
New Revision: 102598

URL: http://llvm.org/viewvc/llvm-project?rev=102598&view=rev
Log:
A not equal for an unordered relation should return true as specified in IEEE-754, e.g.,
NAN != NAN ? 1 : 0 should return 1.  Also fix the case for complex.

Added:
    cfe/trunk/test/CodeGen/const-unordered-compare.c
Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=102598&r1=102597&r2=102598&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Apr 29 00:53:29 2010
@@ -1119,9 +1119,11 @@
         assert(E->getOpcode() == BinaryOperator::NE &&
                "Invalid complex comparison.");
         return Success(((CR_r == APFloat::cmpGreaterThan ||
-                         CR_r == APFloat::cmpLessThan) &&
+                         CR_r == APFloat::cmpLessThan ||
+                         CR_r == APFloat::cmpUnordered) ||
                         (CR_i == APFloat::cmpGreaterThan ||
-                         CR_i == APFloat::cmpLessThan)), E);
+                         CR_i == APFloat::cmpLessThan ||
+                         CR_i == APFloat::cmpUnordered)), E);
       }
     } else {
       if (E->getOpcode() == BinaryOperator::EQ)
@@ -1164,7 +1166,8 @@
       return Success(CR == APFloat::cmpEqual, E);
     case BinaryOperator::NE:
       return Success(CR == APFloat::cmpGreaterThan
-                     || CR == APFloat::cmpLessThan, E);
+                     || CR == APFloat::cmpLessThan
+                     || CR == APFloat::cmpUnordered, E);
     }
   }
 

Added: cfe/trunk/test/CodeGen/const-unordered-compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/const-unordered-compare.c?rev=102598&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/const-unordered-compare.c (added)
+++ cfe/trunk/test/CodeGen/const-unordered-compare.c Thu Apr 29 00:53:29 2010
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
+
+// Checks folding of an unordered comparison
+int nan_ne_check() {
+  // CHECK: store i32 1
+  return (__builtin_nanf("") != __builtin_nanf("")) ? 1 : 0;
+}





More information about the cfe-commits mailing list