Lines Matching +full:test2 +full:. +full:zeros

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.
5 Copyright (C) 2014-2018 Free Software Foundation, Inc.
6 Contributed by Richard Biener <rguenther@suse.de>
7 and Prathamesh Kulkarni <bilbotheelffriend@gmail.com>
9 This file is part of GCC.
14 version.
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 for more details.
22 along with GCC; see the file COPYING3. If not see
23 <http://www.gnu.org/licenses/>. */
26 /* Generic tree predicates we inherit. */
39 /* Operator lists. */
51 #include "cfn-operators.pd"
55 "l" return a long and those prefixed with "ll" return a long long.
61 X<FN>L for all long double functions, in the same order. */
79 it is not a suitable replacement for convert? in all cases. */
89 /* This one has to be last, or it shadows the others. */
94 simplifications to constants or single values. */
111 /* See if ARG1 is zero and X + ARG1 reduces to X.
112 Likewise if the operands are reversed. */
118 /* See if ARG1 is zero and X - ARG1 reduces to X. */
124 /* Simplify x - x.
125 This is unsafe for certain floats even in non-IEEE formats.
126 In IEEE, it is unsafe because it does wrong for NaNs.
128 is volatile. */
141 /* Maybe fold x * 0 to 0. The expressions aren't the same
142 when x is NaN, since x * 0 is also NaN. Nor are they the
143 same in modes with signed zeros, since multiplying a
144 negative value by 0 gives -0, not +0. */
150 /* In IEEE floating point, x*1 is not equivalent to x for snans.
151 Likewise for complex arithmetic with signed zeros. */
159 /* Transform x * -1.0 into -x. */
170 /* Transform (X > 0.0 ? 1.0 : -1.0) into copysign(1, X). */
171 /* Transform (X >= 0.0 ? 1.0 : -1.0) into copysign(1, X). */
172 /* Transform (X < 0.0 ? 1.0 : -1.0) into copysign(1,-X). */
173 /* Transform (X <= 0.0 ? 1.0 : -1.0) into copysign(1,-X). */
185 /* Transform (X > 0.0 ? -1.0 : 1.0) into copysign(1,-X). */
186 /* Transform (X >= 0.0 ? -1.0 : 1.0) into copysign(1,-X). */
187 /* Transform (X < 0.0 ? -1.0 : 1.0) into copysign(1,X). */
188 /* Transform (X <= 0.0 ? -1.0 : 1.0) into copysign(1,X). */
201 /* Transform X * copysign (1.0, X) into abs(X). */
207 /* Transform X * copysign (1.0, -X) into -abs(X). */
213 /* Transform copysign (CST, X) into copysign (ABS(CST), X). */
219 /* X * 1, X / 1 -> X. */
225 /* (A / (1 << B)) -> (A >> B).
226 Only for unsigned A. For signed A, this would not preserve rounding
227 toward zero.
228 For example: (-1 / ( 1 << B)) != -1 >> B. */
239 traps enables better optimizations than these anyway. */
241 /* 0 / X is always zero. */
244 /* But not for 0 / 0 so that we can get the proper warnings and errors. */
247 /* X / -1 is -X. */
252 /* X / X is one. */
255 /* But not for 0 / 0 so that we can get the proper warnings and errors.
256 And not for _Fract types where we can't build 1. */
259 /* X / abs (X) is X < 0 ? -1 : 1. */
266 /* X / -X is -1. */
274 TRUNC_DIV_EXPR. Rewrite into the latter in this case. */
281 /* Combine two successive divisions. Note that combining ceil_div
282 and floor_div is trickier and combining round_div even more so. */
297 /* Combine successive multiplications. Similar to above, but handling
298 overflow is different. */
307 otherwise undefined overflow implies that @0 must be zero. */
312 NaNs or Infinities. */
321 NaNs or Infinities. */
343 /* In IEEE floating point, x/1 is not equivalent to x for snans. */
349 /* In IEEE floating point, x/-1 is not equivalent to -x for snans. */
356 /* Convert (A/B)/C to A/(B*C). */
361 /* Canonicalize x / (C1 * y) to (x * C2) / y. */
374 /* Simplify x / (- y) to -x / y. */
392 reciprocal. This does not have the same rounding properties,
393 so only do this if -freciprocal-math. We can actually
395 tell if it is or not in a portable manner. */
412 /* 0 % X is always zero. */
415 /* But not for 0 % 0 so that we can get the proper warnings and errors. */
418 /* X % 1 is always zero. */
422 /* X % -1 is zero. */
427 /* X % X is zero. */
430 /* But not for 0 % 0 so that we can get the proper warnings and errors. */
433 /* (X % Y) % Y is just X % Y. */
437 /* From extract_muldiv_1: (X * C1) % C2 is zero if C1 is a multiple of C2. */
446 /* X % -C is the same as X % C. */
453 /* Avoid this transformation if C is INT_MIN, i.e. C == -C. */
457 /* X % -Y is the same as X % Y. */
466 INT_MIN % -(-1) into invalid INT_MIN % -1. */
472 /* X - (X / Y) * Y is the same as X % Y. */
479 i.e. "X % C" into "X & (C - 1)", if X and C are positive.
481 to A & ((C << N) - 1). */
495 /* Simplify (unsigned t * 2)/2 -> unsigned t & 0x7FFFFFFF. */
504 /* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */
510 /* Simplify (t * 2) / 2) -> t. */
519 /* Simplify cos(-x) and cos(|x|) -> cos(x). Similarly for cosh. */
524 /* Simplify pow(-x, y) and pow(|x|,y) -> pow(x,y) if y is an even integer. */
531 /* Likewise for powi. */
537 /* Strip negate and abs from both operands of hypot. */
545 /* copysign(-x, y) and copysign(abs(x), y) -> copysign(x, y). */
551 /* abs(x)*abs(x) -> x*x. Should be valid for all types. */
556 /* cos(copysign(x, y)) -> cos(x). Similarly for cosh. */
563 /* pow(copysign(x, y), z) -> pow(x, z) if z is an even integer. */
571 /* Likewise for powi. */
581 /* hypot(copysign(x, y), z) -> hypot(x, z). */
585 /* hypot(x, copysign(y, z)) -> hypot(x, y). */
590 /* copysign(x, CST) -> [-]abs (x). */
598 /* copysign(copysign(x, y), z) -> copysign(x, z). */
604 /* copysign(x,y)*copysign(x,y) -> x*x. */
610 /* ccos(-x) -> ccos(x). Similarly for ccosh. */
616 /* cabs(-x) and cos(conj(x)) -> cabs(x). */
631 into ((1 << C) >> x). */
643 /* Fold (C1/X)*C2 into (C1*C2)/X. */
653 /* Simplify ~X & X as zero. */
667 (x == 0 & y == 0) -> (x | typeof(x)(y)) == 0.
668 (x != 0 | y != 0) -> (x | typeof(x)(y)) != 0. */
676 (x == -1 & y == -1) -> (x & typeof(x)(y)) == -1.
677 (x != -1 | y != -1) -> (x & typeof(x)(y)) != -1. */
685 /* Fold (A & ~B) - (A & B) into (A ^ B) - B. */
694 /* Fold (A & B) - (A & ~B) into B - (A ^ B). */
699 /* Simplify (X & ~Y) |^+ (~X & Y) -> X ^ Y. */
750 /* Simplify (~X & Y) to X ^ Y if we know that (X & ~Y) is 0. */
759 /* X % Y is smaller than Y. */
799 /* Canonicalize X ^ ~0 to ~X. */
815 /* x & C -> x if we know that x & ~C == 0. */
914 simplifications. */
930 /* Convert ~X ^ ~Y to X ^ Y. */
937 /* Convert ~X ^ C to X ^ ~C. */
943 /* Fold (X & Y) ^ Y and (X ^ Y) & Y as ~X & Y. */
951 operands are another bit-wise operation with a common input. If so,
953 constants are involved. For example, convert
955 Further simplification will occur if B and C are constants. */
964 /* Some simple reassociation for bit operations, also handled in reassoc. */
1003 /* A few cases of fold-const.c negate_expr_p predicate. */
1019 ways. */
1037 /* -(A + B) -> (-B) - A. */
1044 /* -(A - B) -> B - A. */
1057 /* A - B -> A + (-B) if B is easily negatable. */
1064 when profitable.
1066 binary operation result instead of to the operands. This allows
1067 to combine successive conversions and bitwise binary operations.
1068 We combine the above two cases by using a conditional convert. */
1076 /* ??? This transform conflicts with fold-const.c doing
1079 in c). This folds extension into the BIT_AND_EXPR.
1080 Restrict it to GIMPLE to avoid endless recursions. */
1083 after hoisting the conversion the operation will be narrower. */
1086 mode. */
1089 of its mode. */
1111 /* Combine successive equal operations with constants. */
1117 folded to a constant. */
1120 to a constant. This can happen if @0 or @1 is a POLY_INT_CST and if
1122 compile time. Try folding one of @0 or @1 with @2 to see whether
1123 that combination can be decided at compile time.
1126 oscillation. */
1135 of the truth_valued_p and logical_inverted_value predicates. */
1156 /* X & !X -> 0. */
1160 /* X | !X and X ^ !X -> 1, , if X is truth-valued. */
1165 /* X ==/!= !X is false/true. */
1176 /* Convert ~ (-A) to A - 1. */
1183 /* Convert - (~A) to A + 1. */
1188 /* Convert ~ (A - 1) or ~ (A + -1) to -A. */
1200 /* Part of convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
1210 /* Otherwise prefer ~(X ^ Y) to ~X ^ Y as more canonical. */
1221 /* Fold A - (A & B) into ~B & A. */
1235 x * C EQ/NE y * C into x EQ/NE y. */
1245 x * C EQ/NE y * C into x EQ/NE y. */
1270 /* (X - 1U) <= INT_MAX-1U into (int) X > 0. */
1283 /* X / 4 < Y / 4 iff X < Y when the division is known to be exact. */
1290 /* X / C1 op C2 into a simple range test. */
1344 /* X + Z < Y + Z is the same as X < Y when there is no overflow. */
1351 /* For equality and subtraction, this is also true with wrapping overflow. */
1360 /* X - Z < Y - Z is the same as X < Y when there is no overflow. */
1367 /* For equality and subtraction, this is also true with wrapping overflow. */
1375 /* And for pointers... */
1387 /* Z - X < Z - Y is the same as Y < X when there is no overflow. */
1394 /* For equality and subtraction, this is also true with wrapping overflow. */
1402 /* And for pointers... */
1414 /* X + Y < Y is the same as X < 0 when there is no overflow. */
1423 /* For equality, this is also true with wrapping overflow. */
1441 /* X - Y < X is the same as Y > 0 when there is no overflow.
1442 For equality, this is also true with wrapping overflow. */
1454 (X / Y) == 0 -> X < Y if X, Y are unsigned.
1455 (X / Y) != 0 -> X >= Y, if X, Y are unsigned. */
1461 /* Complex ==/!= is allowed, but not </>=. */
1466 /* X == C - X can never be true if C is odd. */
1474 possibly set. */
1480 /* Slightly extended version, do not make it recursive to keep it cheap. */
1487 an equivalent to get_nonzero_bits yet. */
1493 /* X == C (or X & Z == Y | C) is impossible if ~nonzero(X) & C != 0. */
1505 and 0's otherwise.
1543 /* Associate (p +p off1) +p off2 as (p +p (off1 + off2)). */
1558 /* Conditionally look through a sign-changing conversion. */
1572 ... = ptr p+ tem;
1574 ... = ptr & ~algn; */
1580 /* Try folding difference of addresses. */
1610 alignment. */
1626 /* We can't reassociate at all for saturating types. */
1629 /* Contract negates. */
1633 /* Apply STRIP_NOPS on the negate. */
1659 happen without overflow. */
1684 or fixed-point plus or minus because of saturation to +-Inf. */
1689 irrespective of overflow issues. */
1711 /* More cases are handled with comparisons. */
1729 scalars. */
1736 /* If one of the types wraps, use that one. */
1739 forever if something doesn't simplify into a constant. */
1751 with (a - 1) + INT_MIN. */
1758 /* X+INT_MAX+1 is X-INT_MIN. */
1762 /* Last resort, use some unsigned type. */
1816 overflow in P + A.
1817 E.g. T=size_t, A=(unsigned)429497295, P>0.
1820 is no overflow. */
1831 one is correct. */
1839 thus sign-extended if necessary. */
1843 we don't want to diagnose overflow here. */
1858 overflow in P + A.
1859 E.g. T=size_t, A=(unsigned)429497295, P>0.
1862 is no overflow. */
1878 one is correct. */
1886 thus sign-extended if necessary. */
1890 we don't want to diagnose overflow here. */
1908 overflow in P + A.
1909 E.g. T=size_t, A=(unsigned)429497295, P>0.
1912 is no overflow. */
1930 one is correct. */
1940 thus sign-extended if necessary. */
1944 we don't want to diagnose overflow here. */
1948 /* (A * C) +- (B * C) -> (A+-B) * C and (A * C) +- A -> A * (C+-1).
1949 Modeled after fold_plusminus_mult_expr. */
1961 original operand (but not on both). */
1964 /* We cannot generate constant 1 for fract. */
1985 /* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax(). */
1991 /* min(max(x,y),y) -> y. */
1995 /* max(min(x,y),y) -> y. */
1999 /* max(a,-a) -> abs(a). */
2006 /* min(a,-a) -> -abs(a). */
2036 /* max (a, a + CST) -> a + CST where CST is positive. */
2037 /* max (a, a + CST) -> a where CST is negative. */
2045 /* min (a, a + CST) -> a where CST is positive. */
2046 /* min (a, a + CST) -> a + CST where CST is negative. */
2055 and the outer convert demotes the expression back to x's type. */
2066 /* If either argument is NaN, return the other one. Avoid the
2067 transformation if we get (and honor) a signalling NaN. */
2071 && (!HONOR_SNANS (@1) || !TREE_REAL_CST (@1).signalling))
2073 /* Convert fmin/fmax to MIN_EXPR/MAX_EXPR. C99 requires these
2074 functions to return the numeric arg if the other one is NaN.
2076 is set. C99 doesn't require -0.0 to be handled, so we don't have to
2077 worry about it either. */
2138 /* Simplifications of shift and rotates. */
2145 /* Optimize -1 >> x for arithmetic right shifts. */
2152 /* Optimize (x >> c) << c into x & (-1<<c). */
2159 types. */
2174 if vector2 is uniform. */
2183 Y is 0. Similarly for X >> Y. */
2198 RROTATE_EXPR by a new constant. */
2205 /* Turn (a OP c1) OP c2 into a OP (c1+c2). */
2217 being well defined. */
2237 if CST2 != 0. */
2252 if the new mask might be further optimized. */
2278 zero extension. */
2287 /* See if we can shorten the right shift. */
2290 /* Otherwise X >> C1 is all zeros, so we'll optimize
2292 is all ones. */
2303 possible, unless MASK masks them all away. In that
2304 case the shift needs to be converted into logical shift. */
2315 /* ((X << 16) & 0xff00) is (X, 0). */
2323 mode's mask. */
2339 (X {&,^,|} C2) >> C1 into (X >> C1) & (C2 >> C1). */
2348 /* ~(~X >> Y) -> X >> Y (for arithmetic shift). */
2373 /* Simplifications of conversions. */
2375 /* Basic strip-useless-type-conversions / strip_nops. */
2383 /* Contract view-conversions. */
2389 conversions use a NOP_EXPR instead. */
2398 zero-extend while keeping the same size (for bool-to-char). */
2410 barriers can be removed. */
2418 /* Handle cases of two conversions in a row. */
2450 conversion is needed. */
2462 (for integers). Avoid this if the final type is a pointer since
2463 then we sometimes need the middle conversion. */
2471 replace that by a single zero-extension. Likewise if the
2473 intermediate conversion. */
2490 initial and intermediate types differ. */
2504 canonicalized as bitwise and of a mask. */
2505 (if (GIMPLE /* PR70366: doing this in GENERIC breaks -Wconversion. */
2517 floating-point conversion. */
2526 masks off bits outside the final type (and nothing else). */
2537 /* (X /[ex] A) * A -> X. */
2542 /* Canonicalization of binary operations. */
2544 /* Convert X + -C into X - C. */
2552 /* Convert x+x into x*2. */
2560 /* 0 - X -> -X. */
2568 /* (ARG0 - ARG1) is the same as (-ARG1 + ARG0). So check whether
2570 (-ARG1 + ARG0) reduces to -ARG1. */
2576 /* Transform x * -1 into -x. */
2581 /* Reassociate (X * CST) * Y to (X * Y) * CST. This does not introduce
2582 signed overflow for CST != 0 && CST != -1. */
2591 number. */
2595 /* COMPLEX_EXPR and REALPART/IMAGPART_EXPR cancellations. */
2606 /* Sometimes we only care about half of a complex expression. */
2637 /* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */
2651 /* Combine COND_EXPRs and VEC_COND_EXPRs. */
2653 /* Simplify constant conditions.
2655 has the same type as the COND_EXPR. This avoids optimizing
2656 away "c ? x : throw", where the throw has a void type.
2657 Note that we cannot throw away the fold-const.c variant nor
2659 A ? B : B -> B triggers and the fold-const.c one can optimize
2660 0 ? A : B to B even if A has side-effects. Something
2661 genmatch cannot handle. */
2676 /* Simplification moved from fold_cond_expr_with_comparison. It may also
2677 be extended. */
2682 1) Conversions are type widening from smaller type.
2683 2) Const c1 equals to c2 after canonicalizing comparison.
2684 3) Comparison has tree code LT, LE, GT or GE.
2687 x. It also makes sense here because simplifying across multiple
2688 referred var is always benefitial for complicated cases.
2691 (cond (eq (convert1? x) c1) (convert2? x) c2) -> (cond (eq x c1) c1 c2). */
2716 /* X <= Y - 1 equals to X < Y. */
2719 /* X > Y - 1 equals to X >= Y. */
2725 /* X < Y + 1 equals to X <= Y. */
2728 /* X >= Y + 1 equals to X > Y. */
2756 1) OP is PLUS or MINUS.
2757 2) CMP is LT, LE, GT or GE.
2758 3) C3 == (C1 op C2), and computation doesn't have undefined behavior.
2763 integer zero. In this case,
2766 B) Const c1 may not equal to (C3 op' C2). In this case we also
2768 code.
2772 type promotion. In order to match&simplify it here, the IR needs
2773 to be cleaned up by other optimizers, i.e, VRP. */
2780 /* Check if it is special case A). */
2807 /* To simplify this pattern, we require c3 = (c1 op c2). Here we
2809 the inverted operator of op. Make sure overflow doesn't happen
2810 if it is undefined. */
2819 /* Check if c1 equals to real_c1. Boundary condition is handled
2820 by adjusting comparison operation if necessary. */
2824 /* X <= Y - 1 equals to X < Y. */
2827 /* X > Y - 1 equals to X >= Y. */
2834 /* X < Y + 1 equals to X <= Y. */
2837 /* X >= Y + 1 equals to X > Y. */
2858 /* A ? B : (A ? X : C) -> A ? B : C. */
2865 /* A ? B : (!A ? C : X) -> A ? B : C. */
2867 would generate matching code for conditions in separate stmts only.
2869 from if-conversion. */
2889 /* A ? B : B -> B. */
2894 /* !A ? B : C -> A ? C : B. */
2900 return all -1 or all 0 results. */
2902 but that isn't necessarily a win on its own. */
2912 /* ... likewise A - (B vcmp C ? 1 : 0) -> A + (B vcmp C ? -1 : 0). */
2923 /* Simplifications of comparisons. */
2926 comparison by changing the comparison code. This is a canonicalization
2927 formerly done by maybe_canonicalize_comparison_1. */
2943 inverted comparison. As we cannot compute an expression
2945 that with expression code iteration. */
2952 here but for that genmatch would need to "inline" that.
2953 For now implement what forward_propagate_comparison did. */
2959 invert_tree_comparison will tell us. But we can't use
2961 to play the trick below. */
2977 /* Transform comparisons of the form X - Y CMP 0 to X CMP Y.
2981 attempts to synthetize ABS_EXPR. */
2990 signed arithmetic case. That form is created by the compiler
2991 often enough for folding it to be of value. One example is in
2992 computing loop trip counts after Operator Strength Reduction. */
2997 /* Handle unfolded multiplication by zero. */
3003 /* If @1 is negative we swap the sense of the comparison. */
3008 /* Simplify comparison of something with itself. For IEEE
3009 floating-point, we can only do some of these simplifications. */
3038 /* Fold ~X op ~Y as Y op X. */
3045 /* Fold ~X op C as X op' ~C, where op' is the swapped comparison. */
3055 /* Fold (double)float1 CMP (double)float2 into float1 CMP float2. */
3085 /* IEEE doesn't distinguish +0 and -0 in comparisons. */
3090 /* x != NaN is always true, other ops are always false. */
3094 /* Fold comparisons against infinity. */
3106 /* x > +Inf is always false, if we ignore NaNs or exceptions. */
3111 /* x <= +Inf is always true, if we don't care about NaNs. */
3114 /* x <= +Inf is the same as x == x, i.e. !isnan(x), but this loses
3115 an "invalid" exception. */
3119 for == this introduces an exception for x a NaN. */
3126 /* x < +Inf is always equal to x <= DBL_MAX. */
3133 an exception for x a NaN so use an unordered comparison. */
3147 occurs when unsafe_math_optimizations are enabled. */
3161 a MINUS_EXPR whose first operand is also a real constant, i.e.
3162 (c1 - x) < c2 becomes x > c1-c2. Reordering is allowed on
3163 floating-point types only if -fassociative-math is set. */
3171 /* Fold comparisons against built-in math functions. */
3180 /* sqrt(x) < y is always false, if y is negative. */
3184 don't care about NaNs, i.e. negative values of x. */
3187 /* sqrt(x) > y is the same as x >= 0, if y is negative. */
3191 /* sqrt(x) < 0 is always false. */
3194 /* sqrt(x) >= 0 is always true if we don't care about NaNs. */
3197 /* sqrt(x) <= 0 -> x == 0. */
3200 /* Otherwise sqrt(x) cmp 0 -> x cmp 0. Here cmp can be >=, >,
3201 == or !=. In the last case:
3205 if x is negative or NaN. Due to -funsafe-math-optimizations,
3206 the results for other x follow from natural arithmetic. */
3217 /* sqrt(x) > y is x == +Inf, when y is very large. */
3221 /* sqrt(x) > c is the same as x > c*c. */
3234 value and we don't care about NaNs or Infinities. */
3238 don't care about NaNs. */
3242 don't care about Infinities. */
3245 /* sqrt(x) < y is x >= 0 && x != +Inf, when y is large. */
3250 /* sqrt(x) < c is the same as x < c*c, if we ignore NaNs. */
3253 /* sqrt(x) < c is the same as x >= 0 && x < c*c. */
3258 /* Transform sqrt(x) cmp sqrt(y) -> x cmp y. */
3264 /* Optimize various special cases of (FTYPE) N CMP CST. */
3278 NaNs. qNaNs are ok in == or != context.
3280 -fno-signaling-nans. */
3285 only one mantissa bit. */
3291 -fno-trapping-math. */
3314 /* Optimize cases when CST is outside of ITYPE's range. */
3321 /* Remove cast if CST is an integer representable by ITYPE. */
3328 (FTYPE) N != CST -> 1. */
3331 /* Otherwise replace with sensible integer constant. */
3338 /* Fold A /[ex] B CMP C to A CMP B * C. */
3371 /* Unordered tests if either argument is a NaN. */
3387 /* Simple range test simplifications. */
3388 /* A < B || A >= B -> true. */
3390 test2 (ge gt ge ne eq ne)
3392 (bit_ior:c (test1 @0 @1) (test2 @0 @1))
3396 /* A < B && A >= B -> false. */
3398 test2 (ge gt eq gt eq gt)
3400 (bit_and:c (test1 @0 @1) (test2 @0 @1))
3412 consider them here.
3433 /* -A CMP -B -> B CMP A. */
3451 /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */
3457 /* From fold_sign_changed_comparison and fold_widened_comparison.
3458 FIXME: the lack of symmetry is disturbing. */
3464 type on targets that require function pointer canonicalization. */
3465 && !(targetm.have_canonicalize_funcptr_for_compare ()
3478 constant which fold_convert produces. */
3485 /* If possible, express the comparison in the shorter mode. */
3519 the default SSA name of an incoming parameter.
3520 SSA names are canonicalized to 2nd place. */
3535 /* If we have (A | C) == D where C & ~D != 0, convert this into 0.
3536 Similarly for NE_EXPR. */
3543 /* (X ^ Y) == 0 becomes X == Y, and (X ^ Y) != 0 becomes X != Y. */
3548 /* (X ^ Y) == Y becomes X == 0.
3549 Likewise (X ^ Y) == X becomes Y == 0. */
3554 /* (X ^ C1) op C2 can be rewritten as X op (C1 ^ C2). */
3566 (A & C) != 0. Similarly for NE_EXPR. */
3574 convert this into a shift followed by ANDing with D. */
3592 this into A < 0. Similarly for (A & C) == 0 into A >= 0. */
3605 this into a right shift or sign extension followed by ANDing with C. */
3620 sign extension followed by AND with C will achieve the effect. */
3623 /* When the addresses are not directly of decls compare base and offset.
3625 comparisons but still no complete part of it. Still it is good
3626 enough to make fold_stmt not regress when not dispatching to fold_binary. */
3637 off0 += mem_ref_offset (base0).force_shwi ();
3642 off1 += mem_ref_offset (base1).force_shwi ();
3652 of other vars etc. */
3671 /* If the offsets are equal we can ignore overflow. */
3674 /* Or if we compare using pointers to decls or strings. */
3692 /* If we compare this as integers require equal offset. */
3701 /* Simplify pointer equality compares using PTA. */
3709 /* PR70920: Transform (intptr_t)x eq/ne CST to x eq/ne (typeof x) CST.
3710 and (typeof ptr_cst) x eq/ne ptr_cst to x eq/ne (typeof x) CST.
3711 Disable the transform if either operand is pointer to function.
3712 This broke pr22051-2.c for arm where function pointer
3713 canonicalizaion is not wanted. */
3730 the specified precision will have known values. */
3780 specified by this mode. Check that @1 is the signed
3781 max associated with this sign bit. */
3783 /* signed_type does not work on pointer types. */
3786 and X >= signed_max+1 because previous transformations. */
3794 /* If the second operand is NaN, the result is constant. */
3802 /* bool_var != 0 becomes bool_var. */
3808 /* bool_var == 1 becomes bool_var. */
3820 clearly less optimal and which we'll transform again in forwprop. */
3822 /* When one argument is a constant, overflow detection can be simplified.
3824 ADD_OVERFLOW detection in tree-ssa-math-opts.c.
3839 /* To detect overflow in unsigned A - B, A < B is simpler than A - B > A.
3840 However, the detection logic for SUB_OVERFLOW in tree-ssa-math-opts.c
3841 expects the long form, so we restrict the transformation for now. */
3851 /* Testing for overflow is unnecessary if we already know the result. */
3869 /* For unsigned operands, -1 / B < A checks whether A * B would overflow.
3870 Simplify it to __builtin_mul_overflow (A, B, <unused>). */
3879 /* Simplification of math builtins. These rules must all be optimizations
3880 as well as IL simplifications. If there is a possibility that the new
3882 section that follows this one.
3893 arithmetic. (The idea here is to exclude non-unary calls in which
3895 when the operand has that value.) */
3898 /* Simplify sqrt(x) * sqrt(x) -> x. */
3905 /* Simplify (A / C) +- (B / C) -> (A +- B) / C. */
3911 /* Simplify sqrt(x) * sqrt(y) -> sqrt(x*y). */
3917 /* Simplify expN(x) * expN(y) -> expN(x+y). */
3923 /* Simplify a/root(b/c) into a*root(c/b). */
3929 /* Simplify x/expN(y) into x*expN(-y). */
3937 /* logN(expN(x)) -> x. */
3941 /* expN(logN(x)) -> x. */
3946 /* Optimize logN(func()) for various exponential functions. We
3948 order to transform logN(x**exponent) into exponent*logN(x). */
3959 /* Prepare to do logN(exp(exponent)) -> exponent*logN(e). */
3963 /* Prepare to do logN(exp2(exponent)) -> exponent*logN(2). */
3968 /* Prepare to do logN(exp10(exponent)) -> exponent*logN(10). */
3993 /* Prepare to do logN(sqrt(x)) -> 0.5*logN(x). */
3997 /* Prepare to do logN(cbrt(x)) -> (1/3)*logN(x). */
4006 /* logN(pow(x,exponent)) -> exponent*logN(x). */
4015 pow(C,x) -> exp2(log2(C)*x). */
4027 the use_exp2 case until after vectorization. It seems actually
4031 pessimization. */
4036 if (targetm.libc_has_function (function_c99_misc)
4051 /* pow(C,x)*expN(y) -> expN(logN(C)*x+y) if C > 0. */
4065 /* sqrt(expN(x)) -> expN(x*0.5). */
4069 /* cbrt(expN(x)) -> expN(x/3). */
4073 /* pow(expN(x), y) -> expN(x*y). */
4078 /* tan(atan(x)) -> x. */
4085 /* cabs(x+0i) or cabs(0+xi) -> abs(x). */
4090 /* trunc(trunc(x)) -> trunc(x), etc. */
4095 /* f(x) -> x if x is integer valued and f does nothing for such values. */
4101 /* hypot(x,0) and hypot(0,x) -> abs(x). */
4106 /* pow(1,x) -> 1. */
4112 /* copysign(x,x) -> x. */
4117 /* copysign(x,y) -> fabs(x) if y is nonnegative. */
4122 /* ldexp(0, x) -> 0. */
4126 /* ldexp(x, 0) -> x. */
4130 /* ldexp(x, y) -> x if x is +-Inf or NaN. */
4136 /* Canonicalization of sequences of math builtins. These rules represent
4137 IL simplifications but are not necessarily optimizations.
4141 the other way, e.g. converting pow into a sequence of sqrts.
4142 We only want to do these canonicalizations before the pass has run. */
4145 /* Simplify tan(x) * cos(x) -> sin(x). */
4150 /* Simplify x * pow(x,c) -> pow(x,c+1). */
4156 /* Simplify sin(x) / cos(x) -> tan(x). */
4161 /* Simplify cos(x) / sin(x) -> 1 / tan(x). */
4166 /* Simplify sin(x) / tan(x) -> cos(x). */
4173 /* Simplify tan(x) / sin(x) -> 1.0 / cos(x). */
4180 /* Simplify pow(x,y) * pow(x,z) -> pow(x,y+z). */
4185 /* Simplify pow(x,y) * pow(z,y) -> pow(x*z,y). */
4190 /* Simplify powi(x,y) * powi(z,y) -> powi(x*z,y). */
4195 /* Simplify pow(x,c) / x -> pow(x,c-1). */
4201 /* Simplify x / pow (y,z) -> x * pow(y,-z). */
4209 /* sqrt(sqrt(x)) -> pow(x,1/4). */
4213 /* sqrt(cbrt(x)) -> pow(x,1/6). */
4217 /* cbrt(sqrt(x)) -> pow(x,1/6). */
4221 /* cbrt(cbrt(x)) -> pow(x,1/9), iff x is nonnegative. */
4225 /* sqrt(pow(x,y)) -> pow(|x|,y*0.5). */
4229 /* cbrt(pow(x,y)) -> pow(x,y/3), iff x is nonnegative. */
4233 /* pow(sqrt(x),y) -> pow(x,y*0.5). */
4237 /* pow(cbrt(x),y) -> pow(x,y/3) iff x is nonnegative. */
4241 /* pow(pow(x,y),z) -> pow(x,y*z) iff x is nonnegative. */
4246 /* cabs(x+xi) -> fabs(x)*sqrt(2). */
4251 /* hypot(x,x) -> fabs(x)*sqrt(2). */
4256 /* cexp(x+yi) -> exp(x)*cexpi(y). */
4262 (if (targetm.libc_has_function (function_c99_math_complex))
4268 /* floor(x) -> trunc(x) if x is nonnegative. */
4290 /* truncl(extend(x)) -> extend(trunc(x)), etc., if x is a double. */
4311 /* truncl(extend(x)) and trunc(extend(x)) -> extend(truncf(x)), etc.,
4312 if x is a float. */
4314 && targetm.libc_has_function (function_c99_misc))
4321 /* llfloorl(extend(x)) -> llfloor(x), etc., if x is a double. */
4330 /* llfloorl(extend(x)) and llfloor(extend(x)) -> llfloorf(x), etc.,
4331 if x is a float. */
4338 /* xfloor(x) -> fix_trunc(x) if x is nonnegative. */
4345 /* xfloor(x) -> fix_trunc(x), etc., if x is integer valued. */
4353 /* xrint(x) -> fix_trunc(x), etc., if x is integer valued. */
4364 sizeof (int) == sizeof (long). */
4371 sizeof (long long) == sizeof (long). */
4378 /* cproj(x) -> x if we're ignoring infinities. */
4385 nonnegative, return (inf + 0i). */
4391 /* If the imag part is inf, return (inf+I*copysign(0,imag)). */
4407 /* pow(x,0) -> 1. */
4410 /* pow(x,1) -> x. */
4413 /* pow(x,-1) -> 1/x. */
4416 /* pow(x,0.5) -> sqrt(x). */
4421 /* pow(x,1/3) -> cbrt(x). */
4428 /* powi(1,x) -> 1. */
4436 /* powi(x,0) -> 1. */
4439 /* powi(x,1) -> x. */
4442 /* powi(x,-1) -> 1/x. */
4446 /* Narrowing of arithmetic and logical operations.
4449 the C/C++ front-ends by shorten_binary_op and shorten_compare. Long
4450 term we want to move all that code out of the front-ends into here. */
4454 narrowing conversion. Then convert the innermost operands to a suitable
4456 operation and convert the result to the desired type. */
4462 so there's no need to check that @1/@3 are integral types. */
4467 result. */
4471 /* The inner conversion must be a widening conversion. */
4476 integer from valueize. */
4486 operands. Like the previous case we have to convert the operands
4488 arithmetic operation. */
4494 so there's no need to check that @1/@3 are integral types. */
4499 result. */
4503 /* The inner conversion must be a widening conversion. */
4529 /* signbit(x) -> 0 if x is nonnegative. */
4534 /* signbit(x) -> x<0 if x doesn't have signed zeros. */
4539 /* Transform comparisons of the form X +- C1 CMP C2 to X CMP C2 -+ C1. */
4570 /* wi::ges_p (@2, 0) should be sufficient for a signed type. */
4586 /* Canonicalizations of BIT_FIELD_REFs. */
4600 /* On GIMPLE this should only apply to register arguments. */
4602 /* A bit-field-ref that referenced the full argument can be stripped. */
4605 /* Low-parts can be reduced to integral conversions.
4606 ??? The following doesn't work for PDP endian. */
4608 /* Don't even think about BITS_BIG_ENDIAN. */
4617 /* Simplify vector extracts. */
4643 /* Constructor elements can be subvectors. */
4654 /* We keep an exact subset of the constructor elements. */
4671 /* The bitfield references a single constructor element. */
4672 (if (k.is_constant (&const_k)
4684 not touching the extraction. */