@@ -673,6 +673,7 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
673673 void visitStoreInst (StoreInst &I);
674674 void visitLoadInst (LoadInst &I);
675675 void visitGetElementPtrInst (GetElementPtrInst &I);
676+ void visitAllocaInst (AllocaInst &AI);
676677
677678 void visitInvokeInst (InvokeInst &II) {
678679 visitCallBase (II);
@@ -1626,6 +1627,13 @@ void SCCPInstVisitor::visitGetElementPtrInst(GetElementPtrInst &I) {
16261627 markConstant (&I, C);
16271628}
16281629
1630+ void SCCPInstVisitor::visitAllocaInst (AllocaInst &I) {
1631+ if (!NullPointerIsDefined (I.getFunction (), I.getAddressSpace ()))
1632+ return (void )markNotNull (ValueState[&I], &I);
1633+
1634+ markOverdefined (&I);
1635+ }
1636+
16291637void SCCPInstVisitor::visitStoreInst (StoreInst &SI) {
16301638 // If this store is of a struct, ignore it.
16311639 if (SI.getOperand (0 )->getType ()->isStructTy ())
@@ -1647,18 +1655,23 @@ void SCCPInstVisitor::visitStoreInst(StoreInst &SI) {
16471655}
16481656
16491657static ValueLatticeElement getValueFromMetadata (const Instruction *I) {
1650- if (I->getType ()->isIntOrIntVectorTy ()) {
1651- if (MDNode *Ranges = I->getMetadata (LLVMContext::MD_range))
1652- return ValueLatticeElement::getRange (
1653- getConstantRangeFromMetadata (*Ranges));
1654-
1655- if (const auto *CB = dyn_cast<CallBase>(I))
1658+ if (const auto *CB = dyn_cast<CallBase>(I)) {
1659+ if (CB->getType ()->isIntOrIntVectorTy ())
16561660 if (std::optional<ConstantRange> Range = CB->getRange ())
16571661 return ValueLatticeElement::getRange (*Range);
1662+ if (CB->getType ()->isPointerTy () && CB->isReturnNonNull ())
1663+ return ValueLatticeElement::getNot (
1664+ ConstantPointerNull::get (cast<PointerType>(I->getType ())));
16581665 }
1666+
1667+ if (I->getType ()->isIntOrIntVectorTy ())
1668+ if (MDNode *Ranges = I->getMetadata (LLVMContext::MD_range))
1669+ return ValueLatticeElement::getRange (
1670+ getConstantRangeFromMetadata (*Ranges));
16591671 if (I->hasMetadata (LLVMContext::MD_nonnull))
16601672 return ValueLatticeElement::getNot (
16611673 ConstantPointerNull::get (cast<PointerType>(I->getType ())));
1674+
16621675 return ValueLatticeElement::getOverdefined ();
16631676}
16641677
0 commit comments