@@ -6245,37 +6245,30 @@ static OverflowResult mapOverflowResult(ConstantRange::OverflowResult OR) {
6245
6245
}
6246
6246
6247
6247
// / Combine constant ranges from computeConstantRange() and computeKnownBits().
6248
- static ConstantRange computeConstantRangeIncludingKnownBits (
6249
- const Value *V, bool ForSigned, const DataLayout &DL, AssumptionCache *AC,
6250
- const Instruction *CxtI, const DominatorTree *DT,
6251
- bool UseInstrInfo = true ) {
6252
- KnownBits Known =
6253
- computeKnownBits (V, DL, /* Depth=*/ 0 , AC, CxtI, DT, UseInstrInfo);
6248
+ static ConstantRange
6249
+ computeConstantRangeIncludingKnownBits (const Value *V, bool ForSigned,
6250
+ const SimplifyQuery &SQ) {
6251
+ KnownBits Known = ::computeKnownBits (V, /* Depth=*/ 0 , SQ);
6254
6252
ConstantRange CR1 = ConstantRange::fromKnownBits (Known, ForSigned);
6255
- ConstantRange CR2 = computeConstantRange (V, ForSigned, UseInstrInfo);
6253
+ ConstantRange CR2 = computeConstantRange (V, ForSigned, SQ. IIQ . UseInstrInfo );
6256
6254
ConstantRange::PreferredRangeType RangeType =
6257
6255
ForSigned ? ConstantRange::Signed : ConstantRange::Unsigned;
6258
6256
return CR1.intersectWith (CR2, RangeType);
6259
6257
}
6260
6258
6261
- OverflowResult llvm::computeOverflowForUnsignedMul (
6262
- const Value *LHS, const Value *RHS, const DataLayout &DL,
6263
- AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT,
6264
- bool UseInstrInfo) {
6265
- KnownBits LHSKnown = computeKnownBits (LHS, DL, /* Depth=*/ 0 , AC, CxtI, DT,
6266
- UseInstrInfo);
6267
- KnownBits RHSKnown = computeKnownBits (RHS, DL, /* Depth=*/ 0 , AC, CxtI, DT,
6268
- UseInstrInfo);
6259
+ OverflowResult llvm::computeOverflowForUnsignedMul (const Value *LHS,
6260
+ const Value *RHS,
6261
+ const SimplifyQuery &SQ) {
6262
+ KnownBits LHSKnown = ::computeKnownBits (LHS, /* Depth=*/ 0 , SQ);
6263
+ KnownBits RHSKnown = ::computeKnownBits (RHS, /* Depth=*/ 0 , SQ);
6269
6264
ConstantRange LHSRange = ConstantRange::fromKnownBits (LHSKnown, false );
6270
6265
ConstantRange RHSRange = ConstantRange::fromKnownBits (RHSKnown, false );
6271
6266
return mapOverflowResult (LHSRange.unsignedMulMayOverflow (RHSRange));
6272
6267
}
6273
6268
6274
- OverflowResult
6275
- llvm::computeOverflowForSignedMul (const Value *LHS, const Value *RHS,
6276
- const DataLayout &DL, AssumptionCache *AC,
6277
- const Instruction *CxtI,
6278
- const DominatorTree *DT, bool UseInstrInfo) {
6269
+ OverflowResult llvm::computeOverflowForSignedMul (const Value *LHS,
6270
+ const Value *RHS,
6271
+ const SimplifyQuery &SQ) {
6279
6272
// Multiplying n * m significant bits yields a result of n + m significant
6280
6273
// bits. If the total number of significant bits does not exceed the
6281
6274
// result bit width (minus 1), there is no overflow.
@@ -6286,8 +6279,8 @@ llvm::computeOverflowForSignedMul(const Value *LHS, const Value *RHS,
6286
6279
6287
6280
// Note that underestimating the number of sign bits gives a more
6288
6281
// conservative answer.
6289
- unsigned SignBits = ComputeNumSignBits (LHS, DL, 0 , AC, CxtI, DT) +
6290
- ComputeNumSignBits (RHS, DL, 0 , AC, CxtI, DT );
6282
+ unsigned SignBits =
6283
+ ::ComputeNumSignBits (LHS, 0 , SQ) + :: ComputeNumSignBits(RHS, 0 , SQ );
6291
6284
6292
6285
// First handle the easy case: if we have enough sign bits there's
6293
6286
// definitely no overflow.
@@ -6304,34 +6297,28 @@ llvm::computeOverflowForSignedMul(const Value *LHS, const Value *RHS,
6304
6297
// product is exactly the minimum negative number.
6305
6298
// E.g. mul i16 with 17 sign bits: 0xff00 * 0xff80 = 0x8000
6306
6299
// For simplicity we just check if at least one side is not negative.
6307
- KnownBits LHSKnown = computeKnownBits (LHS, DL, /* Depth=*/ 0 , AC, CxtI, DT,
6308
- UseInstrInfo);
6309
- KnownBits RHSKnown = computeKnownBits (RHS, DL, /* Depth=*/ 0 , AC, CxtI, DT,
6310
- UseInstrInfo);
6300
+ KnownBits LHSKnown = ::computeKnownBits (LHS, /* Depth=*/ 0 , SQ);
6301
+ KnownBits RHSKnown = ::computeKnownBits (RHS, /* Depth=*/ 0 , SQ);
6311
6302
if (LHSKnown.isNonNegative () || RHSKnown.isNonNegative ())
6312
6303
return OverflowResult::NeverOverflows;
6313
6304
}
6314
6305
return OverflowResult::MayOverflow;
6315
6306
}
6316
6307
6317
- OverflowResult llvm::computeOverflowForUnsignedAdd (
6318
- const Value *LHS, const Value *RHS, const DataLayout &DL,
6319
- AssumptionCache *AC, const Instruction *CxtI, const DominatorTree *DT,
6320
- bool UseInstrInfo) {
6321
- ConstantRange LHSRange = computeConstantRangeIncludingKnownBits (
6322
- LHS, /* ForSigned=*/ false , DL, AC, CxtI, DT, UseInstrInfo);
6323
- ConstantRange RHSRange = computeConstantRangeIncludingKnownBits (
6324
- RHS, /* ForSigned=*/ false , DL, AC, CxtI, DT, UseInstrInfo);
6308
+ OverflowResult llvm::computeOverflowForUnsignedAdd (const Value *LHS,
6309
+ const Value *RHS,
6310
+ const SimplifyQuery &SQ) {
6311
+ ConstantRange LHSRange =
6312
+ computeConstantRangeIncludingKnownBits (LHS, /* ForSigned=*/ false , SQ);
6313
+ ConstantRange RHSRange =
6314
+ computeConstantRangeIncludingKnownBits (RHS, /* ForSigned=*/ false , SQ);
6325
6315
return mapOverflowResult (LHSRange.unsignedAddMayOverflow (RHSRange));
6326
6316
}
6327
6317
6328
6318
static OverflowResult computeOverflowForSignedAdd (const Value *LHS,
6329
6319
const Value *RHS,
6330
6320
const AddOperator *Add,
6331
- const DataLayout &DL,
6332
- AssumptionCache *AC,
6333
- const Instruction *CxtI,
6334
- const DominatorTree *DT) {
6321
+ const SimplifyQuery &SQ) {
6335
6322
if (Add && Add->hasNoSignedWrap ()) {
6336
6323
return OverflowResult::NeverOverflows;
6337
6324
}
@@ -6350,14 +6337,14 @@ static OverflowResult computeOverflowForSignedAdd(const Value *LHS,
6350
6337
//
6351
6338
// Since the carry into the most significant position is always equal to
6352
6339
// the carry out of the addition, there is no signed overflow.
6353
- if (ComputeNumSignBits (LHS, DL, 0 , AC, CxtI, DT ) > 1 &&
6354
- ComputeNumSignBits (RHS, DL, 0 , AC, CxtI, DT ) > 1 )
6340
+ if (:: ComputeNumSignBits (LHS, 0 , SQ ) > 1 &&
6341
+ :: ComputeNumSignBits (RHS, 0 , SQ ) > 1)
6355
6342
return OverflowResult::NeverOverflows;
6356
6343
6357
- ConstantRange LHSRange = computeConstantRangeIncludingKnownBits (
6358
- LHS, /* ForSigned=*/ true , DL, AC, CxtI, DT );
6359
- ConstantRange RHSRange = computeConstantRangeIncludingKnownBits (
6360
- RHS, /* ForSigned=*/ true , DL, AC, CxtI, DT );
6344
+ ConstantRange LHSRange =
6345
+ computeConstantRangeIncludingKnownBits ( LHS, /* ForSigned=*/ true , SQ );
6346
+ ConstantRange RHSRange =
6347
+ computeConstantRangeIncludingKnownBits ( RHS, /* ForSigned=*/ true , SQ );
6361
6348
OverflowResult OR =
6362
6349
mapOverflowResult (LHSRange.signedAddMayOverflow (RHSRange));
6363
6350
if (OR != OverflowResult::MayOverflow)
@@ -6378,8 +6365,7 @@ static OverflowResult computeOverflowForSignedAdd(const Value *LHS,
6378
6365
(LHSRange.isAllNegative () || RHSRange.isAllNegative ());
6379
6366
if (LHSOrRHSKnownNonNegative || LHSOrRHSKnownNegative) {
6380
6367
KnownBits AddKnown (LHSRange.getBitWidth ());
6381
- computeKnownBitsFromAssume (Add, AddKnown, /* Depth=*/ 0 ,
6382
- SimplifyQuery (DL, DT, AC, CxtI, DT));
6368
+ computeKnownBitsFromAssume (Add, AddKnown, /* Depth=*/ 0 , SQ);
6383
6369
if ((AddKnown.isNonNegative () && LHSOrRHSKnownNonNegative) ||
6384
6370
(AddKnown.isNegative () && LHSOrRHSKnownNegative))
6385
6371
return OverflowResult::NeverOverflows;
@@ -6390,10 +6376,7 @@ static OverflowResult computeOverflowForSignedAdd(const Value *LHS,
6390
6376
6391
6377
OverflowResult llvm::computeOverflowForUnsignedSub (const Value *LHS,
6392
6378
const Value *RHS,
6393
- const DataLayout &DL,
6394
- AssumptionCache *AC,
6395
- const Instruction *CxtI,
6396
- const DominatorTree *DT) {
6379
+ const SimplifyQuery &SQ) {
6397
6380
// X - (X % ?)
6398
6381
// The remainder of a value can't have greater magnitude than itself,
6399
6382
// so the subtraction can't overflow.
@@ -6407,32 +6390,29 @@ OverflowResult llvm::computeOverflowForUnsignedSub(const Value *LHS,
6407
6390
// See simplifyICmpWithBinOpOnLHS() for candidates.
6408
6391
if (match (RHS, m_URem (m_Specific (LHS), m_Value ())) ||
6409
6392
match (RHS, m_NUWSub (m_Specific (LHS), m_Value ())))
6410
- if (isGuaranteedNotToBeUndefOrPoison (LHS, AC, CxtI, DT))
6393
+ if (isGuaranteedNotToBeUndefOrPoison (LHS, SQ. AC , SQ. CxtI , SQ. DT ))
6411
6394
return OverflowResult::NeverOverflows;
6412
6395
6413
6396
// Checking for conditions implied by dominating conditions may be expensive.
6414
6397
// Limit it to usub_with_overflow calls for now.
6415
- if (match (CxtI,
6398
+ if (match (SQ. CxtI ,
6416
6399
m_Intrinsic<Intrinsic::usub_with_overflow>(m_Value (), m_Value ())))
6417
- if (auto C =
6418
- isImpliedByDomCondition (CmpInst::ICMP_UGE, LHS, RHS, CxtI, DL)) {
6400
+ if (auto C = isImpliedByDomCondition (CmpInst::ICMP_UGE, LHS, RHS, SQ. CxtI ,
6401
+ SQ. DL )) {
6419
6402
if (*C)
6420
6403
return OverflowResult::NeverOverflows;
6421
6404
return OverflowResult::AlwaysOverflowsLow;
6422
6405
}
6423
- ConstantRange LHSRange = computeConstantRangeIncludingKnownBits (
6424
- LHS, /* ForSigned=*/ false , DL, AC, CxtI, DT );
6425
- ConstantRange RHSRange = computeConstantRangeIncludingKnownBits (
6426
- RHS, /* ForSigned=*/ false , DL, AC, CxtI, DT );
6406
+ ConstantRange LHSRange =
6407
+ computeConstantRangeIncludingKnownBits ( LHS, /* ForSigned=*/ false , SQ );
6408
+ ConstantRange RHSRange =
6409
+ computeConstantRangeIncludingKnownBits ( RHS, /* ForSigned=*/ false , SQ );
6427
6410
return mapOverflowResult (LHSRange.unsignedSubMayOverflow (RHSRange));
6428
6411
}
6429
6412
6430
6413
OverflowResult llvm::computeOverflowForSignedSub (const Value *LHS,
6431
6414
const Value *RHS,
6432
- const DataLayout &DL,
6433
- AssumptionCache *AC,
6434
- const Instruction *CxtI,
6435
- const DominatorTree *DT) {
6415
+ const SimplifyQuery &SQ) {
6436
6416
// X - (X % ?)
6437
6417
// The remainder of a value can't have greater magnitude than itself,
6438
6418
// so the subtraction can't overflow.
@@ -6443,19 +6423,19 @@ OverflowResult llvm::computeOverflowForSignedSub(const Value *LHS,
6443
6423
// then determining no-overflow may allow other transforms.
6444
6424
if (match (RHS, m_SRem (m_Specific (LHS), m_Value ())) ||
6445
6425
match (RHS, m_NSWSub (m_Specific (LHS), m_Value ())))
6446
- if (isGuaranteedNotToBeUndefOrPoison (LHS, AC, CxtI, DT))
6426
+ if (isGuaranteedNotToBeUndefOrPoison (LHS, SQ. AC , SQ. CxtI , SQ. DT ))
6447
6427
return OverflowResult::NeverOverflows;
6448
6428
6449
6429
// If LHS and RHS each have at least two sign bits, the subtraction
6450
6430
// cannot overflow.
6451
- if (ComputeNumSignBits (LHS, DL, 0 , AC, CxtI, DT ) > 1 &&
6452
- ComputeNumSignBits (RHS, DL, 0 , AC, CxtI, DT ) > 1 )
6431
+ if (:: ComputeNumSignBits (LHS, 0 , SQ ) > 1 &&
6432
+ :: ComputeNumSignBits (RHS, 0 , SQ ) > 1)
6453
6433
return OverflowResult::NeverOverflows;
6454
6434
6455
- ConstantRange LHSRange = computeConstantRangeIncludingKnownBits (
6456
- LHS, /* ForSigned=*/ true , DL, AC, CxtI, DT );
6457
- ConstantRange RHSRange = computeConstantRangeIncludingKnownBits (
6458
- RHS, /* ForSigned=*/ true , DL, AC, CxtI, DT );
6435
+ ConstantRange LHSRange =
6436
+ computeConstantRangeIncludingKnownBits ( LHS, /* ForSigned=*/ true , SQ );
6437
+ ConstantRange RHSRange =
6438
+ computeConstantRangeIncludingKnownBits ( RHS, /* ForSigned=*/ true , SQ );
6459
6439
return mapOverflowResult (LHSRange.signedSubMayOverflow (RHSRange));
6460
6440
}
6461
6441
@@ -6949,21 +6929,15 @@ bool llvm::mustExecuteUBIfPoisonOnPathTo(Instruction *Root,
6949
6929
}
6950
6930
6951
6931
OverflowResult llvm::computeOverflowForSignedAdd (const AddOperator *Add,
6952
- const DataLayout &DL,
6953
- AssumptionCache *AC,
6954
- const Instruction *CxtI,
6955
- const DominatorTree *DT) {
6932
+ const SimplifyQuery &SQ) {
6956
6933
return ::computeOverflowForSignedAdd (Add->getOperand (0 ), Add->getOperand (1 ),
6957
- Add, DL, AC, CxtI, DT );
6934
+ Add, SQ );
6958
6935
}
6959
6936
6960
6937
OverflowResult llvm::computeOverflowForSignedAdd (const Value *LHS,
6961
6938
const Value *RHS,
6962
- const DataLayout &DL,
6963
- AssumptionCache *AC,
6964
- const Instruction *CxtI,
6965
- const DominatorTree *DT) {
6966
- return ::computeOverflowForSignedAdd (LHS, RHS, nullptr , DL, AC, CxtI, DT);
6939
+ const SimplifyQuery &SQ) {
6940
+ return ::computeOverflowForSignedAdd (LHS, RHS, nullptr , SQ);
6967
6941
}
6968
6942
6969
6943
bool llvm::isGuaranteedToTransferExecutionToSuccessor (const Instruction *I) {
0 commit comments