diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp | 24 |
2 files changed, 27 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index 8943c31e290..03df953f24e 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -823,7 +823,9 @@ void LazyValueInfoImpl::intersectAssumeOrGuardBlockValueConstantRange( if (!GuardDecl || GuardDecl->use_empty()) return; - for (Instruction &I : make_range(BBI->getIterator().getReverse(), + if (BBI->getIterator() == BBI->getParent()->begin()) + return; + for (Instruction &I : make_range(std::next(BBI->getIterator().getReverse()), BBI->getParent()->rend())) { Value *Cond = nullptr; if (match(&I, m_Intrinsic<Intrinsic::experimental_guard>(m_Value(Cond)))) diff --git a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp index a51b86d34a8..0a33ea6e195 100644 --- a/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp +++ b/llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp @@ -462,6 +462,30 @@ static bool processCallSite(CallSite CS, LazyValueInfo *LVI) { } } + // Deopt bundle operands are intended to capture state with minimal + // perturbance of the code otherwise. If we can find a constant value for + // any such operand and remove a use of the original value, that's + // desireable since it may allow further optimization of that value (e.g. via + // single use rules in instcombine). Since deopt uses tend to, + // idiomatically, appear along rare conditional paths, it's reasonable likely + // we may have a conditional fact with which LVI can fold. + if (auto DeoptBundle = CS.getOperandBundle(LLVMContext::OB_deopt)) { + bool Progress = false; + for (const Use &ConstU : DeoptBundle->Inputs) { + Use &U = const_cast<Use&>(ConstU); + Value *V = U.get(); + if (V->getType()->isVectorTy()) continue; + if (isa<Constant>(V)) continue; + + Constant *C = LVI->getConstant(V, CS.getParent(), CS.getInstruction()); + if (!C) continue; + U.set(C); + Progress = true; + } + if (Progress) + return true; + } + for (Value *V : CS.args()) { PointerType *Type = dyn_cast<PointerType>(V->getType()); // Try to mark pointer typed parameters as non-null. We skip the |