File: expand-check-relative.ll

package info (click to toggle)
llvm-toolchain-17 1%3A17.0.6-22
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,799,624 kB
  • sloc: cpp: 6,428,607; ansic: 1,383,196; asm: 793,408; python: 223,504; objc: 75,364; f90: 60,502; lisp: 33,869; pascal: 15,282; sh: 9,684; perl: 7,453; ml: 4,937; awk: 3,523; makefile: 2,889; javascript: 2,149; xml: 888; fortran: 619; 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()