LLVM: lib/IR/ConstantRange.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

25#include "llvm/Config/llvm-config.h"

38#include

39#include

40#include

41#include

42

43using namespace llvm;

44

48

50 : Lower(std::move(V)), Upper(Lower + 1) {}

51

54 assert(Lower.getBitWidth() == Upper.getBitWidth() &&

55 "ConstantRange with unequal bit widths");

56 assert((Lower != Upper || (Lower.isMaxValue() || Lower.isMinValue())) &&

57 "Lower == Upper, but they aren't min or max value!");

58}

59

61 bool IsSigned) {

66

67

68

71

72

73

76 Upper.clearSignBit();

78}

79

81

82

85

86

90 if (std::optional DifferentBit =

94 }

95 return Known;

96}

97

102

104 BW == 1 ? getEmpty() : ConstantRange(One, SignedMin);

107}

108

112 return CR;

113

115 switch (Pred) {

116 default:

117 llvm_unreachable("Invalid ICmp predicate to makeAllowedICmpRegion()");

119 return CR;

123 return getFull(W);

126 if (UMax.isMinValue())

127 return getEmpty(W);

129 }

132 if (SMax.isMinSignedValue())

133 return getEmpty(W);

135 }

142 if (UMin.isMaxValue())

143 return getEmpty(W);

145 }

148 if (SMin.isMaxSignedValue())

149 return getEmpty(W);

151 }

156 }

157}

158

168

171

172

173

174

175

176

178}

179

183 return true;

184

187}

188

192 return true;

193

196}

197

202 "Only for relational integer predicates!");

203

206

208 return FlippedSignednessPred;

209

212

214}

215

224 RHS = *OnlyElt;

227 RHS = *OnlyMissingElt;

228 } else if (getLower().isMinSignedValue() || getLower().isMinValue()) {

229 Pred =

232 } else if (getUpper().isMinSignedValue() || getUpper().isMinValue()) {

233 Pred =

236 } else {

240 }

241

243 "Bad result!");

244}

245

247 APInt &RHS) const {

250 return Offset.isZero();

251}

252

256 return true;

257

258 switch (Pred) {

261 if (const APInt *R = Other.getSingleElement())

262 return *L == *R;

263 return false;

282 default:

284 }

285}

286

287

289 unsigned BitWidth = V.getBitWidth();

290 if (V == 0)

291 return ConstantRange::getFull(V.getBitWidth());

292

298}

299

300

302

303 unsigned BitWidth = V.getBitWidth();

304 if (V == 0)

305 return ConstantRange::getFull(BitWidth);

306

309

310 if (V.isAllOnes())

312

314 if (V.isNegative()) {

317 } else {

320 }

322}

323

327 unsigned NoWrapKind) {

329

331

332 assert((NoWrapKind == OBO::NoSignedWrap ||

333 NoWrapKind == OBO::NoUnsignedWrap) &&

334 "NoWrapKind invalid!");

335

336 bool Unsigned = NoWrapKind == OBO::NoUnsignedWrap;

338

339 switch (BinOp) {

340 default:

342

343 case Instruction::Add: {

346

350 SMin.isNegative() ? SignedMinVal - SMin : SignedMinVal,

351 SMax.isStrictlyPositive() ? SignedMinVal - SMax : SignedMinVal);

352 }

353

354 case Instruction::Sub: {

357

361 SMax.isStrictlyPositive() ? SignedMinVal + SMax : SignedMinVal,

362 SMin.isNegative() ? SignedMinVal + SMin : SignedMinVal);

363 }

364

365 case Instruction::Mul:

368

369

370 if (const APInt *C = Other.getSingleElement())

372

375

376 case Instruction::Shl: {

377

378

382

383

385 }

386

387

388

395 }

396 }

397}

398

401 unsigned NoWrapKind) {

402

403

405}

406

409 unsigned BitWidth = Mask.getBitWidth();

410

411 if ((Mask & C) != C)

413

414 if (Mask.isZero())

416

417

418

419

422}

423

425 return Lower == Upper && Lower.isMaxValue();

426}

427

429 return Lower == Upper && Lower.isMinValue();

430}

431

433 return Lower.ugt(Upper) && !Upper.isZero();

434}

435

437 return Lower.ugt(Upper);

438}

439

441 return Lower.sgt(Upper) && !Upper.isMinSignedValue();

442}

443

445 return Lower.sgt(Upper);

446}

447

448bool

452 return false;

453 if (Other.isFullSet())

454 return true;

455 return (Upper - Lower).ult(Other.Upper - Other.Lower);

456}

457

458bool

460

461

464

465 return (Upper - Lower).ugt(MaxSize);

466}

467

469

471 return true;

473 return false;

474

476}

477

482

484

486 return true;

488 return false;

489

491}

492

498

504

510

516

518 if (Lower == Upper)

520

522 return Lower.ule(V) && V.ult(Upper);

523 return Lower.ule(V) || V.ult(Upper);

524}

525

529

531 if (Other.isUpperWrapped())

532 return false;

533

534 return Lower.ule(Other.getLower()) && Other.getUpper().ule(Upper);

535 }

536

537 if (Other.isUpperWrapped())

538 return Other.getUpper().ule(Upper) ||

539 Lower.ule(Other.getLower());

540

541 return Other.getUpper().ule(Upper) && Lower.ule(Other.getLower());

542}

543

550

553 return 0;

554

555 return std::max(getSignedMin().getSignificantBits(),

557}

558

561

562 if (Lower == Upper)

563 return *this;

565}

566

570

576 return CR1;

578 return CR2;

581 return CR1;

583 return CR2;

584 }

585

587 return CR1;

588 return CR2;

589}

590

594 "ConstantRange types don't agree!");

595

596

599

602

604 if (Lower.ult(CR.Lower)) {

605

606

607 if (Upper.ule(CR.Lower))

608 return getEmpty();

609

610

611

612 if (Upper.ult(CR.Upper))

614

615

616

617 return CR;

618 }

619

620

621 if (Upper.ult(CR.Upper))

622 return *this;

623

624

625

626 if (Lower.ult(CR.Upper))

628

629

630

631 return getEmpty();

632 }

633

635 if (CR.Lower.ult(Upper)) {

636

637

638 if (CR.Upper.ult(Upper))

639 return CR;

640

641

642

643 if (CR.Upper.ule(Lower))

645

646

647

649 }

650 if (CR.Lower.ult(Lower)) {

651

652

653 if (CR.Upper.ule(Lower))

654 return getEmpty();

655

656

657

659 }

660

661

662

663 return CR;

664 }

665

666 if (CR.Upper.ult(Upper)) {

667

668

669 if (CR.Lower.ult(Upper))

671

672

673

674 if (CR.Lower.ult(Lower))

676

677

678

679 return CR;

680 }

681 if (CR.Upper.ule(Lower)) {

682

683

684 if (CR.Lower.ult(Lower))

685 return *this;

686

687

688

690 }

691

692

693

695}

696

700 "ConstantRange types don't agree!");

701

704

707

709

710

711

712

713

714 if (CR.Upper.ult(Lower) || Upper.ult(CR.Lower))

717

718 APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;

719 APInt U = (CR.Upper - 1).ugt(Upper - 1) ? CR.Upper : Upper;

720

721 if (L.isZero() && U.isZero())

722 return getFull();

723

724 return ConstantRange(std::move(L), std::move(U));

725 }

726

728

729

730 if (CR.Upper.ule(Upper) || CR.Lower.uge(Lower))

731 return *this;

732

733

734

735 if (CR.Lower.ule(Upper) && Lower.ule(CR.Upper))

736 return getFull();

737

738

739

740

741

742

743 if (Upper.ult(CR.Lower) && CR.Upper.ult(Lower))

746

747

748

749 if (Upper.ult(CR.Lower) && Lower.ule(CR.Upper))

751

752

753

