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

Unified Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 780403003: Remove trivial dead stores during dead code elimination (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/optimize.dart
diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart
index c95d5db1a16682c3cb454932c14b6f2c20a329b1..8d83f310f9a4ae10d6f02bafc6bd496ee03d6f79 100644
--- a/pkg/compiler/lib/src/ssa/optimize.dart
+++ b/pkg/compiler/lib/src/ssa/optimize.dart
@@ -982,6 +982,7 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
final Compiler compiler;
final SsaOptimizerTask optimizer;
SsaLiveBlockAnalyzer analyzer;
+ Map<HInstruction, bool> trivialDeadStoreReceivers = <HInstruction, bool>{};
floitsch 2014/12/10 20:33:04 Do you think a Map is warranted? maybe just a mapl
sra1 2014/12/10 23:08:47 Done.
bool eliminatedSideEffects = false;
SsaDeadCodeEliminator(this.compiler, this.optimizer);
@@ -1022,8 +1023,34 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
return false;
}
+ bool isTrivialDeadStoreReceiver(HInstruction instruction) {
+ // For an allocation, if all the loads are dead (awaiting removal after
+ // SsaLoadElimination) and the only other uses are stores, then the
+ // allocation does not escape which makes all the stores dead too.
+ bool isDeadUse(HInstruction use) {
+ if (use is HFieldSet) {
+ // The use must be the receiver. If the use is also the argument, i.e.
floitsch 2014/12/10 20:33:04 Even if the use...
sra1 2014/12/10 23:08:47 Done.
+ // a.x = a, the store is still dead if all other uses are dead.
+ if (use.getDartReceiver(compiler) == instruction) return true;
+ } else if (use is HFieldGet) {
+ assert(use.getDartReceiver(compiler) == instruction);
+ if (isDeadCode(use)) return true;
+ }
+ return false;
+ }
+ return instruction is HForeignNew
+ && trivialDeadStoreReceivers.putIfAbsent(instruction,
+ () => instruction.usedBy.every(isDeadUse));
+ }
+
+ bool isTrivialDeadStore(HInstruction instruction) {
+ return instruction is HFieldSet
+ && isTrivialDeadStoreReceiver(instruction.getDartReceiver(compiler));
+ }
+
bool isDeadCode(HInstruction instruction) {
if (!instruction.usedBy.isEmpty) return false;
+ if (isTrivialDeadStore(instruction)) return true;
if (instruction.sideEffects.hasSideEffects()) return false;
if (instruction.canThrow()
&& instruction.onlyThrowsNSM()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698