Mercurial > hg > graal-jvmci-8
diff graal/GraalCompiler/src/com/sun/c1x/ir/Or.java @ 2869:fc75fd3fa5e4
merge (inlining broken)
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Tue, 07 Jun 2011 19:21:23 +0200 |
parents | 6d24c27902a2 4f64bd98f9dc |
children |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/ir/Or.java Tue Jun 07 19:19:14 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/ir/Or.java Tue Jun 07 19:21:23 2011 +0200 @@ -23,6 +23,7 @@ package com.sun.c1x.ir; import com.oracle.graal.graph.*; +import com.oracle.max.graal.opt.CanonicalizerPhase.CanonicalizerOp; import com.sun.cri.bytecode.*; import com.sun.cri.ci.*; @@ -31,6 +32,7 @@ * */ public final class Or extends Logic { + private static final OrCanonicalizerOp CANONICALIZER = new OrCanonicalizerOp(); /** * @param opcode @@ -54,4 +56,61 @@ return x; } + @SuppressWarnings("unchecked") + @Override + public <T extends Op> T lookup(Class<T> clazz) { + if (clazz == CanonicalizerOp.class) { + return (T) CANONICALIZER; + } + return super.lookup(clazz); + } + + private static class OrCanonicalizerOp implements CanonicalizerOp { + @Override + public Node canonical(Node node) { + assert node instanceof Or; + Or or = (Or) node; + CiKind kind = or.kind; + Graph graph = or.graph(); + Value x = or.x(); + Value y = or.y(); + if (x == y) { + return x; + } + if (x.isConstant() && !y.isConstant()) { + or.swapOperands(); + Value t = y; + y = x; + x = t; + } + if (x.isConstant()) { + if (kind == CiKind.Int) { + return Constant.forInt(x.asConstant().asInt() | y.asConstant().asInt(), graph); + } else { + assert kind == CiKind.Long; + return Constant.forLong(x.asConstant().asLong() | y.asConstant().asLong(), graph); + } + } else if (y.isConstant()) { + if (kind == CiKind.Int) { + int c = y.asConstant().asInt(); + if (c == -1) { + return Constant.forInt(-1, graph); + } + if (c == 0) { + return x; + } + } else { + assert kind == CiKind.Long; + long c = y.asConstant().asLong(); + if (c == -1) { + return Constant.forLong(-1, graph); + } + if (c == 0) { + return x; + } + } + } + return or; + } + } }