<div dir="ltr"><div class="gmail_signature"><div class="gmail_signature">I've been doing a lot of performance testing related to generic value types and SIMD lately, and I've built Swift from sources in order to get an idea of what's coming up optimizerwise. Things have improved and the optimizer is impressive overall. But I still see no improvement in the case exemplified below.</div><div class="gmail_signature"><br></div><div class="gmail_signature">Manually unrolling the simple for loop will make it ~ 4 times faster (and exactly the same as when SIMD float4):<br></div><div class="gmail_signature"><br></div><div class="gmail_signature">struct V4<T> {</div><div class="gmail_signature"> var elements: (T, T, T, T)</div><div class="gmail_signature"> /.../</div><div class="gmail_signature"> subscript(index: Int) -> T { /.../ }</div><div class="gmail_signature"> /.../</div><div class="gmail_signature"> func addedTo(other: V4) -> V4 {</div><div class="gmail_signature"> var r = V4()</div><div class="gmail_signature"> // Manually unrolling makes code ~ 4 times faster:</div><div class="gmail_signature"> // for i in 0 ..< 4 { r[i] = self[i] + other[i] }</div><div class="gmail_signature"> r[0] = self[0] + other[0]</div><div class="gmail_signature"> r[1] = self[1] + other[1]</div><div class="gmail_signature"> r[2] = self[2] + other[2]</div><div class="gmail_signature"> r[3] = self[3] + other[3]</div><div class="gmail_signature"> return r</div><div class="gmail_signature"> }</div><div class="gmail_signature"> /.../</div><div class="gmail_signature">}</div><div class="gmail_signature"><br></div><div class="gmail_signature">Shouldn't the optimizer be able to handle that for loop and make the manual unrolling unnecessary?</div><div class="gmail_signature"><br></div><div class="gmail_signature">(compiled the test with -O -whole-module-optimizations, also tried -Ounchecked but with same results.)</div><div class="gmail_signature"><br></div><div class="gmail_signature">/Jens</div><div class="gmail_signature"><br></div></div>
</div>