Files
clang-p2996/llvm/test/Transforms/GlobalSplit/basic.ll
Nikita Popov 0f46e31cfb [IR] Change representation of getelementptr inrange (#84341)
As part of the migration to ptradd
(https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699),
we need to change the representation of the `inrange` attribute, which
is used for vtable splitting.

Currently, inrange is specified as follows:

```
getelementptr inbounds ({ [4 x ptr], [4 x ptr] }, ptr @vt, i64 0, inrange i32 1, i64 2)
```

The `inrange` is placed on a GEP index, and all accesses must be "in
range" of that index. The new representation is as follows:

```
getelementptr inbounds inrange(-16, 16) ({ [4 x ptr], [4 x ptr] }, ptr @vt, i64 0, i32 1, i64 2)
```

This specifies which offsets are "in range" of the GEP result. The new
representation will continue working when canonicalizing to ptradd
representation:

```
getelementptr inbounds inrange(-16, 16) (i8, ptr @vt, i64 48)
```

The inrange offsets are relative to the return value of the GEP. An
alternative design could make them relative to the source pointer
instead. The result-relative format was chosen on the off-chance that we
want to extend support to non-constant GEPs in the future, in which case
this variant is more expressive.

This implementation "upgrades" the old inrange representation in bitcode
by simply dropping it. This is a very niche feature, and I don't think
trying to upgrade it is worthwhile. Let me know if you disagree.
2024-03-20 10:59:45 +01:00

65 lines
2.3 KiB
LLVM

; RUN: opt -S -passes=globalsplit %s | FileCheck %s
target datalayout = "e-p:64:64"
target triple = "x86_64-unknown-linux-gnu"
; CHECK: @vtt = constant [3 x ptr] [ptr @global.0, ptr getelementptr inbounds (i8, ptr @global.0, i64 8), ptr @global.1]
@vtt = constant [3 x ptr] [
ptr getelementptr inrange(0, 16) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 0, i32 0),
ptr getelementptr inrange(-8, 8) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 0, i32 1),
ptr getelementptr inrange(0, 8) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 1, i32 0)
]
; CHECK-NOT: @global =
; CHECK: @global.0 = private constant [2 x ptr] [ptr @f1, ptr @f2], !type [[T1:![0-9]+]], !type [[T2:![0-9]+]], !type [[T3:![0-9]+]], !vcall_visibility [[VIS:![0-9]+]]{{$}}
; CHECK: @global.1 = private constant [1 x ptr] [ptr @f3], !type [[T4:![0-9]+]], !type [[T5:![0-9]+]], !vcall_visibility [[VIS]]{{$}}
; CHECK-NOT: @global =
@global = internal constant { [2 x ptr], [1 x ptr] } {
[2 x ptr] [ptr @f1, ptr @f2],
[1 x ptr] [ptr @f3]
}, !type !0, !type !1, !type !2, !type !3, !type !4, !vcall_visibility !5
; CHECK: define ptr @f1()
define ptr @f1() {
; CHECK-NEXT: ret ptr @global.0
ret ptr getelementptr inrange(0, 16) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 0, i32 0)
}
; CHECK: define ptr @f2()
define ptr @f2() {
; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @global.0, i64 8)
ret ptr getelementptr inrange(-8, 8) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 0, i32 1)
}
; CHECK: define ptr @f3()
define ptr @f3() {
; CHECK-NEXT: ret ptr getelementptr (i8, ptr @global.0, i64 16)
ret ptr getelementptr inrange(-16, 0) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 0, i32 2)
}
; CHECK: define ptr @f4()
define ptr @f4() {
; CHECK-NEXT: ret ptr @global.1
ret ptr getelementptr inrange(0, 8) ({ [2 x ptr], [1 x ptr] }, ptr @global, i32 0, i32 1, i32 0)
}
define void @foo() {
%p = call i1 @llvm.type.test(ptr null, metadata !"")
ret void
}
declare i1 @llvm.type.test(ptr, metadata) nounwind readnone
; CHECK: [[T1]] = !{i32 0, !"foo"}
; CHECK: [[T2]] = !{i32 15, !"bar"}
; CHECK: [[T3]] = !{i32 16, !"a"}
; CHECK: [[VIS]] = !{i64 2}
; CHECK: [[T4]] = !{i32 1, !"b"}
; CHECK: [[T5]] = !{i32 8, !"c"}
!0 = !{i32 0, !"foo"}
!1 = !{i32 15, !"bar"}
!2 = !{i32 16, !"a"}
!3 = !{i32 17, !"b"}
!4 = !{i32 24, !"c"}
!5 = !{i64 2}