[SR-12046] Creating empty OptionSet with empty array literal generates bad code #54482
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
performance
Environment
Apple Swift version 5.2 (swiftlang-1103.0.19.1 clang-1103.0.30.1)
Target: x86_64-apple-darwin19.0.0
Additional Detail from JIRA
md5: ec0b9f3f4c9bb66b994c0b235ef4e7d8
Issue Description:
The following program defines a straightforward
OptionSet
:When compiled with
-O
, the codegen fortest2
is basically optimal:However, the equivalent function
test1
that attempts to create an emptyOptionSet
generates 315 extra bytes worth of assembly:This nasty codegen is specific to the empty array literal; using the
.init()
construction instead generates optimal code again:It seems that something is defeating the optimiser's ability to optimise initialisation with the empty array literal, even though that optimisation successfully lands with non-empty array literals.
The code size impact is smaller with
-Osize
as the compiler doesn't unroll the loop, but neither outcome is anywhere near optimal.The text was updated successfully, but these errors were encountered: