Commit Graph

2295 Commits

Author SHA1 Message Date
Mark Lacey
dd535d0d6d Remove unused header.
Swift SVN r26745
2015-03-31 00:53:29 +00:00
Nadav Rotem
83b194fb08 Remove some of the passes in the optimization pipeline.
I measured zero performance regressions on the test suite. I added an early
CSE pass because of a specific example in one of the tests where the inliner
brought in an integer literal that needed to be CSE-ed before inst-combine
could fold a comparison into a constant, and simplify-cfg get rid of that
constant.

Representing our literal values as instructions (e.g. integer_literal) forces
us to run CSE constantly. We also need to re-run InstCombine very frequently
because InstSimplifier is not allowed to create new instructions!

Swift SVN r26736
2015-03-30 23:04:29 +00:00
Roman Levenstein
e31ffa6918 Use covered switches to catch potential bugs in the future. NFC.
Swift SVN r26733
2015-03-30 22:25:29 +00:00
Mark Lacey
7d5256f03a Devirtualize in the performance inliner.
Attempt to devirtualize any apply that we come across in the performance
inliner prior to attempting to inline.

The is the first step of getting the inliner/specializer/devirtualizer
working together so that we can converge on high quality code with less
work.

Although this is not meant to directly improve performance, but rather
be a step towards converging to high quality code with fewer passes,
because it alters what gets inlined when, it did have a (mostly)
positive effect on performance.

These are some of the larger deltas I see, where the percentage is
percentage speed-up, and negative percentages indicate a slow-down.

-O:
---
BenchLangCallingCFunction         16.7%
CaptureProp                       17.1%
Sim2DArray                        22.0%

-Ounchecked
-----------
BenchLangCallingCFunction        -11.2%
QuickSort                         39.4%
SwiftStructuresBubbleSort        -26.7%

Swift SVN r26728
2015-03-30 21:24:46 +00:00
Roman Levenstein
71b0e7b4a6 [sil-simplify-cfg] Fix a bug in CheckedCastBrJumpThreading.
Be more careful when replacing targets of terminators. This finally implements a long-due FIXME in CheckedCastBrJumpThreading.

rdar://20345557.

Swift SVN r26725
2015-03-30 21:10:38 +00:00
Erik Eckstein
f2b0e99138 SimplifyCFG: Simplify terminators which jump to a common destination block (without arguments) on all successors.
Such terminators are replaced with a simple branch instruction.
This optimization was done for cond_br but not for other terminators, like switch_enum.




Swift SVN r26716
2015-03-30 15:50:47 +00:00
Michael Gottesman
6bd51ea51c Small style cleanups and convert query to use covered switch. NFC.
Swift SVN r26703
2015-03-29 20:29:07 +00:00
Chris Lattner
d5769ad609 fix <rdar://problem/20097963> incorrect DI diagnostic in unreachable code
Swift SVN r26679
2015-03-28 05:47:52 +00:00
Michael Gottesman
99e0b6bb19 [codemotion] Instead of passing in whether we are late or early, create late early entry points.
I need this so I can write some tests for the late code motion pass in sil-opt.
Plus it follows the model in the inliner.

Swift SVN r26671
2015-03-28 02:47:07 +00:00
John McCall
1ffb87bb1f Implement a 'throw' instruction in SIL.
Swift SVN r26668
2015-03-28 02:00:20 +00:00
Michael Gottesman
a07e8c8fd2 Make the late code motion hoist releases.
Swift SVN r26663
2015-03-28 00:47:11 +00:00
Michael Gottesman
74777a6c3a [remove-pin] Teach remove pin how to recognize a safe guaranteed array semantic call sequence.
Given a strong_pin for which we have not yet seen a strong_unpin, a safe
guaranteed call sequence is of the following form:

retain(x)
call f(@guaranteed x)
release(x)

where f is an array semantic call that we know does not touch globals and thus
are known to not change ref counts.

rdar://20305817

Swift SVN r26662
2015-03-28 00:43:47 +00:00
Roman Levenstein
9b0cb402fc [sil-simplify-cfg] Move the implementation of CheckedCastBrJumpThreading into its own file. NFC.
This is a part of our attempts to clean-up the SimplifyCFG, which got just too huge to work with.

Swift SVN r26660
2015-03-28 00:42:08 +00:00
Nadav Rotem
1e99e160e8 Remove some of the passes at the late stages of the optimization pipeline.
After many attempts I found that the change in this commit does not regress
the performance of the test suite. The passes that I added in this commit come
to replace the late 'SSAPasses' pipe. I am still not completely sure why there
is such a strong dependency between SimplifyCFG and InstCombine.

Swift SVN r26658
2015-03-28 00:20:38 +00:00
Nadav Rotem
412f65a894 Fix a Release mode warning of unused variable.
Swift SVN r26657
2015-03-28 00:20:29 +00:00
Nadav Rotem
94352efa46 SimplifyCFG: Allow canonicalizeSwitchEnums to report when the function was modified.
Swift SVN r26647
2015-03-27 22:10:29 +00:00
Nadav Rotem
a23ec7687d Remember to invalidate PostDom.
Now that we split Dom from PDom analysis we need to invalidate PDom wherever
we invalidate Dom.

