75 sink1 = 0;
76 } else {
77 sink0 = -1;
78 }
79 }
80
81 public static void referenceSnippet01(char a) {
82 if (a != 0) {
83 sink1 = 0;
84 } else {
85 sink0 = -1;
86 }
87 }
88
89 @Ignore("Needs better stamp support for unsigned ranges")
90 @Test
91 public void test1() {
92 assertCanonicallyEqual("integerTestCanonicalization1", "referenceSnippet1");
93 }
94
95 public static void integerTestCanonicalization1(char a) {
96 if (Integer.compareUnsigned(a - 2, a) < 0) {
97 sink1 = 0;
98 } else {
99 sink0 = -1;
100 }
101 }
102
103 public static void referenceSnippet1(char a) {
104 if (Integer.compareUnsigned(a, 2) >= 0) {
105 sink1 = 0;
106 } else {
107 sink0 = -1;
108 }
109 }
110
111 @Test
112 public void test2() {
113 assertCanonicallyEqual("integerTestCanonicalization2", "referenceSnippet2");
114 }
115
116 public static void integerTestCanonicalization2(int a) {
117 if (a - 1 < a) {
118 sink1 = 0;
119 } else {
120 sink0 = -1;
121 }
122 }
123
124 public static void referenceSnippet2(int a) {
221 public static void integerTestCanonicalization7(int a) {
222 if (a < a + 2) {
223 sink1 = 0;
224 } else {
225 sink0 = -1;
226 }
227 }
228
229 public static void referenceSnippet7(int a) {
230 if (a <= Integer.MAX_VALUE - 2) {
231 sink1 = 0;
232 } else {
233 sink0 = -1;
234 }
235 }
236
237 protected void assertCanonicallyEqual(String snippet, String reference) {
238 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
239 PhaseContext context = new PhaseContext(getProviders());
240 CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
241 canonicalizer.apply(graph, context);
242 new GuardLoweringPhase().apply(graph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
243 new FrameStateAssignmentPhase().apply(graph);
244 canonicalizer.apply(graph, context);
245 StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
246 canonicalizer.apply(referenceGraph, context);
247 canonicalizer.apply(referenceGraph, context);
248 assertEquals(referenceGraph, graph, true, true);
249 }
250
251 @Override
252 protected InlineInvokePlugin.InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
253 return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(method);
254 }
255 }
|
75 sink1 = 0;
76 } else {
77 sink0 = -1;
78 }
79 }
80
81 public static void referenceSnippet01(char a) {
82 if (a != 0) {
83 sink1 = 0;
84 } else {
85 sink0 = -1;
86 }
87 }
88
89 @Ignore("Needs better stamp support for unsigned ranges")
90 @Test
91 public void test1() {
92 assertCanonicallyEqual("integerTestCanonicalization1", "referenceSnippet1");
93 }
94
95 public static void integerTestCanonicalization1(char[] a) {
96 int len = a.length;
97 if (Integer.compareUnsigned(len - 2, len) < 0) {
98 sink1 = 0;
99 } else {
100 sink0 = -1;
101 }
102 }
103
104 public static void referenceSnippet1(char[] a) {
105 int len = a.length;
106 if (Integer.compareUnsigned(len, 2) >= 0) {
107 sink1 = 0;
108 } else {
109 sink0 = -1;
110 }
111 }
112
113 @Test
114 public void test2() {
115 assertCanonicallyEqual("integerTestCanonicalization2", "referenceSnippet2");
116 }
117
118 public static void integerTestCanonicalization2(int a) {
119 if (a - 1 < a) {
120 sink1 = 0;
121 } else {
122 sink0 = -1;
123 }
124 }
125
126 public static void referenceSnippet2(int a) {
223 public static void integerTestCanonicalization7(int a) {
224 if (a < a + 2) {
225 sink1 = 0;
226 } else {
227 sink0 = -1;
228 }
229 }
230
231 public static void referenceSnippet7(int a) {
232 if (a <= Integer.MAX_VALUE - 2) {
233 sink1 = 0;
234 } else {
235 sink0 = -1;
236 }
237 }
238
239 protected void assertCanonicallyEqual(String snippet, String reference) {
240 StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES);
241 PhaseContext context = new PhaseContext(getProviders());
242 CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
243
244 canonicalizer.apply(graph, context);
245 new GuardLoweringPhase().apply(graph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
246 new FrameStateAssignmentPhase().apply(graph);
247 canonicalizer.apply(graph, context);
248
249 StructuredGraph referenceGraph = parseEager(reference, AllowAssumptions.YES);
250 canonicalizer.apply(referenceGraph, context);
251 new GuardLoweringPhase().apply(referenceGraph, new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo()));
252 new FrameStateAssignmentPhase().apply(referenceGraph);
253 canonicalizer.apply(referenceGraph, context);
254
255 canonicalizer.apply(referenceGraph, context);
256 assertEquals(referenceGraph, graph, true, true);
257 }
258
259 @Override
260 protected InlineInvokePlugin.InlineInfo bytecodeParserShouldInlineInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
261 return InlineInvokePlugin.InlineInfo.createStandardInlineInfo(method);
262 }
263 }
|