Commit Graph

2592 Commits

Author SHA1 Message Date
Erik Eckstein
380ded8151 SimplifyCFG: debug dump the function name at the beginning of the pass 2016-05-05 10:34:08 -07:00
Erik Eckstein
f24e23660d SimplifyCFG: don't jump thread if the condition is an undef.
Uses of undef can be in a different function. This may result in modifying another function.
A test is included in a following commit.
2016-05-05 10:34:08 -07:00
Erik Eckstein
512cc62e43 SimplifyCFG: recalculate loop header information if a loop header block is jump threaded. 2016-05-05 10:34:08 -07:00
Erik Eckstein
9577aa698a fix comment 2016-05-05 10:34:08 -07:00
Erik Eckstein
7f71e4c6fe SimplifyCFG: improve debug logging 2016-05-05 10:34:08 -07:00
Xin Tong
ccdbc329af Merge pull request #2389 from trentxintong/DSE
Update comments and remove dead functions in DSE
2016-05-04 16:26:05 -07:00
Xin Tong
a6082ae8f1 Update comments and remove dead functions in DSE 2016-05-03 21:23:25 -07:00
Xin Tong
be029e01ea Merge pull request #2386 from trentxintong/DSE
Fix a bug in dead store elimination.
2016-05-03 20:22:38 -07:00
Xin Tong
15df3016e0 Make smaller stores generated for stores that are partly dead deterministic
We do not have problem right now because the we only do partial dead store when
we end up generating only 1 single smaller store.
2016-05-03 17:53:11 -07:00
Xin Tong
c4eda1abbb Fix a bug in dead store elimination. Make sure we consider SILargument when we
invalidate base.

Also small change on how BlockState is allocated.
2016-05-03 16:55:39 -07:00
practicalswift
540cb751ac [gardening] Fix recently introduced typo: "adavances" → "advances"
[gardening] Fix recently introduced typo: "compie" → "compile"

[gardening] Fix recently introduced typo: "consise" → "concise"

[gardening] Fix recently introduced typo: "dengerate" → "degenerate"

[gardening] Fix recently introduced typo: "encodeded" → "encoded"

[gardening] Fix recently introduced typo: "equvalent" → "equivalent"

[gardening] Fix recently introduced typo: "guaranted" → "guaranteed"

[gardening] Fix recently introduced typo: "overridde" → "override"

[gardening] Fix recently introduced typo: "subsquence" → "subsequence"

[gardening] Fix recently introduced typo: "substraction" → "subtraction"

[gardening] Fix recently introduced typo: "whiltespace" → "whitespace"
2016-05-01 20:07:18 +02:00
Arnold Schwaighofer
98e3253bbd UnsafeGuaranteed Peephole: Handle a release after the UnsafeGuaranteedEnd instruction
We seem to emit this pattern now.
2016-04-30 14:17:38 -07:00
Erik Eckstein
53bb3e8ea1 SimplifyCFG: improve switch_enum simplification.
Figure out the enum case if an enum value is dominated by a switch_enum and use this info for a subsequent switch_enum to be simplified.

This change partly recovers the ClosedRange-regression.
rdar://problem/25933907
2016-04-29 10:57:01 -07:00
Erik Eckstein
16e600a6a1 StackPromotion: fix a bug which could place the deallocation inside a loop. 2016-04-29 08:55:13 -07:00
Roman Levenstein
7a9b05babf [sil-devirtualizer] Fix some bugs in the devirtualizer.
- Don't crash if a class_method instruction could not be devirtualized.
- Improve devirtualization of methods with generic parameters and using dependent types.
- Fix a bug in isBindableToSuperclassOf, uncovered while fixing the original bug reported in SR-1206.
  This bug could lead in certain cases to invocations of a wrong method from the base class, instead
  of using a method from a derived class.

rdar://25891588   and SR-1206
2016-04-28 22:40:47 -07:00
Xin Tong
57e2bdb123 Revert "Simplify function signature optimization" 2016-04-25 16:33:17 -07:00
Xin Tong
633ca2e92b Simplify function signature optimzation.
Several functionalities have been added to FSO over time and the logic has become
muddled.

We were always looking at a static image of the SIL and try to reason about what kind of
function signature related optimizations we can do.

This can easily lead to muddled logic. e.g. we need to consider 2 different function
signature optimizations together instead of independently.

Split 1 single function to do all sorts of different analyses in FSO into several
small transformations, each of which does a specific job. After every analysis, we produce
a new function and eventually we collapse all intermediate thunks to in a single thunk.

With this change, it will be easier to implement function signature optimization as now
we can do them independently now.

