Use nonzero bits to refine range in split_constant_offset (PR 81635)

Programming / Compilers / GCC - rsandifo [138bc75d-0d04-0410-961f-82ee72b054a4] - 8 February 2018 15:16 EST

This patch is part 2 of the fix for PR 81635. It means that split_constant_offset can handle loops like:

for (unsigned int i = 0; i < n; i += 4) { a[i] = ...; a[i + 1] = ...; }

CCP records that "i" must have its low 2 bits clear, but we don't include this information in the range of "i", which remains [0, +INF]. I tried making set_nonzero_bits update the range info in the same way that set_range_info updates the nonzero bits, but it regressed cases like vrp117.c and made some other tests worse.

vrp117.c has a multiplication by 10, so CCP can infer that the low bit of the result is clear. If we included that in the range, the range would go from [-INF, +INF] to [-INF, not-quite-+INF]. However, the multiplication is also known to overflow in all cases, so VRP saturates the result to [INT_MAX, INT_MAX]. This obviously creates a contradiction with the nonzero bits, and intersecting the new saturated range with an existing not-quite-+INF range would make us drop to
VR_UNDEFINED. We're prepared to fold a comparison with an [INT_MAX, INT_MAX] value but not with a VR_UNDEFINED value.

The other problems were created when intersecting [-INF, not-quite-+INF] with a useful VR_ANTI_RANGE like ~[-1, 1]. The intersection would keep the former range rather than the latter.

The patch therefore keeps the adjustment local to split_constant_offset for now, but adds a helper routine so that it's easy to move this later.

2018-02-08 Richard Sandiford

gcc/ PR tree-optimization/81635
- wide-int.h (wi::round_down_for_mask, wi::round_up_for_mask): Declare.
- (wi::round_down_for_mask, wi::round_up_for_mask) (test_round_for_mask): New functions. (wide_int_cc_tests): Call test_round_for_mask.
- tree-vrp.h (intersect_range_with_nonzero_bits): Declare.
- tree-vrp.c (intersect_range_with_nonzero_bits): New function.
- tree-data-ref.c (split_constant_offset_1): Use it to refine the range returned by get_range_info.

gcc/testsuite/ PR tree-optimization/81635
- gcc.dg/vect/bb-slp-pr81635-3.c: New test.
- gcc.dg/vect/bb-slp-pr81635-4.c: Likewise.

a5c5f57ec3a Use nonzero bits to refine range in split_constant_offset (PR 81635)
gcc/ChangeLog | 12 +++
gcc/testsuite/ChangeLog | 6 ++
gcc/testsuite/gcc.dg/vect/bb-slp-pr81635-3.c | 62 +++++++++++++++
gcc/testsuite/gcc.dg/vect/bb-slp-pr81635-4.c | 47 +++++++++++
gcc/tree-data-ref.c | 9 ++-
gcc/tree-vrp.c | 47 +++++++++++
gcc/tree-vrp.h | 2 +
gcc/ | 112 +++++++++++++++++++++++++++
gcc/wide-int.h | 2 +
9 files changed, 297 insertions(+), 2 deletions(-)


  • Share