aboutsummaryrefslogtreecommitdiff
path: root/gcc/gimple-range.cc
AgeCommit message (Collapse)AuthorFilesLines
2021-09-13Merged current trunk to branch.Thomas Koenig1-1202/+219
2020-11-13Cleanup range of address calculations.Andrew MacLeod1-31/+68
Align EVRP and ranger for how ranges of ADDR_EXPR are calculated. gcc/ * gimple-range.cc: (gimple_ranger::range_of_range_op): Check for ADDR_EXPR and call range_of_address. (gimple_ranger::range_of_address): Rename from range_of_non_trivial_assignment and match vrp_stmt_computes_nonzero. * gimple-range.h: (range_of_address): Renamed. * range-op.cc: (pointer_table): Add INTEGER_CST handler. gcc/testsuite/ * gcc.dg/tree-ssa/pr78655.c: New.
2020-11-06Combine new calculated ranges with existing range.Andrew MacLeod1-2/+8
When a range is recalculated, retain what was previously known as IL changes can produce different results from un-executed code. This also paves the way for external injection of ranges. gcc/ PR tree-optimization/97737 PR tree-optimization/97741 * gimple-range.cc: (gimple_ranger::range_of_stmt): Intersect newly calculated ranges with the existing known global range. gcc/testsuite/ * gcc.dg/pr97737.c: New. * gcc.dg/pr97741.c: New.
2020-11-05Drop overflow from constants while building ranges in ranger.Aldy Hernandez1-0/+2
Sometimes the overflow flag will leak into the IL. Drop it while creating ranges. There are various places we could plug this. This patch just plugs things at get_tree_range which is the entry point for ranges from tree expressions. It fixes the PR, and probably fixes the ranger entirely, but we may need to revisit this. For example, I looked to see if there were other places that created ranges with TREE_OVERFLOW set, and there are various. For example, the following code pattern appears multiple times in vr-values.c: else if (is_gimple_min_invariant (op0)) vr0.set (op0); This can pick up TREE_OVERFLOW from the IL if present. However, the ranger won't see them so we're good. At some point we should audit all this. Or perhaps just nuke all TREE_OVERFLOW's at irange::set. For now, this will do. gcc/ChangeLog: PR tree-optimization/97721 * gimple-range.cc (get_tree_range): Drop overflow from constants. gcc/testsuite/ChangeLog: * gcc.dg/pr97721.c: New test.
2020-11-04Add Ranger temporal cacheAndrew MacLeod1-9/+14
Add a timestamp to supplement the global range cache to detect when a value may become stale. gcc/ PR tree-optimization/97515 * gimple-range-cache.h (class ranger_cache): New prototypes plus temporal cache pointer. * gimple-range-cache.cc (struct range_timestamp): New. (class temporal_cache): New. (temporal_cache::temporal_cache): New. (temporal_cache::~temporal_cache): New. (temporal_cache::get_timestamp): New. (temporal_cache::set_dependency): New. (temporal_cache::temporal_value): New. (temporal_cache::current_p): New. (temporal_cache::set_timestamp): New. (temporal_cache::set_always_current): New. (ranger_cache::ranger_cache): Allocate the temporal cache. (ranger_cache::~ranger_cache): Free temporal cache. (ranger_cache::get_non_stale_global_range): New. (ranger_cache::set_global_range): Add a timestamp. (ranger_cache::register_dependency): New. Add timestamp dependency. * gimple-range.cc (gimple_ranger::range_of_range_op): Add operand dependencies. (gimple_ranger::range_of_phi): Ditto. (gimple_ranger::range_of_stmt): Check if global range is stale, and recalculate if so. gcc/testsuite/ * gcc.dg/pr97515.c: Check listing for folding of entire function.
2020-11-03Tweaks to ranger cacheAndrew MacLeod1-16/+8
Add some bounds checking to ssa_block_ranges, and privatize the ranges block cache and global cache, adding API points for accessing them. * gimple-range-cache.h (block_range_cache): Add new entry point. (ranger_cache): Privatize global abnd block cache members. * gimple-range-cache.cc (ssa_block_ranges::set_bb_range): Add bounds check. (ssa_block_ranges::set_bb_varying): Ditto. (ssa_block_ranges::get_bb_range): Ditto. (ssa_block_ranges::bb_range_p): Ditto. (block_range_cache::get_block_ranges): Fix formatting. (block_range_cache::query_block_ranges): New. (block_range_cache::get_bb_range): Use Query_block_ranges. (block_range_cache::bb_range_p): Ditto. (ranger_cache::dump): New. (ranger_cache::get_global_range): New. (ranger_cache::set_global_range): New. * gimple-range.cc (gimple_ranger::range_of_expr): Use new API. (gimple_ranger::range_of_stmt): Ditto. (gimple_ranger::export_global_ranges): Ditto. (gimple_ranger::dump): Ditto.
2020-10-27Tweaks to ranger API routines.Andrew MacLeod1-36/+40
Remove the gcc_assert wrappers that contain statements that need to be executed. Audit routines to ensure range is set to UNDEFINED when false is returned. * gimple-range-gori.cc (gori_compute_cache::cache_stmt): Accumulate return values and only set cache when everything returned true. * gimple-range.cc (get_tree_range): Set the return range to UNDEFINED when the range isn't supported. (gimple_ranger::calc_stmt): Return varying if the type is supported, even if the stmt processing failed. False otherwise. (range_of_builtin_ubsan_call): Don't use gcc_assert. (range_of_builtin_call): Ditto. (gimple_ranger::range_of_cond_expr): Ditto. (gimple_ranger::range_of_expr): Ditto (gimple_ranger::range_on_entry): Ditto. (gimple_ranger::range_on_exit): Ditto. (gimple_ranger::range_on_edge): DItto. (gimple_ranger::range_of_stmt): Don't use gcc_assert, and initialize return value to UNDEFINED.
2020-10-26Re: error: ‘EVRP_MODE_DEBUG’ was not declared – was: [PUSHED] Ranger ↵Andrew MacLeod1-1/+1
classes. Initialize zerov to match vr-values.c. * gimple-range.cc (range_of_builtin_call): Initialize zerov to 0.
2020-10-21Handle a_2= &b properly in range calculations.Andrew MacLeod1-9/+23
when processing assignments, we were using the type of b instead of type of &b when computing a range. This was usually filtered out by FRE. turning it off exposed it. gcc/ PR tree-optimization/97520 * gimple-range.cc (range_of_non_trivial_assignment): Handle x = &a by returning a non-zero range. gcc/testsuite/ * gcc.dg/pr97520.c: New.
2020-10-21Adjust overflow for invariants in bounds_of_var_in_loop.Aldy Hernandez1-2/+2
Invariants returned from SCEV can have TREE_OVERFLOW set. Clear the overflow as we do with the rest of the values returned from this function. gcc/ChangeLog: * gimple-range.cc (gimple_ranger::range_of_ssa_name_with_loop_info): Remove TREE_OVERFLOW special case. * vr-values.c (bounds_of_var_in_loop): Adjust overflow for invariants.
2020-10-20Refactor range handling of builtins in vr_values and ranger.Aldy Hernandez1-13/+23
This sets things up so we can share range handling of builtins between vr_values and ranger. It is meant to refactor the code so that we can verify that both implementations yield the same results. First, we abstract out gimple_ranger::range_of_builtin_call into an externally visible counterpart that can be called from vr_values. It will take a range_query since both ranger and vr_values inherit from this base class. Then we abstract out all the builtin handling in vr_values into a separate method that is easier to compare against. Finally, we call the ranger version from vr_values and compare it with the vr_values version. Since this proves both versions return the same, we can remove vr_values::extract_range_builtin in a follow-up patch. The vr_values::range_of_expr change brings the vr_values version up to par with the ranger version. It should've handled non-SSA's. This was a small oversight that went unnoticed because the vr_value version isn't stressed nearly as much as the ranger version. The change is needed because the ranger code handling builtins calls, may call it for integer arguments in range_of_builtin_ubsan_call. There should be no change in functionality. gcc/ChangeLog: * gimple-range.cc (gimple_ranger::range_of_builtin_ubsan_call): Make externally visble... (range_of_builtin_ubsan_call): ...here. Add range_query argument. (gimple_ranger::range_of_builtin_call): Make externally visible... (range_of_builtin_call): ...here. Add range_query argument. * gimple-range.h (range_of_builtin_call): Move out from class and make externally visible. * vr-values.c (vr_values::extract_range_basic): Abstract out builtin handling to... (vr_values::range_of_expr): Handle non SSAs. (vr_values::extract_range_builtin): ...here. * vr-values.h (class vr_values): Add extract_range_builtin. (range_of_expr): Rename NAME to EXPR.
2020-10-20Saturate overflows return from SCEV in ranger.Aldy Hernandez1-2/+2
bounds_of_var_in_loop is returning an overflowed int, which is causing us to create a range for which we can't compare the bounds causing an ICE in verify_range. Overflowed bounds cause compare_values() to return -2, which we don't handle in verify_range. We don't represent overflowed ranges in irange, so this patch just saturates any overflowed end-points to MIN or MAX. gcc/ChangeLog: PR tree-optimization/97501 * gimple-range.cc (gimple_ranger::range_of_ssa_name_with_loop_info): Saturate overflows returned from SCEV. gcc/testsuite/ChangeLog: * gcc.dg/pr97501.c: New test.
2020-10-19Use precision and sign to compare types for rangesAndrew MacLeod1-3/+9
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.
2020-10-14Do not call range_of_ssa_name_with_loop_info with the loop tree root.Aldy Hernandez1-1/+1
gcc/ChangeLog: PR tree-optimization/97396 * gimple-range.cc (gimple_ranger::range_of_phi): Do not call range_of_ssa_name_with_loop_info with the loop tree root. gcc/testsuite/ChangeLog: * gcc.dg/pr97396.c: New test.
2020-10-09vrp: Fix up gcc.target/aarch64/pr90838.c [PR97312, PR94801]Jakub Jelinek1-31/+63
> Perhaps another way out of this would be document and enforce that > __builtin_c[lt]z{,l,ll} etc calls are undefined at zero, but C[TL]Z ifn > calls are defined there based on *_DEFINED_VALUE_AT_ZERO (*) == 2 The following patch implements that, i.e. __builtin_c?z* now take full advantage of them being UB at zero, while the ifns are well defined at zero if *_DEFINED_VALUE_AT_ZERO (*) == 2. That is what fixes PR94801. Furthermore, to fix PR97312, if it is well defined at zero and the value at zero is prec, we don't lower the maximum unless the argument is known to be non-zero. For gimple-range.cc I guess we could improve it if needed e.g. by returning a [0,7][32,32] range for .CTZ of e.g. [0,137], but for now it (roughly) matches what vr-values.c does. 2020-10-09 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/94801 PR target/97312 * vr-values.c (vr_values::extract_range_basic) <CASE_CFN_CLZ, CASE_CFN_CTZ>: When stmt is not an internal-fn call or C?Z_DEFINED_VALUE_AT_ZERO is not 2, assume argument is not zero and thus use [0, prec-1] range unless it can be further improved. For CTZ, don't update maxi from upper bound if it was previously prec. * gimple-range.cc (gimple_ranger::range_of_builtin_call) <CASE_CFN_CLZ, CASE_CFN_CTZ>: Likewise. * gcc.dg/tree-ssa/pr94801.c: New test.
2020-10-08Fix PR97325.Aldy Hernandez1-0/+2
gcc/ChangeLog: PR tree-optimization/97325 * gimple-range.cc (gimple_ranger::range_of_builtin_call): Handle negative numbers in __builtin_ffs and __builtin_popcount.
2020-10-06Ranger classes.Andrew MacLeod1-0/+1284
Add the 8 ranger files and the Makefile changes to build it. 2020-10-06 Andrew MacLeod <amacleod@redhat.com> * Makefile.in (OBJS): Add gimple-range*.o. * gimple-range.h: New file. * gimple-range.cc: New file. * gimple-range-cache.h: New file. * gimple-range-cache.cc: New file. * gimple-range-edge.h: New file. * gimple-range-edge.cc: New file. * gimple-range-gori.h: New file. * gimple-range-gori.cc: New file.