Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Issue 11819031: Add canonicalize optimization for branches. (Closed)

Created:
7 years, 11 months ago by Florian Schneider
Modified:
7 years, 11 months ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Visibility:
Public.

Description

Add canonicalize optimization for branches. Comparisons where the result is only used in a branch on true can be folded into the branch instruction. Patterns like this can occur after inlining and constant propagation. In normal code, we merge branches and comparisons already at graph building time. v3 <- (v1 == v2) Branch if (v3 === true) is optimized to Branch if (v1 == v2) Also: Remove outdated TODOs and rename the canonicalization pass to a better name. Committed: https://code.google.com/p/dart/source/detail?r=16919

Patch Set 1 #

Total comments: 6

Patch Set 2 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+46 lines, -9 lines) Patch
M runtime/vm/compiler.cc View 1 2 chunks +2 lines, -3 lines 0 comments Download
M runtime/vm/flow_graph_optimizer.h View 1 1 chunk +1 line, -1 line 0 comments Download
M runtime/vm/flow_graph_optimizer.cc View 1 3 chunks +1 line, -5 lines 0 comments Download
M runtime/vm/intermediate_language.h View 1 3 chunks +4 lines, -0 lines 0 comments Download
M runtime/vm/intermediate_language.cc View 1 2 chunks +38 lines, -0 lines 0 comments Download

Messages

Total messages: 3 (0 generated)
Florian Schneider
7 years, 11 months ago (2013-01-09 16:03:54 UTC) #1
Kevin Millikin (Google)
LGTM with a stylistic suggestion. https://codereview.chromium.org/11819031/diff/1/runtime/vm/compiler.cc File runtime/vm/compiler.cc (right): https://codereview.chromium.org/11819031/diff/1/runtime/vm/compiler.cc#newcode213 runtime/vm/compiler.cc:213: optimizer.CanonicalizeComputations(); This name is ...
7 years, 11 months ago (2013-01-10 10:35:00 UTC) #2
Florian Schneider
7 years, 11 months ago (2013-01-10 13:18:41 UTC) #3
Message was sent while issue was closed.
https://codereview.chromium.org/11819031/diff/1/runtime/vm/compiler.cc
File runtime/vm/compiler.cc (right):

https://codereview.chromium.org/11819031/diff/1/runtime/vm/compiler.cc#newcod...
runtime/vm/compiler.cc:213: optimizer.CanonicalizeComputations();
On 2013/01/10 10:35:00, kmillikin wrote:
> This name is fine, but you could also call it "Canonicalize" without
ambiguity.

Done.

https://codereview.chromium.org/11819031/diff/1/runtime/vm/intermediate_langu...
File runtime/vm/intermediate_language.cc (right):

https://codereview.chromium.org/11819031/diff/1/runtime/vm/intermediate_langu...
runtime/vm/intermediate_language.cc:1693: Definition* replacement =
comparison()->Canonicalize(optimizer);
On 2013/01/10 10:35:00, kmillikin wrote:
> It might be simpler with an early return, and I like to avoid calling both
IsXXX
> and AsXXX on the same instruction.  Also, the code should be safe if
> comparison()->Canonicalize() returns NULL (or at least assert that it
doesn't). 
> What do you think of:
> 
> Definition* replacement = comparison()->Canonicalize(optimizer);
> if ((replacement == comparision()) || (replacement == NULL)) return this;
> ComparisonInstr* comp = replacement->AsComparison();
> if (comp == NULL) return this;
> 
> // Replace the comparison if the replacement is only used in this branch.
> if ((comp->...) && ... && ...) ...

Done.

https://codereview.chromium.org/11819031/diff/1/runtime/vm/intermediate_langu...
runtime/vm/intermediate_language.cc:1703: ReplaceWith(comp, NULL /* ignored */);
On 2013/01/10 10:35:00, kmillikin wrote:
> You should expand the comment about NULL so the reader doesn't have to look at
> ReplaceWith.
> 
> // It's safe to pass a NULL instruction iterator because we're sure that the
> replacement is not the canonicalization iterator's current instruction.

Done.

Powered by Google App Engine
This is Rietveld 408576698