[llvm] [ValueTracking] Handle range attributes (PR #85143)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 15 02:06:26 PDT 2024
================
@@ -1467,14 +1467,21 @@ static void computeKnownBitsFromOperator(const Operator *I,
break;
}
case Instruction::Call:
- case Instruction::Invoke:
+ case Instruction::Invoke: {
// If range metadata is attached to this call, set known bits from that,
// and then intersect with known bits based on other properties of the
// function.
if (MDNode *MD =
Q.IIQ.getMetadata(cast<Instruction>(I), LLVMContext::MD_range))
computeKnownBitsFromRangeMetadata(*MD, Known);
- if (const Value *RV = cast<CallBase>(I)->getReturnedArgOperand()) {
+
+ const CallBase *CB = cast<CallBase>(I);
+
+ const Attribute RangeAttr = CB->getRetAttr(llvm::Attribute::Range);
+ if (RangeAttr.isValid())
+ Known = RangeAttr.getRange().toKnownBits();
----------------
nikic wrote:
```suggestion
const Attribute RangeAttr = CB->getRetAttr(llvm::Attribute::Range);
if (std::optional<ConstantRange> Range = CB->getRange())
Known = Range->toKnownBits();
```
I'd suggest adding a small wrapper for this, given how often we're going to repeat it...
https://github.com/llvm/llvm-project/pull/85143
More information about the llvm-commits
mailing list