Swift SVN r26646
2015-03-27 22:09:43 +00:00
Nadav Rotem
240ff14db1 Split DominanceAnalysis into Dom and PDom using FunctionAnalysisBase.
This commit splits DominanceAnalysis into two analysis (Dom and PDom) that
can be cached and invalidates using the common FunctionAnalysisBase interface
independent of one another.

Swift SVN r26643
2015-03-27 20:54:28 +00:00
Nadav Rotem
50803a7653 Create FunctionAnalysisBase to handle the boiler plate of caching and invalidating function specific analysis.
Swift SVN r26642
2015-03-27 20:54:22 +00:00
Nadav Rotem
f0fa502d56 Split the RCIdentityAnalysis analysis to allow per-function invalidation.
Before the change the RCIdentityAnalysis kept a single map that contained
the module's RC information. When function passes needed to invalidate the
analysis they had to clear the RC information for the entire module. The
problem was mitigated by the fact that we process one function at a time, and
we start processing a new function less frequently.

II adopted the DominanceAnalysis structure. We should probably implement
this functionality as CRTP.

Swift SVN r26636
2015-03-27 16:55:36 +00:00
Erik Eckstein
9ef85c461b SimplifyCFG: Move optimization from CondFailOpt to SimplifyCFG and remove CondFailOpt pass.
I completely missed that one of the CondFailOpt optimization was already implemented in SimplifyCFG.
I move the other optimization also into SimplifyCFG because both share some code.



Swift SVN r26626
2015-03-27 14:07:14 +00:00
Erik Eckstein
28d9abc394 SimplifyCFG: Eliminate a block argument if all incoming values are equal.
Gives ~ 10% on SelectionSort@-O



Swift SVN r26625
2015-03-27 11:48:14 +00:00
Nadav Rotem
2bfe3cf586 Teach the SIL Linker pass to preserve branch information.
The linker pulls in new functions (which can change the call graph) but it
does not change the control flow of the processed function.

Swift SVN r26614
2015-03-26 23:38:29 +00:00
Nadav Rotem
4afd4305e5 Disable generic specialization in the devirtualzier.
The current approach does not improve the compile time. Mark has a better plan
for making the inliner/devirtualizer/specializer work together.

Swift SVN r26613
2015-03-26 23:38:18 +00:00
Arnold Schwaighofer
468a1ea9d5 SimplifyCFG: Simplify and sanitize the jump threading code
We are able to jump-thread all kinds of terminators these days. Only jump thread
switch-enums if there is really a chance of simplifying. Don't jump thread
blocks with function calls in them.

Swift SVN r26599
2015-03-26 20:03:19 +00:00
Nadav Rotem
e8d84c0850 Rewrite the code to avoid inserting unhandled instructions rather than removing it after insertion. NFC.
Swift SVN r26595
2015-03-26 17:17:28 +00:00
Nadav Rotem
28042c7030 Fix a bug in the comparison of -INT_MIN values. The result of abs() is an unsinged number that can represent the complete input range. We need to use unsigned operations on the result of abs().
Swift SVN r26594
2015-03-26 15:15:36 +00:00
Nadav Rotem
7aa6a27a22 Abbreviate the constraint argument names to match the comments. NFC.
Swift SVN r26593
2015-03-26 15:15:18 +00:00
Erik Eckstein
9d8c98551c Add an optimization pass to optimize cond_fail instructions.
Summary: it tries to move cond_fail instruction to predecessor blocks, if benefitial.
For details see the comment in CondFailOpt.cpp.



Swift SVN r26592
2015-03-26 14:40:59 +00:00
Mark Lacey
62065f7f50 Update function sig opts to work with upcoming call graph changes.
Small tweak to function signature optimization so that it filters out
applies that might have multiple targets, as well as applies of partial
applies, which will take some updates to handle.

Resolves rdar://problem/19632244 and rdar://problem/20049782.

I've opened rdar://problem/20306331 to consider handling
apply-of-partial-apply at some point in the future.

Swift SVN r26585
2015-03-26 09:00:32 +00:00
Roman Levenstein
7011a5f4b4 [generic-specializer] Add support for specializing generic partial_apply instructions.
Use existing machinery of the generic specializer to produce generic specializations of closures referenced by partial_apply instructions. Thanks to the newly introduced ApplyInstBase class, the required changes in the generic specializer are very minimal.

rdar://19290942

Swift SVN r26582
2015-03-26 06:41:30 +00:00
Mark Lacey
88e19c9dec Pass a map by const reference rather than by value.
Update look-ups in the map to use find() rather than operator[] so that
we don't inadvertantly insert new items.

Swift SVN r26580
2015-03-26 06:13:50 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00
Nadav Rotem
e320b2466e Fix a bug in the code that removes overflows from signed multiplication.
The overflow check for X * 1 does not guard the check for X * -1
because X could be MIN_INT, and MIN_INT*-1 overflows. In the new code
we check that the new multiplier is smaller (not smaller or equal).

