Re: optimization removes a __builtin_memcpy?

2008-11-30 Thread Richard Guenther
On Sun, Nov 30, 2008 at 5:28 AM, Steve Kargl
<[EMAIL PROTECTED]> wrote:
> First, I'll preface this with "I'm probably doing something wrong."
> I'm adding support to gfortran for the ERRMSG argument to [DE]ALLOCATE.
> Here's, some code to demonstrate:
>
> program a
>   call works
>   call fails
> end program a
> !
> ! Work with all optimization levels.
> !
> subroutine works
>   character(len=70) :: err = 'No error'
>   integer, allocatable :: i(:)
>   allocate(i(4), errmsg=err)  ! err is unchanged.
>   print *, err
>   deallocate(i)
>   allocate(i(4), i(5), errmsg=err)! err is assigned an error message.
>   print *, err
> end subroutine works
> !
> ! Fails at -O[123] due to len=30, works with -O0.
> !
> subroutine fails
>   character(len=30) :: err = 'No error'
>   integer, allocatable :: i(:)
>   allocate(i(4), errmsg=err)
>   print *, err
>   deallocate(i)
>   allocate(i(4), i(5), errmsg=err)
>   print *, err
> end subroutine fails
>
> kargl[222] gfc4x -o z -fdump-tree-original a.f90
> kargl[223] ./z
>  No error
>  Attempt to deallocate an unallocated object
>  No error
>  Attempt to deallocate an unall
> kargl[224] mv a.f90.003t.original abc
> kargl[225] gfc4x -o z -fdump-tree-original -O a.f90
> a.f90: In function 'fails':
> a.f90:16: error: non-trivial conversion at assignment
> character(kind=1) *
> character(kind=1)[1:30]
> iftmp.17 = err;
>
> a.f90:16: error: non-trivial conversion at assignment
> character(kind=1) *
> character(kind=1)[1:30]
> iftmp.20 = err;
>
> a.f90:16: internal compiler error: verify_gimple failed
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
>
> Looking at a diff of the two -fdump-tree-original outputs shows:
>
> ERRMSG.12 = &"Attempt to deallocate an unallocated object"[1]{lb: 1 sz: 
> 1};
> -ERRMSG.12 = stat.11 != 0 ? (void) __builtin_memcpy ((void *) &err, (void 
> *) ERRMSG.12, 30) : (void) 0;
> +ERRMSG.12 = stat.11 != 0 ? err = *(character(kind=1)[1:30] * {ref-all}) 
> ERRMSG.12 : (void) 0;
>
> The chunk of code that I've add to trans-stmt.c(gfc_trans_deallocate) looks 
> like
>
>  /* A better error message may be possible, but not required.  */
>  const char *msg = "Attempt to deallocate an unallocated object";
>  tree errmsg, slen, dlen;
>
>  gfc_init_se (&se, NULL);
>  gfc_conv_expr_lhs (&se, code->expr);
>
>  errmsg = gfc_create_var (pchar_type_node, "ERRMSG");
>
>  /* astat is >= 0.  */
>  tmp = fold_build2 (NE_EXPR, boolean_type_node, astat,
> build_int_cst (TREE_TYPE (astat), 0));
>
>  /* Create tree for msg.  */
>  gfc_add_modify (&block, errmsg,
>   gfc_build_addr_expr (pchar_type_node,
>gfc_build_localized_cstring_const (msg)));
>
>  /* Don't overflow the string.  slen = min(dlen, len).  */
>  slen = build_int_cst (gfc_charlen_type_node, 44);
>  dlen = gfc_get_expr_charlen (code->expr);
>  slen = fold_build2 (MIN_EXPR, TREE_TYPE (slen), dlen, slen);
>
>  tmp = fold_build3 (COND_EXPR, pchar_type_node, tmp,
>build_call_expr (built_in_decls[BUILT_IN_MEMCPY], 3,
>se.expr, errmsg, slen),
>build_empty_stmt ());
>
>  gfc_add_modify (&block, errmsg, tmp);
>
> The diff shows that the fails case correctly has dlen=30
> and in fact for any value less than slen=44 and -O[123]
> removes the __builtin_memcpy().  So what is missing or
> how to I inhibit this optimization?

You cannot inhibit this optimization, instead the optimization should be
fixed to not generate invalid gimple ;)  (see builtins.c:fold_builtin_memory_op)

Richard.


