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]

[cond-optab, trunk] fold &f != 0 better


I noticed that a common failure on cond-optab (e500, m32r, mcore) was on
pr27150-1.c.  This is a failure to optimize

int g(int f)
{
  return (&f)!=0;
}

The reason is that there is more straight-line coding on cond-optab and
this confuses combine, which is no longer able to optimize it.  But I
decided to treat it as a missed tree optimization, fixing it with the
following patch.

I tested that the modified testcase fails on cond-optab without the
patch, and passes with it.

Bootstrap/regtest in progress, ok for trunk when it finishes?

Paolo

2009-04-09  Paolo Bonzini  <bonzini@gnu.org>

        * fold-const.c (tree_single_nonzero_warnv_p): Always treat decls
        for things others than variables or functions as nonzero.

2009-04-09  Paolo Bonzini  <bonzini@gnu.org>

        * gcc.dg/pr27150-1.c: Change to a link test.

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c    (branch cond-optab)
+++ gcc/fold-const.c    (working copy)
@@ -15011,8 +15011,8 @@ tree_single_nonzero_warnv_p (tree t, boo
          return false;

        /* Weak declarations may link to NULL.  */
-       if (VAR_OR_FUNCTION_DECL_P (base))
-         return !DECL_WEAK (base);
+       if (DECL_P (base))
+         return !VAR_OR_FUNCTION_DECL_P (base) || !DECL_WEAK (base);

        /* Constants are never weak.  */
        if (CONSTANT_CLASS_P (base))
Index: gcc/testsuite/gcc.dg/pr27150-1.c
===================================================================
--- gcc/testsuite/gcc.dg/pr27150-1.c    (branch cond-optab)
+++ gcc/testsuite/gcc.dg/pr27150-1.c    (working copy)
@@ -1,7 +1,9 @@
 /* { dg-do compile } */
 /* { dg-options "-O2" } */
+extern int link_error ();
 int g(int f)
 {
-  return (&f)!=0;
+  int a = ((&f)!=0);
+  if (a) link_error ();
+  return a;
 }
-


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