This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

prepare_decl_rtl in tree-ssa-loop-ivopts.c doesn't work with (ADDR_EXPR (ARRAY_REF))?


Hi,
Currently tree-ssa-loop-ivopts.c doesn't calculate addr_expr's cost,
while uses target_spill_cost instead, as in function
force_expr_to_var_cost. When I experimented with ivopts by calling
computation_cost to calculate cost of ADDR_EXPR, I encountered assert
failure in expand_expr_addr_expr_1, because:
0) The failure comes with (ADDR_EXPR (ARRAY_REF (local_var_decl)));
1) computation_cost calls walk_tree/prepare_decl_rtl to prepare
RTX_REG for variables in ADDR_EXPR, which is the local_var_decl;
2) computation_cost calls expand_expr to do the expanding work.
3) function expand_expr_addr_expr_1 returns the RTX_REG as the result
of expanding, which violates the assertion "gcc_assert (MEM_P
(result))". The corresponding code in expand_expr_addr_expr_1 is like
:

    default:
      /* If the object is a DECL, then expand it for its rtl.  Don't bypass
     expand_expr, as that can have various side effects; LABEL_DECLs for
     example, may not have their DECL_RTL set yet.  Expand the rtl of
     CONSTRUCTORs too, which should yield a memory reference for the
     constructor's contents.  Assume language specific tree nodes can
     be expanded in some interesting way.  */
      gcc_assert (TREE_CODE (exp) < LAST_AND_UNUSED_TREE_CODE);
      if (DECL_P (exp)
      || TREE_CODE (exp) == CONSTRUCTOR
      || TREE_CODE (exp) == COMPOUND_LITERAL_EXPR)
    {
      result = expand_expr (exp, target, tmode,
                modifier == EXPAND_INITIALIZER
                ? EXPAND_INITIALIZER : EXPAND_CONST_ADDRESS);

      /* If the DECL isn't in memory, then the DECL wasn't properly
         marked TREE_ADDRESSABLE, which will be either a front-end
         or a tree optimizer bug.  */

      if (TREE_ADDRESSABLE (exp)
          && ! MEM_P (result)
          && ! targetm.calls.allocate_stack_slots_for_args())
        {
          error ("local frame unavailable (naked function?)");
          return result;
        }
      else
        gcc_assert (MEM_P (result));
      result = XEXP (result, 0);

      /* ??? Is this needed anymore?  */
      if (DECL_P (exp))
        TREE_USED (exp) = 1;

      if (modifier != EXPAND_INITIALIZER
          && modifier != EXPAND_CONST_ADDRESS
          && modifier != EXPAND_SUM)
        result = force_operand (result, target);
      return result;
    }

So the question is
Is it as expected that cost of ADDR_EXPR cannot be calculated by
computation_cost? Or the assertion is because of immature
computation_cost/prepare_decl_rtl?

I am not sure whether I described the problem clearly, please feel
free to ask for more information. Thanks for your patience.

--
Best Regards.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]