diff options
author | Andreas Jonson <andjo403@hotmail.com> | 2024-04-04 08:48:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 14:48:11 +0800 |
commit | d4cd65ecf2546e509f43363f96364c976f49b9da (patch) | |
tree | a87e789375e460c7c44fd3be9fa5767042d7609b /llvm/lib/Analysis | |
parent | 4f19f15a601a5761b12c9c66d99d97dbc89ef90d (diff) | |
download | llvm-d4cd65ecf2546e509f43363f96364c976f49b9da.zip llvm-d4cd65ecf2546e509f43363f96364c976f49b9da.tar.gz llvm-d4cd65ecf2546e509f43363f96364c976f49b9da.tar.bz2 |
[LVI] Handle range attributes (#86413)
This adds handling of range attribute for return values of Call and
Invoke in getFromRangeMetadata and handling of argument with range
attribute in solveBlockValueNonLocal.
There is one additional check of the range metadata at line 1120 in
getValueFromSimpleICmpCondition that is not covered in this PR as after
https://github.com/llvm/llvm-project/pull/75311 there is no test that
cover that check any more and I have not been able to create a test that
trigger that code.
Diffstat (limited to 'llvm/lib/Analysis')
-rw-r--r-- | llvm/lib/Analysis/LazyValueInfo.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index b8bc811..6cded82 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -588,10 +588,14 @@ LazyValueInfoImpl::getBlockValue(Value *Val, BasicBlock *BB, static ValueLatticeElement getFromRangeMetadata(Instruction *BBI) { switch (BBI->getOpcode()) { - default: break; - case Instruction::Load: + default: + break; case Instruction::Call: case Instruction::Invoke: + if (std::optional<ConstantRange> Range = cast<CallBase>(BBI)->getRange()) + return ValueLatticeElement::getRange(*Range); + [[fallthrough]]; + case Instruction::Load: if (MDNode *Ranges = BBI->getMetadata(LLVMContext::MD_range)) if (isa<IntegerType>(BBI->getType())) { return ValueLatticeElement::getRange( @@ -706,10 +710,11 @@ std::optional<ValueLatticeElement> LazyValueInfoImpl::solveBlockValueNonLocal(Value *Val, BasicBlock *BB) { ValueLatticeElement Result; // Start Undefined. - // If this is the entry block, we must be asking about an argument. The - // value is overdefined. + // If this is the entry block, we must be asking about an argument. if (BB->isEntryBlock()) { assert(isa<Argument>(Val) && "Unknown live-in to the entry block"); + if (std::optional<ConstantRange> Range = cast<Argument>(Val)->getRange()) + return ValueLatticeElement::getRange(*Range); return ValueLatticeElement::getOverdefined(); } |