@@ -350,13 +350,14 @@ bool llvm::isKnownNegative(const Value *V, const DataLayout &DL, unsigned Depth,
350
350
return Known.isNegative ();
351
351
}
352
352
353
- static bool isKnownNonEqual (const Value *V1, const Value *V2, const Query &Q);
353
+ static bool isKnownNonEqual (const Value *V1, const Value *V2, unsigned Depth,
354
+ const Query &Q);
354
355
355
356
bool llvm::isKnownNonEqual (const Value *V1, const Value *V2,
356
357
const DataLayout &DL, AssumptionCache *AC,
357
358
const Instruction *CxtI, const DominatorTree *DT,
358
359
bool UseInstrInfo) {
359
- return ::isKnownNonEqual (V1, V2,
360
+ return ::isKnownNonEqual (V1, V2, 0 ,
360
361
Query (DL, AC, safeCxtI (V1, safeCxtI (V2, CxtI)), DT,
361
362
UseInstrInfo, /* ORE=*/ nullptr ));
362
363
}
@@ -2486,7 +2487,8 @@ bool isKnownNonZero(const Value* V, unsigned Depth, const Query& Q) {
2486
2487
}
2487
2488
2488
2489
// / Return true if V2 == V1 + X, where X is known non-zero.
2489
- static bool isAddOfNonZero (const Value *V1, const Value *V2, const Query &Q) {
2490
+ static bool isAddOfNonZero (const Value *V1, const Value *V2, unsigned Depth,
2491
+ const Query &Q) {
2490
2492
const BinaryOperator *BO = dyn_cast<BinaryOperator>(V1);
2491
2493
if (!BO || BO->getOpcode () != Instruction::Add)
2492
2494
return false ;
@@ -2497,24 +2499,54 @@ static bool isAddOfNonZero(const Value *V1, const Value *V2, const Query &Q) {
2497
2499
Op = BO->getOperand (0 );
2498
2500
else
2499
2501
return false ;
2500
- return isKnownNonZero (Op, 0 , Q);
2502
+ return isKnownNonZero (Op, Depth + 1 , Q);
2501
2503
}
2502
2504
2503
2505
// / Return true if it is known that V1 != V2.
2504
- static bool isKnownNonEqual (const Value *V1, const Value *V2, const Query &Q) {
2506
+ static bool isKnownNonEqual (const Value *V1, const Value *V2, unsigned Depth,
2507
+ const Query &Q) {
2505
2508
if (V1 == V2)
2506
2509
return false ;
2507
2510
if (V1->getType () != V2->getType ())
2508
2511
// We can't look through casts yet.
2509
2512
return false ;
2510
- if (isAddOfNonZero (V1, V2, Q) || isAddOfNonZero (V2, V1, Q))
2513
+
2514
+ if (Depth >= MaxAnalysisRecursionDepth)
2515
+ return false ;
2516
+
2517
+ // See if we can recurse through (exactly one of) our operands.
2518
+ auto *O1 = dyn_cast<Operator>(V1);
2519
+ auto *O2 = dyn_cast<Operator>(V2);
2520
+ if (O1 && O2 && O1->getOpcode () == O2->getOpcode ()) {
2521
+ switch (O1->getOpcode ()) {
2522
+ default : break ;
2523
+ case Instruction::Add:
2524
+ case Instruction::Sub:
2525
+ // Assume operand order has been canonicalized
2526
+ if (O1->getOperand (0 ) == O2->getOperand (0 ))
2527
+ return isKnownNonEqual (O1->getOperand (1 ), O2->getOperand (1 ),
2528
+ Depth + 1 , Q);
2529
+ if (O1->getOperand (1 ) == O2->getOperand (1 ))
2530
+ return isKnownNonEqual (O1->getOperand (0 ), O2->getOperand (0 ),
2531
+ Depth + 1 , Q);
2532
+ break ;
2533
+ case Instruction::SExt:
2534
+ case Instruction::ZExt:
2535
+ if (O1->getOperand (0 )->getType () == O2->getOperand (0 )->getType ())
2536
+ return isKnownNonEqual (O1->getOperand (0 ), O2->getOperand (0 ),
2537
+ Depth + 1 , Q);
2538
+ break ;
2539
+ };
2540
+ }
2541
+
2542
+ if (isAddOfNonZero (V1, V2, Depth, Q) || isAddOfNonZero (V2, V1, Depth, Q))
2511
2543
return true ;
2512
2544
2513
2545
if (V1->getType ()->isIntOrIntVectorTy ()) {
2514
2546
// Are any known bits in V1 contradictory to known bits in V2? If V1
2515
2547
// has a known zero where V2 has a known one, they must not be equal.
2516
- KnownBits Known1 = computeKnownBits (V1, 0 , Q);
2517
- KnownBits Known2 = computeKnownBits (V2, 0 , Q);
2548
+ KnownBits Known1 = computeKnownBits (V1, Depth , Q);
2549
+ KnownBits Known2 = computeKnownBits (V2, Depth , Q);
2518
2550
2519
2551
if (Known1.Zero .intersects (Known2.One ) ||
2520
2552
Known2.Zero .intersects (Known1.One ))
0 commit comments