Minimal modifications to the test cases.
2016-04-25 15:28:51 -07:00
Erik Eckstein
3945539e71 DeadObjectElimination: use the debug location of the array store instead of the (unknown) instruction of the lifetime frontier.
The location of the lifetimefrontier can be a return-location which is invalid for the generated release instruction.
2016-04-25 11:38:49 -07:00
practicalswift
9a078b54ef [gardening] Fix recently introduced typo: "a executable" → "an executable"
[gardening] Fix recently introduced typo: "a offset" → "an offset"
[gardening] Fix recently introduced typo: "accessiblity" → "accessibility"
[gardening] Fix recently introduced typo: "cant" → "can't"
[gardening] Fix recently introduced typo: "inteference" → "interference"
[gardening] Fix recently introduced typo: "unsatified" → "unsatisfied"
[gardening] Remove accidental space.
2016-04-24 22:11:59 +02:00
Slava Pestov
2e52338d7c SIL: Rename long form of getOrCreateFunction() to createFunction(), NFC
This made call sites confusing to read because it doesn't actually
check if the function already exists.

Also fix some minor formatting issues. This came up while I was working
on a fix for a bug that turned out to not be a bug.
2016-04-21 17:58:10 -07:00
Erik Eckstein
7348e48727 Don't stack promote allocations in no-return blocks.
Such allocations may missing their final release, which confuses stack-promotion.

Fixes rdar://problem/25842757.
2016-04-21 12:08:58 -07:00
practicalswift
abacf7e73d Merge pull request #2243 from practicalswift/gardening-20160419
[gardening] Typos, PEP-8 and unused code.
2016-04-20 07:30:59 +02:00
Xin Tong
7d26a47200 Fix a non-deterministic retain/release insertion in RRCodeMotion 2016-04-19 22:14:38 -07:00
Xin Tong
c2e8c81227 Disable retain release code motion. There is some nondeterminism in
how we insert the new retain release instructions
2016-04-19 21:42:59 -07:00
Xin Tong
49f1c66d7b Rename mayUseValue to mayHaveSymmetricInteference 2016-04-19 15:23:45 -07:00
practicalswift
092007bf12 [gardening] Fix recently introduced typos. 2016-04-19 21:48:05 +02:00
Xin Tong
51b1c0bc68 Implement retain, release code motion.
Iterative data flow retain sinking and release hoisting.

This allows us to sink retains and hoist releases across harmless loops. which is
an improvement on the SILCodeMotion retain sinking and release hoisting.

It also separates the duty of moving retain and release with the duty of eliminating them
in ASO.

This should eventually replace RR code motion in SILcodemotion and insertion point
in ARCsequence opts (ASO).

This is the performance difference i get with retain sinking and release hoisting.
After disabling retain release code motion in ASO and SILCodeMotion. we can start to take
those code out once this lands.

I see that we go from 24.5% of time spent in SILOptimizations w.r.t. the whole stdlib compilation
to 25.1%.

Improvement is better (i.e. retain sinking and hoisting releases result in performance gain).

<details open>
  <summary>Regression (7)</summary>

TEST                                                    | OLD_MIN | NEW_MIN | DELTA (%) | SPEEDUP
---                                                     | ---     | ---     | ---       | ---
SetIsSubsetOf                                           | 441     | 510     | +15.7%    | **0.86x**
SetIntersect                                            | 1041    | 1197    | +15.0%    | **0.87x**
BenchLangCallingCFunction                               | 184     | 211     | +14.7%    | **0.87x**
Sim2DArray                                              | 326     | 372     | +14.1%    | **0.88x**
SetIsSubsetOf_OfObjects                                 | 498     | 567     | +13.9%    | **0.88x**
GeekbenchGEMM                                           | 945     | 1022    | +8.2%     | **0.92x**
COWTree                                                 | 3839    | 4181    | +8.9%     | **0.92x(?)**

</details>

<details >
  <summary>Improvement (31)</summary>

