[llvm] [SDAG] Handle range attribute for call instructions. (PR #108410)
Andreas Jonson via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 08:41:13 PDT 2024
https://github.com/andjo403 created https://github.com/llvm/llvm-project/pull/108410
Possible way to handle range attribute on Intrinsic in SDAG by creating a MDNode when needed instead of adding a constRange to MachineMemOperand to save memory.
There is no test that have ranges on the Intrinsic where getRangeMetadata is called and I can not find that the range is used for any of the Intrinsics so alternative is to not handle range attribute on them until there is a usage.
>From 45fefd9ab910aa2dcb20529ce1619c7bc71744a5 Mon Sep 17 00:00:00 2001
From: Andreas Jonson <andjo403 at hotmail.com>
Date: Thu, 12 Sep 2024 17:30:44 +0200
Subject: [PATCH] [SDAG] Handle range attribute for call instructions.
---
llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index 1dbcf8fd765101..ede29034964c4b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -4499,6 +4499,17 @@ static const MDNode *getRangeMetadata(const Instruction &I) {
// transforms that are known not to be poison-safe, such as folding logical
// and/or to bitwise and/or. For now, only transfer !range if !noundef is
// also present.
+ if (const auto *CB = dyn_cast<CallBase>(&I))
+ if (CB->hasRetAttr(Attribute::NoUndef))
+ if (std::optional<ConstantRange> CR = CB->getRange()) {
+ Metadata *Range[] = {ConstantAsMetadata::get(ConstantInt::get(
+ I.getContext(), CR->getLower())),
+ ConstantAsMetadata::get(ConstantInt::get(
+ I.getContext(), CR->getUpper()))};
+
+ return MDNode::get(I.getContext(), Range);
+ }
+
if (!I.hasMetadata(LLVMContext::MD_noundef))
return nullptr;
return I.getMetadata(LLVMContext::MD_range);
More information about the llvm-commits
mailing list