Commit Graph

172 Commits

Author SHA1 Message Date
Arnold Schwaighofer
82baf4eca1 Delete now unused variable
Swift SVN r27848
2015-04-28 00:04:17 +00:00
Arnold Schwaighofer
e5a038fafb Nuke dead code
Swift SVN r27845
2015-04-27 23:46:48 +00:00
Arnold Schwaighofer
0bdcbd2612 Nuke old dominator based simplification code that is subsumed by the dominator
based jumpthreading commit.

Swift SVN r27844
2015-04-27 23:46:47 +00:00
Arnold Schwaighofer
3812583031 DominatorBasedJumpThreading: Resurrected
Teach dominator based simplifications to also thread dominated edges.

The code now handles cond_br and switch_enum terminators for both value based
simplifications (where the use is dominated) and jump threading edges (the edge
is dominated).

Update simplify_cfg.sil test cases for split edges.

This also handles the test case from rdar://20390647.

Swift SVN r27843
2015-04-27 23:44:57 +00:00
Arnold Schwaighofer
5272408e62 SimplifyCFG: Canonicalize cond_br (not %cond) bb1, bb2 to cond_br %cond bb2,
bb1.

Swift SVN r27839
2015-04-27 23:43:42 +00:00
Arnold Schwaighofer
bde2409316 SimplifyCFG: Fix a bug in tryToReplaceArgWithIncomingValue
Replace all uses of the *argument value* with the incoming *value*.Triggered by my upcoming changes

Swift SVN r27836
2015-04-27 23:43:40 +00:00
Arnold Schwaighofer
8ed5229a58 SimplifyCFG: Appease SILLocation verification
We can't always adopt the location of the user for the integer_literal because
the user's location might be a (Implicit)ReturnLocation which is disallowed on
most instructions.

Swift SVN r27835
2015-04-27 23:43:39 +00:00
Arnold Schwaighofer
e4e1254383 Reapply "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27739 reapplying r27722.

The test (validation/stdlib/Hashing.swift) that failed is expected to sometimes
fails.

Original message

"SimplifyCFG: Fix a bug in the jump threading code

When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338"

Swift SVN r27741
2015-04-26 01:28:10 +00:00
Arnold Schwaighofer
50355e99dc Revert "SimplifyCFG: Fix a bug in the jump threading code"
This reverts commit r27722.

Broken bot.

Swift SVN r27738
2015-04-26 00:24:34 +00:00
Arnold Schwaighofer
9921573073 SimplifyCFG: Fix a bug in the jump threading code
When jump threading a block we used to propagate phi values directly into the
threaded block - instead of leaving in a copy. Because of this the SSA updater
would propagate the value feeding the copy from the next iteration.
Now when jump threading the destination block into the edge we leave in the phi
(copy) such that the SSA updater picks up value of the right iteration.

rdar://20617338

Swift SVN r27722
2015-04-25 22:42:29 +00:00
Roman Levenstein
e488e5ec89 [simplify-cfg] Fold switch_value on a constant argument into an unconditional branch
rdar://20621777

Swift SVN r27491
2015-04-20 20:33:50 +00:00
Erik Eckstein
665c1b8894 SimplifyCFG: fix wrong jump threading in case of block-args with multiple uses.
This fixes rdar://problem/20565538
(at least part of it).



Swift SVN r27432
2015-04-17 15:26:59 +00:00
Erik Eckstein
0c5a97ebc5 SimplifyCFG: fix condition equivalence checking in checked-cast jump threading.
It was wrong in case two checked_cast_br have select_enum (with identical enum operands) as conditions.



Swift SVN r27356
2015-04-16 11:37:39 +00:00
Arnold Schwaighofer
c0fedecfd8 SimplifyCFG: Only recompute the dom tree on change
Swift SVN r26981
2015-04-04 15:42:47 +00:00
Arnold Schwaighofer
5bd9b4a6d6 SimplifyCFG: sprinkle some verification on top
Verify the dominator tree at strategic points to make sure we don't regress this in the future

