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

[tree-ssa] Patch: where to fix this?


This prevents constant propagation from producing trees with
mismatched types.  Bootstrapped, tested, all SPECmarks work
as well as without this patch.
Original thread reference:
http://gcc.gnu.org/ml/gcc/2003-12/msg01114.html

2004-01-14  Dale Johannesen  <dalej@apple.com>
        * tree-ssa-dom.c (cprop_into_stmt):  Add convert() call
        to prevent type mismatches.

Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-ssa-dom.c,v
retrieving revision 1.1.2.102
diff -u -d -b -w -c -3 -p -r1.1.2.102 tree-ssa-dom.c
cvs server: conflicting specifications of output style
*** tree-ssa-dom.c      19 Dec 2003 07:01:36 -0000      1.1.2.102
--- tree-ssa-dom.c      8 Jan 2004 19:49:55 -0000
*************** cprop_into_stmt (tree stmt)
*** 1809,1814 ****
--- 1809,1823 ----
                      && is_gimple_min_invariant (val)))
                may_have_exposed_new_symbols = true;

+               /* Make sure basic types match.  We cannot substitute a
+                  boolean for an int for example, fold() doesn't
+                  handle this as we would like.  But don't insert
+                gratuitous casts for SSA_NAMEs, this results in
+                aliasing info getting lost.  */
+               if (TREE_TYPE (*op_p) != TREE_TYPE (val)
+                 && TREE_CODE (val) != SSA_NAME)
+                 val = convert (TREE_TYPE (*op_p), val);
+
              propagate_value (op_p, val);

/* And note that we modified this statement. This is now

=====Testcase:

/* Test that (p!=0) + (q!=0) is computed as int,
   not boolean */
/* { dg-options "-O3 } */
char *foo(char *p, char *q) {
   int x = (p !=0) + (q != 0);
   if (x==2)  return "a"; else return 0;
}
extern char *bar(char*, char*) __attribute__((noinline));
char *bar(char *first, char *last)
{
  int y;
  if (!first)  return last;
  if (!last)   return first;
  if (*first == 'a')
    return foo(first, last);
  return 0;
}
main() {
  char *p = "a", *q = "b";
  if (p)
    if (bar(p,q))
      return 0;
  abort();
}


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