Move cabs simplifications to match.pd
[gcc.git] / gcc / match.pd
1 /* Match-and-simplify patterns for shared GENERIC and GIMPLE folding.
2 This file is consumed by genmatch which produces gimple-match.c
3 and generic-match.c from it.
4
5 Copyright (C) 2014-2015 Free Software Foundation, Inc.
6 Contributed by Richard Biener <rguenther@suse.de>
7 and Prathamesh Kulkarni <bilbotheelffriend@gmail.com>
8
9 This file is part of GCC.
10
11 GCC is free software; you can redistribute it and/or modify it under
12 the terms of the GNU General Public License as published by the Free
13 Software Foundation; either version 3, or (at your option) any later
14 version.
15
16 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
17 WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
24
25
26 /* Generic tree predicates we inherit. */
27 (define_predicates
28 integer_onep integer_zerop integer_all_onesp integer_minus_onep
29 integer_each_onep integer_truep integer_nonzerop
30 real_zerop real_onep real_minus_onep
31 zerop
32 CONSTANT_CLASS_P
33 tree_expr_nonnegative_p
34 integer_pow2p
35 HONOR_NANS)
36
37 /* Operator lists. */
38 (define_operator_list tcc_comparison
39 lt le eq ne ge gt unordered ordered unlt unle ungt unge uneq ltgt)
40 (define_operator_list inverted_tcc_comparison
41 ge gt ne eq lt le ordered unordered ge gt le lt ltgt uneq)
42 (define_operator_list inverted_tcc_comparison_with_nans
43 unge ungt ne eq unlt unle ordered unordered ge gt le lt ltgt uneq)
44 (define_operator_list swapped_tcc_comparison
45 gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt)
46 (define_operator_list simple_comparison lt le eq ne ge gt)
47 (define_operator_list swapped_simple_comparison gt ge eq ne le lt)
48
49 (define_operator_list LOG BUILT_IN_LOGF BUILT_IN_LOG BUILT_IN_LOGL)
50 (define_operator_list EXP BUILT_IN_EXPF BUILT_IN_EXP BUILT_IN_EXPL)
51 (define_operator_list LOG2 BUILT_IN_LOG2F BUILT_IN_LOG2 BUILT_IN_LOG2L)
52 (define_operator_list EXP2 BUILT_IN_EXP2F BUILT_IN_EXP2 BUILT_IN_EXP2L)
53 (define_operator_list LOG10 BUILT_IN_LOG10F BUILT_IN_LOG10 BUILT_IN_LOG10L)
54 (define_operator_list EXP10 BUILT_IN_EXP10F BUILT_IN_EXP10 BUILT_IN_EXP10L)
55 (define_operator_list POW BUILT_IN_POWF BUILT_IN_POW BUILT_IN_POWL)
56 (define_operator_list POW10 BUILT_IN_POW10F BUILT_IN_POW10 BUILT_IN_POW10L)
57 (define_operator_list SQRT BUILT_IN_SQRTF BUILT_IN_SQRT BUILT_IN_SQRTL)
58 (define_operator_list CBRT BUILT_IN_CBRTF BUILT_IN_CBRT BUILT_IN_CBRTL)
59 (define_operator_list SIN BUILT_IN_SINF BUILT_IN_SIN BUILT_IN_SINL)
60 (define_operator_list COS BUILT_IN_COSF BUILT_IN_COS BUILT_IN_COSL)
61 (define_operator_list TAN BUILT_IN_TANF BUILT_IN_TAN BUILT_IN_TANL)
62 (define_operator_list COSH BUILT_IN_COSHF BUILT_IN_COSH BUILT_IN_COSHL)
63 (define_operator_list CEXPI BUILT_IN_CEXPIF BUILT_IN_CEXPI BUILT_IN_CEXPIL)
64 (define_operator_list CPROJ BUILT_IN_CPROJF BUILT_IN_CPROJ BUILT_IN_CPROJL)
65 (define_operator_list CCOS BUILT_IN_CCOSF BUILT_IN_CCOS BUILT_IN_CCOSL)
66 (define_operator_list CCOSH BUILT_IN_CCOSHF BUILT_IN_CCOSH BUILT_IN_CCOSHL)
67 (define_operator_list HYPOT BUILT_IN_HYPOTF BUILT_IN_HYPOT BUILT_IN_HYPOTL)
68 (define_operator_list COPYSIGN BUILT_IN_COPYSIGNF
69 BUILT_IN_COPYSIGN
70 BUILT_IN_COPYSIGNL)
71 (define_operator_list CABS BUILT_IN_CABSF BUILT_IN_CABS BUILT_IN_CABSL)
72
73 /* Simplifications of operations with one constant operand and
74 simplifications to constants or single values. */
75
76 (for op (plus pointer_plus minus bit_ior bit_xor)
77 (simplify
78 (op @0 integer_zerop)
79 (non_lvalue @0)))
80
81 /* 0 +p index -> (type)index */
82 (simplify
83 (pointer_plus integer_zerop @1)
84 (non_lvalue (convert @1)))
85
86 /* See if ARG1 is zero and X + ARG1 reduces to X.
87 Likewise if the operands are reversed. */
88 (simplify
89 (plus:c @0 real_zerop@1)
90 (if (fold_real_zero_addition_p (type, @1, 0))
91 (non_lvalue @0)))
92
93 /* See if ARG1 is zero and X - ARG1 reduces to X. */
94 (simplify
95 (minus @0 real_zerop@1)
96 (if (fold_real_zero_addition_p (type, @1, 1))
97 (non_lvalue @0)))
98
99 /* Simplify x - x.
100 This is unsafe for certain floats even in non-IEEE formats.
101 In IEEE, it is unsafe because it does wrong for NaNs.
102 Also note that operand_equal_p is always false if an operand
103 is volatile. */
104 (simplify
105 (minus @0 @0)
106 (if (!FLOAT_TYPE_P (type) || !HONOR_NANS (type))
107 { build_zero_cst (type); }))
108
109 (simplify
110 (mult @0 integer_zerop@1)
111 @1)
112
113 /* Maybe fold x * 0 to 0. The expressions aren't the same
114 when x is NaN, since x * 0 is also NaN. Nor are they the
115 same in modes with signed zeros, since multiplying a
116 negative value by 0 gives -0, not +0. */
117 (simplify
118 (mult @0 real_zerop@1)
119 (if (!HONOR_NANS (type) && !HONOR_SIGNED_ZEROS (type))
120 @1))
121
122 /* In IEEE floating point, x*1 is not equivalent to x for snans.
123 Likewise for complex arithmetic with signed zeros. */
124 (simplify
125 (mult @0 real_onep)
126 (if (!HONOR_SNANS (type)
127 && (!HONOR_SIGNED_ZEROS (type)
128 || !COMPLEX_FLOAT_TYPE_P (type)))
129 (non_lvalue @0)))
130
131 /* Transform x * -1.0 into -x. */
132 (simplify
133 (mult @0 real_minus_onep)
134 (if (!HONOR_SNANS (type)
135 && (!HONOR_SIGNED_ZEROS (type)
136 || !COMPLEX_FLOAT_TYPE_P (type)))
137 (negate @0)))
138
139 /* Make sure to preserve divisions by zero. This is the reason why
140 we don't simplify x / x to 1 or 0 / x to 0. */
141 (for op (mult trunc_div ceil_div floor_div round_div exact_div)
142 (simplify
143 (op @0 integer_onep)
144 (non_lvalue @0)))
145
146 /* X / -1 is -X. */
147 (for div (trunc_div ceil_div floor_div round_div exact_div)
148 (simplify
149 (div @0 integer_minus_onep@1)
150 (if (!TYPE_UNSIGNED (type))
151 (negate @0))))
152
153 /* For unsigned integral types, FLOOR_DIV_EXPR is the same as
154 TRUNC_DIV_EXPR. Rewrite into the latter in this case. */
155 (simplify
156 (floor_div @0 @1)
157 (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
158 && TYPE_UNSIGNED (type))
159 (trunc_div @0 @1)))
160
161 /* Combine two successive divisions. Note that combining ceil_div
162 and floor_div is trickier and combining round_div even more so. */
163 (for div (trunc_div exact_div)
164 (simplify
165 (div (div @0 INTEGER_CST@1) INTEGER_CST@2)
166 (with {
167 bool overflow_p;
168 wide_int mul = wi::mul (@1, @2, TYPE_SIGN (type), &overflow_p);
169 }
170 (if (!overflow_p)
171 (div @0 { wide_int_to_tree (type, mul); })
172 (if (TYPE_UNSIGNED (type)
173 || mul != wi::min_value (TYPE_PRECISION (type), SIGNED))
174 { build_zero_cst (type); })))))
175
176 /* Optimize A / A to 1.0 if we don't care about
177 NaNs or Infinities. */
178 (simplify
179 (rdiv @0 @0)
180 (if (FLOAT_TYPE_P (type)
181 && ! HONOR_NANS (type)
182 && ! HONOR_INFINITIES (type))
183 { build_one_cst (type); }))
184
185 /* Optimize -A / A to -1.0 if we don't care about
186 NaNs or Infinities. */
187 (simplify
188 (rdiv:c @0 (negate @0))
189 (if (FLOAT_TYPE_P (type)
190 && ! HONOR_NANS (type)
191 && ! HONOR_INFINITIES (type))
192 { build_minus_one_cst (type); }))
193
194 /* In IEEE floating point, x/1 is not equivalent to x for snans. */
195 (simplify
196 (rdiv @0 real_onep)
197 (if (!HONOR_SNANS (type))
198 (non_lvalue @0)))
199
200 /* In IEEE floating point, x/-1 is not equivalent to -x for snans. */
201 (simplify
202 (rdiv @0 real_minus_onep)
203 (if (!HONOR_SNANS (type))
204 (negate @0)))
205
206 /* If ARG1 is a constant, we can convert this to a multiply by the
207 reciprocal. This does not have the same rounding properties,
208 so only do this if -freciprocal-math. We can actually
209 always safely do it if ARG1 is a power of two, but it's hard to
210 tell if it is or not in a portable manner. */
211 (for cst (REAL_CST COMPLEX_CST VECTOR_CST)
212 (simplify
213 (rdiv @0 cst@1)
214 (if (optimize)
215 (if (flag_reciprocal_math
216 && !real_zerop (@1))
217 (with
218 { tree tem = const_binop (RDIV_EXPR, type, build_one_cst (type), @1); }
219 (if (tem)
220 (mult @0 { tem; } )))
221 (if (cst != COMPLEX_CST)
222 (with { tree inverse = exact_inverse (type, @1); }
223 (if (inverse)
224 (mult @0 { inverse; } ))))))))
225
226 /* Same applies to modulo operations, but fold is inconsistent here
227 and simplifies 0 % x to 0, only preserving literal 0 % 0. */
228 (for mod (ceil_mod floor_mod round_mod trunc_mod)
229 /* 0 % X is always zero. */
230 (simplify
231 (mod integer_zerop@0 @1)
232 /* But not for 0 % 0 so that we can get the proper warnings and errors. */
233 (if (!integer_zerop (@1))
234 @0))
235 /* X % 1 is always zero. */
236 (simplify
237 (mod @0 integer_onep)
238 { build_zero_cst (type); })
239 /* X % -1 is zero. */
240 (simplify
241 (mod @0 integer_minus_onep@1)
242 (if (!TYPE_UNSIGNED (type))
243 { build_zero_cst (type); }))
244 /* (X % Y) % Y is just X % Y. */
245 (simplify
246 (mod (mod@2 @0 @1) @1)
247 @2)
248 /* From extract_muldiv_1: (X * C1) % C2 is zero if C1 is a multiple of C2. */
249 (simplify
250 (mod (mult @0 INTEGER_CST@1) INTEGER_CST@2)
251 (if (ANY_INTEGRAL_TYPE_P (type)
252 && TYPE_OVERFLOW_UNDEFINED (type)
253 && wi::multiple_of_p (@1, @2, TYPE_SIGN (type)))
254 { build_zero_cst (type); })))
255
256 /* X % -C is the same as X % C. */
257 (simplify
258 (trunc_mod @0 INTEGER_CST@1)
259 (if (TYPE_SIGN (type) == SIGNED
260 && !TREE_OVERFLOW (@1)
261 && wi::neg_p (@1)
262 && !TYPE_OVERFLOW_TRAPS (type)
263 /* Avoid this transformation if C is INT_MIN, i.e. C == -C. */
264 && !sign_bit_p (@1, @1))
265 (trunc_mod @0 (negate @1))))
266
267 /* X % -Y is the same as X % Y. */
268 (simplify
269 (trunc_mod @0 (convert? (negate @1)))
270 (if (!TYPE_UNSIGNED (type)
271 && !TYPE_OVERFLOW_TRAPS (type)
272 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
273 (trunc_mod @0 (convert @1))))
274
275 /* X - (X / Y) * Y is the same as X % Y. */
276 (simplify
277 (minus (convert1? @0) (convert2? (mult (trunc_div @0 @1) @1)))
278 (if ((INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type))
279 && TYPE_UNSIGNED (TREE_TYPE (@0)) == TYPE_UNSIGNED (type))
280 (trunc_mod (convert @0) (convert @1))))
281
282 /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR,
283 i.e. "X % C" into "X & (C - 1)", if X and C are positive.
284 Also optimize A % (C << N) where C is a power of 2,
285 to A & ((C << N) - 1). */
286 (match (power_of_two_cand @1)
287 INTEGER_CST@1)
288 (match (power_of_two_cand @1)
289 (lshift INTEGER_CST@1 @2))
290 (for mod (trunc_mod floor_mod)
291 (simplify
292 (mod @0 (convert?@3 (power_of_two_cand@1 @2)))
293 (if ((TYPE_UNSIGNED (type)
294 || tree_expr_nonnegative_p (@0))
295 && tree_nop_conversion_p (type, TREE_TYPE (@3))
296 && integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
297 (bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
298
299 /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */
300 (simplify
301 (trunc_div (mult @0 integer_pow2p@1) @1)
302 (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
303 (bit_and @0 { wide_int_to_tree
304 (type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1),
305 false, TYPE_PRECISION (type))); })))
306
307 /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */
308 (simplify
309 (mult (trunc_div @0 integer_pow2p@1) @1)
310 (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
311 (bit_and @0 (negate @1))))
312
313 /* Simplify (t * 2) / 2) -> t. */
314 (for div (trunc_div ceil_div floor_div round_div exact_div)
315 (simplify
316 (div (mult @0 @1) @1)
317 (if (ANY_INTEGRAL_TYPE_P (type)
318 && TYPE_OVERFLOW_UNDEFINED (type))
319 @0)))
320
321 (for op (negate abs)
322 /* Simplify cos(-x) and cos(|x|) -> cos(x). Similarly for cosh. */
323 (for coss (COS COSH)
324 (simplify
325 (coss (op @0))
326 (coss @0)))
327 /* Simplify pow(-x, y) and pow(|x|,y) -> pow(x,y) if y is an even integer. */
328 (for pows (POW)
329 (simplify
330 (pows (op @0) REAL_CST@1)
331 (with { HOST_WIDE_INT n; }
332 (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0)
333 (pows @0 @1)))))
334 /* Strip negate and abs from both operands of hypot. */
335 (for hypots (HYPOT)
336 (simplify
337 (hypots (op @0) @1)
338 (hypots @0 @1))
339 (simplify
340 (hypots @0 (op @1))
341 (hypots @0 @1)))
342 /* copysign(-x, y) and copysign(abs(x), y) -> copysign(x, y). */
343 (for copysigns (COPYSIGN)
344 (simplify
345 (copysigns (op @0) @1)
346 (copysigns @0 @1))))
347
348 /* abs(x)*abs(x) -> x*x. Should be valid for all types. */
349 (simplify
350 (mult (abs@1 @0) @1)
351 (mult @0 @0))
352
353 /* cos(copysign(x, y)) -> cos(x). Similarly for cosh. */
354 (for coss (COS COSH)
355 copysigns (COPYSIGN)
356 (simplify
357 (coss (copysigns @0 @1))
358 (coss @0)))
359
360 /* pow(copysign(x, y), z) -> pow(x, z) if z is an even integer. */
361 (for pows (POW)
362 copysigns (COPYSIGN)
363 (simplify
364 (pows (copysigns @0 @1) REAL_CST@1)
365 (with { HOST_WIDE_INT n; }
366 (if (real_isinteger (&TREE_REAL_CST (@1), &n) && (n & 1) == 0)
367 (pows @0 @1)))))
368
369 (for hypots (HYPOT)
370 copysigns (COPYSIGN)
371 /* hypot(copysign(x, y), z) -> hypot(x, z). */
372 (simplify
373 (hypots (copysigns @0 @1) @2)
374 (hypots @0 @2))
375 /* hypot(x, copysign(y, z)) -> hypot(x, y). */
376 (simplify
377 (hypots @0 (copysigns @1 @2))
378 (hypots @0 @1)))
379
380 /* copysign(copysign(x, y), z) -> copysign(x, z). */
381 (for copysigns (COPYSIGN)
382 (simplify
383 (copysigns (copysigns @0 @1) @2)
384 (copysigns @0 @2)))
385
386 /* copysign(x,y)*copysign(x,y) -> x*x. */
387 (for copysigns (COPYSIGN)
388 (simplify
389 (mult (copysigns@2 @0 @1) @2)
390 (mult @0 @0)))
391
392 /* ccos(-x) -> ccos(x). Similarly for ccosh. */
393 (for ccoss (CCOS CCOSH)
394 (simplify
395 (ccoss (negate @0))
396 (ccoss @0)))
397
398 /* cabs(-x) and cos(conj(x)) -> cabs(x). */
399 (for ops (conj negate)
400 (for cabss (CABS)
401 (simplify
402 (cabss (ops @0))
403 (cabss @0))))
404
405 /* Fold (a * (1 << b)) into (a << b) */
406 (simplify
407 (mult:c @0 (convert? (lshift integer_onep@1 @2)))
408 (if (! FLOAT_TYPE_P (type)
409 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
410 (lshift @0 @2)))
411
412 /* Fold (C1/X)*C2 into (C1*C2)/X. */
413 (simplify
414 (mult (rdiv:s REAL_CST@0 @1) REAL_CST@2)
415 (if (flag_associative_math)
416 (with
417 { tree tem = const_binop (MULT_EXPR, type, @0, @2); }
418 (if (tem)
419 (rdiv { tem; } @1)))))
420
421 /* Simplify ~X & X as zero. */
422 (simplify
423 (bit_and:c (convert? @0) (convert? (bit_not @0)))
424 { build_zero_cst (type); })
425
426 /* X % Y is smaller than Y. */
427 (for cmp (lt ge)
428 (simplify
429 (cmp (trunc_mod @0 @1) @1)
430 (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
431 { constant_boolean_node (cmp == LT_EXPR, type); })))
432 (for cmp (gt le)
433 (simplify
434 (cmp @1 (trunc_mod @0 @1))
435 (if (TYPE_UNSIGNED (TREE_TYPE (@0)))
436 { constant_boolean_node (cmp == GT_EXPR, type); })))
437
438 /* x | ~0 -> ~0 */
439 (simplify
440 (bit_ior @0 integer_all_onesp@1)
441 @1)
442
443 /* x & 0 -> 0 */
444 (simplify
445 (bit_and @0 integer_zerop@1)
446 @1)
447
448 /* ~x | x -> -1 */
449 /* ~x ^ x -> -1 */
450 /* ~x + x -> -1 */
451 (for op (bit_ior bit_xor plus)
452 (simplify
453 (op:c (convert? @0) (convert? (bit_not @0)))
454 (convert { build_all_ones_cst (TREE_TYPE (@0)); })))
455
456 /* x ^ x -> 0 */
457 (simplify
458 (bit_xor @0 @0)
459 { build_zero_cst (type); })
460
461 /* Canonicalize X ^ ~0 to ~X. */
462 (simplify
463 (bit_xor @0 integer_all_onesp@1)
464 (bit_not @0))
465
466 /* x & ~0 -> x */
467 (simplify
468 (bit_and @0 integer_all_onesp)
469 (non_lvalue @0))
470
471 /* x & x -> x, x | x -> x */
472 (for bitop (bit_and bit_ior)
473 (simplify
474 (bitop @0 @0)
475 (non_lvalue @0)))
476
477 /* x + (x & 1) -> (x + 1) & ~1 */
478 (simplify
479 (plus:c @0 (bit_and:s @0 integer_onep@1))
480 (bit_and (plus @0 @1) (bit_not @1)))
481
482 /* x & ~(x & y) -> x & ~y */
483 /* x | ~(x | y) -> x | ~y */
484 (for bitop (bit_and bit_ior)
485 (simplify
486 (bitop:c @0 (bit_not (bitop:cs @0 @1)))
487 (bitop @0 (bit_not @1))))
488
489 /* (x | y) & ~x -> y & ~x */
490 /* (x & y) | ~x -> y | ~x */
491 (for bitop (bit_and bit_ior)
492 rbitop (bit_ior bit_and)
493 (simplify
494 (bitop:c (rbitop:c @0 @1) (bit_not@2 @0))
495 (bitop @1 @2)))
496
497 /* (x & y) ^ (x | y) -> x ^ y */
498 (simplify
499 (bit_xor:c (bit_and @0 @1) (bit_ior @0 @1))
500 (bit_xor @0 @1))
501
502 /* (x ^ y) ^ (x | y) -> x & y */
503 (simplify
504 (bit_xor:c (bit_xor @0 @1) (bit_ior @0 @1))
505 (bit_and @0 @1))
506
507 /* (x & y) + (x ^ y) -> x | y */
508 /* (x & y) | (x ^ y) -> x | y */
509 /* (x & y) ^ (x ^ y) -> x | y */
510 (for op (plus bit_ior bit_xor)
511 (simplify
512 (op:c (bit_and @0 @1) (bit_xor @0 @1))
513 (bit_ior @0 @1)))
514
515 /* (x & y) + (x | y) -> x + y */
516 (simplify
517 (plus:c (bit_and @0 @1) (bit_ior @0 @1))
518 (plus @0 @1))
519
520 /* (x + y) - (x | y) -> x & y */
521 (simplify
522 (minus (plus @0 @1) (bit_ior @0 @1))
523 (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
524 && !TYPE_SATURATING (type))
525 (bit_and @0 @1)))
526
527 /* (x + y) - (x & y) -> x | y */
528 (simplify
529 (minus (plus @0 @1) (bit_and @0 @1))
530 (if (!TYPE_OVERFLOW_SANITIZED (type) && !TYPE_OVERFLOW_TRAPS (type)
531 && !TYPE_SATURATING (type))
532 (bit_ior @0 @1)))
533
534 /* (x | y) - (x ^ y) -> x & y */
535 (simplify
536 (minus (bit_ior @0 @1) (bit_xor @0 @1))
537 (bit_and @0 @1))
538
539 /* (x | y) - (x & y) -> x ^ y */
540 (simplify
541 (minus (bit_ior @0 @1) (bit_and @0 @1))
542 (bit_xor @0 @1))
543
544 /* (x | y) & ~(x & y) -> x ^ y */
545 (simplify
546 (bit_and:c (bit_ior @0 @1) (bit_not (bit_and @0 @1)))
547 (bit_xor @0 @1))
548
549 /* (x | y) & (~x ^ y) -> x & y */
550 (simplify
551 (bit_and:c (bit_ior:c @0 @1) (bit_xor:c @1 (bit_not @0)))
552 (bit_and @0 @1))
553
554 /* ~x & ~y -> ~(x | y)
555 ~x | ~y -> ~(x & y) */
556 (for op (bit_and bit_ior)
557 rop (bit_ior bit_and)
558 (simplify
559 (op (convert1? (bit_not @0)) (convert2? (bit_not @1)))
560 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
561 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
562 (bit_not (rop (convert @0) (convert @1))))))
563
564 /* If we are XORing or adding two BIT_AND_EXPR's, both of which are and'ing
565 with a constant, and the two constants have no bits in common,
566 we should treat this as a BIT_IOR_EXPR since this may produce more
567 simplifications. */
568 (for op (bit_xor plus)
569 (simplify
570 (op (convert1? (bit_and@4 @0 INTEGER_CST@1))
571 (convert2? (bit_and@5 @2 INTEGER_CST@3)))
572 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
573 && tree_nop_conversion_p (type, TREE_TYPE (@2))
574 && wi::bit_and (@1, @3) == 0)
575 (bit_ior (convert @4) (convert @5)))))
576
577 /* (X | Y) ^ X -> Y & ~ X*/
578 (simplify
579 (bit_xor:c (convert? (bit_ior:c @0 @1)) (convert? @0))
580 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
581 (convert (bit_and @1 (bit_not @0)))))
582
583 /* Convert ~X ^ ~Y to X ^ Y. */
584 (simplify
585 (bit_xor (convert1? (bit_not @0)) (convert2? (bit_not @1)))
586 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
587 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
588 (bit_xor (convert @0) (convert @1))))
589
590 /* Convert ~X ^ C to X ^ ~C. */
591 (simplify
592 (bit_xor (convert? (bit_not @0)) INTEGER_CST@1)
593 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
594 (bit_xor (convert @0) (bit_not @1))))
595
596 /* Fold (X & Y) ^ Y as ~X & Y. */
597 (simplify
598 (bit_xor:c (bit_and:c @0 @1) @1)
599 (bit_and (bit_not @0) @1))
600
601 /* Given a bit-wise operation CODE applied to ARG0 and ARG1, see if both
602 operands are another bit-wise operation with a common input. If so,
603 distribute the bit operations to save an operation and possibly two if
604 constants are involved. For example, convert
605 (A | B) & (A | C) into A | (B & C)
606 Further simplification will occur if B and C are constants. */
607 (for op (bit_and bit_ior)
608 rop (bit_ior bit_and)
609 (simplify
610 (op (convert? (rop:c @0 @1)) (convert? (rop @0 @2)))
611 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
612 (rop (convert @0) (op (convert @1) (convert @2))))))
613
614
615 (simplify
616 (abs (abs@1 @0))
617 @1)
618 (simplify
619 (abs (negate @0))
620 (abs @0))
621 (simplify
622 (abs tree_expr_nonnegative_p@0)
623 @0)
624
625 /* A few cases of fold-const.c negate_expr_p predicate. */
626 (match negate_expr_p
627 INTEGER_CST
628 (if ((INTEGRAL_TYPE_P (type)
629 && TYPE_OVERFLOW_WRAPS (type))
630 || (!TYPE_OVERFLOW_SANITIZED (type)
631 && may_negate_without_overflow_p (t)))))
632 (match negate_expr_p
633 FIXED_CST)
634 (match negate_expr_p
635 (negate @0)
636 (if (!TYPE_OVERFLOW_SANITIZED (type))))
637 (match negate_expr_p
638 REAL_CST
639 (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (t)))))
640 /* VECTOR_CST handling of non-wrapping types would recurse in unsupported
641 ways. */
642 (match negate_expr_p
643 VECTOR_CST
644 (if (FLOAT_TYPE_P (TREE_TYPE (type)) || TYPE_OVERFLOW_WRAPS (type))))
645
646 /* (-A) * (-B) -> A * B */
647 (simplify
648 (mult:c (convert1? (negate @0)) (convert2? negate_expr_p@1))
649 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
650 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
651 (mult (convert @0) (convert (negate @1)))))
652
653 /* -(A + B) -> (-B) - A. */
654 (simplify
655 (negate (plus:c @0 negate_expr_p@1))
656 (if (!HONOR_SIGN_DEPENDENT_ROUNDING (element_mode (type))
657 && !HONOR_SIGNED_ZEROS (element_mode (type)))
658 (minus (negate @1) @0)))
659
660 /* A - B -> A + (-B) if B is easily negatable. */
661 (simplify
662 (minus @0 negate_expr_p@1)
663 (if (!FIXED_POINT_TYPE_P (type))
664 (plus @0 (negate @1))))
665
666 /* Try to fold (type) X op CST -> (type) (X op ((type-x) CST))
667 when profitable.
668 For bitwise binary operations apply operand conversions to the
669 binary operation result instead of to the operands. This allows
670 to combine successive conversions and bitwise binary operations.
671 We combine the above two cases by using a conditional convert. */
672 (for bitop (bit_and bit_ior bit_xor)
673 (simplify
674 (bitop (convert @0) (convert? @1))
675 (if (((TREE_CODE (@1) == INTEGER_CST
676 && INTEGRAL_TYPE_P (TREE_TYPE (@0))
677 && int_fits_type_p (@1, TREE_TYPE (@0)))
678 || types_match (@0, @1))
679 /* ??? This transform conflicts with fold-const.c doing
680 Convert (T)(x & c) into (T)x & (T)c, if c is an integer
681 constants (if x has signed type, the sign bit cannot be set
682 in c). This folds extension into the BIT_AND_EXPR.
683 Restrict it to GIMPLE to avoid endless recursions. */
684 && (bitop != BIT_AND_EXPR || GIMPLE)
685 && (/* That's a good idea if the conversion widens the operand, thus
686 after hoisting the conversion the operation will be narrower. */
687 TYPE_PRECISION (TREE_TYPE (@0)) < TYPE_PRECISION (type)
688 /* It's also a good idea if the conversion is to a non-integer
689 mode. */
690 || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT
691 /* Or if the precision of TO is not the same as the precision
692 of its mode. */
693 || TYPE_PRECISION (type) != GET_MODE_PRECISION (TYPE_MODE (type))))
694 (convert (bitop @0 (convert @1))))))
695
696 (for bitop (bit_and bit_ior)
697 rbitop (bit_ior bit_and)
698 /* (x | y) & x -> x */
699 /* (x & y) | x -> x */
700 (simplify
701 (bitop:c (rbitop:c @0 @1) @0)
702 @0)
703 /* (~x | y) & x -> x & y */
704 /* (~x & y) | x -> x | y */
705 (simplify
706 (bitop:c (rbitop:c (bit_not @0) @1) @0)
707 (bitop @0 @1)))
708
709 /* Simplify (A & B) OP0 (C & B) to (A OP0 C) & B. */
710 (for bitop (bit_and bit_ior bit_xor)
711 (simplify
712 (bitop (bit_and:c @0 @1) (bit_and @2 @1))
713 (bit_and (bitop @0 @2) @1)))
714
715 /* (x | CST1) & CST2 -> (x & CST2) | (CST1 & CST2) */
716 (simplify
717 (bit_and (bit_ior @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
718 (bit_ior (bit_and @0 @2) (bit_and @1 @2)))
719
720 /* Combine successive equal operations with constants. */
721 (for bitop (bit_and bit_ior bit_xor)
722 (simplify
723 (bitop (bitop @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
724 (bitop @0 (bitop @1 @2))))
725
726 /* Try simple folding for X op !X, and X op X with the help
727 of the truth_valued_p and logical_inverted_value predicates. */
728 (match truth_valued_p
729 @0
730 (if (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1)))
731 (for op (tcc_comparison truth_and truth_andif truth_or truth_orif truth_xor)
732 (match truth_valued_p
733 (op @0 @1)))
734 (match truth_valued_p
735 (truth_not @0))
736
737 (match (logical_inverted_value @0)
738 (truth_not @0))
739 (match (logical_inverted_value @0)
740 (bit_not truth_valued_p@0))
741 (match (logical_inverted_value @0)
742 (eq @0 integer_zerop))
743 (match (logical_inverted_value @0)
744 (ne truth_valued_p@0 integer_truep))
745 (match (logical_inverted_value @0)
746 (bit_xor truth_valued_p@0 integer_truep))
747
748 /* X & !X -> 0. */
749 (simplify
750 (bit_and:c @0 (logical_inverted_value @0))
751 { build_zero_cst (type); })
752 /* X | !X and X ^ !X -> 1, , if X is truth-valued. */
753 (for op (bit_ior bit_xor)
754 (simplify
755 (op:c truth_valued_p@0 (logical_inverted_value @0))
756 { constant_boolean_node (true, type); }))
757 /* X ==/!= !X is false/true. */
758 (for op (eq ne)
759 (simplify
760 (op:c truth_valued_p@0 (logical_inverted_value @0))
761 { constant_boolean_node (op == NE_EXPR ? true : false, type); }))
762
763 /* If arg1 and arg2 are booleans (or any single bit type)
764 then try to simplify:
765
766 (~X & Y) -> X < Y
767 (X & ~Y) -> Y < X
768 (~X | Y) -> X <= Y
769 (X | ~Y) -> Y <= X
770
771 But only do this if our result feeds into a comparison as
772 this transformation is not always a win, particularly on
773 targets with and-not instructions.
774 -> simplify_bitwise_binary_boolean */
775 (simplify
776 (ne (bit_and:c (bit_not @0) @1) integer_zerop)
777 (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
778 && TYPE_PRECISION (TREE_TYPE (@1)) == 1)
779 (lt @0 @1)))
780 (simplify
781 (ne (bit_ior:c (bit_not @0) @1) integer_zerop)
782 (if (INTEGRAL_TYPE_P (TREE_TYPE (@1))
783 && TYPE_PRECISION (TREE_TYPE (@1)) == 1)
784 (le @0 @1)))
785
786 /* ~~x -> x */
787 (simplify
788 (bit_not (bit_not @0))
789 @0)
790
791 /* Convert ~ (-A) to A - 1. */
792 (simplify
793 (bit_not (convert? (negate @0)))
794 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
795 (convert (minus @0 { build_each_one_cst (TREE_TYPE (@0)); }))))
796
797 /* Convert ~ (A - 1) or ~ (A + -1) to -A. */
798 (simplify
799 (bit_not (convert? (minus @0 integer_each_onep)))
800 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
801 (convert (negate @0))))
802 (simplify
803 (bit_not (convert? (plus @0 integer_all_onesp)))
804 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
805 (convert (negate @0))))
806
807 /* Part of convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
808 (simplify
809 (bit_not (convert? (bit_xor @0 INTEGER_CST@1)))
810 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
811 (convert (bit_xor @0 (bit_not @1)))))
812 (simplify
813 (bit_not (convert? (bit_xor:c (bit_not @0) @1)))
814 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
815 (convert (bit_xor @0 @1))))
816
817 /* (x & ~m) | (y & m) -> ((x ^ y) & m) ^ x */
818 (simplify
819 (bit_ior:c (bit_and:cs @0 (bit_not @2)) (bit_and:cs @1 @2))
820 (bit_xor (bit_and (bit_xor @0 @1) @2) @0))
821
822 /* Fold A - (A & B) into ~B & A. */
823 (simplify
824 (minus (convert? @0) (convert?:s (bit_and:cs @0 @1)))
825 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
826 && tree_nop_conversion_p (type, TREE_TYPE (@1)))
827 (convert (bit_and (bit_not @1) @0))))
828
829
830
831 /* ((X inner_op C0) outer_op C1)
832 With X being a tree where value_range has reasoned certain bits to always be
833 zero throughout its computed value range,
834 inner_op = {|,^}, outer_op = {|,^} and inner_op != outer_op
835 where zero_mask has 1's for all bits that are sure to be 0 in
836 and 0's otherwise.
837 if (inner_op == '^') C0 &= ~C1;
838 if ((C0 & ~zero_mask) == 0) then emit (X outer_op (C0 outer_op C1)
839 if ((C1 & ~zero_mask) == 0) then emit (X inner_op (C0 outer_op C1)
840 */
841 (for inner_op (bit_ior bit_xor)
842 outer_op (bit_xor bit_ior)
843 (simplify
844 (outer_op
845 (inner_op:s @2 INTEGER_CST@0) INTEGER_CST@1)
846 (with
847 {
848 bool fail = false;
849 wide_int zero_mask_not;
850 wide_int C0;
851 wide_int cst_emit;
852
853 if (TREE_CODE (@2) == SSA_NAME)
854 zero_mask_not = get_nonzero_bits (@2);
855 else
856 fail = true;
857
858 if (inner_op == BIT_XOR_EXPR)
859 {
860 C0 = wi::bit_and_not (@0, @1);
861 cst_emit = wi::bit_or (C0, @1);
862 }
863 else
864 {
865 C0 = @0;
866 cst_emit = wi::bit_xor (@0, @1);
867 }
868 }
869 (if (!fail && wi::bit_and (C0, zero_mask_not) == 0)
870 (outer_op @2 { wide_int_to_tree (type, cst_emit); })
871 (if (!fail && wi::bit_and (@1, zero_mask_not) == 0)
872 (inner_op @2 { wide_int_to_tree (type, cst_emit); }))))))
873
874 /* Associate (p +p off1) +p off2 as (p +p (off1 + off2)). */
875 (simplify
876 (pointer_plus (pointer_plus:s @0 @1) @3)
877 (pointer_plus @0 (plus @1 @3)))
878
879 /* Pattern match
880 tem1 = (long) ptr1;
881 tem2 = (long) ptr2;
882 tem3 = tem2 - tem1;
883 tem4 = (unsigned long) tem3;
884 tem5 = ptr1 + tem4;
885 and produce
886 tem5 = ptr2; */
887 (simplify
888 (pointer_plus @0 (convert?@2 (minus@3 (convert @1) (convert @0))))
889 /* Conditionally look through a sign-changing conversion. */
890 (if (TYPE_PRECISION (TREE_TYPE (@2)) == TYPE_PRECISION (TREE_TYPE (@3))
891 && ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@1)))
892 || (GENERIC && type == TREE_TYPE (@1))))
893 @1))
894
895 /* Pattern match
896 tem = (sizetype) ptr;
897 tem = tem & algn;
898 tem = -tem;
899 ... = ptr p+ tem;
900 and produce the simpler and easier to analyze with respect to alignment
901 ... = ptr & ~algn; */
902 (simplify
903 (pointer_plus @0 (negate (bit_and (convert @0) INTEGER_CST@1)))
904 (with { tree algn = wide_int_to_tree (TREE_TYPE (@0), wi::bit_not (@1)); }
905 (bit_and @0 { algn; })))
906
907 /* Try folding difference of addresses. */
908 (simplify
909 (minus (convert ADDR_EXPR@0) (convert @1))
910 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
911 (with { HOST_WIDE_INT diff; }
912 (if (ptr_difference_const (@0, @1, &diff))
913 { build_int_cst_type (type, diff); }))))
914 (simplify
915 (minus (convert @0) (convert ADDR_EXPR@1))
916 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
917 (with { HOST_WIDE_INT diff; }
918 (if (ptr_difference_const (@0, @1, &diff))
919 { build_int_cst_type (type, diff); }))))
920
921 /* If arg0 is derived from the address of an object or function, we may
922 be able to fold this expression using the object or function's
923 alignment. */
924 (simplify
925 (bit_and (convert? @0) INTEGER_CST@1)
926 (if (POINTER_TYPE_P (TREE_TYPE (@0))
927 && tree_nop_conversion_p (type, TREE_TYPE (@0)))
928 (with
929 {
930 unsigned int align;
931 unsigned HOST_WIDE_INT bitpos;
932 get_pointer_alignment_1 (@0, &align, &bitpos);
933 }
934 (if (wi::ltu_p (@1, align / BITS_PER_UNIT))
935 { wide_int_to_tree (type, wi::bit_and (@1, bitpos / BITS_PER_UNIT)); }))))
936
937
938 /* We can't reassociate at all for saturating types. */
939 (if (!TYPE_SATURATING (type))
940
941 /* Contract negates. */
942 /* A + (-B) -> A - B */
943 (simplify
944 (plus:c (convert1? @0) (convert2? (negate @1)))
945 /* Apply STRIP_NOPS on @0 and the negate. */
946 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
947 && tree_nop_conversion_p (type, TREE_TYPE (@1))
948 && !TYPE_OVERFLOW_SANITIZED (type))
949 (minus (convert @0) (convert @1))))
950 /* A - (-B) -> A + B */
951 (simplify
952 (minus (convert1? @0) (convert2? (negate @1)))
953 (if (tree_nop_conversion_p (type, TREE_TYPE (@0))
954 && tree_nop_conversion_p (type, TREE_TYPE (@1))
955 && !TYPE_OVERFLOW_SANITIZED (type))
956 (plus (convert @0) (convert @1))))
957 /* -(-A) -> A */
958 (simplify
959 (negate (convert? (negate @1)))
960 (if (tree_nop_conversion_p (type, TREE_TYPE (@1))
961 && !TYPE_OVERFLOW_SANITIZED (type))
962 (convert @1)))
963
964 /* We can't reassociate floating-point unless -fassociative-math
965 or fixed-point plus or minus because of saturation to +-Inf. */
966 (if ((!FLOAT_TYPE_P (type) || flag_associative_math)
967 && !FIXED_POINT_TYPE_P (type))
968
969 /* Match patterns that allow contracting a plus-minus pair
970 irrespective of overflow issues. */
971 /* (A +- B) - A -> +- B */
972 /* (A +- B) -+ B -> A */
973 /* A - (A +- B) -> -+ B */
974 /* A +- (B -+ A) -> +- B */
975 (simplify
976 (minus (plus:c @0 @1) @0)
977 @1)
978 (simplify
979 (minus (minus @0 @1) @0)
980 (negate @1))
981 (simplify
982 (plus:c (minus @0 @1) @1)
983 @0)
984 (simplify
985 (minus @0 (plus:c @0 @1))
986 (negate @1))
987 (simplify
988 (minus @0 (minus @0 @1))
989 @1)
990
991 /* (A +- CST) +- CST -> A + CST */
992 (for outer_op (plus minus)
993 (for inner_op (plus minus)
994 (simplify
995 (outer_op (inner_op @0 CONSTANT_CLASS_P@1) CONSTANT_CLASS_P@2)
996 /* If the constant operation overflows we cannot do the transform
997 as we would introduce undefined overflow, for example
998 with (a - 1) + INT_MIN. */
999 (with { tree cst = fold_binary (outer_op == inner_op
1000 ? PLUS_EXPR : MINUS_EXPR, type, @1, @2); }
1001 (if (cst && !TREE_OVERFLOW (cst))
1002 (inner_op @0 { cst; } ))))))
1003
1004 /* (CST - A) +- CST -> CST - A */
1005 (for outer_op (plus minus)
1006 (simplify
1007 (outer_op (minus CONSTANT_CLASS_P@1 @0) CONSTANT_CLASS_P@2)
1008 (with { tree cst = fold_binary (outer_op, type, @1, @2); }
1009 (if (cst && !TREE_OVERFLOW (cst))
1010 (minus { cst; } @0)))))
1011
1012 /* ~A + A -> -1 */
1013 (simplify
1014 (plus:c (bit_not @0) @0)
1015 (if (!TYPE_OVERFLOW_TRAPS (type))
1016 { build_all_ones_cst (type); }))
1017
1018 /* ~A + 1 -> -A */
1019 (simplify
1020 (plus (convert? (bit_not @0)) integer_each_onep)
1021 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
1022 (negate (convert @0))))
1023
1024 /* -A - 1 -> ~A */
1025 (simplify
1026 (minus (convert? (negate @0)) integer_each_onep)
1027 (if (!TYPE_OVERFLOW_TRAPS (type)
1028 && tree_nop_conversion_p (type, TREE_TYPE (@0)))
1029 (bit_not (convert @0))))
1030
1031 /* -1 - A -> ~A */
1032 (simplify
1033 (minus integer_all_onesp @0)
1034 (bit_not @0))
1035
1036 /* (T)(P + A) - (T)P -> (T) A */
1037 (for add (plus pointer_plus)
1038 (simplify
1039 (minus (convert (add @0 @1))
1040 (convert @0))
1041 (if (element_precision (type) <= element_precision (TREE_TYPE (@1))
1042 /* For integer types, if A has a smaller type
1043 than T the result depends on the possible
1044 overflow in P + A.
1045 E.g. T=size_t, A=(unsigned)429497295, P>0.
1046 However, if an overflow in P + A would cause
1047 undefined behavior, we can assume that there
1048 is no overflow. */
1049 || (INTEGRAL_TYPE_P (TREE_TYPE (@0))
1050 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
1051 /* For pointer types, if the conversion of A to the
1052 final type requires a sign- or zero-extension,
1053 then we have to punt - it is not defined which
1054 one is correct. */
1055 || (POINTER_TYPE_P (TREE_TYPE (@0))
1056 && TREE_CODE (@1) == INTEGER_CST
1057 && tree_int_cst_sign_bit (@1) == 0))
1058 (convert @1))))))
1059
1060
1061 /* Simplifications of MIN_EXPR and MAX_EXPR. */
1062
1063 (for minmax (min max)
1064 (simplify
1065 (minmax @0 @0)
1066 @0))
1067 (simplify
1068 (min @0 @1)
1069 (if (INTEGRAL_TYPE_P (type)
1070 && TYPE_MIN_VALUE (type)
1071 && operand_equal_p (@1, TYPE_MIN_VALUE (type), OEP_ONLY_CONST))
1072 @1))
1073 (simplify
1074 (max @0 @1)
1075 (if (INTEGRAL_TYPE_P (type)
1076 && TYPE_MAX_VALUE (type)
1077 && operand_equal_p (@1, TYPE_MAX_VALUE (type), OEP_ONLY_CONST))
1078 @1))
1079
1080
1081 /* Simplifications of shift and rotates. */
1082
1083 (for rotate (lrotate rrotate)
1084 (simplify
1085 (rotate integer_all_onesp@0 @1)
1086 @0))
1087
1088 /* Optimize -1 >> x for arithmetic right shifts. */
1089 (simplify
1090 (rshift integer_all_onesp@0 @1)
1091 (if (!TYPE_UNSIGNED (type)
1092 && tree_expr_nonnegative_p (@1))
1093 @0))
1094
1095 /* Optimize (x >> c) << c into x & (-1<<c). */
1096 (simplify
1097 (lshift (rshift @0 INTEGER_CST@1) @1)
1098 (if (wi::ltu_p (@1, element_precision (type)))
1099 (bit_and @0 (lshift { build_minus_one_cst (type); } @1))))
1100
1101 /* Optimize (x << c) >> c into x & ((unsigned)-1 >> c) for unsigned
1102 types. */
1103 (simplify
1104 (rshift (lshift @0 INTEGER_CST@1) @1)
1105 (if (TYPE_UNSIGNED (type)
1106 && (wi::ltu_p (@1, element_precision (type))))
1107 (bit_and @0 (rshift { build_minus_one_cst (type); } @1))))
1108
1109 (for shiftrotate (lrotate rrotate lshift rshift)
1110 (simplify
1111 (shiftrotate @0 integer_zerop)
1112 (non_lvalue @0))
1113 (simplify
1114 (shiftrotate integer_zerop@0 @1)
1115 @0)
1116 /* Prefer vector1 << scalar to vector1 << vector2
1117 if vector2 is uniform. */
1118 (for vec (VECTOR_CST CONSTRUCTOR)
1119 (simplify
1120 (shiftrotate @0 vec@1)
1121 (with { tree tem = uniform_vector_p (@1); }
1122 (if (tem)
1123 (shiftrotate @0 { tem; }))))))
1124
1125 /* Rewrite an LROTATE_EXPR by a constant into an
1126 RROTATE_EXPR by a new constant. */
1127 (simplify
1128 (lrotate @0 INTEGER_CST@1)
1129 (rrotate @0 { fold_binary (MINUS_EXPR, TREE_TYPE (@1),
1130 build_int_cst (TREE_TYPE (@1),
1131 element_precision (type)), @1); }))
1132
1133 /* Turn (a OP c1) OP c2 into a OP (c1+c2). */
1134 (for op (lrotate rrotate rshift lshift)
1135 (simplify
1136 (op (op @0 INTEGER_CST@1) INTEGER_CST@2)
1137 (with { unsigned int prec = element_precision (type); }
1138 (if (wi::ge_p (@1, 0, TYPE_SIGN (TREE_TYPE (@1)))
1139 && wi::lt_p (@1, prec, TYPE_SIGN (TREE_TYPE (@1)))
1140 && wi::ge_p (@2, 0, TYPE_SIGN (TREE_TYPE (@2)))
1141 && wi::lt_p (@2, prec, TYPE_SIGN (TREE_TYPE (@2))))
1142 (with { unsigned int low = wi::add (@1, @2).to_uhwi (); }
1143 /* Deal with a OP (c1 + c2) being undefined but (a OP c1) OP c2
1144 being well defined. */
1145 (if (low >= prec)
1146 (if (op == LROTATE_EXPR || op == RROTATE_EXPR)
1147 (op @0 { build_int_cst (TREE_TYPE (@1), low % prec); })
1148 (if (TYPE_UNSIGNED (type) || op == LSHIFT_EXPR)
1149 { build_zero_cst (type); }
1150 (op @0 { build_int_cst (TREE_TYPE (@1), prec - 1); })))
1151 (op @0 { build_int_cst (TREE_TYPE (@1), low); })))))))
1152
1153
1154 /* ((1 << A) & 1) != 0 -> A == 0
1155 ((1 << A) & 1) == 0 -> A != 0 */
1156 (for cmp (ne eq)
1157 icmp (eq ne)
1158 (simplify
1159 (cmp (bit_and (lshift integer_onep @0) integer_onep) integer_zerop)
1160 (icmp @0 { build_zero_cst (TREE_TYPE (@0)); })))
1161
1162 /* (CST1 << A) == CST2 -> A == ctz (CST2) - ctz (CST1)
1163 (CST1 << A) != CST2 -> A != ctz (CST2) - ctz (CST1)
1164 if CST2 != 0. */
1165 (for cmp (ne eq)
1166 (simplify
1167 (cmp (lshift INTEGER_CST@0 @1) INTEGER_CST@2)
1168 (with { int cand = wi::ctz (@2) - wi::ctz (@0); }
1169 (if (cand < 0
1170 || (!integer_zerop (@2)
1171 && wi::ne_p (wi::lshift (@0, cand), @2)))
1172 { constant_boolean_node (cmp == NE_EXPR, type); }
1173 (if (!integer_zerop (@2)
1174 && wi::eq_p (wi::lshift (@0, cand), @2))
1175 (cmp @1 { build_int_cst (TREE_TYPE (@1), cand); }))))))
1176
1177 /* Fold (X << C1) & C2 into (X << C1) & (C2 | ((1 << C1) - 1))
1178 (X >> C1) & C2 into (X >> C1) & (C2 | ~((type) -1 >> C1))
1179 if the new mask might be further optimized. */
1180 (for shift (lshift rshift)
1181 (simplify
1182 (bit_and (convert?:s@4 (shift:s@5 (convert1?@3 @0) INTEGER_CST@1))
1183 INTEGER_CST@2)
1184 (if (tree_nop_conversion_p (TREE_TYPE (@4), TREE_TYPE (@5))
1185 && TYPE_PRECISION (type) <= HOST_BITS_PER_WIDE_INT
1186 && tree_fits_uhwi_p (@1)
1187 && tree_to_uhwi (@1) > 0
1188 && tree_to_uhwi (@1) < TYPE_PRECISION (type))
1189 (with
1190 {
1191 unsigned int shiftc = tree_to_uhwi (@1);
1192 unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (@2);
1193 unsigned HOST_WIDE_INT newmask, zerobits = 0;
1194 tree shift_type = TREE_TYPE (@3);
1195 unsigned int prec;
1196
1197 if (shift == LSHIFT_EXPR)
1198 zerobits = ((((unsigned HOST_WIDE_INT) 1) << shiftc) - 1);
1199 else if (shift == RSHIFT_EXPR
1200 && (TYPE_PRECISION (shift_type)
1201 == GET_MODE_PRECISION (TYPE_MODE (shift_type))))
1202 {
1203 prec = TYPE_PRECISION (TREE_TYPE (@3));
1204 tree arg00 = @0;
1205 /* See if more bits can be proven as zero because of
1206 zero extension. */
1207 if (@3 != @0
1208 && TYPE_UNSIGNED (TREE_TYPE (@0)))
1209 {
1210 tree inner_type = TREE_TYPE (@0);
1211 if ((TYPE_PRECISION (inner_type)
1212 == GET_MODE_PRECISION (TYPE_MODE (inner_type)))
1213 && TYPE_PRECISION (inner_type) < prec)
1214 {
1215 prec = TYPE_PRECISION (inner_type);
1216 /* See if we can shorten the right shift. */
1217 if (shiftc < prec)
1218 shift_type = inner_type;
1219 /* Otherwise X >> C1 is all zeros, so we'll optimize
1220 it into (X, 0) later on by making sure zerobits
1221 is all ones. */
1222 }
1223 }
1224 zerobits = ~(unsigned HOST_WIDE_INT) 0;
1225 if (shiftc < prec)
1226 {
1227 zerobits >>= HOST_BITS_PER_WIDE_INT - shiftc;
1228 zerobits <<= prec - shiftc;
1229 }
1230 /* For arithmetic shift if sign bit could be set, zerobits
1231 can contain actually sign bits, so no transformation is
1232 possible, unless MASK masks them all away. In that
1233 case the shift needs to be converted into logical shift. */
1234 if (!TYPE_UNSIGNED (TREE_TYPE (@3))
1235 && prec == TYPE_PRECISION (TREE_TYPE (@3)))
1236 {
1237 if ((mask & zerobits) == 0)
1238 shift_type = unsigned_type_for (TREE_TYPE (@3));
1239 else
1240 zerobits = 0;
1241 }
1242 }
1243 }
1244 /* ((X << 16) & 0xff00) is (X, 0). */
1245 (if ((mask & zerobits) == mask)
1246 { build_int_cst (type, 0); }
1247 (with { newmask = mask | zerobits; }
1248 (if (newmask != mask && (newmask & (newmask + 1)) == 0)
1249 (with
1250 {
1251 /* Only do the transformation if NEWMASK is some integer
1252 mode's mask. */
1253 for (prec = BITS_PER_UNIT;
1254 prec < HOST_BITS_PER_WIDE_INT; prec <<= 1)
1255 if (newmask == (((unsigned HOST_WIDE_INT) 1) << prec) - 1)
1256 break;
1257 }
1258 (if (prec < HOST_BITS_PER_WIDE_INT
1259 || newmask == ~(unsigned HOST_WIDE_INT) 0)
1260 (with
1261 { tree newmaskt = build_int_cst_type (TREE_TYPE (@2), newmask); }
1262 (if (!tree_int_cst_equal (newmaskt, @2))
1263 (if (shift_type != TREE_TYPE (@3))
1264 (bit_and (convert (shift:shift_type (convert @3) @1)) { newmaskt; })
1265 (bit_and @4 { newmaskt; })))))))))))))
1266
1267 /* Fold (X {&,^,|} C2) << C1 into (X << C1) {&,^,|} (C2 << C1)
1268 (X {&,^,|} C2) >> C1 into (X >> C1) & (C2 >> C1). */
1269 (for shift (lshift rshift)
1270 (for bit_op (bit_and bit_xor bit_ior)
1271 (simplify
1272 (shift (convert?:s (bit_op:s @0 INTEGER_CST@2)) INTEGER_CST@1)
1273 (if (tree_nop_conversion_p (type, TREE_TYPE (@0)))
1274 (with { tree mask = int_const_binop (shift, fold_convert (type, @2), @1); }
1275 (bit_op (shift (convert @0) @1) { mask; }))))))
1276
1277
1278 /* Simplifications of conversions. */
1279
1280 /* Basic strip-useless-type-conversions / strip_nops. */
1281 (for cvt (convert view_convert float fix_trunc)
1282 (simplify
1283 (cvt @0)
1284 (if ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@0)))
1285 || (GENERIC && type == TREE_TYPE (@0)))
1286 @0)))
1287
1288 /* Contract view-conversions. */
1289 (simplify
1290 (view_convert (view_convert @0))
1291 (view_convert @0))
1292
1293 /* For integral conversions with the same precision or pointer
1294 conversions use a NOP_EXPR instead. */
1295 (simplify
1296 (view_convert @0)
1297 (if ((INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
1298 && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
1299 && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0)))
1300 (convert @0)))
1301
1302 /* Strip inner integral conversions that do not change precision or size. */
1303 (simplify
1304 (view_convert (convert@0 @1))
1305 (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
1306 && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
1307 && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
1308 && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))))
1309 (view_convert @1)))
1310
1311 /* Re-association barriers around constants and other re-association
1312 barriers can be removed. */
1313 (simplify
1314 (paren CONSTANT_CLASS_P@0)
1315 @0)
1316 (simplify
1317 (paren (paren@1 @0))
1318 @1)
1319
1320 /* Handle cases of two conversions in a row. */
1321 (for ocvt (convert float fix_trunc)
1322 (for icvt (convert float)
1323 (simplify
1324 (ocvt (icvt@1 @0))
1325 (with
1326 {
1327 tree inside_type = TREE_TYPE (@0);
1328 tree inter_type = TREE_TYPE (@1);
1329 int inside_int = INTEGRAL_TYPE_P (inside_type);
1330 int inside_ptr = POINTER_TYPE_P (inside_type);
1331 int inside_float = FLOAT_TYPE_P (inside_type);
1332 int inside_vec = VECTOR_TYPE_P (inside_type);
1333 unsigned int inside_prec = TYPE_PRECISION (inside_type);
1334 int inside_unsignedp = TYPE_UNSIGNED (inside_type);
1335 int inter_int = INTEGRAL_TYPE_P (inter_type);
1336 int inter_ptr = POINTER_TYPE_P (inter_type);
1337 int inter_float = FLOAT_TYPE_P (inter_type);
1338 int inter_vec = VECTOR_TYPE_P (inter_type);
1339 unsigned int inter_prec = TYPE_PRECISION (inter_type);
1340 int inter_unsignedp = TYPE_UNSIGNED (inter_type);
1341 int final_int = INTEGRAL_TYPE_P (type);
1342 int final_ptr = POINTER_TYPE_P (type);
1343 int final_float = FLOAT_TYPE_P (type);
1344 int final_vec = VECTOR_TYPE_P (type);
1345 unsigned int final_prec = TYPE_PRECISION (type);
1346 int final_unsignedp = TYPE_UNSIGNED (type);
1347 }
1348 (switch
1349 /* In addition to the cases of two conversions in a row
1350 handled below, if we are converting something to its own
1351 type via an object of identical or wider precision, neither
1352 conversion is needed. */
1353 (if (((GIMPLE && useless_type_conversion_p (type, inside_type))
1354 || (GENERIC
1355 && TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (inside_type)))
1356 && (((inter_int || inter_ptr) && final_int)
1357 || (inter_float && final_float))
1358 && inter_prec >= final_prec)
1359 (ocvt @0))
1360
1361 /* Likewise, if the intermediate and initial types are either both
1362 float or both integer, we don't need the middle conversion if the
1363 former is wider than the latter and doesn't change the signedness
1364 (for integers). Avoid this if the final type is a pointer since
1365 then we sometimes need the middle conversion. Likewise if the
1366 final type has a precision not equal to the size of its mode. */
1367 (if (((inter_int && inside_int) || (inter_float && inside_float))
1368 && (final_int || final_float)
1369 && inter_prec >= inside_prec
1370 && (inter_float || inter_unsignedp == inside_unsignedp)
1371 && ! (final_prec != GET_MODE_PRECISION (TYPE_MODE (type))
1372 && TYPE_MODE (type) == TYPE_MODE (inter_type)))
1373 (ocvt @0))
1374
1375 /* If we have a sign-extension of a zero-extended value, we can
1376 replace that by a single zero-extension. Likewise if the
1377 final conversion does not change precision we can drop the
1378 intermediate conversion. */
1379 (if (inside_int && inter_int && final_int
1380 && ((inside_prec < inter_prec && inter_prec < final_prec
1381 && inside_unsignedp && !inter_unsignedp)
1382 || final_prec == inter_prec))
1383 (ocvt @0))
1384
1385 /* Two conversions in a row are not needed unless:
1386 - some conversion is floating-point (overstrict for now), or
1387 - some conversion is a vector (overstrict for now), or
1388 - the intermediate type is narrower than both initial and
1389 final, or
1390 - the intermediate type and innermost type differ in signedness,
1391 and the outermost type is wider than the intermediate, or
1392 - the initial type is a pointer type and the precisions of the
1393 intermediate and final types differ, or
1394 - the final type is a pointer type and the precisions of the
1395 initial and intermediate types differ. */
1396 (if (! inside_float && ! inter_float && ! final_float
1397 && ! inside_vec && ! inter_vec && ! final_vec
1398 && (inter_prec >= inside_prec || inter_prec >= final_prec)
1399 && ! (inside_int && inter_int
1400 && inter_unsignedp != inside_unsignedp
1401 && inter_prec < final_prec)
1402 && ((inter_unsignedp && inter_prec > inside_prec)
1403 == (final_unsignedp && final_prec > inter_prec))
1404 && ! (inside_ptr && inter_prec != final_prec)
1405 && ! (final_ptr && inside_prec != inter_prec)
1406 && ! (final_prec != GET_MODE_PRECISION (TYPE_MODE (type))
1407 && TYPE_MODE (type) == TYPE_MODE (inter_type)))
1408 (ocvt @0))
1409
1410 /* A truncation to an unsigned type (a zero-extension) should be
1411 canonicalized as bitwise and of a mask. */
1412 (if (final_int && inter_int && inside_int
1413 && final_prec == inside_prec
1414 && final_prec > inter_prec
1415 && inter_unsignedp)
1416 (convert (bit_and @0 { wide_int_to_tree
1417 (inside_type,
1418 wi::mask (inter_prec, false,
1419 TYPE_PRECISION (inside_type))); })))
1420
1421 /* If we are converting an integer to a floating-point that can
1422 represent it exactly and back to an integer, we can skip the
1423 floating-point conversion. */
1424 (if (GIMPLE /* PR66211 */
1425 && inside_int && inter_float && final_int &&
1426 (unsigned) significand_size (TYPE_MODE (inter_type))
1427 >= inside_prec - !inside_unsignedp)
1428 (convert @0)))))))
1429
1430 /* If we have a narrowing conversion to an integral type that is fed by a
1431 BIT_AND_EXPR, we might be able to remove the BIT_AND_EXPR if it merely
1432 masks off bits outside the final type (and nothing else). */
1433 (simplify
1434 (convert (bit_and @0 INTEGER_CST@1))
1435 (if (INTEGRAL_TYPE_P (type)
1436 && INTEGRAL_TYPE_P (TREE_TYPE (@0))
1437 && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0))
1438 && operand_equal_p (@1, build_low_bits_mask (TREE_TYPE (@1),
1439 TYPE_PRECISION (type)), 0))
1440 (convert @0)))
1441
1442
1443 /* (X /[ex] A) * A -> X. */
1444 (simplify
1445 (mult (convert? (exact_div @0 @1)) @1)
1446 /* Look through a sign-changing conversion. */
1447 (convert @0))
1448
1449 /* Canonicalization of binary operations. */
1450
1451 /* Convert X + -C into X - C. */
1452 (simplify
1453 (plus @0 REAL_CST@1)
1454 (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1)))
1455 (with { tree tem = fold_unary (NEGATE_EXPR, type, @1); }
1456 (if (!TREE_OVERFLOW (tem) || !flag_trapping_math)
1457 (minus @0 { tem; })))))
1458
1459 /* Convert x+x into x*2.0. */
1460 (simplify
1461 (plus @0 @0)
1462 (if (SCALAR_FLOAT_TYPE_P (type))
1463 (mult @0 { build_real (type, dconst2); })))
1464
1465 (simplify
1466 (minus integer_zerop @1)
1467 (negate @1))
1468
1469 /* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check whether
1470 ARG0 is zero and X + ARG0 reduces to X, since that would mean
1471 (-ARG1 + ARG0) reduces to -ARG1. */
1472 (simplify
1473 (minus real_zerop@0 @1)
1474 (if (fold_real_zero_addition_p (type, @0, 0))
1475 (negate @1)))
1476
1477 /* Transform x * -1 into -x. */
1478 (simplify
1479 (mult @0 integer_minus_onep)
1480 (negate @0))
1481
1482 /* COMPLEX_EXPR and REALPART/IMAGPART_EXPR cancellations. */
1483 (simplify
1484 (complex (realpart @0) (imagpart @0))
1485 @0)
1486 (simplify
1487 (realpart (complex @0 @1))
1488 @0)
1489 (simplify
1490 (imagpart (complex @0 @1))
1491 @1)
1492
1493 /* Sometimes we only care about half of a complex expression. */
1494 (simplify
1495 (realpart (convert?:s (conj:s @0)))
1496 (convert (realpart @0)))
1497 (simplify
1498 (imagpart (convert?:s (conj:s @0)))
1499 (convert (negate (imagpart @0))))
1500 (for part (realpart imagpart)
1501 (for op (plus minus)
1502 (simplify
1503 (part (convert?:s@2 (op:s @0 @1)))
1504 (convert (op (part @0) (part @1))))))
1505 (simplify
1506 (realpart (convert?:s (CEXPI:s @0)))
1507 (convert (COS @0)))
1508 (simplify
1509 (imagpart (convert?:s (CEXPI:s @0)))
1510 (convert (SIN @0)))
1511
1512 /* conj(conj(x)) -> x */
1513 (simplify
1514 (conj (convert? (conj @0)))
1515 (if (tree_nop_conversion_p (TREE_TYPE (@0), type))
1516 (convert @0)))
1517
1518 /* conj({x,y}) -> {x,-y} */
1519 (simplify
1520 (conj (convert?:s (complex:s @0 @1)))
1521 (with { tree itype = TREE_TYPE (type); }
1522 (complex (convert:itype @0) (negate (convert:itype @1)))))
1523
1524 /* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */
1525 (for bswap (BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 BUILT_IN_BSWAP64)
1526 (simplify
1527 (bswap (bswap @0))
1528 @0)
1529 (simplify
1530 (bswap (bit_not (bswap @0)))
1531 (bit_not @0))
1532 (for bitop (bit_xor bit_ior bit_and)
1533 (simplify
1534 (bswap (bitop:c (bswap @0) @1))
1535 (bitop @0 (bswap @1)))))
1536
1537
1538 /* Combine COND_EXPRs and VEC_COND_EXPRs. */
1539
1540 /* Simplify constant conditions.
1541 Only optimize constant conditions when the selected branch
1542 has the same type as the COND_EXPR. This avoids optimizing
1543 away "c ? x : throw", where the throw has a void type.
1544 Note that we cannot throw away the fold-const.c variant nor
1545 this one as we depend on doing this transform before possibly
1546 A ? B : B -> B triggers and the fold-const.c one can optimize
1547 0 ? A : B to B even if A has side-effects. Something
1548 genmatch cannot handle. */
1549 (simplify
1550 (cond INTEGER_CST@0 @1 @2)
1551 (if (integer_zerop (@0))
1552 (if (!VOID_TYPE_P (TREE_TYPE (@2)) || VOID_TYPE_P (type))
1553 @2)
1554 (if (!VOID_TYPE_P (TREE_TYPE (@1)) || VOID_TYPE_P (type))
1555 @1)))
1556 (simplify
1557 (vec_cond VECTOR_CST@0 @1 @2)
1558 (if (integer_all_onesp (@0))
1559 @1
1560 (if (integer_zerop (@0))
1561 @2)))
1562
1563 (for cnd (cond vec_cond)
1564 /* A ? B : (A ? X : C) -> A ? B : C. */
1565 (simplify
1566 (cnd @0 (cnd @0 @1 @2) @3)
1567 (cnd @0 @1 @3))
1568 (simplify
1569 (cnd @0 @1 (cnd @0 @2 @3))
1570 (cnd @0 @1 @3))
1571
1572 /* A ? B : B -> B. */
1573 (simplify
1574 (cnd @0 @1 @1)
1575 @1)
1576
1577 /* !A ? B : C -> A ? C : B. */
1578 (simplify
1579 (cnd (logical_inverted_value truth_valued_p@0) @1 @2)
1580 (cnd @0 @2 @1)))
1581
1582 /* A + (B vcmp C ? 1 : 0) -> A - (B vcmp C), since vector comparisons
1583 return all-1 or all-0 results. */
1584 /* ??? We could instead convert all instances of the vec_cond to negate,
1585 but that isn't necessarily a win on its own. */
1586 (simplify
1587 (plus:c @3 (view_convert? (vec_cond @0 integer_each_onep@1 integer_zerop@2)))
1588 (if (VECTOR_TYPE_P (type)
1589 && TYPE_VECTOR_SUBPARTS (type) == TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0))
1590 && (TYPE_MODE (TREE_TYPE (type))
1591 == TYPE_MODE (TREE_TYPE (TREE_TYPE (@0)))))
1592 (minus @3 (view_convert @0))))
1593
1594 /* ... likewise A - (B vcmp C ? 1 : 0) -> A + (B vcmp C). */
1595 (simplify
1596 (minus @3 (view_convert? (vec_cond @0 integer_each_onep@1 integer_zerop@2)))
1597 (if (VECTOR_TYPE_P (type)
1598 && TYPE_VECTOR_SUBPARTS (type) == TYPE_VECTOR_SUBPARTS (TREE_TYPE (@0))
1599 && (TYPE_MODE (TREE_TYPE (type))
1600 == TYPE_MODE (TREE_TYPE (TREE_TYPE (@0)))))
1601 (plus @3 (view_convert @0))))
1602
1603
1604 /* Simplifications of comparisons. */
1605
1606 /* See if we can reduce the magnitude of a constant involved in a
1607 comparison by changing the comparison code. This is a canonicalization
1608 formerly done by maybe_canonicalize_comparison_1. */
1609 (for cmp (le gt)
1610 acmp (lt ge)
1611 (simplify
1612 (cmp @0 INTEGER_CST@1)
1613 (if (tree_int_cst_sgn (@1) == -1)
1614 (acmp @0 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
1615 (for cmp (ge lt)
1616 acmp (gt le)
1617 (simplify
1618 (cmp @0 INTEGER_CST@1)
1619 (if (tree_int_cst_sgn (@1) == 1)
1620 (acmp @0 { wide_int_to_tree (TREE_TYPE (@1), wi::sub (@1, 1)); }))))
1621
1622
1623 /* We can simplify a logical negation of a comparison to the
1624 inverted comparison. As we cannot compute an expression
1625 operator using invert_tree_comparison we have to simulate
1626 that with expression code iteration. */
1627 (for cmp (tcc_comparison)
1628 icmp (inverted_tcc_comparison)
1629 ncmp (inverted_tcc_comparison_with_nans)
1630 /* Ideally we'd like to combine the following two patterns
1631 and handle some more cases by using
1632 (logical_inverted_value (cmp @0 @1))
1633 here but for that genmatch would need to "inline" that.
1634 For now implement what forward_propagate_comparison did. */
1635 (simplify
1636 (bit_not (cmp @0 @1))
1637 (if (VECTOR_TYPE_P (type)
1638 || (INTEGRAL_TYPE_P (type) && TYPE_PRECISION (type) == 1))
1639 /* Comparison inversion may be impossible for trapping math,
1640 invert_tree_comparison will tell us. But we can't use
1641 a computed operator in the replacement tree thus we have
1642 to play the trick below. */
1643 (with { enum tree_code ic = invert_tree_comparison
1644 (cmp, HONOR_NANS (@0)); }
1645 (if (ic == icmp)
1646 (icmp @0 @1)
1647 (if (ic == ncmp)
1648 (ncmp @0 @1))))))
1649 (simplify
1650 (bit_xor (cmp @0 @1) integer_truep)
1651 (with { enum tree_code ic = invert_tree_comparison
1652 (cmp, HONOR_NANS (@0)); }
1653 (if (ic == icmp)
1654 (icmp @0 @1)
1655 (if (ic == ncmp)
1656 (ncmp @0 @1))))))
1657
1658 /* Transform comparisons of the form X - Y CMP 0 to X CMP Y.
1659 ??? The transformation is valid for the other operators if overflow
1660 is undefined for the type, but performing it here badly interacts
1661 with the transformation in fold_cond_expr_with_comparison which
1662 attempts to synthetize ABS_EXPR. */
1663 (for cmp (eq ne)
1664 (simplify
1665 (cmp (minus@2 @0 @1) integer_zerop)
1666 (if (single_use (@2))
1667 (cmp @0 @1))))
1668
1669 /* Transform comparisons of the form X * C1 CMP 0 to X CMP 0 in the
1670 signed arithmetic case. That form is created by the compiler
1671 often enough for folding it to be of value. One example is in
1672 computing loop trip counts after Operator Strength Reduction. */
1673 (for cmp (simple_comparison)
1674 scmp (swapped_simple_comparison)
1675 (simplify
1676 (cmp (mult @0 INTEGER_CST@1) integer_zerop@2)
1677 /* Handle unfolded multiplication by zero. */
1678 (if (integer_zerop (@1))
1679 (cmp @1 @2)
1680 (if (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
1681 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0)))
1682 /* If @1 is negative we swap the sense of the comparison. */
1683 (if (tree_int_cst_sgn (@1) < 0)
1684 (scmp @0 @2)
1685 (cmp @0 @2))))))
1686
1687 /* Simplify comparison of something with itself. For IEEE
1688 floating-point, we can only do some of these simplifications. */
1689 (simplify
1690 (eq @0 @0)
1691 (if (! FLOAT_TYPE_P (TREE_TYPE (@0))
1692 || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0))))
1693 { constant_boolean_node (true, type); }))
1694 (for cmp (ge le)
1695 (simplify
1696 (cmp @0 @0)
1697 (eq @0 @0)))
1698 (for cmp (ne gt lt)
1699 (simplify
1700 (cmp @0 @0)
1701 (if (cmp != NE_EXPR
1702 || ! FLOAT_TYPE_P (TREE_TYPE (@0))
1703 || ! HONOR_NANS (TYPE_MODE (TREE_TYPE (@0))))
1704 { constant_boolean_node (false, type); })))
1705 (for cmp (unle unge uneq)
1706 (simplify
1707 (cmp @0 @0)
1708 { constant_boolean_node (true, type); }))
1709 (simplify
1710 (ltgt @0 @0)
1711 (if (!flag_trapping_math)
1712 { constant_boolean_node (false, type); }))
1713
1714 /* Fold ~X op ~Y as Y op X. */
1715 (for cmp (simple_comparison)
1716 (simplify
1717 (cmp (bit_not @0) (bit_not @1))
1718 (cmp @1 @0)))
1719
1720 /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */
1721 (for cmp (simple_comparison)
1722 scmp (swapped_simple_comparison)
1723 (simplify
1724 (cmp (bit_not @0) CONSTANT_CLASS_P@1)
1725 (if (TREE_CODE (@1) == INTEGER_CST || TREE_CODE (@1) == VECTOR_CST)
1726 (scmp @0 (bit_not @1)))))
1727
1728 (for cmp (simple_comparison)
1729 /* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */
1730 (simplify
1731 (cmp (convert@2 @0) (convert? @1))
1732 (if (FLOAT_TYPE_P (TREE_TYPE (@0))
1733 && (DECIMAL_FLOAT_TYPE_P (TREE_TYPE (@2))
1734 == DECIMAL_FLOAT_TYPE_P (TREE_TYPE (@0)))
1735 && (DECIMAL_FLOAT_TYPE_P (TREE_TYPE (@2))
1736 == DECIMAL_FLOAT_TYPE_P (TREE_TYPE (@1))))
1737 (with
1738 {
1739 tree type1 = TREE_TYPE (@1);
1740 if (TREE_CODE (@1) == REAL_CST && !DECIMAL_FLOAT_TYPE_P (type1))
1741 {
1742 REAL_VALUE_TYPE orig = TREE_REAL_CST (@1);
1743 if (TYPE_PRECISION (type1) > TYPE_PRECISION (float_type_node)
1744 && exact_real_truncate (TYPE_MODE (float_type_node), &orig))
1745 type1 = float_type_node;
1746 if (TYPE_PRECISION (type1) > TYPE_PRECISION (double_type_node)
1747 && exact_real_truncate (TYPE_MODE (double_type_node), &orig))
1748 type1 = double_type_node;
1749 }
1750 tree newtype
1751 = (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (type1)
1752 ? TREE_TYPE (@0) : type1);
1753 }
1754 (if (TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (newtype))
1755 (cmp (convert:newtype @0) (convert:newtype @1))))))
1756
1757 (simplify
1758 (cmp @0 REAL_CST@1)
1759 /* IEEE doesn't distinguish +0 and -0 in comparisons. */
1760 (switch
1761 /* a CMP (-0) -> a CMP 0 */
1762 (if (REAL_VALUE_MINUS_ZERO (TREE_REAL_CST (@1)))
1763 (cmp @0 { build_real (TREE_TYPE (@1), dconst0); }))
1764 /* x != NaN is always true, other ops are always false. */
1765 (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))
1766 && ! HONOR_SNANS (@1))
1767 { constant_boolean_node (cmp == NE_EXPR, type); })
1768 /* Fold comparisons against infinity. */
1769 (if (REAL_VALUE_ISINF (TREE_REAL_CST (@1))
1770 && MODE_HAS_INFINITIES (TYPE_MODE (TREE_TYPE (@1))))
1771 (with
1772 {
1773 REAL_VALUE_TYPE max;
1774 enum tree_code code = cmp;
1775 bool neg = REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1));
1776 if (neg)
1777 code = swap_tree_comparison (code);
1778 }
1779 (switch
1780 /* x > +Inf is always false, if with ignore sNANs. */
1781 (if (code == GT_EXPR
1782 && ! HONOR_SNANS (@0))
1783 { constant_boolean_node (false, type); })
1784 (if (code == LE_EXPR)
1785 /* x <= +Inf is always true, if we don't case about NaNs. */
1786 (if (! HONOR_NANS (@0))
1787 { constant_boolean_node (true, type); }
1788 /* x <= +Inf is the same as x == x, i.e. !isnan(x). */
1789 (eq @0 @0)))
1790 /* x == +Inf and x >= +Inf are always equal to x > DBL_MAX. */
1791 (if (code == EQ_EXPR || code == GE_EXPR)
1792 (with { real_maxval (&max, neg, TYPE_MODE (TREE_TYPE (@0))); }
1793 (if (neg)
1794 (lt @0 { build_real (TREE_TYPE (@0), max); })
1795 (gt @0 { build_real (TREE_TYPE (@0), max); }))))
1796 /* x < +Inf is always equal to x <= DBL_MAX. */
1797 (if (code == LT_EXPR)
1798 (with { real_maxval (&max, neg, TYPE_MODE (TREE_TYPE (@0))); }
1799 (if (neg)
1800 (ge @0 { build_real (TREE_TYPE (@0), max); })
1801 (le @0 { build_real (TREE_TYPE (@0), max); }))))
1802 /* x != +Inf is always equal to !(x > DBL_MAX). */
1803 (if (code == NE_EXPR)
1804 (with { real_maxval (&max, neg, TYPE_MODE (TREE_TYPE (@0))); }
1805 (if (! HONOR_NANS (@0))
1806 (if (neg)
1807 (ge @0 { build_real (TREE_TYPE (@0), max); })
1808 (le @0 { build_real (TREE_TYPE (@0), max); }))
1809 (if (neg)
1810 (bit_xor (lt @0 { build_real (TREE_TYPE (@0), max); })
1811 { build_one_cst (type); })
1812 (bit_xor (gt @0 { build_real (TREE_TYPE (@0), max); })
1813 { build_one_cst (type); }))))))))))
1814
1815 /* If this is a comparison of a real constant with a PLUS_EXPR
1816 or a MINUS_EXPR of a real constant, we can convert it into a
1817 comparison with a revised real constant as long as no overflow
1818 occurs when unsafe_math_optimizations are enabled. */
1819 (if (flag_unsafe_math_optimizations)
1820 (for op (plus minus)
1821 (simplify
1822 (cmp (op @0 REAL_CST@1) REAL_CST@2)
1823 (with
1824 {
1825 tree tem = const_binop (op == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR,
1826 TREE_TYPE (@1), @2, @1);
1827 }
1828 (if (tem && !TREE_OVERFLOW (tem))
1829 (cmp @0 { tem; }))))))
1830
1831 /* Likewise, we can simplify a comparison of a real constant with
1832 a MINUS_EXPR whose first operand is also a real constant, i.e.
1833 (c1 - x) < c2 becomes x > c1-c2. Reordering is allowed on
1834 floating-point types only if -fassociative-math is set. */
1835 (if (flag_associative_math)
1836 (simplify
1837 (cmp (minus REAL_CST@0 @1) REAL_CST@2)
1838 (with { tree tem = const_binop (MINUS_EXPR, TREE_TYPE (@1), @0, @2); }
1839 (if (tem && !TREE_OVERFLOW (tem))
1840 (cmp { tem; } @1)))))
1841
1842 /* Fold comparisons against built-in math functions. */
1843 (if (flag_unsafe_math_optimizations
1844 && ! flag_errno_math)
1845 (for sq (SQRT)
1846 (simplify
1847 (cmp (sq @0) REAL_CST@1)
1848 (switch
1849 (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1)))
1850 (switch
1851 /* sqrt(x) < y is always false, if y is negative. */
1852 (if (cmp == EQ_EXPR || cmp == LT_EXPR || cmp == LE_EXPR)
1853 { constant_boolean_node (false, type); })
1854 /* sqrt(x) > y is always true, if y is negative and we
1855 don't care about NaNs, i.e. negative values of x. */
1856 (if (cmp == NE_EXPR || !HONOR_NANS (@0))
1857 { constant_boolean_node (true, type); })
1858 /* sqrt(x) > y is the same as x >= 0, if y is negative. */
1859 (ge @0 { build_real (TREE_TYPE (@0), dconst0); })))
1860 (if (cmp == GT_EXPR || cmp == GE_EXPR)
1861 (with
1862 {
1863 REAL_VALUE_TYPE c2;
1864 real_arithmetic (&c2, MULT_EXPR,
1865 &TREE_REAL_CST (@1), &TREE_REAL_CST (@1));
1866 real_convert (&c2, TYPE_MODE (TREE_TYPE (@0)), &c2);
1867 }
1868 (if (REAL_VALUE_ISINF (c2))
1869 /* sqrt(x) > y is x == +Inf, when y is very large. */
1870 (if (HONOR_INFINITIES (@0))
1871 (eq @0 { build_real (TREE_TYPE (@0), c2); })
1872 { constant_boolean_node (false, type); })
1873 /* sqrt(x) > c is the same as x > c*c. */
1874 (cmp @0 { build_real (TREE_TYPE (@0), c2); }))))
1875 (if (cmp == LT_EXPR || cmp == LE_EXPR)
1876 (with
1877 {
1878 REAL_VALUE_TYPE c2;
1879 real_arithmetic (&c2, MULT_EXPR,
1880 &TREE_REAL_CST (@1), &TREE_REAL_CST (@1));
1881 real_convert (&c2, TYPE_MODE (TREE_TYPE (@0)), &c2);
1882 }
1883 (if (REAL_VALUE_ISINF (c2))
1884 (switch
1885 /* sqrt(x) < y is always true, when y is a very large
1886 value and we don't care about NaNs or Infinities. */
1887 (if (! HONOR_NANS (@0) && ! HONOR_INFINITIES (@0))
1888 { constant_boolean_node (true, type); })
1889 /* sqrt(x) < y is x != +Inf when y is very large and we
1890 don't care about NaNs. */
1891 (if (! HONOR_NANS (@0))
1892 (ne @0 { build_real (TREE_TYPE (@0), c2); }))
1893 /* sqrt(x) < y is x >= 0 when y is very large and we
1894 don't care about Infinities. */
1895 (if (! HONOR_INFINITIES (@0))
1896 (ge @0 { build_real (TREE_TYPE (@0), dconst0); }))
1897 /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */
1898 (if (GENERIC)
1899 (truth_andif
1900 (ge @0 { build_real (TREE_TYPE (@0), dconst0); })
1901 (ne @0 { build_real (TREE_TYPE (@0), c2); }))))
1902 /* sqrt(x) < c is the same as x < c*c, if we ignore NaNs. */
1903 (if (! HONOR_NANS (@0))
1904 (cmp @0 { build_real (TREE_TYPE (@0), c2); })
1905 /* sqrt(x) < c is the same as x >= 0 && x < c*c. */
1906 (if (GENERIC)
1907 (truth_andif
1908 (ge @0 { build_real (TREE_TYPE (@0), dconst0); })
1909 (cmp @0 { build_real (TREE_TYPE (@0), c2); }))))))))))))
1910
1911 /* Unordered tests if either argument is a NaN. */
1912 (simplify
1913 (bit_ior (unordered @0 @0) (unordered @1 @1))
1914 (if (types_match (@0, @1))
1915 (unordered @0 @1)))
1916 (simplify
1917 (bit_and (ordered @0 @0) (ordered @1 @1))
1918 (if (types_match (@0, @1))
1919 (ordered @0 @1)))
1920 (simplify
1921 (bit_ior:c (unordered @0 @0) (unordered:c@2 @0 @1))
1922 @2)
1923 (simplify
1924 (bit_and:c (ordered @0 @0) (ordered:c@2 @0 @1))
1925 @2)
1926
1927 /* -A CMP -B -> B CMP A. */
1928 (for cmp (tcc_comparison)
1929 scmp (swapped_tcc_comparison)
1930 (simplify
1931 (cmp (negate @0) (negate @1))
1932 (if (FLOAT_TYPE_P (TREE_TYPE (@0))
1933 || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
1934 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))
1935 (scmp @0 @1)))
1936 (simplify
1937 (cmp (negate @0) CONSTANT_CLASS_P@1)
1938 (if (FLOAT_TYPE_P (TREE_TYPE (@0))
1939 || (ANY_INTEGRAL_TYPE_P (TREE_TYPE (@0))
1940 && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (@0))))
1941 (with { tree tem = fold_unary (NEGATE_EXPR, TREE_TYPE (@0), @1); }
1942 (if (tem && !TREE_OVERFLOW (tem))
1943 (scmp @0 { tem; }))))))
1944
1945 /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */
1946 (for op (eq ne)
1947 (simplify
1948 (op (abs @0) zerop@1)
1949 (op @0 @1)))
1950
1951 /* From fold_sign_changed_comparison and fold_widened_comparison. */
1952 (for cmp (simple_comparison)
1953 (simplify
1954 (cmp (convert@0 @00) (convert?@1 @10))
1955 (if (TREE_CODE (TREE_TYPE (@0)) == INTEGER_TYPE
1956 /* Disable this optimization if we're casting a function pointer
1957 type on targets that require function pointer canonicalization. */
1958 && !(targetm.have_canonicalize_funcptr_for_compare ()
1959 && TREE_CODE (TREE_TYPE (@00)) == POINTER_TYPE
1960 && TREE_CODE (TREE_TYPE (TREE_TYPE (@00))) == FUNCTION_TYPE)
1961 && single_use (@0))
1962 (if (TYPE_PRECISION (TREE_TYPE (@00)) == TYPE_PRECISION (TREE_TYPE (@0))
1963 && (TREE_CODE (@10) == INTEGER_CST
1964 || (@1 != @10 && types_match (TREE_TYPE (@10), TREE_TYPE (@00))))
1965 && (TYPE_UNSIGNED (TREE_TYPE (@00)) == TYPE_UNSIGNED (TREE_TYPE (@0))
1966 || cmp == NE_EXPR
1967 || cmp == EQ_EXPR)
1968 && (POINTER_TYPE_P (TREE_TYPE (@00)) == POINTER_TYPE_P (TREE_TYPE (@0))))
1969 /* ??? The special-casing of INTEGER_CST conversion was in the original
1970 code and here to avoid a spurious overflow flag on the resulting
1971 constant which fold_convert produces. */
1972 (if (TREE_CODE (@1) == INTEGER_CST)
1973 (cmp @00 { force_fit_type (TREE_TYPE (@00), wi::to_widest (@1), 0,
1974 TREE_OVERFLOW (@1)); })
1975 (cmp @00 (convert @1)))
1976
1977 (if (TYPE_PRECISION (TREE_TYPE (@0)) > TYPE_PRECISION (TREE_TYPE (@00)))
1978 /* If possible, express the comparison in the shorter mode. */
1979 (if ((cmp == EQ_EXPR || cmp == NE_EXPR
1980 || TYPE_UNSIGNED (TREE_TYPE (@0)) == TYPE_UNSIGNED (TREE_TYPE (@00)))
1981 && (types_match (TREE_TYPE (@10), TREE_TYPE (@00))
1982 || ((TYPE_PRECISION (TREE_TYPE (@00))
1983 >= TYPE_PRECISION (TREE_TYPE (@10)))
1984 && (TYPE_UNSIGNED (TREE_TYPE (@00))
1985 == TYPE_UNSIGNED (TREE_TYPE (@10))))
1986 || (TREE_CODE (@10) == INTEGER_CST
1987 && (TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
1988 || TREE_CODE (TREE_TYPE (@00)) == BOOLEAN_TYPE)
1989 && int_fits_type_p (@10, TREE_TYPE (@00)))))
1990 (cmp @00 (convert @10))
1991 (if (TREE_CODE (@10) == INTEGER_CST
1992 && TREE_CODE (TREE_TYPE (@00)) == INTEGER_TYPE
1993 && !int_fits_type_p (@10, TREE_TYPE (@00)))
1994 (with
1995 {
1996 tree min = lower_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
1997 tree max = upper_bound_in_type (TREE_TYPE (@10), TREE_TYPE (@00));
1998 bool above = integer_nonzerop (const_binop (LT_EXPR, type, max, @10));
1999 bool below = integer_nonzerop (const_binop (LT_EXPR, type, @10, min));
2000 }
2001 (if (above || below)
2002 (if (cmp == EQ_EXPR || cmp == NE_EXPR)
2003 { constant_boolean_node (cmp == EQ_EXPR ? false : true, type); }
2004 (if (cmp == LT_EXPR || cmp == LE_EXPR)
2005 { constant_boolean_node (above ? true : false, type); }
2006 (if (cmp == GT_EXPR || cmp == GE_EXPR)
2007 { constant_boolean_node (above ? false : true, type); }))))))))))))
2008
2009 (for cmp (eq ne)
2010 /* A local variable can never be pointed to by
2011 the default SSA name of an incoming parameter.
2012 SSA names are canonicalized to 2nd place. */
2013 (simplify
2014 (cmp addr@0 SSA_NAME@1)
2015 (if (SSA_NAME_IS_DEFAULT_DEF (@1)
2016 && TREE_CODE (SSA_NAME_VAR (@1)) == PARM_DECL)
2017 (with { tree base = get_base_address (TREE_OPERAND (@0, 0)); }
2018 (if (TREE_CODE (base) == VAR_DECL
2019 && auto_var_in_fn_p (base, current_function_decl))
2020 (if (cmp == NE_EXPR)
2021 { constant_boolean_node (true, type); }
2022 { constant_boolean_node (false, type); }))))))
2023
2024 /* Equality compare simplifications from fold_binary */
2025 (for cmp (eq ne)
2026
2027 /* If we have (A | C) == D where C & ~D != 0, convert this into 0.
2028 Similarly for NE_EXPR. */
2029 (simplify
2030 (cmp (convert?@3 (bit_ior @0 INTEGER_CST@1)) INTEGER_CST@2)
2031 (if (tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0))
2032 && wi::bit_and_not (@1, @2) != 0)
2033 { constant_boolean_node (cmp == NE_EXPR, type); }))
2034
2035 /* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y. */
2036 (simplify
2037 (cmp (bit_xor @0 @1) integer_zerop)
2038 (cmp @0 @1))
2039
2040 /* (X ^ Y) == Y becomes X == 0.
2041 Likewise (X ^ Y) == X becomes Y == 0. */
2042 (simplify
2043 (cmp:c (bit_xor:c @0 @1) @0)
2044 (cmp @1 { build_zero_cst (TREE_TYPE (@1)); }))
2045
2046 /* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */
2047 (simplify
2048 (cmp (convert?@3 (bit_xor @0 INTEGER_CST@1)) INTEGER_CST@2)
2049 (if (tree_nop_conversion_p (TREE_TYPE (@3), TREE_TYPE (@0)))
2050 (cmp @0 (bit_xor @1 (convert @2)))))
2051
2052 (simplify
2053 (cmp (convert? addr@0) integer_zerop)
2054 (if (tree_single_nonzero_warnv_p (@0, NULL))
2055 { constant_boolean_node (cmp == NE_EXPR, type); })))
2056
2057 /* If we have (A & C) == C where C is a power of 2, convert this into
2058 (A & C) != 0. Similarly for NE_EXPR. */
2059 (for cmp (eq ne)
2060 icmp (ne eq)
2061 (simplify
2062 (cmp (bit_and@2 @0 integer_pow2p@1) @1)
2063 (icmp @2 { build_zero_cst (TREE_TYPE (@0)); })))
2064
2065 /* If we have (A & C) != 0 where C is the sign bit of A, convert
2066 this into A < 0. Similarly for (A & C) == 0 into A >= 0. */
2067 (for cmp (eq ne)
2068 ncmp (ge lt)
2069 (simplify
2070 (cmp (bit_and (convert?@2 @0) integer_pow2p@1) integer_zerop)
2071 (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
2072 && (TYPE_PRECISION (TREE_TYPE (@0))
2073 == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
2074 && element_precision (@2) >= element_precision (@0)
2075 && wi::only_sign_bit_p (@1, element_precision (@0)))
2076 (with { tree stype = signed_type_for (TREE_TYPE (@0)); }
2077 (ncmp (convert:stype @0) { build_zero_cst (stype); })))))
2078
2079 /* When the addresses are not directly of decls compare base and offset.
2080 This implements some remaining parts of fold_comparison address
2081 comparisons but still no complete part of it. Still it is good
2082 enough to make fold_stmt not regress when not dispatching to fold_binary. */
2083 (for cmp (simple_comparison)
2084 (simplify
2085 (cmp (convert1?@2 addr@0) (convert2? addr@1))
2086 (with
2087 {
2088 HOST_WIDE_INT off0, off1;
2089 tree base0 = get_addr_base_and_unit_offset (TREE_OPERAND (@0, 0), &off0);
2090 tree base1 = get_addr_base_and_unit_offset (TREE_OPERAND (@1, 0), &off1);
2091 if (base0 && TREE_CODE (base0) == MEM_REF)
2092 {
2093 off0 += mem_ref_offset (base0).to_short_addr ();
2094 base0 = TREE_OPERAND (base0, 0);
2095 }
2096 if (base1 && TREE_CODE (base1) == MEM_REF)
2097 {
2098 off1 += mem_ref_offset (base1).to_short_addr ();
2099 base1 = TREE_OPERAND (base1, 0);
2100 }
2101 }
2102 (if (base0 && base1)
2103 (with
2104 {
2105 int equal = 2;
2106 if (decl_in_symtab_p (base0)
2107 && decl_in_symtab_p (base1))
2108 equal = symtab_node::get_create (base0)
2109 ->equal_address_to (symtab_node::get_create (base1));
2110 else if ((DECL_P (base0)
2111 || TREE_CODE (base0) == SSA_NAME
2112 || TREE_CODE (base0) == STRING_CST)
2113 && (DECL_P (base1)
2114 || TREE_CODE (base1) == SSA_NAME
2115 || TREE_CODE (base1) == STRING_CST))
2116 equal = (base0 == base1);
2117 }
2118 (if (equal == 1
2119 && (cmp == EQ_EXPR || cmp == NE_EXPR
2120 /* If the offsets are equal we can ignore overflow. */
2121 || off0 == off1
2122 || POINTER_TYPE_OVERFLOW_UNDEFINED
2123 /* Or if we compare using pointers to decls or strings. */
2124 || (POINTER_TYPE_P (TREE_TYPE (@2))
2125 && (DECL_P (base0) || TREE_CODE (base0) == STRING_CST))))
2126 (switch
2127 (if (cmp == EQ_EXPR)
2128 { constant_boolean_node (off0 == off1, type); })
2129 (if (cmp == NE_EXPR)
2130 { constant_boolean_node (off0 != off1, type); })
2131 (if (cmp == LT_EXPR)
2132 { constant_boolean_node (off0 < off1, type); })
2133 (if (cmp == LE_EXPR)
2134 { constant_boolean_node (off0 <= off1, type); })
2135 (if (cmp == GE_EXPR)
2136 { constant_boolean_node (off0 >= off1, type); })
2137 (if (cmp == GT_EXPR)
2138 { constant_boolean_node (off0 > off1, type); }))
2139 (if (equal == 0
2140 && DECL_P (base0) && DECL_P (base1)
2141 /* If we compare this as integers require equal offset. */
2142 && (!INTEGRAL_TYPE_P (TREE_TYPE (@2))
2143 || off0 == off1))
2144 (switch
2145 (if (cmp == EQ_EXPR)
2146 { constant_boolean_node (false, type); })
2147 (if (cmp == NE_EXPR)
2148 { constant_boolean_node (true, type); })))))))))
2149
2150 /* Non-equality compare simplifications from fold_binary */
2151 (for cmp (lt gt le ge)
2152 /* Comparisons with the highest or lowest possible integer of
2153 the specified precision will have known values. */
2154 (simplify
2155 (cmp (convert?@2 @0) INTEGER_CST@1)
2156 (if ((INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
2157 && tree_nop_conversion_p (TREE_TYPE (@2), TREE_TYPE (@0)))
2158 (with
2159 {
2160 tree arg1_type = TREE_TYPE (@1);
2161 unsigned int prec = TYPE_PRECISION (arg1_type);
2162 wide_int max = wi::max_value (arg1_type);
2163 wide_int signed_max = wi::max_value (prec, SIGNED);
2164 wide_int min = wi::min_value (arg1_type);
2165 }
2166 (switch
2167 (if (wi::eq_p (@1, max))
2168 (switch
2169 (if (cmp == GT_EXPR)
2170 { constant_boolean_node (false, type); })
2171 (if (cmp == GE_EXPR)
2172 (eq @2 @1))
2173 (if (cmp == LE_EXPR)
2174 { constant_boolean_node (true, type); })
2175 (if (cmp == LT_EXPR)
2176 (ne @2 @1))))
2177 (if (wi::eq_p (@1, min))
2178 (switch
2179 (if (cmp == LT_EXPR)
2180 { constant_boolean_node (false, type); })
2181 (if (cmp == LE_EXPR)
2182 (eq @2 @1))
2183 (if (cmp == GE_EXPR)
2184 { constant_boolean_node (true, type); })
2185 (if (cmp == GT_EXPR)
2186 (ne @2 @1))))
2187 (if (wi::eq_p (@1, max - 1))
2188 (switch
2189 (if (cmp == GT_EXPR)
2190 (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))
2191 (if (cmp == LE_EXPR)
2192 (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::add (@1, 1)); }))))
2193 (if (wi::eq_p (@1, min + 1))
2194 (switch
2195 (if (cmp == GE_EXPR)
2196 (ne @2 { wide_int_to_tree (TREE_TYPE (@1), wi::sub (@1, 1)); }))
2197 (if (cmp == LT_EXPR)
2198 (eq @2 { wide_int_to_tree (TREE_TYPE (@1), wi::sub (@1, 1)); }))))
2199 (if (wi::eq_p (@1, signed_max)
2200 && TYPE_UNSIGNED (arg1_type)
2201 /* We will flip the signedness of the comparison operator
2202 associated with the mode of @1, so the sign bit is
2203 specified by this mode. Check that @1 is the signed
2204 max associated with this sign bit. */
2205 && prec == GET_MODE_PRECISION (TYPE_MODE (arg1_type))
2206 /* signed_type does not work on pointer types. */
2207 && INTEGRAL_TYPE_P (arg1_type))
2208 /* The following case also applies to X < signed_max+1
2209 and X >= signed_max+1 because previous transformations. */
2210 (if (cmp == LE_EXPR || cmp == GT_EXPR)
2211 (with { tree st = signed_type_for (arg1_type); }
2212 (if (cmp == LE_EXPR)
2213 (ge (convert:st @0) { build_zero_cst (st); })
2214 (lt (convert:st @0) { build_zero_cst (st); }))))))))))
2215
2216 (for cmp (unordered ordered unlt unle ungt unge uneq ltgt)
2217 /* If the second operand is NaN, the result is constant. */
2218 (simplify
2219 (cmp @0 REAL_CST@1)
2220 (if (REAL_VALUE_ISNAN (TREE_REAL_CST (@1))
2221 && (cmp != LTGT_EXPR || ! flag_trapping_math))
2222 { constant_boolean_node (cmp == ORDERED_EXPR || cmp == LTGT_EXPR
2223 ? false : true, type); })))
2224
2225 /* bool_var != 0 becomes bool_var. */
2226 (simplify
2227 (ne @0 integer_zerop)
2228 (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE
2229 && types_match (type, TREE_TYPE (@0)))
2230 (non_lvalue @0)))
2231 /* bool_var == 1 becomes bool_var. */
2232 (simplify
2233 (eq @0 integer_onep)
2234 (if (TREE_CODE (TREE_TYPE (@0)) == BOOLEAN_TYPE
2235 && types_match (type, TREE_TYPE (@0)))
2236 (non_lvalue @0)))
2237 /* Do not handle
2238 bool_var == 0 becomes !bool_var or
2239 bool_var != 1 becomes !bool_var
2240 here because that only is good in assignment context as long
2241 as we require a tcc_comparison in GIMPLE_CONDs where we'd
2242 replace if (x == 0) with tem = ~x; if (tem != 0) which is
2243 clearly less optimal and which we'll transform again in forwprop. */
2244
2245
2246 /* Simplification of math builtins. These rules must all be optimizations
2247 as well as IL simplifications. If there is a possibility that the new
2248 form could be a pessimization, the rule should go in the canonicalization
2249 section that follows this one.
2250
2251 Rules can generally go in this section if they satisfy one of
2252 the following:
2253
2254 - the rule describes an identity
2255
2256 - the rule replaces calls with something as simple as addition or
2257 multiplication
2258
2259 - the rule contains unary calls only and simplifies the surrounding
2260 arithmetic. (The idea here is to exclude non-unary calls in which
2261 one operand is constant and in which the call is known to be cheap
2262 when the operand has that value.) */
2263
2264 (if (flag_unsafe_math_optimizations)
2265 /* Simplify sqrt(x) * sqrt(x) -> x. */
2266 (simplify
2267 (mult (SQRT@1 @0) @1)
2268 (if (!HONOR_SNANS (type))
2269 @0))
2270
2271 /* Simplify sqrt(x) * sqrt(y) -> sqrt(x*y). */
2272 (for root (SQRT CBRT)
2273 (simplify
2274 (mult (root:s @0) (root:s @1))
2275 (root (mult @0 @1))))
2276
2277 /* Simplify expN(x) * expN(y) -> expN(x+y). */
2278 (for exps (EXP EXP2 EXP10 POW10)
2279 (simplify
2280 (mult (exps:s @0) (exps:s @1))
2281 (exps (plus @0 @1))))
2282
2283 /* Simplify a/root(b/c) into a*root(c/b). */
2284 (for root (SQRT CBRT)
2285 (simplify
2286 (rdiv @0 (root:s (rdiv:s @1 @2)))
2287 (mult @0 (root (rdiv @2 @1)))))
2288
2289 /* Simplify x/expN(y) into x*expN(-y). */
2290 (for exps (EXP EXP2 EXP10 POW10)
2291 (simplify
2292 (rdiv @0 (exps:s @1))
2293 (mult @0 (exps (negate @1)))))
2294
2295 /* Special case, optimize logN(expN(x)) = x. */
2296 (for logs (LOG LOG2 LOG10 LOG10)
2297 exps (EXP EXP2 EXP10 POW10)
2298 (simplify
2299 (logs (exps @0))
2300 @0))
2301
2302 /* Optimize logN(func()) for various exponential functions. We
2303 want to determine the value "x" and the power "exponent" in
2304 order to transform logN(x**exponent) into exponent*logN(x). */
2305 (for logs (LOG LOG LOG LOG2 LOG2 LOG2 LOG10 LOG10)
2306 exps (EXP2 EXP10 POW10 EXP EXP10 POW10 EXP EXP2)
2307 (simplify
2308 (logs (exps @0))
2309 (with {
2310 tree x;
2311 switch (exps)
2312 {
2313 CASE_FLT_FN (BUILT_IN_EXP):
2314 /* Prepare to do logN(exp(exponent)) -> exponent*logN(e). */
2315 x = build_real_truncate (type, dconst_e ());
2316 break;
2317 CASE_FLT_FN (BUILT_IN_EXP2):
2318 /* Prepare to do logN(exp2(exponent)) -> exponent*logN(2). */
2319 x = build_real (type, dconst2);
2320 break;
2321 CASE_FLT_FN (BUILT_IN_EXP10):
2322 CASE_FLT_FN (BUILT_IN_POW10):
2323 /* Prepare to do logN(exp10(exponent)) -> exponent*logN(10). */
2324 {
2325 REAL_VALUE_TYPE dconst10;
2326 real_from_integer (&dconst10, VOIDmode, 10, SIGNED);
2327 x = build_real (type, dconst10);
2328 }
2329 break;
2330 default:
2331 gcc_unreachable ();
2332 }
2333 }
2334 (mult (logs { x; }) @0))))
2335
2336 (for logs (LOG LOG
2337 LOG2 LOG2
2338 LOG10 LOG10)
2339 exps (SQRT CBRT)
2340 (simplify
2341 (logs (exps @0))
2342 (with {
2343 tree x;
2344 switch (exps)
2345 {
2346 CASE_FLT_FN (BUILT_IN_SQRT):
2347 /* Prepare to do logN(sqrt(x)) -> 0.5*logN(x). */
2348 x = build_real (type, dconsthalf);
2349 break;
2350 CASE_FLT_FN (BUILT_IN_CBRT):
2351 /* Prepare to do logN(cbrt(x)) -> (1/3)*logN(x). */
2352 x = build_real_truncate (type, dconst_third ());
2353 break;
2354 default:
2355 gcc_unreachable ();
2356 }
2357 }
2358 (mult { x; } (logs @0)))))
2359
2360 /* logN(pow(x,exponent)) -> exponent*logN(x). */
2361 (for logs (LOG LOG2 LOG10)
2362 pows (POW)
2363 (simplify
2364 (logs (pows @0 @1))
2365 (mult @1 (logs @0))))
2366
2367 (for sqrts (SQRT)
2368 cbrts (CBRT)
2369 exps (EXP EXP2 EXP10 POW10)
2370 /* sqrt(expN(x)) -> expN(x*0.5). */
2371 (simplify
2372 (sqrts (exps @0))
2373 (exps (mult @0 { build_real (type, dconsthalf); })))
2374 /* cbrt(expN(x)) -> expN(x/3). */
2375 (simplify
2376 (cbrts (exps @0))
2377 (exps (mult @0 { build_real_truncate (type, dconst_third ()); })))))
2378
2379 /* cabs(x+0i) or cabs(0+xi) -> abs(x). */
2380 (simplify
2381 (CABS (complex:c @0 real_zerop@1))
2382 (abs @0))
2383
2384 /* Canonicalization of sequences of math builtins. These rules represent
2385 IL simplifications but are not necessarily optimizations.
2386
2387 The sincos pass is responsible for picking "optimal" implementations
2388 of math builtins, which may be more complicated and can sometimes go
2389 the other way, e.g. converting pow into a sequence of sqrts.
2390 We only want to do these canonicalizations before the pass has run. */
2391
2392 (if (flag_unsafe_math_optimizations && canonicalize_math_p ())
2393 /* Simplify tan(x) * cos(x) -> sin(x). */
2394 (simplify
2395 (mult:c (TAN:s @0) (COS:s @0))
2396 (SIN @0))
2397
2398 /* Simplify x * pow(x,c) -> pow(x,c+1). */
2399 (simplify
2400 (mult @0 (POW:s @0 REAL_CST@1))
2401 (if (!TREE_OVERFLOW (@1))
2402 (POW @0 (plus @1 { build_one_cst (type); }))))
2403
2404 /* Simplify sin(x) / cos(x) -> tan(x). */
2405 (simplify
2406 (rdiv (SIN:s @0) (COS:s @0))
2407 (TAN @0))
2408
2409 /* Simplify cos(x) / sin(x) -> 1 / tan(x). */
2410 (simplify
2411 (rdiv (COS:s @0) (SIN:s @0))
2412 (rdiv { build_one_cst (type); } (TAN @0)))
2413
2414 /* Simplify sin(x) / tan(x) -> cos(x). */
2415 (simplify
2416 (rdiv (SIN:s @0) (TAN:s @0))
2417 (if (! HONOR_NANS (@0)
2418 && ! HONOR_INFINITIES (@0))
2419 (cos @0)))
2420
2421 /* Simplify tan(x) / sin(x) -> 1.0 / cos(x). */
2422 (simplify
2423 (rdiv (TAN:s @0) (SIN:s @0))
2424 (if (! HONOR_NANS (@0)
2425 && ! HONOR_INFINITIES (@0))
2426 (rdiv { build_one_cst (type); } (COS @0))))
2427
2428 /* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */
2429 (simplify
2430 (mult (POW:s @0 @1) (POW:s @0 @2))
2431 (POW @0 (plus @1 @2)))
2432
2433 /* Simplify pow(x,y) * pow(z,y) -> pow(x*z,y). */
2434 (simplify
2435 (mult (POW:s @0 @1) (POW:s @2 @1))
2436 (POW (mult @0 @2) @1))
2437
2438 /* Simplify pow(x,c) / x -> pow(x,c-1). */
2439 (simplify
2440 (rdiv (POW:s @0 REAL_CST@1) @0)
2441 (if (!TREE_OVERFLOW (@1))
2442 (POW @0 (minus @1 { build_one_cst (type); }))))
2443
2444 /* Simplify x / pow (y,z) -> x * pow(y,-z). */
2445 (simplify
2446 (rdiv @0 (POW:s @1 @2))
2447 (mult @0 (POW @1 (negate @2))))
2448
2449 (for sqrts (SQRT)
2450 cbrts (CBRT)
2451 pows (POW)
2452 /* sqrt(sqrt(x)) -> pow(x,1/4). */
2453 (simplify
2454 (sqrts (sqrts @0))
2455 (pows @0 { build_real (type, dconst_quarter ()); }))
2456 /* sqrt(cbrt(x)) -> pow(x,1/6). */
2457 (simplify
2458 (sqrts (cbrts @0))
2459 (pows @0 { build_real_truncate (type, dconst_sixth ()); }))
2460 /* cbrt(sqrt(x)) -> pow(x,1/6). */
2461 (simplify
2462 (cbrts (sqrts @0))
2463 (pows @0 { build_real_truncate (type, dconst_sixth ()); }))
2464 /* cbrt(cbrt(x)) -> pow(x,1/9), iff x is nonnegative. */
2465 (simplify
2466 (cbrts (cbrts tree_expr_nonnegative_p@0))
2467 (pows @0 { build_real_truncate (type, dconst_ninth ()); }))
2468 /* sqrt(pow(x,y)) -> pow(|x|,y*0.5). */
2469 (simplify
2470 (sqrts (pows @0 @1))
2471 (pows (abs @0) (mult @1 { build_real (type, dconsthalf); })))
2472 /* cbrt(pow(x,y)) -> pow(x,y/3), iff x is nonnegative. */
2473 (simplify
2474 (cbrts (pows tree_expr_nonnegative_p@0 @1))
2475 (pows @0 (mult @1 { build_real_truncate (type, dconst_third ()); }))))
2476
2477 /* cabs(x+xi) -> fabs(x)*sqrt(2). */
2478 (simplify
2479 (CABS (complex @0 @0))
2480 (mult (abs @0) { build_real_truncate (type, dconst_sqrt2 ()); })))
2481
2482 /* If the real part is inf and the imag part is known to be
2483 nonnegative, return (inf + 0i). */
2484 (simplify
2485 (CPROJ (complex REAL_CST@0 tree_expr_nonnegative_p@1))
2486 (if (real_isinf (TREE_REAL_CST_PTR (@0)))
2487 (with
2488 {
2489 REAL_VALUE_TYPE rinf;
2490 real_inf (&rinf);
2491 }
2492 { build_complex (type, build_real (TREE_TYPE (type), rinf),
2493 build_zero_cst (TREE_TYPE (type))); })))
2494 /* If the imag part is inf, return (inf+I*copysign(0,imag)). */
2495 (simplify
2496 (CPROJ (complex @0 REAL_CST@1))
2497 (if (real_isinf (TREE_REAL_CST_PTR (@1)))
2498 (with
2499 {
2500 REAL_VALUE_TYPE rinf, rzero = dconst0;
2501 real_inf (&rinf);
2502 rzero.sign = TREE_REAL_CST_PTR (@1)->sign;
2503 }
2504 { build_complex (type, build_real (TREE_TYPE (type), rinf),
2505 build_real (TREE_TYPE (type), rzero)); })))
2506
2507
2508 /* Narrowing of arithmetic and logical operations.
2509
2510 These are conceptually similar to the transformations performed for
2511 the C/C++ front-ends by shorten_binary_op and shorten_compare. Long
2512 term we want to move all that code out of the front-ends into here. */
2513
2514 /* If we have a narrowing conversion of an arithmetic operation where
2515 both operands are widening conversions from the same type as the outer
2516 narrowing conversion. Then convert the innermost operands to a suitable
2517 unsigned type (to avoid introducing undefined behaviour), perform the
2518 operation and convert the result to the desired type. */
2519 (for op (plus minus)
2520 (simplify
2521 (convert (op:s (convert@2 @0) (convert@3 @1)))
2522 (if (INTEGRAL_TYPE_P (type)
2523 /* We check for type compatibility between @0 and @1 below,
2524 so there's no need to check that @1/@3 are integral types. */
2525 && INTEGRAL_TYPE_P (TREE_TYPE (@0))
2526 && INTEGRAL_TYPE_P (TREE_TYPE (@2))
2527 /* The precision of the type of each operand must match the
2528 precision of the mode of each operand, similarly for the
2529 result. */
2530 && (TYPE_PRECISION (TREE_TYPE (@0))
2531 == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
2532 && (TYPE_PRECISION (TREE_TYPE (@1))
2533 == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
2534 && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
2535 /* The inner conversion must be a widening conversion. */
2536 && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
2537 && types_match (@0, @1)
2538 && types_match (@0, type))
2539 (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
2540 (convert (op @0 @1))
2541 (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
2542 (convert (op (convert:utype @0) (convert:utype @1))))))))
2543
2544 /* This is another case of narrowing, specifically when there's an outer
2545 BIT_AND_EXPR which masks off bits outside the type of the innermost
2546 operands. Like the previous case we have to convert the operands
2547 to unsigned types to avoid introducing undefined behaviour for the
2548 arithmetic operation. */
2549 (for op (minus plus)
2550 (simplify
2551 (bit_and (op:s (convert@2 @0) (convert@3 @1)) INTEGER_CST@4)
2552 (if (INTEGRAL_TYPE_P (type)
2553 /* We check for type compatibility between @0 and @1 below,
2554 so there's no need to check that @1/@3 are integral types. */
2555 && INTEGRAL_TYPE_P (TREE_TYPE (@0))
2556 && INTEGRAL_TYPE_P (TREE_TYPE (@2))
2557 /* The precision of the type of each operand must match the
2558 precision of the mode of each operand, similarly for the
2559 result. */
2560 && (TYPE_PRECISION (TREE_TYPE (@0))
2561 == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
2562 && (TYPE_PRECISION (TREE_TYPE (@1))
2563 == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
2564 && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
2565 /* The inner conversion must be a widening conversion. */
2566 && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
2567 && types_match (@0, @1)
2568 && (tree_int_cst_min_precision (@4, TYPE_SIGN (TREE_TYPE (@0)))
2569 <= TYPE_PRECISION (TREE_TYPE (@0)))
2570 && (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0))
2571 || tree_int_cst_sgn (@4) >= 0))
2572 (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
2573 (with { tree ntype = TREE_TYPE (@0); }
2574 (convert (bit_and (op @0 @1) (convert:ntype @4))))
2575 (with { tree utype = unsigned_type_for (TREE_TYPE (@0)); }
2576 (convert (bit_and (op (convert:utype @0) (convert:utype @1))
2577 (convert:utype @4))))))))
2578
2579 /* Transform (@0 < @1 and @0 < @2) to use min,
2580 (@0 > @1 and @0 > @2) to use max */
2581 (for op (lt le gt ge)
2582 ext (min min max max)
2583 (simplify
2584 (bit_and (op:s @0 @1) (op:s @0 @2))
2585 (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
2586 (op @0 (ext @1 @2)))))
2587