754 assert(CR.Lower.ule(Upper) && CR.Upper.ult(Lower) &&

755 "ConstantRange::unionWith missed a case with one range wrapped");

757 }

758

759

760

761 if (CR.Lower.ule(Upper) || Lower.ule(CR.Upper))

762 return getFull();

763

764 APInt L = CR.Lower.ult(Lower) ? CR.Lower : Lower;

765 APInt U = CR.Upper.ugt(Upper) ? CR.Upper : Upper;

766

767 return ConstantRange(std::move(L), std::move(U));

768}

769

770std::optional

772

775 return Result;

776 return std::nullopt;

777}

778

779std::optional

781

784 return Result;

785 return std::nullopt;

786}

787

789 uint32_t ResultBitWidth) const {

790 switch (CastOp) {

791 default:

793 case Instruction::Trunc:

794 return truncate(ResultBitWidth);

795 case Instruction::SExt:

797 case Instruction::ZExt:

799 case Instruction::BitCast:

800 return *this;

801 case Instruction::FPToUI:

802 case Instruction::FPToSI:

804 return *this;

805 else

806 return getFull(ResultBitWidth);

807 case Instruction::UIToFP: {

808

812 if (ResultBitWidth > BW) {

813 Min = Min.zext(ResultBitWidth);

814 Max = Max.zext(ResultBitWidth);

815 }

816 return getNonEmpty(std::move(Min), std::move(Max) + 1);

817 }

818 case Instruction::SIToFP: {

819

823 if (ResultBitWidth > BW) {

824 SMin = SMin.sext(ResultBitWidth);

825 SMax = SMax.sext(ResultBitWidth);

826 }

828 }

829 case Instruction::FPTrunc:

830 case Instruction::FPExt:

831 case Instruction::IntToPtr:

832 case Instruction::PtrToAddr:

833 case Instruction::PtrToInt:

834 case Instruction::AddrSpaceCast:

835

836 return getFull(ResultBitWidth);

837 };

838}

839

841 if (isEmptySet()) return getEmpty(DstTySize);

842

844 if (DstTySize == SrcTySize)

845 return *this;

846 assert(SrcTySize < DstTySize && "Not a value extension");

848

849 APInt LowerExt(DstTySize, 0);

850 if (!Upper)

851 LowerExt = Lower.zext(DstTySize);

854 }

855

856 return ConstantRange(Lower.zext(DstTySize), Upper.zext(DstTySize));

857}

858

860 if (isEmptySet()) return getEmpty(DstTySize);

861

863 if (DstTySize == SrcTySize)

864 return *this;

865 assert(SrcTySize < DstTySize && "Not a value extension");

866

867

868 if (Upper.isMinSignedValue())

869 return ConstantRange(Lower.sext(DstTySize), Upper.zext(DstTySize));

870

874 }

875

876 return ConstantRange(Lower.sext(DstTySize), Upper.sext(DstTySize));

877}

878

880 unsigned NoWrapKind) const {

882 return *this;

885 return getEmpty(DstTySize);

887 return getFull(DstTySize);

888

889 APInt LowerDiv(Lower), UpperDiv(Upper);

890 ConstantRange Union(DstTySize, false);

891

892

893

894

896

897

898 if (Upper.getActiveBits() > DstTySize)

899 return getFull(DstTySize);

900

901

905 } else {

906

907

908 if (Upper.countr_one() == DstTySize)

909 return getFull(DstTySize);

910 Union =

913

914

915 if (LowerDiv == UpperDiv)

916 return Union;

917 }

918 }

919

920

921 if (LowerDiv.getActiveBits() > DstTySize) {

922

923

925 return Union;

926

928 LowerDiv -= Adjust;

929 UpperDiv -= Adjust;

930 }

931

932 unsigned UpperDivWidth = UpperDiv.getActiveBits();

933 if (UpperDivWidth <= DstTySize)

935 UpperDiv.trunc(DstTySize)).unionWith(Union);

936

939 .unionWith(Union);

940

941

942 if (UpperDivWidth == DstTySize + 1) {

943

944 UpperDiv.clearBit(DstTySize);

945 if (UpperDiv.ult(LowerDiv))

947 UpperDiv.trunc(DstTySize)).unionWith(Union);

948 }

949

950 return getFull(DstTySize);

951}

952

955 if (SrcTySize > DstTySize)

957 if (SrcTySize < DstTySize)

959 return *this;

960}

961

964 if (SrcTySize > DstTySize)

966 if (SrcTySize < DstTySize)

968 return *this;

969}

970

974

975 switch (BinOp) {

976 case Instruction::Add:

978 case Instruction::Sub:

980 case Instruction::Mul:

982 case Instruction::UDiv:

984 case Instruction::SDiv:

986 case Instruction::URem:

988 case Instruction::SRem:

990 case Instruction::Shl:

992 case Instruction::LShr:

994 case Instruction::AShr:

996 case Instruction::And:

998 case Instruction::Or:

1000 case Instruction::Xor:

1002

1003

1004 case Instruction::FAdd:

1006 case Instruction::FSub:

1008 case Instruction::FMul:

1010 default:

1011

1012 return getFull();

1013 }

1014}

1015

1018 unsigned NoWrapKind) const {

1020

1021 switch (BinOp) {

1022 case Instruction::Add:

1024 case Instruction::Sub:

1026 case Instruction::Mul:

1028 case Instruction::Shl:

1030 default:

1031

1032

1034 }

1035}

1036

1038 switch (IntrinsicID) {

1039 case Intrinsic::uadd_sat:

1040 case Intrinsic::usub_sat:

1041 case Intrinsic::sadd_sat:

1042 case Intrinsic::ssub_sat:

1043 case Intrinsic::umin:

1044 case Intrinsic::umax:

1045 case Intrinsic::smin:

1046 case Intrinsic::smax:

1047 case Intrinsic::abs:

1048 case Intrinsic::ctlz:

1049 case Intrinsic::cttz:

1050 case Intrinsic::ctpop:

1051 return true;

1052 default:

1053 return false;

1054 }

1055}

1056

1059 switch (IntrinsicID) {

1060 case Intrinsic::uadd_sat:

1061 return Ops[0].uadd_sat(Ops[1]);

1062 case Intrinsic::usub_sat:

1063 return Ops[0].usub_sat(Ops[1]);

1064 case Intrinsic::sadd_sat:

1065 return Ops[0].sadd_sat(Ops[1]);

1066 case Intrinsic::ssub_sat:

1067 return Ops[0].ssub_sat(Ops[1]);

1068 case Intrinsic::umin:

1069 return Ops[0].umin(Ops[1]);

1070 case Intrinsic::umax:

1071 return Ops[0].umax(Ops[1]);

1072 case Intrinsic::smin:

1073 return Ops[0].smin(Ops[1]);

1074 case Intrinsic::smax:

1075 return Ops[0].smax(Ops[1]);

1076 case Intrinsic::abs: {

1077 const APInt *IntMinIsPoison = Ops[1].getSingleElement();

1078 assert(IntMinIsPoison && "Must be known (immarg)");

1079 assert(IntMinIsPoison->getBitWidth() == 1 && "Must be boolean");

1081 }

1082 case Intrinsic::ctlz: {

1083 const APInt *ZeroIsPoison = Ops[1].getSingleElement();

1084 assert(ZeroIsPoison && "Must be known (immarg)");

1087 }

1088 case Intrinsic::cttz: {

1089 const APInt *ZeroIsPoison = Ops[1].getSingleElement();

1090 assert(ZeroIsPoison && "Must be known (immarg)");

1093 }

1094 case Intrinsic::ctpop:

1095 return Ops[0].ctpop();

1096 default:

1099 }

1100}

1101

1105 return getEmpty();

1107 return getFull();

1108

1111 if (NewLower == NewUpper)

1112 return getFull();

1113

1115 if (X.isSizeStrictlySmallerThan(*this) ||

1116 X.isSizeStrictlySmallerThan(Other))

