Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy propagation, remove unused values (closures!) and local variables #4837

Closed
wants to merge 8 commits into from

Conversation

lrytz
Copy link
Member

@lrytz lrytz commented Nov 6, 2015

See individual commit messages.

@scala-jenkins scala-jenkins added this to the 2.12.0-M4 milestone Nov 6, 2015
@lrytz
Copy link
Member Author

lrytz commented Nov 6, 2015

Review by @retronym

@lrytz
Copy link
Member Author

lrytz commented Nov 6, 2015

@lrytz
Copy link
Member Author

lrytz commented Nov 7, 2015

The community build found some issues, will look at those next week:

[spire:error] java.lang.NullPointerException
[spire:error]   at scala.tools.nsc.backend.jvm.opt.BytecodeUtils$FrameExtensions$.peekStack$extension(BytecodeUtils.scala:490)
[spire:error]   at scala.tools.nsc.backend.jvm.opt.LocalOpt.replaceByPop$1(LocalOpt.scala:404)
[spire:error]   at scala.tools.nsc.backend.jvm.opt.LocalOpt.scala$tools$nsc$backend$jvm$opt$LocalOpt$$$anonfun$9(LocalOpt.scala:411)
[spire:error]   at scala.tools.nsc.backend.jvm.opt.LocalOpt.scala$tools$nsc$backend$jvm$opt$LocalOpt$$$anonfun$9$adapted(LocalOpt.scala:410)
[spire:error]   at scala.tools.nsc.backend.jvm.opt.LocalOpt$$Lambda$8395/1251991824.apply(Unknown Source)
[spire:error]   at scala.collection.TraversableLike$WithFilter.scala$collection$TraversableLike$WithFilter$$$anonfun$40(TraversableLike.scala:778)
[spire:error]   at scala.collection.TraversableLike$WithFilter$$Lambda$4644/409134695.apply(Unknown Source)
[spire:error]   at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
[spire:error]   at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
[spire:error]   at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
[spire:error]   at scala.tools.nsc.backend.jvm.opt.LocalOpt.eliminateStaleStores(LocalOpt.scala:410)

also akka and twitter-util failed, the rest passed.

@SethTisue
Copy link
Member

(the twitter-util failure is unrelated to your changes)

Previously the VarInstruction extractor did not include IINCs.
Also give rename the isVarInstruction predicate to isLoadStoreOrRet,
as it doesn't include IINC.

Also fixes a bug in removeJumpAndAdjustStack, it checked the wrong
opcode range before.
When running DCE, directly remove eliminated callsites from the call
graph (instead delegating this task to the callees).
By convention (for performance), `aliasingFrame.aliases(slot) == null`
means that the value at `slot` has no aliases, so this is isomorphic
to having a singleton `AliasSet(slot)`.

When merging an AliasingFrame `other` into `this`, at every value slot
we have to keep the intersection of the two alias sets. In other words
we have to remove from `this.aliases(slot)` those values that are
not in `other.aliases(slot)`. This was wrong for the cases where
`other.aliases == null` - we did not treat this case as a singleton
set.
Copy propagation uses an AliasingAnalyzer: it replaces a `LOAD n`
instruction by `LOAD m` where m is the smallest alias of n. This
leads to stale STORE instructions.

Stale STOREs are identified using a ProdCons analyzer and replaced by
POPs.

Values that are pushed on the stack by a side-effect free instruction
and consumed by a POP are then removed by `eliminatePushPop`. This
includes elimination of unused closure allocations and unused boxes
and  tuple allocations (*).

A final cleanup eliminates `STORE x; LOADx` pairs where the stored
value is not otherwise used.

Fixes
  - scala/scala-dev#25
  - scala/scala-dev#7
  - scala/scala-dev#14
  - scala/scala-dev#12

(*) We don't yet rewrite reads of boxes and tuples yet. For example,
`val x = (1, 2); x._1` remains a method invocation and the tuple
cannot be eliminated (scala/scala-dev#11).

Inspired in many ways by Miguel's work!
@lrytz
Copy link
Member Author

lrytz commented Nov 11, 2015

community build (with the optimizer enabled) succeeded: https://scala-ci.typesafe.com/view/scala-2.12.x/job/scala-2.12.x-integrate-community-build/213/

@retronym
Copy link
Member

I'll take another pass over this tomorrow.

@lrytz
Copy link
Member Author

lrytz commented Dec 18, 2015

closing in favor of #4858

@lrytz lrytz closed this Dec 18, 2015
@lrytz lrytz deleted the opt/copyProp branch February 4, 2016 08:52
@SethTisue SethTisue removed this from the 2.12.0-M4 milestone Mar 14, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants