union U { struct A { int a; int b; }aa; long long ll; }; struct B{ union U u1; union U u2; } bg; struct B bg; struct B bar(); int foo (int n) { if (n) { bg = bar(); } return bg.u1.ll + bg.u2.ll; }; // Two union fields loads are partially redundant. gcc genearted code at -O2: foo: .LFB2: subq $24, %rsp .LCFI0: testl %edi, %edi je .L2 xorl %eax, %eax call bar movq %rax, bg(%rip) movq %rdx, bg+8(%rip) .L2: movq bg(%rip), %rax addl bg+8(%rip), %eax addq $24, %rsp ret
Confirmed. Looks like something for postreload-gcse to handle. Before that, there are no partial redundancies in the RTL (at least, not in the quick look I gave it).
GCC is still not generating good code here, neither does ICC. However LLVM does a good job here. David (In reply to comment #1) > Confirmed. Looks like something for postreload-gcse to handle. Before that, > there are no partial redundancies in the RTL (at least, not in the quick look I > gave it).