Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /** |
| 18 | * Tests for ABS vectorization. |
| 19 | */ |
| 20 | public class Main { |
| 21 | |
| 22 | private static final int SPQUIET = 1 << 22; |
| 23 | private static final long DPQUIET = 1L << 51; |
| 24 | |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 25 | /// CHECK-START: void Main.doitByte(byte[]) loop_optimization (before) |
| 26 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 27 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 28 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop>> outer_loop:none |
| 29 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 30 | // |
Artem Serov | 8f7c410 | 2017-06-21 11:21:37 +0100 | [diff] [blame] | 31 | /// CHECK-START-ARM: void Main.doitByte(byte[]) loop_optimization (after) |
| 32 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 33 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 34 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 35 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 36 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 37 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 38 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 39 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 40 | // |
| 41 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
| 42 | // |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 43 | /// CHECK-START-ARM64: void Main.doitByte(byte[]) loop_optimization (after) |
| 44 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 45 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 46 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 47 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 48 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 49 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 50 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 51 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 52 | // |
| 53 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 54 | // |
| 55 | /// CHECK-START-MIPS64: void Main.doitByte(byte[]) loop_optimization (after) |
| 56 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 57 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 58 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 59 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 60 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 61 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 62 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 63 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 64 | // |
| 65 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 66 | private static void doitByte(byte[] x) { |
| 67 | for (int i = 0; i < x.length; i++) { |
| 68 | x[i] = (byte) Math.abs(x[i]); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// CHECK-START: void Main.doitChar(char[]) loop_optimization (before) |
| 73 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 74 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 75 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop>> outer_loop:none |
| 76 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 77 | // |
| 78 | /// CHECK-START: void Main.doitChar(char[]) loop_optimization (after) |
| 79 | /// CHECK-NOT: VecAbs |
| 80 | private static void doitChar(char[] x) { |
| 81 | // Basically a nop due to zero extension. |
| 82 | for (int i = 0; i < x.length; i++) { |
| 83 | x[i] = (char) Math.abs(x[i]); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /// CHECK-START: void Main.doitShort(short[]) loop_optimization (before) |
| 88 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 89 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 90 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop>> outer_loop:none |
| 91 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 92 | // |
Artem Serov | 8f7c410 | 2017-06-21 11:21:37 +0100 | [diff] [blame] | 93 | /// CHECK-START-ARM: void Main.doitShort(short[]) loop_optimization (after) |
| 94 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 95 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 96 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 97 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 98 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 99 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 100 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 101 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 102 | // |
| 103 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
| 104 | // |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 105 | /// CHECK-START-ARM64: void Main.doitShort(short[]) loop_optimization (after) |
| 106 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 107 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 108 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 109 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 110 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 111 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 112 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 113 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 114 | // |
| 115 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 116 | // |
| 117 | /// CHECK-START-MIPS64: void Main.doitShort(short[]) loop_optimization (after) |
| 118 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 119 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 120 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 121 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 122 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 123 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 124 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 125 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 126 | // |
| 127 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 128 | private static void doitShort(short[] x) { |
| 129 | for (int i = 0; i < x.length; i++) { |
| 130 | x[i] = (short) Math.abs(x[i]); |
| 131 | } |
| 132 | } |
| 133 | |
Aart Bik | df011c3 | 2017-09-28 12:53:04 -0700 | [diff] [blame] | 134 | /// CHECK-START: void Main.doitCastedChar(char[]) loop_optimization (before) |
| 135 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 136 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 137 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop>> outer_loop:none |
| 138 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 139 | // |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame^] | 140 | // FIXME: Pattern currently not detected. b/67935418 |
| 141 | // CHECK-START-ARM64: void Main.doitCastedChar(char[]) loop_optimization (after) |
| 142 | // CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 143 | // CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 144 | // CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 145 | // CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 146 | // CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 147 | // CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
Aart Bik | df011c3 | 2017-09-28 12:53:04 -0700 | [diff] [blame] | 148 | // |
Vladimir Marko | 61b9228 | 2017-10-11 13:23:17 +0100 | [diff] [blame^] | 149 | // CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | df011c3 | 2017-09-28 12:53:04 -0700 | [diff] [blame] | 150 | // |
| 151 | private static void doitCastedChar(char[] x) { |
| 152 | for (int i = 0; i < x.length; i++) { |
| 153 | x[i] = (char) Math.abs((short) x[i]); |
| 154 | } |
| 155 | } |
| 156 | |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 157 | /// CHECK-START: void Main.doitInt(int[]) loop_optimization (before) |
| 158 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 159 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 160 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop>> outer_loop:none |
| 161 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 162 | // |
Artem Serov | 8f7c410 | 2017-06-21 11:21:37 +0100 | [diff] [blame] | 163 | /// CHECK-START-ARM: void Main.doitInt(int[]) loop_optimization (after) |
| 164 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 165 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 166 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 167 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 168 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 169 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 170 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 171 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 172 | // |
| 173 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
| 174 | // |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 175 | /// CHECK-START-ARM64: void Main.doitInt(int[]) loop_optimization (after) |
| 176 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 177 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 178 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 179 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 180 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 181 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 182 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 183 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 184 | // |
| 185 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 186 | // |
| 187 | /// CHECK-START-MIPS64: void Main.doitInt(int[]) loop_optimization (after) |
| 188 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 189 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 190 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 191 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 192 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 193 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 194 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsInt loop:<<Loop2>> outer_loop:none |
| 195 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 196 | // |
| 197 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 198 | private static void doitInt(int[] x) { |
| 199 | for (int i = 0; i < x.length; i++) { |
| 200 | x[i] = Math.abs(x[i]); |
| 201 | } |
| 202 | } |
| 203 | |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 204 | /// CHECK-START: void Main.doitLong(long[]) loop_optimization (before) |
| 205 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 206 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 207 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsLong loop:<<Loop>> outer_loop:none |
| 208 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 209 | // |
| 210 | /// CHECK-START-ARM64: void Main.doitLong(long[]) loop_optimization (after) |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 211 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 212 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 213 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 214 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 215 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 216 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 217 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsLong loop:<<Loop2>> outer_loop:none |
| 218 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 219 | // |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 220 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 221 | // |
| 222 | /// CHECK-START-MIPS64: void Main.doitLong(long[]) loop_optimization (after) |
| 223 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 224 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 225 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 226 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 227 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 228 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 229 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsLong loop:<<Loop2>> outer_loop:none |
| 230 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 231 | // |
| 232 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 233 | private static void doitLong(long[] x) { |
| 234 | for (int i = 0; i < x.length; i++) { |
| 235 | x[i] = Math.abs(x[i]); |
| 236 | } |
| 237 | } |
| 238 | |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 239 | /// CHECK-START: void Main.doitFloat(float[]) loop_optimization (before) |
| 240 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 241 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 242 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsFloat loop:<<Loop>> outer_loop:none |
| 243 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 244 | // |
| 245 | /// CHECK-START-ARM64: void Main.doitFloat(float[]) loop_optimization (after) |
| 246 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 247 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 248 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 249 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 250 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 251 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 252 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsFloat loop:<<Loop2>> outer_loop:none |
| 253 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 254 | // |
| 255 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 256 | // |
| 257 | /// CHECK-START-MIPS64: void Main.doitFloat(float[]) loop_optimization (after) |
| 258 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 259 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 260 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 261 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 262 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 263 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 264 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsFloat loop:<<Loop2>> outer_loop:none |
| 265 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 266 | // |
| 267 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 268 | private static void doitFloat(float[] x) { |
| 269 | for (int i = 0; i < x.length; i++) { |
| 270 | x[i] = Math.abs(x[i]); |
| 271 | } |
| 272 | } |
| 273 | |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 274 | /// CHECK-START: void Main.doitDouble(double[]) loop_optimization (before) |
| 275 | /// CHECK-DAG: Phi loop:<<Loop:B\d+>> outer_loop:none |
| 276 | /// CHECK-DAG: ArrayGet loop:<<Loop>> outer_loop:none |
| 277 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsDouble loop:<<Loop>> outer_loop:none |
| 278 | /// CHECK-DAG: ArraySet loop:<<Loop>> outer_loop:none |
| 279 | // |
| 280 | /// CHECK-START-ARM64: void Main.doitDouble(double[]) loop_optimization (after) |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 281 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 282 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 283 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 284 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 285 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 286 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 287 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsDouble loop:<<Loop2>> outer_loop:none |
| 288 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
Aart Bik | 9899026 | 2017-04-10 13:15:57 -0700 | [diff] [blame] | 289 | // |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 290 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Goran Jakovljevic | 19680d3 | 2017-05-11 10:38:36 +0200 | [diff] [blame] | 291 | // |
| 292 | /// CHECK-START-MIPS64: void Main.doitDouble(double[]) loop_optimization (after) |
| 293 | /// CHECK-DAG: Phi loop:<<Loop1:B\d+>> outer_loop:none |
| 294 | /// CHECK-DAG: VecLoad loop:<<Loop1>> outer_loop:none |
| 295 | /// CHECK-DAG: VecAbs loop:<<Loop1>> outer_loop:none |
| 296 | /// CHECK-DAG: VecStore loop:<<Loop1>> outer_loop:none |
| 297 | /// CHECK-DAG: Phi loop:<<Loop2:B\d+>> outer_loop:none |
| 298 | /// CHECK-DAG: ArrayGet loop:<<Loop2>> outer_loop:none |
| 299 | /// CHECK-DAG: InvokeStaticOrDirect intrinsic:MathAbsDouble loop:<<Loop2>> outer_loop:none |
| 300 | /// CHECK-DAG: ArraySet loop:<<Loop2>> outer_loop:none |
| 301 | // |
| 302 | /// CHECK-EVAL: "<<Loop1>>" != "<<Loop2>>" |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 303 | private static void doitDouble(double[] x) { |
| 304 | for (int i = 0; i < x.length; i++) { |
| 305 | x[i] = Math.abs(x[i]); |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | public static void main(String[] args) { |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 310 | // Bytes, chars, shorts. |
| 311 | byte[] xb = new byte[256]; |
| 312 | for (int i = 0; i < 256; i++) { |
| 313 | xb[i] = (byte) i; |
| 314 | } |
| 315 | doitByte(xb); |
| 316 | for (int i = 0; i < 256; i++) { |
| 317 | expectEquals32((byte) Math.abs((byte) i), xb[i]); |
| 318 | } |
| 319 | char[] xc = new char[1024 * 64]; |
| 320 | for (int i = 0; i < 1024 * 64; i++) { |
| 321 | xc[i] = (char) i; |
| 322 | } |
| 323 | doitChar(xc); |
Aart Bik | df011c3 | 2017-09-28 12:53:04 -0700 | [diff] [blame] | 324 | for (int i = 0; i < 1024 * 64; i++) { |
Aart Bik | 304c8a5 | 2017-05-23 11:01:13 -0700 | [diff] [blame] | 325 | expectEquals32((char) Math.abs((char) i), xc[i]); |
| 326 | } |
| 327 | short[] xs = new short[1024 * 64]; |
| 328 | for (int i = 0; i < 1024 * 64; i++) { |
| 329 | xs[i] = (short) i; |
| 330 | } |
| 331 | doitShort(xs); |
| 332 | for (int i = 0; i < 1024 * 64; i++) { |
| 333 | expectEquals32((short) Math.abs((short) i), xs[i]); |
| 334 | } |
Aart Bik | df011c3 | 2017-09-28 12:53:04 -0700 | [diff] [blame] | 335 | for (int i = 0; i < 1024 * 64; i++) { |
| 336 | xc[i] = (char) i; |
| 337 | } |
| 338 | doitCastedChar(xc); |
| 339 | for (int i = 0; i < 1024 * 64; i++) { |
| 340 | expectEquals32((char) Math.abs((short) i), xc[i]); |
| 341 | } |
Aart Bik | 6daebeb | 2017-04-03 14:35:41 -0700 | [diff] [blame] | 342 | // Set up minint32, maxint32 and some others. |
| 343 | int[] xi = new int[8]; |
| 344 | xi[0] = 0x80000000; |
| 345 | xi[1] = 0x7fffffff; |
| 346 | xi[2] = 0x80000001; |
| 347 | xi[3] = -13; |
| 348 | xi[4] = -1; |
| 349 | xi[5] = 0; |
| 350 | xi[6] = 1; |
| 351 | xi[7] = 999; |
| 352 | doitInt(xi); |
| 353 | expectEquals32(0x80000000, xi[0]); |
| 354 | expectEquals32(0x7fffffff, xi[1]); |
| 355 | expectEquals32(0x7fffffff, xi[2]); |
| 356 | expectEquals32(13, xi[3]); |
| 357 | expectEquals32(1, xi[4]); |
| 358 | expectEquals32(0, xi[5]); |
| 359 | expectEquals32(1, xi[6]); |
| 360 | expectEquals32(999, xi[7]); |
| 361 | |
| 362 | // Set up minint64, maxint64 and some others. |
| 363 | long[] xl = new long[8]; |
| 364 | xl[0] = 0x8000000000000000L; |
| 365 | xl[1] = 0x7fffffffffffffffL; |
| 366 | xl[2] = 0x8000000000000001L; |
| 367 | xl[3] = -13; |
| 368 | xl[4] = -1; |
| 369 | xl[5] = 0; |
| 370 | xl[6] = 1; |
| 371 | xl[7] = 999; |
| 372 | doitLong(xl); |
| 373 | expectEquals64(0x8000000000000000L, xl[0]); |
| 374 | expectEquals64(0x7fffffffffffffffL, xl[1]); |
| 375 | expectEquals64(0x7fffffffffffffffL, xl[2]); |
| 376 | expectEquals64(13, xl[3]); |
| 377 | expectEquals64(1, xl[4]); |
| 378 | expectEquals64(0, xl[5]); |
| 379 | expectEquals64(1, xl[6]); |
| 380 | expectEquals64(999, xl[7]); |
| 381 | |
| 382 | // Set up float NaN and some others. |
| 383 | float[] xf = new float[16]; |
| 384 | xf[0] = Float.intBitsToFloat(0x7f800001); |
| 385 | xf[1] = Float.intBitsToFloat(0x7fa00000); |
| 386 | xf[2] = Float.intBitsToFloat(0x7fc00000); |
| 387 | xf[3] = Float.intBitsToFloat(0x7fffffff); |
| 388 | xf[4] = Float.intBitsToFloat(0xff800001); |
| 389 | xf[5] = Float.intBitsToFloat(0xffa00000); |
| 390 | xf[6] = Float.intBitsToFloat(0xffc00000); |
| 391 | xf[7] = Float.intBitsToFloat(0xffffffff); |
| 392 | xf[8] = Float.NEGATIVE_INFINITY; |
| 393 | xf[9] = -99.2f; |
| 394 | xf[10] = -1.0f; |
| 395 | xf[11] = -0.0f; |
| 396 | xf[12] = +0.0f; |
| 397 | xf[13] = +1.0f; |
| 398 | xf[14] = +99.2f; |
| 399 | xf[15] = Float.POSITIVE_INFINITY; |
| 400 | doitFloat(xf); |
| 401 | expectEqualsNaN32(0x7f800001, Float.floatToRawIntBits(xf[0])); |
| 402 | expectEqualsNaN32(0x7fa00000, Float.floatToRawIntBits(xf[1])); |
| 403 | expectEqualsNaN32(0x7fc00000, Float.floatToRawIntBits(xf[2])); |
| 404 | expectEqualsNaN32(0x7fffffff, Float.floatToRawIntBits(xf[3])); |
| 405 | expectEqualsNaN32(0x7f800001, Float.floatToRawIntBits(xf[4])); |
| 406 | expectEqualsNaN32(0x7fa00000, Float.floatToRawIntBits(xf[5])); |
| 407 | expectEqualsNaN32(0x7fc00000, Float.floatToRawIntBits(xf[6])); |
| 408 | expectEqualsNaN32(0x7fffffff, Float.floatToRawIntBits(xf[7])); |
| 409 | expectEquals32( |
| 410 | Float.floatToRawIntBits(Float.POSITIVE_INFINITY), |
| 411 | Float.floatToRawIntBits(xf[8])); |
| 412 | expectEquals32( |
| 413 | Float.floatToRawIntBits(99.2f), |
| 414 | Float.floatToRawIntBits(xf[9])); |
| 415 | expectEquals32( |
| 416 | Float.floatToRawIntBits(1.0f), |
| 417 | Float.floatToRawIntBits(xf[10])); |
| 418 | expectEquals32(0, Float.floatToRawIntBits(xf[11])); |
| 419 | expectEquals32(0, Float.floatToRawIntBits(xf[12])); |
| 420 | expectEquals32( |
| 421 | Float.floatToRawIntBits(1.0f), |
| 422 | Float.floatToRawIntBits(xf[13])); |
| 423 | expectEquals32( |
| 424 | Float.floatToRawIntBits(99.2f), |
| 425 | Float.floatToRawIntBits(xf[14])); |
| 426 | expectEquals32( |
| 427 | Float.floatToRawIntBits(Float.POSITIVE_INFINITY), |
| 428 | Float.floatToRawIntBits(xf[15])); |
| 429 | |
| 430 | // Set up double NaN and some others. |
| 431 | double[] xd = new double[16]; |
| 432 | xd[0] = Double.longBitsToDouble(0x7ff0000000000001L); |
| 433 | xd[1] = Double.longBitsToDouble(0x7ff4000000000000L); |
| 434 | xd[2] = Double.longBitsToDouble(0x7ff8000000000000L); |
| 435 | xd[3] = Double.longBitsToDouble(0x7fffffffffffffffL); |
| 436 | xd[4] = Double.longBitsToDouble(0xfff0000000000001L); |
| 437 | xd[5] = Double.longBitsToDouble(0xfff4000000000000L); |
| 438 | xd[6] = Double.longBitsToDouble(0xfff8000000000000L); |
| 439 | xd[7] = Double.longBitsToDouble(0xffffffffffffffffL); |
| 440 | xd[8] = Double.NEGATIVE_INFINITY; |
| 441 | xd[9] = -99.2f; |
| 442 | xd[10] = -1.0f; |
| 443 | xd[11] = -0.0f; |
| 444 | xd[12] = +0.0f; |
| 445 | xd[13] = +1.0f; |
| 446 | xd[14] = +99.2f; |
| 447 | xd[15] = Double.POSITIVE_INFINITY; |
| 448 | doitDouble(xd); |
| 449 | expectEqualsNaN64(0x7ff0000000000001L, Double.doubleToRawLongBits(xd[0])); |
| 450 | expectEqualsNaN64(0x7ff4000000000000L, Double.doubleToRawLongBits(xd[1])); |
| 451 | expectEqualsNaN64(0x7ff8000000000000L, Double.doubleToRawLongBits(xd[2])); |
| 452 | expectEqualsNaN64(0x7fffffffffffffffL, Double.doubleToRawLongBits(xd[3])); |
| 453 | expectEqualsNaN64(0x7ff0000000000001L, Double.doubleToRawLongBits(xd[4])); |
| 454 | expectEqualsNaN64(0x7ff4000000000000L, Double.doubleToRawLongBits(xd[5])); |
| 455 | expectEqualsNaN64(0x7ff8000000000000L, Double.doubleToRawLongBits(xd[6])); |
| 456 | expectEqualsNaN64(0x7fffffffffffffffL, Double.doubleToRawLongBits(xd[7])); |
| 457 | expectEquals64( |
| 458 | Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), |
| 459 | Double.doubleToRawLongBits(xd[8])); |
| 460 | expectEquals64( |
| 461 | Double.doubleToRawLongBits(99.2f), |
| 462 | Double.doubleToRawLongBits(xd[9])); |
| 463 | expectEquals64( |
| 464 | Double.doubleToRawLongBits(1.0f), |
| 465 | Double.doubleToRawLongBits(xd[10])); |
| 466 | expectEquals64(0, Double.doubleToRawLongBits(xd[11])); |
| 467 | expectEquals64(0, Double.doubleToRawLongBits(xd[12])); |
| 468 | expectEquals64( |
| 469 | Double.doubleToRawLongBits(1.0f), |
| 470 | Double.doubleToRawLongBits(xd[13])); |
| 471 | expectEquals64( |
| 472 | Double.doubleToRawLongBits(99.2f), |
| 473 | Double.doubleToRawLongBits(xd[14])); |
| 474 | expectEquals64( |
| 475 | Double.doubleToRawLongBits(Double.POSITIVE_INFINITY), |
| 476 | Double.doubleToRawLongBits(xd[15])); |
| 477 | |
| 478 | System.out.println("passed"); |
| 479 | } |
| 480 | |
| 481 | private static void expectEquals32(int expected, int result) { |
| 482 | if (expected != result) { |
| 483 | throw new Error("Expected: " + expected + ", found: " + result); |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | private static void expectEquals64(long expected, long result) { |
| 488 | if (expected != result) { |
| 489 | throw new Error("Expected: " + expected + ", found: " + result); |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | // We allow that an expected NaN result has become quiet. |
| 494 | private static void expectEqualsNaN32(int expected, int result) { |
| 495 | if (expected != result && (expected | SPQUIET) != result) { |
| 496 | throw new Error("Expected: 0x" + Integer.toHexString(expected) |
| 497 | + ", found: 0x" + Integer.toHexString(result)); |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | // We allow that an expected NaN result has become quiet. |
| 502 | private static void expectEqualsNaN64(long expected, long result) { |
| 503 | if (expected != result && (expected | DPQUIET) != result) { |
| 504 | throw new Error("Expected: 0x" + Long.toHexString(expected) |
| 505 | + ", found: 0x" + Long.toHexString(result)); |
| 506 | } |
| 507 | } |
| 508 | } |