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. -- Summary: missing constant evaluation for const union Product: gcc Version: unknown Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: tree-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: andi-gcc at firstfloor dot org GCC host triplet: x86_64-linux GCC target triplet: x86-64-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42591 >From Received: (qmail 12960 invoked by uid 48); 3 Jan 2010 07:14:00 -0000 Date: 3 Jan 2010 07:14:00 -0000 Subject: [Bug tree-optimization/42591] New: missing constant evaluation for const union X-Bugzilla-Reason: CC Message-ID: <bug-42591-7...@http.gcc.gnu.org/bugzilla/> Reply-To: gcc-bugzi...@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "andi-gcc at firstfloor dot org" <gcc-bugzi...@gcc.gnu.org> typedef long long s64;