LLVM
8.0.1
|
#include "llvm/Transforms/Scalar/CorrelatedValuePropagation.h"
#include "llvm/ADT/DepthFirstIterator.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/GlobalsModRef.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/LazyValueInfo.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/CallSite.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/DomTreeUpdater.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/InstrTypes.h"
#include "llvm/IR/Instruction.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/Operator.h"
#include "llvm/IR/PassManager.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/Value.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
#include <cassert>
#include <utility>
Go to the source code of this file.
Macros | |
#define | DEBUG_TYPE "correlated-value-propagation" |
Functions | |
STATISTIC (NumPhis, "Number of phis propagated") | |
STATISTIC (NumPhiCommon, "Number of phis deleted via common incoming value") | |
STATISTIC (NumSelects, "Number of selects propagated") | |
STATISTIC (NumMemAccess, "Number of memory access targets propagated") | |
STATISTIC (NumCmps, "Number of comparisons propagated") | |
STATISTIC (NumReturns, "Number of return values propagated") | |
STATISTIC (NumDeadCases, "Number of switch cases removed") | |
STATISTIC (NumSDivs, "Number of sdiv converted to udiv") | |
STATISTIC (NumUDivs, "Number of udivs whose width was decreased") | |
STATISTIC (NumAShrs, "Number of ashr converted to lshr") | |
STATISTIC (NumSRems, "Number of srem converted to urem") | |
STATISTIC (NumOverflows, "Number of overflow checks removed") | |
INITIALIZE_PASS_BEGIN (CorrelatedValuePropagation, "correlated-propagation", "Value Propagation", false, false) INITIALIZE_PASS_END(CorrelatedValuePropagation | |
static bool | processSelect (SelectInst *S, LazyValueInfo *LVI) |
static bool | simplifyCommonValuePhi (PHINode *P, LazyValueInfo *LVI, DominatorTree *DT) |
Try to simplify a phi with constant incoming values that match the edge values of a non-constant value on all other edges: bb0: isnull = icmp eq i8* x, null br i1 isnull, label bb2, label bb1 bb1: br label bb2 bb2: r = phi i8* [ x, bb1 ], [ null, bb0 ] –> r = x. More... | |
static bool | processPHI (PHINode *P, LazyValueInfo *LVI, DominatorTree *DT, const SimplifyQuery &SQ) |
static bool | processMemAccess (Instruction *I, LazyValueInfo *LVI) |
static bool | processCmp (CmpInst *Cmp, LazyValueInfo *LVI) |
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove this comparison. More... | |
static bool | processSwitch (SwitchInst *SI, LazyValueInfo *LVI, DominatorTree *DT) |
Simplify a switch instruction by removing cases which can never fire. More... | |
static bool | willNotOverflow (IntrinsicInst *II, LazyValueInfo *LVI) |
static void | processOverflowIntrinsic (IntrinsicInst *II) |
static bool | processCallSite (CallSite CS, LazyValueInfo *LVI) |
Infer nonnull attributes for the arguments at the specified callsite. More... | |
static bool | hasPositiveOperands (BinaryOperator *SDI, LazyValueInfo *LVI) |
static bool | processUDivOrURem (BinaryOperator *Instr, LazyValueInfo *LVI) |
Try to shrink a udiv/urem's width down to the smallest power of two that's sufficient to contain its operands. More... | |
static bool | processSRem (BinaryOperator *SDI, LazyValueInfo *LVI) |
static bool | processSDiv (BinaryOperator *SDI, LazyValueInfo *LVI) |
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove the both operands of this SDiv are positive. More... | |
static bool | processAShr (BinaryOperator *SDI, LazyValueInfo *LVI) |
static bool | processAdd (BinaryOperator *AddOp, LazyValueInfo *LVI) |
static Constant * | getConstantAt (Value *V, Instruction *At, LazyValueInfo *LVI) |
static bool | runImpl (Function &F, LazyValueInfo *LVI, DominatorTree *DT, const SimplifyQuery &SQ) |
Variables | |
static cl::opt< bool > | DontProcessAdds ("cvp-dont-process-adds", cl::init(true)) |
correlated | propagation |
correlated Value | Propagation |
correlated Value | false |
#define DEBUG_TYPE "correlated-value-propagation" |
Definition at line 53 of file CorrelatedValuePropagation.cpp.
|
static |
Definition at line 660 of file CorrelatedValuePropagation.cpp.
References C, llvm::dyn_cast(), llvm::LazyValueInfo::getConstant(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::LazyValueInfo::getPredicateAt(), llvm::ConstantInt::getTrue(), llvm::LazyValueInfo::True, and llvm::LazyValueInfo::Unknown.
Referenced by runImpl().
|
static |
Definition at line 494 of file CorrelatedValuePropagation.cpp.
References llvm::ConstantInt::get(), llvm::LazyValueInfo::getPredicateAt(), llvm::Value::getType(), llvm::CmpInst::ICMP_SGE, llvm::RISCVFenceField::O, llvm::User::operands(), and llvm::LazyValueInfo::True.
Referenced by processSDiv(), and processSRem().
INITIALIZE_PASS_BEGIN | ( | CorrelatedValuePropagation | , |
"correlated-propagation" | , | ||
"Value Propagation" | , | ||
false | , | ||
false | |||
) |
|
static |
Definition at line 606 of file CorrelatedValuePropagation.cpp.
References llvm::MCID::Add, llvm::ConstantRange::contains(), DontProcessAdds, llvm::LazyValueInfo::getConstantRange(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::Optional< T >::getValue(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::ConstantRange::isEmptySet(), llvm::Type::isVectorTy(), llvm::ConstantRange::makeGuaranteedNoWrapRegion(), llvm::Instruction::setHasNoSignedWrap(), and llvm::Instruction::setHasNoUnsignedWrap().
Referenced by runImpl().
|
static |
Definition at line 586 of file CorrelatedValuePropagation.cpp.
References llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::Instruction::getDebugLoc(), llvm::Value::getName(), llvm::User::getOperand(), llvm::LazyValueInfo::getPredicateAt(), llvm::Value::getType(), llvm::CmpInst::ICMP_SGE, llvm::Instruction::isExact(), llvm::Type::isVectorTy(), llvm::Value::replaceAllUsesWith(), and llvm::LazyValueInfo::True.
Referenced by runImpl().
|
static |
Infer nonnull attributes for the arguments at the specified callsite.
Definition at line 455 of file CorrelatedValuePropagation.cpp.
References llvm::AttributeList::addParamAttribute(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::arg_size(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::args(), assert(), llvm::dyn_cast(), llvm::SmallVectorBase::empty(), llvm::LazyValueInfo::False, llvm::Attribute::get(), llvm::ConstantPointerNull::get(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getAttributes(), llvm::Value::getContext(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::getInstruction(), llvm::LazyValueInfo::getPredicateAt(), llvm::CmpInst::ICMP_EQ, llvm::Attribute::NonNull, llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::paramHasAttr(), processOverflowIntrinsic(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::CallSiteBase< FunTy, BBTy, ValTy, UserTy, UseTy, InstrTy, CallTy, InvokeTy, IterTy >::setAttributes(), and willNotOverflow().
Referenced by runImpl().
|
static |
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove this comparison.
Even for local conditions, this can sometimes prove conditions instcombine can't by exploiting range information.
Definition at line 276 of file CorrelatedValuePropagation.cpp.
References C, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::ConstantInt::get(), llvm::Value::getContext(), llvm::Type::getInt1Ty(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::CmpInst::getPredicate(), llvm::LazyValueInfo::getPredicateAt(), I, llvm::Value::replaceAllUsesWith(), and llvm::LazyValueInfo::Unknown.
Referenced by runImpl().
|
static |
Definition at line 255 of file CorrelatedValuePropagation.cpp.
References C, llvm::LazyValueInfo::getConstant(), llvm::Instruction::getParent(), llvm::getPointerOperand(), I, and llvm::User::replaceUsesOfWith().
Referenced by runImpl().
|
static |
Definition at line 432 of file CorrelatedValuePropagation.cpp.
References B, llvm::IRBuilder< T, Inserter >::CreateAdd(), llvm::IRBuilder< T, Inserter >::CreateInsertValue(), llvm::IRBuilder< T, Inserter >::CreateSub(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::Value::getContext(), llvm::ConstantInt::getFalse(), llvm::IntrinsicInst::getIntrinsicID(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::getType(), llvm_unreachable, llvm::Value::replaceAllUsesWith(), llvm::Intrinsic::sadd_with_overflow, llvm::Intrinsic::ssub_with_overflow, llvm::Intrinsic::uadd_with_overflow, and llvm::Intrinsic::usub_with_overflow.
Referenced by processCallSite().
|
static |
Definition at line 185 of file CorrelatedValuePropagation.cpp.
References C, llvm::dbgs(), llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::LazyValueInfo::False, llvm::SelectInst::getCondition(), llvm::LazyValueInfo::getConstantOnEdge(), llvm::SelectInst::getFalseValue(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::LazyValueInfo::getPredicateOnEdge(), llvm::SelectInst::getTrueValue(), llvm::Value::getType(), llvm::CmpInst::ICMP_EQ, llvm::Type::isVectorTy(), LLVM_DEBUG, P, llvm::Value::replaceAllUsesWith(), llvm::PHINode::setIncomingValue(), SI, simplifyCommonValuePhi(), and llvm::SimplifyInstruction().
Referenced by runImpl().
|
static |
See if LazyValueInfo's ability to exploit edge conditions or range information is sufficient to prove the both operands of this SDiv are positive.
If this is the case, replace the SDiv with a UDiv. Even for local conditions, this can sometimes prove conditions instcombine can't by exploiting range information.
Definition at line 568 of file CorrelatedValuePropagation.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Instruction::getDebugLoc(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::getType(), hasPositiveOperands(), llvm::Instruction::isExact(), llvm::Type::isVectorTy(), processUDivOrURem(), and llvm::Value::replaceAllUsesWith().
Referenced by runImpl().
|
static |
Definition at line 106 of file CorrelatedValuePropagation.cpp.
References C, llvm::dyn_cast(), llvm::Instruction::eraseFromParent(), llvm::UndefValue::get(), llvm::SelectInst::getCondition(), llvm::LazyValueInfo::getConstant(), llvm::SelectInst::getFalseValue(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::SelectInst::getTrueValue(), llvm::Value::getType(), llvm::ConstantInt::isOne(), llvm::Type::isVectorTy(), Other, llvm::Value::replaceAllUsesWith(), and std::swap().
Referenced by runImpl().
|
static |
Definition at line 546 of file CorrelatedValuePropagation.cpp.
References llvm::Instruction::eraseFromParent(), llvm::Instruction::getDebugLoc(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Value::getType(), hasPositiveOperands(), llvm::Type::isVectorTy(), processUDivOrURem(), and llvm::Value::replaceAllUsesWith().
Referenced by runImpl().
|
static |
Simplify a switch instruction by removing cases which can never fire.
If the uselessness of a case could be determined locally then constant propagation would already have figured it out. Instead, walk the predecessors and statically evaluate cases based on information available on that edge. Cases that cannot fire no matter what the incoming edge can safely be removed. If a case fires on every incoming edge then the entire switch can be removed and replaced with a branch to the case destination.
Definition at line 310 of file CorrelatedValuePropagation.cpp.
References llvm::SwitchInst::case_begin(), llvm::SwitchInst::case_end(), llvm::ConstantFoldTerminator(), llvm::DomTreeUpdater::deleteEdge(), llvm::LazyValueInfo::False, llvm::SwitchInst::getCondition(), llvm::SwitchInst::getNumCases(), llvm::Instruction::getParent(), getParent(), llvm::LazyValueInfo::getPredicateOnEdge(), llvm::CmpInst::ICMP_EQ, llvm::DomTreeUpdater::Lazy, llvm::pred_begin(), llvm::pred_end(), llvm::SwitchInst::removeCase(), llvm::BasicBlock::removePredecessor(), llvm::SwitchInst::setCondition(), llvm::successors(), llvm::LazyValueInfo::True, and llvm::LazyValueInfo::Unknown.
Referenced by llvm::collectCmpOps(), and runImpl().
|
static |
Try to shrink a udiv/urem's width down to the smallest power of two that's sufficient to contain its operands.
Definition at line 506 of file CorrelatedValuePropagation.cpp.
References assert(), B, llvm::Instruction::eraseFromParent(), llvm::APInt::getActiveBits(), llvm::LazyValueInfo::getConstantRange(), llvm::Value::getContext(), llvm::Type::getIntegerBitWidth(), llvm::Type::getIntNTy(), llvm::Value::getName(), llvm::BinaryOperator::getOpcode(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::Value::getType(), llvm::ConstantRange::getUnsignedMax(), llvm::Instruction::isExact(), llvm::Type::isVectorTy(), llvm::User::operands(), llvm::PowerOf2Ceil(), llvm::Value::replaceAllUsesWith(), and llvm::ConstantRange::unionWith().
Referenced by processSDiv(), processSRem(), and runImpl().
|
static |
Definition at line 683 of file CorrelatedValuePropagation.cpp.
References llvm::MCID::Add, C, llvm::MCID::Call, llvm::depth_first(), F(), llvm::getBestSimplifyQuery(), getConstantAt(), llvm::Function::getEntryBlock(), llvm::Instruction::getOpcode(), llvm::SPII::Load, processAdd(), processAShr(), processCallSite(), processCmp(), processMemAccess(), processPHI(), processSDiv(), processSelect(), processSRem(), processSwitch(), processUDivOrURem(), llvm::MipsISD::Ret, runOnFunction(), llvm::MCID::Select, and llvm::SPII::Store.
Referenced by llvm::CorrelatedValuePropagationPass::run().
|
static |
Try to simplify a phi with constant incoming values that match the edge values of a non-constant value on all other edges: bb0: isnull = icmp eq i8* x, null br i1 isnull, label bb2, label bb1 bb1: br label bb2 bb2: r = phi i8* [ x, bb1 ], [ null, bb0 ] –> r = x.
Definition at line 140 of file CorrelatedValuePropagation.cpp.
References C, llvm::DominatorTree::dominates(), llvm::SmallVectorBase::empty(), llvm::Instruction::eraseFromParent(), llvm::LazyValueInfo::getConstantOnEdge(), llvm::PHINode::getIncomingBlock(), llvm::PHINode::getIncomingValue(), llvm::PHINode::getNumIncomingValues(), llvm::Instruction::getParent(), llvm::SmallVectorTemplateBase< T >::push_back(), and llvm::Value::replaceAllUsesWith().
Referenced by processPHI().
STATISTIC | ( | NumPhis | , |
"Number of phis propagated" | |||
) |
STATISTIC | ( | NumPhiCommon | , |
"Number of phis deleted via common incoming value" | |||
) |
STATISTIC | ( | NumSelects | , |
"Number of selects propagated" | |||
) |
STATISTIC | ( | NumMemAccess | , |
"Number of memory access targets propagated" | |||
) |
STATISTIC | ( | NumCmps | , |
"Number of comparisons propagated" | |||
) |
STATISTIC | ( | NumReturns | , |
"Number of return values propagated" | |||
) |
STATISTIC | ( | NumDeadCases | , |
"Number of switch cases removed" | |||
) |
STATISTIC | ( | NumSDivs | , |
"Number of sdiv converted to udiv" | |||
) |
STATISTIC | ( | NumUDivs | , |
"Number of udivs whose width was decreased" | |||
) |
STATISTIC | ( | NumAShrs | , |
"Number of ashr converted to lshr" | |||
) |
STATISTIC | ( | NumSRems | , |
"Number of srem converted to urem" | |||
) |
STATISTIC | ( | NumOverflows | , |
"Number of overflow checks removed" | |||
) |
|
static |
Definition at line 403 of file CorrelatedValuePropagation.cpp.
References llvm::MCID::Add, llvm::ConstantRange::contains(), llvm::LazyValueInfo::getConstantRange(), llvm::IntrinsicInst::getIntrinsicID(), llvm::User::getOperand(), llvm::Instruction::getParent(), llvm::ConstantRange::isEmptySet(), llvm::ConstantRange::makeGuaranteedNoWrapRegion(), llvm::Intrinsic::sadd_with_overflow, llvm::Intrinsic::ssub_with_overflow, llvm::Intrinsic::uadd_with_overflow, and llvm::Intrinsic::usub_with_overflow.
Referenced by processCallSite(), shouldMergeGEPs(), and llvm::InstCombiner::visitInstruction().
Referenced by processAdd().
correlated Value false |
Definition at line 98 of file CorrelatedValuePropagation.cpp.
correlated propagation |
Definition at line 98 of file CorrelatedValuePropagation.cpp.
correlated Value Propagation |
Definition at line 98 of file CorrelatedValuePropagation.cpp.