patches/gcc/4.3.2/360-fix-expensive-optimize.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Sun Apr 19 16:17:11 2009 +0000 (2009-04-19)
branchnewlib
changeset 1365 c4d124ed9f8e
permissions -rw-r--r--
Update the newlib devel branch with stuf from /trunk.

-------- diffstat follows --------
/devel/newlib/configure | 8 4 4 0
/devel/newlib/scripts/build/kernel/linux.sh | 2 1 1 0
/devel/newlib/scripts/build/cc/gcc.sh | 34 22 12 0 +
/devel/newlib/scripts/build/debug/300-gdb.sh | 52 45 7 0 +
/devel/newlib/scripts/build/libc/uClibc.sh | 6 3 3 0
/devel/newlib/scripts/build/mpfr.sh | 2 1 1 0
/devel/newlib/scripts/crosstool-NG.sh.in | 20 18 2 0 +
/devel/newlib/scripts/functions | 44 34 10 0 +
/devel/newlib/patches/glibc/2_9/500-ppc-glibc-2.9-atomic.patch | 414 0 414 0 ----------
/devel/newlib/patches/glibc/2_9/140-regex-BZ9697.patch | 111 0 111 0 ---
/devel/newlib/patches/glibc/2_9/190-queue-header-updates.patch | 89 0 89 0 --
/devel/newlib/patches/glibc/2_9/370-hppa_glibc-2.7-hppa-nptl-carlos.patch | 249 0 249 0 ------
/devel/newlib/patches/glibc/2_9/450-alpha-glibc-2.5-no-page-header.patch | 32 0 32 0 -
/devel/newlib/patches/glibc/2_9/330-2.3.3-china.patch | 35 0 35 0 -
/devel/newlib/patches/glibc/2_9/270-ldbl-nexttowardf.patch | 68 0 68 0 --
/devel/newlib/patches/glibc/2_9/410-2.9-fnmatch.patch | 64 0 64 0 --
/devel/newlib/patches/glibc/2_9/340-new-valencian-locale.patch | 120 0 120 0 ---
/devel/newlib/patches/glibc/2_9/350-2.4-undefine-__i686.patch | 47 0 47 0 -
/devel/newlib/patches/glibc/2_9/160-i386-x86_64-revert-clone-cfi.patch | 53 0 53 0 -
/devel/newlib/patches/glibc/2_9/150-regex-BZ697.patch | 28 0 28 0 -
/devel/newlib/patches/glibc/2_9/420-dont-build-timezone.patch | 19 0 19 0 -
/devel/newlib/patches/glibc/2_9/290-no-inline-gmon.patch | 38 0 38 0 -
/devel/newlib/patches/glibc/2_9/280-section-comments.patch | 29 0 29 0 -
/devel/newlib/patches/glibc/2_9/180-math-tests.patch | 72 0 72 0 --
/devel/newlib/patches/glibc/2_9/250-resolv-dynamic.patch | 44 0 44 0 -
/devel/newlib/patches/glibc/2_9/120-_nss_dns_gethostbyaddr2_r-check-and-adjust-the-buffer-alignment.patch | 35 0 35 0 -
/devel/newlib/patches/glibc/2_9/300-2.9-check_native-headers.patch | 22 0 22 0 -
/devel/newlib/patches/glibc/2_9/130-add_prio-macros.patch | 26 0 26 0 -
/devel/newlib/patches/glibc/2_9/310-2.3.6-fix-pr631.patch | 50 0 50 0 -
/devel/newlib/patches/glibc/2_9/510-sh-no-asm-user-header.patch | 70 0 70 0 --
/devel/newlib/patches/glibc/2_9/260-fadvise64_64.patch | 30 0 30 0 -
/devel/newlib/patches/glibc/2_9/440-alpha-glibc-2.4-xstat.patch | 249 0 249 0 ------
/devel/newlib/patches/glibc/2_9/170-2.10-dns-no-gethostbyname4.patch | 35 0 35 0 -
/devel/newlib/patches/glibc/2_9/230-2.3.3-localedef-fix-trampoline.patch | 74 0 74 0 --
/devel/newlib/patches/glibc/2_9/480-alpha-glibc-2.8-cache-shape.patch | 18 0 18 0 -
/devel/newlib/patches/glibc/2_9/360-2.8-nscd-one-fork.patch | 45 0 45 0 -
/devel/newlib/patches/glibc/2_9/210-2.9-strlen-hack.patch | 109 0 109 0 ---
/devel/newlib/patches/glibc/2_9/320-2.9-assume-pipe2.patch | 59 0 59 0 -
/devel/newlib/patches/glibc/2_9/100-ssp-compat.patch | 193 0 193 0 -----
/devel/newlib/patches/glibc/2_9/110-respect-env-CPPFLAGS.patch | 30 0 30 0 -
/devel/newlib/patches/glibc/2_9/220-manual-no-perl.patch | 29 0 29 0 -
/devel/newlib/patches/glibc/2_9/390-2.3.3_pre20040117-pt_pax.patch | 35 0 35 0 -
/devel/newlib/patches/glibc/2_9/460-alpha-glibc-2.5-no-asm-elf-header.patch | 38 0 38 0 -
/devel/newlib/patches/glibc/2_9/400-tests-sandbox-libdl-paths.patch | 198 0 198 0 -----
/devel/newlib/patches/glibc/2_9/520-sh-no-asm-elf-header.patch | 27 0 27 0 -
/devel/newlib/patches/glibc/2_9/240-i386-LOAD_PIC_REG.patch | 23 0 23 0 -
/devel/newlib/patches/glibc/2_9/200-awk-in-C-locale.patch | 23 0 23 0 -
/devel/newlib/patches/glibc/2_9/430-2.7-cross-compile-nptl.patch | 57 0 57 0 -
/devel/newlib/patches/glibc/2_9/380-2.3.6-dl_execstack-PaX-support.patch | 71 0 71 0 --
/devel/newlib/patches/glibc/2_9/490-ptr-mangling.patch | 114 0 114 0 ---
/devel/newlib/patches/glibc/2_9/470-alpha-glibc-2.8-creat.patch | 19 0 19 0 -
/devel/newlib/patches/glibc/ports-2_9/100-arm_linux_tls.patch | 14 0 14 0 -
/devel/newlib/patches/uClibc/0.9.30.1/140-gnu89-inline.patch | 2 1 1 0
/devel/newlib/docs/known-issues.txt | 16 15 1 0 +
/devel/newlib/docs/overview.txt | 2 1 1 0
/devel/newlib/samples/armeb-unknown-linux-uclibc/uClibc-0.9.30.config | 243 0 243 0 ------
/devel/newlib/samples/armeb-unknown-linux-uclibc/crosstool.config | 78 55 23 0 +-
/devel/newlib/samples/sh4-unknown-linux-gnu/crosstool.config | 35 18 17 0 +
/devel/newlib/samples/x86_64-unknown-linux-gnu/crosstool.config | 104 68 36 0 +--
/devel/newlib/samples/arm-unknown-elf/crosstool.config | 54 47 7 0 +
/devel/newlib/samples/armeb-unknown-eabi/crosstool.config | 54 47 7 0 +
/devel/newlib/samples/arm-unknown-linux-gnueabi/crosstool.config | 113 73 40 0 +--
/devel/newlib/samples/ia64-unknown-linux-gnu/crosstool.config | 91 61 30 0 +-
/devel/newlib/samples/x86_64-unknown-linux-uclibc/uClibc-0.9.30.config | 245 0 245 0 ------
/devel/newlib/samples/x86_64-unknown-linux-uclibc/crosstool.config | 78 55 23 0 +-
/devel/newlib/samples/armeb-unknown-linux-gnueabi/crosstool.config | 105 69 36 0 +--
/devel/newlib/samples/powerpc-e500v2-linux-gnuspe/crosstool.config | 96 63 33 0 +-
/devel/newlib/samples/i686-nptl-linux-gnu/crosstool.config | 78 48 30 0 +-
/devel/newlib/samples/arm-unknown-linux-gnu/crosstool.config | 105 69 36 0 +--
/devel/newlib/samples/powerpc-unknown-linux-gnu/crosstool.config | 103 67 36 0 +-
/devel/newlib/samples/mips-unknown-linux-uclibc/uClibc-0.9.30.config | 254 0 254 0 ------
/devel/newlib/samples/mips-unknown-linux-uclibc/crosstool.config | 77 54 23 0 +-
/devel/newlib/samples/arm-unknown-linux-uclibcgnueabi/uClibc-0.9.30.config | 253 0 253 0 ------
/devel/newlib/samples/arm-unknown-linux-uclibcgnueabi/crosstool.config | 78 55 23 0 +-
/devel/newlib/samples/arm-iphone-linux-gnueabi/crosstool.config | 84 57 27 0 +-
/devel/newlib/samples/armeb-unknown-linux-gnu/crosstool.config | 105 69 36 0 +--
/devel/newlib/samples/powerpc-unknown_nofpu-linux-gnu/crosstool.config | 104 68 36 0 +--
/devel/newlib/samples/i586-geode-linux-uclibc/uClibc-0.9.30.config | 263 0 263 0 ------
/devel/newlib/samples/i586-geode-linux-uclibc/crosstool.config | 78 55 23 0 +-
/devel/newlib/samples/arm-unknown-linux-uclibc/uClibc-0.9.30.config | 253 0 253 0 ------
/devel/newlib/samples/arm-unknown-linux-uclibc/crosstool.config | 78 55 23 0 +-
/devel/newlib/samples/powerpc-unknown-linux-uclibc/uClibc-0.9.30.config | 248 0 248 0 ------
/devel/newlib/samples/powerpc-unknown-linux-uclibc/crosstool.config | 77 54 23 0 +-
/devel/newlib/samples/mips-unknown-elf/crosstool.config | 54 47 7 0 +
/devel/newlib/samples/powerpc-405-linux-gnu/crosstool.config | 104 68 36 0 +--
/devel/newlib/samples/armeb-unknown-linux-uclibcgnueabi/crosstool.config | 26 13 13 0
/devel/newlib/samples/arm-unknown-eabi/crosstool.config | 54 47 7 0 +
/devel/newlib/samples/mipsel-unknown-linux-gnu/crosstool.config | 104 68 36 0 +--
/devel/newlib/samples/powerpc64-unknown-linux-gnu/crosstool.config | 75 49 26 0 +-
/devel/newlib/samples/alphaev56-unknown-linux-gnu/crosstool.config | 94 63 31 0 +-
/devel/newlib/samples/powerpc-860-linux-gnu/crosstool.config | 102 67 35 0 +-
/devel/newlib/config/kernel/linux.in | 87 46 41 0 +-
/devel/newlib/config/cc/gcc.in | 35 30 5 0 +
/devel/newlib/config/debug/gdb.in | 2 1 1 0
94 files changed, 1851 insertions(+), 5813 deletions(-)
yann@1183
     1
