<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - Many small consecutive moves of constants aren't optimized into something better."
href="https://llvm.org/bugs/show_bug.cgi?id=31844">31844</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Many small consecutive moves of constants aren't optimized into something better.
</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>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>george.burgess.iv@gmail.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>george.burgess.iv@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Motivating example: <a href="https://godbolt.org/g/VOk6W6">https://godbolt.org/g/VOk6W6</a>
Danny noted that test2 gets turned into good code because clang emits an
intermediate alloca to write the {0, 1, ...} array to, whereas in test1, {0, 1,
...} gets written directly to an sret param. As a result, SROA was able to work
on test2, but not test1.
The idea at the moment is that we should just make MemCpyOpt handle this; it's
happy to turn consecutive stores of the same value into a memset, but isn't
currently able to turn consecutive stores of different values into a memcpy:
<a href="http://llvm.org/docs/doxygen/html/MemCpyOptimizer_8cpp_source.html#l00626">http://llvm.org/docs/doxygen/html/MemCpyOptimizer_8cpp_source.html#l00626</a> .
I'm happy to see what I can do here, but this isn't at the top of my list. So,
if someone else wants to jump on this, feel free. :)
(Mildly verbose) repro: running `opt -O2` on the following code is effectively
a nop.
%struct.FooContainer = type { i16, %struct.Foo, i16 }
%struct.Foo = type { [16 x i8] }
; Function Attrs: norecurse nounwind uwtable
define void @_Z5test1v(%struct.FooContainer* noalias nocapture sret
%agg.result) local_unnamed_addr {
entry:
%a = getelementptr inbounds %struct.FooContainer, %struct.FooContainer*
%agg.result, i64 0, i32 0
store i16 0, i16* %a, align 2
%arrayinit.begin = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 0
store i8 0, i8* %arrayinit.begin, align 2
%arrayinit.element = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 1
store i8 1, i8* %arrayinit.element, align 1
%arrayinit.element2 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 2
store i8 2, i8* %arrayinit.element2, align 2
%arrayinit.element3 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 3
store i8 3, i8* %arrayinit.element3, align 1
%arrayinit.element4 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 4
store i8 4, i8* %arrayinit.element4, align 2
%arrayinit.element5 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 5
store i8 5, i8* %arrayinit.element5, align 1
%arrayinit.element6 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 6
store i8 6, i8* %arrayinit.element6, align 2
%arrayinit.element7 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 7
store i8 7, i8* %arrayinit.element7, align 1
%arrayinit.element8 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 8
store i8 8, i8* %arrayinit.element8, align 2
%arrayinit.element9 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 9
store i8 9, i8* %arrayinit.element9, align 1
%arrayinit.element10 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 10
store i8 10, i8* %arrayinit.element10, align 2
%arrayinit.element11 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 11
store i8 11, i8* %arrayinit.element11, align 1
%arrayinit.element12 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 12
store i8 12, i8* %arrayinit.element12, align 2
%arrayinit.element13 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 13
store i8 13, i8* %arrayinit.element13, align 1
%arrayinit.element14 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 14
store i8 14, i8* %arrayinit.element14, align 2
%arrayinit.element15 = getelementptr inbounds %struct.FooContainer,
%struct.FooContainer* %agg.result, i64 0, i32 1, i32 0, i64 15
store i8 15, i8* %arrayinit.element15, align 1
%c = getelementptr inbounds %struct.FooContainer, %struct.FooContainer*
%agg.result, i64 0, i32 2
store i16 7, i16* %c, align 2
ret void
}</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>