diff options
author | Hal Finkel <hfinkel@anl.gov> | 2016-12-15 02:53:42 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2016-12-15 02:53:42 +0000 |
commit | cb9f78e1c3951337de4ba24902eced2c72184319 (patch) | |
tree | a2290a1daa25da9cc6b1d3a9d9c59564bef3792c /llvm/lib/Analysis/CodeMetrics.cpp | |
parent | dfe85e2d88cdc7684abdeff6c91356d16a394849 (diff) | |
download | bcm5719-llvm-cb9f78e1c3951337de4ba24902eced2c72184319.tar.gz bcm5719-llvm-cb9f78e1c3951337de4ba24902eced2c72184319.zip |
Make processing @llvm.assume more efficient by using operand bundles
There was an efficiency problem with how we processed @llvm.assume in
ValueTracking (and other places). The AssumptionCache tracked all of the
assumptions in a given function. In order to find assumptions relevant to
computing known bits, etc. we searched every assumption in the function. For
ValueTracking, that means that we did O(#assumes * #values) work in InstCombine
and other passes (with a constant factor that can be quite large because we'd
repeat this search at every level of recursion of the analysis).
Several of us discussed this situation at the last developers' meeting, and
this implements the discussed solution: Make the values that an assume might
affect operands of the assume itself. To avoid exposing this detail to
frontends and passes that need not worry about it, I've used the new
operand-bundle feature to add these extra call "operands" in a way that does
not affect the intrinsic's signature. I think this solution is relatively
clean. InstCombine adds these extra operands based on what ValueTracking, LVI,
etc. will need and then those passes need only search the users of the values
under consideration. This should fix the computational-complexity problem.
At this point, no passes depend on the AssumptionCache, and so I'll remove
that as a follow-up change.
Differential Revision: https://reviews.llvm.org/D27259
llvm-svn: 289755
Diffstat (limited to 'llvm/lib/Analysis/CodeMetrics.cpp')
-rw-r--r-- | llvm/lib/Analysis/CodeMetrics.cpp | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/llvm/lib/Analysis/CodeMetrics.cpp b/llvm/lib/Analysis/CodeMetrics.cpp index bdffdd8eb27..859adf0eb94 100644 --- a/llvm/lib/Analysis/CodeMetrics.cpp +++ b/llvm/lib/Analysis/CodeMetrics.cpp @@ -76,20 +76,12 @@ void CodeMetrics::collectEphemeralValues( SmallPtrSet<const Value *, 32> Visited; SmallVector<const Value *, 16> Worklist; - for (auto &AssumeVH : AC->assumptions()) { - if (!AssumeVH) - continue; - Instruction *I = cast<Instruction>(AssumeVH); - - // Filter out call sites outside of the loop so we don't do a function's - // worth of work for each of its loops (and, in the common case, ephemeral - // values in the loop are likely due to @llvm.assume calls in the loop). - if (!L->contains(I->getParent())) - continue; - - if (EphValues.insert(I).second) - appendSpeculatableOperands(I, Visited, Worklist); - } + for (auto &B : L->blocks()) + for (auto &I : *B) + if (auto *II = dyn_cast<IntrinsicInst>(&I)) + if (II->getIntrinsicID() == Intrinsic::assume && + EphValues.insert(II).second) + appendSpeculatableOperands(II, Visited, Worklist); completeEphemeralValues(Visited, Worklist, EphValues); } @@ -100,16 +92,12 @@ void CodeMetrics::collectEphemeralValues( SmallPtrSet<const Value *, 32> Visited; SmallVector<const Value *, 16> Worklist; - for (auto &AssumeVH : AC->assumptions()) { - if (!AssumeVH) - continue; - Instruction *I = cast<Instruction>(AssumeVH); - assert(I->getParent()->getParent() == F && - "Found assumption for the wrong function!"); - - if (EphValues.insert(I).second) - appendSpeculatableOperands(I, Visited, Worklist); - } + for (auto &B : *F) + for (auto &I : B) + if (auto *II = dyn_cast<IntrinsicInst>(&I)) + if (II->getIntrinsicID() == Intrinsic::assume && + EphValues.insert(II).second) + appendSpeculatableOperands(II, Visited, Worklist); completeEphemeralValues(Visited, Worklist, EphValues); } |