56 #include "llvm/IR/IntrinsicsAArch64.h"
57 #include "llvm/IR/IntrinsicsRISCV.h"
58 #include "llvm/IR/IntrinsicsX86.h"
102 return DL.getPointerTypeSizeInBits(Ty);
127 :
DL(
DL), AC(AC), CxtI(CxtI), DT(DT), ORE(ORE), IIQ(UseInstrInfo) {}
141 CxtI = dyn_cast<Instruction>(V);
155 CxtI = dyn_cast<Instruction>(V1);
159 CxtI = dyn_cast<Instruction>(
V2);
167 const APInt &DemandedElts,
171 if (isa<ScalableVectorType>(Shuf->
getType()))
176 int NumMaskElts = cast<FixedVectorType>(Shuf->
getType())->getNumElements();
178 if (DemandedElts.
isZero())
185 for (
int i = 0;
i != NumMaskElts; ++
i) {
186 if (!DemandedElts[
i])
189 assert(
M < (NumElts * 2) &&
"Invalid shuffle mask constant");
196 DemandedLHS.
setBit(
M % NumElts);
198 DemandedRHS.
setBit(
M % NumElts);
205 KnownBits &Known,
unsigned Depth,
const Query &Q);
211 if (isa<ScalableVectorType>(V->
getType())) {
216 auto *FVTy = dyn_cast<FixedVectorType>(V->
getType());
228 Query(
DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo, ORE));
237 Query(
DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo, ORE));
241 unsigned Depth,
const Query &Q);
263 V, DemandedElts,
Depth,
264 Query(
DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo, ORE));
272 "LHS and RHS should have the same type");
274 "LHS and RHS should be integers");
318 return !
I->user_empty() &&
all_of(
I->users(), [](
const User *U) {
319 ICmpInst::Predicate P;
320 return match(U, m_ICmp(P, m_Value(), m_Zero())) && ICmpInst::isEquality(P);
328 bool OrZero,
unsigned Depth,
336 unsigned Depth,
const Query &Q);
344 Query(
DL, AC,
safeCxtI(V, CxtI), DT, UseInstrInfo));
359 if (
auto *CI = dyn_cast<ConstantInt>(V))
360 return CI->getValue().isStrictlyPositive();
385 UseInstrInfo,
nullptr));
400 unsigned Depth,
const Query &Q);
406 if (isa<ScalableVectorType>(V->
getType()))
409 auto *FVTy = dyn_cast<FixedVectorType>(V->
getType());
432 bool NSW,
const APInt &DemandedElts,
434 unsigned Depth,
const Query &Q) {
464 bool isKnownNegativeOp0 = Known2.
isNegative();
467 (isKnownNonNegativeOp1 && isKnownNonNegativeOp0);
472 (isKnownNegativeOp1 && isKnownNonNegativeOp0 &&
474 (isKnownNegativeOp0 && isKnownNonNegativeOp1 && Known.
isNonZero());
478 bool SelfMultiply = Op0 == Op1;
505 for (
unsigned i = 0;
i < NumRanges; ++
i) {
507 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 0));
509 mdconst::extract<ConstantInt>(Ranges.
getOperand(2 *
i + 1));
513 unsigned CommonPrefixBits =
517 Known.
One &= UnsignedMax &
Mask;
533 while (!WorkSet.empty()) {
535 if (!Visited.
insert(V).second)
540 return EphValues.count(U);
545 if (V ==
I || (isa<Instruction>(V) &&
547 !cast<Instruction>(V)->isTerminator())) {
549 if (
const User *U = dyn_cast<User>(V))
561 return CI->isAssumeLikeIntrinsic();
635 if (!Q.AC || !Q.CxtI)
642 AttrKinds.push_back(Attribute::Dereferenceable);
648 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
652 assert(
I->getFunction() == Q.CxtI->getFunction() &&
653 "Got assumption for the wrong function!");
659 assert(
I->getCalledFunction()->getIntrinsicID() == Intrinsic::assume &&
660 "must be an assume intrinsic");
676 unsigned Depth,
const Query &Q) {
679 if (!Q.AC || !Q.CxtI)
687 V, {Attribute::Alignment}, Q.CxtI, Q.DT, Q.AC)) {
696 for (
auto &AssumeVH : Q.AC->assumptionsFor(V)) {
700 assert(
I->getParent()->getParent() == Q.CxtI->getParent()->getParent() &&
701 "Got assumption for the wrong function!");
707 assert(
I->getCalledFunction()->getIntrinsicID() == Intrinsic::assume &&
708 "must be an assume intrinsic");
739 QueryNoAC.AC =
nullptr;
747 switch (Cmp->getPredicate()) {
757 Known.
One |= RHSKnown.
One;
759 }
else if (
match(Cmp,
770 Known.
One |= RHSKnown.
One & MaskKnown.
One;
785 }
else if (
match(Cmp,
811 }
else if (
match(Cmp,
854 Known.
One |= RHSKnown.
One;
876 Known.
One |= RHSKnown.
One <<
C;
991 <<
"Detected conflicting code assumptions. Program may "
992 "have undefined behavior, or compiler may have "
1008 KnownBits &Known2,
unsigned Depth,
const Query &Q,
1019 bool ShiftAmtIsConstant = Known.
isConstant();
1022 if (ShiftAmtIsConstant) {
1023 Known = KF(Known2, Known);
1038 if (MaxShiftAmtIsOutOfRange) {
1055 ShifterOperandIsNonZero =
1057 if (!*ShifterOperandIsNonZero)
1063 for (
unsigned ShiftAmt = 0; ShiftAmt <
BitWidth; ++ShiftAmt) {
1066 if ((ShiftAmt & ~ShiftAmtKZ) != ShiftAmt)
1068 if ((ShiftAmt | ShiftAmtKO) != ShiftAmt)
1073 if (ShiftAmt == 0) {
1074 if (!ShifterOperandIsNonZero)
1075 ShifterOperandIsNonZero =
1077 if (*ShifterOperandIsNonZero)
1092 const APInt &DemandedElts,
1098 switch (
I->getOpcode()) {
1102 Q.IIQ.getMetadata(cast<LoadInst>(
I), LLVMContext::MD_range))
1105 case Instruction::And: {
1117 Value *
X =
nullptr, *
Y =
nullptr;
1118 if (!Known.
Zero[0] && !Known.
One[0] &&
1127 case Instruction::Or:
1133 case Instruction::Xor:
1140 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(
I));
1142 Known, Known2,
Depth, Q);
1145 case Instruction::UDiv: {
1187 Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(
RHS)))
1193 case Instruction::FPTrunc:
1194 case Instruction::FPExt:
1195 case Instruction::FPToUI:
1196 case Instruction::FPToSI:
1197 case Instruction::SIToFP:
1198 case Instruction::UIToFP:
1200 case Instruction::PtrToInt:
1201 case Instruction::IntToPtr:
1204 case Instruction::ZExt:
1205 case Instruction::Trunc: {
1206 Type *SrcTy =
I->getOperand(0)->getType();
1208 unsigned SrcBitWidth;
1213 Q.DL.getPointerTypeSizeInBits(ScalarTy) :
1214 Q.DL.getTypeSizeInBits(ScalarTy);
1216 assert(SrcBitWidth &&
"SrcBitWidth can't be zero");
1222 case Instruction::BitCast: {
1223 Type *SrcTy =
I->getOperand(0)->getType();
1227 !
I->getType()->isVectorTy()) {
1233 auto *SrcVecTy = dyn_cast<FixedVectorType>(SrcTy);
1234 if (!SrcVecTy || !SrcVecTy->getElementType()->isIntegerTy() ||
1235 !
I->getType()->isIntOrIntVectorTy())
1240 unsigned SubBitWidth = SrcVecTy->getScalarSizeInBits();
1257 unsigned SubScale =
BitWidth / SubBitWidth;
1259 for (
unsigned i = 0;
i != NumElts; ++
i) {
1260 if (DemandedElts[
i])
1261 SubDemandedElts.
setBit(
i * SubScale);
1265 for (
unsigned i = 0;
i != SubScale; ++
i) {
1268 unsigned ShiftElt = Q.DL.isLittleEndian() ?
i : SubScale - 1 -
i;
1269 Known.
insertBits(KnownSrc, ShiftElt * SubBitWidth);
1274 case Instruction::SExt: {
1276 unsigned SrcBitWidth =
I->getOperand(0)->getType()->getScalarSizeInBits();
1278 Known = Known.
trunc(SrcBitWidth);
1285 case Instruction::Shl: {
1286 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(
I));
1293 Result.Zero.setSignBit();
1295 Result.One.setSignBit();
1307 case Instruction::LShr: {
1319 case Instruction::AShr: {
1327 case Instruction::Sub: {
1328 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(
I));
1330 DemandedElts, Known, Known2,
Depth, Q);
1334 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(
I));
1336 DemandedElts, Known, Known2,
Depth, Q);
1339 case Instruction::SRem:
1345 case Instruction::URem:
1350 case Instruction::Alloca:
1353 case Instruction::GetElementPtr: {
1362 for (
unsigned i = 1,
e =
I->getNumOperands();
i !=
e; ++
i, ++GTI) {
1378 "Access to structure field must be known at compile time");
1383 unsigned Idx = cast<ConstantInt>(
Index)->getZExtValue();
1386 AccConstIndices += Offset;
1397 unsigned IndexBitWidth =
Index->getType()->getScalarSizeInBits();
1400 TypeSize IndexTypeSize = Q.DL.getTypeAllocSize(IndexedTy);
1411 APInt ScalingFactor(IndexBitWidth, TypeSizeInBytes);
1412 IndexConst *= ScalingFactor;
1429 true,
false, Known, IndexBits);
1434 true,
false, Known,
Index);
1438 case Instruction::PHI: {
1441 Value *R =
nullptr, *L =
nullptr;
1451 if ((Opcode == Instruction::LShr || Opcode == Instruction::AShr ||
1452 Opcode == Instruction::Shl) &&
1467 case Instruction::Shl:
1471 case Instruction::LShr:
1476 case Instruction::AShr:
1488 Opcode == Instruction::Sub ||
1489 Opcode == Instruction::And ||
1490 Opcode == Instruction::Or ||
1498 unsigned OpNum =
P->getOperand(0) == R ? 0 : 1;
1499 Instruction *RInst =
P->getIncomingBlock(OpNum)->getTerminator();
1500 Instruction *LInst =
P->getIncomingBlock(1-OpNum)->getTerminator();
1515 auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1516 if (OverflowOp && Q.IIQ.hasNoSignedWrap(OverflowOp)) {
1535 else if (Opcode == Instruction::Sub && BO->
getOperand(0) ==
I) {
1553 if (
P->getNumIncomingValues() == 0)
1560 if (isa_and_nonnull<UndefValue>(
P->hasConstantValue()))
1565 for (
unsigned u = 0,
e =
P->getNumIncomingValues(); u <
e; ++u) {
1566 Value *IncValue =
P->getIncomingValue(u);
1568 if (IncValue ==
P)
continue;
1575 RecQ.CxtI =
P->getIncomingBlock(u)->getTerminator();
1591 case Instruction::Invoke:
1596 Q.IIQ.getMetadata(cast<Instruction>(
I), LLVMContext::MD_range))
1598 if (
const Value *RV = cast<CallBase>(
I)->getReturnedArgOperand()) {
1604 switch (II->getIntrinsicID()) {
1608 bool IntMinIsPoison =
match(II->getArgOperand(1),
m_One());
1609 Known = Known2.
abs(IntMinIsPoison);
1612 case Intrinsic::bitreverse:
1617 case Intrinsic::bswap:
1622 case Intrinsic::ctlz: {
1629 unsigned LowBits =
Log2_32(PossibleLZ)+1;
1633 case Intrinsic::cttz: {
1640 unsigned LowBits =
Log2_32(PossibleTZ)+1;
1644 case Intrinsic::ctpop: {
1649 unsigned LowBits =
Log2_32(BitsPossiblySet)+1;
1655 case Intrinsic::fshr:
1656 case Intrinsic::fshl: {
1663 if (II->getIntrinsicID() == Intrinsic::fshr)
1676 case Intrinsic::uadd_sat:
1677 case Intrinsic::usub_sat: {
1678 bool IsAdd = II->getIntrinsicID() == Intrinsic::uadd_sat;
1685 unsigned LeadingKnown;
1694 IsAdd,
false, Known, Known2);
1727 case Intrinsic::x86_sse42_crc32_64_64:
1730 case Intrinsic::riscv_vsetvli:
1731 case Intrinsic::riscv_vsetvlimax:
1737 case Intrinsic::vscale: {
1738 if (!II->getParent() || !II->getFunction() ||
1739 !II->getFunction()->hasFnAttribute(Attribute::VScaleRange))
1742 auto Attr = II->getFunction()->getFnAttribute(Attribute::VScaleRange);
1748 unsigned VScaleMin = Attr.getVScaleRangeMin();
1752 if (VScaleMin == VScaleMax) {
1753 Known.
One = VScaleMin;
1754 Known.
Zero = VScaleMin;
1768 case Instruction::ShuffleVector: {
1769 auto *Shuf = dyn_cast<ShuffleVectorInst>(
I);
1777 APInt DemandedLHS, DemandedRHS;
1784 if (!!DemandedLHS) {
1785 const Value *
LHS = Shuf->getOperand(0);
1791 if (!!DemandedRHS) {
1792 const Value *
RHS = Shuf->getOperand(1);
1798 case Instruction::InsertElement: {
1799 const Value *Vec =
I->getOperand(0);
1800 const Value *Elt =
I->getOperand(1);
1801 auto *CIdx = dyn_cast<ConstantInt>(
I->getOperand(2));
1804 if (!CIdx || CIdx->getValue().uge(NumElts)) {
1810 unsigned EltIdx = CIdx->getZExtValue();
1812 if (DemandedElts[EltIdx]) {
1819 APInt DemandedVecElts = DemandedElts;
1821 if (!!DemandedVecElts) {
1827 case Instruction::ExtractElement: {
1830 const Value *Vec =
I->getOperand(0);
1831 const Value *Idx =
I->getOperand(1);
1832 auto *CIdx = dyn_cast<ConstantInt>(Idx);
1833 if (isa<ScalableVectorType>(Vec->
getType())) {
1838 unsigned NumElts = cast<FixedVectorType>(Vec->
getType())->getNumElements();
1840 if (CIdx && CIdx->getValue().ult(NumElts))
1845 case Instruction::ExtractValue:
1846 if (
IntrinsicInst *II = dyn_cast<IntrinsicInst>(
I->getOperand(0))) {
1850 switch (II->getIntrinsicID()) {
1852 case Intrinsic::uadd_with_overflow:
1853 case Intrinsic::sadd_with_overflow:
1855 II->getArgOperand(1),
false, DemandedElts,
1856 Known, Known2,
Depth, Q);
1858 case Intrinsic::usub_with_overflow:
1859 case Intrinsic::ssub_with_overflow:
1861 II->getArgOperand(1),
false, DemandedElts,
1862 Known, Known2,
Depth, Q);
1864 case Intrinsic::umul_with_overflow:
1865 case Intrinsic::smul_with_overflow:
1867 DemandedElts, Known, Known2,
Depth, Q);
1873 case Instruction::Freeze:
1884 unsigned Depth,
const Query &Q) {
1914 KnownBits &Known,
unsigned Depth,
const Query &Q) {
1915 if (!DemandedElts || isa<ScalableVectorType>(V->
getType())) {
1922 assert(V &&
"No Value?");
1930 "Not integer or pointer type!");
1932 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
1934 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
1935 "DemandedElt width should equal the fixed vector number of elements");
1938 "DemandedElt width should be 1 for scalars");
1944 "V and Known should have same BitWidth");
1947 "V and Known should have same BitWidth");
1958 if (isa<ConstantPointerNull>(V) || isa<ConstantAggregateZero>(V)) {
1968 for (
unsigned i = 0,
e = CDV->getNumElements();
i !=
e; ++
i) {
1969 if (!DemandedElts[
i])
1971 APInt Elt = CDV->getElementAsAPInt(
i);
1978 if (
const auto *CV = dyn_cast<ConstantVector>(V)) {
1982 for (
unsigned i = 0,
e = CV->getNumOperands();
i !=
e; ++
i) {
1983 if (!DemandedElts[
i])
1986 auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
1991 const APInt &Elt = ElementCI->getValue();
2002 if (isa<UndefValue>(V))
2007 assert(!isa<ConstantData>(V) &&
"Unhandled constant data!");
2015 if (
const GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
2016 if (!GA->isInterposable())
2021 if (
const Operator *
I = dyn_cast<Operator>(V))
2025 if (isa<PointerType>(V->
getType())) {
2036 assert((Known.
Zero & Known.
One) == 0 &&
"Bits known to be one AND zero?");
2042 unsigned Depth, Query &Q) {
2044 Value *Start =
nullptr, *Step =
nullptr;
2050 if (U.get() == Start) {
2068 return (OrZero || Q.IIQ.hasNoUnsignedWrap(BO) ||
2069 Q.IIQ.hasNoSignedWrap(BO)) &&
2071 case Instruction::SDiv:
2077 case Instruction::UDiv:
2081 return (OrZero || Q.IIQ.isExact(BO)) &&
2083 case Instruction::Shl:
2084 return OrZero || Q.IIQ.hasNoUnsignedWrap(BO) || Q.IIQ.hasNoSignedWrap(BO);
2085 case Instruction::AShr:
2089 case Instruction::LShr:
2090 return OrZero || Q.IIQ.isExact(BO);
2124 Value *
X =
nullptr, *
Y =
nullptr;
2131 if (
const ZExtInst *ZI = dyn_cast<ZExtInst>(V))
2159 if (OrZero || Q.IIQ.hasNoUnsignedWrap(VOBO) ||
2160 Q.IIQ.hasNoSignedWrap(VOBO)) {
2179 if ((~(LHSBits.
Zero & RHSBits.
Zero)).isPowerOf2())
2189 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
2206 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2207 return isKnownToBeAPowerOfTwo(U.get(), OrZero, NewDepth, RecQ);
2233 F =
I->getFunction();
2235 if (!
GEP->isInBounds() ||
2240 assert(
GEP->getType()->isPointerTy() &&
"We only support plain pointer GEP");
2251 GTI != GTE; ++GTI) {
2253 if (
StructType *STy = GTI.getStructTypeOrNull()) {
2254 ConstantInt *OpC = cast<ConstantInt>(GTI.getOperand());
2258 if (ElementOffset > 0)
2264 if (Q.DL.getTypeAllocSize(GTI.getIndexedType()).getKnownMinSize() == 0)
2269 if (
ConstantInt *OpC = dyn_cast<ConstantInt>(GTI.getOperand())) {
2293 if (isa<Constant>(V))
2299 unsigned NumUsesExplored = 0;
2300 for (
auto *U : V->
users()) {
2308 if (
const auto *CB = dyn_cast<CallBase>(U))
2309 if (
auto *CalledFunc = CB->getCalledFunction())
2311 if (CB->getArgOperand(
Arg.getArgNo()) == V &&
2312 Arg.hasNonNullAttr(
false) &&
2333 NonNullIfTrue =
true;
2335 NonNullIfTrue =
false;
2341 for (
auto *CmpU : U->users()) {
2342 assert(WorkList.empty() &&
"Should be!");
2343 if (Visited.
insert(CmpU).second)
2344 WorkList.push_back(CmpU);
2346 while (!WorkList.empty()) {
2355 for (
auto *CurrU : Curr->users())
2356 if (Visited.
insert(CurrU).second)
2357 WorkList.push_back(CurrU);
2361 if (
const BranchInst *BI = dyn_cast<BranchInst>(Curr)) {
2362 assert(BI->isConditional() &&
"uses a comparison!");
2365 BI->getSuccessor(NonNullIfTrue ? 0 : 1);
2369 }
else if (NonNullIfTrue &&
isGuard(Curr) &&
2370 DT->
dominates(cast<Instruction>(Curr), CtxI)) {
2386 for (
unsigned i = 0;
i < NumRanges; ++
i) {
2388 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 *
i + 0));
2390 mdconst::extract<ConstantInt>(Ranges->
getOperand(2 *
i + 1));
2402 Value *Start =
nullptr, *Step =
nullptr;
2403 const APInt *StartC, *StepC;
2418 case Instruction::Shl:
2420 case Instruction::AShr:
2421 case Instruction::LShr:
2438 if (isa<ScalableVectorType>(V->
getType()))
2441 if (
auto *
C = dyn_cast<Constant>(V)) {
2442 if (
C->isNullValue())
2444 if (isa<ConstantInt>(
C))
2448 if (
auto *CE = dyn_cast<ConstantExpr>(
C)) {
2450 if (CE->getOpcode() == Instruction::IntToPtr ||
2451 CE->getOpcode() == Instruction::PtrToInt)
2452 if (Q.DL.getTypeSizeInBits(CE->getOperand(0)->getType())
2454 Q.DL.getTypeSizeInBits(CE->getType()).getFixedSize())
2460 if (
auto *VecTy = dyn_cast<FixedVectorType>(
C->getType())) {
2461 for (
unsigned i = 0,
e = VecTy->getNumElements();
i !=
e; ++
i) {
2462 if (!DemandedElts[
i])
2467 if (!isa<UndefValue>(Elt) && !isa<ConstantInt>(Elt))
2476 if (
const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
2477 if (!GV->isAbsoluteSymbolRef() && !GV->hasExternalWeakLinkage() &&
2478 GV->getType()->getAddressSpace() == 0)
2484 if (
auto *
I = dyn_cast<Instruction>(V)) {
2485 if (
MDNode *Ranges = Q.IIQ.getMetadata(
I, LLVMContext::MD_range)) {
2488 if (
auto *Ty = dyn_cast<IntegerType>(V->
getType())) {
2489 const APInt ZeroValue(Ty->getBitWidth(), 0);
2507 if (isa<AllocaInst>(V) && Q.DL.getAllocaAddrSpace() == 0)
2512 if (
const Argument *A = dyn_cast<Argument>(V)) {
2513 if (((A->hasPassPointeeByValueCopyAttr() &&
2515 A->hasNonNullAttr()))
2520 if (
const LoadInst *LI = dyn_cast<LoadInst>(V))
2521 if (Q.IIQ.getMetadata(LI, LLVMContext::MD_nonnull))
2524 if (
const auto *Call = dyn_cast<CallBase>(V)) {
2525 if (Call->isReturnNonNull())
2547 if (
auto *BCO = dyn_cast<BitCastOperator>(V))
2550 if (
auto *I2P = dyn_cast<IntToPtrInst>(V))
2551 if (Q.DL.getTypeSizeInBits(I2P->getSrcTy()).getFixedSize() <=
2552 Q.DL.getTypeSizeInBits(I2P->getDestTy()).getFixedSize())
2558 if (
auto *P2I = dyn_cast<PtrToIntInst>(V))
2559 if (Q.DL.getTypeSizeInBits(P2I->getSrcTy()).getFixedSize() <=
2560 Q.DL.getTypeSizeInBits(P2I->getDestTy()).getFixedSize())
2566 Value *
X =
nullptr, *
Y =
nullptr;
2572 if (isa<SExtInst>(V) || isa<ZExtInst>(V))
2580 if (Q.IIQ.hasNoUnsignedWrap(BO))
2656 if ((Q.IIQ.hasNoSignedWrap(BO) || Q.IIQ.hasNoUnsignedWrap(BO)) &&
2662 else if (
const SelectInst *
SI = dyn_cast<SelectInst>(V)) {
2668 else if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
2678 RecQ.CxtI = PN->getIncomingBlock(U)->getTerminator();
2679 return isKnownNonZero(U.get(), DemandedElts, NewDepth, RecQ);
2683 else if (
const auto *EEI = dyn_cast<ExtractElementInst>(V)) {
2684 const Value *Vec = EEI->getVectorOperand();
2685 const Value *Idx = EEI->getIndexOperand();
2686 auto *CIdx = dyn_cast<ConstantInt>(Idx);
2687 if (
auto *VecTy = dyn_cast<FixedVectorType>(Vec->
getType())) {
2688 unsigned NumElts = VecTy->getNumElements();
2690 if (CIdx && CIdx->getValue().ult(NumElts))
2696 else if (
const FreezeInst *FI = dyn_cast<FreezeInst>(V)) {
2697 auto *
Op = FI->getOperand(0);
2701 }
else if (
const auto *II = dyn_cast<IntrinsicInst>(V)) {
2702 if (II->getIntrinsicID() == Intrinsic::vscale)
2708 return Known.
One != 0;
2714 if (isa<ScalableVectorType>(V->
getType()))
2717 auto *FVTy = dyn_cast<FixedVectorType>(V->
getType());
2718 APInt DemandedElts =
2743 case Instruction::Sub:
2753 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
2754 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
2755 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
2756 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
2762 !cast<ConstantInt>(Op1->
getOperand(1))->isZero())
2766 case Instruction::Shl: {
2769 auto *OBO1 = cast<OverflowingBinaryOperator>(Op1);
2770 auto *OBO2 = cast<OverflowingBinaryOperator>(Op2);
2771 if ((!OBO1->hasNoUnsignedWrap() || !OBO2->hasNoUnsignedWrap()) &&
2772 (!OBO1->hasNoSignedWrap() || !OBO2->hasNoSignedWrap()))
2779 case Instruction::AShr:
2780 case Instruction::LShr: {
2781 auto *PEO1 = cast<PossiblyExactOperator>(Op1);
2782 auto *PEO2 = cast<PossiblyExactOperator>(Op2);
2783 if (!PEO1->isExact() || !PEO2->isExact())
2790 case Instruction::SExt:
2791 case Instruction::ZExt:
2795 case Instruction::PHI: {
2796 const PHINode *PN1 = cast<PHINode>(Op1);
2797 const PHINode *PN2 = cast<PHINode>(Op2);
2803 Value *Start1 =
nullptr, *Step1 =
nullptr;
2805 Value *Start2 =
nullptr, *Step2 =
nullptr;
2812 cast<Operator>(BO2));
2821 if (Values->first != PN1 || Values->second != PN2)
2824 return std::make_pair(Start1, Start2);
2850 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(
V2)) {
2853 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
2863 if (
auto *OBO = dyn_cast<OverflowingBinaryOperator>(
V2)) {
2866 (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) &&
2873 unsigned Depth,
const Query &Q) {
2879 bool UsedFullRecursion =
false;
2881 if (!VisitedBBs.
insert(IncomBB).second)
2890 if (UsedFullRecursion)
2894 RecQ.CxtI = IncomBB->getTerminator();
2897 UsedFullRecursion =
true;
2917 auto *O1 = dyn_cast<Operator>(V1);
2918 auto *O2 = dyn_cast<Operator>(
V2);
2919 if (O1 && O2 && O1->getOpcode() == O2->getOpcode()) {
2923 if (
const PHINode *PN1 = dyn_cast<PHINode>(V1)) {
2967 return Mask.isSubsetOf(Known.
Zero);
2976 "Input should be a Select!");
2986 const Value *LHS2 =
nullptr, *RHS2 =
nullptr;
2998 return CLow->
sle(*CHigh);
3003 const APInt *&CHigh) {
3008 auto *InnerII = dyn_cast<IntrinsicInst>(II->
getArgOperand(0));
3009 if (!InnerII || InnerII->getIntrinsicID() != InverseID ||
3016 return CLow->
sle(*CHigh);
3024 const APInt &DemandedElts,
3026 const auto *CV = dyn_cast<Constant>(V);
3027 if (!CV || !isa<FixedVectorType>(CV->getType()))
3030 unsigned MinSignBits = TyBits;
3031 unsigned NumElts = cast<FixedVectorType>(CV->getType())->getNumElements();
3032 for (
unsigned i = 0;
i != NumElts; ++
i) {
3033 if (!DemandedElts[
i])
3036 auto *Elt = dyn_cast_or_null<ConstantInt>(CV->getAggregateElement(
i));
3040 MinSignBits =
std::min(MinSignBits, Elt->getValue().getNumSignBits());
3047 const APInt &DemandedElts,
3048 unsigned Depth,
const Query &Q);
3051 unsigned Depth,
const Query &Q) {
3053 assert(Result > 0 &&
"At least one sign bit needs to be present!");
3065 const APInt &DemandedElts,
3066 unsigned Depth,
const Query &Q) {
3071 if (isa<ScalableVectorType>(Ty))
3077 if (
auto *FVTy = dyn_cast<FixedVectorType>(Ty)) {
3079 FVTy->getNumElements() == DemandedElts.
getBitWidth() &&
3080 "DemandedElt width should equal the fixed vector number of elements");
3083 "DemandedElt width should be 1 for scalars");
3093 Q.DL.getPointerTypeSizeInBits(ScalarTy) :
3094 Q.DL.getTypeSizeInBits(ScalarTy);
3097 unsigned FirstAnswer = 1;
3105 if (
auto *U = dyn_cast<Operator>(V)) {
3108 case Instruction::SExt:
3109 Tmp = TyBits - U->getOperand(0)->getType()->getScalarSizeInBits();
3112 case Instruction::SDiv: {
3113 const APInt *Denominator;
3130 case Instruction::SRem: {
3133 const APInt *Denominator;
3154 unsigned ResBits = TyBits - Denominator->
ceilLogBase2();
3161 case Instruction::AShr: {
3166 if (ShAmt->
uge(TyBits))
3169 Tmp += ShAmtLimited;
3170 if (Tmp > TyBits) Tmp = TyBits;
3174 case Instruction::Shl: {
3179 if (ShAmt->
uge(TyBits) ||
3180 ShAmt->
uge(Tmp))
break;
3186 case Instruction::And:
3187 case Instruction::Or:
3188 case Instruction::Xor:
3204 const APInt *CLow, *CHigh;
3209 if (Tmp == 1)
break;
3218 if (Tmp == 1)
break;
3221 if (
const auto *CRHS = dyn_cast<Constant>(U->getOperand(1)))
3222 if (CRHS->isAllOnesValue()) {
3228 if ((Known.
Zero | 1).isAllOnes())
3238 if (Tmp2 == 1)
break;
3241 case Instruction::Sub:
3243 if (Tmp2 == 1)
break;
3246 if (
const auto *CLHS = dyn_cast<Constant>(U->getOperand(0)))
3247 if (CLHS->isNullValue()) {
3252 if ((Known.
Zero | 1).isAllOnes())
3267 if (Tmp == 1)
break;
3274 if (SignBitsOp0 == 1)
break;
3276 if (SignBitsOp1 == 1)
break;
3277 unsigned OutValidBits =
3278 (TyBits - SignBitsOp0 + 1) + (TyBits - SignBitsOp1 + 1);
3279 return OutValidBits > TyBits ? 1 : TyBits - OutValidBits + 1;
3282 case Instruction::PHI: {
3283 const PHINode *PN = cast<PHINode>(U);
3286 if (NumIncomingValues > 4)
break;
3288 if (NumIncomingValues == 0)
break;
3294 for (
unsigned i = 0,
e = NumIncomingValues;
i !=
e; ++
i) {
3295 if (Tmp == 1)
return Tmp;
3303 case Instruction::Trunc:
3308 case Instruction::ExtractElement:
3315 case Instruction::ShuffleVector: {
3318 auto *Shuf = dyn_cast<ShuffleVectorInst>(U);
3323 APInt DemandedLHS, DemandedRHS;
3329 if (!!DemandedLHS) {
3330 const Value *
LHS = Shuf->getOperand(0);
3337 if (!!DemandedRHS) {
3338 const Value *
RHS = Shuf->getOperand(1);
3346 assert(Tmp <= TyBits &&
"Failed to determine minimum sign bits");
3350 if (
const auto *II = dyn_cast<IntrinsicInst>(U)) {
3351 switch (II->getIntrinsicID()) {
3355 if (Tmp == 1)
break;
3361 const APInt *CLow, *CHigh;
3376 if (
unsigned VecSignBits =
3394 if (
F->isIntrinsic())
3395 return F->getIntrinsicID();
3401 if (
F->hasLocalLinkage() || !TLI || !TLI->
getLibFunc(CB, Func) ||
3411 return Intrinsic::sin;
3415 return Intrinsic::cos;
3419 return Intrinsic::exp;
3423 return Intrinsic::exp2;
3427 return Intrinsic::log;
3429 case LibFunc_log10f:
3430 case LibFunc_log10l:
3431 return Intrinsic::log10;
3439 return Intrinsic::fabs;
3448 case LibFunc_copysign:
3449 case LibFunc_copysignf:
3450 case LibFunc_copysignl:
3451 return Intrinsic::copysign;
3453 case LibFunc_floorf:
3454 case LibFunc_floorl:
3461 case LibFunc_truncf:
3462 case LibFunc_truncl:
3467 return Intrinsic::rint;
3468 case LibFunc_nearbyint:
3469 case LibFunc_nearbyintf:
3470 case LibFunc_nearbyintl:
3471 return Intrinsic::nearbyint;
3473 case LibFunc_roundf:
3474 case LibFunc_roundl:
3476 case LibFunc_roundeven:
3477 case LibFunc_roundevenf:
3478 case LibFunc_roundevenl:
3479 return Intrinsic::roundeven;
3483 return Intrinsic::pow;
3487 return Intrinsic::sqrt;
3500 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3501 return !CFP->getValueAPF().isNegZero();
3506 auto *
Op = dyn_cast<Operator>(V);
3515 if (isa<SIToFPInst>(
Op) || isa<UIToFPInst>(
Op))
3518 if (
auto *Call = dyn_cast<CallInst>(
Op)) {
3524 case Intrinsic::sqrt:
3525 case Intrinsic::canonicalize:
3527 case Intrinsic::experimental_constrained_sqrt: {
3529 const auto *CI = cast<ConstrainedFPIntrinsic>(Call);
3536 case Intrinsic::fabs:
3539 case Intrinsic::experimental_constrained_sitofp:
3540 case Intrinsic::experimental_constrained_uitofp:
3560 if (
const ConstantFP *CFP = dyn_cast<ConstantFP>(V)) {
3561 return !CFP->getValueAPF().isNegative() ||
3562 (!SignBitOnly && CFP->getValueAPF().isZero());
3566 if (
auto *CV = dyn_cast<Constant>(V)) {
3567 if (
auto *CVFVTy = dyn_cast<FixedVectorType>(CV->getType())) {
3568 unsigned NumElts = CVFVTy->getNumElements();
3569 for (
unsigned i = 0;
i != NumElts; ++
i) {
3570 auto *CFP = dyn_cast_or_null<ConstantFP>(CV->getAggregateElement(
i));
3573 if (CFP->getValueAPF().isNegative() &&
3574 (SignBitOnly || !CFP->getValueAPF().isZero()))
3586 const Operator *
I = dyn_cast<Operator>(V);
3590 switch (
I->getOpcode()) {
3594 case Instruction::UIToFP:
3596 case Instruction::FMul:
3597 case Instruction::FDiv:
3600 if (
I->getOperand(0) ==
I->getOperand(1) &&
3601 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()))
3605 case Instruction::FAdd:
3606 case Instruction::FRem:
3616 case Instruction::FPExt:
3617 case Instruction::FPTrunc:
3621 case Instruction::ExtractElement:
3628 const auto *CI = cast<CallInst>(
I);
3634 Value *V0 =
I->getOperand(0), *V1 =
I->getOperand(1);
3635 auto isPositiveNum = [&](
Value *V) {
3653 return isPositiveNum(V0) || isPositiveNum(V1);
3667 case Intrinsic::exp:
3668 case Intrinsic::exp2:
3669 case Intrinsic::fabs:
3672 case Intrinsic::sqrt:
3676 return CI->hasNoNaNs() && (CI->hasNoSignedZeros() ||
3701 case Intrinsic::fma:
3702 case Intrinsic::fmuladd:
3704 return I->getOperand(0) ==
I->getOperand(1) &&
3705 (!SignBitOnly || cast<FPMathOperator>(
I)->hasNoNaNs()) &&
3728 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
3729 if (FPMathOp->hasNoInfs())
3733 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3734 return !CFP->isInfinity();
3739 if (
auto *Inst = dyn_cast<Instruction>(V)) {
3740 switch (Inst->getOpcode()) {
3745 case Instruction::SIToFP:
3746 case Instruction::UIToFP: {
3750 int IntSize = Inst->getOperand(0)->getType()->getScalarSizeInBits();
3751 if (Inst->getOpcode() == Instruction::SIToFP)
3765 auto *VFVTy = dyn_cast<FixedVectorType>(V->
getType());
3766 if (VFVTy && isa<Constant>(V)) {
3768 unsigned NumElts = VFVTy->getNumElements();
3769 for (
unsigned i = 0;
i != NumElts; ++
i) {
3773 if (isa<UndefValue>(Elt))
3775 auto *CElt = dyn_cast<ConstantFP>(Elt);
3776 if (!CElt || CElt->isInfinity())
3792 if (
auto *FPMathOp = dyn_cast<FPMathOperator>(V))
3793 if (FPMathOp->hasNoNaNs())
3797 if (
auto *CFP = dyn_cast<ConstantFP>(V))
3798 return !CFP->isNaN();
3803 if (
auto *Inst = dyn_cast<Instruction>(V)) {
3804 switch (Inst->getOpcode()) {
3805 case Instruction::FAdd:
3806 case Instruction::FSub:
3813 case Instruction::FMul:
3821 case Instruction::FDiv:
3822 case Instruction::FRem:
3830 case Instruction::SIToFP:
3831 case Instruction::UIToFP:
3833 case Instruction::FPTrunc:
3834 case Instruction::FPExt:
3841 if (
const auto *II = dyn_cast<IntrinsicInst>(V)) {
3842 switch (II->getIntrinsicID()) {
3843 case Intrinsic::canonicalize:
3844 case Intrinsic::fabs:
3845 case Intrinsic::copysign:
3846 case Intrinsic::exp:
3847 case Intrinsic::exp2:
3851 case Intrinsic::rint:
3852 case Intrinsic::nearbyint:
3854 case Intrinsic::roundeven:
3856 case Intrinsic::sqrt:
3870 auto *VFVTy = dyn_cast<FixedVectorType>(V->
getType());
3871 if (VFVTy && isa<Constant>(V)) {
3873 unsigned NumElts = VFVTy->getNumElements();
3874 for (
unsigned i = 0;
i != NumElts; ++
i) {
3878 if (isa<UndefValue>(Elt))
3880 auto *CElt = dyn_cast<ConstantFP>(Elt);
3881 if (!CElt || CElt->isNaN())
3902 if (isa<UndefValue>(V))
3906 if (!
DL.getTypeStoreSize(V->
getType()).isNonZero())
3921 if (
C->isNullValue())
3928 if (CFP->getType()->isHalfTy())
3930 else if (CFP->getType()->isFloatTy())
3932 else if (CFP->getType()->isDoubleTy())
3941 if (CI->getBitWidth() % 8 == 0) {
3942 assert(CI->getBitWidth() > 8 &&
"8 bits should be handled above!");
3943 if (!CI->getValue().isSplat(8))
3949 if (
auto *CE = dyn_cast<ConstantExpr>(
C)) {
3950 if (CE->getOpcode() == Instruction::IntToPtr) {
3951 if (
auto *PtrTy = dyn_cast<PointerType>(CE->getType())) {
3952 unsigned BitWidth =
DL.getPointerSizeInBits(PtrTy->getAddressSpace());
3966 if (
LHS == UndefInt8)
3968 if (
RHS == UndefInt8)
3974 Value *Val = UndefInt8;
3975 for (
unsigned I = 0,
E = CA->getNumElements();
I !=
E; ++
I)
3981 if (isa<ConstantAggregate>(
C)) {
3982 Value *Val = UndefInt8;
3983 for (
unsigned I = 0,
E =
C->getNumOperands();
I !=
E; ++
I)
4003 StructType *STy = dyn_cast<StructType>(IndexedType);
4017 while (PrevTo != OrigTo) {
4043 "tmp", InsertBefore);
4060 assert(InsertBefore &&
"Must have someplace to insert!");
4065 unsigned IdxSkip = Idxs.size();
4080 if (idx_range.
empty())
4084 "Not looking at a struct or array?");
4086 "Invalid indices for type?");
4088 if (
Constant *
C = dyn_cast<Constant>(V)) {
4089 C =
C->getAggregateElement(idx_range[0]);
4090 if (!
C)
return nullptr;
4097 const unsigned *req_idx = idx_range.
begin();
4098 for (
const unsigned *
i =
I->idx_begin(), *
e =
I->idx_end();
4099 i !=
e; ++
i, ++req_idx) {
4100 if (req_idx == idx_range.
end()) {
4140 unsigned size =
I->getNumIndices() + idx_range.
size();
4145 Idxs.
append(
I->idx_begin(),
I->idx_end());
4151 &&
"Number of indices added not correct?");
4161 unsigned CharSize) {
4163 if (
GEP->getNumOperands() != 3)
4168 ArrayType *AT = dyn_cast<ArrayType>(
GEP->getSourceElementType());
4174 const ConstantInt *FirstIdx = dyn_cast<ConstantInt>(
GEP->getOperand(1));
4175 if (!FirstIdx || !FirstIdx->
isZero())
4187 unsigned ElementSize,
uint64_t Offset) {
4198 const ConstantInt *FirstIdx = dyn_cast<ConstantInt>(
GEP->getOperand(1));
4199 if (!FirstIdx || !FirstIdx->
isZero())
4209 APInt Off(
DL.getIndexSizeInBits(
GEP->getPointerAddressSpace()), 0);
4210 if (!
GEP->accumulateConstantOffset(
DL, Off))
4214 uint64_t StartIdx = Off.getLimitedValue();
4234 uint64_t SizeInBytes =
DL.getTypeStoreSize(GVTy).getFixedSize();
4235 uint64_t Length = SizeInBytes / (ElementSize / 8);
4236 if (Length <= Offset)
4241 Slice.
Array =
nullptr;
4243 Slice.
Length = Length - Offset;
4248 if (
auto *ArrayInit = dyn_cast<ConstantDataArray>(
Init)) {
4249 Type *InitElTy = ArrayInit->getElementType();
4254 ArrayTy = ArrayInit->getType();
4259 if (ElementSize != 8)
4270 Array = dyn_cast<ConstantDataArray>(
Init);
4271 ArrayTy = dyn_cast<ArrayType>(
Init->getType());
4275 if (Offset > NumElts)
4278 Slice.
Array = Array;
4280 Slice.
Length = NumElts - Offset;
4293 if (Slice.
Array ==
nullptr) {
4310 Str = Str.substr(Slice.
Offset);
4316 Str = Str.substr(0, Str.find(
'\0'));
4329 unsigned CharSize) {
4335 if (
const PHINode *PN = dyn_cast<PHINode>(V)) {
4336 if (!PHIs.
insert(PN).second)
4341 for (
Value *IncValue : PN->incoming_values()) {
4343 if (Len == 0)
return 0;
4345 if (Len == ~0ULL)
continue;
4347 if (Len != LenSoFar && LenSoFar != ~0ULL)
4359 if (Len1 == 0)
return 0;
4361 if (Len2 == 0)
return 0;
4362 if (Len1 == ~0ULL)
return Len2;
4363 if (Len2 == ~0ULL)
return Len1;
4364 if (Len1 != Len2)
return 0;
4373 if (Slice.
Array ==
nullptr)
4377 unsigned NullIndex = 0;
4378 for (
unsigned E = Slice.
Length; NullIndex <
E; ++NullIndex) {
4383 return NullIndex + 1;
4396 return Len == ~0ULL ? 1 : Len;
4401 bool MustPreserveNullness) {
4403 "getArgumentAliasingToReturnedPointer only works on nonnull calls");
4404 if (
const Value *RV = Call->getReturnedArgOperand())
4408 Call, MustPreserveNullness))
4409 return Call->getArgOperand(0);
4414 const CallBase *Call,
bool MustPreserveNullness) {
4415 switch (Call->getIntrinsicID()) {
4416 case Intrinsic::launder_invariant_group:
4417 case Intrinsic::strip_invariant_group:
4418 case Intrinsic::aarch64_irg:
4419 case Intrinsic::aarch64_tagp:
4421 case Intrinsic::ptrmask:
4422 return !MustPreserveNullness;
4439 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
4441 if (!PrevValue || LI->
getLoopFor(PrevValue->getParent()) != L)
4449 if (
auto *
Load = dyn_cast<LoadInst>(PrevValue))
4458 for (
unsigned Count = 0; MaxLookup == 0 || Count < MaxLookup; ++Count) {
4459 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
4460 V =
GEP->getPointerOperand();
4463 V = cast<Operator>(V)->getOperand(0);
4466 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
4467 if (GA->isInterposable())
4469 V = GA->getAliasee();
4471 if (
auto *PHI = dyn_cast<PHINode>(V)) {
4473 if (PHI->getNumIncomingValues() == 1) {
4474 V = PHI->getIncomingValue(0);
4477 }
else if (
auto *Call = dyn_cast<CallBase>(V)) {
4502 LoopInfo *LI,
unsigned MaxLookup) {
4505 Worklist.push_back(V);
4510 if (!Visited.
insert(
P).second)
4513 if (
auto *
SI = dyn_cast<SelectInst>(
P)) {
4514 Worklist.push_back(
SI->getTrueValue());
4515 Worklist.push_back(
SI->getFalseValue());
4519 if (
auto *PN = dyn_cast<PHINode>(
P)) {
4536 Objects.push_back(
P);
4537 }
while (!Worklist.empty());
4544 if (
const Operator *U = dyn_cast<Operator>(V)) {
4547 if (U->getOpcode() == Instruction::PtrToInt)
4548 return U->getOperand(0);
4556 (!isa<ConstantInt>(U->getOperand(1)) &&
4558 !isa<PHINode>(U->getOperand(1))))
4560 V = U->getOperand(0);
4581 for (
const Value *V : Objs) {
4582 if (!Visited.
insert(V).second)
4587 if (
O->getType()->isPointerTy()) {
4588 Working.push_back(
O);
4598 Objects.push_back(
const_cast<Value *
>(V));
4600 }
while (!Working.empty());
4609 auto AddWork = [&](
Value *V) {
4610 if (Visited.
insert(V).second)
4611 Worklist.push_back(V);
4619 if (
AllocaInst *AI = dyn_cast<AllocaInst>(V)) {
4620 if (Result && Result != AI)
4623 }
else if (
CastInst *CI = dyn_cast<CastInst>(V)) {
4624 AddWork(CI->getOperand(0));
4625 }
else if (
PHINode *PN = dyn_cast<PHINode>(V)) {
4626 for (
Value *IncValue : PN->incoming_values())
4628 }
else if (
auto *
SI = dyn_cast<SelectInst>(V)) {
4629 AddWork(
SI->getTrueValue());
4630 AddWork(
SI->getFalseValue());
4632 if (OffsetZero && !
GEP->hasAllZeroIndices())
4634 AddWork(
GEP->getPointerOperand());
4635 }
else if (
CallBase *CB = dyn_cast<CallBase>(V)) {
4636 Value *Returned = CB->getReturnedArgOperand();
4644 }
while (!Worklist.empty());
4650 const Value *V,
bool AllowLifetime,
bool AllowDroppable) {
4681 return F.hasFnAttribute(Attribute::SanitizeThread) ||
4683 F.hasFnAttribute(Attribute::SanitizeAddress) ||
4684 F.hasFnAttribute(Attribute::SanitizeHWAddress);
4692 const Operator *Inst = dyn_cast<Operator>(V);
4706 auto hasEqualReturnAndLeadingOperandTypes =
4707 [](
const Operator *Inst,
unsigned NumLeadingOperands) {
4711 for (
unsigned ItOp = 0; ItOp < NumLeadingOperands; ++ItOp)
4717 hasEqualReturnAndLeadingOperandTypes(Inst, 2));
4719 hasEqualReturnAndLeadingOperandTypes(Inst, 1));
4731 case Instruction::UDiv:
4732 case Instruction::URem: {
4739 case Instruction::SDiv:
4740 case Instruction::SRem: {
4742 const APInt *Numerator, *Denominator;
4746 if (*Denominator == 0)
4759 const LoadInst *LI = dyn_cast<LoadInst>(Inst);
4770 auto *CI = dyn_cast<const CallInst>(Inst);
4779 case Instruction::VAArg:
4780 case Instruction::Alloca:
4781 case Instruction::Invoke:
4782 case Instruction::CallBr:
4783 case Instruction::PHI:
4786 case Instruction::Br:
4787 case Instruction::IndirectBr:
4788 case Instruction::Switch:
4789 case Instruction::Unreachable:
4790 case Instruction::Fence:
4791 case Instruction::AtomicRMW:
4792 case Instruction::AtomicCmpXchg:
4793 case Instruction::LandingPad:
4794 case Instruction::Resume:
4795 case Instruction::CatchSwitch:
4796 case Instruction::CatchPad:
4797 case Instruction::CatchRet:
4798 case Instruction::CleanupPad:
4799 case Instruction::CleanupRet:
4805 if (
I.mayReadOrWriteMemory())
4841 V,
DL,
Depth, AC, CxtI, DT, ORE, UseInstrInfo);
4852 bool UseInstrInfo) {
4854 nullptr, UseInstrInfo);
4856 nullptr, UseInstrInfo);
4896 nullptr, UseInstrInfo);
4898 nullptr, UseInstrInfo);
4908 bool UseInstrInfo) {
4910 LHS,
false,
DL, 0, AC, CxtI, DT,
4911 nullptr, UseInstrInfo);
4913 RHS,
false,
DL, 0, AC, CxtI, DT,
4914 nullptr, UseInstrInfo);