TEST                                                    | OLD_MIN | NEW_MIN | DELTA (%) | SPEEDUP
---                                                     | ---     | ---     | ---       | ---
ObjectiveCBridgeFromNSDictionaryAnyObjectToString       | 174526  | 165392  | -5.2%     | **1.06x**
RGBHistogram                                            | 3128    | 2957    | -5.5%     | **1.06x**
ObjectiveCBridgeToNSDictionary                          | 16510   | 15494   | -6.2%     | **1.07x**
LuhnAlgoLazy                                            | 2294    | 2120    | -7.6%     | **1.08x**
DictionarySwapOfObjects                                 | 6477    | 5994    | -7.5%     | **1.08x**
StringRemoveDupes                                       | 1610    | 1485    | -7.8%     | **1.08x**
ObjectiveCBridgeFromNSSetAnyObjectToString              | 159358  | 147824  | -7.2%     | **1.08x**
ObjectiveCBridgeToNSSet                                 | 16191   | 14924   | -7.8%     | **1.08x**
DictionaryHashableClass                                 | 1839    | 1704    | -7.3%     | **1.08x**
DictionaryLiteral                                       | 2906    | 2678    | -7.8%     | **1.09x(?)**
StringUtilsUnderscoreCase                               | 10031   | 9187    | -8.4%     | **1.09x**
LuhnAlgoEager                                           | 2320    | 2113    | -8.9%     | **1.10x**
ObjectiveCBridgeFromNSSetAnyObjectToStringForced        | 99553   | 90348   | -9.2%     | **1.10x**
RIPEMD                                                  | 3327    | 3009    | -9.6%     | **1.11x**
Combos                                                  | 595     | 538     | -9.6%     | **1.11x**
Roman                                                   | 10      | 9       | -10.0%    | **1.11x**
StringUtilsCamelCase                                    | 10783   | 9646    | -10.5%    | **1.12x**
SetIntersect_OfObjects                                  | 2511    | 2182    | -13.1%    | **1.15x**
SwiftStructuresTrie                                     | 28331   | 24339   | -14.1%    | **1.16x**
Dictionary2OfObjects                                    | 3748    | 3115    | -16.9%    | **1.20x**
DictionaryOfObjects                                     | 2473    | 2050    | -17.1%    | **1.21x**
Dictionary                                              | 894     | 737     | -17.6%    | **1.21x**
Dictionary2                                             | 2268    | 1859    | -18.0%    | **1.22x**
StringIteration                                         | 8027    | 6344    | -21.0%    | **1.27x**
Phonebook                                               | 8207    | 6436    | -21.6%    | **1.28x**
BenchLangArray                                          | 119     | 91      | -23.5%    | **1.31x**
LinkedList                                              | 8267    | 6297    | -23.8%    | **1.31x**
StrToInt                                                | 5585    | 4180    | -25.2%    | **1.34x**
Dictionary3OfObjects                                    | 1122    | 831     | -25.9%    | **1.35x**
Dictionary3                                             | 731     | 515     | -29.6%    | **1.42x**
SuperChars                                              | 513353  | 258735  | -49.6%    | **1.98x**
2016-04-18 15:39:17 -07:00
Xin Tong
d84de12943 Revert "Change FSO explosion heuristic"
This reverts commit fa09c6b71d.

Broke Linux build. And also PR "please benchmark" does not seem to catch it.
2016-04-14 11:05:00 -07:00
Xin Tong
fa09c6b71d Change FSO explosion heuristic
If we can not find the epilogue releases for all the fields with
reference sematics, but we found for some fields. Explode the argument.

I do not see a performance improvement with this change

rdar://25451364
2016-04-13 19:40:53 -07:00
Erik Eckstein
b8feb278dc DeadObjectElemination: fix two problems with handling of the tuple_extract following an array init call
1) handle cases where the tuple_extract is not in the same basic block as the init call. This is not a correctness issue, but might miss some opportunities.
2) bail if there are multiple tuple_extract. This is a correctness issue, but a theoretical one. I don't think that in reality we will ever get multiple tuple_extracts out of SILGen.
2016-04-13 13:28:29 -07:00
Arnold Schwaighofer
d97e7d93c7 UnsafeGuaranteedPeephole: Also use RCIdentity for matching retains 2016-04-13 09:11:27 -07:00
Arnold Schwaighofer
7d86d6f664 UnsafeGuaranteedPeephole: Use RCIdentityFunctionInfo when matching release 2016-04-13 08:46:31 -07:00
Ted Kremenek
35a99b2b5a Merge pull request #2129 from jdhealy/gardening-deindent-comment-RedundantOverflowCheckRemovalPass
[gardening] De-indent comment in `RedundantOverflowCheckRemovalPass`.
2016-04-10 15:07:27 -07:00
J.D. Healy
c809ca1469 [gardening] De-indent comment in RedundantOverflowCheckRemovalPass.
[ci skip]
2016-04-10 17:47:08 -04:00
Arnold Schwaighofer
75100a9598 UnsafeGuaranteedPeephole: Also skip sideeffect free instructions 2016-04-10 14:28:02 -07:00
practicalswift
872070900d [gardening] Consistent formatting of STATISTIC(…, "…"); 2016-04-09 23:51:23 +02:00
practicalswift
0e91354da3 [gardening] Fix recently introduced typo: "domiator" → "dominator" 2016-04-09 12:19:21 +02:00
Mark Lacey
de884107c8 We need to be very careful in generic specialization of recurisive functions.
We were waiting to delete old apply / try_apply instructions until after
fully specializing all the apply / try_apply in the function. This is
problematic when we have a recursive call and specializing the function
that we're currently processing, since we end up cloning the function
with the old apply / try_apply present.

