[llvm] dad14d4 - [SCCP] Merge return range attributes (#105998)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 00:35:09 PDT 2024
Author: Pedro Lobo
Date: 2024-08-26T09:35:05+02:00
New Revision: dad14d4d729360c2db36745ae9d9cd9d2a6a8c37
URL: https://github.com/llvm/llvm-project/commit/dad14d4d729360c2db36745ae9d9cd9d2a6a8c37
DIFF: https://github.com/llvm/llvm-project/commit/dad14d4d729360c2db36745ae9d9cd9d2a6a8c37.diff
LOG: [SCCP] Merge return range attributes (#105998)
Take the intersection of the existing range attribute for the return
value and the inferred range.
Added:
llvm/test/Transforms/SCCP/ip-constant-ranges-intersection.ll
Modified:
llvm/lib/Transforms/IPO/SCCP.cpp
Removed:
################################################################################
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