LLVM 20.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.
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 2019 of file InstCombineMulDivRem.cpp.
References B, llvm::SmallPtrSetImpl< PtrType >::begin(), llvm::Instruction::clone(), llvm::InstCombinerImpl::eraseInstFromFunction(), llvm::FMul, llvm::CallBase::getArgOperand(), llvm::MDNode::getMostGenericFPMath(), I, llvm::FastMathFlags::intersectRewrite(), llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_SpecificFP(), llvm::PatternMatch::match(), llvm::Mul, R2, llvm::InstCombiner::replaceInstUsesWith(), llvm::Instruction::setMetadata(), llvm::FastMathFlags::unionValue(), and X.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Remove negation and try to reassociate constant math.
Definition at line 1898 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 1933 of file InstCombineMulDivRem.cpp.
References llvm::BinaryOperator::CreateFMulFMF(), llvm::IRBuilderBase::CreateFNegFMF(), llvm::IRBuilderBase::CreateIntrinsic(), llvm::IRBuilderBase::CreateNeg(), I, and II.
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 1979 of file InstCombineMulDivRem.cpp.
References llvm::IRBuilderBase::CreateFDivFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::IRBuilderBase::CreateUnaryIntrinsic(), I, II, llvm::PatternMatch::m_FDiv(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), and Y.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Definition at line 1151 of file InstCombineMulDivRem.cpp.
References assert(), llvm::IRBuilderBase::CreateLShr(), llvm::IRBuilderBase::CreateSDiv(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateUDiv(), llvm::Value::hasOneUse(), I, llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Specific(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::Mul, X, and Y.
Referenced by llvm::InstCombinerImpl::commonIDivTransforms().
|
static |
Definition at line 100 of file InstCombineMulDivRem.cpp.
References Cond, llvm::IRBuilderBase::CreateFNegFMF(), llvm::IRBuilderBase::CreateNeg(), llvm::IRBuilderBase::CreateSelect(), llvm::IRBuilderBase::CreateSelectFMF(), I, llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_c_FMul(), llvm::PatternMatch::m_c_Mul(), llvm::PatternMatch::m_One(), llvm::PatternMatch::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 142 of file InstCombineMulDivRem.cpp.
References llvm::IRBuilderBase::CreateAdd(), llvm::IRBuilderBase::CreateFreeze(), llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), llvm::Value::getName(), llvm::User::getOperand(), llvm::Instruction::hasNoSignedWrap(), llvm::Instruction::hasNoUnsignedWrap(), llvm::isGuaranteedNotToBeUndef(), llvm::PatternMatch::m_Add(), llvm::PatternMatch::m_AllOnes(), llvm::PatternMatch::m_BinOp(), llvm::PatternMatch::m_Not(), llvm::PatternMatch::m_One(), llvm::PatternMatch::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 666 of file InstCombineMulDivRem.cpp.
References A, 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 699 of file InstCombineMulDivRem.cpp.
References llvm::all_of(), llvm::any_of(), llvm::SmallPtrSetImpl< PtrType >::begin(), getFSqrtDivOptPattern(), getParent(), llvm::Instruction::hasAllowReassoc(), llvm::Instruction::hasNoInfs(), llvm::Instruction::hasNoNaNs(), llvm::Instruction::hasNoSignedZeros(), I, R2, and X.
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
True if C1 is a multiple of C2. Quotient contains C1/C2.
Definition at line 1130 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 1122 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 1591 of file InstCombineMulDivRem.cpp.
References llvm::InstCombiner::Builder, llvm::CallingConv::C, llvm::IRBuilderBase::CreateBinOp(), D, llvm::InstCombinerImpl::getLosslessUnsignedTrunc(), I, llvm::PatternMatch::m_Constant(), llvm::PatternMatch::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 2223 of file InstCombineMulDivRem.cpp.
References llvm::CallingConv::C, 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 47 of file InstCombineMulDivRem.cpp.
References A, B, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), I, llvm::InstCombiner::isKnownToBeAPowerOfTwo(), llvm::PatternMatch::m_LShr(), llvm::PatternMatch::m_One(), llvm::PatternMatch::m_OneUse(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::match(), llvm::InstCombiner::replaceOperand(), and simplifyValueKnownNonZero().
Referenced by llvm::InstCombinerImpl::commonIDivRemTransforms(), and simplifyValueKnownNonZero().