Skip to content

Commit 4377656

Browse files
authored
[Metadata] Try to merge the first and last ranges. (#101860)
Fixes #101859. If we have at least 2 ranges, we have to try to merge the last and first ones to handle the wrap range.
1 parent eccc648 commit 4377656

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/IR/Metadata.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,10 +1318,11 @@ MDNode *MDNode::getMostGenericRange(MDNode *A, MDNode *B) {
13181318
++BI;
13191319
}
13201320

1321-
// If we have more than 2 ranges (4 endpoints) we have to try to merge
1321+
// We haven't handled wrap in the previous merge,
1322+
// if we have at least 2 ranges (4 endpoints) we have to try to merge
13221323
// the last and first ones.
13231324
unsigned Size = EndPoints.size();
1324-
if (Size > 4) {
1325+
if (Size > 2) {
13251326
ConstantInt *FB = EndPoints[0];
13261327
ConstantInt *FE = EndPoints[1];
13271328
if (tryMergeRange(EndPoints, FB, FE)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt -passes=gvn -S < %s | FileCheck %s
3+
4+
define i8 @foo(ptr %arg, i8 %arg1) {
5+
; CHECK-LABEL: define i8 @foo(
6+
; CHECK-SAME: ptr [[ARG:%.*]], i8 [[ARG1:%.*]]) {
7+
; CHECK-NEXT: [[BB:.*:]]
8+
; CHECK-NEXT: [[I:%.*]] = load i8, ptr [[ARG]], align 1, !range [[RNG0:![0-9]+]]
9+
; CHECK-NEXT: [[I3:%.*]] = add i8 [[I]], [[I]]
10+
; CHECK-NEXT: ret i8 [[I3]]
11+
;
12+
bb:
13+
%i = load i8, ptr %arg, align 1, !range !{i8 127, i8 -20}
14+
%i2 = load i8, ptr %arg, align 1, !range !{i8 -27, i8 -24, i8 -20, i8 -17}
15+
%i3 = add i8 %i, %i2
16+
ret i8 %i3
17+
}
18+
;.
19+
; CHECK: [[RNG0]] = !{i8 127, i8 -17}
20+
;.

0 commit comments

Comments
 (0)