#include "InstCombineInternal.h"
#include "llvm/ADT/APFloat.h"
#include "llvm/ADT/APInt.h"
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/STLFunctionalExtras.h"
#include "llvm/ADT/SmallBitVector.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Statistic.h"
#include "llvm/Analysis/AliasAnalysis.h"
#include "llvm/Analysis/AssumeBundleQueries.h"
#include "llvm/Analysis/AssumptionCache.h"
#include "llvm/Analysis/InstructionSimplify.h"
#include "llvm/Analysis/Loads.h"
#include "llvm/Analysis/MemoryBuiltins.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Attributes.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constant.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InlineAsm.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/IntrinsicsAArch64.h"
#include "llvm/IR/IntrinsicsAMDGPU.h"
#include "llvm/IR/IntrinsicsARM.h"
#include "llvm/IR/IntrinsicsHexagon.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PatternMatch.h"
#include "llvm/IR/Statepoint.h"
#include "llvm/IR/Type.h"
#include "llvm/IR/User.h"
#include "llvm/IR/Value.h"
#include "llvm/IR/ValueHandle.h"
#include "llvm/Support/AtomicOrdering.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compiler.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/InstCombine/InstCombiner.h"
#include "llvm/Transforms/Utils/AssumeBundleBuilder.h"
#include "llvm/Transforms/Utils/Local.h"
#include "llvm/Transforms/Utils/SimplifyLibCalls.h"
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <optional>
#include <utility>
#include <vector>
#define DEBUG_TYPE …
#include "llvm/Transforms/Utils/InstructionWorklist.h"
usingnamespacellvm;
usingnamespacePatternMatch;
STATISTIC(NumSimplified, "Number of library calls simplified");
static cl::opt<unsigned> GuardWideningWindow(
"instcombine-guard-widening-window",
cl::init(3),
cl::desc("How wide an instruction window to bypass looking for "
"another guard"));
static Type *getPromotedType(Type *Ty) { … }
static bool hasUndefSource(AnyMemTransferInst *MI) { … }
Instruction *InstCombinerImpl::SimplifyAnyMemTransfer(AnyMemTransferInst *MI) { … }
Instruction *InstCombinerImpl::SimplifyAnyMemSet(AnyMemSetInst *MI) { … }
Value *InstCombinerImpl::simplifyMaskedLoad(IntrinsicInst &II) { … }
Instruction *InstCombinerImpl::simplifyMaskedStore(IntrinsicInst &II) { … }
Instruction *InstCombinerImpl::simplifyMaskedGather(IntrinsicInst &II) { … }
Instruction *InstCombinerImpl::simplifyMaskedScatter(IntrinsicInst &II) { … }
static Instruction *simplifyInvariantGroupIntrinsic(IntrinsicInst &II,
InstCombinerImpl &IC) { … }
static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) { … }
static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) { … }
static Value *simplifyNeonTbl1(const IntrinsicInst &II,
InstCombiner::BuilderTy &Builder) { … }
static bool haveSameOperands(const IntrinsicInst &I, const IntrinsicInst &E,
unsigned NumOperands) { … }
static bool
removeTriviallyEmptyRange(IntrinsicInst &EndI, InstCombinerImpl &IC,
std::function<bool(const IntrinsicInst &)> IsStart) { … }
Instruction *InstCombinerImpl::visitVAEndInst(VAEndInst &I) { … }
static CallInst *canonicalizeConstantArg0ToArg1(CallInst &Call) { … }
static Instruction *createOverflowTuple(IntrinsicInst *II, Value *Result,
Constant *Overflow) { … }
Instruction *
InstCombinerImpl::foldIntrinsicWithOverflowCommon(IntrinsicInst *II) { … }
static bool inputDenormalIsIEEE(const Function &F, const Type *Ty) { … }
static bool inputDenormalIsDAZ(const Function &F, const Type *Ty) { … }
static FCmpInst::Predicate fpclassTestIsFCmp0(FPClassTest Mask,
const Function &F, Type *Ty) { … }
Instruction *InstCombinerImpl::foldIntrinsicIsFPClass(IntrinsicInst &II) { … }
static std::optional<bool> getKnownSign(Value *Op, const SimplifyQuery &SQ) { … }
static std::optional<bool> getKnownSignOrZero(Value *Op,
const SimplifyQuery &SQ) { … }
static bool signBitMustBeTheSame(Value *Op0, Value *Op1,
const SimplifyQuery &SQ) { … }
static Instruction *moveAddAfterMinMax(IntrinsicInst *II,
InstCombiner::BuilderTy &Builder) { … }
Instruction *InstCombinerImpl::matchSAddSubSat(IntrinsicInst &MinMax1) { … }
static Instruction *foldClampRangeOfTwo(IntrinsicInst *II,
InstCombiner::BuilderTy &Builder) { … }
static Value *reassociateMinMaxWithConstants(IntrinsicInst *II,
IRBuilderBase &Builder,
const SimplifyQuery &SQ) { … }
static Instruction *
reassociateMinMaxWithConstantInOperand(IntrinsicInst *II,
InstCombiner::BuilderTy &Builder) { … }
static Instruction *factorizeMinMaxTree(IntrinsicInst *II) { … }
static Instruction *
foldShuffledIntrinsicOperands(IntrinsicInst *II,
InstCombiner::BuilderTy &Builder) { … }
template <Intrinsic::ID IntrID>
static Instruction *foldBitOrderCrossLogicOp(Value *V,
InstCombiner::BuilderTy &Builder) { … }
static Value *simplifyReductionOperand(Value *Arg, bool CanReorderLanes) { … }
template <Intrinsic::ID IntrID>
static Value *
foldMinimumOverTrailingOrLeadingZeroCount(Value *I0, Value *I1,
const DataLayout &DL,
InstCombiner::BuilderTy &Builder) { … }
Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { … }
Instruction *InstCombinerImpl::visitFenceInst(FenceInst &FI) { … }
Instruction *InstCombinerImpl::visitInvokeInst(InvokeInst &II) { … }
Instruction *InstCombinerImpl::visitCallBrInst(CallBrInst &CBI) { … }
Instruction *InstCombinerImpl::tryOptimizeCall(CallInst *CI) { … }
static IntrinsicInst *findInitTrampolineFromAlloca(Value *TrampMem) { … }
static IntrinsicInst *findInitTrampolineFromBB(IntrinsicInst *AdjustTramp,
Value *TrampMem) { … }
static IntrinsicInst *findInitTrampoline(Value *Callee) { … }
bool InstCombinerImpl::annotateAnyAllocSite(CallBase &Call,
const TargetLibraryInfo *TLI) { … }
Instruction *InstCombinerImpl::visitCallBase(CallBase &Call) { … }
bool InstCombinerImpl::transformConstExprCastCall(CallBase &Call) { … }
Instruction *
InstCombinerImpl::transformCallThroughTrampoline(CallBase &Call,
IntrinsicInst &Tramp) { … }