1117

1118 return getFull();

1119 return X;

1120}

1121

1123 unsigned NoWrapKind,

1125

1126

1128 return getEmpty();

1130 return getFull();

1131

1134

1135

1136

1137

1138

1139

1140 if (NoWrapKind & OBO::NoSignedWrap)

1141 Result = Result.intersectWith(sadd_sat(Other), RangeType);

1142

1143 if (NoWrapKind & OBO::NoUnsignedWrap)

1144 Result = Result.intersectWith(uadd_sat(Other), RangeType);

1145

1146 return Result;

1147}

1148

1152 return getEmpty();

1154 return getFull();

1155

1158 if (NewLower == NewUpper)

1159 return getFull();

1160

1162 if (X.isSizeStrictlySmallerThan(*this) ||

1163 X.isSizeStrictlySmallerThan(Other))

1164

1165 return getFull();

1166 return X;

1167}

1168

1170 unsigned NoWrapKind,

1172

1173

1175 return getEmpty();

1177 return getFull();

1178

1181

1182

1183

1184

1185

1186

1187 if (NoWrapKind & OBO::NoSignedWrap)

1188 Result = Result.intersectWith(ssub_sat(Other), RangeType);

1189

1190 if (NoWrapKind & OBO::NoUnsignedWrap) {

1192 return getEmpty();

1193 Result = Result.intersectWith(usub_sat(Other), RangeType);

1194 }

1195

1196 return Result;

1197}

1198

1201

1202

1203

1204

1205

1207 return getEmpty();

1208

1210 if (C->isOne())

1212 if (C->isAllOnes())

1214 }

1215

1216 if (const APInt *C = Other.getSingleElement()) {

1217 if (C->isOne())

1218 return *this;

1219 if (C->isAllOnes())

1221 }

1222

1223

1224

1225

1226

1227

1228

1229

1234

1236 this_max * Other_max + 1);

1238

1239

1240

1241

1242

1245 return UR;

1246

1247

1248

1249

1250

1251

1252

1257

1258 auto L = {this_min * Other_min, this_min * Other_max,

1259 this_max * Other_min, this_max * Other_max};

1260 auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };

1261 ConstantRange Result_sext(std::min(L, Compare), std::max(L, Compare) + 1);

1263

1265}

1266

1269 unsigned NoWrapKind,

1272 return getEmpty();

1274 return getFull();

1275

1277

1279 Result = Result.intersectWith(smul_sat(Other), RangeType);

1280

1282 Result = Result.intersectWith(umul_sat(Other), RangeType);

1283

1284

1287 !Result.isAllNonNegative()) {

1289 Result = Result.intersectWith(

1292 RangeType);

1293 }

1294

1295 return Result;

1296}

1297

1300 return getEmpty();

1301

1304 APInt OtherMin = Other.getSignedMin();

1305 APInt OtherMax = Other.getSignedMax();

1306

1307 bool O1, O2, O3, O4;

1308 auto Muls = {Min.smul_ov(OtherMin, O1), Min.smul_ov(OtherMax, O2),

1309 Max.smul_ov(OtherMin, O3), Max.smul_ov(OtherMax, O4)};

1310 if (O1 || O2 || O3 || O4)

1311 return getFull();

1312

1313 auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };

1314 return getNonEmpty(std::min(Muls, Compare), std::max(Muls, Compare) + 1);

1315}

1316

1319

1320

1322 return getEmpty();

1328 return Res;

1329}

1330

1333

1334

1336 return getEmpty();

1342 return Res;

1343}

1344

1347

1348

1350 return getEmpty();

1356 return Res;

1357}

1358

1361

1362

1364 return getEmpty();

1370 return Res;

1371}

1372

1375 if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isZero())

1376 return getEmpty();

1377

1379

1380 APInt RHS_umin = RHS.getUnsignedMin();

1381 if (RHS_umin.isZero()) {

1382

1383

1384 if (RHS.getUpper() == 1)

1385 RHS_umin = RHS.getLower();

1386 else

1387 RHS_umin = 1;

1388 }

1389

1391 return getNonEmpty(std::move(Lower), std::move(Upper));

1392}

1393

1397

1398

1399

1400

1402 auto [PosR, NegR] = RHS.splitPosNeg();

1403

1405 if (!PosL.isEmptySet() && !PosR.isEmptySet())

1406

1407 PosRes = ConstantRange(PosL.Lower.sdiv(PosR.Upper - 1),

1408 (PosL.Upper - 1).sdiv(PosR.Lower) + 1);

1409

1410 if (!NegL.isEmptySet() && !NegR.isEmptySet()) {

1411

1412

1413

1414

1415

1416

1417 APInt Lo = (NegL.Upper - 1).sdiv(NegR.Lower);

1418 if (NegL.Lower.isMinSignedValue() && NegR.Upper.isZero()) {

1419

1420

1421 if (!NegR.Lower.isAllOnes()) {

1422 APInt AdjNegRUpper;

1423 if (RHS.Lower.isAllOnes())

1424

1425 AdjNegRUpper = RHS.Upper;

1426 else

1427

1428 AdjNegRUpper = NegR.Upper - 1;

1429

1431 ConstantRange(Lo, NegL.Lower.sdiv(AdjNegRUpper - 1) + 1));

1432 }

1433

1434

1435

1436 if (NegL.Upper != SignedMin + 1) {

1437 APInt AdjNegLLower;

1438 if (Upper == SignedMin + 1)

1439

1440 AdjNegLLower = Lower;

1441 else

1442

1443 AdjNegLLower = NegL.Lower + 1;

1444

1447 AdjNegLLower.sdiv(NegR.Upper - 1) + 1));

1448 }

1449 } else {

1451 ConstantRange(std::move(Lo), NegL.Lower.sdiv(NegR.Upper - 1) + 1));

1452 }

1453 }

1454

1456 if (!PosL.isEmptySet() && !NegR.isEmptySet())

1457

1458 NegRes = ConstantRange((PosL.Upper - 1).sdiv(NegR.Upper - 1),

1459 PosL.Lower.sdiv(NegR.Lower) + 1);

1460

1461 if (!NegL.isEmptySet() && !PosR.isEmptySet())

1462

1465 (NegL.Upper - 1).sdiv(PosR.Upper - 1) + 1));

1466

1467

1469

1470

1471 if (contains(Zero) && (!PosR.isEmptySet() || !NegR.isEmptySet()))

1473 return Res;

1474}

1475

1477 if (isEmptySet() || RHS.isEmptySet() || RHS.getUnsignedMax().isZero())

1478 return getEmpty();

1479

1480 if (const APInt *RHSInt = RHS.getSingleElement()) {

1481

1482 if (RHSInt->isZero())

1483 return getEmpty();

1484

1486 return {LHSInt->urem(*RHSInt)};

1487 }

1488

1489

1491 return *this;

1492

1493

1496}

1497

1499 if (isEmptySet() || RHS.isEmptySet())

1500 return getEmpty();

1501

1502 if (const APInt *RHSInt = RHS.getSingleElement()) {

1503

1504 if (RHSInt->isZero())

1505 return getEmpty();

1506

1508 return {LHSInt->srem(*RHSInt)};

1509 }

1510

1514

1515

1516 if (MaxAbsRHS.isZero())

1517 return getEmpty();

1518

1519 if (MinAbsRHS.isZero())

1520 ++MinAbsRHS;

1521

1523

1525

1526 if (MaxLHS.ult(MinAbsRHS))

1527 return *this;

1528

1529

1532 }

1533

1534

1535 if (MaxLHS.isNegative()) {

1536 if (MinLHS.ugt(-MinAbsRHS))

1537 return *this;

1538

1541 }

1542

1543

1546 return ConstantRange(std::move(Lower), std::move(Upper));

1547}

1548

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1580

1581

1582 if ((LHS.isFullSet() || RHS.isFullSet()) ||

1583 (LHS.isWrappedSet() || RHS.isWrappedSet()))

