25
25
*/
26
26
package jdk .graal .compiler .core .test ;
27
27
28
+ import org .junit .Test ;
29
+
28
30
import jdk .graal .compiler .nodes .StructuredGraph ;
29
31
import jdk .graal .compiler .nodes .calc .NegateNode ;
30
32
import jdk .graal .compiler .nodes .calc .RightShiftNode ;
31
33
import jdk .graal .compiler .nodes .calc .UnsignedRightShiftNode ;
32
- import org .junit .Test ;
33
34
34
35
public class NegateCanonicalizationTest extends GraalCompilerTest {
35
36
@@ -49,19 +50,37 @@ public static long signExtractLong(long x) {
49
50
return (x >> 63 ) >>> 63 ;
50
51
}
51
52
52
- private void checkNodes (String methodName ) {
53
+ public static int negateNegate (int x ) {
54
+ int var0 = -x ;
55
+ int var1 = -(0 ^ var0 );
56
+ return var1 ;
57
+ }
58
+
59
+ public static int negateNotDecrement (int x ) {
60
+ return -~(x - 1 );
61
+ }
62
+
63
+ private void checkNodesOnlyUnsignedRightShift (String methodName ) {
53
64
StructuredGraph graph = parseForCompile (getResolvedJavaMethod (methodName ));
54
65
createCanonicalizerPhase ().apply (graph , getProviders ());
55
66
assertTrue (graph .getNodes ().filter (NegateNode .class ).count () == 0 );
56
67
assertTrue (graph .getNodes ().filter (RightShiftNode .class ).count () == 0 );
57
68
assertTrue (graph .getNodes ().filter (UnsignedRightShiftNode .class ).count () == 1 );
58
69
}
59
70
71
+ private void checkNodesNoNegate (String methodName ) {
72
+ StructuredGraph graph = parseForCompile (getResolvedJavaMethod (methodName ));
73
+ createCanonicalizerPhase ().apply (graph , getProviders ());
74
+ assertTrue (graph .getNodes ().filter (NegateNode .class ).count () == 0 );
75
+ }
76
+
60
77
@ Test
61
78
public void testNegate () {
62
- checkNodes ("negateInt" );
63
- checkNodes ("negateLong" );
64
- checkNodes ("signExtractInt" );
65
- checkNodes ("signExtractLong" );
79
+ checkNodesOnlyUnsignedRightShift ("negateInt" );
80
+ checkNodesOnlyUnsignedRightShift ("negateLong" );
81
+ checkNodesOnlyUnsignedRightShift ("signExtractInt" );
82
+ checkNodesOnlyUnsignedRightShift ("signExtractLong" );
83
+ checkNodesNoNegate ("negateNegate" );
84
+ checkNodesNoNegate ("negateNotDecrement" );
66
85
}
67
86
}
0 commit comments