How to control code segments ?

2008-11-30 Thread Dong Phuong
I'm porting for a microcontroler which has segmented
memory.

THe memory is devided into many pages, each page is
16K. And I'm going to use 256 pages for code. But
these 256 pages are not continuous in physical memory,
so when I want to jump to a function, I have to know
what is the segment address of this function, and then
set the CSP with this value, and jump to it.

So what I want to know is if I'm in a function, is
there any way for me to know what code segments I'm
locating in ? If I know this,  when I have to jump to
another function, I can decide wheather this function
is in the same segment with the function that I'm
locating in, and then can decide if I have to change
the CSP.

And when I compile a long long program with so many
methods, is there any way for GCC so that it can
realize that the code has exceeded 16K and have to use
a new segments ? or the user must explicit declare
this in the C source program ? 

If you know any hints or any doccument about this,
please show me. THank you very much. 


  


Re: gcc4.1.2 compilation errors

2008-11-30 Thread yx
Andrew, thank you very much for your answer. I have just used the
option you suggested for benchmark galgel, it works!

Since I can not modify the source code of SPEC2000 benchmark, I don't
quite understand when you say I need "alt sources which remove the
cast as lvalue".  Where I can find the alternative source for 176.gcc?

If anyone have experience to successfully compile 176.gcc, 252.eon and
253.perlbmk in SPEC2000 with gcc4.1.2 version, could you kindly tell
me what kind of compiler option you use for these three benchmarks?

Any help will be greatly appreciated!

On Sat, Nov 29, 2008 at 10:12 PM, Andrew Thomas Pinski
<[EMAIL PROTECTED]> wrote:
>
>
> Sent from my iPhone
>
> On Nov 29, 2008, at 6:34 PM, yx <[EMAIL PROTECTED]> wrote:
>
>> Hi,
>>
>> I am trying to compile SPEC2000 benchmark with gcc 4.1.2 (gfortran and
>> g++ were compiled successfully for gcc4.1.2.) However I got
>> compilation errors for 4 benchmarks in SPEC2000. The error messages
>> are listed as follows:
>>
>> 176. gcc:
>> reorg.c: In function 'find_end_label'
>> reorg.c:831: error: invalid lvalue in increment
>> reorg.c: In function delete_from_delay_slot?
>> reorg.c:1033: error: invalid lvalue in increment
>> reorg.c: In function make_return_insns?
>> reorg.c:4157: error: invalid lvalue in increment
>> reorg.c: In function dbr_schedule?
>> reorg.c:4237: error: invalid lvalue in increment
>> reorg.c:4312: warning: incompatible implicit declaration of built-in
>> function memset specmake: *** [reorg.o] Error 1
>> specmake  options 2> options.err | tee options.out
>
> You need the alt sources which remove the cast as lvalue.
>
>>
>>
>> 252.eon:
>> ggFrame2.cc: In function std::istream& operator>>(std::istream&,
>> ggFrame2&)?
>> ggFrame2.cc:64: error: no match for operator>> in is >> "("
>> 253.perlbmk:
>> perlio.c: In function PerlIO_setpos
>> perlio.c:472: error: incompatible type for argument 2 of fseek
>> perlio.c: In function PerlIO_getpos
>> perlio.c:490: error: incompatible types in assignment
>> specmake: *** [perlio.o] Error 1
>>
>> 178.galgel:
>> local412/bin/gfortran -c -o modules.o  -malign-double   -O3
>> modules.f90
>> In file modules.f90:1
>
> Try with -ffixed-form, the source is written in fixed form Fortran 90/95.
>  .f90 causes gfortran to default to free form.
>
> Thanks,
> Andrew Pinski
>
>>
>>
>> C  Maximal sizes 
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:16
>>
>> C *** Parameters of the problem ***
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:36
>>
>> C *** Coefficients for boundary conditions ***
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:41
>>
>> Real*8, Dimension(0:mm) ::
>>  1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:42
>>
>>*F1, F2, F3, F4, G1, G2, G3, G4, A, B
>>   1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:51
>>
>> C * Inner products  of polynomials **
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:66
>>
>> C * Inner products  of functions **
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:71
>>
>>   Real*8, Dimension(mm,mm) ::
>> 1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:72
>>
>>* VXX,  VXY,  VYX,  VYY,  VXX2, VXY2, VYX2, VYY2
>>   1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:84
>>
>>   Real*8, Dimension(mm,mm,mm) ::
>>1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:85
>>
>>* VXXX, VXXY, VXYX, VXYY, VYXX, VYXY, VYYX, VYYY
>>   1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:97
>>
>>   Real*8, Dimension(mm,mm) :: TXX, TYY, TXX2, TYY2,
>>   1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:98
>>
>>*  PXX, PYY, PXX2, PYY2
>>   1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:104
>>
>>   Real*8, Dimension(mm,mm,mm) ::
>>1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:105
>>
>>*  WXTX, WXTY, WYTX, WYTY, WXPX, WXPY, WYPX, WYPY
>>   1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:108
>>
>> C *** Matrices of the Galerkin system ***
>> 1
>> Error: Unclassifiable statement at (1)
>> In file modules.f90:140
>>
>> Real*8,  Dimension(N11,N11) ::
>>  1
>> Error: Syntax error in data declaration at (1)
>> In file modules.f90:141
>>
>>*POP, Poj1, Poj2, Poj3, Poj4
>>   1
>> Error: Unclassifiable

