Skip to content

Commit dad14d4

Browse files
authored
[SCCP] Merge return range attributes (#105998)
Take the intersection of the existing range attribute for the return value and the inferred range.
1 parent 2e9cbb6 commit dad14d4

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

llvm/lib/Transforms/IPO/SCCP.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,12 +289,10 @@ static bool runIPSCCP(
289289
if (ReturnValue.isConstantRangeIncludingUndef())
290290
continue;
291291

292-
// Do not touch existing attribute for now.
293-
// TODO: We should be able to take the intersection of the existing
294-
// attribute and the inferred range.
292+
// Take the intersection of the existing attribute and the inferred range.
293+
ConstantRange CR = ReturnValue.getConstantRange();
295294
if (F->hasRetAttribute(Attribute::Range))
296-
continue;
297-
auto &CR = ReturnValue.getConstantRange();
295+
CR = CR.intersectWith(F->getRetAttribute(Attribute::Range).getRange());
298296
F->addRangeRetAttr(CR);
299297
continue;
300298
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=ipsccp -S | FileCheck %s
3+
4+
declare range(i32 0, 20) i32 @callee(i32)
5+
6+
define range(i32 10, 30) i32 @caller(i32 %x) {
7+
; CHECK-LABEL: define range(i32 10, 20) i32 @caller(
8+
; CHECK-SAME: i32 [[X:%.*]]) {
9+
; CHECK-NEXT: [[ENTRY:.*:]]
10+
; CHECK-NEXT: [[CALL:%.*]] = call range(i32 0, 20) i32 @callee()
11+
; CHECK-NEXT: ret i32 [[CALL]]
12+
;
13+
entry:
14+
%call = call range(i32 0, 20) i32 @callee()
15+
ret i32 %call
16+
}

0 commit comments

Comments
 (0)