On Tue, 17 Jun 2014 13:01:41 -0700 Walter Bright via Digitalmars-d <[email protected]> wrote:
> On 6/17/2014 3:27 AM, Jonathan M Davis via Digitalmars-d wrote: > > I would hope that the compiler could and would optimize out setting > > the out parameter to its init value when it's unnecessary > > This is called "dead assignment elimination" and is a bog standard > data flow analysis technique that has been in common use since the > 1980's. > > Compile some sample code and see! > > Also: > > grep -r "dead assignment" *.c > > in the compiler source tree. > > BTW, data flow analysis was not pioneered by the Clang folks, despite > them being very good compiler devs. Oh, it doesn't surprise me in the least that this is a long-standing and known compiler technique, particularly since it's a fairly obvious thing to do. It's just that statements that you've made in the past with regards to code flow analysis imply that dmd does very little of it, which would imply that optimizations like this are done a lot less than they could be, because it does require some level of flow analysis to figure out whether a variable is guaranteed to be assigned to or not. Regardless, I fully support how out works. I just think that we should try and optimize out its costs when they're not necessary, and if the compiler can already do that, that's great. - Jonathan M Davis
