diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2023-11-07 07:13:25 +0000 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-11-08 23:55:53 -0700 |
| commit | d99bed1b10f85f2becca2a1c2587e1c2cb1968e6 (patch) | |
| tree | e23b0ea094d2c4541c8dfa17d2a8681e892349ef /src/codegen/llvm/BitcodeReader.zig | |
| parent | a1d688b86aeba7ab72ae12679ff04a7730931af3 (diff) | |
| download | zig-d99bed1b10f85f2becca2a1c2587e1c2cb1968e6.tar.gz zig-d99bed1b10f85f2becca2a1c2587e1c2cb1968e6.zip | |
Sema: optimize runtime array_mul
There are two optimizations here, which work together to avoid a
pathological case.
The first optimization is that AstGen now records the result type of an
array multiplication expression where possible. This type is not used
according to the language specification, but instead as an optimization.
In the expression '.{x} ** 1000', if we know that the result must be an
array, then it is much more efficient to coerce the LHS to an array with
length 1 before doing the multiplication. Otherwise, we end up with a
1000-element tuple which we must coerce to an array by individually
extracting each field.
Secondly, the previous logic would repeatedly extract element/field
values from the LHS when initializing the result. This is unnecessary:
each element must only be extracted once, and the result reused.
These changes together give huge improvements to compiler performance on
a pathological case: AIR instructions go from 65551 to 15, and total AIR
bytes go from 1.86MiB to 264.57KiB. Codegen time spent on this function
(in a debug compiler build) goes from minutes to essentially zero.
Resolves: #17586
Diffstat (limited to 'src/codegen/llvm/BitcodeReader.zig')
0 files changed, 0 insertions, 0 deletions
