Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upConditional optimization: true || x == true, false && y == false, etc. #6105
Comments
This comment has been minimized.
This comment has been minimized.
Imported From: https://issues.scala-lang.org/browse/SI-6105?orig=1 |
This comment has been minimized.
This comment has been minimized.
@magarciaEPFL said: |
This comment has been minimized.
This comment has been minimized.
@magarciaEPFL said: Description: https://groups.google.com/d/topic/scala-internals/iz5PiIMTPs0/discussion Sources at branch: https://github.com/magarciaEPFL/scala/tree/GenBCodeOpt |
scabug
added
enhancement
optimizer
labels
Apr 7, 2017
This comment has been minimized.
This comment has been minimized.
@lrytz did this happen? |
This comment has been minimized.
This comment has been minimized.
works in 2.12 |
lrytz
closed this
Mar 7, 2018
This comment has been minimized.
This comment has been minimized.
(i didn't intend to close, was on the wrong ticket) these are not yet implemented
|
lrytz
reopened this
Mar 7, 2018
This comment has been minimized.
This comment has been minimized.
NthPortal
commented
Mar 7, 2018
the first two are not necessarily true for |
This comment has been minimized.
This comment has been minimized.
I think you misunderstood what is meant, my comment was not very clear. there's no comparison involved. I updated my comment above. |
scabug commentedJul 18, 2012
There are four key optimizations that Mondrian's optimizer could make but doesn't.
Mondrian's optimizer is smart enough to turn
if (true) a else b
intoa
. To my delight, it is smart enough to do this even iftrue
is inside afinal val
and not the literaltrue
. This zeroth-order optimization is very helpful.However, Mondrian's optimizer misses several key first-order optimizations that are quite useful.
Unfortunately, you have to be careful with the two remaining cases unless you can prove that
x
&y
are side-effect free.This is something that is pretty easy to encounter in performance-critical cases where you don't really want to have to rely on the JIT optimizer to be smart enough.
One would hope that the optimizer would actually be smart enough to recurse through boolean expressions and apply these transformations from the outside in. There are also some additional safe transformations like
x && true && y == x && y
.