001/* 002 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. 003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 004 * 005 * This code is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU General Public License version 2 only, as 007 * published by the Free Software Foundation. 008 * 009 * This code is distributed in the hope that it will be useful, but WITHOUT 010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 011 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 012 * version 2 for more details (a copy is included in the LICENSE file that 013 * accompanied this code). 014 * 015 * You should have received a copy of the GNU General Public License version 016 * 2 along with this work; if not, write to the Free Software Foundation, 017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 018 * 019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 020 * or visit www.oracle.com if you need additional information or have any 021 * questions. 022 */ 023package com.oracle.graal.nodes.calc; 024 025import jdk.internal.jvmci.common.*; 026import jdk.internal.jvmci.meta.*; 027 028import com.oracle.graal.compiler.common.calc.*; 029import com.oracle.graal.compiler.common.type.*; 030import com.oracle.graal.graph.*; 031import com.oracle.graal.graph.spi.Canonicalizable.BinaryCommutative; 032import com.oracle.graal.graph.spi.*; 033import com.oracle.graal.nodeinfo.*; 034import com.oracle.graal.nodes.*; 035import com.oracle.graal.nodes.util.*; 036 037@NodeInfo(shortName = "==") 038public final class FloatEqualsNode extends CompareNode implements BinaryCommutative<ValueNode> { 039 public static final NodeClass<FloatEqualsNode> TYPE = NodeClass.create(FloatEqualsNode.class); 040 041 public FloatEqualsNode(ValueNode x, ValueNode y) { 042 super(TYPE, Condition.EQ, false, x, y); 043 assert x.stamp() instanceof FloatStamp && y.stamp() instanceof FloatStamp : x.stamp() + " " + y.stamp(); 044 assert x.stamp().isCompatible(y.stamp()); 045 } 046 047 public static LogicNode create(ValueNode x, ValueNode y, ConstantReflectionProvider constantReflection) { 048 LogicNode result = CompareNode.tryConstantFold(Condition.EQ, x, y, constantReflection, false); 049 if (result != null) { 050 return result; 051 } else { 052 return new FloatEqualsNode(x, y).maybeCommuteInputs(); 053 } 054 } 055 056 @Override 057 public ValueNode canonical(CanonicalizerTool tool, ValueNode forX, ValueNode forY) { 058 ValueNode result = super.canonical(tool, forX, forY); 059 if (result != this) { 060 return result; 061 } 062 Stamp xStampGeneric = forX.stamp(); 063 Stamp yStampGeneric = forY.stamp(); 064 if (xStampGeneric instanceof FloatStamp && yStampGeneric instanceof FloatStamp) { 065 FloatStamp xStamp = (FloatStamp) xStampGeneric; 066 FloatStamp yStamp = (FloatStamp) yStampGeneric; 067 if (GraphUtil.unproxify(forX) == GraphUtil.unproxify(forY) && xStamp.isNonNaN() && yStamp.isNonNaN()) { 068 return LogicConstantNode.tautology(); 069 } else if (xStamp.alwaysDistinct(yStamp)) { 070 return LogicConstantNode.contradiction(); 071 } 072 } 073 return this; 074 } 075 076 @Override 077 protected CompareNode duplicateModified(ValueNode newX, ValueNode newY) { 078 if (newX.stamp() instanceof FloatStamp && newY.stamp() instanceof FloatStamp) { 079 return new FloatEqualsNode(newX, newY); 080 } else if (newX.stamp() instanceof IntegerStamp && newY.stamp() instanceof IntegerStamp) { 081 return new IntegerEqualsNode(newX, newY); 082 } 083 throw JVMCIError.shouldNotReachHere(); 084 } 085 086 @Override 087 public Stamp getSucceedingStampForX(boolean negated) { 088 if (!negated) { 089 return getX().stamp().join(getY().stamp()); 090 } 091 return null; 092 } 093 094 @Override 095 public Stamp getSucceedingStampForY(boolean negated) { 096 if (!negated) { 097 return getX().stamp().join(getY().stamp()); 098 } 099 return null; 100 } 101 102 @Override 103 public TriState tryFold(Stamp xStampGeneric, Stamp yStampGeneric) { 104 if (xStampGeneric instanceof FloatStamp && yStampGeneric instanceof FloatStamp) { 105 FloatStamp xStamp = (FloatStamp) xStampGeneric; 106 FloatStamp yStamp = (FloatStamp) yStampGeneric; 107 if (xStamp.alwaysDistinct(yStamp)) { 108 return TriState.FALSE; 109 } else if (xStamp.neverDistinct(yStamp)) { 110 return TriState.TRUE; 111 } 112 } 113 return TriState.UNKNOWN; 114 } 115}