https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125730
--- Comment #12 from Richard Biener <rguenth at gcc dot gnu.org> ---
So this is also a missed optimization, while SCEV analyzes
*_5 = fetched_Value.1_6;
(get_scalar_evolution
(scalar = _5)
(scalar_evolution = {values_16(D) + ((unsigned long) first_kw_arg_12 -
(unsigned long) argnames_11(D)), +, 8}_1))
so a base with pointer type and correct "base", IVOPTs later has use->iv->base
as
(char * * *) (((unsigned long) first_kw_arg_12 + (unsigned long)
values_16(D)) - (unsigned long) argnames_11(D))
which happens in alloc_iv where we do
/* Canonicalize the address expression in base if it were an unsigned
computation. That leads to more equalities being detected and results in:
1) More accurate cost can be computed for address expressions;
2) Duplicate candidates won't be created for bases in different
forms, like &a[0] and &a.
3) Duplicate candidates won't be created for IV expressions that differ
only in their sign. */
aff_tree comb;
STRIP_NOPS (expr);
expr = fold_convert (unsigned_type_for (TREE_TYPE (expr)), expr);
tree_to_aff_combination (expr, TREE_TYPE (expr), &comb);
base = fold_convert (TREE_TYPE (base), aff_combination_to_tree (&comb));
that loses relevant information. The following avoids this:
diff --git a/gcc/tree-ssa-loop-ivopts.cc b/gcc/tree-ssa-loop-ivopts.cc
index 4ca55325188..bbd3cfaab24 100644
--- a/gcc/tree-ssa-loop-ivopts.cc
+++ b/gcc/tree-ssa-loop-ivopts.cc
@@ -1162,8 +1162,8 @@ alloc_iv (struct ivopts_data *data, tree base, tree step,
sizeof (struct iv));
gcc_assert (step != NULL_TREE);
- /* Canonicalize the address expression in base if it were an unsigned
- computation. That leads to more equalities being detected and results
in:
+ /* Canonicalize the address expression in base.
+ That leads to more equalities being detected and results in:
1) More accurate cost can be computed for address expressions;
2) Duplicate candidates won't be created for bases in different
@@ -1171,10 +1171,8 @@ alloc_iv (struct ivopts_data *data, tree base, tree
step,
3) Duplicate candidates won't be created for IV expressions that differ
only in their sign. */
aff_tree comb;
- STRIP_NOPS (expr);
- expr = fold_convert (unsigned_type_for (TREE_TYPE (expr)), expr);
tree_to_aff_combination (expr, TREE_TYPE (expr), &comb);
- base = fold_convert (TREE_TYPE (base), aff_combination_to_tree (&comb));
+ base = aff_combination_to_tree (&comb);
iv->base = base;
iv->base_object = determine_base_object (data, base);