Re: gcc4.1.2 compilation errors

2008-11-30 Thread Kenneth Hoste


On Nov 30, 2008, at 21:08 , yx wrote:


Andrew, thank you very much for your answer. I have just used the
option you suggested for benchmark galgel, it works!

Since I can not modify the source code of SPEC2000 benchmark, I don't
quite understand when you say I need "alt sources which remove the
cast as lvalue".  Where I can find the alternative source for 176.gcc?


Andrew means to say you should use the src.alt option provided by the  
SPEC framework, see http://www.specbench.org/cpu2000/docs/1.2/config.html#toc_srcalt 
 .


Also, try and make sure you're using the latest version of the SPEC  
framework, which is v.13 for SPEC CPU2000.



If anyone have experience to successfully compile 176.gcc, 252.eon and
253.perlbmk in SPEC2000 with gcc4.1.2 version, could you kindly tell
me what kind of compiler option you use for these three benchmarks?


252.eon needs  -DHAS_ERRLIST while 253.perlbmk needs - 
DSPEC_CPU2000_LINUX_I386 -DSPEC_CPU2000_NEED_BOOL .


To compile 176.gcc I didn't need any special flags. I was using v1.3,  
so maybe you should double-check on that (see the "version" file in  
the SPEC CPU2000 root dir)...


K.





Any help will be greatly appreciated!

On Sat, Nov 29, 2008 at 10:12 PM, Andrew Thomas Pinski
<[EMAIL PROTECTED]> wrote:



Sent from my iPhone

On Nov 29, 2008, at 6:34 PM, yx <[EMAIL PROTECTED]> wrote:


Hi,

I am trying to compile SPEC2000 benchmark with gcc 4.1.2 (gfortran  
and

g++ were compiled successfully for gcc4.1.2.) However I got
compilation errors for 4 benchmarks in SPEC2000. The error messages
are listed as follows:

176. gcc:
reorg.c: In function 'find_end_label'
reorg.c:831: error: invalid lvalue in increment
reorg.c: In function delete_from_delay_slot?
reorg.c:1033: error: invalid lvalue in increment
reorg.c: In function make_return_insns?
reorg.c:4157: error: invalid lvalue in increment
reorg.c: In function dbr_schedule?
reorg.c:4237: error: invalid lvalue in increment
reorg.c:4312: warning: incompatible implicit declaration of built-in
function memset specmake: *** [reorg.o] Error 1
specmake  options 2> options.err | tee options.out


You need the alt sources which remove the cast as lvalue.




252.eon:
ggFrame2.cc: In function std::istream& operator>>(std::istream&,
ggFrame2&)?
ggFrame2.cc:64: error: no match for operator>> in is >> "("
253.perlbmk:
perlio.c: In function PerlIO_setpos
perlio.c:472: error: incompatible type for argument 2 of fseek
perlio.c: In function PerlIO_getpos
perlio.c:490: error: incompatible types in assignment
specmake: *** [perlio.o] Error 1

178.galgel:
local412/bin/gfortran -c -o modules.o  -malign-double   -O3
modules.f90
In file modules.f90:1


Try with -ffixed-form, the source is written in fixed form Fortran  
90/95.

.f90 causes gfortran to default to free form.

Thanks,
Andrew Pinski