1585

1586 auto LLo = LHS.getLower();

1587 auto LHi = LHS.getUpper() - 1;

1588 auto RLo = RHS.getLower();

1589 auto RHi = RHS.getUpper() - 1;

1590

1591

1592 auto Mask = ~((LLo ^ LHi) | (RLo ^ RHi) | (LLo ^ RLo));

1593 unsigned LeadingOnes = Mask.countLeadingOnes();

1594 Mask.clearLowBits(BitWidth - LeadingOnes);

1595

1597 const APInt &BHi) {

1598 unsigned LeadingOnes = ((BLo & BHi) | Mask).countLeadingOnes();

1599 unsigned StartBit = BitWidth - LeadingOnes;

1600 ALo.clearLowBits(StartBit);

1601 return ALo;

1602 };

1603

1604 auto LowerBoundByLHS = estimateBound(LLo, RLo, RHi);

1605 auto LowerBoundByRHS = estimateBound(RLo, LLo, LHi);

1606

1607 return APIntOps::umax(LowerBoundByLHS, LowerBoundByRHS);

1608}

1609

1612 return getEmpty();

1613

1619 return KnownBitsRange.intersectWith(UMinUMaxRange);

1620}

1621

1624 return getEmpty();

1625

1628

1629

1630

1631

1632

1633

1634 auto UpperBound =

1636

1639 return KnownBitsRange.intersectWith(UMaxUMinRange);

1640}

1641

1644 return getEmpty();

1645

1646

1649

1650

1651 if (Other.isSingleElement() && Other.getSingleElement()->isAllOnes())

1654 return Other.binaryNot();

1655

1658 KnownBits Known = LHSKnown ^ RHSKnown;

1660

1662 return CR;

1663

1664

1665

1666

1667 if ((~LHSKnown.Zero).isSubsetOf(RHSKnown.One))

1669 else if ((~RHSKnown.Zero).isSubsetOf(LHSKnown.One))

1671 return CR;

1672}

1673

1677 return getEmpty();

1678

1681 if (const APInt *RHS = Other.getSingleElement()) {

1683 if (RHS->uge(BW))

1684 return getEmpty();

1685

1686 unsigned EqualLeadingBits = (Min ^ Max).countl_zero();

1687 if (RHS->ule(EqualLeadingBits))

1688 return getNonEmpty(Min << *RHS, (Max << *RHS) + 1);

1689

1692 }

1693

1694 APInt OtherMax = Other.getUnsignedMax();

1696

1697

1698 Max <<= Other.getUnsignedMin();

1699 Min <<= OtherMax;

1701 }

1702

1703

1704 if (OtherMax.ugt(Max.countl_zero()))

1705 return getFull();

1706

1707

1708

1709 Min <<= Other.getUnsignedMin();

1710 Max <<= OtherMax;

1711

1713}

1714

1718 bool Overflow;

1719 APInt LHSMin = LHS.getUnsignedMin();

1720 unsigned RHSMin = RHS.getUnsignedMin().getLimitedValue(BitWidth);

1721 APInt MinShl = LHSMin.ushl_ov(RHSMin, Overflow);

1722 if (Overflow)

1723 return ConstantRange::getEmpty(BitWidth);

1724 APInt LHSMax = LHS.getUnsignedMax();

1725 unsigned RHSMax = RHS.getUnsignedMax().getLimitedValue(BitWidth);

1726 APInt MaxShl = MinShl;

1728 if (RHSMin <= MaxShAmt)

1729 MaxShl = LHSMax << std::min(RHSMax, MaxShAmt);

1730 RHSMin = std::max(RHSMin, MaxShAmt + 1);

1732 if (RHSMin <= RHSMax)

1736}

1737

1739 const APInt &LHSMax,

1740 unsigned RHSMin,

1741 unsigned RHSMax) {

1743 bool Overflow;

1744 APInt MinShl = LHSMin.sshl_ov(RHSMin, Overflow);

1745 if (Overflow)

1746 return ConstantRange::getEmpty(BitWidth);

1747 APInt MaxShl = MinShl;

1749 if (RHSMin <= MaxShAmt)

1750 MaxShl = LHSMax << std::min(RHSMax, MaxShAmt);

1751 RHSMin = std::max(RHSMin, MaxShAmt + 1);

1753 if (RHSMin <= RHSMax)

1757}

1758

1760 const APInt &LHSMax,

1761 unsigned RHSMin, unsigned RHSMax) {

1763 bool Overflow;

1764 APInt MaxShl = LHSMax.sshl_ov(RHSMin, Overflow);

1765 if (Overflow)

1766 return ConstantRange::getEmpty(BitWidth);

1767 APInt MinShl = MaxShl;

1769 if (RHSMin <= MaxShAmt)

1770 MinShl = LHSMin.shl(std::min(RHSMax, MaxShAmt));

1771 RHSMin = std::max(RHSMin, MaxShAmt + 1);

1773 if (RHSMin <= RHSMax)

1776}

1777

1781 unsigned RHSMin = RHS.getUnsignedMin().getLimitedValue(BitWidth);

1782 unsigned RHSMax = RHS.getUnsignedMax().getLimitedValue(BitWidth);

1783 APInt LHSMin = LHS.getSignedMin();

1784 APInt LHSMax = LHS.getSignedMax();

1790 RHSMax)

1792 RHSMin, RHSMax),

1794}

1795

1797 unsigned NoWrapKind,

1800 return getEmpty();

1801

1802 switch (NoWrapKind) {

1803 case 0:

1813 default:

1815 }

1816}

1817

1821 return getEmpty();

1822

1826}

1827

1831 return getEmpty();

1832

1833

1834

1835

1836

1837

1838

1840

1841

1842

1843

1844

1845

1847

1848

1849

1850

1851

1852

1854

1855

1856

1857

1858

1859

1861

1864

1865 min = PosMin;

1866 max = PosMax;

1868

1869 min = NegMin;

1870 max = NegMax;

1871 } else {

1872

1873 min = NegMin;

1874 max = PosMax;

1875 }

1877}

1878

1881 return getEmpty();

1882

1885 return getNonEmpty(std::move(NewL), std::move(NewU));

1886}

1887

1890 return getEmpty();

1891

1894 return getNonEmpty(std::move(NewL), std::move(NewU));

1895}

1896

1899 return getEmpty();

1900

1903 return getNonEmpty(std::move(NewL), std::move(NewU));

1904}

1905

1908 return getEmpty();

1909

1912 return getNonEmpty(std::move(NewL), std::move(NewU));

1913}

1914

1917 return getEmpty();

1918

1921 return getNonEmpty(std::move(NewL), std::move(NewU));

1922}

1923

1926 return getEmpty();

1927

1928

1929

1930

1931

1932

1933

1936 APInt OtherMin = Other.getSignedMin();

1937 APInt OtherMax = Other.getSignedMax();

1938

1940 Max.smul_sat(OtherMin), Max.smul_sat(OtherMax)};

1941 auto Compare = [](const APInt &A, const APInt &B) { return A.slt(B); };

1942 return getNonEmpty(std::min(L, Compare), std::max(L, Compare) + 1);

1943}

1944

1947 return getEmpty();

1948

1951 return getNonEmpty(std::move(NewL), std::move(NewU));

1952}

1953

1956 return getEmpty();

1957

1959 APInt ShAmtMin = Other.getUnsignedMin(), ShAmtMax = Other.getUnsignedMax();

1961 APInt NewU = Max.sshl_sat(Max.isNegative() ? ShAmtMin : ShAmtMax) + 1;

1962 return getNonEmpty(std::move(NewL), std::move(NewU));

1963}

1964

1967 return getEmpty();

1969 return getFull();

1971}

1972

1975 return getEmpty();

1976

1979

1980 if (Upper.isStrictlyPositive() || !Lower.isStrictlyPositive())

1982 else

1984

