Index: gcc.target/spu/overlay-1.c =================================================================== --- gcc.target/spu/overlay-1.c (revision 0) +++ gcc.target/spu/overlay-1.c (revision 0) @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fpartition-functions-into-sections=150 -msafe-dma -fdump-rtl-fpart" } */ + +#include +#include +#define SPE_ADDR 0x0 +#define EA_ADDR 0x2000 + +int +spu_dma (void) +{ + int status = 0; + spu_writech (MFC_LSA, SPE_ADDR); + spu_writech (MFC_EAH, 0x0); + spu_writech (MFC_EAL, EA_ADDR); + spu_writech (MFC_Size, 0x10); + spu_writech (MFC_TagID, 5); + spu_writech (MFC_Cmd, 0x20); + return 0; +} + +int +main () +{ + spu_dma (); +} + +/* { dg-final { scan-rtl-dump-times "starts a critical section" 1 "fpart" } } */ +/* { dg-final { cleanup-rtl-dump "fpart" } } */ + + Index: gcc.target/spu/overlay-2.c =================================================================== --- gcc.target/spu/overlay-2.c (revision 0) +++ gcc.target/spu/overlay-2.c (revision 0) @@ -0,0 +1,31 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fpartition-functions-into-sections=150 -munsafe-dma -fdump-rtl-fpart" } */ + +#include +#include +#define SPE_ADDR 0x0 +#define EA_ADDR 0x2000 + +int +spu_dma (void) +{ + int status = 0; + spu_writech (MFC_LSA, SPE_ADDR); + spu_writech (MFC_EAH, 0x0); + spu_writech (MFC_EAL, EA_ADDR); + spu_writech (MFC_Size, 0x10); + spu_writech (MFC_TagID, 5); + spu_writech (MFC_Cmd, 0x20); + return 0; +} + +int +main () +{ + spu_dma (); +} + +/* { dg-final { scan-rtl-dump-times "starts a critical section" 1 "fpart" } } */ +/* { dg-final { cleanup-rtl-dump "fpart" } } */ + + Index: gcc.dg/section/section.exp =================================================================== --- gcc.dg/section/section.exp (revision 0) +++ gcc.dg/section/section.exp (revision 0) @@ -0,0 +1,39 @@ +# Copyright (C) 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +# GCC testsuite that uses the `dg.exp' driver. + +# Load support procs. +load_lib gcc-dg.exp + +# Skip these tests for targets that don't support this extension. +if { ![check_named_sections_available] } { return } + +# Set up flags used for tests that don't specify options. +set DEFAULT_SECTIONFLAGS "" + +# These flags are used for all targets. +lappend DEFAULT_SECTIONFLAGS "-O2" "-w" "-fpartition-functions-into-sections=150" + +# Initialize `dg'. +dg-init + +# Main loop. +dg-runtest [lsort [glob -nocomplain $srcdir/$subdir/section-size-*.\[cS\]]] \ + "" $DEFAULT_SECTIONFLAGS + +# All done. +dg-finish Index: gcc.dg/section/section-size-5.c =================================================================== --- gcc.dg/section/section-size-5.c (revision 0) +++ gcc.dg/section/section-size-5.c (revision 0) @@ -0,0 +1,26 @@ +/* { dg-do link } */ +/* { dg-options "-O2 -w -fpartition-functions-into-sections=300" } */ +/* Same test as pr18628.c. */ + +int i; + +int main() +{ + for (;;) + { + switch (i) + { + case 0: + case 1: + return 1; + + case 2: + case 3: + return 0; + + case 5: + --i; + } + } +} + Index: gcc.dg/section/prof/sections-prof.exp =================================================================== --- gcc.dg/section/prof/sections-prof.exp (revision 0) +++ gcc.dg/section/prof/sections-prof.exp (revision 0) @@ -0,0 +1,59 @@ +# Copyright (C) 2008 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +# Test the functionality of programs compiled with profile-directed structure +# rearrangement using -fprofile-generate followed by -fprofile-use. + +load_lib gcc-dg.exp +load_lib target-supports.exp + +# Skip these tests for targets that don't support this extension. +if { ![check_named_sections_available] } { return } + +# Some targets don't support tree profiling. +if { ![check_profiling_available ""] } { + return +} + +# The procedures in profopt.exp need these parameters. +set tool gcc +set prof_ext "gcda" + +# Override the list defined in profopt.exp. +set PROFOPT_OPTIONS [list {}] + +if $tracelevel then { + strace $tracelevel +} + +# Load support procs. +load_lib profopt.exp + +# These are globals used by profopt-execute. The first is options +# needed to generate profile data, the second is options to use the +# profile data. +set common "-O2" +set profile_option [concat $common " -fprofile-generate"] +set feedback_option [concat $common "-w -fprofile-use -fpartition-functions-into-sections=300"] + +foreach src [lsort [glob -nocomplain $srcdir/$subdir/*.c]] { + # If we're only testing specific files and this isn't one of them, skip it. + if ![runtest_file_p $runtests $src] then { + continue + } + profopt-execute $src +} + Index: gcc.dg/section/prof/section-prof-1.c =================================================================== --- gcc.dg/section/prof/section-prof-1.c (revision 0) +++ gcc.dg/section/prof/section-prof-1.c (revision 0) @@ -0,0 +1,67 @@ +/* { dg-options "-O2" } */ + +/* Same test as vect-outer-fir.c */ +#include +extern void abort (void); +#define N 40 +#define M 128 +float in[N+M]; +float coeff[M]; +float out[N]; +float fir_out[N]; + +/* Should be Vectorized. Fixed misaligment in the inner-loop. */ +/* Not vectorized because we can't determine the inner-loop bound. */ +void foo (){ + int i,j,k; + float diff; + + for (i = 0; i < N; i++) { + out[i] = 0; + } + + for (k = 0; k < 4; k++) { + for (i = 0; i < N; i++) { + diff = 0; + for (j = k; j < M; j+=4) { + diff += in[j+i]*coeff[j]; + } + out[i] += diff; + } + } + +} + +/* Vectorized. Changing misalignment in the inner-loop. */ +void fir (){ + int i,j,k; + float diff; + + for (i = 0; i < N; i++) { + diff = 0; + for (j = 0; j < M; j++) { + diff += in[j+i]*coeff[j]; + } + fir_out[i] = diff; + } +} + + +int main (void) +{ + int i, j; + float diff; + + for (i = 0; i < M; i++) + coeff[i] = i; + for (i = 0; i < N+M; i++) + in[i] = i; + foo (); + fir (); + for (i = 0; i < N; i++) { + if (out[i] != fir_out[i]) + abort (); + } + return 0; +} + Index: gcc.dg/section/section-size-1.c =================================================================== --- gcc.dg/section/section-size-1.c (revision 0) +++ gcc.dg/section/section-size-1.c (revision 0) @@ -0,0 +1,56 @@ +/* { dg-do run } */ + +/* Same test as vect-outer-4m.c. */ + +#include + +#define N 40 +#define M 128 +unsigned short in[N+M]; +unsigned int out[N]; +extern void abort (void); +/* Outer-loop vectorization. */ +/* Not vectorized due to multiple-types in the inner-loop. */ + +unsigned int +foo (){ + int i,j; + unsigned int diff; + unsigned int s=0; + + for (i = 0; i < N; i++) { + diff = 0; + for (j = 0; j < M; j+=8) { + diff += in[j+i]; + } + s+=((unsigned short)diff>>3); + } + return s; +} + +int main (void) +{ + int i, j; + unsigned int diff; + unsigned int s=0,sum=0; + + for (i = 0; i < N+M; i++) { + in[i] = i; + } + + sum=foo (); + + for (i = 0; i < N; i++) { + diff = 0; + for (j = 0; j < M; j+=8) { + diff += in[j+i]; + } + s += ((unsigned short)diff>>3); + } + + if (s != sum) + abort (); + + return 0; +} + Index: gcc.dg/section/section-size-2.c =================================================================== --- gcc.dg/section/section-size-2.c (revision 0) +++ gcc.dg/section/section-size-2.c (revision 0) @@ -0,0 +1,67 @@ +/* { dg-do run } */ + +/* Same test as vect-outer-fir.c */ +#include +extern void abort (void); +#define N 40 +#define M 128 +float in[N+M]; +float coeff[M]; +float out[N]; +float fir_out[N]; + +/* Should be Vectorized. Fixed misaligment in the inner-loop. */ +/* Not vectorized because we can't determine the inner-loop bound. */ +void foo (){ + int i,j,k; + float diff; + + for (i = 0; i < N; i++) { + out[i] = 0; + } + + for (k = 0; k < 4; k++) { + for (i = 0; i < N; i++) { + diff = 0; + for (j = k; j < M; j+=4) { + diff += in[j+i]*coeff[j]; + } + out[i] += diff; + } + } + +} + +/* Vectorized. Changing misalignment in the inner-loop. */ +void fir (){ + int i,j,k; + float diff; + + for (i = 0; i < N; i++) { + diff = 0; + for (j = 0; j < M; j++) { + diff += in[j+i]*coeff[j]; + } + fir_out[i] = diff; + } +} + + +int main (void) +{ + int i, j; + float diff; + + for (i = 0; i < M; i++) + coeff[i] = i; + for (i = 0; i < N+M; i++) + in[i] = i; + foo (); + fir (); + for (i = 0; i < N; i++) { + if (out[i] != fir_out[i]) + abort (); + } + return 0; +} + Index: gcc.dg/section/section-size-3.c =================================================================== --- gcc.dg/section/section-size-3.c (revision 0) +++ gcc.dg/section/section-size-3.c (revision 0) @@ -0,0 +1,52 @@ +/* { dg-do run } */ + +#include + +#define N 16 +int result[N] = + { 8, 10, 12, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38 }; +int result1[N] = + { 11, 13, 15, 18, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41 }; +int out[N]; +extern void abort (void); + + +int +main (void) +{ + void *p = &&a; + void *q = &&b; + int arr[N]; + int k = 3; + int m, i = 0; + + do + { + m = k + 5; + arr[i] = m; + k = k + 2; + i++; + } + while (i < N); + + /* check results: */ + for (i = 0; i < N; i++) + { + if (arr[i] != result[i]) + goto *p; + } +b: + abort (); +a: + for (i = 0; i < N; i++) + { + out[i] = result[i] + 3; + } + for (i = 0; i < N; i++) + { + if (out[i] != result1[i]) + goto *q; + } + + return 0; +} Index: gcc.dg/section/section-size-4.c =================================================================== --- gcc.dg/section/section-size-4.c (revision 0) +++ gcc.dg/section/section-size-4.c (revision 0) @@ -0,0 +1,51 @@ +/* { dg-do run } */ + +#include + +extern void abort (void); +#define N 16 +#define M 20 +int in[N] = { 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38 }; +int arr[N] = + { 13, 17, 21, 25, 29, 33, 37, 47, 51, 55, 59, 63, 67, 71, 75, 79 }; +int out[N]; + +typedef int (*func) (int); + +static int +foo (int a) +{ + return (2 * a + 3); +} + +static int +foo1 (int a) +{ + return (2 * a - 3); +} + +static void __attribute__((noinline)) +compute_output (int *out, func f, int elem) +{ + *out = (*f) (elem); +} + +int +main (void) +{ + int i; + + for (i = 0; i < N; i++) + { + if (in[i] > M) + compute_output (&out[i], foo, in[i]); + else + compute_output (&out[i], foo1, in[i]); + } + + for (i = 0; i < N; i++) + if (out[i] != arr[i]) + abort (); + + return 0; +} Index: ChangeLog =================================================================== --- ChangeLog (revision 141911) +++ ChangeLog (working copy) @@ -1,3 +1,19 @@ +2008-11-19 Revital Eres + + * gcc.dg/sections/: New directory with tests for the function + partitioning into sections pass. + * gcc.dg/sections/section.exp: New script. + (gcc.dg/sections/section-size-1.c, + gcc.dg/sections/section-size-2.c, + gcc.dg/sections/section-size-3.c, + gcc.dg/sections/section-size-4.c, + gcc.dg/sections/section-size-5.c): New tests. + * gcc.dg/sections/prof/: New directory. + * gcc.dg/sections/prof/sections-prof.exp: New script. + * gcc.dg/sections/prof/section-prof-1.c: New test. + * gcc.target/spu/overlay-1.c: New test. + * gcc.target/spu/overlay-2.c: New test. + 2008-11-15 Jerry DeLisle PR libfortran/37294