[llvm] Use range attribute to constant fold comparisons with constant values. (PR #84627)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Mar 9 07:32:17 PST 2024
================
@@ -3729,6 +3729,19 @@ static Value *simplifyICmpWithIntrinsicOnLHS(CmpInst::Predicate Pred,
}
}
+/// Helper method to get range from metadata or attribute.
+static std::optional<ConstantRange> getRange(Value *V,
+ const InstrInfoQuery &IIQ) {
+ if (Instruction *I = dyn_cast<Instruction>(V))
+ if (MDNode *MD = IIQ.getMetadata(I, LLVMContext::MD_range))
+ return getConstantRangeFromMetadata(*MD);
+ if (const Argument *A = dyn_cast<Argument>(V))
----------------
nikic wrote:
We should also check call return values.
Once full support is in place we should probably forbid use of !range of calls.
https://github.com/llvm/llvm-project/pull/84627
More information about the llvm-commits
mailing list