1985

1986 if (IntMinIsPoison)

1988 else

1990 }

1991

1993

1994

1995 if (IntMinIsPoison && SMin.isMinSignedValue()) {

1996

1997 if (SMax.isMinSignedValue())

1998 return getEmpty();

2000 }

2001

2002

2003 if (SMin.isNonNegative())

2005

2006

2007 if (SMax.isNegative())

2009

2010

2013}

2014

2017 return getEmpty();

2018

2020 if (ZeroIsPoison && contains(Zero)) {

2021

2022

2023

2024

2025

2026

2029

2030

2031 return getEmpty();

2032 }

2033

2034

2039

2042 } else {

2044 }

2045 }

2046

2047

2048

2051}

2052

2056 "Unexpected wrapped set.");

2061 if (Lower.isZero())

2064

2065

2067

2068

2072 std::max(BitWidth - LCPLength - 1, Lower.countr_zero()) + 1));

2073}

2074

2077 return getEmpty();

2078

2081 if (ZeroIsPoison && contains(Zero)) {

2082

2083

2084

2085

2086

2087

2088 if (Lower.isZero()) {

2089 if (Upper == 1) {

2090

2091

2092 return getEmpty();

2093 }

2094

2095

2097 } else if (Upper == 1) {

2098

2100 } else {

2105 }

2106 }

2107

2112

2113

2114

2116

2119}

2120

2124 "Unexpected wrapped set.");

2129

2131

2133 unsigned LCPPopCount = Lower.getHiBits(LCPLength).popcount();

2134

2135

2136 unsigned MinBits =

2137 LCPPopCount + (Lower.countr_zero() < BitWidth - LCPLength ? 1 : 0);

2138

2139

2140

2141

2142 unsigned MaxBits = LCPPopCount + (BitWidth - LCPLength) -

2143 (Max.countr_one() < BitWidth - LCPLength ? 1 : 0);

2145}

2146

2149 return getEmpty();

2150

2157

2158

2159

2162

2165}

2166

2171

2173 APInt OtherMin = Other.getUnsignedMin(), OtherMax = Other.getUnsignedMax();

2174

2175

2176 if (Min.ugt(~OtherMin))

2178 if (Max.ugt(~OtherMax))

2181}

2182

2187

2189 APInt OtherMin = Other.getSignedMin(), OtherMax = Other.getSignedMax();

2190

2193

2194

2195

2197 Min.sgt(SignedMax - OtherMin))

2199 if (Max.isNegative() && OtherMax.isNegative() &&

2200 Max.slt(SignedMin - OtherMax))

2202

2203 if (Max.isNonNegative() && OtherMax.isNonNegative() &&

2204 Max.sgt(SignedMax - OtherMax))

2207 Min.slt(SignedMin - OtherMin))

2209

2211}

2212

2217

2219 APInt OtherMin = Other.getUnsignedMin(), OtherMax = Other.getUnsignedMax();

2220

2221

2222 if (Max.ult(OtherMin))

2224 if (Min.ult(OtherMax))

2227}

2228

2233

2235 APInt OtherMin = Other.getSignedMin(), OtherMax = Other.getSignedMax();

2236

2239

2240

2241

2242 if (Min.isNonNegative() && OtherMax.isNegative() &&

2243 Min.sgt(SignedMax + OtherMax))

2245 if (Max.isNegative() && OtherMin.isNonNegative() &&

2246 Max.slt(SignedMin + OtherMin))

2248

2249 if (Max.isNonNegative() && OtherMin.isNegative() &&

2250 Max.sgt(SignedMax + OtherMin))

2252 if (Min.isNegative() && OtherMax.isNonNegative() &&

2253 Min.slt(SignedMin + OtherMax))

2255

2257}

2258

2263

2265 APInt OtherMin = Other.getUnsignedMin(), OtherMax = Other.getUnsignedMax();

2266 bool Overflow;

2267

2268 (void) Min.umul_ov(OtherMin, Overflow);

2269 if (Overflow)

2271

2272 (void) Max.umul_ov(OtherMax, Overflow);

2273 if (Overflow)

2275

2277}

2278

2281 OS << "full-set";

2283 OS << "empty-set";

2284 else

2285 OS << "[" << Lower << "," << Upper << ")";

2286}

2287

2288#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)

2292#endif

2293

2295 const unsigned NumRanges = Ranges.getNumOperands() / 2;

2296 assert(NumRanges >= 1 && "Must have at least one range!");

2297 assert(Ranges.getNumOperands() % 2 == 0 && "Must be a sequence of pairs");

2298

2301

2302 ConstantRange CR(FirstLow->getValue(), FirstHigh->getValue());

2303

2304 for (unsigned i = 1; i < NumRanges; ++i) {

2307

2308

2309

2311 }

2312

2313 return CR;

2314}

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

This file implements a class to represent arbitrary precision integral constant values and operations...

static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")

static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")

#define LLVM_DUMP_METHOD

Mark debug helper function definitions like dump() that should not be stripped from debug builds.

static APInt estimateBitMaskedAndLowerBound(const ConstantRange &LHS, const ConstantRange &RHS)

Estimate the 'bit-masked AND' operation's lower bound.

Definition ConstantRange.cpp:1577

static ConstantRange computeShlNUW(const ConstantRange &LHS, const ConstantRange &RHS)

Definition ConstantRange.cpp:1715

static ConstantRange getUnsignedPopCountRange(const APInt &Lower, const APInt &Upper)

Definition ConstantRange.cpp:2121

static ConstantRange computeShlNSW(const ConstantRange &LHS, const ConstantRange &RHS)

Definition ConstantRange.cpp:1778

static ConstantRange makeExactMulNUWRegion(const APInt &V)

Exact mul nuw region for single element RHS.

Definition ConstantRange.cpp:288

static ConstantRange computeShlNSWWithNNegLHS(const APInt &LHSMin, const APInt &LHSMax, unsigned RHSMin, unsigned RHSMax)

Definition ConstantRange.cpp:1738

static ConstantRange makeExactMulNSWRegion(const APInt &V)

Exact mul nsw region for single element RHS.

Definition ConstantRange.cpp:301

static ConstantRange getPreferredRange(const ConstantRange &CR1, const ConstantRange &CR2, ConstantRange::PreferredRangeType Type)

Definition ConstantRange.cpp:571

static ConstantRange getUnsignedCountTrailingZerosRange(const APInt &Lower, const APInt &Upper)

Definition ConstantRange.cpp:2053

static ConstantRange computeShlNSWWithNegLHS(const APInt &LHSMin, const APInt &LHSMax, unsigned RHSMin, unsigned RHSMax)

Definition ConstantRange.cpp:1759

This file contains the declarations for the subclasses of Constant, which represent the different fla...

const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]

static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)

static TableGen::Emitter::OptClass< SkeletonEmitter > X("gen-skeleton-class", "Generate example skeleton class")

Class for arbitrary precision integers.

LLVM_ABI APInt umul_ov(const APInt &RHS, bool &Overflow) const

LLVM_ABI APInt usub_sat(const APInt &RHS) const

LLVM_ABI APInt udiv(const APInt &RHS) const

Unsigned division operation.

static APInt getAllOnes(unsigned numBits)

Return an APInt of a specified width with all bits set.

void clearBit(unsigned BitPosition)

Set a given bit to 0.

LLVM_ABI APInt zext(unsigned width) const

Zero extend to a new width.

static APInt getSignMask(unsigned BitWidth)

Get the SignMask for a specific bit width.

bool isMinSignedValue() const

Determine if this is the smallest signed value.

unsigned getActiveBits() const

Compute the number of active bits in the value.

LLVM_ABI APInt trunc(unsigned width) const

Truncate to new width.

static APInt getMaxValue(unsigned numBits)

Gets maximum unsigned value of APInt for specific bit width.

LLVM_ABI APInt sshl_ov(const APInt &Amt, bool &Overflow) const

