Bug 42591 - missing constant evaluation for const union
Summary: missing constant evaluation for const union
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: 4.6.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2010-01-03 07:13 UTC by Andi Kleen
Modified: 2012-03-13 23:44 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux
Target: x86-64-linux
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andi Kleen 2010-01-03 07:13:59 UTC
typedef long long s64;
From 
http://embed.cs.utah.edu/embarrassing/dec_09/harvest/gcc-head_llvm-gcc-head/

typedef unsigned long long u64;
union ktime
{
  s64 tv64;
};
typedef union ktime ktime_t;
ktime_t ns_to_ktime (u64 ns);
union ktime const ktime_zero = { 0LL };

ktime_t
ns_to_ktime (u64 ns)
{
  ktime_t __constr_expr_0;

  {
    __constr_expr_0.tv64 = (s64) ((u64) ktime_zero.tv64 + ns);
    return (__constr_expr_0);
  }
}

/* Checksum = 1A82CF6 */

this generates with 4.5.0 20091219 -O2 

 movq    %rdi, %rax
 addq    ktime_zero(%rip), %rax
 ret

llvm in this case uses the known const value of ktime_zero and just generates
an assignment (this makes more difference with -m32) gcc should too.
Comment 1 Andrew Pinski 2010-01-03 07:22:10 UTC
fold_const_aggregate_ref should handle it but maybe the CONSTRUCTOR does not the field set. 
Comment 2 Andrew Pinski 2012-03-13 23:44:58 UTC
Fixed in 4.6.0.