C  Maximal sizes 
1
Error: Unclassifiable statement at (1)
In file modules.f90:16

C *** Parameters of the problem ***
1
Error: Unclassifiable statement at (1)
In file modules.f90:36

C *** Coefficients for boundary conditions ***
1
Error: Unclassifiable statement at (1)
In file modules.f90:41

   Real*8, Dimension(0:mm) ::
1
Error: Syntax error in data declaration at (1)
In file modules.f90:42

  *F1, F2, F3, F4, G1, G2, G3, G4, A, B
 1
Error: Unclassifiable statement at (1)
In file modules.f90:51

C * Inner products  of polynomials **
1
Error: Unclassifiable statement at (1)
In file modules.f90:66

C * Inner products  of functions **
1
Error: Unclassifiable statement at (1)
In file modules.f90:71

 Real*8, Dimension(mm,mm) ::
   1
Error: Syntax error in data declaration at (1)
In file modules.f90:72

  * VXX,  VXY,  VYX,  VYY,  VXX2, VXY2, VYX2, VYY2
 1
Error: Unclassifiable statement at (1)
In file modules.f90:84

 Real*8, Dimension(mm,mm,mm) ::
  1
Error: Syntax error in data declaration at (1)
In file modules.f90:85

  * VXXX, VXXY, VXYX, VXYY, VYXX, VYXY, VYYX, VYYY
 1
Error: Unclassifiable statement at (1)
In file modules.f90:97

 Real*8, Dimension(mm,mm) :: TXX, TYY, TXX2, TYY2,
 1
Error: Syntax error in data declaration at (1)
In file modules.f90:98

  *  PXX, PYY, PXX2, PYY2
 1
Error: Unclassifiable statement at (1)
In file modules.f90:104

 Real*8, Dimension(mm,mm,mm) ::
  1
Error: Syntax error in data declaration at (1)
In file modules.f90:105

  *  WXTX, WXTY, WYTX, WYTY, WXPX, WXPY, WYPX, WYPY
 1
Error: Unclassifiable statement at (1)
In file modules.f90:108

C *** Matrices of the Galerkin system  
***

1
Error: Unclassifiable statement at (1)
In file modu

Re: optimization removes a __builtin_memcpy?

2008-11-30 Thread Richard Guenther
On Sun, Nov 30, 2008 at 5:28 AM, Steve Kargl
<[EMAIL PROTECTED]> wrote:
> First, I'll preface this with "I'm probably doing something wrong."
> I'm adding support to gfortran for the ERRMSG argument to [DE]ALLOCATE.
> Here's, some code to demonstrate:
>
> program a
>   call works
>   call fails
> end program a
> !
> ! Work with all optimization levels.
> !
> subroutine works
>   character(len=70) :: err = 'No error'
>   integer, allocatable :: i(:)
>   allocate(i(4), errmsg=err)  ! err is unchanged.
>   print *, err
>   deallocate(i)
>   allocate(i(4), i(5), errmsg=err)! err is assigned an error message.
>   print *, err
> end subroutine works
> !
> ! Fails at -O[123] due to len=30, works with -O0.
> !
> subroutine fails
>   character(len=30) :: err = 'No error'
>   integer, allocatable :: i(:)
>   allocate(i(4), errmsg=err)
>   print *, err
>   deallocate(i)
>   allocate(i(4), i(5), errmsg=err)
>   print *, err
> end subroutine fails
>
> kargl[222] gfc4x -o z -fdump-tree-original a.f90
> kargl[223] ./z
>  No error
>  Attempt to deallocate an unallocated object
>  No error
>  Attempt to deallocate an unall
> kargl[224] mv a.f90.003t.original abc
> kargl[225] gfc4x -o z -fdump-tree-original -O a.f90
> a.f90: In function 'fails':
> a.f90:16: error: non-trivial conversion at assignment
> character(kind=1) *
> character(kind=1)[1:30]
> iftmp.17 = err;
>
> a.f90:16: error: non-trivial conversion at assignment
> character(kind=1) *
> character(kind=1)[1:30]
> iftmp.20 = err;
>
> a.f90:16: internal compiler error: verify_gimple failed
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See  for instructions.
>
> Looking at a diff of the two -fdump-tree-original outputs shows:
>
> ERRMSG.12 = &"Attempt to deallocate an unallocated object"[1]{lb: 1 sz: 
> 1};
> -ERRMSG.12 = stat.11 != 0 ? (void) __builtin_memcpy ((void *) &err, (void 
> *) ERRMSG.12, 30) : (void) 0;
> +ERRMSG.12 = stat.11 != 0 ? err = *(character(kind=1)[1:30] * {ref-all}) 
> ERRMSG.12 : (void) 0;

