src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/NegateNodeCanonicalizationTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/NegateNodeCanonicalizationTest.java

Print this page




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.nodes.test;
  24 
  25 import static org.graalvm.compiler.core.common.CompilationIdentifier.INVALID_COMPILATION_ID;
  26 import static org.junit.Assert.assertEquals;
  27 import jdk.vm.ci.meta.JavaConstant;
  28 
  29 import org.junit.Before;
  30 import org.junit.Test;
  31 
  32 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;

  33 import org.graalvm.compiler.nodes.ConstantNode;
  34 import org.graalvm.compiler.nodes.StructuredGraph;
  35 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;





  36 
  37 /**
  38  * This class tests that the canonicalization for constant negate nodes cover all cases.
  39  */

  40 public class NegateNodeCanonicalizationTest {
  41 
  42     private StructuredGraph graph;
  43 
  44     @Before
  45     public void before() {
  46         graph = new StructuredGraph(AllowAssumptions.YES, INVALID_COMPILATION_ID);
  47     }
  48 
  49     @Test
  50     public void testByte() {
  51         byte[] a = new byte[]{Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE};
  52         for (byte i : a) {
  53             ConstantNode node = ConstantNode.forByte(i, graph);
  54             JavaConstant expected = JavaConstant.forInt(-i);
  55             assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp()).getNeg().foldConstant(node.asConstant()));
  56         }
  57     }
  58 
  59     @Test
  60     public void testChar() {
  61         char[] a = new char[]{Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE};
  62         for (char i : a) {
  63             ConstantNode node = ConstantNode.forChar(i, graph);
  64             JavaConstant expected = JavaConstant.forInt(-i);
  65             assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp()).getNeg().foldConstant(node.asConstant()));
  66         }




   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.graalvm.compiler.nodes.test;
  24 

  25 import static org.junit.Assert.assertEquals;




  26 
  27 import org.graalvm.compiler.core.common.type.ArithmeticOpTable;
  28 import org.graalvm.compiler.core.test.GraalCompilerTest;
  29 import org.graalvm.compiler.nodes.ConstantNode;
  30 import org.graalvm.compiler.nodes.StructuredGraph;
  31 import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions;
  32 import org.graalvm.compiler.test.AddExports;
  33 import org.junit.Before;
  34 import org.junit.Test;
  35 
  36 import jdk.vm.ci.meta.JavaConstant;
  37 
  38 /**
  39  * This class tests that the canonicalization for constant negate nodes cover all cases.
  40  */
  41 @AddExports("jdk.internal.vm.ci/jdk.vm.ci.meta")
  42 public class NegateNodeCanonicalizationTest {
  43 
  44     private StructuredGraph graph;
  45 
  46     @Before
  47     public void before() {
  48         graph = new StructuredGraph.Builder(GraalCompilerTest.getInitialOptions(), AllowAssumptions.YES).build();
  49     }
  50 
  51     @Test
  52     public void testByte() {
  53         byte[] a = new byte[]{Byte.MIN_VALUE, Byte.MIN_VALUE + 1, -1, 0, 1, Byte.MAX_VALUE - 1, Byte.MAX_VALUE};
  54         for (byte i : a) {
  55             ConstantNode node = ConstantNode.forByte(i, graph);
  56             JavaConstant expected = JavaConstant.forInt(-i);
  57             assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp()).getNeg().foldConstant(node.asConstant()));
  58         }
  59     }
  60 
  61     @Test
  62     public void testChar() {
  63         char[] a = new char[]{Character.MIN_VALUE, Character.MIN_VALUE + 1, 0, 1, Character.MAX_VALUE - 1, Character.MAX_VALUE};
  64         for (char i : a) {
  65             ConstantNode node = ConstantNode.forChar(i, graph);
  66             JavaConstant expected = JavaConstant.forInt(-i);
  67             assertEquals(expected, ArithmeticOpTable.forStamp(node.stamp()).getNeg().foldConstant(node.asConstant()));
  68         }


src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes.test/src/org/graalvm/compiler/nodes/test/NegateNodeCanonicalizationTest.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File