PR tree-optimization/32044
yann@1183
     2
yann@1183
     3
From: rakdver
yann@1183
     4
Date: 2008-12-12 21:32:47 +0100
yann@1183
     5
yann@1183
     6
* tree-scalar-evolution.h (expression_expensive_p): Declare.
yann@1183
     7
* tree-scalar-evolution.c (expression_expensive_p): New function.
yann@1183
     8
(scev_const_prop): Avoid introducing expensive expressions.
yann@1183
     9
* tree-ssa-loop-ivopts.c (may_eliminate_iv): Ditto.
yann@1183
    10
yann@1183
    11
* gcc.dg/pr34027-1.c: Change outcome.
yann@1183
    12
* gcc.dg/tree-ssa/pr32044.c: New test.
yann@1183
    13
yann@1183
    14
cherry picked from svn://gcc.gnu.org/svn/gcc/trunk, rev 142719 and adapted to
yann@1183
    15
apply on gcc 4.3.2
yann@1183
    16
yann@1183
    17
------------------------------------------------------------------------
yann@1183
    18
Index: gcc-4.3.2/gcc/tree-scalar-evolution.c
yann@1183
    19
===================================================================
yann@1183
    20
--- gcc-4.3.2.orig/gcc/tree-scalar-evolution.c	2009-01-28 10:14:37.000000000 +0100
yann@1183
    21