Btw, you assign "void" to ERRMSG.12 - this is certainly invalid GENERIC and not
what you want to do, right?

Richard.


Re: How to control code segments ?

2008-11-30 Thread Alan Lehotsky

Look at the implementation of the IP2K compiler and linker.
It uses a segmented paged architecture just like the machine you are  
describing.


In essence what we did was implement linker relaxation to deal with  
this.
When we called any function, we emitted the appropriate long-call by  
setting

the page register and jumping to the location on that page.

In the linker, we implemented relaxation code that looked to see if
we were changing to the SAME page, and if so deleted the instruction  
changing
the PAGE and did a local jump to the destination.  Now, because a  
function could cross a page
boundary (we only had 4kb pages (and 16 bit instructions), all our  
branches were done this way

(if I recall correctly).

It's a little tedious, but not too technically demanding a solution

Al Lehotsky

On Nov 30, 2008, at 2:06 PM, Dong Phuong wrote:


I'm porting for a microcontroler which has segmented
memory.

THe memory is devided into many pages, each page is
16K. And I'm going to use 256 pages for code. But
these 256 pages are not continuous in physical memory,
so when I want to jump to a function, I have to know
what is the segment address of this function, and then
set the CSP with this value, and jump to it.

So what I want to know is if I'm in a function, is
there any way for me to know what code segments I'm
locating in ? If I know this,  when I have to jump to
another function, I can decide wheather this function
is in the same segment with the function that I'm
locating in, and then can decide if I have to change
the CSP.

And when I compile a long long program with so many
methods, is there any way for GCC so that it can
realize that the code has exceeded 16K and have to use
a new segments ? or the user must explicit declare
this in the C source program ?

If you know any hints or any doccument about this,
please show me. THank you very much.







Re: How to control code segments ?

2008-11-30 Thread Dong Phuong


"Linker relaxation" is maybe what I'm looking for. 

But I've searched it on google , but there are few
doccuments about it, now I haven't imagined yet how to
implement Linker Relaxation. 

Could you tell me some of doccuments about it and
where in the binutils that it was implemented ? 

--- Alan Lehotsky <[EMAIL PROTECTED]> wrote:

> Look at the implementation of the IP2K compiler and
> linker.
> It uses a segmented paged architecture just like the
> machine you are  
> describing.
> 
> In essence what we did was implement linker
> relaxation to deal with  
> this.
> When we called any function, we emitted the
> appropriate long-call by  
> setting
> the page register and jumping to the location on
> that page.
> 
> In the linker, we implemented relaxation code that
> looked to see if
> we were changing to the SAME page, and if so deleted
> the instruction  
> changing
> the PAGE and did a local jump to the destination. 
> Now, because a  
> function could cross a page
> boundary (we only had 4kb pages (and 16 bit
> instructions), all our  
> branches were done this way
> (if I recall correctly).
> 
> It's a little tedious, but not too technically
> demanding a solution
> 
> Al Lehotsky
> 
> On Nov 30, 2008, at 2:06 PM, Dong Phuong wrote:
> 
> > I'm porting for a microcontroler which has
> segmented
> > memory.
> >
> > THe memory is devided into many pages, each page
> is
> > 16K. And I'm going to use 256 pages for code. But
> > these 256 pages are not continuous in physical
> memory,
> > so when I want to jump to a function, I have to
> know
> > what is the segment address of this function, and
> then
> > set the CSP with this value, and jump to it.
> >
> > So what I want to know is if I'm in a function, is
> > there any way for me to know what code segments
> I'm
> > locating in ? If I know this,  when I have to jump
> to
> > another function, I can decide wheather this
> function
> > is in the same segment with the function that I'm
> > locating in, and then can decide if I have to
> change
> > the CSP.
> >
> > And when I compile a long long program with so
> many
> > methods, is there any way for GCC so that it can
> > realize that the code has exceeded 16K and have to
> use
> > a new segments ? or the user must explicit declare
> > this in the C source program ?
> >
> > If you know any hints or any doccument about this,
> > please show me. THank you very much.
> >
> >
> >
> 
>