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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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