<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Missed bitfield optimization"
href="https://bugs.llvm.org/show_bug.cgi?id=47700">47700</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed bitfield optimization
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>union u
{
unsigned long ulong_val;
struct {
unsigned long a:4;
unsigned long b:60;
};
};
union u pack(union u in)
{
union u ret;
ret.ulong_val |= in.b;
ret.ulong_val <<= 4;
ret.ulong_val |= in.a;
return ret;
}
pack(u): # @pack(u)
movq %rdi, %rax
orq $-16, %rax
ret
GCC:
pack(u):
movq %rdi, %rax
ret
----------------------------------------
define i64 @src(i64 %0) {
%1:
%2 = alloca i64 8, align 8
%3 = alloca i64 8, align 8
%4 = gep inbounds * %3, 8 x i32 0, 1 x i64 0
store i64 %0, * %4, align 8
%5 = bitcast * %3 to *
%6 = bitcast * %5 to *
%7 = load i64, * %6, align 8
%8 = lshr i64 %7, 4
%9 = bitcast * %2 to *
%10 = load i64, * %9, align 8
%11 = or i64 %10, %8
store i64 %11, * %9, align 8
%12 = bitcast * %2 to *
%13 = load i64, * %12, align 8
%14 = shl i64 %13, 4
store i64 %14, * %12, align 8
%15 = bitcast * %3 to *
%16 = bitcast * %15 to *
%17 = load i64, * %16, align 8
%18 = and i64 %17, 15
%19 = bitcast * %2 to *
%20 = load i64, * %19, align 8
%21 = or i64 %20, %18
store i64 %21, * %19, align 8
%22 = gep inbounds * %2, 8 x i32 0, 1 x i64 0
%23 = load i64, * %22, align 8
ret i64 %23
}
=>
define i64 @tgt(i64 %0) {
%1:
ret i64 %0
}
Transformation seems to be correct!
<a href="https://alive2.llvm.org/ce/z/PJbo7v">https://alive2.llvm.org/ce/z/PJbo7v</a>
Godbolt: <a href="https://godbolt.org/z/zb8zdx">https://godbolt.org/z/zb8zdx</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>