OSDN Git Service

Daily bump.
[pf3gnuchains/gcc-fork.git] / gcc / tree-ssa-pre.c
index 84c884b..2fb4710 100644 (file)
@@ -1088,47 +1088,59 @@ fully_constant_expression (pre_expr e)
        vn_nary_op_t nary = PRE_EXPR_NARY (e);
        switch (TREE_CODE_CLASS (nary->opcode))
          {
+         case tcc_expression:
+           if (nary->opcode == TRUTH_NOT_EXPR)
+             goto do_unary;
+           if (nary->opcode != TRUTH_AND_EXPR
+               && nary->opcode != TRUTH_OR_EXPR
+               && nary->opcode != TRUTH_XOR_EXPR)
+             return e;
+           /* Fallthrough.  */
          case tcc_binary:
+         case tcc_comparison:
            {
              /* We have to go from trees to pre exprs to value ids to
                 constants.  */
              tree naryop0 = nary->op[0];
              tree naryop1 = nary->op[1];
-             tree const0, const1, result;
-             if (is_gimple_min_invariant (naryop0))
-               const0 = naryop0;
-             else
+             tree result;
+             if (!is_gimple_min_invariant (naryop0))
                {
                  pre_expr rep0 = get_or_alloc_expr_for (naryop0);
                  unsigned int vrep0 = get_expr_value_id (rep0);
-                 const0 = get_constant_for_value_id (vrep0);
+                 tree const0 = get_constant_for_value_id (vrep0);
+                 if (const0)
+                   naryop0 = fold_convert (TREE_TYPE (naryop0), const0);
                }
-             if (is_gimple_min_invariant (naryop1))
-               const1 = naryop1;
-             else
+             if (!is_gimple_min_invariant (naryop1))
                {
                  pre_expr rep1 = get_or_alloc_expr_for (naryop1);
                  unsigned int vrep1 = get_expr_value_id (rep1);
-                 const1 = get_constant_for_value_id (vrep1);
-               }
-             result = NULL;
-             if (const0 && const1)
-               {
-                 tree type1 = TREE_TYPE (nary->op[0]);
-                 tree type2 = TREE_TYPE (nary->op[1]);
-                 const0 = fold_convert (type1, const0);
-                 const1 = fold_convert (type2, const1);
-                 result = fold_binary (nary->opcode, nary->type, const0,
-                                       const1);
+                 tree const1 = get_constant_for_value_id (vrep1);
+                 if (const1)
+                   naryop1 = fold_convert (TREE_TYPE (naryop1), const1);
                }
+             result = fold_binary (nary->opcode, nary->type,
+                                   naryop0, naryop1);
              if (result && is_gimple_min_invariant (result))
                return get_or_alloc_expr_for_constant (result);
+             /* We might have simplified the expression to a
+                SSA_NAME for example from x_1 * 1.  But we cannot
+                insert a PHI for x_1 unconditionally as x_1 might
+                not be available readily.  */
              return e;
            }
+         case tcc_reference:
+           if (nary->opcode != REALPART_EXPR
+               && nary->opcode != IMAGPART_EXPR 
+               && nary->opcode != VIEW_CONVERT_EXPR)
+             return e;
+           /* Fallthrough.  */
          case tcc_unary:
+do_unary:
            {
-           /* We have to go from trees to pre exprs to value ids to
-              constants.  */
+             /* We have to go from trees to pre exprs to value ids to
+                constants.  */
              tree naryop0 = nary->op[0];
              tree const0, result;
              if (is_gimple_min_invariant (naryop0))
@@ -1146,7 +1158,6 @@ fully_constant_expression (pre_expr e)
                  const0 = fold_convert (type1, const0);
                  result = fold_unary (nary->opcode, nary->type, const0);
                }
-             
              if (result && is_gimple_min_invariant (result))
                return get_or_alloc_expr_for_constant (result);
              return e;
@@ -1745,9 +1756,8 @@ phi_translate_set (bitmap_set_t dest, bitmap_set_t set, basic_block pred,
       pre_expr translated;
       translated = phi_translate (expr, set, NULL, pred, phiblock);
 
-      /* Don't add constants or empty translations to the cache, since
-        we won't look them up that way, or use the result, anyway.  */
-      if (translated && !value_id_constant_p (get_expr_value_id (translated)))
+      /* Don't add empty translations to the cache  */
+      if (translated)
        phi_trans_add (expr, translated, pred);
 
       if (translated != NULL)
@@ -3020,23 +3030,15 @@ insert_into_preds_of_block (basic_block block, unsigned int exprnum,
             should give us back a constant with the right type.
          */
          tree constant = PRE_EXPR_CONSTANT (eprime);
-         if (TREE_TYPE (constant) != type)
+         if (!useless_type_conversion_p (type, TREE_TYPE (constant)))
            {
              tree builtexpr = fold_convert (type, constant);
-             if (is_gimple_min_invariant (builtexpr))
-               {
-                 PRE_EXPR_CONSTANT (eprime) = builtexpr;
-               }
-             else
+             if (!is_gimple_min_invariant (builtexpr)) 
                {
                  tree forcedexpr = force_gimple_operand (builtexpr,
                                                          &stmts, true,
                                                          NULL);
-                 if (is_gimple_min_invariant (forcedexpr))
-                   {
-                     PRE_EXPR_CONSTANT (eprime) = forcedexpr;
-                   }
-                 else
+                 if (!is_gimple_min_invariant (forcedexpr))
                    {
                      if (forcedexpr != builtexpr)
                        {
@@ -3222,7 +3224,7 @@ do_regular_insertion (basic_block block, basic_block dom)
          basic_block bprime;
          pre_expr eprime = NULL;
          edge_iterator ei;
-         pre_expr edoubleprime;
+         pre_expr edoubleprime = NULL;
 
          val = get_expr_value_id (expr);
          if (bitmap_set_contains_value (PHI_GEN (block), val))
@@ -3642,10 +3644,7 @@ compute_avail (void)
 
              add_to_value (get_expr_value_id (e), e);
              if (!in_fre)
-               {
-                 bitmap_insert_into_set (TMP_GEN (block), e);
-                 bitmap_value_insert_into_set (maximal_set, e);
-               }
+               bitmap_insert_into_set (TMP_GEN (block), e);
              bitmap_value_insert_into_set (AVAIL_OUT (block), e);
            }
 
@@ -3714,6 +3713,7 @@ compute_avail (void)
                    if (is_exception_related (stmt))
                      continue;
                  case tcc_binary:
+                 case tcc_comparison:
                    {
                      vn_nary_op_t nary;
                      unsigned int i;