Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c > #6007

Re: register at file scope

From Philipp Klaus Krause <pkk@spth.de>
Newsgroups comp.std.c
Subject Re: register at file scope
Date 2019-10-28 12:22 +0100
Organization solani.org
Message-ID <qp6j0d$kaq$1@solani.org> (permalink)
References <qoujmq$bf1$1@solani.org> <qp1p09$f8l$1@dont-email.me> <qp1vg1$jr5$1@solani.org> <qp3vl6$j5h$1@dont-email.me>

Show all headers | View raw


Am 27.10.19 um 12:39 schrieb David Brown:
> 
> After all, what optimisations would actually be enabled here?  When a
> file-static variable is known not to escape (it's address is not taken,
> or the address is not passed out of the unit) then the compiler can make
> various optimisations - it might eliminate it entirely, reduce its size,
> use value or range information to improve code, etc.  When it is
> globally accessible in a way unknown to the compiler - any other unit
> might read it or change it - then it has lost this information.  Taking
> its address does not make it lose more information.
> 
> Can you give concrete examples of the kind of optimisation a compiler
> (even in theory) could make given that "int x;" is accessible from other
> independently compiled units but where the compiler knows the address of
> x will never be taken?
> 

Consdier e.g.

int i;

void g(void);

void f(int *p)
{
  if(i <= *p)
	i = *p + 1;

  if (*p & 0xa5)
    …
}

If int i was declared a register int i, the compiler could assume that p
does not point at i, and thus could reuse the earlier value of *p in the
second if condition instead of having to reload from memory.

> 
> Remember also that the trend in optimising compilers is towards cross-TU
> information exchange and optimisation (link-time optimisation,
> whole-program optimisation, omniscient compilation, and various other
> terms).  Such cross-unit information exchange and optimisation provides
> improvements that subsume your suggestion here, and provide vastly more
> benefits in addition.
> 

While LLVM is going that way, there is a large number of C
implementations (most timplementations tagret some small embedded
systems) out there, most of which probably don't have the manpower to
switch to whole-program optimization. There are still implementations
that work a function at a time, not even taking full advantage of static.

Philipp

Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

register at file scope Philipp Klaus Krause <pkk@spth.de> - 2019-10-25 12:45 +0200
  Re: register at file scope David Brown <david.brown@hesbynett.no> - 2019-10-26 17:33 +0200
    Re: register at file scope Philipp Klaus Krause <pkk@spth.de> - 2019-10-26 19:24 +0200
      Re: register at file scope David Brown <david.brown@hesbynett.no> - 2019-10-27 12:39 +0100
        Re: register at file scope Philipp Klaus Krause <pkk@spth.de> - 2019-10-28 12:22 +0100
          Re: register at file scope David Brown <david.brown@hesbynett.no> - 2019-10-28 15:28 +0100
            Re: register at file scope Philipp Klaus Krause <pkk@spth.de> - 2019-10-29 10:00 +0100
              Re: register at file scope David Brown <david.brown@hesbynett.no> - 2019-10-29 13:46 +0100
              Re: register at file scope Philipp Klaus Krause <pkk@spth.de> - 2019-11-25 12:19 +0100

csiph-web