Skip to content

Commit 45fefd9

Browse files
committed
[SDAG] Handle range attribute for call instructions.
1 parent 43fd2c4 commit 45fefd9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,6 +4499,17 @@ static const MDNode *getRangeMetadata(const Instruction &I) {
44994499
// transforms that are known not to be poison-safe, such as folding logical
45004500
// and/or to bitwise and/or. For now, only transfer !range if !noundef is
45014501
// also present.
4502+
if (const auto *CB = dyn_cast<CallBase>(&I))
4503+
if (CB->hasRetAttr(Attribute::NoUndef))
4504+
if (std::optional<ConstantRange> CR = CB->getRange()) {
4505+
Metadata *Range[] = {ConstantAsMetadata::get(ConstantInt::get(
4506+
I.getContext(), CR->getLower())),
4507+
ConstantAsMetadata::get(ConstantInt::get(
4508+
I.getContext(), CR->getUpper()))};
4509+
4510+
return MDNode::get(I.getContext(), Range);
4511+
}
4512+
45024513
if (!I.hasMetadata(LLVMContext::MD_noundef))
45034514
return nullptr;
45044515
return I.getMetadata(LLVMContext::MD_range);

0 commit comments

Comments
 (0)