[llvm] [SCCP] Merge return range attributes (PR #105998)
Pedro Lobo via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 25 11:44:13 PDT 2024
https://github.com/pedroclobo updated https://github.com/llvm/llvm-project/pull/105998
>From 78527900efda3b81b0c71f9b22fefa559fff2998 Mon Sep 17 00:00:00 2001
From: Pedro Lobo <pedrocerqueiralobo at gmail.com>
Date: Sun, 25 Aug 2024 19:37:57 +0100
Subject: [PATCH] [SCCP] Merge range attributes
---
llvm/lib/Transforms/IPO/SCCP.cpp | 8 +++-----
.../SCCP/ip-constant-ranges-intersection.ll | 16 ++++++++++++++++
2 files changed, 19 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/Transforms/SCCP/ip-constant-ranges-intersection.ll
diff --git a/llvm/lib/Transforms/IPO/SCCP.cpp b/llvm/lib/Transforms/IPO/SCCP.cpp
index 94ae511b2e4a1e..6fa2724e0116ec 100644
--- a/llvm/lib/Transforms/IPO/SCCP.cpp
+++ b/llvm/lib/Transforms/IPO/SCCP.cpp
@@ -289,12 +289,10 @@ static bool runIPSCCP(
if (ReturnValue.isConstantRangeIncludingUndef())
continue;
- // Do not touch existing attribute for now.
- // TODO: We should be able to take the intersection of the existing
- // attribute and the inferred range.
+ // Take the intersection of the existing attribute and the inferred range.
+ ConstantRange CR = ReturnValue.getConstantRange();
if (F->hasRetAttribute(Attribute::Range))
- continue;
- auto &CR = ReturnValue.getConstantRange();
+ CR = CR.intersectWith(F->getRetAttribute(Attribute::Range).getRange());
F->addRangeRetAttr(CR);
continue;
}
diff --git a/llvm/test/Transforms/SCCP/ip-constant-ranges-intersection.ll b/llvm/test/Transforms/SCCP/ip-constant-ranges-intersection.ll
new file mode 100644
index 00000000000000..2e3fa627282d02
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/ip-constant-ranges-intersection.ll
@@ -0,0 +1,16 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
+
+declare range(i32 0, 20) i32 @callee(i32)
+
+define range(i32 10, 30) i32 @caller(i32 %x) {
+; CHECK-LABEL: define range(i32 10, 20) i32 @caller(
+; CHECK-SAME: i32 [[X:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: [[CALL:%.*]] = call range(i32 0, 20) i32 @callee()
+; CHECK-NEXT: ret i32 [[CALL]]
+;
+entry:
+ %call = call range(i32 0, 20) i32 @callee()
+ ret i32 %call
+}
More information about the llvm-commits
mailing list