Commit Graph

71 Commits

Author SHA1 Message Date
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
Arnold Schwaighofer
f7c01f2061 Nuke isReadNone function
We can now compute the same result with Inst.mayReadOrWriteMemory(). NFC.

Swift SVN r25743
2015-03-04 05:03:45 +00:00
Dmitri Hrybenko
61286f0260 Fix warnings produced by a newer version of Clang
Swift SVN r25257
2015-02-12 23:50:47 +00:00
Michael Gottesman
c5635ed7de Use new tinyptr MutableArrayRef API.
Swift SVN r24502
2015-01-19 04:06:36 +00:00
Michael Gottesman
9307afe0d2 [ls-opts] Invalidate the state of loads that become dead due to their only argument being a store that we are eliminating correctly.
rdar://19383222

Swift SVN r24363
2015-01-11 20:18:31 +00:00
Arnold Schwaighofer
d1df3d6e28 LoadStoreOpts: Don't ignore aliasing stores
The code used ssa value inquality to disqualify aliasing. This is not strong
enough. Use AliasAnalysis instead.

This is a correctness fix.

Unfortunately, I measured the following regressions at -O:

TEST``````````````````````````Speedup(minbefore/minafter)
ArrayOfGenericPOD`````````````0.73871
ArrayOfPOD````````````````````0.701107
CaptureProp```````````````````0.886796
Dictionary2```````````````````0.907991
Dictionary3```````````````````0.86035
LevenshteinDistance```````````0.714346
QuickSort`````````````````````0.942924
RC4```````````````````````````0.742609
SwiftStructuresInsertionSort``0.942875
TwoSum````````````````````````0.956233

I measured the following regressions at -Onone:

TEST```````````````````````Speedup(minbefore/minafter)
RIPEMD`````````````````````0.955413
SwiftStructuresBubbleSort``0.943074

I measured the following regressions at -Ounchecked:

TEST```````````Speedup(minbefore/minafter)
RC4````````````0.757648
StringBuilder``0.956013
SuperChars`````0.954549

rdar://19362910

Swift SVN r24247
2015-01-07 22:19:48 +00:00
Michael Gottesman
189e558373 Remove cruft that snuck in.
Swift SVN r24184
2015-01-05 21:57:53 +00:00
Michael Gottesman
266886953c [ls-opt] Add in LSValue, LSStore, LSLoad and use it when we are not trying to forward from multiple reaching stores.
LSValue, LSStore, and LSLoad are structs that are meant to be able to
allow for load store opts to use the same logic for performing load
store opts from one load, store and covering sets of loads, stores.

This changes LoadStoreOpts to use these data structures when it is not
considering covering stores.

Swift SVN r24183
2015-01-05 21:29:12 +00:00
Michael Gottesman
aac51db34f [ls-opts] Fix crasher where we are determing whether or not to load
store forward while performing the load store forwarding. This can cause
us to dereference an empty SILValue.

The forwarding feasability code in LoadStoreOpts is separated into an
analysis and a action part. The action part assumes that SILValues
returned are never null. This violates a normal error handling pattern
with SILValues. We should introduce some notion of a SILValue that can
not be null. Until then, this patch fixes the crasher.

<rdar://problem/19369189>

Swift SVN r24169
2015-01-04 02:03:55 +00:00
Michael Gottesman
2118fc0dea [ls-opt] Add in global state class called LSContext and refactor the top level function in LSOpts to use it.
This is just a convenient way to encapsulate all global state used in the
algorithm and to reduce the number of arguments passed.

Swift SVN r24166
2015-01-01 14:34:50 +00:00
Michael Gottesman
998f644874 [ls-opts] Make comment clearer. NFC.
Swift SVN r24163
2015-01-01 14:34:47 +00:00
Michael Gottesman
565119d9a5 [load-store] Small cleanup. NFC.
Swift SVN r23932
2014-12-15 05:22:39 +00:00
Michael Gottesman
d368eaefe4 [ls-opts] Round to nearest power of 2 when reserving buckets for BBToBBIDMap
Swift SVN r23591
2014-12-01 02:13:09 +00:00
Michael Gottesman
d14de75404 [ls-opts] Pass in the size of the post order to BBToBBIDMap so we can avoid unnecessary memory allocation.
Swift SVN r23590
2014-12-01 01:49:50 +00:00
Michael Gottesman
1afc987739 Refactor the SILArgument API on SILBasicBlock so we can insert bb arguments anywhere in the argument list. Also clean up the API names so that they all match.
Swift SVN r23543
2014-11-22 00:24:40 +00:00
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