aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/InlineFunction.cpp
diff options
context:
space:
mode:
authorAndreas Jonson <andjo403@hotmail.com>2024-05-29 12:05:05 +0200
committerGitHub <noreply@github.com>2024-05-29 12:05:05 +0200
commit5c214eb0c628c874f2c9496e663be4067e64442a (patch)
tree4db842bba832cb1bd7f51b47765e36c16c2589c0 /llvm/lib/Transforms/Utils/InlineFunction.cpp
parente1aa8ad6faa1524f12338ca58d1eadfde6f29f34 (diff)
downloadllvm-5c214eb0c628c874f2c9496e663be4067e64442a.zip
llvm-5c214eb0c628c874f2c9496e663be4067e64442a.tar.gz
llvm-5c214eb0c628c874f2c9496e663be4067e64442a.tar.bz2
[Inline] Clone return range attribute on the callsite into inlined call (#92666)
Diffstat (limited to 'llvm/lib/Transforms/Utils/InlineFunction.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index 7b846f2..eb471b2 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -30,11 +30,12 @@
#include "llvm/Analysis/ProfileSummaryInfo.h"
#include "llvm/Analysis/ValueTracking.h"
#include "llvm/Analysis/VectorUtils.h"
-#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/Argument.h"
+#include "llvm/IR/AttributeMask.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/CFG.h"
#include "llvm/IR/Constant.h"
+#include "llvm/IR/ConstantRange.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DebugInfo.h"
@@ -1450,6 +1451,8 @@ static AttrBuilder IdentifyValidPoisonGeneratingAttributes(CallBase &CB) {
Valid.addAttribute(Attribute::NonNull);
if (CB.hasRetAttr(Attribute::Alignment))
Valid.addAlignmentAttr(CB.getRetAlign());
+ if (std::optional<ConstantRange> Range = CB.getRange())
+ Valid.addRangeAttr(*Range);
return Valid;
}
@@ -1541,6 +1544,14 @@ static void AddReturnAttributes(CallBase &CB, ValueToValueMapTy &VMap) {
if (ValidPG.getAlignment().valueOrOne() < AL.getRetAlignment().valueOrOne())
ValidPG.removeAttribute(Attribute::Alignment);
if (ValidPG.hasAttributes()) {
+ Attribute CBRange = ValidPG.getAttribute(Attribute::Range);
+ if (CBRange.isValid()) {
+ Attribute NewRange = AL.getRetAttr(Attribute::Range);
+ if (NewRange.isValid()) {
+ ValidPG.addRangeAttr(
+ CBRange.getRange().intersectWith(NewRange.getRange()));
+ }
+ }
// Three checks.
// If the callsite has `noundef`, then a poison due to violating the
// return attribute will create UB anyways so we can always propagate.