Swift SVN r26980
2015-04-04 15:42:46 +00:00
Arnold Schwaighofer
ecd6ed9d3a SimplifyCFG: Fix dominatorBaseSimplify
Separate it into two phases: one that simplifies based on the domtree and one
that changes the CFG. Recompute the domtree in between.

Don't process unreachable blocks created by checked cast jump threading. The
dominator tree update in checked cast jump threading is buggy - recalclate the
dominator tree for now.

I measured no changes in performance and a +0.1-0.2% change in compile time of
'ninja -j1 swift-stdlib'.

rdar://20404463

Swift SVN r26979
2015-04-04 15:42:46 +00:00
Arnold Schwaighofer
e7e6e69c20 SimplifyCFG: Don't simplify an instruction without a use in propagateSwitchEnumCondition
Swift SVN r26978
2015-04-04 15:42:45 +00:00
Arnold Schwaighofer
e5e116b262 SimplifyCFG: simplifySwitchEnumToSelectEnum changes the CFG
Recompute (post)dominators.

Swift SVN r26977
2015-04-04 15:42:44 +00:00
Arnold Schwaighofer
d9e381f6e1 SimplifyCFG: Add a method to clear the worklist
To be used by a follow up commit.

Swift SVN r26976
2015-04-04 15:42:44 +00:00
Arnold Schwaighofer
4904072297 SimplifyCFG: propagateSwitchEnumCondition should not change the CFG
It is called from dominatorBasedSimplify which relies on a correct dominator
tree. Instead when we know the branch target of a switch_enum because of a
dominating switch_enum on the same operand change the dominated switch_enum to
use a enum instruction of the known enum case.

Disable some tests that now fail. They will be enabled again in follow up
commits.

Swift SVN r26975
2015-04-04 15:42:43 +00:00
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +00:00
Arnold Schwaighofer
e08e118246 SimplifyCFG: Fix Changed handling
Once we changed the CFG we changed it ...

Noticed while looking at other bugs we probably have in the vicinity.
No test case.

Swift SVN r26880
2015-04-02 17:48:55 +00:00
Arnold Schwaighofer
68a3d0263e Revert "Dominating edge condition based jump threading"
This reverts commit r26815.

It is breaking the bot.

Swift SVN r26837
2015-04-01 23:37:26 +00:00
Arnold Schwaighofer
9d81bf8b24 Dominating edge condition based jump threading
The classical jump threading that we have not been doing.

No performance impact measured.

Swift SVN r26815
2015-04-01 18:27:40 +00:00
Arnold Schwaighofer
885afc9043 SimplifyCFG: Tail duplicate when coming from objc-method call blocks
This can expose a path the ARC optimizer can push a retain/release into.

Improves DeltaBlue by 15% in optimized builds.

Swift SVN r26812
2015-04-01 15:01:34 +00:00
Erik Eckstein
5712a7eeaa SimplifyCFG: rewrite the dominator based condition simplification.
The optimization simplifies a condition if it is dominated by a terminating instruction with the same condition.
With this change we can also simplify non-terminator instructions, e.g. a cond_fail which is dominated by a cond_br,
or a select_enum which is dominated by a switch_enum.

I do not handle the pattern cond_br(select_enum) anymore, because SILCombine converts this to switch_enum anyway.

There is no notable effect on the benchmarks. But it simplifies the class array code a bit.



Swift SVN r26809
2015-04-01 10:50:46 +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
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
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
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
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
Erik Eckstein
14f5fb86e2 SimplifyCFG: small refactoring, NFC
Swift SVN r26537
2015-03-25 09:37:20 +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
Nadav Rotem
683317e607 Fix two cases where SimplifyCFG invalidated analysis too aggressively.
Swift SVN r26481
2015-03-24 04:56:21 +00:00
Nadav Rotem
d78b376d07 [passes] Replace the old invalidation lattice with a new invalidation scheme.
The old invalidation lattice was incorrect because changes to control flow could cause changes to the
call graph, so we've decided to change the way passes invalidate analysis.  In the new scheme, the lattice
is replaced with a list of traits that passes preserve or invalidate. The current traits are Calls and Branches.
Now, passes report which traits they preserve, which is the opposite of the previous implementation where
passes needed to report what they invalidate.

