@@ -2505,4 +2505,80 @@ TEST_F(ConstantRangeTest, binaryNot) {
2505
2505
[](const APInt &N) { return ~N; }, PreferSmallest);
2506
2506
}
2507
2507
2508
- } // anonymous namespace
2508
+ template <typename T>
2509
+ void testConstantRangeICmpPredEquivalence (ICmpInst::Predicate SrcPred, T Func) {
2510
+ unsigned Bits = 4 ;
2511
+ EnumerateTwoConstantRanges (
2512
+ Bits, [&](const ConstantRange &CR1, const ConstantRange &CR2) {
2513
+ ICmpInst::Predicate TgtPred;
2514
+ bool ExpectedEquivalent;
2515
+ std::tie (TgtPred, ExpectedEquivalent) = Func (CR1, CR2);
2516
+ if (TgtPred == CmpInst::Predicate::BAD_ICMP_PREDICATE)
2517
+ return ;
2518
+ bool TrulyEquivalent = true ;
2519
+ ForeachNumInConstantRange (CR1, [&](const APInt &N1) {
2520
+ if (!TrulyEquivalent)
2521
+ return ;
2522
+ ForeachNumInConstantRange (CR2, [&](const APInt &N2) {
2523
+ if (!TrulyEquivalent)
2524
+ return ;
2525
+ TrulyEquivalent &= ICmpInst::compare (N1, N2, SrcPred) ==
2526
+ ICmpInst::compare (N1, N2, TgtPred);
2527
+ });
2528
+ });
2529
+ ASSERT_EQ (TrulyEquivalent, ExpectedEquivalent);
2530
+ });
2531
+ }
2532
+
2533
+ TEST_F (ConstantRangeTest, areInsensitiveToSignednessOfICmpPredicate) {
2534
+ for (auto Pred : seq_inclusive (ICmpInst::Predicate::FIRST_ICMP_PREDICATE,
2535
+ ICmpInst::Predicate::LAST_ICMP_PREDICATE)) {
2536
+ if (ICmpInst::isEquality (Pred))
2537
+ continue ;
2538
+ ICmpInst::Predicate FlippedSignednessPred =
2539
+ ICmpInst::getFlippedSignednessPredicate (Pred);
2540
+ testConstantRangeICmpPredEquivalence (Pred, [FlippedSignednessPred](
2541
+ const ConstantRange &CR1,
2542
+ const ConstantRange &CR2) {
2543
+ return std::make_pair (
2544
+ FlippedSignednessPred,
2545
+ ConstantRange::areInsensitiveToSignednessOfICmpPredicate (CR1, CR2));
2546
+ });
2547
+ }
2548
+ }
2549
+
2550
+ TEST_F (ConstantRangeTest, areInsensitiveToSignednessOfInvertedICmpPredicate) {
2551
+ for (auto Pred : seq_inclusive (ICmpInst::Predicate::FIRST_ICMP_PREDICATE,
2552
+ ICmpInst::Predicate::LAST_ICMP_PREDICATE)) {
2553
+ if (ICmpInst::isEquality (Pred))
2554
+ continue ;
2555
+ ICmpInst::Predicate InvertedFlippedSignednessPred =
2556
+ ICmpInst::getInversePredicate (
2557
+ ICmpInst::getFlippedSignednessPredicate (Pred));
2558
+ testConstantRangeICmpPredEquivalence (
2559
+ Pred, [InvertedFlippedSignednessPred](const ConstantRange &CR1,
2560
+ const ConstantRange &CR2) {
2561
+ return std::make_pair (
2562
+ InvertedFlippedSignednessPred,
2563
+ ConstantRange::areInsensitiveToSignednessOfInvertedICmpPredicate (
2564
+ CR1, CR2));
2565
+ });
2566
+ }
2567
+ }
2568
+
2569
+ TEST_F (ConstantRangeTest, getEquivalentPredWithFlippedSignedness) {
2570
+ for (auto Pred : seq_inclusive (ICmpInst::Predicate::FIRST_ICMP_PREDICATE,
2571
+ ICmpInst::Predicate::LAST_ICMP_PREDICATE)) {
2572
+ if (ICmpInst::isEquality (Pred))
2573
+ continue ;
2574
+ testConstantRangeICmpPredEquivalence (
2575
+ Pred, [Pred](const ConstantRange &CR1, const ConstantRange &CR2) {
2576
+ return std::make_pair (
2577
+ ConstantRange::getEquivalentPredWithFlippedSignedness (Pred, CR1,
2578
+ CR2),
2579
+ /* ExpectedEquivalent=*/ true );
2580
+ });
2581
+ }
2582
+ }
2583
+
2584
+ } // anonymous namespace
0 commit comments