File: expand-check-relative.ll

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 1,998,492 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (58 lines) | stat: -rw-r--r-- 1,722 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
; RUN: opt -S -passes=wholeprogramdevirt %s | FileCheck %s

; Test that we correctly expand the llvm.type.checked.load.relative intrinsic in
; cases where we cannot devirtualize.

target datalayout = "e-p:64:64"
target triple = "x86_64-unknown-linux-gnu"

@vt1 = constant { [2 x i32] } { [2 x i32] [
  i32 trunc (i64 sub (i64 ptrtoint (ptr @vf1 to i64), i64 ptrtoint (ptr @vt1 to i64)) to i32),
  i32 trunc (i64 sub (i64 ptrtoint (ptr @vf2 to i64), i64 ptrtoint (ptr @vt1 to i64)) to i32)
]}, align 8, !type !0, !type !1

!0 = !{i64 0, !"vfunc1.type"}
!1 = !{i64 4, !"vfunc2.type"}


define void @vf1(ptr %this) {
  ret void
}

define void @vf2(ptr %this) {
  ret void
}

; CHECK: define void @call
; CHECK:  [[TT:%.*]] = call i1 @llvm.type.test(ptr [[VT:%.*]], metadata !"vfunc1.type")
; CHECK:  br i1 [[TT]]

; Relative pointer computation at the address of the i32 value to the i32 value
; to get to the pointer value.

; CHECK:  [[T0:%.*]] = getelementptr i8, ptr [[VT]], i32 0
; CHECK:  [[T1:%.*]] = load i32, ptr [[T0]]
; CHECK:  [[T2:%.*]] = sext i32 [[T1]] to i64
; CHECK:  [[T3:%.*]] = ptrtoint ptr [[T0]] to i64
; CHECK:  [[T4:%.*]] = add i64 [[T3]], [[T2]]
; CHECK:  [[F:%.*]] = inttoptr i64 [[T4]] to ptr
; CHECK:  call void [[F]](ptr

define void @call(ptr %obj) {
  %vtable = load ptr, ptr %obj
  %pair = call {ptr, i1} @llvm.type.checked.load.relative(ptr %vtable, i32 0, metadata !"vfunc1.type")
  %p = extractvalue {ptr, i1} %pair, 1
  br i1 %p, label %cont, label %trap

cont:
  %fptr = extractvalue {ptr, i1} %pair, 0
  call void %fptr(ptr %obj)
  ret void

trap:
  call void @llvm.trap()
  unreachable
}

declare {ptr, i1} @llvm.type.checked.load.relative(ptr, i32, metadata)
declare void @llvm.trap()