Commit Graph

56 Commits

Author SHA1 Message Date
Michael Gottesman
2d703a28f5 [proj] Add Projection::create{Addr,Value}Projection so one can create Projections without knowing what the internal state of the projection is.
Swift SVN r23371
2014-11-17 17:52:16 +00:00
Michael Gottesman
eeab468c8e [proj] Prepare Projection so that I can add generic create{Addr,Value}Projection.
I want to cleanup some code paths in SILCombine and LoadStoreOpts to use
generic create{Addr,Value}Projection methods which create the
appropriate projection instruction for a Projection method. Also this
will allow me to start to hide more of the internal state of Projection.

Swift SVN r23366
2014-11-17 06:43:37 +00:00
Michael Gottesman
a4a633351f [projection] Make projection constructors private and create static failable initializers using Optional.
This changes the Projection API so that you pass in an instruction and get back
an optional depending on what theinstruction was. This is much cleaner than
always needing to do a switch.

This commit also cleans up the naming in Projection so that we always use the
term "value projection" for struct_extract, tuple_extract, and
unchecked_enum_data instead of the term "extract". This lines up better with the
name we use for the *_addr instructions, "address projection" and avoids
ambiguity since unchecked_enum_data does not have the word "extract" in it.

Additionally by adding in the failable initializers, my centralization of the
initialization logic enables me to ensure that isAddrProjection and
isValueProjection stay in sync with the various constructors via asserts. This
should prevent future bugs if we add additional notions of "projection".

Swift SVN r23356
2014-11-16 04:09:16 +00:00
Andrew Trick
e70dd32ff4 comment
Swift SVN r23312
2014-11-14 00:09:06 +00:00
Dave Abrahams
e64d37745a LoadStoreOpts: kill unused variable
Swift SVN r23186
2014-11-09 03:46:26 +00:00
Mark Lacey
4f6e4394b2 Silence a few of the release build warnings.
Swift SVN r23156
2014-11-07 03:39:54 +00:00
Michael Gottesman
3ae10834d6 [ls-opts] Teach LoadStoreOpts how to forward smaller previous loaded items to the uses of larger later loads that partially alias the load.
This will help the ARC optimizer given future function sig optimization work and
is in general good since this has been a hole in our load store forwarding for a
while.

rdar://18831605

Swift SVN r23102
2014-11-04 19:44:06 +00:00
Michael Gottesman
5f70b01e4d [load-store-opts] Refactor load store opts to use the new ProjectionPath infrastructure.
rdar://18831605

Swift SVN r23063
2014-11-02 02:53:36 +00:00
Michael Gottesman
0e05c73510 [load-store-opts] Change ForwardingKind to be a c++11 enum class instead of an enum.
Swift SVN r23038
2014-10-31 21:52:47 +00:00
Adrian Prantl
c41b30299f Audit all SILPasses to ensure that new instructions are never created
without a valid SILDebugScope. An assertion in IRGenSIL prevents future
optimizations from regressing in this regard.
Introducing SILBuilderWithScope and SILBuilderwithPostprocess to ease the
transition.

This patch is large, but mostly mechanical.
<rdar://problem/18494573> Swift: Debugger is not stopping at the set breakpoint

Swift SVN r22978
2014-10-28 01:49:11 +00:00
Joe Groff
e3f9a2035c SIL: Move SILGen and passes over to use "builtin" instead of "apply (builtin_function_ref)".
Swift SVN r22785
2014-10-15 23:37:22 +00:00
Dmitri Hrybenko
5c9c675291 Revert "Remove type check workaround for invalid casts"
This reverts commit r22498.  We need more auditing of stdlib for invalid
casts.

rdar://18151953

Swift SVN r22536
2014-10-06 08:27:35 +00:00
Arnold Schwaighofer
a934abf2a8 Remove type check workaround for invalid casts
The stdlib has been fixed and no longer produces invalid casts.

rdar://18151953

