Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1 | /* |
| 2 | * Optimizations for Tiny Code Generator for QEMU |
| 3 | * |
| 4 | * Copyright (c) 2010 Samsung Electronics. |
| 5 | * Contributed by Kirill Batuzov <batuzovk@ispras.ru> |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | * of this software and associated documentation files (the "Software"), to deal |
| 9 | * in the Software without restriction, including without limitation the rights |
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | * copies of the Software, and to permit persons to whom the Software is |
| 12 | * furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice shall be included in |
| 15 | * all copies or substantial portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 23 | * THE SOFTWARE. |
| 24 | */ |
| 25 | |
Peter Maydell | 757e725 | 2016-01-26 18:17:08 +0000 | [diff] [blame] | 26 | #include "qemu/osdep.h" |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 27 | #include "qemu-common.h" |
Paolo Bonzini | 00f6da6 | 2016-03-15 13:16:36 +0100 | [diff] [blame] | 28 | #include "exec/cpu-common.h" |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 29 | #include "tcg-op.h" |
| 30 | |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 31 | #define CASE_OP_32_64(x) \ |
| 32 | glue(glue(case INDEX_op_, x), _i32): \ |
| 33 | glue(glue(case INDEX_op_, x), _i64) |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 34 | |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 35 | struct tcg_temp_info { |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 36 | bool is_const; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 37 | uint16_t prev_copy; |
| 38 | uint16_t next_copy; |
| 39 | tcg_target_ulong val; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 40 | tcg_target_ulong mask; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 41 | }; |
| 42 | |
| 43 | static struct tcg_temp_info temps[TCG_MAX_TEMPS]; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 44 | static TCGTempSet temps_used; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 45 | |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 46 | static inline bool temp_is_const(TCGArg arg) |
| 47 | { |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 48 | return temps[arg].is_const; |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static inline bool temp_is_copy(TCGArg arg) |
| 52 | { |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 53 | return temps[arg].next_copy != arg; |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 54 | } |
| 55 | |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 56 | /* Reset TEMP's state, possibly removing the temp for the list of copies. */ |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 57 | static void reset_temp(TCGArg temp) |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 58 | { |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 59 | temps[temps[temp].next_copy].prev_copy = temps[temp].prev_copy; |
| 60 | temps[temps[temp].prev_copy].next_copy = temps[temp].next_copy; |
| 61 | temps[temp].next_copy = temp; |
| 62 | temps[temp].prev_copy = temp; |
| 63 | temps[temp].is_const = false; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 64 | temps[temp].mask = -1; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 65 | } |
| 66 | |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 67 | /* Reset all temporaries, given that there are NB_TEMPS of them. */ |
| 68 | static void reset_all_temps(int nb_temps) |
| 69 | { |
| 70 | bitmap_zero(temps_used.l, nb_temps); |
| 71 | } |
| 72 | |
| 73 | /* Initialize and activate a temporary. */ |
| 74 | static void init_temp_info(TCGArg temp) |
| 75 | { |
| 76 | if (!test_bit(temp, temps_used.l)) { |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 77 | temps[temp].next_copy = temp; |
| 78 | temps[temp].prev_copy = temp; |
| 79 | temps[temp].is_const = false; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 80 | temps[temp].mask = -1; |
| 81 | set_bit(temp, temps_used.l); |
| 82 | } |
| 83 | } |
| 84 | |
Blue Swirl | fe0de7a | 2011-07-30 19:18:32 +0000 | [diff] [blame] | 85 | static int op_bits(TCGOpcode op) |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 86 | { |
Richard Henderson | 8399ad5 | 2011-08-17 14:11:45 -0700 | [diff] [blame] | 87 | const TCGOpDef *def = &tcg_op_defs[op]; |
| 88 | return def->flags & TCG_OPF_64BIT ? 64 : 32; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 89 | } |
| 90 | |
Richard Henderson | a62f6f5 | 2014-05-22 10:59:12 -0700 | [diff] [blame] | 91 | static TCGOpcode op_to_mov(TCGOpcode op) |
| 92 | { |
| 93 | switch (op_bits(op)) { |
| 94 | case 32: |
| 95 | return INDEX_op_mov_i32; |
| 96 | case 64: |
| 97 | return INDEX_op_mov_i64; |
| 98 | default: |
| 99 | fprintf(stderr, "op_to_mov: unexpected return value of " |
| 100 | "function op_bits.\n"); |
| 101 | tcg_abort(); |
| 102 | } |
| 103 | } |
| 104 | |
Blue Swirl | fe0de7a | 2011-07-30 19:18:32 +0000 | [diff] [blame] | 105 | static TCGOpcode op_to_movi(TCGOpcode op) |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 106 | { |
| 107 | switch (op_bits(op)) { |
| 108 | case 32: |
| 109 | return INDEX_op_movi_i32; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 110 | case 64: |
| 111 | return INDEX_op_movi_i64; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 112 | default: |
| 113 | fprintf(stderr, "op_to_movi: unexpected return value of " |
| 114 | "function op_bits.\n"); |
| 115 | tcg_abort(); |
| 116 | } |
| 117 | } |
| 118 | |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 119 | static TCGArg find_better_copy(TCGContext *s, TCGArg arg) |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 120 | { |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 121 | TCGTemp *ts = arg_temp(arg); |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 122 | TCGArg i; |
| 123 | |
| 124 | /* If this is already a global, we can't do better. */ |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 125 | if (ts->temp_global) { |
| 126 | return arg; |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* Search for a global first. */ |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 130 | for (i = temps[arg].next_copy ; i != arg; i = temps[i].next_copy) { |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 131 | if (i < s->nb_globals) { |
| 132 | return i; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | /* If it is a temp, search for a temp local. */ |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 137 | if (!ts->temp_local) { |
| 138 | for (i = temps[arg].next_copy ; i != arg; i = temps[i].next_copy) { |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 139 | if (s->temps[i].temp_local) { |
| 140 | return i; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /* Failure to find a better representation, return the same temp. */ |
Richard Henderson | fa477d2 | 2016-11-02 11:20:15 -0600 | [diff] [blame^] | 146 | return arg; |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static bool temps_are_copies(TCGArg arg1, TCGArg arg2) |
| 150 | { |
| 151 | TCGArg i; |
| 152 | |
| 153 | if (arg1 == arg2) { |
| 154 | return true; |
| 155 | } |
| 156 | |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 157 | if (!temp_is_copy(arg1) || !temp_is_copy(arg2)) { |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 158 | return false; |
| 159 | } |
| 160 | |
| 161 | for (i = temps[arg1].next_copy ; i != arg1 ; i = temps[i].next_copy) { |
| 162 | if (i == arg2) { |
| 163 | return true; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | return false; |
| 168 | } |
| 169 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 170 | static void tcg_opt_gen_movi(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg val) |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 171 | { |
| 172 | TCGOpcode new_op = op_to_movi(op->opc); |
| 173 | tcg_target_ulong mask; |
| 174 | |
| 175 | op->opc = new_op; |
| 176 | |
| 177 | reset_temp(dst); |
Aurelien Jarno | b41059d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 178 | temps[dst].is_const = true; |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 179 | temps[dst].val = val; |
| 180 | mask = val; |
Aurelien Jarno | 9615212 | 2015-07-10 18:03:30 +0200 | [diff] [blame] | 181 | if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_movi_i32) { |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 182 | /* High bits of the destination are now garbage. */ |
| 183 | mask |= ~0xffffffffull; |
| 184 | } |
| 185 | temps[dst].mask = mask; |
| 186 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 187 | op->args[0] = dst; |
| 188 | op->args[1] = val; |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 189 | } |
| 190 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 191 | static void tcg_opt_gen_mov(TCGContext *s, TCGOp *op, TCGArg dst, TCGArg src) |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 192 | { |
Aurelien Jarno | 5365718 | 2015-06-04 21:53:25 +0200 | [diff] [blame] | 193 | if (temps_are_copies(dst, src)) { |
| 194 | tcg_op_remove(s, op); |
| 195 | return; |
| 196 | } |
| 197 | |
Aurelien Jarno | 8d6a916 | 2015-06-04 21:53:24 +0200 | [diff] [blame] | 198 | TCGOpcode new_op = op_to_mov(op->opc); |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 199 | tcg_target_ulong mask; |
Richard Henderson | a62f6f5 | 2014-05-22 10:59:12 -0700 | [diff] [blame] | 200 | |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 201 | op->opc = new_op; |
Richard Henderson | a62f6f5 | 2014-05-22 10:59:12 -0700 | [diff] [blame] | 202 | |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 203 | reset_temp(dst); |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 204 | mask = temps[src].mask; |
| 205 | if (TCG_TARGET_REG_BITS > 32 && new_op == INDEX_op_mov_i32) { |
| 206 | /* High bits of the destination are now garbage. */ |
| 207 | mask |= ~0xffffffffull; |
| 208 | } |
| 209 | temps[dst].mask = mask; |
| 210 | |
Richard Henderson | 4343913 | 2017-06-19 23:18:10 -0700 | [diff] [blame] | 211 | if (arg_temp(src)->type == arg_temp(dst)->type) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 212 | temps[dst].next_copy = temps[src].next_copy; |
| 213 | temps[dst].prev_copy = src; |
| 214 | temps[temps[dst].next_copy].prev_copy = dst; |
| 215 | temps[src].next_copy = dst; |
Aurelien Jarno | 299f801 | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 216 | temps[dst].is_const = temps[src].is_const; |
| 217 | temps[dst].val = temps[src].val; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 218 | } |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 219 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 220 | op->args[0] = dst; |
| 221 | op->args[1] = src; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 222 | } |
| 223 | |
Blue Swirl | fe0de7a | 2011-07-30 19:18:32 +0000 | [diff] [blame] | 224 | static TCGArg do_constant_folding_2(TCGOpcode op, TCGArg x, TCGArg y) |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 225 | { |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 226 | uint64_t l64, h64; |
| 227 | |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 228 | switch (op) { |
| 229 | CASE_OP_32_64(add): |
| 230 | return x + y; |
| 231 | |
| 232 | CASE_OP_32_64(sub): |
| 233 | return x - y; |
| 234 | |
| 235 | CASE_OP_32_64(mul): |
| 236 | return x * y; |
| 237 | |
Kirill Batuzov | 9a81090 | 2011-07-07 16:37:15 +0400 | [diff] [blame] | 238 | CASE_OP_32_64(and): |
| 239 | return x & y; |
| 240 | |
| 241 | CASE_OP_32_64(or): |
| 242 | return x | y; |
| 243 | |
| 244 | CASE_OP_32_64(xor): |
| 245 | return x ^ y; |
| 246 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 247 | case INDEX_op_shl_i32: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 248 | return (uint32_t)x << (y & 31); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 249 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 250 | case INDEX_op_shl_i64: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 251 | return (uint64_t)x << (y & 63); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 252 | |
| 253 | case INDEX_op_shr_i32: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 254 | return (uint32_t)x >> (y & 31); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 255 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 256 | case INDEX_op_shr_i64: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 257 | return (uint64_t)x >> (y & 63); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 258 | |
| 259 | case INDEX_op_sar_i32: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 260 | return (int32_t)x >> (y & 31); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 261 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 262 | case INDEX_op_sar_i64: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 263 | return (int64_t)x >> (y & 63); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 264 | |
| 265 | case INDEX_op_rotr_i32: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 266 | return ror32(x, y & 31); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 267 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 268 | case INDEX_op_rotr_i64: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 269 | return ror64(x, y & 63); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 270 | |
| 271 | case INDEX_op_rotl_i32: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 272 | return rol32(x, y & 31); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 273 | |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 274 | case INDEX_op_rotl_i64: |
Richard Henderson | 50c5c4d | 2014-03-18 07:45:39 -0700 | [diff] [blame] | 275 | return rol64(x, y & 63); |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 276 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 277 | CASE_OP_32_64(not): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 278 | return ~x; |
| 279 | |
Richard Henderson | cb25c80 | 2011-08-17 14:11:47 -0700 | [diff] [blame] | 280 | CASE_OP_32_64(neg): |
| 281 | return -x; |
| 282 | |
| 283 | CASE_OP_32_64(andc): |
| 284 | return x & ~y; |
| 285 | |
| 286 | CASE_OP_32_64(orc): |
| 287 | return x | ~y; |
| 288 | |
| 289 | CASE_OP_32_64(eqv): |
| 290 | return ~(x ^ y); |
| 291 | |
| 292 | CASE_OP_32_64(nand): |
| 293 | return ~(x & y); |
| 294 | |
| 295 | CASE_OP_32_64(nor): |
| 296 | return ~(x | y); |
| 297 | |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 298 | case INDEX_op_clz_i32: |
| 299 | return (uint32_t)x ? clz32(x) : y; |
| 300 | |
| 301 | case INDEX_op_clz_i64: |
| 302 | return x ? clz64(x) : y; |
| 303 | |
| 304 | case INDEX_op_ctz_i32: |
| 305 | return (uint32_t)x ? ctz32(x) : y; |
| 306 | |
| 307 | case INDEX_op_ctz_i64: |
| 308 | return x ? ctz64(x) : y; |
| 309 | |
Richard Henderson | a768e4e | 2016-11-21 11:13:39 +0100 | [diff] [blame] | 310 | case INDEX_op_ctpop_i32: |
| 311 | return ctpop32(x); |
| 312 | |
| 313 | case INDEX_op_ctpop_i64: |
| 314 | return ctpop64(x); |
| 315 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 316 | CASE_OP_32_64(ext8s): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 317 | return (int8_t)x; |
| 318 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 319 | CASE_OP_32_64(ext16s): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 320 | return (int16_t)x; |
| 321 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 322 | CASE_OP_32_64(ext8u): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 323 | return (uint8_t)x; |
| 324 | |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 325 | CASE_OP_32_64(ext16u): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 326 | return (uint16_t)x; |
| 327 | |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 328 | case INDEX_op_ext_i32_i64: |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 329 | case INDEX_op_ext32s_i64: |
| 330 | return (int32_t)x; |
| 331 | |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 332 | case INDEX_op_extu_i32_i64: |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 333 | case INDEX_op_extrl_i64_i32: |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 334 | case INDEX_op_ext32u_i64: |
| 335 | return (uint32_t)x; |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 336 | |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 337 | case INDEX_op_extrh_i64_i32: |
| 338 | return (uint64_t)x >> 32; |
| 339 | |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 340 | case INDEX_op_muluh_i32: |
| 341 | return ((uint64_t)(uint32_t)x * (uint32_t)y) >> 32; |
| 342 | case INDEX_op_mulsh_i32: |
| 343 | return ((int64_t)(int32_t)x * (int32_t)y) >> 32; |
| 344 | |
| 345 | case INDEX_op_muluh_i64: |
| 346 | mulu64(&l64, &h64, x, y); |
| 347 | return h64; |
| 348 | case INDEX_op_mulsh_i64: |
| 349 | muls64(&l64, &h64, x, y); |
| 350 | return h64; |
| 351 | |
Richard Henderson | 01547f7 | 2013-08-14 15:22:46 -0700 | [diff] [blame] | 352 | case INDEX_op_div_i32: |
| 353 | /* Avoid crashing on divide by zero, otherwise undefined. */ |
| 354 | return (int32_t)x / ((int32_t)y ? : 1); |
| 355 | case INDEX_op_divu_i32: |
| 356 | return (uint32_t)x / ((uint32_t)y ? : 1); |
| 357 | case INDEX_op_div_i64: |
| 358 | return (int64_t)x / ((int64_t)y ? : 1); |
| 359 | case INDEX_op_divu_i64: |
| 360 | return (uint64_t)x / ((uint64_t)y ? : 1); |
| 361 | |
| 362 | case INDEX_op_rem_i32: |
| 363 | return (int32_t)x % ((int32_t)y ? : 1); |
| 364 | case INDEX_op_remu_i32: |
| 365 | return (uint32_t)x % ((uint32_t)y ? : 1); |
| 366 | case INDEX_op_rem_i64: |
| 367 | return (int64_t)x % ((int64_t)y ? : 1); |
| 368 | case INDEX_op_remu_i64: |
| 369 | return (uint64_t)x % ((uint64_t)y ? : 1); |
| 370 | |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 371 | default: |
| 372 | fprintf(stderr, |
| 373 | "Unrecognized operation %d in do_constant_folding.\n", op); |
| 374 | tcg_abort(); |
| 375 | } |
| 376 | } |
| 377 | |
Blue Swirl | fe0de7a | 2011-07-30 19:18:32 +0000 | [diff] [blame] | 378 | static TCGArg do_constant_folding(TCGOpcode op, TCGArg x, TCGArg y) |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 379 | { |
| 380 | TCGArg res = do_constant_folding_2(op, x, y); |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 381 | if (op_bits(op) == 32) { |
Aurelien Jarno | 29f3ff8 | 2015-07-10 18:03:31 +0200 | [diff] [blame] | 382 | res = (int32_t)res; |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 383 | } |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 384 | return res; |
| 385 | } |
| 386 | |
Richard Henderson | 9519da7 | 2012-10-02 11:32:26 -0700 | [diff] [blame] | 387 | static bool do_constant_folding_cond_32(uint32_t x, uint32_t y, TCGCond c) |
| 388 | { |
| 389 | switch (c) { |
| 390 | case TCG_COND_EQ: |
| 391 | return x == y; |
| 392 | case TCG_COND_NE: |
| 393 | return x != y; |
| 394 | case TCG_COND_LT: |
| 395 | return (int32_t)x < (int32_t)y; |
| 396 | case TCG_COND_GE: |
| 397 | return (int32_t)x >= (int32_t)y; |
| 398 | case TCG_COND_LE: |
| 399 | return (int32_t)x <= (int32_t)y; |
| 400 | case TCG_COND_GT: |
| 401 | return (int32_t)x > (int32_t)y; |
| 402 | case TCG_COND_LTU: |
| 403 | return x < y; |
| 404 | case TCG_COND_GEU: |
| 405 | return x >= y; |
| 406 | case TCG_COND_LEU: |
| 407 | return x <= y; |
| 408 | case TCG_COND_GTU: |
| 409 | return x > y; |
| 410 | default: |
| 411 | tcg_abort(); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | static bool do_constant_folding_cond_64(uint64_t x, uint64_t y, TCGCond c) |
| 416 | { |
| 417 | switch (c) { |
| 418 | case TCG_COND_EQ: |
| 419 | return x == y; |
| 420 | case TCG_COND_NE: |
| 421 | return x != y; |
| 422 | case TCG_COND_LT: |
| 423 | return (int64_t)x < (int64_t)y; |
| 424 | case TCG_COND_GE: |
| 425 | return (int64_t)x >= (int64_t)y; |
| 426 | case TCG_COND_LE: |
| 427 | return (int64_t)x <= (int64_t)y; |
| 428 | case TCG_COND_GT: |
| 429 | return (int64_t)x > (int64_t)y; |
| 430 | case TCG_COND_LTU: |
| 431 | return x < y; |
| 432 | case TCG_COND_GEU: |
| 433 | return x >= y; |
| 434 | case TCG_COND_LEU: |
| 435 | return x <= y; |
| 436 | case TCG_COND_GTU: |
| 437 | return x > y; |
| 438 | default: |
| 439 | tcg_abort(); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | static bool do_constant_folding_cond_eq(TCGCond c) |
| 444 | { |
| 445 | switch (c) { |
| 446 | case TCG_COND_GT: |
| 447 | case TCG_COND_LTU: |
| 448 | case TCG_COND_LT: |
| 449 | case TCG_COND_GTU: |
| 450 | case TCG_COND_NE: |
| 451 | return 0; |
| 452 | case TCG_COND_GE: |
| 453 | case TCG_COND_GEU: |
| 454 | case TCG_COND_LE: |
| 455 | case TCG_COND_LEU: |
| 456 | case TCG_COND_EQ: |
| 457 | return 1; |
| 458 | default: |
| 459 | tcg_abort(); |
| 460 | } |
| 461 | } |
| 462 | |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 463 | /* Return 2 if the condition can't be simplified, and the result |
| 464 | of the condition (0 or 1) if it can */ |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 465 | static TCGArg do_constant_folding_cond(TCGOpcode op, TCGArg x, |
| 466 | TCGArg y, TCGCond c) |
| 467 | { |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 468 | if (temp_is_const(x) && temp_is_const(y)) { |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 469 | switch (op_bits(op)) { |
| 470 | case 32: |
Richard Henderson | 9519da7 | 2012-10-02 11:32:26 -0700 | [diff] [blame] | 471 | return do_constant_folding_cond_32(temps[x].val, temps[y].val, c); |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 472 | case 64: |
Richard Henderson | 9519da7 | 2012-10-02 11:32:26 -0700 | [diff] [blame] | 473 | return do_constant_folding_cond_64(temps[x].val, temps[y].val, c); |
| 474 | default: |
| 475 | tcg_abort(); |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 476 | } |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 477 | } else if (temps_are_copies(x, y)) { |
Richard Henderson | 9519da7 | 2012-10-02 11:32:26 -0700 | [diff] [blame] | 478 | return do_constant_folding_cond_eq(c); |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 479 | } else if (temp_is_const(y) && temps[y].val == 0) { |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 480 | switch (c) { |
| 481 | case TCG_COND_LTU: |
| 482 | return 0; |
| 483 | case TCG_COND_GEU: |
| 484 | return 1; |
| 485 | default: |
| 486 | return 2; |
| 487 | } |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 488 | } |
Alex Bennée | 550276a | 2016-09-30 22:30:55 +0100 | [diff] [blame] | 489 | return 2; |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 492 | /* Return 2 if the condition can't be simplified, and the result |
| 493 | of the condition (0 or 1) if it can */ |
| 494 | static TCGArg do_constant_folding_cond2(TCGArg *p1, TCGArg *p2, TCGCond c) |
| 495 | { |
| 496 | TCGArg al = p1[0], ah = p1[1]; |
| 497 | TCGArg bl = p2[0], bh = p2[1]; |
| 498 | |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 499 | if (temp_is_const(bl) && temp_is_const(bh)) { |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 500 | uint64_t b = ((uint64_t)temps[bh].val << 32) | (uint32_t)temps[bl].val; |
| 501 | |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 502 | if (temp_is_const(al) && temp_is_const(ah)) { |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 503 | uint64_t a; |
| 504 | a = ((uint64_t)temps[ah].val << 32) | (uint32_t)temps[al].val; |
| 505 | return do_constant_folding_cond_64(a, b, c); |
| 506 | } |
| 507 | if (b == 0) { |
| 508 | switch (c) { |
| 509 | case TCG_COND_LTU: |
| 510 | return 0; |
| 511 | case TCG_COND_GEU: |
| 512 | return 1; |
| 513 | default: |
| 514 | break; |
| 515 | } |
| 516 | } |
| 517 | } |
| 518 | if (temps_are_copies(al, bl) && temps_are_copies(ah, bh)) { |
| 519 | return do_constant_folding_cond_eq(c); |
| 520 | } |
| 521 | return 2; |
| 522 | } |
| 523 | |
Richard Henderson | 24c9ae4 | 2012-10-02 11:32:21 -0700 | [diff] [blame] | 524 | static bool swap_commutative(TCGArg dest, TCGArg *p1, TCGArg *p2) |
| 525 | { |
| 526 | TCGArg a1 = *p1, a2 = *p2; |
| 527 | int sum = 0; |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 528 | sum += temp_is_const(a1); |
| 529 | sum -= temp_is_const(a2); |
Richard Henderson | 24c9ae4 | 2012-10-02 11:32:21 -0700 | [diff] [blame] | 530 | |
| 531 | /* Prefer the constant in second argument, and then the form |
| 532 | op a, a, b, which is better handled on non-RISC hosts. */ |
| 533 | if (sum > 0 || (sum == 0 && dest == a2)) { |
| 534 | *p1 = a2; |
| 535 | *p2 = a1; |
| 536 | return true; |
| 537 | } |
| 538 | return false; |
| 539 | } |
| 540 | |
Richard Henderson | 0bfcb86 | 2012-10-02 11:32:23 -0700 | [diff] [blame] | 541 | static bool swap_commutative2(TCGArg *p1, TCGArg *p2) |
| 542 | { |
| 543 | int sum = 0; |
Aurelien Jarno | d9c769c | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 544 | sum += temp_is_const(p1[0]); |
| 545 | sum += temp_is_const(p1[1]); |
| 546 | sum -= temp_is_const(p2[0]); |
| 547 | sum -= temp_is_const(p2[1]); |
Richard Henderson | 0bfcb86 | 2012-10-02 11:32:23 -0700 | [diff] [blame] | 548 | if (sum > 0) { |
| 549 | TCGArg t; |
| 550 | t = p1[0], p1[0] = p2[0], p2[0] = t; |
| 551 | t = p1[1], p1[1] = p2[1], p2[1] = t; |
| 552 | return true; |
| 553 | } |
| 554 | return false; |
| 555 | } |
| 556 | |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 557 | /* Propagate constants and copies, fold constant expressions. */ |
Aurelien Jarno | 36e60ef | 2015-06-04 21:53:27 +0200 | [diff] [blame] | 558 | void tcg_optimize(TCGContext *s) |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 559 | { |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 560 | int oi, oi_next, nb_temps, nb_globals; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 561 | TCGOp *prev_mb = NULL; |
Richard Henderson | 5d8f536 | 2012-09-21 10:13:38 -0700 | [diff] [blame] | 562 | |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 563 | /* Array VALS has an element for each temp. |
| 564 | If this temp holds a constant then its value is kept in VALS' element. |
Aurelien Jarno | e590d4e | 2012-09-11 12:31:21 +0200 | [diff] [blame] | 565 | If this temp is a copy of other ones then the other copies are |
| 566 | available through the doubly linked circular list. */ |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 567 | |
| 568 | nb_temps = s->nb_temps; |
| 569 | nb_globals = s->nb_globals; |
Paolo Bonzini | d193a14 | 2013-01-11 15:42:51 -0800 | [diff] [blame] | 570 | reset_all_temps(nb_temps); |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 571 | |
Richard Henderson | dcb8e75 | 2016-06-22 19:42:31 -0700 | [diff] [blame] | 572 | for (oi = s->gen_op_buf[0].next; oi != 0; oi = oi_next) { |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 573 | tcg_target_ulong mask, partmask, affected; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 574 | int nb_oargs, nb_iargs, i; |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 575 | TCGArg tmp; |
| 576 | |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 577 | TCGOp * const op = &s->gen_op_buf[oi]; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 578 | TCGOpcode opc = op->opc; |
| 579 | const TCGOpDef *def = &tcg_op_defs[opc]; |
| 580 | |
| 581 | oi_next = op->next; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 582 | |
| 583 | /* Count the arguments, and initialize the temps that are |
| 584 | going to be used */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 585 | if (opc == INDEX_op_call) { |
| 586 | nb_oargs = op->callo; |
| 587 | nb_iargs = op->calli; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 588 | for (i = 0; i < nb_oargs + nb_iargs; i++) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 589 | tmp = op->args[i]; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 590 | if (tmp != TCG_CALL_DUMMY_ARG) { |
| 591 | init_temp_info(tmp); |
| 592 | } |
| 593 | } |
Aurelien Jarno | 1ff8c54 | 2012-09-11 16:18:49 +0200 | [diff] [blame] | 594 | } else { |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 595 | nb_oargs = def->nb_oargs; |
| 596 | nb_iargs = def->nb_iargs; |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 597 | for (i = 0; i < nb_oargs + nb_iargs; i++) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 598 | init_temp_info(op->args[i]); |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 599 | } |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 600 | } |
| 601 | |
| 602 | /* Do copy propagation */ |
| 603 | for (i = nb_oargs; i < nb_oargs + nb_iargs; i++) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 604 | if (temp_is_copy(op->args[i])) { |
| 605 | op->args[i] = find_better_copy(s, op->args[i]); |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 606 | } |
| 607 | } |
| 608 | |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 609 | /* For commutative operations make constant second argument */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 610 | switch (opc) { |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 611 | CASE_OP_32_64(add): |
| 612 | CASE_OP_32_64(mul): |
Kirill Batuzov | 9a81090 | 2011-07-07 16:37:15 +0400 | [diff] [blame] | 613 | CASE_OP_32_64(and): |
| 614 | CASE_OP_32_64(or): |
| 615 | CASE_OP_32_64(xor): |
Richard Henderson | cb25c80 | 2011-08-17 14:11:47 -0700 | [diff] [blame] | 616 | CASE_OP_32_64(eqv): |
| 617 | CASE_OP_32_64(nand): |
| 618 | CASE_OP_32_64(nor): |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 619 | CASE_OP_32_64(muluh): |
| 620 | CASE_OP_32_64(mulsh): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 621 | swap_commutative(op->args[0], &op->args[1], &op->args[2]); |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 622 | break; |
Aurelien Jarno | 65a7cce | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 623 | CASE_OP_32_64(brcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 624 | if (swap_commutative(-1, &op->args[0], &op->args[1])) { |
| 625 | op->args[2] = tcg_swap_cond(op->args[2]); |
Aurelien Jarno | 65a7cce | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 626 | } |
| 627 | break; |
| 628 | CASE_OP_32_64(setcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 629 | if (swap_commutative(op->args[0], &op->args[1], &op->args[2])) { |
| 630 | op->args[3] = tcg_swap_cond(op->args[3]); |
Aurelien Jarno | 65a7cce | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 631 | } |
| 632 | break; |
Richard Henderson | fa01a20 | 2012-09-21 10:13:37 -0700 | [diff] [blame] | 633 | CASE_OP_32_64(movcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 634 | if (swap_commutative(-1, &op->args[1], &op->args[2])) { |
| 635 | op->args[5] = tcg_swap_cond(op->args[5]); |
Richard Henderson | fa01a20 | 2012-09-21 10:13:37 -0700 | [diff] [blame] | 636 | } |
Richard Henderson | 5d8f536 | 2012-09-21 10:13:38 -0700 | [diff] [blame] | 637 | /* For movcond, we canonicalize the "false" input reg to match |
| 638 | the destination reg so that the tcg backend can implement |
| 639 | a "move if true" operation. */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 640 | if (swap_commutative(op->args[0], &op->args[4], &op->args[3])) { |
| 641 | op->args[5] = tcg_invert_cond(op->args[5]); |
Richard Henderson | 5d8f536 | 2012-09-21 10:13:38 -0700 | [diff] [blame] | 642 | } |
Richard Henderson | 1e484e6 | 2012-10-02 11:32:22 -0700 | [diff] [blame] | 643 | break; |
Richard Henderson | d7156f7 | 2013-02-19 23:51:52 -0800 | [diff] [blame] | 644 | CASE_OP_32_64(add2): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 645 | swap_commutative(op->args[0], &op->args[2], &op->args[4]); |
| 646 | swap_commutative(op->args[1], &op->args[3], &op->args[5]); |
Richard Henderson | 1e484e6 | 2012-10-02 11:32:22 -0700 | [diff] [blame] | 647 | break; |
Richard Henderson | d7156f7 | 2013-02-19 23:51:52 -0800 | [diff] [blame] | 648 | CASE_OP_32_64(mulu2): |
Richard Henderson | 4d3203f | 2013-02-19 23:51:53 -0800 | [diff] [blame] | 649 | CASE_OP_32_64(muls2): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 650 | swap_commutative(op->args[0], &op->args[2], &op->args[3]); |
Richard Henderson | 1414968 | 2012-10-02 11:32:30 -0700 | [diff] [blame] | 651 | break; |
Richard Henderson | 0bfcb86 | 2012-10-02 11:32:23 -0700 | [diff] [blame] | 652 | case INDEX_op_brcond2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 653 | if (swap_commutative2(&op->args[0], &op->args[2])) { |
| 654 | op->args[4] = tcg_swap_cond(op->args[4]); |
Richard Henderson | 0bfcb86 | 2012-10-02 11:32:23 -0700 | [diff] [blame] | 655 | } |
| 656 | break; |
| 657 | case INDEX_op_setcond2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 658 | if (swap_commutative2(&op->args[1], &op->args[3])) { |
| 659 | op->args[5] = tcg_swap_cond(op->args[5]); |
Richard Henderson | 0bfcb86 | 2012-10-02 11:32:23 -0700 | [diff] [blame] | 660 | } |
| 661 | break; |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 662 | default: |
| 663 | break; |
| 664 | } |
| 665 | |
Richard Henderson | 2d49754 | 2013-03-21 09:13:33 -0700 | [diff] [blame] | 666 | /* Simplify expressions for "shift/rot r, 0, a => movi r, 0", |
| 667 | and "sub r, 0, a => neg r, a" case. */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 668 | switch (opc) { |
Aurelien Jarno | 01ee528 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 669 | CASE_OP_32_64(shl): |
| 670 | CASE_OP_32_64(shr): |
| 671 | CASE_OP_32_64(sar): |
| 672 | CASE_OP_32_64(rotl): |
| 673 | CASE_OP_32_64(rotr): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 674 | if (temp_is_const(op->args[1]) && temps[op->args[1]].val == 0) { |
| 675 | tcg_opt_gen_movi(s, op, op->args[0], 0); |
Aurelien Jarno | 01ee528 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 676 | continue; |
| 677 | } |
| 678 | break; |
Richard Henderson | 2d49754 | 2013-03-21 09:13:33 -0700 | [diff] [blame] | 679 | CASE_OP_32_64(sub): |
| 680 | { |
| 681 | TCGOpcode neg_op; |
| 682 | bool have_neg; |
| 683 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 684 | if (temp_is_const(op->args[2])) { |
Richard Henderson | 2d49754 | 2013-03-21 09:13:33 -0700 | [diff] [blame] | 685 | /* Proceed with possible constant folding. */ |
| 686 | break; |
| 687 | } |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 688 | if (opc == INDEX_op_sub_i32) { |
Richard Henderson | 2d49754 | 2013-03-21 09:13:33 -0700 | [diff] [blame] | 689 | neg_op = INDEX_op_neg_i32; |
| 690 | have_neg = TCG_TARGET_HAS_neg_i32; |
| 691 | } else { |
| 692 | neg_op = INDEX_op_neg_i64; |
| 693 | have_neg = TCG_TARGET_HAS_neg_i64; |
| 694 | } |
| 695 | if (!have_neg) { |
| 696 | break; |
| 697 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 698 | if (temp_is_const(op->args[1]) |
| 699 | && temps[op->args[1]].val == 0) { |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 700 | op->opc = neg_op; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 701 | reset_temp(op->args[0]); |
| 702 | op->args[1] = op->args[2]; |
Richard Henderson | 2d49754 | 2013-03-21 09:13:33 -0700 | [diff] [blame] | 703 | continue; |
| 704 | } |
| 705 | } |
| 706 | break; |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 707 | CASE_OP_32_64(xor): |
| 708 | CASE_OP_32_64(nand): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 709 | if (!temp_is_const(op->args[1]) |
| 710 | && temp_is_const(op->args[2]) |
| 711 | && temps[op->args[2]].val == -1) { |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 712 | i = 1; |
| 713 | goto try_not; |
| 714 | } |
| 715 | break; |
| 716 | CASE_OP_32_64(nor): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 717 | if (!temp_is_const(op->args[1]) |
| 718 | && temp_is_const(op->args[2]) |
| 719 | && temps[op->args[2]].val == 0) { |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 720 | i = 1; |
| 721 | goto try_not; |
| 722 | } |
| 723 | break; |
| 724 | CASE_OP_32_64(andc): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 725 | if (!temp_is_const(op->args[2]) |
| 726 | && temp_is_const(op->args[1]) |
| 727 | && temps[op->args[1]].val == -1) { |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 728 | i = 2; |
| 729 | goto try_not; |
| 730 | } |
| 731 | break; |
| 732 | CASE_OP_32_64(orc): |
| 733 | CASE_OP_32_64(eqv): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 734 | if (!temp_is_const(op->args[2]) |
| 735 | && temp_is_const(op->args[1]) |
| 736 | && temps[op->args[1]].val == 0) { |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 737 | i = 2; |
| 738 | goto try_not; |
| 739 | } |
| 740 | break; |
| 741 | try_not: |
| 742 | { |
| 743 | TCGOpcode not_op; |
| 744 | bool have_not; |
| 745 | |
| 746 | if (def->flags & TCG_OPF_64BIT) { |
| 747 | not_op = INDEX_op_not_i64; |
| 748 | have_not = TCG_TARGET_HAS_not_i64; |
| 749 | } else { |
| 750 | not_op = INDEX_op_not_i32; |
| 751 | have_not = TCG_TARGET_HAS_not_i32; |
| 752 | } |
| 753 | if (!have_not) { |
| 754 | break; |
| 755 | } |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 756 | op->opc = not_op; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 757 | reset_temp(op->args[0]); |
| 758 | op->args[1] = op->args[i]; |
Richard Henderson | e201b56 | 2014-01-28 13:15:38 -0800 | [diff] [blame] | 759 | continue; |
| 760 | } |
Aurelien Jarno | 01ee528 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 761 | default: |
| 762 | break; |
| 763 | } |
| 764 | |
Richard Henderson | 464a144 | 2014-01-31 07:42:11 -0600 | [diff] [blame] | 765 | /* Simplify expression for "op r, a, const => mov r, a" cases */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 766 | switch (opc) { |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 767 | CASE_OP_32_64(add): |
| 768 | CASE_OP_32_64(sub): |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 769 | CASE_OP_32_64(shl): |
| 770 | CASE_OP_32_64(shr): |
| 771 | CASE_OP_32_64(sar): |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 772 | CASE_OP_32_64(rotl): |
| 773 | CASE_OP_32_64(rotr): |
Aurelien Jarno | 38ee188 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 774 | CASE_OP_32_64(or): |
| 775 | CASE_OP_32_64(xor): |
Richard Henderson | 464a144 | 2014-01-31 07:42:11 -0600 | [diff] [blame] | 776 | CASE_OP_32_64(andc): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 777 | if (!temp_is_const(op->args[1]) |
| 778 | && temp_is_const(op->args[2]) |
| 779 | && temps[op->args[2]].val == 0) { |
| 780 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 781 | continue; |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 782 | } |
| 783 | break; |
Richard Henderson | 464a144 | 2014-01-31 07:42:11 -0600 | [diff] [blame] | 784 | CASE_OP_32_64(and): |
| 785 | CASE_OP_32_64(orc): |
| 786 | CASE_OP_32_64(eqv): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 787 | if (!temp_is_const(op->args[1]) |
| 788 | && temp_is_const(op->args[2]) |
| 789 | && temps[op->args[2]].val == -1) { |
| 790 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 791 | continue; |
Richard Henderson | 464a144 | 2014-01-31 07:42:11 -0600 | [diff] [blame] | 792 | } |
| 793 | break; |
Aurelien Jarno | 56e4943 | 2012-09-06 16:47:13 +0200 | [diff] [blame] | 794 | default: |
| 795 | break; |
| 796 | } |
| 797 | |
Aurelien Jarno | 3031244 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 798 | /* Simplify using known-zero bits. Currently only ops with a single |
| 799 | output argument is supported. */ |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 800 | mask = -1; |
Paolo Bonzini | 633f650 | 2013-01-11 15:42:53 -0800 | [diff] [blame] | 801 | affected = -1; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 802 | switch (opc) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 803 | CASE_OP_32_64(ext8s): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 804 | if ((temps[op->args[1]].mask & 0x80) != 0) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 805 | break; |
| 806 | } |
| 807 | CASE_OP_32_64(ext8u): |
| 808 | mask = 0xff; |
| 809 | goto and_const; |
| 810 | CASE_OP_32_64(ext16s): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 811 | if ((temps[op->args[1]].mask & 0x8000) != 0) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 812 | break; |
| 813 | } |
| 814 | CASE_OP_32_64(ext16u): |
| 815 | mask = 0xffff; |
| 816 | goto and_const; |
| 817 | case INDEX_op_ext32s_i64: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 818 | if ((temps[op->args[1]].mask & 0x80000000) != 0) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 819 | break; |
| 820 | } |
| 821 | case INDEX_op_ext32u_i64: |
| 822 | mask = 0xffffffffU; |
| 823 | goto and_const; |
| 824 | |
| 825 | CASE_OP_32_64(and): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 826 | mask = temps[op->args[2]].mask; |
| 827 | if (temp_is_const(op->args[2])) { |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 828 | and_const: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 829 | affected = temps[op->args[1]].mask & ~mask; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 830 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 831 | mask = temps[op->args[1]].mask & mask; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 832 | break; |
| 833 | |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 834 | case INDEX_op_ext_i32_i64: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 835 | if ((temps[op->args[1]].mask & 0x80000000) != 0) { |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 836 | break; |
| 837 | } |
| 838 | case INDEX_op_extu_i32_i64: |
| 839 | /* We do not compute affected as it is a size changing op. */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 840 | mask = (uint32_t)temps[op->args[1]].mask; |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 841 | break; |
| 842 | |
Richard Henderson | 23ec69ed | 2014-01-28 12:03:24 -0800 | [diff] [blame] | 843 | CASE_OP_32_64(andc): |
| 844 | /* Known-zeros does not imply known-ones. Therefore unless |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 845 | op->args[2] is constant, we can't infer anything from it. */ |
| 846 | if (temp_is_const(op->args[2])) { |
| 847 | mask = ~temps[op->args[2]].mask; |
Richard Henderson | 23ec69ed | 2014-01-28 12:03:24 -0800 | [diff] [blame] | 848 | goto and_const; |
| 849 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 850 | /* But we certainly know nothing outside op->args[1] may be set. */ |
| 851 | mask = temps[op->args[1]].mask; |
Richard Henderson | 23ec69ed | 2014-01-28 12:03:24 -0800 | [diff] [blame] | 852 | break; |
| 853 | |
Aurelien Jarno | e46b225 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 854 | case INDEX_op_sar_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 855 | if (temp_is_const(op->args[2])) { |
| 856 | tmp = temps[op->args[2]].val & 31; |
| 857 | mask = (int32_t)temps[op->args[1]].mask >> tmp; |
Aurelien Jarno | e46b225 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 858 | } |
| 859 | break; |
| 860 | case INDEX_op_sar_i64: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 861 | if (temp_is_const(op->args[2])) { |
| 862 | tmp = temps[op->args[2]].val & 63; |
| 863 | mask = (int64_t)temps[op->args[1]].mask >> tmp; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 864 | } |
| 865 | break; |
| 866 | |
Aurelien Jarno | e46b225 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 867 | case INDEX_op_shr_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 868 | if (temp_is_const(op->args[2])) { |
| 869 | tmp = temps[op->args[2]].val & 31; |
| 870 | mask = (uint32_t)temps[op->args[1]].mask >> tmp; |
Aurelien Jarno | e46b225 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 871 | } |
| 872 | break; |
| 873 | case INDEX_op_shr_i64: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 874 | if (temp_is_const(op->args[2])) { |
| 875 | tmp = temps[op->args[2]].val & 63; |
| 876 | mask = (uint64_t)temps[op->args[1]].mask >> tmp; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 877 | } |
| 878 | break; |
| 879 | |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 880 | case INDEX_op_extrl_i64_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 881 | mask = (uint32_t)temps[op->args[1]].mask; |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 882 | break; |
| 883 | case INDEX_op_extrh_i64_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 884 | mask = (uint64_t)temps[op->args[1]].mask >> 32; |
Richard Henderson | 4bb7a41 | 2013-09-09 17:03:24 -0700 | [diff] [blame] | 885 | break; |
| 886 | |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 887 | CASE_OP_32_64(shl): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 888 | if (temp_is_const(op->args[2])) { |
| 889 | tmp = temps[op->args[2]].val & (TCG_TARGET_REG_BITS - 1); |
| 890 | mask = temps[op->args[1]].mask << tmp; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 891 | } |
| 892 | break; |
| 893 | |
| 894 | CASE_OP_32_64(neg): |
| 895 | /* Set to 1 all bits to the left of the rightmost. */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 896 | mask = -(temps[op->args[1]].mask & -temps[op->args[1]].mask); |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 897 | break; |
| 898 | |
| 899 | CASE_OP_32_64(deposit): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 900 | mask = deposit64(temps[op->args[1]].mask, op->args[3], |
| 901 | op->args[4], temps[op->args[2]].mask); |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 902 | break; |
| 903 | |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 904 | CASE_OP_32_64(extract): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 905 | mask = extract64(temps[op->args[1]].mask, op->args[2], op->args[3]); |
| 906 | if (op->args[2] == 0) { |
| 907 | affected = temps[op->args[1]].mask & ~mask; |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 908 | } |
| 909 | break; |
| 910 | CASE_OP_32_64(sextract): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 911 | mask = sextract64(temps[op->args[1]].mask, |
| 912 | op->args[2], op->args[3]); |
| 913 | if (op->args[2] == 0 && (tcg_target_long)mask >= 0) { |
| 914 | affected = temps[op->args[1]].mask & ~mask; |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 915 | } |
| 916 | break; |
| 917 | |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 918 | CASE_OP_32_64(or): |
| 919 | CASE_OP_32_64(xor): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 920 | mask = temps[op->args[1]].mask | temps[op->args[2]].mask; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 921 | break; |
| 922 | |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 923 | case INDEX_op_clz_i32: |
| 924 | case INDEX_op_ctz_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 925 | mask = temps[op->args[2]].mask | 31; |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 926 | break; |
| 927 | |
| 928 | case INDEX_op_clz_i64: |
| 929 | case INDEX_op_ctz_i64: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 930 | mask = temps[op->args[2]].mask | 63; |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 931 | break; |
| 932 | |
Richard Henderson | a768e4e | 2016-11-21 11:13:39 +0100 | [diff] [blame] | 933 | case INDEX_op_ctpop_i32: |
| 934 | mask = 32 | 31; |
| 935 | break; |
| 936 | case INDEX_op_ctpop_i64: |
| 937 | mask = 64 | 63; |
| 938 | break; |
| 939 | |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 940 | CASE_OP_32_64(setcond): |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 941 | case INDEX_op_setcond2_i32: |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 942 | mask = 1; |
| 943 | break; |
| 944 | |
| 945 | CASE_OP_32_64(movcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 946 | mask = temps[op->args[3]].mask | temps[op->args[4]].mask; |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 947 | break; |
| 948 | |
Aurelien Jarno | c8d7027 | 2013-09-03 08:27:39 +0200 | [diff] [blame] | 949 | CASE_OP_32_64(ld8u): |
Aurelien Jarno | c8d7027 | 2013-09-03 08:27:39 +0200 | [diff] [blame] | 950 | mask = 0xff; |
| 951 | break; |
| 952 | CASE_OP_32_64(ld16u): |
Aurelien Jarno | c8d7027 | 2013-09-03 08:27:39 +0200 | [diff] [blame] | 953 | mask = 0xffff; |
| 954 | break; |
| 955 | case INDEX_op_ld32u_i64: |
Aurelien Jarno | c8d7027 | 2013-09-03 08:27:39 +0200 | [diff] [blame] | 956 | mask = 0xffffffffu; |
| 957 | break; |
| 958 | |
| 959 | CASE_OP_32_64(qemu_ld): |
| 960 | { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 961 | TCGMemOpIdx oi = op->args[nb_oargs + nb_iargs]; |
Richard Henderson | 59227d5 | 2015-05-12 11:51:44 -0700 | [diff] [blame] | 962 | TCGMemOp mop = get_memop(oi); |
Aurelien Jarno | c8d7027 | 2013-09-03 08:27:39 +0200 | [diff] [blame] | 963 | if (!(mop & MO_SIGN)) { |
| 964 | mask = (2ULL << ((8 << (mop & MO_SIZE)) - 1)) - 1; |
| 965 | } |
| 966 | } |
| 967 | break; |
| 968 | |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 969 | default: |
| 970 | break; |
| 971 | } |
| 972 | |
Richard Henderson | bc8d688 | 2014-06-08 18:24:14 -0700 | [diff] [blame] | 973 | /* 32-bit ops generate 32-bit results. For the result is zero test |
| 974 | below, we can ignore high bits, but for further optimizations we |
| 975 | need to record that the high bits contain garbage. */ |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 976 | partmask = mask; |
Richard Henderson | bc8d688 | 2014-06-08 18:24:14 -0700 | [diff] [blame] | 977 | if (!(def->flags & TCG_OPF_64BIT)) { |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 978 | mask |= ~(tcg_target_ulong)0xffffffffu; |
| 979 | partmask &= 0xffffffffu; |
| 980 | affected &= 0xffffffffu; |
Aurelien Jarno | f096dc9 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 981 | } |
| 982 | |
Richard Henderson | 24666ba | 2014-05-22 11:14:10 -0700 | [diff] [blame] | 983 | if (partmask == 0) { |
Aurelien Jarno | eabb7b9 | 2016-04-21 10:48:49 +0200 | [diff] [blame] | 984 | tcg_debug_assert(nb_oargs == 1); |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 985 | tcg_opt_gen_movi(s, op, op->args[0], 0); |
Paolo Bonzini | 633f650 | 2013-01-11 15:42:53 -0800 | [diff] [blame] | 986 | continue; |
| 987 | } |
| 988 | if (affected == 0) { |
Aurelien Jarno | eabb7b9 | 2016-04-21 10:48:49 +0200 | [diff] [blame] | 989 | tcg_debug_assert(nb_oargs == 1); |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 990 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
Paolo Bonzini | 633f650 | 2013-01-11 15:42:53 -0800 | [diff] [blame] | 991 | continue; |
| 992 | } |
| 993 | |
Aurelien Jarno | 56e4943 | 2012-09-06 16:47:13 +0200 | [diff] [blame] | 994 | /* Simplify expression for "op r, a, 0 => movi r, 0" cases */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 995 | switch (opc) { |
Aurelien Jarno | 61251c0 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 996 | CASE_OP_32_64(and): |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 997 | CASE_OP_32_64(mul): |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 998 | CASE_OP_32_64(muluh): |
| 999 | CASE_OP_32_64(mulsh): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1000 | if ((temp_is_const(op->args[2]) && temps[op->args[2]].val == 0)) { |
| 1001 | tcg_opt_gen_movi(s, op, op->args[0], 0); |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 1002 | continue; |
| 1003 | } |
| 1004 | break; |
Aurelien Jarno | 56e4943 | 2012-09-06 16:47:13 +0200 | [diff] [blame] | 1005 | default: |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | /* Simplify expression for "op r, a, a => mov r, a" cases */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1010 | switch (opc) { |
Kirill Batuzov | 9a81090 | 2011-07-07 16:37:15 +0400 | [diff] [blame] | 1011 | CASE_OP_32_64(or): |
| 1012 | CASE_OP_32_64(and): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1013 | if (temps_are_copies(op->args[1], op->args[2])) { |
| 1014 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
Kirill Batuzov | 9a81090 | 2011-07-07 16:37:15 +0400 | [diff] [blame] | 1015 | continue; |
| 1016 | } |
| 1017 | break; |
Blue Swirl | fe0de7a | 2011-07-30 19:18:32 +0000 | [diff] [blame] | 1018 | default: |
| 1019 | break; |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 1020 | } |
| 1021 | |
Aurelien Jarno | 3c94193 | 2012-09-18 19:12:36 +0200 | [diff] [blame] | 1022 | /* Simplify expression for "op r, a, a => movi r, 0" cases */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1023 | switch (opc) { |
Richard Henderson | e64e958 | 2014-01-28 13:26:17 -0800 | [diff] [blame] | 1024 | CASE_OP_32_64(andc): |
Aurelien Jarno | 3c94193 | 2012-09-18 19:12:36 +0200 | [diff] [blame] | 1025 | CASE_OP_32_64(sub): |
| 1026 | CASE_OP_32_64(xor): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1027 | if (temps_are_copies(op->args[1], op->args[2])) { |
| 1028 | tcg_opt_gen_movi(s, op, op->args[0], 0); |
Aurelien Jarno | 3c94193 | 2012-09-18 19:12:36 +0200 | [diff] [blame] | 1029 | continue; |
| 1030 | } |
| 1031 | break; |
| 1032 | default: |
| 1033 | break; |
| 1034 | } |
| 1035 | |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1036 | /* Propagate constants through copy operations and do constant |
| 1037 | folding. Constants will be substituted to arguments by register |
| 1038 | allocator where needed and possible. Also detect copies. */ |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1039 | switch (opc) { |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1040 | CASE_OP_32_64(mov): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1041 | tcg_opt_gen_mov(s, op, op->args[0], op->args[1]); |
Aurelien Jarno | 97a79eb | 2015-06-05 11:19:18 +0200 | [diff] [blame] | 1042 | break; |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1043 | CASE_OP_32_64(movi): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1044 | tcg_opt_gen_movi(s, op, op->args[0], op->args[1]); |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1045 | break; |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1046 | |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 1047 | CASE_OP_32_64(not): |
Richard Henderson | cb25c80 | 2011-08-17 14:11:47 -0700 | [diff] [blame] | 1048 | CASE_OP_32_64(neg): |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 1049 | CASE_OP_32_64(ext8s): |
| 1050 | CASE_OP_32_64(ext8u): |
| 1051 | CASE_OP_32_64(ext16s): |
| 1052 | CASE_OP_32_64(ext16u): |
Richard Henderson | a768e4e | 2016-11-21 11:13:39 +0100 | [diff] [blame] | 1053 | CASE_OP_32_64(ctpop): |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 1054 | case INDEX_op_ext32s_i64: |
| 1055 | case INDEX_op_ext32u_i64: |
Aurelien Jarno | 8bcb5c8 | 2015-07-27 12:41:45 +0200 | [diff] [blame] | 1056 | case INDEX_op_ext_i32_i64: |
| 1057 | case INDEX_op_extu_i32_i64: |
Richard Henderson | 609ad70 | 2015-07-24 07:16:00 -0700 | [diff] [blame] | 1058 | case INDEX_op_extrl_i64_i32: |
| 1059 | case INDEX_op_extrh_i64_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1060 | if (temp_is_const(op->args[1])) { |
| 1061 | tmp = do_constant_folding(opc, temps[op->args[1]].val, 0); |
| 1062 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1063 | break; |
Kirill Batuzov | a640f03 | 2011-07-07 16:37:17 +0400 | [diff] [blame] | 1064 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1065 | goto do_default; |
| 1066 | |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 1067 | CASE_OP_32_64(add): |
| 1068 | CASE_OP_32_64(sub): |
| 1069 | CASE_OP_32_64(mul): |
Kirill Batuzov | 9a81090 | 2011-07-07 16:37:15 +0400 | [diff] [blame] | 1070 | CASE_OP_32_64(or): |
| 1071 | CASE_OP_32_64(and): |
| 1072 | CASE_OP_32_64(xor): |
Kirill Batuzov | 55c0975 | 2011-07-07 16:37:16 +0400 | [diff] [blame] | 1073 | CASE_OP_32_64(shl): |
| 1074 | CASE_OP_32_64(shr): |
| 1075 | CASE_OP_32_64(sar): |
Richard Henderson | 25c4d9c | 2011-08-17 14:11:46 -0700 | [diff] [blame] | 1076 | CASE_OP_32_64(rotl): |
| 1077 | CASE_OP_32_64(rotr): |
Richard Henderson | cb25c80 | 2011-08-17 14:11:47 -0700 | [diff] [blame] | 1078 | CASE_OP_32_64(andc): |
| 1079 | CASE_OP_32_64(orc): |
| 1080 | CASE_OP_32_64(eqv): |
| 1081 | CASE_OP_32_64(nand): |
| 1082 | CASE_OP_32_64(nor): |
Richard Henderson | 0327152 | 2013-08-14 14:35:56 -0700 | [diff] [blame] | 1083 | CASE_OP_32_64(muluh): |
| 1084 | CASE_OP_32_64(mulsh): |
Richard Henderson | 01547f7 | 2013-08-14 15:22:46 -0700 | [diff] [blame] | 1085 | CASE_OP_32_64(div): |
| 1086 | CASE_OP_32_64(divu): |
| 1087 | CASE_OP_32_64(rem): |
| 1088 | CASE_OP_32_64(remu): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1089 | if (temp_is_const(op->args[1]) && temp_is_const(op->args[2])) { |
| 1090 | tmp = do_constant_folding(opc, temps[op->args[1]].val, |
| 1091 | temps[op->args[2]].val); |
| 1092 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1093 | break; |
Kirill Batuzov | 53108fb | 2011-07-07 16:37:14 +0400 | [diff] [blame] | 1094 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1095 | goto do_default; |
| 1096 | |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 1097 | CASE_OP_32_64(clz): |
| 1098 | CASE_OP_32_64(ctz): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1099 | if (temp_is_const(op->args[1])) { |
| 1100 | TCGArg v = temps[op->args[1]].val; |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 1101 | if (v != 0) { |
| 1102 | tmp = do_constant_folding(opc, v, 0); |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1103 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 1104 | } else { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1105 | tcg_opt_gen_mov(s, op, op->args[0], op->args[2]); |
Richard Henderson | 0e28d00 | 2016-11-16 09:23:28 +0100 | [diff] [blame] | 1106 | } |
| 1107 | break; |
| 1108 | } |
| 1109 | goto do_default; |
| 1110 | |
Aurelien Jarno | 7ef55fc | 2012-09-21 11:07:29 +0200 | [diff] [blame] | 1111 | CASE_OP_32_64(deposit): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1112 | if (temp_is_const(op->args[1]) && temp_is_const(op->args[2])) { |
| 1113 | tmp = deposit64(temps[op->args[1]].val, op->args[3], |
| 1114 | op->args[4], temps[op->args[2]].val); |
| 1115 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1116 | break; |
Aurelien Jarno | 7ef55fc | 2012-09-21 11:07:29 +0200 | [diff] [blame] | 1117 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1118 | goto do_default; |
| 1119 | |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 1120 | CASE_OP_32_64(extract): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1121 | if (temp_is_const(op->args[1])) { |
| 1122 | tmp = extract64(temps[op->args[1]].val, |
| 1123 | op->args[2], op->args[3]); |
| 1124 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 1125 | break; |
| 1126 | } |
| 1127 | goto do_default; |
| 1128 | |
| 1129 | CASE_OP_32_64(sextract): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1130 | if (temp_is_const(op->args[1])) { |
| 1131 | tmp = sextract64(temps[op->args[1]].val, |
| 1132 | op->args[2], op->args[3]); |
| 1133 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 7ec8bab | 2016-10-14 12:04:32 -0500 | [diff] [blame] | 1134 | break; |
| 1135 | } |
| 1136 | goto do_default; |
| 1137 | |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1138 | CASE_OP_32_64(setcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1139 | tmp = do_constant_folding_cond(opc, op->args[1], |
| 1140 | op->args[2], op->args[3]); |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 1141 | if (tmp != 2) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1142 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1143 | break; |
Aurelien Jarno | f8dd19e | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1144 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1145 | goto do_default; |
| 1146 | |
Aurelien Jarno | fbeaa26 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1147 | CASE_OP_32_64(brcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1148 | tmp = do_constant_folding_cond(opc, op->args[0], |
| 1149 | op->args[1], op->args[2]); |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 1150 | if (tmp != 2) { |
| 1151 | if (tmp) { |
Paolo Bonzini | d193a14 | 2013-01-11 15:42:51 -0800 | [diff] [blame] | 1152 | reset_all_temps(nb_temps); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1153 | op->opc = INDEX_op_br; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1154 | op->args[0] = op->args[3]; |
Aurelien Jarno | fbeaa26 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1155 | } else { |
Richard Henderson | 0c627cd | 2014-03-30 16:51:54 -0700 | [diff] [blame] | 1156 | tcg_op_remove(s, op); |
Aurelien Jarno | fbeaa26 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1157 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1158 | break; |
Aurelien Jarno | fbeaa26 | 2012-09-06 16:47:14 +0200 | [diff] [blame] | 1159 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1160 | goto do_default; |
| 1161 | |
Richard Henderson | fa01a20 | 2012-09-21 10:13:37 -0700 | [diff] [blame] | 1162 | CASE_OP_32_64(movcond): |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1163 | tmp = do_constant_folding_cond(opc, op->args[1], |
| 1164 | op->args[2], op->args[5]); |
Aurelien Jarno | b336ceb | 2012-09-18 19:37:00 +0200 | [diff] [blame] | 1165 | if (tmp != 2) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1166 | tcg_opt_gen_mov(s, op, op->args[0], op->args[4-tmp]); |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1167 | break; |
Richard Henderson | fa01a20 | 2012-09-21 10:13:37 -0700 | [diff] [blame] | 1168 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1169 | if (temp_is_const(op->args[3]) && temp_is_const(op->args[4])) { |
| 1170 | tcg_target_ulong tv = temps[op->args[3]].val; |
| 1171 | tcg_target_ulong fv = temps[op->args[4]].val; |
| 1172 | TCGCond cond = op->args[5]; |
Richard Henderson | 333b21b | 2016-10-23 20:44:32 -0700 | [diff] [blame] | 1173 | if (fv == 1 && tv == 0) { |
| 1174 | cond = tcg_invert_cond(cond); |
| 1175 | } else if (!(tv == 1 && fv == 0)) { |
| 1176 | goto do_default; |
| 1177 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1178 | op->args[3] = cond; |
Richard Henderson | 333b21b | 2016-10-23 20:44:32 -0700 | [diff] [blame] | 1179 | op->opc = opc = (opc == INDEX_op_movcond_i32 |
| 1180 | ? INDEX_op_setcond_i32 |
| 1181 | : INDEX_op_setcond_i64); |
| 1182 | nb_iargs = 2; |
| 1183 | } |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1184 | goto do_default; |
| 1185 | |
Richard Henderson | 212c328 | 2012-10-02 11:32:28 -0700 | [diff] [blame] | 1186 | case INDEX_op_add2_i32: |
| 1187 | case INDEX_op_sub2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1188 | if (temp_is_const(op->args[2]) && temp_is_const(op->args[3]) |
| 1189 | && temp_is_const(op->args[4]) && temp_is_const(op->args[5])) { |
| 1190 | uint32_t al = temps[op->args[2]].val; |
| 1191 | uint32_t ah = temps[op->args[3]].val; |
| 1192 | uint32_t bl = temps[op->args[4]].val; |
| 1193 | uint32_t bh = temps[op->args[5]].val; |
Richard Henderson | 212c328 | 2012-10-02 11:32:28 -0700 | [diff] [blame] | 1194 | uint64_t a = ((uint64_t)ah << 32) | al; |
| 1195 | uint64_t b = ((uint64_t)bh << 32) | bl; |
| 1196 | TCGArg rl, rh; |
Richard Henderson | 5a18407 | 2016-06-23 20:34:33 -0700 | [diff] [blame] | 1197 | TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32, 2); |
Richard Henderson | 212c328 | 2012-10-02 11:32:28 -0700 | [diff] [blame] | 1198 | |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1199 | if (opc == INDEX_op_add2_i32) { |
Richard Henderson | 212c328 | 2012-10-02 11:32:28 -0700 | [diff] [blame] | 1200 | a += b; |
| 1201 | } else { |
| 1202 | a -= b; |
| 1203 | } |
| 1204 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1205 | rl = op->args[0]; |
| 1206 | rh = op->args[1]; |
| 1207 | tcg_opt_gen_movi(s, op, rl, (int32_t)a); |
| 1208 | tcg_opt_gen_movi(s, op2, rh, (int32_t)(a >> 32)); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1209 | |
| 1210 | /* We've done all we need to do with the movi. Skip it. */ |
| 1211 | oi_next = op2->next; |
Richard Henderson | 212c328 | 2012-10-02 11:32:28 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | } |
| 1214 | goto do_default; |
| 1215 | |
Richard Henderson | 1414968 | 2012-10-02 11:32:30 -0700 | [diff] [blame] | 1216 | case INDEX_op_mulu2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1217 | if (temp_is_const(op->args[2]) && temp_is_const(op->args[3])) { |
| 1218 | uint32_t a = temps[op->args[2]].val; |
| 1219 | uint32_t b = temps[op->args[3]].val; |
Richard Henderson | 1414968 | 2012-10-02 11:32:30 -0700 | [diff] [blame] | 1220 | uint64_t r = (uint64_t)a * b; |
| 1221 | TCGArg rl, rh; |
Richard Henderson | 5a18407 | 2016-06-23 20:34:33 -0700 | [diff] [blame] | 1222 | TCGOp *op2 = tcg_op_insert_before(s, op, INDEX_op_movi_i32, 2); |
Richard Henderson | 1414968 | 2012-10-02 11:32:30 -0700 | [diff] [blame] | 1223 | |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1224 | rl = op->args[0]; |
| 1225 | rh = op->args[1]; |
| 1226 | tcg_opt_gen_movi(s, op, rl, (int32_t)r); |
| 1227 | tcg_opt_gen_movi(s, op2, rh, (int32_t)(r >> 32)); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1228 | |
| 1229 | /* We've done all we need to do with the movi. Skip it. */ |
| 1230 | oi_next = op2->next; |
Richard Henderson | 1414968 | 2012-10-02 11:32:30 -0700 | [diff] [blame] | 1231 | break; |
| 1232 | } |
| 1233 | goto do_default; |
| 1234 | |
Richard Henderson | bc1473e | 2012-10-02 11:32:25 -0700 | [diff] [blame] | 1235 | case INDEX_op_brcond2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1236 | tmp = do_constant_folding_cond2(&op->args[0], &op->args[2], |
| 1237 | op->args[4]); |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1238 | if (tmp != 2) { |
| 1239 | if (tmp) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1240 | do_brcond_true: |
Paolo Bonzini | d193a14 | 2013-01-11 15:42:51 -0800 | [diff] [blame] | 1241 | reset_all_temps(nb_temps); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1242 | op->opc = INDEX_op_br; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1243 | op->args[0] = op->args[5]; |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1244 | } else { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1245 | do_brcond_false: |
Richard Henderson | 0c627cd | 2014-03-30 16:51:54 -0700 | [diff] [blame] | 1246 | tcg_op_remove(s, op); |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1247 | } |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1248 | } else if ((op->args[4] == TCG_COND_LT |
| 1249 | || op->args[4] == TCG_COND_GE) |
| 1250 | && temp_is_const(op->args[2]) |
| 1251 | && temps[op->args[2]].val == 0 |
| 1252 | && temp_is_const(op->args[3]) |
| 1253 | && temps[op->args[3]].val == 0) { |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1254 | /* Simplify LT/GE comparisons vs zero to a single compare |
| 1255 | vs the high word of the input. */ |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1256 | do_brcond_high: |
Paolo Bonzini | d193a14 | 2013-01-11 15:42:51 -0800 | [diff] [blame] | 1257 | reset_all_temps(nb_temps); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1258 | op->opc = INDEX_op_brcond_i32; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1259 | op->args[0] = op->args[1]; |
| 1260 | op->args[1] = op->args[3]; |
| 1261 | op->args[2] = op->args[4]; |
| 1262 | op->args[3] = op->args[5]; |
| 1263 | } else if (op->args[4] == TCG_COND_EQ) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1264 | /* Simplify EQ comparisons where one of the pairs |
| 1265 | can be simplified. */ |
| 1266 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1267 | op->args[0], op->args[2], |
| 1268 | TCG_COND_EQ); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1269 | if (tmp == 0) { |
| 1270 | goto do_brcond_false; |
| 1271 | } else if (tmp == 1) { |
| 1272 | goto do_brcond_high; |
| 1273 | } |
| 1274 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1275 | op->args[1], op->args[3], |
| 1276 | TCG_COND_EQ); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1277 | if (tmp == 0) { |
| 1278 | goto do_brcond_false; |
| 1279 | } else if (tmp != 1) { |
| 1280 | goto do_default; |
| 1281 | } |
| 1282 | do_brcond_low: |
| 1283 | reset_all_temps(nb_temps); |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1284 | op->opc = INDEX_op_brcond_i32; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1285 | op->args[1] = op->args[2]; |
| 1286 | op->args[2] = op->args[4]; |
| 1287 | op->args[3] = op->args[5]; |
| 1288 | } else if (op->args[4] == TCG_COND_NE) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1289 | /* Simplify NE comparisons where one of the pairs |
| 1290 | can be simplified. */ |
| 1291 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1292 | op->args[0], op->args[2], |
| 1293 | TCG_COND_NE); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1294 | if (tmp == 0) { |
| 1295 | goto do_brcond_high; |
| 1296 | } else if (tmp == 1) { |
| 1297 | goto do_brcond_true; |
| 1298 | } |
| 1299 | tmp = do_constant_folding_cond(INDEX_op_brcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1300 | op->args[1], op->args[3], |
| 1301 | TCG_COND_NE); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1302 | if (tmp == 0) { |
| 1303 | goto do_brcond_low; |
| 1304 | } else if (tmp == 1) { |
| 1305 | goto do_brcond_true; |
| 1306 | } |
| 1307 | goto do_default; |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1308 | } else { |
| 1309 | goto do_default; |
Richard Henderson | bc1473e | 2012-10-02 11:32:25 -0700 | [diff] [blame] | 1310 | } |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1311 | break; |
Richard Henderson | bc1473e | 2012-10-02 11:32:25 -0700 | [diff] [blame] | 1312 | |
| 1313 | case INDEX_op_setcond2_i32: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1314 | tmp = do_constant_folding_cond2(&op->args[1], &op->args[3], |
| 1315 | op->args[5]); |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1316 | if (tmp != 2) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1317 | do_setcond_const: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1318 | tcg_opt_gen_movi(s, op, op->args[0], tmp); |
| 1319 | } else if ((op->args[5] == TCG_COND_LT |
| 1320 | || op->args[5] == TCG_COND_GE) |
| 1321 | && temp_is_const(op->args[3]) |
| 1322 | && temps[op->args[3]].val == 0 |
| 1323 | && temp_is_const(op->args[4]) |
| 1324 | && temps[op->args[4]].val == 0) { |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1325 | /* Simplify LT/GE comparisons vs zero to a single compare |
| 1326 | vs the high word of the input. */ |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1327 | do_setcond_high: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1328 | reset_temp(op->args[0]); |
| 1329 | temps[op->args[0]].mask = 1; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1330 | op->opc = INDEX_op_setcond_i32; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1331 | op->args[1] = op->args[2]; |
| 1332 | op->args[2] = op->args[4]; |
| 1333 | op->args[3] = op->args[5]; |
| 1334 | } else if (op->args[5] == TCG_COND_EQ) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1335 | /* Simplify EQ comparisons where one of the pairs |
| 1336 | can be simplified. */ |
| 1337 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1338 | op->args[1], op->args[3], |
| 1339 | TCG_COND_EQ); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1340 | if (tmp == 0) { |
| 1341 | goto do_setcond_const; |
| 1342 | } else if (tmp == 1) { |
| 1343 | goto do_setcond_high; |
| 1344 | } |
| 1345 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1346 | op->args[2], op->args[4], |
| 1347 | TCG_COND_EQ); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1348 | if (tmp == 0) { |
| 1349 | goto do_setcond_high; |
| 1350 | } else if (tmp != 1) { |
| 1351 | goto do_default; |
| 1352 | } |
| 1353 | do_setcond_low: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1354 | reset_temp(op->args[0]); |
| 1355 | temps[op->args[0]].mask = 1; |
Richard Henderson | c45cb8b | 2014-09-19 13:49:15 -0700 | [diff] [blame] | 1356 | op->opc = INDEX_op_setcond_i32; |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1357 | op->args[2] = op->args[3]; |
| 1358 | op->args[3] = op->args[5]; |
| 1359 | } else if (op->args[5] == TCG_COND_NE) { |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1360 | /* Simplify NE comparisons where one of the pairs |
| 1361 | can be simplified. */ |
| 1362 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1363 | op->args[1], op->args[3], |
| 1364 | TCG_COND_NE); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1365 | if (tmp == 0) { |
| 1366 | goto do_setcond_high; |
| 1367 | } else if (tmp == 1) { |
| 1368 | goto do_setcond_const; |
| 1369 | } |
| 1370 | tmp = do_constant_folding_cond(INDEX_op_setcond_i32, |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1371 | op->args[2], op->args[4], |
| 1372 | TCG_COND_NE); |
Richard Henderson | a763551 | 2014-04-23 22:18:30 -0700 | [diff] [blame] | 1373 | if (tmp == 0) { |
| 1374 | goto do_setcond_low; |
| 1375 | } else if (tmp == 1) { |
| 1376 | goto do_setcond_const; |
| 1377 | } |
| 1378 | goto do_default; |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1379 | } else { |
| 1380 | goto do_default; |
Richard Henderson | bc1473e | 2012-10-02 11:32:25 -0700 | [diff] [blame] | 1381 | } |
Richard Henderson | 6c4382f | 2012-10-02 11:32:27 -0700 | [diff] [blame] | 1382 | break; |
Richard Henderson | bc1473e | 2012-10-02 11:32:25 -0700 | [diff] [blame] | 1383 | |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1384 | case INDEX_op_call: |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1385 | if (!(op->args[nb_oargs + nb_iargs + 1] |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 1386 | & (TCG_CALL_NO_READ_GLOBALS | TCG_CALL_NO_WRITE_GLOBALS))) { |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1387 | for (i = 0; i < nb_globals; i++) { |
Aurelien Jarno | 1208d7d | 2015-07-27 12:41:44 +0200 | [diff] [blame] | 1388 | if (test_bit(i, temps_used.l)) { |
| 1389 | reset_temp(i); |
| 1390 | } |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1391 | } |
| 1392 | } |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 1393 | goto do_reset_output; |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1394 | |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1395 | default: |
Richard Henderson | 6e14e91 | 2012-10-02 11:32:24 -0700 | [diff] [blame] | 1396 | do_default: |
| 1397 | /* Default case: we know nothing about operation (or were unable |
| 1398 | to compute the operation result) so no propagation is done. |
| 1399 | We trash everything if the operation is the end of a basic |
Paolo Bonzini | 3a9d8b1 | 2013-01-11 15:42:52 -0800 | [diff] [blame] | 1400 | block, otherwise we only trash the output args. "mask" is |
| 1401 | the non-zero bits mask for the first output arg. */ |
Aurelien Jarno | a255066 | 2012-09-19 21:40:30 +0200 | [diff] [blame] | 1402 | if (def->flags & TCG_OPF_BB_END) { |
Paolo Bonzini | d193a14 | 2013-01-11 15:42:51 -0800 | [diff] [blame] | 1403 | reset_all_temps(nb_temps); |
Aurelien Jarno | a255066 | 2012-09-19 21:40:30 +0200 | [diff] [blame] | 1404 | } else { |
Richard Henderson | cf06667 | 2014-03-22 20:06:52 -0700 | [diff] [blame] | 1405 | do_reset_output: |
| 1406 | for (i = 0; i < nb_oargs; i++) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1407 | reset_temp(op->args[i]); |
Aurelien Jarno | 3031244 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 1408 | /* Save the corresponding known-zero bits mask for the |
| 1409 | first output argument (only one supported so far). */ |
| 1410 | if (i == 0) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1411 | temps[op->args[i]].mask = mask; |
Aurelien Jarno | 3031244 | 2013-09-03 08:27:38 +0200 | [diff] [blame] | 1412 | } |
Aurelien Jarno | a255066 | 2012-09-19 21:40:30 +0200 | [diff] [blame] | 1413 | } |
Kirill Batuzov | 22613af | 2011-07-07 16:37:13 +0400 | [diff] [blame] | 1414 | } |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1415 | break; |
| 1416 | } |
Pranith Kumar | 34f9392 | 2016-08-23 09:48:25 -0400 | [diff] [blame] | 1417 | |
| 1418 | /* Eliminate duplicate and redundant fence instructions. */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1419 | if (prev_mb) { |
Pranith Kumar | 34f9392 | 2016-08-23 09:48:25 -0400 | [diff] [blame] | 1420 | switch (opc) { |
| 1421 | case INDEX_op_mb: |
| 1422 | /* Merge two barriers of the same type into one, |
| 1423 | * or a weaker barrier into a stronger one, |
| 1424 | * or two weaker barriers into a stronger one. |
| 1425 | * mb X; mb Y => mb X|Y |
| 1426 | * mb; strl => mb; st |
| 1427 | * ldaq; mb => ld; mb |
| 1428 | * ldaq; strl => ld; mb; st |
| 1429 | * Other combinations are also merged into a strong |
| 1430 | * barrier. This is stricter than specified but for |
| 1431 | * the purposes of TCG is better than not optimizing. |
| 1432 | */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1433 | prev_mb->args[0] |= op->args[0]; |
Pranith Kumar | 34f9392 | 2016-08-23 09:48:25 -0400 | [diff] [blame] | 1434 | tcg_op_remove(s, op); |
| 1435 | break; |
| 1436 | |
| 1437 | default: |
| 1438 | /* Opcodes that end the block stop the optimization. */ |
| 1439 | if ((def->flags & TCG_OPF_BB_END) == 0) { |
| 1440 | break; |
| 1441 | } |
| 1442 | /* fallthru */ |
| 1443 | case INDEX_op_qemu_ld_i32: |
| 1444 | case INDEX_op_qemu_ld_i64: |
| 1445 | case INDEX_op_qemu_st_i32: |
| 1446 | case INDEX_op_qemu_st_i64: |
| 1447 | case INDEX_op_call: |
| 1448 | /* Opcodes that touch guest memory stop the optimization. */ |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1449 | prev_mb = NULL; |
Pranith Kumar | 34f9392 | 2016-08-23 09:48:25 -0400 | [diff] [blame] | 1450 | break; |
| 1451 | } |
| 1452 | } else if (opc == INDEX_op_mb) { |
Richard Henderson | acd9370 | 2016-12-08 12:28:42 -0800 | [diff] [blame] | 1453 | prev_mb = op; |
Pranith Kumar | 34f9392 | 2016-08-23 09:48:25 -0400 | [diff] [blame] | 1454 | } |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1455 | } |
Kirill Batuzov | 8f2e8c0 | 2011-07-07 16:37:12 +0400 | [diff] [blame] | 1456 | } |