[LAA] Hold bounds via ValueHandles during SCEV expansion
authorAdam Nemet <anemet@apple.com>
Fri, 21 Aug 2015 23:19:57 +0000 (23:19 +0000)
committerAdam Nemet <anemet@apple.com>
Fri, 21 Aug 2015 23:19:57 +0000 (23:19 +0000)
commitd4fd5e5000048b033182d070c1ebcc1c29a57fa2
tree2997a5147e0f82c47685139f401413b950051ea5
parent23d9019965d0bf25b8461ee1ceaba8cfc4cfbc23
[LAA] Hold bounds via ValueHandles during SCEV expansion

SCEV expansion can invalidate previously expanded values.  For example
in SCEVExpander::ReuseOrCreateCast, if we already have the requested
cast value but it's not at the desired location, a new cast is inserted
and the old cast will be invalidated.

Therefore, when expanding the bounds for the pointers, a later entry can
invalidate the IR value for an earlier one.  The fix is to store a value
handle rather than the value itself.

The newly added test has a more detailed description of how the bug
triggers.

This bug can have a negative but potentially highly variable performance
impact in Loop Distribution.  Because one of the bound values was
invalidated and is an undef expression now, InstCombine is free to
transform the array overlap check:

   Start0 <= End1 && Start1 <= End0

into:

   Start0 <= End1

So depending on the runtime location of the arrays, we would detect a
conflict and fall back on the original loop of the versioned loop.

Also tested compile time with SPEC2006 LTO bc files.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@245760 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Analysis/LoopAccessAnalysis.cpp
test/Transforms/LoopDistribute/bounds-expansion-bug.ll [new file with mode: 0644]