Mercurial > hg > graal-compiler
changeset 23111:b64fd2996da7
Convert conditional add into a flow free form
author | Tom Rodriguez <tom.rodriguez@oracle.com> |
---|---|
date | Mon, 30 Nov 2015 22:05:12 -0800 |
parents | 02b6e8f05130 |
children | 7e2419c4f3af |
files | graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java |
diffstat | 1 files changed, 21 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Mon Nov 30 16:41:10 2015 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/calc/ConditionalNode.java Mon Nov 30 22:05:12 2015 -0800 @@ -152,6 +152,27 @@ return trueValue(); } + if (condition instanceof IntegerLessThanNode && trueValue().stamp() instanceof IntegerStamp) { + /* + * Convert a conditional add ((x < 0) ? (x + y) : x) into (x + (y & (x >> (bits - 1)))) + * to avoid the test. + */ + IntegerLessThanNode lt = (IntegerLessThanNode) condition; + if (lt.getY().isConstant() && lt.getY().asConstant().isDefaultForKind()) { + if (falseValue() == lt.getX()) { + if (trueValue() instanceof AddNode) { + AddNode add = (AddNode) trueValue(); + if (add.getX() == falseValue()) { + int bits = ((IntegerStamp) trueValue().stamp()).getBits(); + ValueNode shift = new RightShiftNode(lt.getX(), ConstantNode.forIntegerBits(bits, bits - 1)); + ValueNode and = new AndNode(shift, add.getY()); + return new AddNode(add.getX(), and); + } + } + } + } + } + return this; }