+++ gcc-4.3.2/gcc/tree-scalar-evolution.c	2009-01-28 10:17:50.000000000 +0100
yann@1183
    22
@@ -2716,6 +2716,50 @@
yann@1183
    23
   scalar_evolution_info = NULL;
yann@1183
    24
 }
yann@1183
    25
 
yann@1183
    26
+/* Returns true if the expression EXPR is considered to be too expensive
yann@1183
    27
+   for scev_const_prop.  */
yann@1183
    28
+
yann@1183
    29
+bool
yann@1183
    30
+expression_expensive_p (tree expr)
yann@1183
    31
+{
yann@1183
    32
+  enum tree_code code;
yann@1183
    33
+
yann@1183
    34
+  if (is_gimple_val (expr))
yann@1183
    35
+    return false;
yann@1183
    36
+
yann@1183
    37
+  code = TREE_CODE (expr);
yann@1183
    38
+  if (code == TRUNC_DIV_EXPR
yann@1183
    39
+      || code == CEIL_DIV_EXPR
yann@1183
    40
+      || code == FLOOR_DIV_EXPR
yann@1183
    41
+      || code == ROUND_DIV_EXPR
yann@1183
    42
+      || code == TRUNC_MOD_EXPR
yann@1183
    43
+      || code == CEIL_MOD_EXPR
yann@1183
    44
+      || code == FLOOR_MOD_EXPR
yann@1183
    45
+      || code == ROUND_MOD_EXPR
yann@1183
    46
+      || code == EXACT_DIV_EXPR)
yann@1183
    47
+    {
yann@1183
    48
+      /* Division by power of two is usually cheap, so we allow it.
yann@1183
    49
+	 Forbid anything else.  */
yann@1183
    50
+      if (!integer_pow2p (TREE_OPERAND (expr, 1)))
yann@1183
    51
+	return true;
yann@1183
    52
+    }
yann@1183
    53
+
yann@1183
    54
+  switch (TREE_CODE_CLASS (code))
yann@1183
    55
+    {
yann@1183
    56
+    case tcc_binary:
yann@1183
    57
+    case tcc_comparison:
yann@1183
    58
+      if (expression_expensive_p (TREE_OPERAND (expr, 1)))
yann@1183
    59
+	return true;
yann@1183
    60
+
yann@1183
    61
+      /* Fallthru.  */
yann@1183
    62
+    case tcc_unary:
yann@1183
    63
+      return expression_expensive_p (TREE_OPERAND (expr, 0));
yann@1183
    64
+
yann@1183
    65
+    default:
yann@1183
    66
+      return true;
yann@1183
    67
+    }
yann@1183
    68
+}
yann@1183
    69