LLVM_ABI APInt smul_sat(const APInt &RHS) const

unsigned countLeadingOnes() const

LLVM_ABI APInt sadd_sat(const APInt &RHS) const

bool sgt(const APInt &RHS) const

Signed greater than comparison.

bool ugt(const APInt &RHS) const

Unsigned greater than comparison.

static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)

Get a value with a block of bits set.

bool isZero() const

Determine if this value is zero, i.e. all bits are clear.

void setSignBit()

Set the sign bit to 1.

unsigned getBitWidth() const

Return the number of bits in the APInt.

bool ult(const APInt &RHS) const

Unsigned less than comparison.

static APInt getSignedMaxValue(unsigned numBits)

Gets maximum signed value of APInt for a specific bit width.

static APInt getMinValue(unsigned numBits)

Gets minimum unsigned value of APInt for a specific bit width.

bool isNegative() const

Determine sign of this APInt.

LLVM_ABI APInt sdiv(const APInt &RHS) const

Signed division function for APInt.

bool sle(const APInt &RHS) const

Signed less or equal comparison.

static APInt getSignedMinValue(unsigned numBits)

Gets minimum signed value of APInt for a specific bit width.

LLVM_ABI APInt sshl_sat(const APInt &RHS) const

LLVM_ABI APInt ushl_sat(const APInt &RHS) const

LLVM_ABI APInt ushl_ov(const APInt &Amt, bool &Overflow) const

unsigned countLeadingZeros() const

unsigned countl_one() const

Count the number of leading one bits.

void clearLowBits(unsigned loBits)

Set bottom loBits bits to 0.

LLVM_ABI APInt uadd_sat(const APInt &RHS) const

APInt ashr(unsigned ShiftAmt) const

Arithmetic right-shift function.

void setAllBits()

Set every bit to 1.

bool getBoolValue() const

Convert APInt to a boolean value.

LLVM_ABI APInt smul_ov(const APInt &RHS, bool &Overflow) const

bool isNonNegative() const

Determine if this APInt Value is non-negative (>= 0)

bool ule(const APInt &RHS) const

Unsigned less or equal comparison.

LLVM_ABI APInt sext(unsigned width) const

Sign extend to a new width.

APInt shl(unsigned shiftAmt) const

Left-shift function.

LLVM_ABI APInt umul_sat(const APInt &RHS) const

static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)

Constructs an APInt value that has the bottom loBitsSet bits set.

bool slt(const APInt &RHS) const

Signed less than comparison.

static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)

Constructs an APInt value that has the top hiBitsSet bits set.

static APInt getZero(unsigned numBits)

Get the '0' value for the specified bit-width.

bool sge(const APInt &RHS) const

Signed greater or equal comparison.

static APInt getBitsSetFrom(unsigned numBits, unsigned loBit)

Constructs an APInt value that has a contiguous range of bits set.

static APInt getOneBitSet(unsigned numBits, unsigned BitNo)

Return an APInt with exactly one bit set in the result.

APInt lshr(unsigned shiftAmt) const

Logical right-shift function.

bool uge(const APInt &RHS) const

Unsigned greater or equal comparison.

LLVM_ABI APInt ssub_sat(const APInt &RHS) const

ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...

Predicate

This enumeration lists the possible predicates for CmpInst subclasses.

@ ICMP_SLT

signed less than

@ ICMP_SLE

signed less or equal

@ ICMP_UGE

unsigned greater or equal

@ ICMP_UGT

unsigned greater than

@ ICMP_SGT

signed greater than

@ ICMP_ULT

unsigned less than

@ ICMP_SGE

signed greater or equal

@ ICMP_ULE

unsigned less or equal

static bool isRelational(Predicate P)

Return true if the predicate is relational (not EQ or NE).

Predicate getInversePredicate() const

For example, EQ -> NE, UGT -> ULE, SLT -> SGE, OEQ -> UNE, UGT -> OLE, OLT -> UGE,...

static bool isIntPredicate(Predicate P)

This class represents a range of values.