Rather than doing this, clean up the old apply / try_apply immediately
after processing each one.

Resolves SR-1114 / rdar://problem/25455308.
2016-04-08 23:30:01 -07:00
Arnold Schwaighofer
be7ddc69d9 UnsafeGuaranteedPeephole: Skip debug instructions and ignore retain/release uses 2016-04-08 17:54:39 -07:00
Erik Eckstein
1eab8aa955 Re-instate "StackPromotion: Ignore unreachable blocks in post-dominator tree."
With a bug fix which should ensure that it doesn't violate the stack nesting.

Original commit: 3d050f7b43
2016-04-08 10:20:47 -07:00
Slava Pestov
8f038cead4 SIL: Stricter asserts for non-fragile references from fragile functions
Building off of the previous patches, add stricter assertions to
inlining passes and SIL serialization.
2016-04-08 02:16:30 -07:00
Slava Pestov
5aa99fa346 SILOptimizer: Create non-[fragile] specializations of [fragile] functions where possible
Change the optimizer to only make specializations [fragile] if both the
original callee is [fragile] *and* the caller is [fragile].

Otherwise, the specialized callee might be [fragile] even if it is never
called from a [fragile] function, which inhibits the optimizer from
devirtualizing calls inside the specialization.

This opens up some missed optimization opportunities in the performance
inliner and devirtualization, which currently reject fragile->non-fragile
references:

TEST                                                    | OLD_MIN | NEW_MIN | DELTA (%) | SPEEDUP
---                                                     | ---     | ---     | ---       | ---
DictionaryRemoveOfObjects                               | 38391   | 35859   | -6.6%     | **1.07x**
Hanoi                                                   | 5853    | 5288    | -9.7%     | **1.11x**
Phonebook                                               | 18287   | 14988   | -18.0%    | **1.22x**
SetExclusiveOr_OfObjects                                | 20001   | 15906   | -20.5%    | **1.26x**
SetUnion_OfObjects                                      | 16490   | 12370   | -25.0%    | **1.33x**

Right now, passes other than performance inlining and devirtualization
of class methods are not checking invariants on [fragile] functions
at all, which was incorrect; as part of the work on building the
standard library with -enable-resilience, I added these checks, which
regressed performance with resilience disabled. This patch makes up for
these regressions.

Furthermore, once SIL type lowering is aware of resilience, this will
allow the stack promotion pass to make further optimizations after
specializing [fragile] callees.
2016-04-08 02:10:31 -07:00
swiftix
baf8e7d7cb Merge pull request #2067 from swiftix/SR-249
Add [nonatomic] attribute to all SIL reference counting instructions.

Support this attribute at SIL level,  IRGen and LLVM-based ARC passes.
2016-04-06 23:56:43 -07:00
eeckstein
2de4dbb765 Merge pull request #2084 from eeckstein/remove_from_parent
Remove removeFromParent
2016-04-06 16:43:11 -07:00
Jordan Rose
52b961de61 Revert "Fix post-dominator tree in stack promotion"
This broke the test suite under optimizations with a SIL verifier error: "stack dealloc does
not match most recent stack alloc".

This reverts commit 7a2ca23bc2, reversing
changes made to 4c55e8d7a7.
2016-04-06 16:02:20 -07:00
Erik Eckstein
0f1a89d5dc SpeculativeDevirtualizer: erase a dead block and not just remove it from the function.
And add a few asserts to make the code clearer.
2016-04-06 14:55:47 -07:00
Erik Eckstein
3d050f7b43 StackPromotion: Ignore unreachable blocks in post-dominator tree.
Unreachable blocks prevented stack promotion in some cases.
Now we use our own post-dominator tree which ignores unreachable blocks instead of the standard post-dominator tree provided by the PostDominanceAnalysis.
Unreachable blocks (better: unreachable sub-graphs) are of no interrest because we don't have to insert the dealloc instructions in unreachable blocks anyway.
2016-04-06 11:11:13 -07:00
Roman Levenstein
2e77b3990b Add [nonatomic] attribute to all SIL reference counting instructions. 2016-04-06 01:52:43 -07:00
Andrew Trick
6ffafe4dd3 NFC: Remove a dead call in the DeadObjectElimination pass.
Cleanup after a pasto. Thanks Roman.
2016-04-05 16:28:27 -07:00
practicalswift
798877ae77 [gardening] "if (foo)[SPACE][SPACE]{" → "if (foo)[SPACE]{" 2016-04-03 22:57:05 +02:00