* go.test/go-test.exp (go-set-goarch): Enable tests on s390[x].
[official-gcc.git] / gcc / match.pd
blob826ceb477f031caa514088327bafa3c5c3a9ccc1
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 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.
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.
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.
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/>.  */
26 /* Generic tree predicates we inherit.  */
27 (define_predicates
28    integer_onep integer_zerop integer_all_onesp
29    real_zerop real_onep
30    CONSTANT_CLASS_P
31    tree_expr_nonnegative_p)
34 /* Simplifications of operations with one constant operand and
35    simplifications to constants or single values.  */
37 (for op (plus pointer_plus minus bit_ior bit_xor)
38   (simplify
39     (op @0 integer_zerop)
40     (non_lvalue @0)))
42 /* Simplify x - x.
43    This is unsafe for certain floats even in non-IEEE formats.
44    In IEEE, it is unsafe because it does wrong for NaNs.
45    Also note that operand_equal_p is always false if an operand
46    is volatile.  */
47 (simplify
48   (minus @0 @0)
49   (if (!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type)))
50    { build_zero_cst (type); }))
52 (simplify
53   (mult @0 integer_zerop@1)
54   @1)
56 /* Make sure to preserve divisions by zero.  This is the reason why
57    we don't simplify x / x to 1 or 0 / x to 0.  */
58 (for op (mult trunc_div ceil_div floor_div round_div exact_div)
59   (simplify
60     (op @0 integer_onep)
61     (non_lvalue @0)))
63 /* Same applies to modulo operations, but fold is inconsistent here
64    and simplifies 0 % x to 0, only preserving literal 0 % 0.  */
65 (for op (ceil_mod floor_mod round_mod trunc_mod)
66  /* 0 % X is always zero.  */
67  (simplify
68   (op integer_zerop@0 @1)
69   /* But not for 0 % 0 so that we can get the proper warnings and errors.  */
70   (if (!integer_zerop (@1))
71    @0))
72  /* X % 1 is always zero.  */
73  (simplify
74   (op @0 integer_onep)
75   { build_zero_cst (type); }))
77 /* x | ~0 -> ~0  */
78 (simplify
79   (bit_ior @0 integer_all_onesp@1)
80   @1)
82 /* x & 0 -> 0  */
83 (simplify
84   (bit_and @0 integer_zerop@1)
85   @1)
87 /* x ^ x -> 0 */
88 (simplify
89   (bit_xor @0 @0)
90   { build_zero_cst (type); })
92 /* Canonicalize X ^ ~0 to ~X.  */
93 (simplify
94   (bit_xor @0 integer_all_onesp@1)
95   (bit_not @0))
97 /* x & ~0 -> x  */
98 (simplify
99  (bit_and @0 integer_all_onesp)
100   (non_lvalue @0))
102 /* x & x -> x,  x | x -> x  */
103 (for bitop (bit_and bit_ior)
104  (simplify
105   (bitop @0 @0)
106   (non_lvalue @0)))
108 (simplify
109  (abs (negate @0))
110  (abs @0))
111 (simplify
112  (abs tree_expr_nonnegative_p@0)
113  @0)
116 /* Simplifications of conversions.  */
118 /* Basic strip-useless-type-conversions / strip_nops.  */
119 (for cvt (convert view_convert float fix_trunc)
120  (simplify
121   (cvt @0)
122   (if ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@0)))
123        || (GENERIC && type == TREE_TYPE (@0)))
124    @0)))
126 /* Contract view-conversions.  */
127 (simplify
128   (view_convert (view_convert @0))
129   (view_convert @0))
131 /* For integral conversions with the same precision or pointer
132    conversions use a NOP_EXPR instead.  */
133 (simplify
134   (view_convert @0)
135   (if ((INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
136        && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
137        && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0)))
138    (convert @0)))
140 /* Strip inner integral conversions that do not change precision or size.  */
141 (simplify
142   (view_convert (convert@0 @1))
143   (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
144        && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
145        && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
146        && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))))
147    (view_convert @1)))
149 /* Re-association barriers around constants and other re-association
150    barriers can be removed.  */
151 (simplify
152  (paren CONSTANT_CLASS_P@0)
153  @0)
154 (simplify
155  (paren (paren@1 @0))
156  @1)