Swift SVN r22498
2014-10-03 17:01:07 +00:00
Arnold Schwaighofer
ef3adb2186 Dont' trivial bitcast between differently sized structs.
Really we want to only cast between equally sized types. SIL does not really
have a concept of types of the same size so this solution is a workaround
(temporary) for acutal code in the standard library which casts a pointer of an
UTF16 type to a pointer of an UTF8 type.

rdar://18118602

Swift SVN r21470
2014-08-27 00:05:04 +00:00
Michael Gottesman
eeca7e5186 [load-store] We no longer perform single BB load-store opts so we should always have a post dominator tree. Remove NULL check.
Swift SVN r21272
2014-08-19 04:13:01 +00:00
Manman Ren
084ad2f21c [Load Store Opts] use BBArguments to merge in multiple stores.
We use a DenseMap to map an address to a list of reaching StoreInsts,
one for each predecessor. The map is passed as function arguments instead
of a member in LSBBForwarder since it is only used during one invocation
of optimizing a basic block.

We can now remove all loads in rdar://17613168 and enable dead object
elimination. There is one issue though, one of the loads is loop invariant
and is moved outside by LICM, but we need to run LoadStoreOpt and DeadObjectElim
afterwards to actually remove the dead object.

Performance for rdar://17613168 (with added passes after LICM):
-Ounchecked: 13.8s to 0.199s
-O: 15.4s to 2s


Swift SVN r20922
2014-08-01 22:04:59 +00:00
Manman Ren
c02607305e [Load Store Opts] more refactoring. NFC.
Swift SVN r20918
2014-08-01 21:37:47 +00:00
Manman Ren
f98a535eb5 [Load Store Opts] fix typo.
Swift SVN r20905
2014-08-01 18:24:18 +00:00
Manman Ren
0b7cd65a57 [Load Store Opts] separate the feasibility check. NFC.
To help adding BBArguments to merge in multiple stores, we separate
the feasibility check so we can check the feasibility before creating
BBArguments.


Swift SVN r20904
2014-08-01 18:23:06 +00:00
Manman Ren
cd31f6a361 [Load Store Opts] add comments and remove clear inside the loop.
There is no need to clear the state before merging in the states of
the predecessors. In the case of a self loop, we need the previous
state of the basic block, otherwise, the state will be initialized to
the state of the first predecessor.


Swift SVN r20766
2014-07-30 18:54:23 +00:00
Manman Ren
658b8f0c9a [Load Store Opts] remove AA and other members from LSBBForwarder. NFC.
Swift SVN r20721
2014-07-29 23:38:25 +00:00
Andrew Trick
cbad3697a3 TODO comment to remind me of what I wanted to change.
Swift SVN r20447
2014-07-23 23:43:32 +00:00
Michael Gottesman
9ceca6d313 Add in a small TODO. NFC.
Swift SVN r20351
2014-07-22 23:45:25 +00:00
Michael Gottesman
ec533fafa7 [load-store-opts] Enable global load store opts.
rdar://17680758



Swift SVN r20349
2014-07-22 23:43:44 +00:00
Manman Ren
3260a4182c [Global Load Store Opts] fix a issue when a BB is its own predecessor.
When BB is its own predecessor, we can't do the following
state[BB] = state[first pred of BB]
state[BB].merge(state[other predecessors])
--> here we are merging in the updated state[BB]

Instead we should do
state[BB].merge(state[predecessors other than BB])


Swift SVN r20114
2014-07-17 21:50:50 +00:00
Michael Gottesman
d47255dbcc Remove dead var that snuck in.
Swift SVN r20011
2014-07-16 06:10:40 +00:00
Michael Gottesman
e5d7111db8 [load-store-opts] Change load store opts single BB pass to be a simple forward dataflow with an intersection merge operation.
This is not run by default unless one passes in the flag -Xllvm -enable-global-load-store-opts.

Also in order to make sure in the face of multi-bbs dead store elimination is
still correct, we use the post order dominator tree to determine if the dead
store is post dominated by the store that is causing it to be dead.

