<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 - opt ignores alignment"
href="https://bugs.llvm.org/show_bug.cgi?id=45188">45188</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>opt ignores alignment
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm@henning-thielemann.de
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>I have a nested struct, where the inner struct contains an i64 and thus
requires 8-byte alignment.
$ cat alignment.ll
target triple = "x86_64-unknown-linux-gnu"
%struct = type { i1, { float, i64 } }
define %struct* @initialize(i8*) {
%ptr = bitcast i8* %0 to %struct*
%ptrBool = getelementptr %struct, %struct* %ptr, i32 0, i32 0
store i1 1, i1* %ptrBool
%ptrFloat = getelementptr %struct, %struct* %ptr, i32 0, i32 1, i32 0
store float 42.0, float* %ptrFloat
%ptrInt64 = getelementptr %struct, %struct* %ptr, i32 0, i32 1, i32 1
store i64 123456789, i64* %ptrInt64
ret %struct* %ptr
}
Without optimization the field offsets are computed correctly:
$ llc-9 <alignment.ll
.text
.file "<stdin>"
.globl initialize # -- Begin function initialize
.p2align 4, 0x90
.type initialize,@function
initialize: # @initialize
.cfi_startproc
# %bb.0:
movq %rdi, %rax
movb $1, (%rdi)
movl $1109917696, 8(%rdi) # imm = 0x42280000
movq $123456789, 16(%rdi) # imm = 0x75BCD15
retq
.Lfunc_end0:
.size initialize, .Lfunc_end0-initialize
.cfi_endproc
# -- End function
.section ".note.GNU-stack","",@progbits
With optimization the struct becomes surprisingly more compact:
$ opt-9 -O1 <alignment.ll | llc-9
.text
.file "<stdin>"
.globl initialize # -- Begin function initialize
.p2align 4, 0x90
.type initialize,@function
initialize: # @initialize
# %bb.0:
movq %rdi, %rax
movb $1, (%rdi)
movl $1109917696, 4(%rdi) # imm = 0x42280000
movq $123456789, 8(%rdi) # imm = 0x75BCD15
retq
.Lfunc_end0:
.size initialize, .Lfunc_end0-initialize
# -- End function
.section ".note.GNU-stack","",@progbits
It looks like opt flattens the struct.
$ opt-9 -O1 <alignment.ll | llvm-dis-9
; ModuleID = '<stdin>'
source_filename = "<stdin>"
target triple = "x86_64-unknown-linux-gnu"
%struct = type { i1, { float, i64 } }
; Function Attrs: nofree norecurse nounwind writeonly
define %struct* @initialize(i8*) local_unnamed_addr #0 {
%ptr = bitcast i8* %0 to %struct*
%ptrBool = bitcast i8* %0 to i1*
store i1 true, i1* %ptrBool, align 1
%ptrFloat = getelementptr i8, i8* %0, i64 4
%2 = bitcast i8* %ptrFloat to float*
store float 4.200000e+01, float* %2, align 4
%ptrInt64 = getelementptr i8, i8* %0, i64 8
%3 = bitcast i8* %ptrInt64 to i64*
store i64 123456789, i64* %3, align 4
ret %struct* %ptr
}
attributes #0 = { nofree norecurse nounwind writeonly }
It seems that bitcasting from i8* enables opt to do wrong simplifications.
If I replace i8* by {}* then opt leaves the struct layout as is.
Is this a bug or a feature?
Do I need to give opt more information in order to prevent it from such wrong
simplifications?</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>