File: unique-retval-same-vtable.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 (56 lines) | stat: -rw-r--r-- 2,148 bytes parent folder | download | duplicates (12)
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
; Test for PR45393: Two virtual functions that return unique i1 values
; in the same vtable. Both calls are optimized to a comparison of
; this's vptr against the address of the vtable. When nesting these
; checks, LLVM would previously assume the nested check always fails,
; but that assumption does not hold if both checks refer to the same vtable.
; This tests checks that this case is handled correctly.
;
; RUN: opt -S -passes='wholeprogramdevirt,default<O2>' -wholeprogramdevirt-summary-action=import \
; RUN:   -wholeprogramdevirt-read-summary=%p/Inputs/unique-retval-same-vtable.yaml \
; RUN:   -o - %s | FileCheck %s
;
; Check that C::f() contains both possible return values.
; CHECK-LABEL: define {{.*}} @_ZNK1C1fEv
; CHECK-NOT: }
; CHECK: 20074028
; CHECK-NOT: }
; CHECK: 1008434

target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%class.C = type { ptr }

define hidden i32 @_ZNK1C1fEv(ptr %this) {
entry:
  %vtable = load ptr, ptr %this
  %0 = tail call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1C")
  tail call void @llvm.assume(i1 %0)
  %vfn = getelementptr inbounds ptr, ptr %vtable, i64 2
  %1 = load ptr, ptr %vfn
  %call = tail call zeroext i1 %1(ptr %this)
  br i1 %call, label %if.then, label %return

if.then:
  %vtable2 = load ptr, ptr %this
  %2 = tail call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1C")
  tail call void @llvm.assume(i1 %2)
  %vfn3 = getelementptr inbounds ptr, ptr %vtable2, i64 3
  %3 = load ptr, ptr %vfn3
  ; The method being called here and the method being called before
  ; the branch above both return true in the same vtable and only that
  ; vtable. Therefore, if this call is reached, we must select
  ; 20074028. Earlier versions of LLVM mistakenly concluded that
  ; this code *never* selects 200744028.
  %call4 = tail call zeroext i1 %3(ptr nonnull %this)
  %. = select i1 %call4, i32 20074028, i32 3007762
  br label %return

return:
  %retval.0 = phi i32 [ %., %if.then ], [ 1008434, %entry ]
  ret i32 %retval.0
}

declare i1 @llvm.type.test(ptr, metadata)

declare void @llvm.assume(i1)