With this pass enabled, we see a 3.5% decrease in overall time in the precommit
bench and the following tests increase in speed by > 5%:

2Sum:          8.9%
Rectangles:    7.35%
Ackermann:     6.43%
StringBuilder: 6.16%
EditDistance:  5.71%
StringWalk:    5.58%

That means that 30% of our benchmarks increased in speed by > 5%. Many of the
other benchmarks increased in speed significantly but not as drmatically.

The only benchmark that regressed is SmallPt which I am looking into.

rdar://17680758

Swift SVN r20009
2014-07-16 06:01:37 +00:00
Mark Lacey
f1a6921564 Fix an assert in store-to-load forwarding.
The code does the right thing, but the assert should be checking that
the load we're about to replace has the same type as the value we're
replacing it with.

This was exposed by changes to inline generic code.

Swift SVN r19921
2014-07-14 06:32:15 +00:00
Michael Gottesman
0a15d018cc Rely on the stdlib's runtime assert and undefined behavior to promote 3/4 remaining unchecked_addr_cast types to object bit casts.
This commit enables support in the optimizer for promoting the following
unchecked_addr_cast kinds to object bit casts:

1. (Trivial => Trivial) yields a trivial bit cast.
2. (Non-Trivial => Trivial) yields a trivial bit cast.
3. (Non-Trivial => Non-Trivial) yields a ref bit cast.

We do not promote conversions in between trivial and non-trivial types
since a trivial bit cast must have a trivial output and if we allowed
for ref bit casts in between the two, we would be breaking the rule that
ref bit casts do not change the reference semantics of its input, output
types. Technically, we could lower trivial => trivial as a ref cast and
then simplify later but that is unnecessary currently.

<rdar://problem/17373087>

Swift SVN r19784
2014-07-10 05:24:00 +00:00
Michael Gottesman
f66bbd9417 Revert "Revert "Expand the amount of unchecked_addr_casts that we can handle.""
This reverts commit r19279 and adds in the necessary fixes.

Swift SVN r19295
2014-06-27 16:49:08 +00:00
Michael Gottesman
cf896976a0 Revert "Expand the amount of unchecked_addr_casts that we can handle."
This reverts commit r19272 to unblock the submission. I am going to
cherry-pick this later.

Swift SVN r19279
2014-06-27 00:02:05 +00:00
Michael Gottesman
256f1e5515 Expand the amount of unchecked_addr_casts that we can handle.
This is tested by an assertion in IRGen. After Beta3, this code is going
to go away and be replaced by just always promoting the cast. Then the
IRGen assertion will be replaced by propagating undef. The assertion in
the stdlib will still fire in that case since the assertion is based on
the tops not the given value implying that we will not lose any
correctness.

Swift SVN r19272
2014-06-26 23:07:52 +00:00
Michael Gottesman
3fc1042ca1 [load-store] Refactor load->load and store->load forwarding to use the same underlying method.
Both have the same form of, (Address, Value, Load). For the store->load I pass in
(SI->getDest(), SI->getSrc(), LI) and for the load->load I pass in
(OldLI->getOperand(), OldLI, LI).

This also for free lets our load deduplication support forwarding from casts.

Swift SVN r19133
2014-06-24 09:57:23 +00:00
Michael Gottesman
f6eefe63a3 [load-store] Teach load store opts how to forward stores -> partial loads which are related via typed GEPs.
I also refactored findExtractPathBetweenValues to be able to be used for both
partial load duplication and forwarding stores to partial loads.