Node: I tried to limit the changes in this commit to mechanical changes to ease the review. I will cleanup some
of the code in a following commit.

Swift SVN r26449
2015-03-23 21:18:58 +00:00
Roman Levenstein
f3ae8c1f52 Minor clean-up after my recent re-factoring of cast optimizations. NFC.
Swift SVN r26312
2015-03-19 20:03:44 +00:00
Chris Lattner
4f708c049b fix const correctness and standardize on names for the successor list of
TerminatorInsts.  Now you can walk over the successor list of a terminator
and actually modify the SILSuccessor directly, allowing better CFG
transformations.  NFC.




Swift SVN r26140
2015-03-14 17:52:27 +00:00
Roman Levenstein
aea50324fc Remove the cast optimization logic from sil-combine and simplify-cfg and turn them into clients of CastOptimizer.
This is the last part of the re-factoring. Now all the logic for performing cast optimizations is inside CastOptimizer, which makes it easier to reason about it and to maintain it.

Swift SVN r26123
2015-03-14 02:23:05 +00:00
Michael Gottesman
26debff435 Fix typo from a long long time ago. Also add a comment flag to indicate that the passes below it are only for testing. NFC.
Swift SVN r25837
2015-03-07 04:47:44 +00:00
Erik Eckstein
dfedf8edf2 Added a comment for the SimplifyCFG passes which are used by sil-opt.
Swift SVN r25758
2015-03-04 18:28:50 +00:00
Erik Eckstein
de09d1e684 SimplifyCFG: create a simplifyBBArgs pass.
Purpose: for testing



Swift SVN r25756
2015-03-04 15:18:08 +00:00
Erik Eckstein
30a1ff956f SimplifyCFG: fix a crash in simplifyToSelectValue
rdar://problem/20037686

A test will follow in a separate commit



Swift SVN r25755
2015-03-04 15:11:16 +00:00
Roman Levenstein
ecd9298090 Small optimization of cast-folding: Don't generate unconditional cast if its result is not used.
Swift SVN r25691
2015-03-02 22:28:22 +00:00
Roman Levenstein
a4055afc15 Third part of the cast folding and type-casts re-factoring. Addressing JoeG's comments.
This patch does the following:
- Improvements and correctness fixes for conversions of existential metatypes. They may succeed if you have a concrete or existential metatype that conforms to the protocol. Based on Joe's review of my previous patch.
- Removes special-cases for AnyObject. AnyObject is handled as any other class existential.
- Improves folding of conversions from class existential metatypes to concrete non-class metatypes
- Improves comments.
- Adds more tests to cover new test-cases.
- Adjusts a few existing tests.

Swift SVN r25690
2015-03-02 22:28:21 +00:00
Arnold Schwaighofer
715bd5e507 SimplifyCFG: Simplify conditional branches to cond_fail blocks
cond_fail on the branch condition value leading to the cond_fail's parent block.

Swift SVN r25665
2015-03-02 01:05:34 +00:00
Roman Levenstein
6f3cfaf764 Improve comments for my previous commit. NFC.
Provide an explanation about when it is safe to jump-thread the checked_cast_br even if the dominating instruction and the current instruction do not have the same "exactness".

Swift SVN r25649
2015-03-01 00:46:20 +00:00
Roman Levenstein
c66e7bc733 [sil-simplify-cfg] Bugfix for jump-threading of checked_cast_br.
Fix a stupid bug. When we look for a dominating checked_cast_br, we need to check that both the current one and a dominating one are either both [exact] or both not [exact].

rdar://19948357

Swift SVN r25637
2015-02-28 07:03:53 +00:00