[llvm] r260439 - [LVI] Handle constants defensively

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 14:29:54 PST 2016


FYI, this change was causing clang test failures due to clang tests 
which were checking particular IR and caught the more precise getValueAt 
results.

Hopefully, the clang builds are fixed w/260451.  I ended up fixing that 
not by changing the clang tests, but by not placing nonnull attributes 
on parameters which are simply constants.  Doing so doesn't gain us any 
extra information and is just a waste of compile time.


On 02/10/2016 01:46 PM, Philip Reames via llvm-commits wrote:
> Author: reames
> Date: Wed Feb 10 15:46:32 2016
> New Revision: 260439
>
> URL: http://llvm.org/viewvc/llvm-project?rev=260439&view=rev
> Log:
> [LVI] Handle constants defensively
>
> There's nothing preventing callers of LVI from asking for lattice values representing a Constant.  In fact, given that several callers are walking back through PHI nodes and trying to simplify predicates, such queries are actually quite common.  This is mostly harmless today, but we start volatiling assertions if we add new calls to getBlockValue in otherwise reasonable places.
>
> Note that this change is not NFC.  Specifically:
> 1) The result returned through getValueAt will now be more precise.  In principle, this could trigger any latent infinite optimization loops in callers, but in practice, we're unlikely to see this.
> 2) The result returned through getBlockValueAt is potentially weakened for non-constants that were previously queried.  With the old code, you had the possibility that a later query might bypass the cache and discover some information the original query did not.  I can't find a scenario which actually causes this to happen, but it was in principle possible.  On the other hand, this may end up reducing compile time when the same value is queried repeatedly.
>
>
> Modified:
>      llvm/trunk/lib/Analysis/LazyValueInfo.cpp
>
> Modified: llvm/trunk/lib/Analysis/LazyValueInfo.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/LazyValueInfo.cpp?rev=260439&r1=260438&r2=260439&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/LazyValueInfo.cpp (original)
> +++ llvm/trunk/lib/Analysis/LazyValueInfo.cpp Wed Feb 10 15:46:32 2016
> @@ -1155,9 +1155,10 @@ LVILatticeVal LazyValueInfoCache::getVal
>           << BB->getName() << "'\n");
>   
>     assert(BlockValueStack.empty() && BlockValueSet.empty());
> -  pushBlockValue(std::make_pair(BB, V));
> -
> -  solve();
> +  if (!hasBlockValue(V, BB)) {
> +    pushBlockValue(std::make_pair(BB, V));
> +    solve();
> +  }
>     LVILatticeVal Result = getBlockValue(V, BB);
>     intersectAssumeBlockValueConstantRange(V, Result, CxtI);
>   
> @@ -1169,6 +1170,9 @@ LVILatticeVal LazyValueInfoCache::getVal
>     DEBUG(dbgs() << "LVI Getting value " << *V << " at '"
>           << CxtI->getName() << "'\n");
>   
> +  if (auto *C = dyn_cast<Constant>(V))
> +    return LVILatticeVal::get(C);
> +
>     LVILatticeVal Result = LVILatticeVal::getOverdefined();
>     if (auto *I = dyn_cast<Instruction>(V))
>       Result = getFromRangeMetadata(I);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list