Swift SVN r19132
2014-06-24 08:37:14 +00:00
Michael Gottesman
ee818e7533 [load-store] Teach load store forwarding how to forward stores -> loads with an intervening unchecked_addr_cast of layout compatible types.
Swift SVN r19130
2014-06-24 07:21:05 +00:00
Michael Gottesman
735a23a0a3 [sil-combine] Rewrite unchecked_addr_cast to access layout compatible first element fields via typed GEPS.
A first element field of a nominal type is either the first element of a
struct or the first payload of an enum. We currently allow the stdlib to
rappel into struct heirarchies using reinterpretCast. This patch teaches
the optimizer how to rewrite such unchecked_addr_cast into
unchecked_enum_data_addr and struct_element_addr instructions. Then
Mem2Reg and Load Store Forwarding will remove the allocation generated
by such uses of reinterpret cast.

<rdar://problem/16703656>

Swift SVN r18977
2014-06-18 09:34:05 +00:00
Michael Gottesman
102cd40ea0 [load-store-opts] RetainValue is insert from a load store opts perspective despite it having side effects due to it touching reference counts.
Swift SVN r18912
2014-06-15 20:01:42 +00:00
Michael Gottesman
aa70a16d7e [load-store-opts] Track, perform load forwarding, and eliminate multiple stores.
rdar://16703656

Swift SVN r17746
2014-05-09 00:44:28 +00:00
Michael Gottesman
9fee32d515 [load-store-opts] Do not invalidate stores if AA says that an instruction does not alias the store's destination conservatively.
Swift SVN r17738
2014-05-09 00:00:21 +00:00
Michael Gottesman
02c42cd0a4 [load-store-opts] Refactor out special cases for strong_retain, cond-fail, and dealloc_stack into a helper function call isLSForwardingInertInstruction.
Swift SVN r17735
2014-05-08 23:34:22 +00:00
Michael Gottesman
f18dbbe9e8 [load-store-opts] Refactor load forwarding into its own method LSBBForwarder::tryToForwardLoad.
Now the main optimize method of load store forwarding is ~60 lines and
is significantly more readable.

Swift SVN r17718
2014-05-08 22:42:16 +00:00
Michael Gottesman
df441227f1 [load-store-opts] Refactor out dead store elimination into LSBBForwarder::tryToEliminateDeadStore.
Swift SVN r17717
2014-05-08 22:42:16 +00:00
Michael Gottesman
d4698e3beb [load-store-opts] Move invalidateAliasingLoads onto LSBBForwarder and remove unneeded arguments.
Swift SVN r17716
2014-05-08 22:42:16 +00:00
Michael Gottesman
f510d16666 [load-store-opts] Refactor out call to recursivelyDeleteTriviallyDeadInstructions -> LSBBForwarder::deleteInstruction.
Swift SVN r17715
2014-05-08 22:42:15 +00:00
Michael Gottesman
328dd3cf52 [load-store-opts] Refactor/Simplify LoadStoreOpts by including a BBState structure.
This makes the main method able to be broken down into simpler pieces
without the need to pass as many things around.

Swift SVN r17714
2014-05-08 22:42:14 +00:00
Michael Gottesman
bd62e9d9e7 [load-store-opts] Keeping performing load store optimizations on a basic block until we no longer eliminate anything.
Swift SVN r17670
2014-05-08 02:33:35 +00:00
Manman Ren
fb299a4899 [LoadStoreOpt] make sure Loads do not hold deleted SILInstructions.
We add a callback function to recursivelyDeleteTriviallyDeadInstructions.
When a Load instruction is deleted, we erase it from Loads.

rdar://16815627


Swift SVN r17558
2014-05-06 20:02:31 +00:00
Mark Lacey
1452d24671 Small cleanup: Remove unnecessary calls to getDef(), mostly in dyn_cast<>(...).
Swift SVN r16235
2014-04-11 23:05:16 +00:00
Nadav Rotem
cce0b2d342 Add comments that describe the purpose of the set.
Swift SVN r15394
2014-03-23 20:55:24 +00:00
Nadav Rotem
4d9598fad1 Remove store instructions that store a loaded value that is known to be unmodified.
After this change swap in RC4 contains only 2 stores (of the swapped values).



Swift SVN r15386
2014-03-23 08:03:58 +00:00