From 4e533ef7a95faca92757acccd6f92ffa97783b4b Mon Sep 17 00:00:00 2001 From: Adam Nemet Date: Fri, 21 Aug 2015 23:19:57 +0000 Subject: [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. llvm-svn: 245760 --- llvm/lib/Analysis/LoopAccessAnalysis.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'llvm/lib/Analysis/LoopAccessAnalysis.cpp') diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 41499df43cc..87dd8d47a65 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1593,10 +1593,13 @@ static Instruction *getFirstInst(Instruction *FirstInst, Value *V, return nullptr; } -/// \brief IR Values for the lower and upper bounds of a pointer evolution. +/// \brief IR Values for the lower and upper bounds of a pointer evolution. We +/// need to use value-handles because SCEV expansion can invalidate previously +/// expanded values. Thus expansion of a pointer can invalidate the bounds for +/// a previous one. struct PointerBounds { - Value *Start; - Value *End; + TrackingVH Start; + TrackingVH End; }; /// \brief Expand code for the lower and upper bound of the pointer group \p CG -- cgit v1.2.3