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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Better is the following, but the way get_computation_aff_1 works we'll end up
losing all pointer bases which can be seen in gcc.dg/tree-ssa/loop-19.c which
then produces

  _1 = (sizetype) &a;
  _6 = &MEM <vector(2) double> [(double *)0B + _1 + ivtmp.13_3 * 1];

which is btw the effect if we'd just assume there's no pointer base (the
other way of trying to "fix" this).

This also shows that the patch below misses (a long standing issue) to
handle the mixed type affine combinations that result from POINTER_PLUS_EXPR
handling which currently does just

    case POINTER_PLUS_EXPR:
      tree_to_aff_combination (op0, type, comb);
      tree_to_aff_combination (op1, sizetype, &tmp);
      aff_combination_add (comb, &tmp);

there's no POINTER_DIFF_EXPR handling yet.  In short, it's a bit of a mess.
get_computation_aff_1 should probably see to preserve use->iv->base and
we should only accept the same original base then when building the
TMR from the computation with the new IV or fall back to sth like above.

diff --git a/gcc/tree-affine.cc b/gcc/tree-affine.cc
index b5b7249c675..eb42bf2e5b3 100644
--- a/gcc/tree-affine.cc
+++ b/gcc/tree-affine.cc
@@ -32,6 +32,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "dumpfile.h"
 #include "cfgexpand.h"
 #include "value-query.h"
+#include "tree-ssa.h"

 /* Extends CST as appropriate for the affine combinations COMB.  */

@@ -237,7 +238,7 @@ aff_combination_convert (aff_tree *comb, tree type)
   if (comb->rest && !POINTER_TYPE_P (type))
     comb->rest = fold_convert (type, comb->rest);

-  if (TYPE_PRECISION (type) == TYPE_PRECISION (comb_type))
+  if (useless_type_conversion_p (type, comb_type))
     return;

   comb->offset = wide_int_ext_for_comb (comb->offset, comb->type);
@@ -246,7 +247,8 @@ aff_combination_convert (aff_tree *comb, tree type)
       if (comb->elts[i].coef == 0)
        continue;
       comb->elts[j].coef = comb->elts[i].coef;
-      comb->elts[j].val = fold_convert (type, comb->elts[i].val);
+      if (!POINTER_TYPE_P (type))
+       comb->elts[j].val = fold_convert (type, comb->elts[i].val);
       j++;
     }

@@ -312,10 +314,10 @@ expr_to_aff_combination (aff_tree *comb, tree_code code,
tree type,
        tree itype = TREE_TYPE (inner);
        enum tree_code icode = TREE_CODE (inner);

-       /* STRIP_NOPS  */
        if (tree_nop_conversion_p (otype, itype))
          {
-           tree_to_aff_combination (op0, type, comb);
+           tree_to_aff_combination (op0, itype, comb);
+           aff_combination_convert (comb, type);
            return true;
          }

@@ -394,7 +396,7 @@ tree_to_aff_combination (tree expr, tree type, aff_tree
*comb)
   machine_mode mode;
   int unsignedp, reversep, volatilep;

-  STRIP_NOPS (expr);
+  STRIP_USELESS_TYPE_CONVERSION (expr);

   code = TREE_CODE (expr);
   switch (code)

Reply via email to