Bug 35310 - Late struct expansion -- missing PRE (2)
Summary: Late struct expansion -- missing PRE (2)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2008-02-23 05:27 UTC by davidxl
Modified: 2012-10-31 21:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-02-03 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description davidxl 2008-02-23 05:27:00 UTC
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
Comment 1 Steven Bosscher 2009-02-06 21:52:19 UTC
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).
Comment 2 davidxl 2012-10-31 21:17:27 UTC
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).