data-ref: Tighten index-based alias checks [PR99726]
authorRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:01 +0000 (19:34 +0100)
committerRichard Sandiford <richard.sandiford@arm.com>
Wed, 31 Mar 2021 18:34:01 +0000 (19:34 +0100)
commitb5c7accfb56a7347008f629be4c7344dd849b1b1
tree42b4abf64ffc6a6b91ca569794bfdd1f7b0b83dc
parent1b5f74e8be4dd7abe5624ff60adceff19ca71bda
data-ref: Tighten index-based alias checks [PR99726]

create_intersect_range_checks_index tries to create a runtime
alias check based on index comparisons.  It looks through the
access functions for the two DRs to find a SCEV for the loop
that is being versioned and converts a DR_STEP-based check
into an index-based check.

However, there isn't any reliable sign information in the types,
so the code expects the value of the IV step (when interpreted as
signed) to be negative iff the DR_STEP (when interpreted as signed)
is negative.

r10-4762 added another assert related to this assumption and the
assert fired for the testcase in the PR.  The sign of the IV step
didn't match the sign of the DR_STEP.

I think this is actually showing what was previously a wrong-code bug.
The signs didn't match because the DRs contained *two* access function
SCEVs for the loop being versioned.  It doesn't look like the code
is set up to deal with this, since it checks each access function
independently and treats it as the sole source of DR_STEP.

The patch therefore moves the main condition out of the loop.
This also has the advantage of not building a tree for one access
function only to throw it away if we find an inner function that
makes the comparison invalid.

gcc/
PR tree-optimization/99726
* tree-data-ref.c (create_intersect_range_checks_index): Bail
out if there is more than one access function SCEV for the loop
being versioned.

gcc/testsuite/
PR tree-optimization/99726
* gcc.target/i386/pr99726.c: New test.
gcc/testsuite/gcc.target/i386/pr99726.c [new file with mode: 0644]
gcc/tree-data-ref.c