+
yann@1183
    70
 /* Replace ssa names for that scev can prove they are constant by the
yann@1183
    71
    appropriate constants.  Also perform final value replacement in loops,
yann@1183
    72
    in case the replacement expressions are cheap.
yann@1183
    73
@@ -2802,12 +2846,6 @@
yann@1183
    74
 	continue;
yann@1183
    75
 
yann@1183
    76
       niter = number_of_latch_executions (loop);
yann@1183
    77
-      /* We used to check here whether the computation of NITER is expensive,
yann@1183
    78
-	 and avoided final value elimination if that is the case.  The problem
yann@1183
    79
-	 is that it is hard to evaluate whether the expression is too
yann@1183
    80
-	 expensive, as we do not know what optimization opportunities the
yann@1183
    81
-	 the elimination of the final value may reveal.  Therefore, we now
yann@1183
    82
-	 eliminate the final values of induction variables unconditionally.  */
yann@1183
    83
       if (niter == chrec_dont_know)
yann@1183
    84
 	continue;
yann@1183
    85
 
yann@1183
    86
@@ -2838,7 +2876,15 @@
yann@1183
    87
 	      /* Moving the computation from the loop may prolong life range
yann@1183
    88
 		 of some ssa names, which may cause problems if they appear
yann@1183
    89
 		 on abnormal edges.  */
