* c-c++-common/ubsan/float-cast-overflow-6.c: Add i?86-*-* target.
[official-gcc.git] / gcc / match.pd
blob2057dccba46f164ff0c0a7e7b97e5a66ba0af31a
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)
33 /* Simplifications of operations with one constant operand and
34    simplifications to constants or single values.  */
36 (for op (plus pointer_plus minus bit_ior bit_xor)
37   (simplify
38     (op @0 integer_zerop)
39     (non_lvalue @0)))
41 /* Simplify x - x.
42    This is unsafe for certain floats even in non-IEEE formats.
43    In IEEE, it is unsafe because it does wrong for NaNs.
44    Also note that operand_equal_p is always false if an operand
45    is volatile.  */
46 (simplify
47   (minus @0 @0)
48   (if (!FLOAT_TYPE_P (type) || !HONOR_NANS (TYPE_MODE (type)))
49    { build_zero_cst (type); }))
51 (simplify
52   (mult @0 integer_zerop@1)
53   @1)
55 /* Make sure to preserve divisions by zero.  This is the reason why
56    we don't simplify x / x to 1 or 0 / x to 0.  */
57 (for op (mult trunc_div ceil_div floor_div round_div exact_div)
58   (simplify
59     (op @0 integer_onep)
60     (non_lvalue @0)))
62 /* Same applies to modulo operations, but fold is inconsistent here
63    and simplifies 0 % x to 0, only preserving literal 0 % 0.  */
64 (for op (ceil_mod floor_mod round_mod trunc_mod)
65  /* 0 % X is always zero.  */
66  (simplify
67   (op integer_zerop@0 @1)
68   /* But not for 0 % 0 so that we can get the proper warnings and errors.  */
69   (if (!integer_zerop (@1))
70    @0))
71  /* X % 1 is always zero.  */
72  (simplify
73   (op @0 integer_onep)
74   { build_zero_cst (type); }))
76 /* x | ~0 -> ~0  */
77 (simplify
78   (bit_ior @0 integer_all_onesp@1)
79   @1)
81 /* x & 0 -> 0  */
82 (simplify
83   (bit_and @0 integer_zerop@1)
84   @1)
86 /* x ^ x -> 0 */
87 (simplify
88   (bit_xor @0 @0)
89   { build_zero_cst (type); })
91 /* Canonicalize X ^ ~0 to ~X.  */
92 (simplify
93   (bit_xor @0 integer_all_onesp@1)
94   (bit_not @0))
96 /* x & ~0 -> x  */
97 (simplify
98  (bit_and @0 integer_all_onesp)
99   (non_lvalue @0))
101 /* x & x -> x,  x | x -> x  */
102 (for bitop (bit_and bit_ior)
103  (simplify
104   (bitop @0 @0)
105   (non_lvalue @0)))
108 /* Simplifications of conversions.  */
110 /* Basic strip-useless-type-conversions / strip_nops.  */
111 (for cvt (convert view_convert)
112  (simplify
113   (cvt @0)
114   (if ((GIMPLE && useless_type_conversion_p (type, TREE_TYPE (@0)))
115        || (GENERIC && type == TREE_TYPE (@0)))
116    @0)))
118 /* Contract view-conversions.  */
119 (simplify
120   (view_convert (view_convert @0))
121   (view_convert @0))
123 /* For integral conversions with the same precision or pointer
124    conversions use a NOP_EXPR instead.  */
125 (simplify
126   (view_convert @0)
127   (if ((INTEGRAL_TYPE_P (type) || POINTER_TYPE_P (type))
128        && (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
129        && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (@0)))
130    (convert @0)))
132 /* Strip inner integral conversions that do not change precision or size.  */
133 (simplify
134   (view_convert (convert@0 @1))
135   (if ((INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0)))
136        && (INTEGRAL_TYPE_P (TREE_TYPE (@1)) || POINTER_TYPE_P (TREE_TYPE (@1)))
137        && (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (TREE_TYPE (@1)))
138        && (TYPE_SIZE (TREE_TYPE (@0)) == TYPE_SIZE (TREE_TYPE (@1))))
139    (view_convert @1)))
141 /* Re-association barriers around constants and other re-association
142    barriers can be removed.  */
143 (simplify
144  (paren CONSTANT_CLASS_P@0)
145  @0)
146 (simplify
147  (paren (paren@1 @0))
148  @1)