David Brazdil | fb50270 | 2016-02-02 10:09:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | public class Main { |
| 18 | |
| 19 | /// CHECK-START: int Main.BoolCond_IntVarVar(boolean, int, int) register (after) |
| 20 | /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] |
| 21 | |
| 22 | public static int BoolCond_IntVarVar(boolean cond, int x, int y) { |
| 23 | return cond ? x : y; |
| 24 | } |
| 25 | |
| 26 | /// CHECK-START: int Main.BoolCond_IntVarCst(boolean, int) register (after) |
| 27 | /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] |
| 28 | |
| 29 | public static int BoolCond_IntVarCst(boolean cond, int x) { |
| 30 | return cond ? x : 1; |
| 31 | } |
| 32 | |
| 33 | /// CHECK-START: int Main.BoolCond_IntCstVar(boolean, int) register (after) |
| 34 | /// CHECK: Select [{{i\d+}},{{i\d+}},{{z\d+}}] |
| 35 | |
| 36 | public static int BoolCond_IntCstVar(boolean cond, int y) { |
| 37 | return cond ? 1 : y; |
| 38 | } |
| 39 | |
| 40 | /// CHECK-START: float Main.BoolCond_FloatVarVar(boolean, float, float) register (after) |
| 41 | /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] |
| 42 | |
| 43 | public static float BoolCond_FloatVarVar(boolean cond, float x, float y) { |
| 44 | return cond ? x : y; |
| 45 | } |
| 46 | |
| 47 | /// CHECK-START: float Main.BoolCond_FloatVarCst(boolean, float) register (after) |
| 48 | /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] |
| 49 | |
| 50 | public static float BoolCond_FloatVarCst(boolean cond, float x) { |
| 51 | return cond ? x : 1.0f; |
| 52 | } |
| 53 | |
| 54 | /// CHECK-START: float Main.BoolCond_FloatCstVar(boolean, float) register (after) |
| 55 | /// CHECK: Select [{{f\d+}},{{f\d+}},{{z\d+}}] |
| 56 | |
| 57 | public static float BoolCond_FloatCstVar(boolean cond, float y) { |
| 58 | return cond ? 1.0f : y; |
| 59 | } |
| 60 | |
| 61 | /// CHECK-START: int Main.IntNonmatCond_IntVarVar(int, int, int, int) register (after) |
| 62 | /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] |
| 63 | /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] |
| 64 | |
| 65 | public static int IntNonmatCond_IntVarVar(int a, int b, int x, int y) { |
| 66 | return a > b ? x : y; |
| 67 | } |
| 68 | |
| 69 | /// CHECK-START: int Main.IntMatCond_IntVarVar(int, int, int, int) register (after) |
| 70 | /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{i\d+}},{{i\d+}}] |
| 71 | /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},{{z\d+}}] |
| 72 | /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] |
| 73 | |
| 74 | public static int IntMatCond_IntVarVar(int a, int b, int x, int y) { |
| 75 | int result = (a > b ? x : y); |
| 76 | return result + (a > b ? 0 : 1); |
| 77 | } |
| 78 | |
| 79 | /// CHECK-START: int Main.FloatLtNonmatCond_IntVarVar(float, float, int, int) register (after) |
| 80 | /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}] |
| 81 | /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] |
| 82 | |
| 83 | public static int FloatLtNonmatCond_IntVarVar(float a, float b, int x, int y) { |
| 84 | return a > b ? x : y; |
| 85 | } |
| 86 | |
| 87 | /// CHECK-START: int Main.FloatGtNonmatCond_IntVarVar(float, float, int, int) register (after) |
| 88 | /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] |
| 89 | /// CHECK-NEXT: Select [{{i\d+}},{{i\d+}},<<Cond>>] |
| 90 | |
| 91 | public static int FloatGtNonmatCond_IntVarVar(float a, float b, int x, int y) { |
| 92 | return a < b ? x : y; |
| 93 | } |
| 94 | |
| 95 | /// CHECK-START: float Main.FloatGtNonmatCond_FloatVarVar(float, float, float, float) register (after) |
| 96 | /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] |
| 97 | /// CHECK-NEXT: Select [{{f\d+}},{{f\d+}},<<Cond>>] |
| 98 | |
| 99 | public static float FloatGtNonmatCond_FloatVarVar(float a, float b, float x, float y) { |
| 100 | return a < b ? x : y; |
| 101 | } |
| 102 | |
| 103 | /// CHECK-START: int Main.FloatLtMatCond_IntVarVar(float, float, int, int) register (after) |
| 104 | /// CHECK: <<Cond:z\d+>> LessThanOrEqual [{{f\d+}},{{f\d+}}] |
| 105 | /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>] |
| 106 | /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] |
| 107 | |
| 108 | public static int FloatLtMatCond_IntVarVar(float a, float b, int x, int y) { |
| 109 | int result = (a > b ? x : y); |
| 110 | return result + (a > b ? 0 : 1); |
| 111 | } |
| 112 | |
| 113 | /// CHECK-START: int Main.FloatGtMatCond_IntVarVar(float, float, int, int) register (after) |
| 114 | /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual [{{f\d+}},{{f\d+}}] |
| 115 | /// CHECK-NEXT: <<Sel:i\d+>> Select [{{i\d+}},{{i\d+}},<<Cond>>] |
| 116 | /// CHECK-NEXT: Add [<<Cond>>,<<Sel>>] |
| 117 | |
| 118 | public static int FloatGtMatCond_IntVarVar(float a, float b, int x, int y) { |
| 119 | int result = (a < b ? x : y); |
| 120 | return result + (a < b ? 0 : 1); |
| 121 | } |
| 122 | |
| 123 | /// CHECK-START: float Main.FloatGtMatCond_FloatVarVar(float, float, float, float) register (after) |
| 124 | /// CHECK: <<Cond:z\d+>> GreaterThanOrEqual |
| 125 | /// CHECK-NEXT: <<Sel:f\d+>> Select [{{f\d+}},{{f\d+}},<<Cond>>] |
| 126 | /// CHECK-NEXT: TypeConversion [<<Cond>>] |
| 127 | |
| 128 | public static float FloatGtMatCond_FloatVarVar(float a, float b, float x, float y) { |
| 129 | float result = (a < b ? x : y); |
| 130 | return result + (a < b ? 0 : 1); |
| 131 | } |
| 132 | |
| 133 | public static void assertEqual(int expected, int actual) { |
| 134 | if (expected != actual) { |
| 135 | throw new Error("Assertion failed: " + expected + " != " + actual); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | public static void assertEqual(float expected, float actual) { |
| 140 | if (expected != actual) { |
| 141 | throw new Error("Assertion failed: " + expected + " != " + actual); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | public static void main(String[] args) { |
| 146 | assertEqual(5, BoolCond_IntVarVar(true, 5, 7)); |
| 147 | assertEqual(7, BoolCond_IntVarVar(false, 5, 7)); |
| 148 | assertEqual(5, BoolCond_IntVarCst(true, 5)); |
| 149 | assertEqual(1, BoolCond_IntVarCst(false, 5)); |
| 150 | assertEqual(1, BoolCond_IntCstVar(true, 7)); |
| 151 | assertEqual(7, BoolCond_IntCstVar(false, 7)); |
| 152 | |
| 153 | assertEqual(5, BoolCond_FloatVarVar(true, 5, 7)); |
| 154 | assertEqual(7, BoolCond_FloatVarVar(false, 5, 7)); |
| 155 | assertEqual(5, BoolCond_FloatVarCst(true, 5)); |
| 156 | assertEqual(1, BoolCond_FloatVarCst(false, 5)); |
| 157 | assertEqual(1, BoolCond_FloatCstVar(true, 7)); |
| 158 | assertEqual(7, BoolCond_FloatCstVar(false, 7)); |
| 159 | |
| 160 | assertEqual(5, IntNonmatCond_IntVarVar(3, 2, 5, 7)); |
| 161 | assertEqual(7, IntNonmatCond_IntVarVar(2, 3, 5, 7)); |
| 162 | assertEqual(5, IntMatCond_IntVarVar(3, 2, 5, 7)); |
| 163 | assertEqual(8, IntMatCond_IntVarVar(2, 3, 5, 7)); |
| 164 | |
| 165 | assertEqual(5, FloatLtNonmatCond_IntVarVar(3, 2, 5, 7)); |
| 166 | assertEqual(7, FloatLtNonmatCond_IntVarVar(2, 3, 5, 7)); |
| 167 | assertEqual(7, FloatLtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7)); |
| 168 | assertEqual(7, FloatLtNonmatCond_IntVarVar(2, Float.NaN, 5, 7)); |
| 169 | |
| 170 | assertEqual(5, FloatGtNonmatCond_IntVarVar(2, 3, 5, 7)); |
| 171 | assertEqual(7, FloatGtNonmatCond_IntVarVar(3, 2, 5, 7)); |
| 172 | assertEqual(7, FloatGtNonmatCond_IntVarVar(Float.NaN, 2, 5, 7)); |
| 173 | assertEqual(7, FloatGtNonmatCond_IntVarVar(2, Float.NaN, 5, 7)); |
| 174 | |
| 175 | assertEqual(5, FloatGtNonmatCond_FloatVarVar(2, 3, 5, 7)); |
| 176 | assertEqual(7, FloatGtNonmatCond_FloatVarVar(3, 2, 5, 7)); |
| 177 | assertEqual(7, FloatGtNonmatCond_FloatVarVar(Float.NaN, 2, 5, 7)); |
| 178 | assertEqual(7, FloatGtNonmatCond_FloatVarVar(2, Float.NaN, 5, 7)); |
| 179 | |
| 180 | assertEqual(5, FloatLtMatCond_IntVarVar(3, 2, 5, 7)); |
| 181 | assertEqual(8, FloatLtMatCond_IntVarVar(2, 3, 5, 7)); |
| 182 | assertEqual(8, FloatLtMatCond_IntVarVar(Float.NaN, 2, 5, 7)); |
| 183 | assertEqual(8, FloatLtMatCond_IntVarVar(2, Float.NaN, 5, 7)); |
| 184 | |
| 185 | assertEqual(5, FloatGtMatCond_IntVarVar(2, 3, 5, 7)); |
| 186 | assertEqual(8, FloatGtMatCond_IntVarVar(3, 2, 5, 7)); |
| 187 | assertEqual(8, FloatGtMatCond_IntVarVar(Float.NaN, 2, 5, 7)); |
| 188 | assertEqual(8, FloatGtMatCond_IntVarVar(2, Float.NaN, 5, 7)); |
| 189 | |
| 190 | assertEqual(5, FloatGtMatCond_FloatVarVar(2, 3, 5, 7)); |
| 191 | assertEqual(8, FloatGtMatCond_FloatVarVar(3, 2, 5, 7)); |
| 192 | assertEqual(8, FloatGtMatCond_FloatVarVar(Float.NaN, 2, 5, 7)); |
| 193 | assertEqual(8, FloatGtMatCond_FloatVarVar(2, Float.NaN, 5, 7)); |
| 194 | } |
| 195 | } |