<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 - Misoptimization involving memset and store"
href="https://bugs.llvm.org/show_bug.cgi?id=36129">36129</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Misoptimization involving memset and store
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</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>jbc.engelen@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=19760" name="attach_19760" title="O3 output LLVM5.0">attachment 19760</a> <a href="attachment.cgi?id=19760&action=edit" title="O3 output LLVM5.0">[details]</a></span>
O3 output LLVM5.0
The `llvm5.ll` is the optimized (-O3) output of LLVM 5.0 opt of a simple
testcase compiled by LDC. The testcase is setting %dt and %dt2 to the same
value by different means, and asserts that they are equal indeed.
`llvm6.ll` is the output of opt 6.0.0 when optimizing `llvm5.ll`:
reproducer= `opt -O3 llvm5.ll -S -o llvm6.ll`.
LLVM6.0 does a misoptimization and the assert fails.
Zooming in:
```
%datum.DateTime = type { %datum.Date, %datum.TimeOfDay, [1 x i8] }
%datum.Date = type { i16, i8, [1 x i8] }
%datum.TimeOfDay = type { i8, i8, i8 }
define i32 @main....
%dt2 = alloca i64, align 8
%tmpcast = bitcast i64* %dt2 to %datum.DateTime*
;...
%5 = bitcast i64* %dt2 to i8*
store i64 1, i64* %dt2, align 8
%6 = getelementptr inbounds %datum.DateTime, %datum.DateTime* %tmpcast, i64
0, i32 1, i32 0
call void @llvm.memset.p0i8.i64(i8* %6, i8 0, i64 3, i32 4, i1 false) #5
%7 = getelementptr inbounds %datum.DateTime, %datum.DateTime* %tmpcast, i64
0, i32 1, i32 1
store i8 30, i8* %7, align 1
```
is optimized to
```
define i32 @main....
%dt2 = alloca i64, align 8
%tmpcast = bitcast i64* %dt2 to %datum.DateTime*
;...
%5 = bitcast i64* %dt2 to i8*
; The following store is correct I think
store i64 32985348833281, i64* %dt2, align 8
%6 = getelementptr inbounds %datum.DateTime, %datum.DateTime* %tmpcast, i64
0, i32 1, i32 0
; This memset overwrites partly the correct value.
; I think if this memset would not be there, all would be fine.
call void @llvm.memset.p0i8.i64(i8* nonnull %6, i8 0, i64 3, i32 4, i1 false)
#4
```
[Remark: I can see that perhaps endianness is tricky here. But actually, the
LLVM optimizer itself converted the type of %dt2 to i64* (instead of
%datum.DateTime*).]</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>