Swift SVN r26553
2015-03-25 20:42:24 +00:00
Nadav Rotem
13c9f22f73 Fix a bug in the code that removes redundant overflow checks in signed multiplication.
Previously we were removing overflow checks if a previous (or future) check
used a smaller multiplier. However, this logic is incorrect for signed integers
because it does not consider underflows (example, x * 10 vs. x * -100000).

The code now checks that the multiplier that's dominated by another check is
closer or equal to zero (the absolute value is smaller or equal to the
guarding multiplier).

Swift SVN r26550
2015-03-25 19:47:31 +00:00
Nadav Rotem
ae75f152dc Teach DCE to invalidate branches and calls only if changes were made.
Swift SVN r26549
2015-03-25 19:47:28 +00:00
Nadav Rotem
dc01d61c72 [overflow] Teach the overflow optimizations to get rid of multiplication overflow checks.
Use the knowledge of previous (or future) overflow checks to remove multiplication by smaller values.
For example:
  x * 100
  x * 10 // can remove this overflow checks.

Swift SVN r26543
2015-03-25 17:01:26 +00:00
Erik Eckstein
14f5fb86e2 SimplifyCFG: small refactoring, NFC
Swift SVN r26537
2015-03-25 09:37:20 +00:00
Mark Lacey
08bfb01db7 Tweak exclusion logic in function signature optimizations.
We no longer force-inline transparent functions that make it to the
performance inliner, so bailing on these makes less sense.

Swift SVN r26536
2015-03-25 09:03:39 +00:00
Mark Lacey
db3530e7c8 Tweak function deletion logic in mandatory inlining.
Now that we generate autoclosure functions with the transparent bit set,
we only need to check that bit to determine whether we can delete
inlined functions.

Swift SVN r26535
2015-03-25 09:03:38 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Michael Gottesman
254c784c94 [+0 self][pin removal] Teach pinremoval how to use RCIdentityAnalysis when removing pins.
Previously, we were being very conservative and were not trying to look through
any RCId uses. Now we understand how to look through RCIdentical instructions to
pair a pin and unpin. We also understand how to use the new getRCUses API on
RCIdentityAnalysis to get all uses of a value, looking through RCIdentical
instructions.

I also added some code to COWArrayOpts to teach it how to look through enum insts (which I needed).

Additionally I got stuck and added support for automatic indentation in Debug
statements. This is better than having to indent by hand every time.

There were no significant perf changes since this code was not being emitted by
the frontend. But without this +0 self causes COW to break.

rdar://20267677

Swift SVN r26529
2015-03-25 06:21:11 +00:00
Michael Gottesman
5c3b4a8dfe [cow] Teach uniqueness about mark_dependence on the array value.
We already did this for element accesses, this just extends it to handle array value.

This prevents a regression that is caused by my needing to insert an enum
so I can properly RAW a strong_pin operand onto the strong pin's users in a
subsequent patch to improve RemovePin for +0 self.

rdar://20267677

Swift SVN r26528
2015-03-25 06:21:10 +00:00
Michael Gottesman
a2233ebef4 [cow] Replaced some for () { if-else-if-else } code with common terminator statements with individual terminator. NFC.
Swift SVN r26527
2015-03-25 06:21:10 +00:00
Mark Lacey
a367feae6a Make all autoclosures transparent, and stop checking isTransparent on apply.
This should clear the way for removing isTransparent on apply entirely.

Previously we marked any apply of an autoclosure transparent, but now
that the mandatory inliner inlines anything marked transparent, we don't
need that.

Resolves rdar://problem/20286251.

Swift SVN r26525
2015-03-25 05:55:33 +00:00
Mark Lacey
3bb5122aaa During mandatory inlining, look at isTransparent() on the callee.
Mandatory inlining normally only looks at isTransparent() on the apply
instruction. This change makes it also inline in cases where the apply
is not marked isTransparent(), but the applied function is. This can
arise in cases where previous transparent inlining exposes new
opportunities, e.g. when a transparent function is passed as a parameter
to another transparent function.

Resolves rdar://problem/19419019.

Swift SVN r26516
2015-03-25 02:48:11 +00:00
Erik Eckstein
ce13c48090 SimplifyCFG: Ignore expect-intrinsics for dominator-based cond_br optimization.
Swift SVN r26490
2015-03-24 15:49:53 +00:00
Erik Eckstein
2c967f891d SILCombine: Optimize binary bit operations: and, or, xor.
It does the usual things, e.g. x & 0 -> 0, x | 0 -> x, etc.



Swift SVN r26489
2015-03-24 15:48:30 +00:00
Erik Eckstein
b0f55d701d Enable bridge_object_to_word instruction for CSE.
Swift SVN r26488
2015-03-24 15:45:56 +00:00
Nadav Rotem
683317e607 Fix two cases where SimplifyCFG invalidated analysis too aggressively.
Swift SVN r26481
2015-03-24 04:56:21 +00:00