If we don't HONOR_NANS we should not try to use any unordered
comparison results.  Best case those will just be optimized away;
realistically, they ICE.  For example, the rs6000 backend has some
code that specifically checks we never do this.

This patch fixes it.  Bootstrapped and tested on powerpc64-linux
{-m32,-m64}.  Is this okay for trunk?


Segher


2019-04-18  Segher Boessenkool  <seg...@kernel.crashing.org>

        PR tree-optimization/88055
        * tree-call-cdce.c (comparison_code_if_no_nans): New function.
        (gen_one_condition): Use it if !HONOR_NANS.

---
 gcc/tree-call-cdce.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/gcc/tree-call-cdce.c b/gcc/tree-call-cdce.c
index 2b1e934..2e482b3 100644
--- a/gcc/tree-call-cdce.c
+++ b/gcc/tree-call-cdce.c
@@ -362,6 +362,40 @@ can_guard_call_p (gimple *call)
          || find_fallthru_edge (gimple_bb (call)->succs));
 }
 
+/* For a comparison code return the comparison code we should use if we don't
+   HONOR_NANS.  */
+
+static enum tree_code
+comparison_code_if_no_nans (tree_code code)
+{
+  switch (code)
+    {
+    case UNLT_EXPR:
+      return LT_EXPR;
+    case UNGT_EXPR:
+      return GT_EXPR;
+    case UNLE_EXPR:
+      return LE_EXPR;
+    case UNGE_EXPR:
+      return GE_EXPR;
+    case UNEQ_EXPR:
+      return EQ_EXPR;
+    case LTGT_EXPR:
+      return NE_EXPR;
+
+    case LT_EXPR:
+    case GT_EXPR:
+    case LE_EXPR:
+    case GE_EXPR:
+    case EQ_EXPR:
+    case NE_EXPR:
+      return code;
+
+    default:
+      gcc_unreachable ();
+    }
+}
+
 /* A helper function to generate gimple statements for one bound
    comparison, so that the built-in function is called whenever
    TCODE <ARG, LBUB> is *false*.  TEMP_NAME1/TEMP_NAME2 are names
@@ -378,6 +412,9 @@ gen_one_condition (tree arg, int lbub,
                   vec<gimple *> conds,
                    unsigned *nconds)
 {
+  if (!HONOR_NANS (arg))
+    tcode = comparison_code_if_no_nans (tcode);
+
   tree lbub_real_cst, lbub_cst, float_type;
   tree temp, tempn, tempc, tempcn;
   gassign *stmt1;
-- 
1.8.3.1

Reply via email to