IntegerSubExactSplitNode.java revision 12968:4d8a004e5c6d
1255736Sdavidch/*
2255736Sdavidch * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3255736Sdavidch * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4255736Sdavidch *
5255736Sdavidch * This code is free software; you can redistribute it and/or modify it
6255736Sdavidch * under the terms of the GNU General Public License version 2 only, as
7255736Sdavidch * published by the Free Software Foundation.
8255736Sdavidch *
9255736Sdavidch * This code is distributed in the hope that it will be useful, but WITHOUT
10255736Sdavidch * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11255736Sdavidch * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12255736Sdavidch * version 2 for more details (a copy is included in the LICENSE file that
13255736Sdavidch * accompanied this code).
14255736Sdavidch *
15255736Sdavidch * You should have received a copy of the GNU General Public License version
16255736Sdavidch * 2 along with this work; if not, write to the Free Software Foundation,
17255736Sdavidch * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18255736Sdavidch *
19255736Sdavidch * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20255736Sdavidch * or visit www.oracle.com if you need additional information or have any
21255736Sdavidch * questions.
22255736Sdavidch */
23255736Sdavidchpackage org.graalvm.compiler.replacements.nodes.arithmetic;
24255736Sdavidch
25255736Sdavidchimport org.graalvm.compiler.core.common.type.IntegerStamp;
26255736Sdavidchimport org.graalvm.compiler.core.common.type.Stamp;
27255736Sdavidchimport org.graalvm.compiler.graph.NodeClass;
28255736Sdavidchimport org.graalvm.compiler.graph.spi.SimplifierTool;
29255736Sdavidchimport org.graalvm.compiler.nodeinfo.NodeInfo;
30255736Sdavidchimport org.graalvm.compiler.nodes.AbstractBeginNode;
31255736Sdavidchimport org.graalvm.compiler.nodes.ValueNode;
32255736Sdavidchimport org.graalvm.compiler.nodes.calc.SubNode;
33255736Sdavidchimport org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
34255736Sdavidch
35255736Sdavidchimport jdk.vm.ci.meta.Value;
36255736Sdavidch
37255736Sdavidch@NodeInfo
38255736Sdavidchpublic final class IntegerSubExactSplitNode extends IntegerExactArithmeticSplitNode {
39255736Sdavidch    public static final NodeClass<IntegerSubExactSplitNode> TYPE = NodeClass.create(IntegerSubExactSplitNode.class);
40255736Sdavidch
41255736Sdavidch    public IntegerSubExactSplitNode(Stamp stamp, ValueNode x, ValueNode y, AbstractBeginNode next, AbstractBeginNode overflowSuccessor) {
42255736Sdavidch        super(TYPE, stamp, x, y, next, overflowSuccessor);
43255736Sdavidch    }
44255736Sdavidch
45255736Sdavidch    @Override
46255736Sdavidch    protected Value generateArithmetic(NodeLIRBuilderTool gen) {
47255736Sdavidch        return gen.getLIRGeneratorTool().getArithmetic().emitSub(gen.operand(getX()), gen.operand(getY()), true);
48255736Sdavidch    }
49255736Sdavidch
50255736Sdavidch    @Override
51255736Sdavidch    public void simplify(SimplifierTool tool) {
52255736Sdavidch        if (!IntegerStamp.subtractionCanOverflow((IntegerStamp) x.stamp(), (IntegerStamp) y.stamp())) {
53255736Sdavidch            tool.deleteBranch(overflowSuccessor);
54255736Sdavidch            tool.addToWorkList(next);
55255736Sdavidch            SubNode replacement = graph().unique(new SubNode(x, y));
56255736Sdavidch            graph().replaceSplitWithFloating(this, replacement, next);
57255736Sdavidch            tool.addToWorkList(replacement);
58255736Sdavidch        }
59255736Sdavidch    }
60255736Sdavidch}
61255736Sdavidch