|
LLVM 23.0.0git
|
#include "InstCombineInternal.h"#include "llvm/ADT/APInt.h"#include "llvm/ADT/SmallPtrSet.h"#include "llvm/ADT/SmallVector.h"#include "llvm/Analysis/InstructionSimplify.h"#include "llvm/Analysis/ValueTracking.h"#include "llvm/IR/BasicBlock.h"#include "llvm/IR/Constant.h"#include "llvm/IR/Constants.h"#include "llvm/IR/InstrTypes.h"#include "llvm/IR/Instruction.h"#include "llvm/IR/Instructions.h"#include "llvm/IR/IntrinsicInst.h"#include "llvm/IR/Intrinsics.h"#include "llvm/IR/Operator.h"#include "llvm/IR/PatternMatch.h"#include "llvm/IR/Type.h"#include "llvm/IR/Value.h"#include "llvm/Support/Casting.h"#include "llvm/Support/ErrorHandling.h"#include "llvm/Transforms/InstCombine/InstCombiner.h"#include "llvm/Transforms/Utils/BuildLibCalls.h"#include <cassert>#include "llvm/Transforms/Utils/InstructionWorklist.h"Go to the source code of this file.
Namespaces | |
| namespace | llvm |
| This is an optimization pass for GlobalISel generic memory operations. | |
Macros | |
| #define | DEBUG_TYPE "instcombine" |
Functions | |
| static Value * | simplifyValueKnownNonZero (Value *V, InstCombinerImpl &IC, Instruction &CxtI) |
| The specific integer value is used in a context where it is known to be non-zero. | |
| static Value * | foldMulSelectToNegate (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
| static Value * | foldMulShl1 (BinaryOperator &Mul, bool CommuteOperands, InstCombiner::BuilderTy &Builder) |
| Reduce integer multiplication patterns that contain a (+/-1 << Z) factor. | |
| static bool | getFSqrtDivOptPattern (Instruction *Div, SmallPtrSetImpl< Instruction * > &R1, SmallPtrSetImpl< Instruction * > &R2) |
| static bool | isFSqrtDivToFMulLegal (Instruction *X, SmallPtrSetImpl< Instruction * > &R1, SmallPtrSetImpl< Instruction * > &R2) |
| static bool | multiplyOverflows (const APInt &C1, const APInt &C2, APInt &Product, bool IsSigned) |
| True if the multiply can not be expressed in an int this size. | |
| static bool | isMultiple (const APInt &C1, const APInt &C2, APInt &Quotient, bool IsSigned) |
| True if C1 is a multiple of C2. Quotient contains C1/C2. | |
| static Value * | foldIDivShl (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
| static Instruction * | narrowUDivURem (BinaryOperator &I, InstCombinerImpl &IC) |
| If we have zero-extended operands of an unsigned div or rem, we may be able to narrow the operation (sink the zext below the math). | |
| static Instruction * | foldFDivConstantDividend (BinaryOperator &I) |
| Remove negation and try to reassociate constant math. | |
| static Instruction * | foldFDivPowDivisor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
| Negate the exponent of pow/exp to fold division-by-pow() into multiply. | |
| static Instruction * | foldFDivSqrtDivisor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
| Convert div to mul if we have an sqrt divisor iff sqrt's operand is a fdiv instruction. | |
| static Instruction * | convertFSqrtDivIntoFMul (CallInst *CI, Instruction *X, const SmallPtrSetImpl< Instruction * > &R1, const SmallPtrSetImpl< Instruction * > &R2, InstCombiner::BuilderTy &B, InstCombinerImpl *IC) |
| static Instruction * | simplifyIRemMulShl (BinaryOperator &I, InstCombinerImpl &IC) |
| #define DEBUG_TYPE "instcombine" |
Definition at line 38 of file InstCombineMulDivRem.cpp.
|
static |
Definition at line 2070 of file InstCombineMulDivRem.cpp.
References B(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::cast(), llvm::Instruction::clone(), llvm::InstCombinerImpl::eraseInstFromFunction(), llvm::FMul, llvm::CallBase::getArgOperand(), llvm::ilist_node_impl< OptionsT >::getIterator(), llvm::MDNode::getMostGenericFPMath(), I, llvm::FastMathFlags::intersectRewrite(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::match(), Mul, R2, llvm::InstCombiner::replaceInstUsesWith(), llvm::FastMathFlags::unionValue(), and X.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Remove negation and try to reassociate constant math.
Definition at line 1949 of file InstCombineMulDivRem.cpp.
References llvm::CallingConv::C, llvm::ConstantFoldBinaryOpOperands(), llvm::ConstantFoldUnaryOpOperand(), llvm::BinaryOperator::CreateFDivFMF(), DL, I, llvm::Constant::isNormalFP(), llvm::PatternMatch::m_Constant(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FNeg(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and X.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Negate the exponent of pow/exp to fold division-by-pow() into multiply.
Definition at line 1984 of file InstCombineMulDivRem.cpp.
References llvm::BinaryOperator::CreateFMulFMF(), llvm::dyn_cast(), I, II, and Pow.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Convert div to mul if we have an sqrt divisor iff sqrt's operand is a fdiv instruction.
Definition at line 2030 of file InstCombineMulDivRem.cpp.
References llvm::BinaryOperator::CreateFMulFMF(), llvm::dyn_cast(), I, II, llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and Y.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Definition at line 1198 of file InstCombineMulDivRem.cpp.
References assert(), llvm::cast(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Mul, X, and Y.
Referenced by llvm::InstCombinerImpl::commonIDivTransforms().
|
static |
Definition at line 108 of file InstCombineMulDivRem.cpp.
References Cond, I, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_One(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Select(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_Value(), and llvm::PatternMatch::match().
Referenced by llvm::InstCombinerImpl::visitFMul(), and llvm::InstCombinerImpl::visitMul().
|
static |
Reduce integer multiplication patterns that contain a (+/-1 << Z) factor.
Callers are expected to call this twice to handle commuted patterns.
Definition at line 150 of file InstCombineMulDivRem.cpp.
References llvm::cast(), llvm::Instruction::hasNoSignedWrap(), llvm::isGuaranteedNotToBeUndef(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_BinOp(), llvm::MIPatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), Mul, std::swap(), X, and Y.
Referenced by llvm::InstCombinerImpl::visitMul().
|
static |
Definition at line 711 of file InstCombineMulDivRem.cpp.
References A(), llvm::cast(), llvm::SmallPtrSetImplBase::empty(), llvm::User::getOperand(), I, llvm::SmallPtrSetImpl< PtrType >::insert(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_FMul(), llvm::PatternMatch::m_FPOne(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::m_Sqrt(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), R2, and llvm::Value::users().
Referenced by isFSqrtDivToFMulLegal().
|
static |
Definition at line 744 of file InstCombineMulDivRem.cpp.
References llvm::all_of(), llvm::any_of(), llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::cast(), getFSqrtDivOptPattern(), llvm::BasicBlock::getParent(), llvm::Instruction::hasAllowReassoc(), llvm::Instruction::hasNoInfs(), llvm::Instruction::hasNoNaNs(), llvm::Instruction::hasNoSignedZeros(), I, R2, and X.
Referenced by llvm::InstCombinerImpl::visitFDiv().
True if C1 is a multiple of C2. Quotient contains C1/C2.
Definition at line 1177 of file InstCombineMulDivRem.cpp.
References assert(), llvm::APInt::getBitWidth(), llvm::APInt::isAllOnes(), llvm::APInt::isMinSignedValue(), llvm::APInt::isMinValue(), llvm::APInt::isZero(), llvm::APInt::sdivrem(), and llvm::APInt::udivrem().
Referenced by llvm::InstCombinerImpl::commonIDivTransforms().
|
static |
True if the multiply can not be expressed in an int this size.
Definition at line 1169 of file InstCombineMulDivRem.cpp.
References llvm::APInt::smul_ov(), and llvm::APInt::umul_ov().
Referenced by llvm::InstCombinerImpl::commonIDivTransforms().
|
static |
If we have zero-extended operands of an unsigned div or rem, we may be able to narrow the operation (sink the zext below the math).
Definition at line 1641 of file InstCombineMulDivRem.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateBinOp(), D(), DL, llvm::InstCombiner::getDataLayout(), llvm::getLosslessUnsignedTrunc(), I, llvm::isa(), llvm::PatternMatch::m_Constant(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), N, X, and Y.
Referenced by llvm::InstCombinerImpl::visitUDiv(), and llvm::InstCombinerImpl::visitURem().
|
static |
Definition at line 2274 of file InstCombineMulDivRem.cpp.
References llvm::CallingConv::C, llvm::cast(), llvm::APInt::getBitWidth(), llvm::Constant::getNullValue(), llvm::OverflowingBinaryOperator::hasNoSignedWrap(), llvm::OverflowingBinaryOperator::hasNoUnsignedWrap(), I, llvm::APInt::isZero(), llvm::PatternMatch::m_APInt(), llvm::PatternMatch::m_Mul(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setHasNoSignedWrap(), llvm::Instruction::setHasNoUnsignedWrap(), llvm::APInt::ult(), X, and Y.
Referenced by llvm::InstCombinerImpl::commonIRemTransforms().
|
static |
The specific integer value is used in a context where it is known to be non-zero.
If this allows us to simplify the computation, do so and return the new operand, otherwise return null.
Definition at line 51 of file InstCombineMulDivRem.cpp.
References A(), B(), llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), llvm::dyn_cast(), I, llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::MIPatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), llvm::IRBuilderBase::SetInsertPoint(), and simplifyValueKnownNonZero().
Referenced by llvm::InstCombinerImpl::commonIDivRemTransforms(), and simplifyValueKnownNonZero().