LLVM
15.0.0git
|
#include "InstCombineInternal.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/Analysis/InstructionSimplify.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. More... | |
static Value * | foldMulSelectToNegate (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
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. More... | |
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. More... | |
static Value * | takeLog2 (IRBuilderBase &Builder, Value *Op, unsigned Depth, bool DoFold) |
static Instruction * | narrowUDivURem (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
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). More... | |
static Instruction * | foldFDivConstantDivisor (BinaryOperator &I) |
Remove negation and try to convert division into multiplication. More... | |
static Instruction * | foldFDivConstantDividend (BinaryOperator &I) |
Remove negation and try to reassociate constant math. More... | |
static Instruction * | foldFDivPowDivisor (BinaryOperator &I, InstCombiner::BuilderTy &Builder) |
Negate the exponent of pow/exp to fold division-by-pow() into multiply. More... | |
Variables | |
static const unsigned | MaxDepth = 6 |
#define DEBUG_TYPE "instcombine" |
Definition at line 36 of file InstCombineMulDivRem.cpp.
|
static |
Remove negation and try to reassociate constant math.
Definition at line 1244 of file InstCombineMulDivRem.cpp.
References llvm::BinaryOperator::CreateFDivFMF(), llvm::ConstantExpr::getFDiv(), llvm::ConstantExpr::getFMul(), llvm::ConstantExpr::getFNeg(), 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 |
Remove negation and try to convert division into multiplication.
Definition at line 1215 of file InstCombineMulDivRem.cpp.
References llvm::BinaryOperator::CreateFDivFMF(), llvm::BinaryOperator::CreateFMulFMF(), llvm::ConstantFP::get(), llvm::ConstantExpr::getFDiv(), llvm::ConstantExpr::getFNeg(), I, llvm::PatternMatch::m_Constant(), 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 1277 of file InstCombineMulDivRem.cpp.
References llvm::AMDGPU::HSAMD::Kernel::Key::Args, Builder, llvm::BinaryOperator::CreateFMulFMF(), I, and powi().
Referenced by llvm::InstCombinerImpl::visitFDiv().
|
static |
Definition at line 98 of file InstCombineMulDivRem.cpp.
References Builder, Cond, 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 |
True if C1 is a multiple of C2. Quotient contains C1/C2.
Definition at line 748 of file InstCombineMulDivRem.cpp.
References assert(), C1, llvm::APInt::getBitWidth(), llvm::APInt::isAllOnes(), 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 740 of file InstCombineMulDivRem.cpp.
References C1.
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 987 of file InstCombineMulDivRem.cpp.
References Builder, D, llvm::ConstantExpr::getTrunc(), llvm::ConstantExpr::getZExt(), 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 |
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 45 of file InstCombineMulDivRem.cpp.
References B, llvm::InstCombiner::Builder, llvm::IRBuilderBase::CreateShl(), llvm::IRBuilderBase::CreateSub(), llvm::Value::hasOneUse(), I, llvm::InstCombinerImpl::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::InstCombinerImpl::replaceOperand(), and llvm::NVPTX::PTXLdStInstCode::V2.
Referenced by llvm::InstCombinerImpl::commonIDivTransforms(), and llvm::InstCombinerImpl::commonIRemTransforms().
|
static |
Definition at line 923 of file InstCombineMulDivRem.cpp.
References Builder, llvm::Depth, llvm::ConstantExpr::getExactLogBase2(), llvm_unreachable, llvm::PatternMatch::m_Power2(), llvm::PatternMatch::m_Shl(), llvm::PatternMatch::m_Value(), llvm::PatternMatch::m_ZExt(), llvm::PatternMatch::match(), MaxDepth, SI, X, and Y.
Referenced by llvm::InstCombinerImpl::visitUDiv().
|
static |
Definition at line 918 of file InstCombineMulDivRem.cpp.
Referenced by llvm::SUnit::biasCriticalPath(), combineX86ShufflesRecursively(), directlyImpliesPoison(), llvm::MachineInstr::dumpr(), impliesPoison(), llvm::SITargetLowering::isCanonicalized(), isDereferenceableAndAlignedPointer(), and takeLog2().