On Mon, 12 Mar 2012 04:46:45 -0500, Mantis <mail.mantis...@gmail.com> wrote:
12.03.2012 6:01, Robert Jacques пишет:
On Sun, 11 Mar 2012 21:49:52 -0500, Mantis <mail.mantis...@gmail.com>
wrote:
[...]
That's the point of discussion. Fields of structure may not be optimized
away, because they are not independent variables. In D you have
unchecked pointer-to-pointer casts, and results of these casts should
depend on target architecture, not on optimizer implementation. At
particular, if such optimizations are allowed, some C API will no longer
be accessible from D.

Unused fields of a structure are optimized away _today_. Unless a
piece of code takes the address of the struct, all of the fields are
treated as independent variables.

I can't confirm: http://pastebin.com/YgBULGfe
Prints "42\n3.14\n", compiled with dmd -release on windows x86. How
exactly did you find out that such optimization is performed?


We are referring to values on the stack; unless inlined, the returning function 
always has to return all values for both structs and MRV. So, by 'optimized 
away' I'm referring to the ability of the optimizer to not keep values around, 
if that's more efficient. So to test it, you'd probably want to include enough 
operations for the optimizer not want to do this. Second, taking the address of 
a field might be tripping the optimizer up, so try looking at the stack 
directly. I honestly don't know if DMD does this particular optimization as the 
x86 stack is cheap and out of order chips (i.e. x86) thrive on independent 
assignments, but it's a big and very visible feature of NVCC, a GPU C/C++ 
compiler.


Reply via email to