yann@1183
    90
-	      || contains_abnormal_ssa_name_p (def))
yann@1183
    91
+	      || contains_abnormal_ssa_name_p (def)
yann@1183
    92
+	      /* Do not emit expensive expressions.  The rationale is that
yann@1183
    93
+		 when someone writes a code like
yann@1183
    94
+
yann@1183
    95
+		 while (n > 45) n -= 45;
yann@1183
    96
+
yann@1183
    97
+		 he probably knows that n is not large, and does not want it
yann@1183
    98
+		 to be turned into n %= 45.  */
yann@1183
    99
+	      || expression_expensive_p (def))
yann@1183
   100
 	    continue;
yann@1183
   101
 
yann@1183
   102
 	  /* Eliminate the PHI node and replace it by a computation outside
yann@1183
   103
Index: gcc-4.3.2/gcc/tree-scalar-evolution.h
yann@1183
   104
===================================================================
yann@1183
   105
--- gcc-4.3.2.orig/gcc/tree-scalar-evolution.h	2009-01-28 10:22:47.000000000 +0100
yann@1183
   106
+++ gcc-4.3.2/gcc/tree-scalar-evolution.h	2009-01-28 10:23:10.000000000 +0100
yann@1183
   107
@@ -35,6 +35,7 @@
yann@1183
   108
 extern void scev_analysis (void);
yann@1183
   109
 unsigned int scev_const_prop (void);
yann@1183
   110
 
yann@1183
   111
+bool expression_expensive_p (tree);
yann@1183
   112
 extern bool simple_iv (struct loop *, tree, tree, affine_iv *, bool);
yann@1183
   113
 
yann@1183
   114
 /* Returns the loop of the polynomial chrec CHREC.  */
yann@1183
   115
Index: gcc-4.3.2/gcc/testsuite/gcc.dg/pr34027-1.c
yann@1183
   116
===================================================================
yann@1183
   117
--- gcc-4.3.2.orig/gcc/testsuite/gcc.dg/pr34027-1.c	2009-01-28 10:24:09.000000000 +0100
yann@1183
   118
+++ gcc-4.3.2/gcc/testsuite/gcc.dg/pr34027-1.c	2009-01-28 10:24:43.000000000 +0100
yann@1183
   119
@@ -8,5 +8,9 @@
yann@1183
   120
   return ns;
yann@1183
   121
 }
yann@1183
   122
 
yann@1183
   123
-/* { dg-final { scan-tree-dump "ns % 10000" "optimized" } } */
yann@1183
   124
+/* This test was originally introduced to test that we transform
yann@1183
   125
+   to ns % 10000.  See the discussion of PR 32044 why we do not do
yann@1183
   126
+   that anymore.  */
yann@1183
   127
+/* { dg-final { scan-tree-dump-times "%" 0 "optimized" } } */
yann@1183
   128
+/* { dg-final { scan-tree-dump-times "/" 0 "optimized" } } */
yann@1183
   129
 /* { dg-final { cleanup-tree-dump "optimized" } } */
yann@1183
   130
Index: gcc-4.3.2/gcc/testsuite/gcc.dg/tree-ssa/pr32044.c
yann@1183
   131
===================================================================
yann@1183
   132
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
yann@1183
   133
