xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/range.cc (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1*4c3eb207Smrg /* Misc range functions.
2*4c3eb207Smrg    Copyright (C) 2017-2020 Free Software Foundation, Inc.
3*4c3eb207Smrg    Contributed by Aldy Hernandez <aldyh@redhat.com>.
4*4c3eb207Smrg 
5*4c3eb207Smrg This file is part of GCC.
6*4c3eb207Smrg 
7*4c3eb207Smrg GCC is free software; you can redistribute it and/or modify it under
8*4c3eb207Smrg the terms of the GNU General Public License as published by the Free
9*4c3eb207Smrg Software Foundation; either version 3, or (at your option) any later
10*4c3eb207Smrg version.
11*4c3eb207Smrg 
12*4c3eb207Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13*4c3eb207Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
14*4c3eb207Smrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15*4c3eb207Smrg  for more details.
16*4c3eb207Smrg 
17*4c3eb207Smrg You should have received a copy of the GNU General Public License
18*4c3eb207Smrg along with GCC; see the file COPYING3.  If not see
19*4c3eb207Smrg <http://www.gnu.org/licenses/>.  */
20*4c3eb207Smrg 
21*4c3eb207Smrg #include "config.h"
22*4c3eb207Smrg #include "system.h"
23*4c3eb207Smrg #include "coretypes.h"
24*4c3eb207Smrg #include "backend.h"
25*4c3eb207Smrg #include "tree.h"
26*4c3eb207Smrg #include "gimple.h"
27*4c3eb207Smrg #include "gimple-pretty-print.h"
28*4c3eb207Smrg #include "fold-const.h"
29*4c3eb207Smrg #include "ssa.h"
30*4c3eb207Smrg #include "range.h"
31*4c3eb207Smrg 
32*4c3eb207Smrg value_range
range_zero(tree type)33*4c3eb207Smrg range_zero (tree type)
34*4c3eb207Smrg {
35*4c3eb207Smrg   return value_range (build_zero_cst (type), build_zero_cst (type));
36*4c3eb207Smrg }
37*4c3eb207Smrg 
38*4c3eb207Smrg value_range
range_nonzero(tree type)39*4c3eb207Smrg range_nonzero (tree type)
40*4c3eb207Smrg {
41*4c3eb207Smrg   return value_range (build_zero_cst (type), build_zero_cst (type),
42*4c3eb207Smrg 		      VR_ANTI_RANGE);
43*4c3eb207Smrg }
44*4c3eb207Smrg 
45*4c3eb207Smrg value_range
range_positives(tree type)46*4c3eb207Smrg range_positives (tree type)
47*4c3eb207Smrg {
48*4c3eb207Smrg   unsigned prec = TYPE_PRECISION (type);
49*4c3eb207Smrg   signop sign = TYPE_SIGN (type);
50*4c3eb207Smrg   return value_range (type, wi::zero (prec), wi::max_value (prec, sign));
51*4c3eb207Smrg }
52*4c3eb207Smrg 
53*4c3eb207Smrg value_range
range_negatives(tree type)54*4c3eb207Smrg range_negatives (tree type)
55*4c3eb207Smrg {
56*4c3eb207Smrg   unsigned prec = TYPE_PRECISION (type);
57*4c3eb207Smrg   signop sign = TYPE_SIGN (type);
58*4c3eb207Smrg   value_range r;
59*4c3eb207Smrg   if (sign == UNSIGNED)
60*4c3eb207Smrg     r.set_undefined ();
61*4c3eb207Smrg   else
62*4c3eb207Smrg     r = value_range (type, wi::min_value (prec, sign), wi::minus_one (prec));
63*4c3eb207Smrg   return r;
64*4c3eb207Smrg }
65