changeset 16369:f8ba57019a5d

LSRA spill optimization: move spill position to the dominator if at spill interval.
author Josef Eisl <josef.eisl@jku.at>
date Wed, 11 Jun 2014 17:02:27 +0200
parents ef641ba1fb69
children 3324ab9fe71a
files graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Wed Jun 11 14:51:27 2014 +0200
+++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/alloc/LinearScan.java	Wed Jun 11 17:02:27 2014 +0200
@@ -1975,9 +1975,16 @@
             if (interval != null && interval.isSplitParent() && interval.spillState() == SpillState.SpillInDominator) {
                 AbstractBlock<?> defBlock = blockForId(interval.spillDefinitionPos());
                 AbstractBlock<?> spillBlock = null;
+                Interval firstSpillChild = null;
                 try (Indent indent = Debug.logAndIndent("interval %s (%s)", interval, defBlock)) {
                     for (Interval splitChild : interval.getSplitChildren()) {
                         if (isStackSlot(splitChild.location())) {
+                            if (firstSpillChild == null || splitChild.from() < firstSpillChild.from()) {
+                                firstSpillChild = splitChild;
+                            } else {
+                                assert firstSpillChild.from() < splitChild.from();
+                            }
+                            // iterate all blocks where the interval has use positions
                             for (AbstractBlock<?> splitBlock : blocksForSplitChild(splitChild)) {
                                 assert dominates(defBlock, splitBlock) : String.format("Definition does not dominate the spill block %s !dom %s (interval %s)", defBlock, splitBlock, interval);
                                 Debug.log("Split interval %s, block %s", splitChild, splitBlock);
@@ -1999,6 +2006,17 @@
                             spillBlock = moveSpillOutOfLoop(defBlock, spillBlock);
                         }
 
+                        /*
+                         * If the spill block is the begin of the first split child (aka the value
+                         * is on the stack) spill in the dominator.
+                         */
+                        assert firstSpillChild != null;
+                        if (!defBlock.equals(spillBlock) && spillBlock.equals(blockForId(firstSpillChild.from()))) {
+                            AbstractBlock<?> dom = spillBlock.getDominator();
+                            Debug.log("Spill block (%s) is the beginning of a spill child -> use dominator (%s)", spillBlock, dom);
+                            spillBlock = dom;
+                        }
+
                         if (!defBlock.equals(spillBlock)) {
                             assert dominates(defBlock, spillBlock);
                             betterSpillPos.increment();