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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2017-08-08
          Component|c++                         |middle-end
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
We are not able to analyze the number of iterations and end up vectorizing the
function.

t.C:12:19: note: Symbolic number of iterations is (((unsigned long) __for_end_6
- (unsigned long) ((const int *) __for_range_5 + 4)) /[ex] 4 &
4611686018427387903) + 1


  <bb 2> [15.00%]:
  __for_range_5 = &this_4(D)->items;
  __for_end_6 = &MEM[(void *)this_4(D) + 8B];

  <bb 3> [85.00%]:
  # total_11 = PHI <total_9(4), 0(2)>
  # __for_begin_14 = PHI <__for_begin_10(4), __for_range_5(2)>
  item_8 = *__for_begin_14;
  total_9 = item_8 + total_11;
  __for_begin_10 = __for_begin_14 + 4;
  if (__for_end_6 == __for_begin_10)
    goto <bb 5>; [15.00%]
  else
    goto <bb 4>; [85.00%]

  <bb 4> [72.25%]:
  goto <bb 3>; [100.00%]

  <bb 5> [15.00%]:
  # total_12 = PHI <total_9(3)>

it looks like expand_simple_operations fails to handle ADDR_EXPR in

  e = gimple_assign_rhs1 (stmt);
  code = gimple_assign_rhs_code (stmt);
  if (get_gimple_rhs_class (code) == GIMPLE_SINGLE_RHS)
    {
      if (is_gimple_min_invariant (e))
        return e;

      if (code == SSA_NAME)
        return expand_simple_operations (e, stop);

      return expr;
    }

but when it is sth that just mimics a POINTER_PLUS_EXPR it should.

Index: gcc/tree-ssa-loop-niter.c
===================================================================
--- gcc/tree-ssa-loop-niter.c   (revision 250813)
+++ gcc/tree-ssa-loop-niter.c   (working copy)
@@ -42,6 +42,7 @@ along with GCC; see the file COPYING3.
 #include "tree-chrec.h"
 #include "tree-scalar-evolution.h"
 #include "params.h"
+#include "tree-dfa.h"


 /* The maximum number of dominator BBs we search for conditions
@@ -1980,6 +1981,21 @@ expand_simple_operations (tree expr, tre

       if (code == SSA_NAME)
        return expand_simple_operations (e, stop);
+      else if (code == ADDR_EXPR)
+       {
+         HOST_WIDE_INT offset;
+         tree base = get_addr_base_and_unit_offset (TREE_OPERAND (e, 0),
+                                                    &offset);
+         if (base
+             && TREE_CODE (base) == MEM_REF)
+           {
+             ee = expand_simple_operations (TREE_OPERAND (base, 0), stop);
+             return fold_build2 (POINTER_PLUS_EXPR, TREE_TYPE (expr), ee,
+                                 wide_int_to_tree (sizetype,
+                                                   mem_ref_offset (base)
+                                                   + offset));
+           }
+       }

       return expr;
     }

Reply via email to