<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 optimization: aliasing problem in a struct when a member array is indexed with 64-bit int"
href="https://bugs.llvm.org/show_bug.cgi?id=44718">44718</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed optimization: aliasing problem in a struct when a member array is indexed with 64-bit int
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>michel.bernert@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Tested with clang 9.0.0: x86_64-pc-windows-msvc
Compiled with '-O2'.
-----C CODE-----
#include <stdint.h>
struct S {
uint32_t a;
uint32_t array[32];
};
uint32_t test1(struct S* ptr, uint32_t index)
{
ptr->a = 5;
ptr->array[index] = 4;
return ptr->a;
}
uint32_t test2(struct S* ptr, uint64_t index)
{
ptr->a = 5;
ptr->array[index] = 4;
return ptr->a;
}
----------------
Produced assembly:
test1:
mov dword ptr [rcx], 5
mov eax, edx
mov dword ptr [rcx + 4*rax + 4], 4
mov eax, 5
ret
test2:
mov dword ptr [rcx], 5
mov dword ptr [rcx + 4*rdx + 4], 4
mov eax, dword ptr [rcx]
ret
In 'test2', the first store is not forwarded, as if the array store could
overwrite the first member. This doesn't happen in 'test1' where the index is
32-bits.
If I'm not mistaken, any index outside the array range is undefined behaviour,
regardless of the width of the index, so I don't see any reason for a member
store to alias another member.
I also tested with GCC and in both cases the first store is correctly
forwarded.</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>