+++ gcc-4.3.2/gcc/testsuite/gcc.dg/tree-ssa/pr32044.c	2009-01-28 10:25:50.000000000 +0100
yann@1183
   134
@@ -0,0 +1,55 @@
yann@1183
   135
+/* { dg-do compile } */
yann@1183
   136
+/* { dg-options "-O2 -fdump-tree-empty -fdump-tree-final_cleanup" } */
yann@1183
   137
+
yann@1183
   138
+int foo (int n)
yann@1183
   139
+{
yann@1183
   140
+  while (n >= 45)
yann@1183
   141
+    n -= 45;
yann@1183
   142
+
yann@1183
   143
+  return n;
yann@1183
   144
+}
yann@1183
   145
+
yann@1183
   146
+int bar (int n)
yann@1183
   147
+{
yann@1183
   148
+  while (n >= 64)
yann@1183
   149
+    n -= 64;
yann@1183
   150
+
yann@1183
   151
+  return n;
yann@1183
   152
+}
yann@1183
   153
+
yann@1183
   154
+int bla (int n)
yann@1183
   155
+{
yann@1183
   156
+  int i = 0;
yann@1183
   157
+
yann@1183
   158
+  while (n >= 45)
yann@1183
   159
+    {
yann@1183
   160
+      i++;
yann@1183
   161
+      n -= 45;
yann@1183
   162
+    }
yann@1183
   163
+
yann@1183
   164
+  return i;
yann@1183
   165
+}
yann@1183
   166
+
yann@1183
   167
+int baz (int n)
yann@1183
   168
+{
yann@1183
   169
+  int i = 0;
yann@1183
   170
+
yann@1183
   171
+  while (n >= 64)
yann@1183
   172
+    {
yann@1183
   173
+      i++;
yann@1183
   174
+      n -= 64;
yann@1183
   175
+    }
yann@1183
   176
+
yann@1183
   177
+  return i;
yann@1183
   178
+}
yann@1183
   179
+
yann@1183
   180
+/* The loops computing division/modulo by 64 should be eliminated.  */
yann@1183
   181
+/* { dg-final { scan-tree-dump-times "Removing empty loop" 2 "empty" } } */
yann@1183
   182
+
yann@1183
   183
+/* There should be no division/modulo in the final dump (division and modulo
yann@1183
   184
+   by 64 are done using bit operations).  */
yann@1183
   185
+/* { dg-final { scan-tree-dump-times "/" 0 "final_cleanup" } } */
yann@1183
   186
+/* { dg-final { scan-tree-dump-times "%" 0 "final_cleanup" } } */
yann@1183
   187
+
yann@1183
   188
+/* { dg-final { cleanup-tree-dump "empty" } } */
yann@1183
   189
+/* { dg-final { cleanup-tree-dump "final_cleanup" } } */
yann@1183
   190
Index: gcc-4.3.2/gcc/tree-ssa-loop-ivopts.c
yann@1183
   191
===================================================================
yann@1183
   192
--- gcc-4.3.2.orig/gcc/tree-ssa-loop-ivopts.c	2009-01-28 10:26:04.000000000 +0100
yann@1183
   193
+++ gcc-4.3.2/gcc/tree-ssa-loop-ivopts.c	2009-01-28 10:27:09.000000000 +0100
yann@1183
   194
@@ -3778,7 +3778,12 @@
yann@1183
   195
     return false;
yann@1183
   196
 
yann@1183
   197
   cand_value_at (loop, cand, use->stmt, nit, &bnd);
yann@1183
   198
+
yann@1183
   199
   *bound = aff_combination_to_tree (&bnd);
yann@1183
   200
+  /* It is unlikely that computing the number of iterations using division
yann@1183
   201
+     would be more profitable than keeping the original induction variable.  */
yann@1183
   202
+  if (expression_expensive_p (*bound))
yann@1183
   203
+    return false;
yann@1183
   204
   return true;
yann@1183
   205
 }
yann@1183
   206
 
yann@1183
   207