In article <86o6…@linuxsc.com>, Tim Rentsch <tr.1…@z991.linuxsc.com> wrote:
>ant…@mips.complang.tuwien.ac.at (Anton Ertl) writes: >
>> Thomas Koenig <tkoe…@netcologne.de> writes: >>
>>> On an OoO machine, there can be considerable advantage of >>> doing this kind of thing. For example, compare (if you will >>> excuse my French) >>> >>> add_v1_: >>> addq %rsi, %rdi >>> addq %rdx, %rdi >>> leaq (%rdi,%rcx), %rax >>> ret >>> add_v2_: >>> addq %rsi, %rdi >>> addq %rcx, %rdx >>> leaq (%rdi,%rdx), %rax >>> ret
>> >> On an in-order machine, it's even clearer. In add_v2_, the two >> adds can be done in the same cycle on an in-order machine. On >> an OoO machine, this is not always relevant, in particular, if >> rdx is only ready after rsi and rdi are ready. >>
>> >> If the undefined behaviour nonsense would not be so sad, it >> would be funny. The undefined behaviour advocates love to >> claim that undefined behaviour allows more optimization than >> defined behaviour, but in Comment 1 Richard Biener writes that >> gcc does not perform this optimization because of undefined >> behaviour. [...]
> >I suspect you are misunderstanding the meaning of RB's comment. >The rules of C do not prohibit the optimization from being done.
The code in question isn't even C; it is Fortran. It says that quite clearly in both the bug description as well as the code snippets in the bug that Thomas was referring to. Rules for undefined behavior in Fortran obviously different from those of C, since Fortran is a different langauge.
>gcc does not perform the transformation because of a choice gcc >has made about how code is compiled. If gcc had made different >choices then changing the order of integer adds would still be >conforming. The holdup here is not undefined behavior but how >gcc has chosen to exploit, or not exploit, some cases where some >circumstances of undefined should be treated.
C came up in this context as a parenthetical, "if one considers the assembly equivalent of this...". Here, it was clear that C syntax was merely used as a pseudocode. Arguments about C's behavior and definition are beside the point. - Dan C.