diff options
author | Andrew MacLeod <amacleod@redhat.com> | 2020-10-19 19:04:40 -0400 |
---|---|---|
committer | Andrew MacLeod <amacleod@redhat.com> | 2020-10-19 19:11:17 -0400 |
commit | 6e02de946125c36871bd4d8eff21f7f88f01a8aa (patch) | |
tree | d56c07a37e03501257e2682ecccc234d5a29cdff /gcc/gimple-range.h | |
parent | f000b7c436e62c52798187d8150216569eef17b5 (diff) | |
download | gcc-6e02de946125c36871bd4d8eff21f7f88f01a8aa.zip gcc-6e02de946125c36871bd4d8eff21f7f88f01a8aa.tar.gz gcc-6e02de946125c36871bd4d8eff21f7f88f01a8aa.tar.bz2 |
Use precision and sign to compare types for ranges
Sanity check ranges by comparing just SIGN and PRECISION.
gcc/
PR tree-optimization/97360
* gimple-range.h (range_compatible_p): New.
* gimple-range-gori.cc (is_gimple_logical_p): Use range_compatible_p.
(range_is_either_true_or_false): Ditto.
(gori_compute::outgoing_edge_range_p): Cast result to the correct
type if necessary.
(logical_stmt_cache::cacheable_p): Use range_compatible_p.
* gimple-range.cc (gimple_ranger::calc_stmt): Check range_compatible_p
before casting the range.
(gimple_ranger::range_on_exit): Use range_compatible_p.
(gimple_ranger::range_on_edge): Ditto.
gcc/testsuite/
* gcc.dg/pr97360-2.c: New test.
Diffstat (limited to 'gcc/gimple-range.h')
-rw-r--r-- | gcc/gimple-range.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/gcc/gimple-range.h b/gcc/gimple-range.h index 041dc7c..a6e8793 100644 --- a/gcc/gimple-range.h +++ b/gcc/gimple-range.h @@ -115,6 +115,18 @@ gimple_range_ssa_p (tree exp) return NULL_TREE; } +// Return true if TYPE1 and TYPE2 are compatible range types. + +static inline bool +range_compatible_p (tree type1, tree type2) +{ + // types_compatible_p requires conversion in both directions to be useless. + // GIMPLE only requires a cast one way in order to be compatible. + // Ranges really only need the sign and precision to be the same. + return (TYPE_PRECISION (type1) == TYPE_PRECISION (type2) + && TYPE_SIGN (type1) == TYPE_SIGN (type2)); +} + // Return the legacy GCC global range for NAME if it has one, otherwise // return VARYING. |