@@ -640,82 +640,69 @@ static void computeKnownBitsFromCmp(const Value *V, const ICmpInst *Cmp,
640
640
QueryNoAC.AC = nullptr ;
641
641
642
642
// Note that ptrtoint may change the bitwidth.
643
- Value *A, *B;
644
643
auto m_V =
645
644
m_CombineOr (m_Specific (V), m_PtrToIntSameSize (Q.DL , m_Specific (V)));
646
645
647
646
CmpInst::Predicate Pred;
648
- uint64_t C;
647
+ const APInt *Mask, *C;
648
+ uint64_t ShAmt;
649
649
switch (Cmp->getPredicate ()) {
650
650
case ICmpInst::ICMP_EQ:
651
- // assume(v = a)
652
- if (match (Cmp, m_c_ICmp (Pred, m_V, m_Value (A)))) {
653
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC);
654
- Known = Known.unionWith (RHSKnown);
655
- // assume(v & b = a)
651
+ // assume(V = C)
652
+ if (match (Cmp, m_ICmp (Pred, m_V, m_APInt (C)))) {
653
+ Known = Known.unionWith (KnownBits::makeConstant (*C));
654
+ // assume(V & Mask = C)
656
655
} else if (match (Cmp,
657
- m_c_ICmp (Pred, m_c_And (m_V, m_Value (B)), m_Value (A)))) {
658
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC);
659
- KnownBits MaskKnown = computeKnownBits (B, Depth + 1 , QueryNoAC);
660
-
661
- // For those bits in the mask that are known to be one, we can propagate
662
- // known bits from the RHS to V.
663
- Known.Zero |= RHSKnown.Zero & MaskKnown.One ;
664
- Known.One |= RHSKnown.One & MaskKnown.One ;
665
- // assume(v | b = a)
656
+ m_ICmp (Pred, m_And (m_V, m_APInt (Mask)), m_APInt (C)))) {
657
+ // For one bits in Mask, we can propagate bits from C to V.
658
+ Known.Zero |= ~*C & *Mask;
659
+ Known.One |= *C & *Mask;
660
+ // assume(V | Mask = C)
666
661
} else if (match (Cmp,
667
- m_c_ICmp (Pred, m_c_Or (m_V, m_Value (B)), m_Value (A)))) {
668
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC);
669
- KnownBits BKnown = computeKnownBits (B, Depth + 1 , QueryNoAC);
670
-
671
- // For those bits in B that are known to be zero, we can propagate known
672
- // bits from the RHS to V.
673
- Known.Zero |= RHSKnown.Zero & BKnown.Zero ;
674
- Known.One |= RHSKnown.One & BKnown.Zero ;
675
- // assume(v ^ b = a)
662
+ m_ICmp (Pred, m_Or (m_V, m_APInt (Mask)), m_APInt (C)))) {
663
+ // For zero bits in Mask, we can propagate bits from C to V.
664
+ Known.Zero |= ~*C & ~*Mask;
665
+ Known.One |= *C & ~*Mask;
666
+ // assume(V ^ Mask = C)
676
667
} else if (match (Cmp,
677
- m_c_ICmp (Pred, m_c_Xor (m_V, m_Value (B)), m_Value (A)))) {
678
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC);
679
- KnownBits BKnown = computeKnownBits (B, Depth + 1 , QueryNoAC);
680
-
681
- // For those bits in B that are known to be zero, we can propagate known
682
- // bits from the RHS to V. For those bits in B that are known to be one,
683
- // we can propagate inverted known bits from the RHS to V.
684
- Known.Zero |= RHSKnown.Zero & BKnown.Zero ;
685
- Known.One |= RHSKnown.One & BKnown.Zero ;
686
- Known.Zero |= RHSKnown.One & BKnown.One ;
687
- Known.One |= RHSKnown.Zero & BKnown.One ;
688
- // assume(v << c = a)
689
- } else if (match (Cmp, m_c_ICmp (Pred, m_Shl (m_V, m_ConstantInt (C)),
690
- m_Value (A))) &&
691
- C < BitWidth) {
692
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC);
693
-
694
- // For those bits in RHS that are known, we can propagate them to known
695
- // bits in V shifted to the right by C.
696
- RHSKnown.Zero .lshrInPlace (C);
697
- RHSKnown.One .lshrInPlace (C);
668
+ m_ICmp (Pred, m_Xor (m_V, m_APInt (Mask)), m_APInt (C)))) {
669
+ // For those bits in Mask that are zero, we can propagate known bits
670
+ // from C to V. For those bits in Mask that are one, we can propagate
671
+ // inverted bits from C to V.
672
+ Known.Zero |= ~*C & ~*Mask;
673
+ Known.One |= *C & ~*Mask;
674
+ Known.Zero |= *C & *Mask;
675
+ Known.One |= ~*C & *Mask;
676
+ // assume(V << ShAmt = C)
677
+ } else if (match (Cmp, m_ICmp (Pred, m_Shl (m_V, m_ConstantInt (ShAmt)),
678
+ m_APInt (C))) &&
679
+ ShAmt < BitWidth) {
680
+ // For those bits in C that are known, we can propagate them to known
681
+ // bits in V shifted to the right by ShAmt.
682
+ KnownBits RHSKnown = KnownBits::makeConstant (*C);
683
+ RHSKnown.Zero .lshrInPlace (ShAmt);
684
+ RHSKnown.One .lshrInPlace (ShAmt);
698
685
Known = Known.unionWith (RHSKnown);
699
- // assume(v >> c = a )
700
- } else if (match (Cmp, m_c_ICmp (Pred, m_Shr (m_V, m_ConstantInt (C )),
701
- m_Value (A ))) &&
702
- C < BitWidth) {
703
- KnownBits RHSKnown = computeKnownBits (A, Depth + 1 , QueryNoAC );
686
+ // assume(V >> ShAmt = C )
687
+ } else if (match (Cmp, m_ICmp (Pred, m_Shr (m_V, m_ConstantInt (ShAmt )),
688
+ m_APInt (C ))) &&
689
+ ShAmt < BitWidth) {
690
+ KnownBits RHSKnown = KnownBits::makeConstant (*C );
704
691
// For those bits in RHS that are known, we can propagate them to known
705
692
// bits in V shifted to the right by C.
706
- Known.Zero |= RHSKnown.Zero << C ;
707
- Known.One |= RHSKnown.One << C ;
693
+ Known.Zero |= RHSKnown.Zero << ShAmt ;
694
+ Known.One |= RHSKnown.One << ShAmt ;
708
695
}
709
696
break ;
710
697
case ICmpInst::ICMP_NE: {
711
- // assume (v & b != 0) where b is a power of 2
698
+ // assume (V & B != 0) where B is a power of 2
712
699
const APInt *BPow2;
713
- if (match (Cmp, m_ICmp (Pred, m_c_And (m_V, m_Power2 (BPow2)), m_Zero ()))) {
700
+ if (match (Cmp, m_ICmp (Pred, m_And (m_V, m_Power2 (BPow2)), m_Zero ())))
714
701
Known.One |= *BPow2;
715
- }
716
702
break ;
717
703
}
718
704
default :
705
+ Value *A;
719
706
const APInt *Offset = nullptr ;
720
707
if (match (Cmp, m_ICmp (Pred, m_CombineOr (m_V, m_Add (m_V, m_APInt (Offset))),
721
708
m_Value (A)))) {
0 commit comments