[llvm-bugs] [Bug 47700] New: Missed bitfield optimization
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Oct 1 00:15:05 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47700
Bug ID: 47700
Summary: Missed bitfield optimization
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
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!
https://alive2.llvm.org/ce/z/PJbo7v
Godbolt: https://godbolt.org/z/zb8zdx
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201001/10c685c8/attachment-0001.html>
More information about the llvm-bugs
mailing list