# HG changeset patch # User Christian Wimmer # Date 1385151583 28800 # Node ID c7ce697ddb9a91e8060dcacb9bc51cde55d0ae1f # Parent 6217f601e65d5a039d1d6f76bff716b3a18fa663 Improvements and bugfixes of word type rewriter diff -r 6217f601e65d -r c7ce697ddb9a graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/ObjectAccessTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/ObjectAccessTest.java Fri Nov 22 12:19:16 2013 -0800 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/ObjectAccessTest.java Fri Nov 22 12:19:43 2013 -0800 @@ -46,7 +46,7 @@ private final ReplacementsImpl installer; public ObjectAccessTest() { - installer = new ReplacementsImpl(getProviders(), new Assumptions(false)); + installer = new ReplacementsImpl(getProviders(), new Assumptions(false), getTarget()); } private static final ThreadLocal inliningPolicy = new ThreadLocal<>(); @@ -60,7 +60,7 @@ @Test public void testRead1() { for (Kind kind : KINDS) { - assertRead(parse("read" + kind.name() + "1"), kind, false, ID); + assertRead(parse("read" + kind.name() + "1"), kind, true, ID); } } @@ -74,14 +74,14 @@ @Test public void testRead3() { for (Kind kind : KINDS) { - assertRead(parse("read" + kind.name() + "3"), kind, false, LocationIdentity.ANY_LOCATION); + assertRead(parse("read" + kind.name() + "3"), kind, true, LocationIdentity.ANY_LOCATION); } } @Test public void testWrite1() { for (Kind kind : KINDS) { - assertWrite(parse("write" + kind.name() + "1"), kind, false, ID); + assertWrite(parse("write" + kind.name() + "1"), kind, true, ID); } } @@ -95,7 +95,7 @@ @Test public void testWrite3() { for (Kind kind : KINDS) { - assertWrite(parse("write" + kind.name() + "3"), kind, false, LocationIdentity.ANY_LOCATION); + assertWrite(parse("write" + kind.name() + "3"), kind, true, LocationIdentity.ANY_LOCATION); } } diff -r 6217f601e65d -r c7ce697ddb9a graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/PointerTest.java --- a/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/PointerTest.java Fri Nov 22 12:19:16 2013 -0800 +++ b/graal/com.oracle.graal.replacements.test/src/com/oracle/graal/replacements/test/PointerTest.java Fri Nov 22 12:19:43 2013 -0800 @@ -52,7 +52,7 @@ public PointerTest() { target = getCodeCache().getTarget(); - installer = new ReplacementsImpl(getProviders(), new Assumptions(false)); + installer = new ReplacementsImpl(getProviders(), new Assumptions(false), getTarget()); } private static final ThreadLocal inliningPolicy = new ThreadLocal<>(); @@ -66,7 +66,7 @@ @Test public void testRead1() { for (Kind kind : KINDS) { - assertRead(parse("read" + kind.name() + "1"), kind, false, ID); + assertRead(parse("read" + kind.name() + "1"), kind, true, ID); } } @@ -80,14 +80,14 @@ @Test public void testRead3() { for (Kind kind : KINDS) { - assertRead(parse("read" + kind.name() + "3"), kind, false, LocationIdentity.ANY_LOCATION); + assertRead(parse("read" + kind.name() + "3"), kind, true, LocationIdentity.ANY_LOCATION); } } @Test public void testWrite1() { for (Kind kind : KINDS) { - assertWrite(parse("write" + kind.name() + "1"), kind, false, ID); + assertWrite(parse("write" + kind.name() + "1"), kind, true, ID); } } @@ -101,7 +101,7 @@ @Test public void testWrite3() { for (Kind kind : KINDS) { - assertWrite(parse("write" + kind.name() + "3"), kind, false, LocationIdentity.ANY_LOCATION); + assertWrite(parse("write" + kind.name() + "3"), kind, true, LocationIdentity.ANY_LOCATION); } } diff -r 6217f601e65d -r c7ce697ddb9a graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java --- a/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Fri Nov 22 12:19:16 2013 -0800 +++ b/graal/com.oracle.graal.word/src/com/oracle/graal/word/phases/WordTypeRewriterPhase.java Fri Nov 22 12:19:43 2013 -0800 @@ -86,6 +86,21 @@ * prepared to see the word type during canonicalization. */ protected void inferStamps(StructuredGraph graph) { + /* + * We want to make the stamps more precise. For cyclic phi functions, this means we have to + * ignore the initial stamp because the imprecise stamp would always propagate around the + * cycle. We therefore set the stamp to an illegal stamp, which is automatically ignored + * when the phi function performs the "meet" operator on its input stamps. + */ + for (Node n : graph.getNodes()) { + if (n instanceof PhiNode || n instanceof ProxyNode) { + ValueNode node = (ValueNode) n; + if (node.kind() == Kind.Object) { + node.setStamp(StampFactory.illegal(node.kind())); + } + } + } + boolean stampChanged; do { stampChanged = false; @@ -104,6 +119,22 @@ } } } while (stampChanged); + + /* + * Check that all the illegal stamps we introduced above are correctly replaced with real + * stamps again. + */ + assert checkNoIllegalStamp(graph); + } + + private static boolean checkNoIllegalStamp(StructuredGraph graph) { + for (Node n : graph.getNodes()) { + if (n instanceof ValueNode) { + ValueNode node = (ValueNode) n; + assert !(node.stamp() instanceof IllegalStamp); + } + } + return true; } /** @@ -243,7 +274,7 @@ } else { location = makeLocation(graph, arguments.get(1), readKind, arguments.get(2)); } - replace(invoke, readOp(graph, arguments.get(0), invoke, location, BarrierType.NONE, false)); + replace(invoke, readOp(graph, arguments.get(0), invoke, location, readKind, BarrierType.NONE, false)); break; } case READ_HEAP: { @@ -251,7 +282,7 @@ Kind readKind = asKind(callTargetNode.returnType()); LocationNode location = makeLocation(graph, arguments.get(1), readKind, ANY_LOCATION); BarrierType barrierType = (BarrierType) arguments.get(2).asConstant().asObject(); - replace(invoke, readOp(graph, arguments.get(0), invoke, location, barrierType, arguments.get(3).asConstant().asInt() == 0 ? false : true)); + replace(invoke, readOp(graph, arguments.get(0), invoke, location, readKind, barrierType, arguments.get(3).asConstant().asInt() == 0 ? false : true)); break; } case WRITE: @@ -390,15 +421,16 @@ if (locationIdentity.isConstant()) { return makeLocation(graph, offset, readKind, (LocationIdentity) locationIdentity.asConstant().asObject()); } - return SnippetLocationNode.create(locationIdentity, ConstantNode.forObject(readKind, metaAccess, graph), ConstantNode.forLong(0, graph), offset, ConstantNode.forInt(1, graph), graph); + return SnippetLocationNode.create(locationIdentity, ConstantNode.forObject(readKind, metaAccess, graph), ConstantNode.forLong(0, graph), fromSigned(graph, offset), + ConstantNode.forInt(1, graph), graph); } protected LocationNode makeLocation(StructuredGraph graph, ValueNode offset, Kind readKind, LocationIdentity locationIdentity) { - return IndexedLocationNode.create(locationIdentity, readKind, 0, offset, graph, 1); + return IndexedLocationNode.create(locationIdentity, readKind, 0, fromSigned(graph, offset), graph, 1); } - protected ValueNode readOp(StructuredGraph graph, ValueNode base, Invoke invoke, LocationNode location, BarrierType barrierType, boolean compressible) { - ReadNode read = graph.add(new ReadNode(base, location, invoke.asNode().stamp(), barrierType, compressible)); + protected ValueNode readOp(StructuredGraph graph, ValueNode base, Invoke invoke, LocationNode location, Kind readKind, BarrierType barrierType, boolean compressible) { + ReadNode read = graph.add(new ReadNode(base, location, StampFactory.forKind(readKind), barrierType, compressible)); graph.addBeforeFixed(invoke.asNode(), read); /* * The read must not float outside its block otherwise it may float above an explicit zero