Files
clang-p2996/llvm/test/Transforms/MergeFunc/constexpr.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

87 lines
2.6 KiB
LLVM

; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals all --version 4
; RUN: opt -S -passes=mergefunc -mergefunc-use-aliases < %s | FileCheck %s
@g1 = external unnamed_addr global i8
@g2 = external unnamed_addr global i8
;.
; CHECK: @g1 = external unnamed_addr global i8
; CHECK: @g2 = external unnamed_addr global i8
;.
define i1 @f1() unnamed_addr {
; CHECK-LABEL: define i1 @f1() unnamed_addr {
; CHECK-NEXT: ret i1 icmp eq (ptr @g1, ptr @g2)
;
ret i1 icmp eq (ptr @g1, ptr @g2)
}
define i1 @f2() unnamed_addr {
; CHECK-LABEL: define i1 @f2() unnamed_addr {
; CHECK-NEXT: ret i1 icmp ne (ptr @g1, ptr @g2)
;
ret i1 icmp ne (ptr @g1, ptr @g2)
}
define ptr @f3() unnamed_addr {
; CHECK-LABEL: define ptr @f3() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr inbounds (i8, ptr @g1, i64 2)
;
ret ptr getelementptr inbounds (i8, ptr @g1, i64 2)
}
define ptr @f4() unnamed_addr {
; CHECK-LABEL: define ptr @f4() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr (i16, ptr @g1, i64 2)
;
ret ptr getelementptr (i16, ptr @g1, i64 2)
}
define ptr @f5() unnamed_addr {
; CHECK-LABEL: define ptr @f5() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr (i8, ptr @g1, i64 2)
;
ret ptr getelementptr (i8, ptr @g1, i64 2)
}
define i64 @f6() unnamed_addr {
; CHECK-LABEL: define i64 @f6() unnamed_addr {
; CHECK-NEXT: ret i64 add nuw (i64 ptrtoint (ptr @g1 to i64), i64 1)
;
ret i64 add nuw (i64 ptrtoint (ptr @g1 to i64), i64 1)
}
define i64 @f7() unnamed_addr {
; CHECK-LABEL: define i64 @f7() unnamed_addr {
; CHECK-NEXT: ret i64 add (i64 ptrtoint (ptr @g1 to i64), i64 1)
;
ret i64 add (i64 ptrtoint (ptr @g1 to i64), i64 1)
}
define i64 @f8() unnamed_addr {
; CHECK-LABEL: define i64 @f8() unnamed_addr {
; CHECK-NEXT: ret i64 sub (i64 ptrtoint (ptr @g1 to i64), i64 1)
;
ret i64 sub (i64 ptrtoint (ptr @g1 to i64), i64 1)
}
define ptr @f10() unnamed_addr {
; CHECK-LABEL: define ptr @f10() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr inrange(0, 4) ([4 x i32], ptr @g1, i64 0, i64 1)
;
ret ptr getelementptr inrange(0, 4) ([4 x i32], ptr @g1, i64 0, i64 1)
}
define ptr @f11() unnamed_addr {
; CHECK-LABEL: define ptr @f11() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr ([4 x i32], ptr @g1, i64 0, i64 1)
;
ret ptr getelementptr ([4 x i32], ptr @g1, i64 0, i64 1)
}
define ptr @f12() unnamed_addr {
; CHECK-LABEL: define ptr @f12() unnamed_addr {
; CHECK-NEXT: ret ptr getelementptr inrange(-4, 12) ([4 x i32], ptr @g1, i64 0, i64 1)
;
ret ptr getelementptr inrange(-4, 12) ([4 x i32], ptr @g1, i64 0, i64 1)
}