@@ -708,6 +708,25 @@ static void computeKnownBitsFromCmp(const Value *V, CmpInst::Predicate Pred,
708
708
}
709
709
}
710
710
711
+ static void computeKnownBitsFromICmpCond (const Value *V, ICmpInst *Cmp,
712
+ KnownBits &Known,
713
+ const SimplifyQuery &SQ, bool Invert) {
714
+ ICmpInst::Predicate Pred =
715
+ Invert ? Cmp->getInversePredicate () : Cmp->getPredicate ();
716
+ Value *LHS = Cmp->getOperand (0 );
717
+ Value *RHS = Cmp->getOperand (1 );
718
+
719
+ // Handle icmp pred (trunc V), C
720
+ if (match (LHS, m_Trunc (m_Specific (V)))) {
721
+ KnownBits DstKnown (LHS->getType ()->getScalarSizeInBits ());
722
+ computeKnownBitsFromCmp (LHS, Pred, LHS, RHS, DstKnown, SQ);
723
+ Known = Known.unionWith (DstKnown.anyext (Known.getBitWidth ()));
724
+ return ;
725
+ }
726
+
727
+ computeKnownBitsFromCmp (V, Pred, LHS, RHS, Known, SQ);
728
+ }
729
+
711
730
static void computeKnownBitsFromCond (const Value *V, Value *Cond,
712
731
KnownBits &Known, unsigned Depth,
713
732
const SimplifyQuery &SQ, bool Invert) {
@@ -727,9 +746,7 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
727
746
}
728
747
729
748
if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
730
- computeKnownBitsFromCmp (
731
- V, Invert ? Cmp->getInversePredicate () : Cmp->getPredicate (),
732
- Cmp->getOperand (0 ), Cmp->getOperand (1 ), Known, SQ);
749
+ computeKnownBitsFromICmpCond (V, Cmp, Known, SQ, Invert);
733
750
}
734
751
735
752
void llvm::computeKnownBitsFromContext (const Value *V, KnownBits &Known,
@@ -815,8 +832,7 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
815
832
if (!isValidAssumeForContext (I, Q.CxtI , Q.DT ))
816
833
continue ;
817
834
818
- computeKnownBitsFromCmp (V, Cmp->getPredicate (), Cmp->getOperand (0 ),
819
- Cmp->getOperand (1 ), Known, Q);
835
+ computeKnownBitsFromICmpCond (V, Cmp, Known, Q, /* Invert=*/ false );
820
836
}
821
837
822
838
// Conflicting assumption: Undefined behavior will occur on this execution
@@ -9133,7 +9149,7 @@ addValueAffectedByCondition(Value *V,
9133
9149
9134
9150
// Peek through unary operators to find the source of the condition.
9135
9151
Value *Op;
9136
- if (match (I, m_PtrToInt (m_Value (Op)))) {
9152
+ if (match (I, m_CombineOr ( m_PtrToInt (m_Value (Op)), m_Trunc ( m_Value (Op) )))) {
9137
9153
if (isa<Instruction>(Op) || isa<Argument>(Op))
9138
9154
InsertAffected (Op);
9139
9155
}
0 commit comments