[SR-9809] swiftc appears to make some sub-optimal optimization choices #52229
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler itself
performance
Attachment: Download
Environment
I have tested this out with both swift 4.2.1 (Xcode 10.1), and swift 5 (Xcode 10.2b1).
Additional Detail from JIRA
md5: 8253cbbd63b4aa9d3b4b4607f09e3f48
Issue Description:
I was playing around with the compiler the other day in an attempt to discover techniques for getting Swift to produce faster code, and then I encountered a bit of a head-scratcher along the way.
Attached is some simple code that demonstrates a case where Swift appears to produce sub-optimal assembly for code that uses an
UnsafeBufferPointer<Float>
compared to the same code using[Float]
.Specifically, when compiling with
-O
, the version using[Float]
is optimized how I would expect, and-Ounchecked
appears to produce identical code. But the version that usesUnsafeBufferPointer<Float>
produces assembly that does not unroll the loop when I specify-O
, however it unrolls the loop (and produces identical assembly to[Float]
) when I specify-Ounchecked
.I have included the sample code, and a script that will run the Swift compiler to produce assembly for both pieces of code, with both of the optimization flags.
The text was updated successfully, but these errors were encountered: