[clang] [llvm] [SCCP] Infer return attributes in SCCP as well (PR #106732)
Nikita Popov via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 30 11:41:29 PDT 2024
================
@@ -354,6 +354,36 @@ bool SCCPSolver::removeNonFeasibleEdges(BasicBlock *BB, DomTreeUpdater &DTU,
return true;
}
+void SCCPSolver::inferReturnAttributes() const {
+ for (const auto &I : getTrackedRetVals()) {
+ Function *F = I.first;
+ const ValueLatticeElement &ReturnValue = I.second;
+
+ // If there is a known constant range for the return value, add range
+ // attribute to the return value.
+ if (ReturnValue.isConstantRange() &&
+ !ReturnValue.getConstantRange().isSingleElement()) {
+ // Do not add range metadata if the return value may include undef.
+ if (ReturnValue.isConstantRangeIncludingUndef())
+ continue;
+
+ // Take the intersection of the existing attribute and the inferred range.
+ ConstantRange CR = ReturnValue.getConstantRange();
+ if (F->hasRetAttribute(Attribute::Range))
+ CR = CR.intersectWith(F->getRetAttribute(Attribute::Range).getRange());
+ F->addRangeRetAttr(CR);
+ continue;
----------------
nikic wrote:
nonnull applies only to pointers, while range applies only to (vectors of) integers, so they can not apply at the same time.
https://github.com/llvm/llvm-project/pull/106732
More information about the cfe-commits
mailing list