On 11/08/13 02:28, Konstantin Vladimirov wrote:
typedef struct
{
unsigned prev;
unsigned next;
} foo_t;
void
foo( unsigned x, unsigned y)
{
foo_t *ptr = (foo_t *)((void *)x);
if (y != 0)
{
ptr->prev = y;
ptr->next = x;
}
else
{
ptr->prev = 0; /* or explicitly ptr->prev = y; no difference */
ptr->next = 0;
}
}
Umm, you can't hoist ptr->prev before the conditional because that would
change the meaning of this code.
I think you wanted the conditional to test y == 0 which exposes the code
hoisting opportunity for the ptr->prev assignment. Once you fix the
testcase the code in jump2 will hoist the assignment resulting in:
.cfi_startproc
testl %esi, %esi
movl %edi, %eax
movl $0, (%edi)
je .L5
movl $0, 4(%rax)
ret
.p2align 4,,10
.p2align 3
.L5:
movl %edi, 4(%rax)
ret
.cfi_endproc
Jeff