@@ -673,6 +673,7 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
673
673
void visitStoreInst (StoreInst &I);
674
674
void visitLoadInst (LoadInst &I);
675
675
void visitGetElementPtrInst (GetElementPtrInst &I);
676
+ void visitAllocaInst (AllocaInst &AI);
676
677
677
678
void visitInvokeInst (InvokeInst &II) {
678
679
visitCallBase (II);
@@ -1626,6 +1627,13 @@ void SCCPInstVisitor::visitGetElementPtrInst(GetElementPtrInst &I) {
1626
1627
markConstant (&I, C);
1627
1628
}
1628
1629
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
+
1629
1637
void SCCPInstVisitor::visitStoreInst (StoreInst &SI) {
1630
1638
// If this store is of a struct, ignore it.
1631
1639
if (SI.getOperand (0 )->getType ()->isStructTy ())
@@ -1647,18 +1655,23 @@ void SCCPInstVisitor::visitStoreInst(StoreInst &SI) {
1647
1655
}
1648
1656
1649
1657
static 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 ())
1656
1660
if (std::optional<ConstantRange> Range = CB->getRange ())
1657
1661
return ValueLatticeElement::getRange (*Range);
1662
+ if (CB->getType ()->isPointerTy () && CB->isReturnNonNull ())
1663
+ return ValueLatticeElement::getNot (
1664
+ ConstantPointerNull::get (cast<PointerType>(I->getType ())));
1658
1665
}
1666
+
1667
+ if (I->getType ()->isIntOrIntVectorTy ())
1668
+ if (MDNode *Ranges = I->getMetadata (LLVMContext::MD_range))
1669
+ return ValueLatticeElement::getRange (
1670
+ getConstantRangeFromMetadata (*Ranges));
1659
1671
if (I->hasMetadata (LLVMContext::MD_nonnull))
1660
1672
return ValueLatticeElement::getNot (
1661
1673
ConstantPointerNull::get (cast<PointerType>(I->getType ())));
1674
+
1662
1675
return ValueLatticeElement::getOverdefined ();
1663
1676
}
1664
1677
0 commit comments