https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112971

--- Comment #20 from JuzheZhong <juzhe.zhong at rivai dot ai> ---
Hi, Andrew.

I saw this code which seems to cause infinite loop:

  if (TREE_CODE (arg1) == VECTOR_CST
      && TREE_CODE (arg2) == VECTOR_CST
      && known_eq (TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg1)),
                   TYPE_VECTOR_SUBPARTS (TREE_TYPE (arg2))))
    {
      tree type = TREE_TYPE (arg1);
      bool step_ok_p;
      if (VECTOR_CST_STEPPED_P (arg1)
          && VECTOR_CST_STEPPED_P (arg2))
        /* We can operate directly on the encoding if:

              a3 - a2 == a2 - a1 && b3 - b2 == b2 - b1
            implies
              (a3 op b3) - (a2 op b2) == (a2 op b2) - (a1 op b1)

           Addition and subtraction are the supported operators
           for which this is true.  */
        step_ok_p = (code == PLUS_EXPR || code == MINUS_EXPR);
      else if (VECTOR_CST_STEPPED_P (arg1))
        /* We can operate directly on stepped encodings if:

             a3 - a2 == a2 - a1
           implies:
             (a3 op c) - (a2 op c) == (a2 op c) - (a1 op c)

           which is true if (x -> x op c) distributes over addition.  */
        step_ok_p = distributes_over_addition_p (code, 1);
      else
        /* Similarly in reverse.  */
        step_ok_p = distributes_over_addition_p (code, 2);
      tree_vector_builder elts;
      if (!elts.new_binary_operation (type, arg1, arg2, step_ok_p))
        return NULL_TREE;
      unsigned int count = elts.encoded_nelts ();
      for (unsigned int i = 0; i < count; ++i)
        {
          tree elem1 = VECTOR_CST_ELT (arg1, i);
          tree elem2 = VECTOR_CST_ELT (arg2, i);

          tree elt = const_binop (code, elem1, elem2);

          /* It is possible that const_binop cannot handle the given
             code and return NULL_TREE */
          if (elt == NULL_TREE)
            return NULL_TREE;
          elts.quick_push (elt);
        }

      return elts.build ();
    }

Could you give me suggestions how to fix it?

Reply via email to