- Fixes a bug when calculating the offset in GetLinearExpression. The code previously used zext to extend the offset, so negative offsets were converted to large positive ones.
- Enhance aliasGEP to deduce that, if the difference between two GEP allocations is positive and all the variables that govern the offset are also positive (i.e. the offset is strictly after the higher base pointer), then locations that fit in the gap between the two base pointers are NoAlias.
The original patch forgot to check if the Scale in VariableGEPIndex flipped the sign of the variable. The BasicAA pass iterates over the instructions in the order they appear in the function, and so BasicAliasAnalysis::aliasGEP is called with the variable it first comes across as parameter GEP1. Adding a %reorder label puts the definition of %a after %b so aliasGEP is called with %b as the first parameter and %a as the second. aliasGEP later calculates that %a == %b + 1 - %idxprom where %idxprom >= 0 (if %a was passed as the first parameter it would calculate %b == %a - 1 + %idxprom where %idxprom >= 0) - ignoring that %idxprom is scaled by -1 here lead the patch to incorrectly conclude that %a > %b.
This patch now ensures that isValueEqualInPotentialCycles is called for the existing modulo-distance check as it too is only valid if the variable doesn't change across cycles. The fix described in (1) makes this codepath execute more frequently, as variables that were within a small negative distance of each other were being interpreted as being a very large positive distance away from each other. The code now correctly identifies more variables as being outside a scale-modulo-distance of each other, and so declares more variables as NoAlias.
Thanks to Lang to isolating the first bug, Rich Barton for isolating the second bug and Hal for improving the patch.
If I change this PartialAlias return to MayAlias, all of the regression tests still pass. Is there a test covering this?