@@ -428,6 +428,12 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
428
428
return markConstant (ValueState[V], V, C);
429
429
}
430
430
431
+ // / markConstantRange - Mark the object as constant range with \p CR. If the
432
+ // / object is not a constant range with the range \p CR, add it to the
433
+ // / instruction work list so that the users of the instruction are updated
434
+ // / later.
435
+ bool markConstantRange (ValueLatticeElement &IV, Value *V, ConstantRange &CR);
436
+
431
437
// markOverdefined - Make a value be marked as "overdefined". If the
432
438
// value is not already overdefined, add it to the overdefined instruction
433
439
// work list so that the users of the instruction are updated later.
@@ -788,6 +794,17 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
788
794
markOverdefined (ValueState[V], V);
789
795
}
790
796
797
+ void trackValueOfArgument (Argument *A) {
798
+ if (A->getType ()->isIntegerTy ()) {
799
+ if (std::optional<ConstantRange> Range = A->getRange ()) {
800
+ markConstantRange (ValueState[A], A, *Range);
801
+ return ;
802
+ }
803
+ }
804
+ // Assume nothing about the incoming arguments without range.
805
+ markOverdefined (A);
806
+ }
807
+
791
808
bool isStructLatticeConstant (Function *F, StructType *STy);
792
809
793
810
Constant *getConstant (const ValueLatticeElement &LV, Type *Ty) const ;
@@ -873,6 +890,15 @@ bool SCCPInstVisitor::markConstant(ValueLatticeElement &IV, Value *V,
873
890
return true ;
874
891
}
875
892
893
+ bool SCCPInstVisitor::markConstantRange (ValueLatticeElement &IV, Value *V,
894
+ ConstantRange &CR) {
895
+ if (!IV.markConstantRange (CR))
896
+ return false ;
897
+ LLVM_DEBUG (dbgs () << " markConstantRange: " << CR << " : " << *V << ' \n ' );
898
+ pushToWorkList (IV, V);
899
+ return true ;
900
+ }
901
+
876
902
bool SCCPInstVisitor::markOverdefined (ValueLatticeElement &IV, Value *V) {
877
903
if (!IV.markOverdefined ())
878
904
return false ;
@@ -1581,10 +1607,15 @@ void SCCPInstVisitor::visitStoreInst(StoreInst &SI) {
1581
1607
}
1582
1608
1583
1609
static ValueLatticeElement getValueFromMetadata (const Instruction *I) {
1584
- if (MDNode *Ranges = I->getMetadata (LLVMContext::MD_range))
1585
- if (I->getType ()-> isIntegerTy ( ))
1610
+ if (I->getType ()-> isIntegerTy ()) {
1611
+ if (MDNode *Ranges = I->getMetadata (LLVMContext::MD_range ))
1586
1612
return ValueLatticeElement::getRange (
1587
1613
getConstantRangeFromMetadata (*Ranges));
1614
+
1615
+ if (const auto *CB = dyn_cast<CallBase>(I))
1616
+ if (std::optional<ConstantRange> Range = CB->getRange ())
1617
+ return ValueLatticeElement::getRange (*Range);
1618
+ }
1588
1619
if (I->hasMetadata (LLVMContext::MD_nonnull))
1589
1620
return ValueLatticeElement::getNot (
1590
1621
ConstantPointerNull::get (cast<PointerType>(I->getType ())));
@@ -2090,6 +2121,10 @@ const SmallPtrSet<Function *, 16> SCCPSolver::getMRVFunctionsTracked() {
2090
2121
2091
2122
void SCCPSolver::markOverdefined (Value *V) { Visitor->markOverdefined (V); }
2092
2123
2124
+ void SCCPSolver::trackValueOfArgument (Argument *V) {
2125
+ Visitor->trackValueOfArgument (V);
2126
+ }
2127
+
2093
2128
bool SCCPSolver::isStructLatticeConstant (Function *F, StructType *STy) {
2094
2129
return Visitor->isStructLatticeConstant (F, STy);
2095
2130
}
0 commit comments