OSDN Git Service

2006-10-21 Richard Guenther <rguenther@suse.de>
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 21 Oct 2006 13:23:41 +0000 (13:23 +0000)
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>
Sat, 21 Oct 2006 13:23:41 +0000 (13:23 +0000)
PR tree-optimization/3511
* tree-ssa-pre.c (phi_translate): Fold CALL_EXPRs that
got new invariant arguments during PHI translation.

* gcc.dg/tree-ssa/ssa-pre-15.c: New testcase.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@117932 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c [new file with mode: 0644]
gcc/tree-ssa-pre.c

index fdaa244..eb1c329 100644 (file)
@@ -1,5 +1,11 @@
 2006-10-21  Richard Guenther  <rguenther@suse.de>
 
+       PR tree-optimization/3511
+       * tree-ssa-pre.c (phi_translate): Fold CALL_EXPRs that
+       got new invariant arguments during PHI translation.
+
+2006-10-21  Richard Guenther  <rguenther@suse.de>
+
        PR middle-end/26898
        * fold-const.c (fold_comparison): Fold signed comparisons
        of the form X +- C1 CMP Y +- C2.
index 55d336c..c30830d 100644 (file)
@@ -1,5 +1,10 @@
 2006-10-21  Richard Guenther  <rguenther@suse.de>
 
+       PR tree-optimization/3511
+       * gcc.dg/tree-ssa/ssa-pre-15.c: New testcase.
+
+2006-10-21  Richard Guenther  <rguenther@suse.de>
+
        PR middle-end/26898
        * gcc.dg/torture/pr26898-1.c: New testcase.
        * gcc.dg/torture/pr26898-2.c: Likewise.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-pre-15.c
new file mode 100644 (file)
index 0000000..518fda8
--- /dev/null
@@ -0,0 +1,16 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+/* Verify we PRE the strlen call, as strlen("") folds to zero.  */
+
+extern __SIZE_TYPE__ strlen (const char *);
+
+__SIZE_TYPE__ mystrlen (const char *s)
+{
+  if (!s)
+    s = "";
+  return strlen(s);
+}
+
+/* { dg-final { scan-tree-dump "= 0;" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
index 9c7b89f..ba32b3c 100644 (file)
@@ -1076,6 +1076,7 @@ phi_translate (tree expr, value_set_t set, basic_block pred,
            tree newexpr;
            tree vh = get_value_handle (expr);
            bool listchanged = false;
+           bool invariantarg = false;
            VEC (tree, gc) *vuses = VALUE_HANDLE_VUSES (vh);
            VEC (tree, gc) *tvuses;
 
@@ -1134,10 +1135,26 @@ phi_translate (tree expr, value_set_t set, basic_block pred,
                    if (newval != oldval)
                      {
                        listchanged = true;
+                       invariantarg |= is_gimple_min_invariant (newval);
                        TREE_VALUE (newwalker) = get_value_handle (newval);
                      }
                  }
              }
+
+           /* In case of new invariant args we might try to fold the call
+              again.  */
+           if (invariantarg)
+             {
+               tree tmp = fold_ternary (CALL_EXPR, TREE_TYPE (expr),
+                                        newop0, newarglist, newop2);
+               if (tmp)
+                 {
+                   STRIP_TYPE_NOPS (tmp);
+                   if (is_gimple_min_invariant (tmp))
+                     return tmp;
+                 }
+             }
+
            if (listchanged)
              vn_lookup_or_add (newarglist, NULL);