@@ -706,45 +706,57 @@ static void computeKnownBitsFromCmp(const Value *V, CmpInst::Predicate Pred,
706
706
}
707
707
}
708
708
709
- static void computeKnownBitsFromCond (const Value *V, Value *Cond,
710
- KnownBits &Known, unsigned Depth,
711
- const SimplifyQuery &SQ, bool Invert) {
709
+ using InformationFn = function_ref<void (const Value *, bool )>;
710
+
711
+ static void computeInformationFromCond (const Value *V, Value *Cond,
712
+ unsigned Depth, const SimplifyQuery &SQ,
713
+ InformationFn Fn, bool Invert) {
712
714
Value *A, *B;
713
715
if (Depth < MaxAnalysisRecursionDepth &&
714
716
(Invert ? match (Cond, m_LogicalOr (m_Value (A), m_Value (B)))
715
717
: match (Cond, m_LogicalAnd (m_Value (A), m_Value (B))))) {
716
- computeKnownBitsFromCond (V, A, Known, Depth + 1 , SQ, Invert);
717
- computeKnownBitsFromCond (V, B, Known, Depth + 1 , SQ, Invert);
718
+ computeInformationFromCond (V, A, Depth + 1 , SQ, Fn , Invert);
719
+ computeInformationFromCond (V, B, Depth + 1 , SQ, Fn , Invert);
718
720
}
719
721
720
- if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
721
- computeKnownBitsFromCmp (
722
- V, Invert ? Cmp->getInversePredicate () : Cmp->getPredicate (),
723
- Cmp->getOperand (0 ), Cmp->getOperand (1 ), Known, SQ);
722
+ Fn (Cond, Invert);
724
723
}
725
724
726
- void llvm::computeKnownBitsFromContext (const Value *V, KnownBits &Known,
727
- unsigned Depth, const SimplifyQuery &Q) {
728
- if (!Q.CxtI )
729
- return ;
730
-
725
+ static void computeInformationFromDominatingConditions (const Value *V,
726
+ unsigned Depth,
727
+ const SimplifyQuery &Q,
728
+ InformationFn Fn) {
731
729
if (Q.DC && Q.DT ) {
732
730
// Handle dominating conditions.
733
731
for (BranchInst *BI : Q.DC ->conditionsFor (V)) {
734
732
BasicBlockEdge Edge0 (BI->getParent (), BI->getSuccessor (0 ));
735
733
if (Q.DT ->dominates (Edge0, Q.CxtI ->getParent ()))
736
- computeKnownBitsFromCond (V, BI->getCondition (), Known, Depth, Q,
737
- /* Invert*/ false );
734
+ computeInformationFromCond (V, BI->getCondition (), Depth, Q, Fn ,
735
+ /* Invert*/ false );
738
736
739
737
BasicBlockEdge Edge1 (BI->getParent (), BI->getSuccessor (1 ));
740
738
if (Q.DT ->dominates (Edge1, Q.CxtI ->getParent ()))
741
- computeKnownBitsFromCond (V, BI->getCondition (), Known, Depth, Q,
742
- /* Invert*/ true );
739
+ computeInformationFromCond (V, BI->getCondition (), Depth, Q, Fn ,
740
+ /* Invert*/ true );
743
741
}
744
-
745
- if (Known.hasConflict ())
746
- Known.resetAll ();
747
742
}
743
+ }
744
+
745
+ void llvm::computeKnownBitsFromContext (const Value *V, KnownBits &Known,
746
+ unsigned Depth, const SimplifyQuery &Q) {
747
+ if (!Q.CxtI )
748
+ return ;
749
+
750
+ computeInformationFromDominatingConditions (
751
+ V, Depth, Q, [&Known, &Q, V](const Value *Cond, bool Invert) {
752
+ if (auto *Cmp = dyn_cast<ICmpInst>(Cond))
753
+ computeKnownBitsFromCmp (
754
+ V, Invert ? Cmp->getInversePredicate () : Cmp->getPredicate (),
755
+ Cmp->getOperand (0 ), Cmp->getOperand (1 ), Known, Q);
756
+ });
757
+
758
+ if (Known.hasConflict ())
759
+ Known.resetAll ();
748
760
749
761
if (!Q.AC )
750
762
return ;
0 commit comments