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