@@ -589,30 +589,34 @@ static bool isKnownNonZeroFromAssume(const Value *V, const SimplifyQuery &Q) {
589
589
if (!Q.AC || !Q.CxtI )
590
590
return false ;
591
591
592
- if (Q.CxtI && V->getType ()->isPointerTy ()) {
593
- SmallVector<Attribute::AttrKind, 2 > AttrKinds{Attribute::NonNull};
594
- if (!NullPointerIsDefined (Q.CxtI ->getFunction (),
595
- V->getType ()->getPointerAddressSpace ()))
596
- AttrKinds.push_back (Attribute::Dereferenceable);
597
-
598
- if (getKnowledgeValidInContext (V, AttrKinds, Q.CxtI , Q.DT , Q.AC ))
599
- return true ;
600
- }
601
-
602
- for (auto &AssumeVH : Q.AC ->assumptionsFor (V)) {
603
- if (!AssumeVH)
592
+ for (AssumptionCache::ResultElem &Elem : Q.AC ->assumptionsFor (V)) {
593
+ if (!Elem.Assume )
604
594
continue ;
605
- CallInst *I = cast<CallInst>(AssumeVH);
595
+
596
+ AssumeInst *I = cast<AssumeInst>(Elem.Assume );
606
597
assert (I->getFunction () == Q.CxtI ->getFunction () &&
607
598
" Got assumption for the wrong function!" );
608
599
600
+ if (Elem.Index != AssumptionCache::ExprResultIdx) {
601
+ if (!V->getType ()->isPointerTy ())
602
+ continue ;
603
+ if (RetainedKnowledge RK = getKnowledgeFromBundle (
604
+ *I, I->bundle_op_info_begin ()[Elem.Index ])) {
605
+ if (RK.WasOn == V &&
606
+ (RK.AttrKind == Attribute::NonNull ||
607
+ (RK.AttrKind == Attribute::Dereferenceable &&
608
+ !NullPointerIsDefined (Q.CxtI ->getFunction (),
609
+ V->getType ()->getPointerAddressSpace ()))) &&
610
+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
611
+ return true ;
612
+ }
613
+ continue ;
614
+ }
615
+
609
616
// Warning: This loop can end up being somewhat performance sensitive.
610
617
// We're running this loop for once for each value queried resulting in a
611
618
// runtime of ~O(#assumes * #values).
612
619
613
- assert (I->getCalledFunction ()->getIntrinsicID () == Intrinsic::assume &&
614
- " must be an assume intrinsic" );
615
-
616
620
Value *RHS;
617
621
CmpInst::Predicate Pred;
618
622
auto m_V = m_CombineOr (m_Specific (V), m_PtrToInt (m_Specific (V)));
@@ -741,32 +745,34 @@ void llvm::computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
741
745
742
746
unsigned BitWidth = Known.getBitWidth ();
743
747
744
- // Refine Known set if the pointer alignment is set by assume bundles.
745
- if (V->getType ()->isPointerTy ()) {
746
- if (RetainedKnowledge RK = getKnowledgeValidInContext (
747
- V, { Attribute::Alignment }, Q.CxtI , Q.DT , Q.AC )) {
748
- if (isPowerOf2_64 (RK.ArgValue ))
749
- Known.Zero .setLowBits (Log2_64 (RK.ArgValue ));
750
- }
751
- }
752
-
753
748
// Note that the patterns below need to be kept in sync with the code
754
749
// in AssumptionCache::updateAffectedValues.
755
750
756
- for (auto &AssumeVH : Q.AC ->assumptionsFor (V)) {
757
- if (!AssumeVH )
751
+ for (AssumptionCache::ResultElem &Elem : Q.AC ->assumptionsFor (V)) {
752
+ if (!Elem. Assume )
758
753
continue ;
759
- CallInst *I = cast<CallInst>(AssumeVH);
754
+
755
+ AssumeInst *I = cast<AssumeInst>(Elem.Assume );
760
756
assert (I->getParent ()->getParent () == Q.CxtI ->getParent ()->getParent () &&
761
757
" Got assumption for the wrong function!" );
762
758
759
+ if (Elem.Index != AssumptionCache::ExprResultIdx) {
760
+ if (!V->getType ()->isPointerTy ())
761
+ continue ;
762
+ if (RetainedKnowledge RK = getKnowledgeFromBundle (
763
+ *I, I->bundle_op_info_begin ()[Elem.Index ])) {
764
+ if (RK.WasOn == V && RK.AttrKind == Attribute::Alignment &&
765
+ isPowerOf2_64 (RK.ArgValue ) &&
766
+ isValidAssumeForContext (I, Q.CxtI , Q.DT ))
767
+ Known.Zero .setLowBits (Log2_64 (RK.ArgValue ));
768
+ }
769
+ continue ;
770
+ }
771
+
763
772
// Warning: This loop can end up being somewhat performance sensitive.
764
773
// We're running this loop for once for each value queried resulting in a
765
774
// runtime of ~O(#assumes * #values).
766
775
767
- assert (I->getCalledFunction ()->getIntrinsicID () == Intrinsic::assume &&
768
- " must be an assume intrinsic" );
769
-
770
776
Value *Arg = I->getArgOperand (0 );
771
777
772
778
if (Arg == V && isValidAssumeForContext (I, Q.CxtI , Q.DT )) {
0 commit comments