This is the mail archive of the gcc-bugs@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]

[Bug tree-optimization/80153] ivopt generate wrong code


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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
The reason for the tree-affine oddity is that IVO calls

#0  tree_to_aff_combination (expr=<addr_expr 0x7ffff69c3fe0>, 
    type=<integer_type 0x7ffff68b73f0>, comb=0x7fffffffd310)

that is, tree_to_aff_combination with a mismatched expr/type.  For example from
alloc_iv:

1174          tree_to_aff_combination (expr, TREE_TYPE (base), &comb);
1175          base = fold_convert (TREE_TYPE (base), aff_combination_to_tree
(&comb));

that's unexpected.  But the problematic case happens where IVO does right:

Breakpoint 7, tree_to_aff_combination (expr=<nop_expr 0x7ffff69c3300>, 
    type=<integer_type 0x7ffff68b73f0>, comb=0x7fffffffd4a0)

but tree_to_aff_combination calls STRIP_NOPS on expr which is (unsigned int)
"oops!\n" and thus creates the above problematical case itself.

We can either avoid stripping the nops or deal with the appearant mismatch
by converting back the elts we add to 'type'.  I think instrumenting to
see whether we can assert tree_to_aff_combination gets matched types passed
(so we can eliminate the type arg) would be nice - we certainly can't handle
all kind of mismatches sanely.

Then using STRIP_SIGN_NOPS would be safe but IIRC removing sign conversions
was intentional (though even that might be problematic).  tree-affine was
really designed for addresses (so type would always be a pointer).

So sth like the following should better pass bootstrap / test (IVO will trigger
the assert) but it might require adding some "safe" cases to not regress
code quality (not sure if we have testcases):

Index: gcc/tree-affine.c
===================================================================
--- gcc/tree-affine.c   (revision 246414)
+++ gcc/tree-affine.c   (working copy)
@@ -261,12 +261,21 @@ tree_to_aff_combination (tree expr, tree
   HOST_WIDE_INT bitpos, bitsize;
   machine_mode mode;
   int unsignedp, reversep, volatilep;
+  tree exptype = TREE_TYPE (expr);

-  STRIP_NOPS (expr);
+  gcc_checking_assert (tree_nop_conversion_p (type, exptype)
+                      && TYPE_UNSIGNED (type) == TYPE_UNSIGNED (exptype)
+                      && POINTER_TYPE_P (type) == POINTER_TYPE_P (exptype));
+
+  STRIP_SIGN_NOPS (expr);

   code = TREE_CODE (expr);
   switch (code)
     {
+    CASE_CONVERT:
+      /* Add safe cases.  */
+      break;
+
     case INTEGER_CST:
       aff_combination_const (comb, type, wi::to_widest (expr));
       return;

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