LLVM_ABI ConstantRange multiply(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a multiplication of a value in thi...

Definition ConstantRange.cpp:1200

LLVM_ABI ConstantRange add(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an addition of a value in this ran...

Definition ConstantRange.cpp:1103

LLVM_ABI bool isUpperSignWrapped() const

Return true if the (exclusive) upper bound wraps around the signed domain.

Definition ConstantRange.cpp:444

LLVM_ABI unsigned getActiveBits() const

Compute the maximal number of active bits needed to represent every value in this range.

Definition ConstantRange.cpp:544

LLVM_ABI ConstantRange zextOrTrunc(uint32_t BitWidth) const

Make this range have the bit width given by BitWidth.

Definition ConstantRange.cpp:953

PreferredRangeType

If represented precisely, the result of some range operations may consist of multiple disjoint ranges...

LLVM_ABI std::optional< ConstantRange > exactUnionWith(const ConstantRange &CR) const

Union the two ranges and return the result if it can be represented exactly, otherwise return std::nu...

Definition ConstantRange.cpp:780

LLVM_ABI bool getEquivalentICmp(CmpInst::Predicate &Pred, APInt &RHS) const

Set up Pred and RHS such that ConstantRange::makeExactICmpRegion(Pred, RHS) == *this.

Definition ConstantRange.cpp:246

LLVM_ABI ConstantRange umul_sat(const ConstantRange &Other) const

Perform an unsigned saturating multiplication of two constant ranges.

Definition ConstantRange.cpp:1915

static LLVM_ABI CmpInst::Predicate getEquivalentPredWithFlippedSignedness(CmpInst::Predicate Pred, const ConstantRange &CR1, const ConstantRange &CR2)

If the comparison between constant ranges this and Other is insensitive to the signedness of the comp...

Definition ConstantRange.cpp:198

LLVM_ABI ConstantRange subtract(const APInt &CI) const

Subtract the specified constant from the endpoints of this constant range.

Definition ConstantRange.cpp:559

const APInt * getSingleElement() const

If this set contains a single element, return it, otherwise return null.

LLVM_ABI ConstantRange binaryXor(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a binary-xor of a value in this ra...

Definition ConstantRange.cpp:1642

const APInt * getSingleMissingElement() const

If this set contains all but a single element, return it, otherwise return null.

static LLVM_ABI ConstantRange fromKnownBits(const KnownBits &Known, bool IsSigned)

Initialize a range based on a known bits constraint.

Definition ConstantRange.cpp:60

const APInt & getLower() const

Return the lower value for this range.

LLVM_ABI OverflowResult unsignedSubMayOverflow(const ConstantRange &Other) const

Return whether unsigned sub of the two ranges always/never overflows.

Definition ConstantRange.cpp:2213

LLVM_ABI bool isAllNegative() const

Return true if all values in this range are negative.

Definition ConstantRange.cpp:468

LLVM_ABI OverflowResult unsignedAddMayOverflow(const ConstantRange &Other) const

Return whether unsigned add of the two ranges always/never overflows.

Definition ConstantRange.cpp:2167

LLVM_ABI ConstantRange urem(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an unsigned remainder operation of...

Definition ConstantRange.cpp:1476

LLVM_ABI ConstantRange sshl_sat(const ConstantRange &Other) const

Perform a signed saturating left shift of this constant range by a value in Other.

Definition ConstantRange.cpp:1954

LLVM_ABI ConstantRange smul_fast(const ConstantRange &Other) const

Return range of possible values for a signed multiplication of this and Other.

Definition ConstantRange.cpp:1298

LLVM_ABI ConstantRange lshr(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a logical right shift of a value i...

Definition ConstantRange.cpp:1819

LLVM_ABI KnownBits toKnownBits() const

Return known bits for values in this range.

Definition ConstantRange.cpp:80

LLVM_ABI ConstantRange castOp(Instruction::CastOps CastOp, uint32_t BitWidth) const

Return a new range representing the possible values resulting from an application of the specified ca...

Definition ConstantRange.cpp:788

LLVM_ABI ConstantRange umin(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an unsigned minimum of a value in ...

Definition ConstantRange.cpp:1360

LLVM_ABI APInt getUnsignedMin() const

Return the smallest unsigned value contained in the ConstantRange.

Definition ConstantRange.cpp:499

LLVM_ABI ConstantRange difference(const ConstantRange &CR) const

Subtract the specified range from this range (aka relative complement of the sets).

Definition ConstantRange.cpp:567

LLVM_ABI bool isFullSet() const

Return true if this set contains all of the elements possible for this data-type.

Definition ConstantRange.cpp:424

LLVM_ABI ConstantRange srem(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a signed remainder operation of a ...

Definition ConstantRange.cpp:1498

LLVM_ABI bool icmp(CmpInst::Predicate Pred, const ConstantRange &Other) const

Does the predicate Pred hold between ranges this and Other?

Definition ConstantRange.cpp:253

LLVM_ABI ConstantRange sadd_sat(const ConstantRange &Other) const

Perform a signed saturating addition of two constant ranges.

Definition ConstantRange.cpp:1888

LLVM_ABI ConstantRange ushl_sat(const ConstantRange &Other) const

Perform an unsigned saturating left shift of this constant range by a value in Other.

Definition ConstantRange.cpp:1945

static LLVM_ABI ConstantRange intrinsic(Intrinsic::ID IntrinsicID, ArrayRef< ConstantRange > Ops)

Compute range of intrinsic result for the given operand ranges.

Definition ConstantRange.cpp:1057

LLVM_ABI void dump() const

Allow printing from a debugger easily.

Definition ConstantRange.cpp:2289

LLVM_ABI bool isEmptySet() const

Return true if this set contains no members.

Definition ConstantRange.cpp:428

LLVM_ABI ConstantRange smul_sat(const ConstantRange &Other) const

Perform a signed saturating multiplication of two constant ranges.

Definition ConstantRange.cpp:1924

LLVM_ABI bool isAllPositive() const

Return true if all values in this range are positive.

Definition ConstantRange.cpp:483

LLVM_ABI ConstantRange shl(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a left shift of a value in this ra...

Definition ConstantRange.cpp:1675

LLVM_ABI ConstantRange zeroExtend(uint32_t BitWidth) const

Return a new range in the specified integer type, which must be strictly larger than the current type...

Definition ConstantRange.cpp:840

LLVM_ABI bool isSignWrappedSet() const

Return true if this set wraps around the signed domain.

Definition ConstantRange.cpp:440

LLVM_ABI bool isSizeLargerThan(uint64_t MaxSize) const

Compare set size of this range with Value.

Definition ConstantRange.cpp:459

LLVM_ABI APInt getSignedMin() const

Return the smallest signed value contained in the ConstantRange.

Definition ConstantRange.cpp:511

LLVM_ABI ConstantRange abs(bool IntMinIsPoison=false) const

Calculate absolute value range.

Definition ConstantRange.cpp:1973

static LLVM_ABI bool isIntrinsicSupported(Intrinsic::ID IntrinsicID)

Returns true if ConstantRange calculations are supported for intrinsic with IntrinsicID.

Definition ConstantRange.cpp:1037

static LLVM_ABI ConstantRange makeSatisfyingICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)

Produce the largest range such that all values in the returned range satisfy the given predicate with...

Definition ConstantRange.cpp:159

LLVM_ABI bool isWrappedSet() const

Return true if this set wraps around the unsigned domain.

Definition ConstantRange.cpp:432

LLVM_ABI ConstantRange usub_sat(const ConstantRange &Other) const

Perform an unsigned saturating subtraction of two constant ranges.

Definition ConstantRange.cpp:1897

LLVM_ABI ConstantRange uadd_sat(const ConstantRange &Other) const

Perform an unsigned saturating addition of two constant ranges.

Definition ConstantRange.cpp:1879

LLVM_ABI ConstantRange overflowingBinaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind) const

Return a new range representing the possible values resulting from an application of the specified ov...

Definition ConstantRange.cpp:1016

LLVM_ABI void print(raw_ostream &OS) const

Print out the bounds to a stream.

Definition ConstantRange.cpp:2279

LLVM_ABI ConstantRange(uint32_t BitWidth, bool isFullSet)

Initialize a full or empty set for the specified bit width.

Definition ConstantRange.cpp:45

LLVM_ABI OverflowResult unsignedMulMayOverflow(const ConstantRange &Other) const

Return whether unsigned mul of the two ranges always/never overflows.

Definition ConstantRange.cpp:2259

LLVM_ABI std::pair< ConstantRange, ConstantRange > splitPosNeg() const

Split the ConstantRange into positive and negative components, ignoring zero values.

Definition ConstantRange.cpp:98

LLVM_ABI ConstantRange subWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const

Return a new range representing the possible values resulting from an subtraction with wrap type NoWr...

Definition ConstantRange.cpp:1169

bool isSingleElement() const

Return true if this set contains exactly one member.

LLVM_ABI ConstantRange truncate(uint32_t BitWidth, unsigned NoWrapKind=0) const

Return a new range in the specified integer type, which must be strictly smaller than the current typ...

Definition ConstantRange.cpp:879

LLVM_ABI ConstantRange ssub_sat(const ConstantRange &Other) const

Perform a signed saturating subtraction of two constant ranges.

Definition ConstantRange.cpp:1906

LLVM_ABI bool isAllNonNegative() const

Return true if all values in this range are non-negative.

Definition ConstantRange.cpp:478

LLVM_ABI ConstantRange umax(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an unsigned maximum of a value in ...

Definition ConstantRange.cpp:1332

LLVM_ABI ConstantRange signExtend(uint32_t BitWidth) const

Return a new range in the specified integer type, which must be strictly larger than the current type...

Definition ConstantRange.cpp:859

static LLVM_ABI ConstantRange makeAllowedICmpRegion(CmpInst::Predicate Pred, const ConstantRange &Other)

Produce the smallest range such that all values that may satisfy the given predicate with any value c...

Definition ConstantRange.cpp:109

LLVM_ABI ConstantRange sdiv(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a signed division of a value in th...

Definition ConstantRange.cpp:1394

const APInt & getUpper() const

Return the upper value for this range.

LLVM_ABI bool isUpperWrapped() const

Return true if the exclusive upper bound wraps around the unsigned domain.

Definition ConstantRange.cpp:436

LLVM_ABI ConstantRange shlWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const

Return a new range representing the possible values resulting from a left shift with wrap type NoWrap...

Definition ConstantRange.cpp:1796

LLVM_ABI ConstantRange unionWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const

Return the range that results from the union of this range with another range.

Definition ConstantRange.cpp:697

static LLVM_ABI ConstantRange makeExactICmpRegion(CmpInst::Predicate Pred, const APInt &Other)

Produce the exact range such that all values in the returned range satisfy the given predicate with a...

Definition ConstantRange.cpp:169

LLVM_ABI ConstantRange inverse() const

Return a new range that is the logical not of the current set.

Definition ConstantRange.cpp:1965

LLVM_ABI std::optional< ConstantRange > exactIntersectWith(const ConstantRange &CR) const

Intersect the two ranges and return the result if it can be represented exactly, otherwise return std...

Definition ConstantRange.cpp:771

LLVM_ABI ConstantRange ashr(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a arithmetic right shift of a valu...

Definition ConstantRange.cpp:1829

LLVM_ABI ConstantRange binaryAnd(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a binary-and of a value in this ra...

Definition ConstantRange.cpp:1610

LLVM_ABI bool contains(const APInt &Val) const

Return true if the specified value is in the set.

Definition ConstantRange.cpp:517

static LLVM_ABI bool areInsensitiveToSignednessOfInvertedICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)

Return true iff CR1 ult CR2 is equivalent to CR1 sge CR2.

Definition ConstantRange.cpp:189

LLVM_ABI OverflowResult signedAddMayOverflow(const ConstantRange &Other) const

Return whether signed add of the two ranges always/never overflows.

Definition ConstantRange.cpp:2183

LLVM_ABI APInt getUnsignedMax() const

Return the largest unsigned value contained in the ConstantRange.

Definition ConstantRange.cpp:493

LLVM_ABI ConstantRange addWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const

Return a new range representing the possible values resulting from an addition with wrap type NoWrapK...

Definition ConstantRange.cpp:1122

LLVM_ABI ConstantRange intersectWith(const ConstantRange &CR, PreferredRangeType Type=Smallest) const

Return the range that results from the intersection of this range with another range.

Definition ConstantRange.cpp:591

LLVM_ABI APInt getSignedMax() const

Return the largest signed value contained in the ConstantRange.

Definition ConstantRange.cpp:505

OverflowResult

Represents whether an operation on the given constant range is known to always or never overflow.

@ NeverOverflows

Never overflows.

@ AlwaysOverflowsHigh

Always overflows in the direction of signed/unsigned max value.

@ AlwaysOverflowsLow

Always overflows in the direction of signed/unsigned min value.

@ MayOverflow

May or may not overflow.

static LLVM_ABI ConstantRange makeMaskNotEqualRange(const APInt &Mask, const APInt &C)

Initialize a range containing all values X that satisfy (X & Mask) / != C.

Definition ConstantRange.cpp:407

static LLVM_ABI bool areInsensitiveToSignednessOfICmpPredicate(const ConstantRange &CR1, const ConstantRange &CR2)

Return true iff CR1 ult CR2 is equivalent to CR1 slt CR2.

Definition ConstantRange.cpp:180

LLVM_ABI ConstantRange cttz(bool ZeroIsPoison=false) const

Calculate cttz range.

Definition ConstantRange.cpp:2075

static ConstantRange getNonEmpty(APInt Lower, APInt Upper)

Create non-empty constant range with the given bounds.

LLVM_ABI ConstantRange ctpop() const

Calculate ctpop range.

Definition ConstantRange.cpp:2147

static LLVM_ABI ConstantRange makeGuaranteedNoWrapRegion(Instruction::BinaryOps BinOp, const ConstantRange &Other, unsigned NoWrapKind)

Produce the largest range containing all X such that "X BinOp Y" is guaranteed not to wrap (overflow)...

Definition ConstantRange.cpp:325

LLVM_ABI ConstantRange smin(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a signed minimum of a value in thi...

Definition ConstantRange.cpp:1346

LLVM_ABI ConstantRange udiv(const ConstantRange &Other) const

Return a new range representing the possible values resulting from an unsigned division of a value in...

Definition ConstantRange.cpp:1374

LLVM_ABI unsigned getMinSignedBits() const

Compute the maximal number of bits needed to represent every value in this signed range.

Definition ConstantRange.cpp:551

uint32_t getBitWidth() const

Get the bit width of this ConstantRange.

LLVM_ABI ConstantRange binaryNot() const

Return a new range representing the possible values resulting from a binary-xor of a value in this ra...

Definition ConstantRange.cpp:1549

LLVM_ABI ConstantRange smax(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a signed maximum of a value in thi...

Definition ConstantRange.cpp:1318

LLVM_ABI ConstantRange binaryOp(Instruction::BinaryOps BinOp, const ConstantRange &Other) const

Return a new range representing the possible values resulting from an application of the specified bi...

Definition ConstantRange.cpp:971

LLVM_ABI ConstantRange binaryOr(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a binary-or of a value in this ran...

Definition ConstantRange.cpp:1622

LLVM_ABI OverflowResult signedSubMayOverflow(const ConstantRange &Other) const

Return whether signed sub of the two ranges always/never overflows.

Definition ConstantRange.cpp:2229

LLVM_ABI ConstantRange ctlz(bool ZeroIsPoison=false) const

Calculate ctlz range.

Definition ConstantRange.cpp:2015

LLVM_ABI ConstantRange sub(const ConstantRange &Other) const

Return a new range representing the possible values resulting from a subtraction of a value in this r...

Definition ConstantRange.cpp:1150

LLVM_ABI ConstantRange sextOrTrunc(uint32_t BitWidth) const

Make this range have the bit width given by BitWidth.

Definition ConstantRange.cpp:962

static LLVM_ABI ConstantRange makeExactNoWrapRegion(Instruction::BinaryOps BinOp, const APInt &Other, unsigned NoWrapKind)

Produce the range that contains X if and only if "X BinOp Other" does not wrap.

Definition ConstantRange.cpp:399

LLVM_ABI bool isSizeStrictlySmallerThan(const ConstantRange &CR) const

Compare set size of this range with the range CR.

Definition ConstantRange.cpp:449

LLVM_ABI ConstantRange multiplyWithNoWrap(const ConstantRange &Other, unsigned NoWrapKind, PreferredRangeType RangeType=Smallest) const

Return a new range representing the possible values resulting from a multiplication with wrap type No...

Definition ConstantRange.cpp:1268

Predicate getFlippedSignednessPredicate() const

For example, SLT->ULT, ULT->SLT, SLE->ULE, ULE->SLE, EQ->EQ.

Utility class for integer operators which may exhibit overflow - Add, Sub, Mul, and Shl.

The instances of the Type class are immutable: once they are created, they are never changed.

This class implements an extremely fast bulk output stream that can only output to a stream.

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

LLVM_ABI std::optional< unsigned > GetMostSignificantDifferentBit(const APInt &A, const APInt &B)

Compare two values, and if they are different, return the position of the most significant bit that i...

LLVM_ABI APInt RoundingUDiv(const APInt &A, const APInt &B, APInt::Rounding RM)

Return A unsign-divided by B, rounded by the given rounding mode.

LLVM_ABI APInt RoundingSDiv(const APInt &A, const APInt &B, APInt::Rounding RM)

Return A sign-divided by B, rounded by the given rounding mode.

const APInt & smin(const APInt &A, const APInt &B)

Determine the smaller of two APInts considered to be signed.

const APInt & smax(const APInt &A, const APInt &B)

Determine the larger of two APInts considered to be signed.

const APInt & umin(const APInt &A, const APInt &B)

Determine the smaller of two APInts considered to be unsigned.

const APInt & umax(const APInt &A, const APInt &B)

Determine the larger of two APInts considered to be unsigned.

@ C

The default llvm calling convention, compatible with C.

std::enable_if_t< detail::IsValidPointer< X, Y >::value, X * > extract(Y &&MD)

Extract a Value from Metadata.

This is an optimization pass for GlobalISel generic memory operations.

GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)

@ Low

Lower the current thread's priority such that it does not affect foreground tasks significantly.

LLVM_ABI ConstantRange getConstantRangeFromMetadata(const MDNode &RangeMD)

Parse out a conservative ConstantRange from !range metadata.

Definition ConstantRange.cpp:2294

int countl_zero(T Val)

Count number of 0's from the most significant bit to the least stopping at the first 1.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

@ UMin

Unsigned integer min implemented in terms of select(cmp()).

@ SMax

Signed integer max implemented in terms of select(cmp()).

@ SMin

Signed integer min implemented in terms of select(cmp()).

@ UMax

Unsigned integer max implemented in terms of select(cmp()).

constexpr unsigned BitWidth

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.

static KnownBits makeConstant(const APInt &C)

Create known bits from a known constant.

bool isNonNegative() const

Returns true if this value is known to be non-negative.

bool isUnknown() const

Returns true if we don't know any bits.

bool hasConflict() const

Returns true if there is conflicting information.

unsigned getBitWidth() const

Get the bit width of this value.

APInt getMaxValue() const

Return the maximal unsigned value possible given these KnownBits.

APInt getMinValue() const

Return the minimal unsigned value possible given these KnownBits.

bool isNegative() const

Returns true if this value is known to be negative.