home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / compiler / 1484 < prev    next >
Encoding:
Internet Message Format  |  1992-08-31  |  2.3 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!udel!gvls1!faatcrl!iecc!compilers-sender
  2. From: wismuell@Informatik.TU-Muenchen.DE (Roland Wismueller)
  3. Newsgroups: comp.compilers
  4. Subject: Re: -O4 in SunOS compiler
  5. Keywords: sparc, optimize, C
  6. Message-ID: <92-09-003@comp.compilers>
  7. Date: 31 Aug 92 14:59:35 GMT
  8. References: <92-08-164@comp.compilers>
  9. Sender: compilers-sender@iecc.cambridge.ma.us
  10. Reply-To: wismuell@Informatik.TU-Muenchen.DE (Roland Wismueller)
  11. Organization: Technische Universitaet Muenchen, Germany
  12. Lines: 47
  13. Approved: compilers@iecc.cambridge.ma.us
  14. Originator: wismuell@sunbode7.informatik.tu-muenchen.de
  15.  
  16. jb3o+@andrew.cmu.edu (Jon Allen Boone) writes:
  17. |> What does the -O4 switch do to the SunOS compiler?...
  18. |> "Same as -O3, but trace  the  effects  of pointer assignments."
  19. |> Ok....what does it mean to trace the effects of pointer assignements?
  20.  
  21. To trace the effects of pointer assignements means to compute alias sets
  22. for pointer assignments. Normally (i.e. with -O3 or lower) the compiler
  23. assumes, that a pointer may write to any variable that can be accessed by
  24. pointers. This includes all global and static variables, arrays and
  25. variables whose address have been taken with the '&' operator.
  26.  
  27. With -O4 the compiler tries to figure out, to which of these variables a
  28. pointer can actually point. For example, look at the following code:
  29.  
  30.     int i,j;
  31.     int a[10],k;
  32.     int *pi, *q = &k;
  33.  
  34.     if (...) {
  35.         p = &i;
  36.     }
  37.     else {
  38.         p = &j;
  39.     }
  40.     *p = 123;
  41.  
  42. Without -O4, the compiler assumes that the assignment '*p = 123' may write
  43. to any variable of {i,j,k,a}. With -O4 the compiler recognizes that '*p =
  44. 123' can only affect the variables i and j.
  45.  
  46. So -O4 has several consequences:
  47.   * The compiler must perform additional data flow analysis
  48.   * There may be more chances for optimizations
  49.   * The compiler may produce 'wrong' code
  50.  
  51. The last item is common to all optimizing compilers (at least for C),
  52. since aliasing analysis relies on some assumptions that must hold for a
  53. program, e.g.  the sequence 'p = &i; *(p+offset) = 123;' will access (a
  54. component of) i, but no other variable. Of course, you cannot enforce this
  55. in C.
  56. --
  57. wismuell@informatik.tu-muenchen.de
  58. Munich University of Technology,
  59. Department of Computer Science, FRG
  60. -- 
  61. Send compilers articles to compilers@iecc.cambridge.ma.us or
  62. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  63.