File: unique-retval-same-vtable.ll

package info (click to toggle)
llvm-toolchain-14 1%3A14.0.6-12
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,496,180 kB
  • sloc: cpp: 5,593,972; ansic: 986,872; asm: 585,869; python: 184,223; objc: 72,530; lisp: 31,119; f90: 27,793; javascript: 9,780; pascal: 9,762; sh: 9,482; perl: 7,468; ml: 5,432; awk: 3,523; makefile: 2,538; xml: 953; cs: 573; fortran: 567
file content (59 lines) | stat: -rw-r--r-- 2,458 bytes parent folder | download | duplicates (4)
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
59
; 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 { i32 (...)** }

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

if.then:
  %vtable2 = load i1 (%class.C*)**, i1 (%class.C*)*** %0
  %4 = bitcast i1 (%class.C*)** %vtable2 to i8*
  %5 = tail call i1 @llvm.type.test(i8* %4, metadata !"_ZTS1C")
  tail call void @llvm.assume(i1 %5)
  %vfn3 = getelementptr inbounds i1 (%class.C*)*, i1 (%class.C*)** %vtable2, i64 3
  %6 = load i1 (%class.C*)*, i1 (%class.C*)** %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 %6(%class.C* 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(i8*, metadata)

declare void @llvm.assume(i1)