1; Test for PR45393: Two virtual functions that return unique i1 values 2; in the same vtable. Both calls are optimized to a comparison of 3; this's vptr against the address of the vtable. When nesting these 4; checks, LLVM would previously assume the nested check always fails, 5; but that assumption does not hold if both checks refer to the same vtable. 6; This tests checks that this case is handled correctly. 7; 8; RUN: opt -S -wholeprogramdevirt -wholeprogramdevirt-summary-action=import \ 9; RUN: -wholeprogramdevirt-read-summary=%p/Inputs/unique-retval-same-vtable.yaml \ 10; RUN: -O2 -o - %s | FileCheck %s 11; 12; Check that C::f() contains both possible return values. 13; CHECK-LABEL: define {{.*}} @_ZNK1C1fEv 14; CHECK-NOT: } 15; CHECK: 20074028 16; CHECK-NOT: } 17; CHECK: 1008434 18 19target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 20target triple = "x86_64-unknown-linux-gnu" 21 22%class.C = type { i32 (...)** } 23 24define hidden i32 @_ZNK1C1fEv(%class.C* %this) { 25entry: 26 %0 = bitcast %class.C* %this to i1 (%class.C*)*** 27 %vtable = load i1 (%class.C*)**, i1 (%class.C*)*** %0 28 %1 = bitcast i1 (%class.C*)** %vtable to i8* 29 %2 = tail call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1C") 30 tail call void @llvm.assume(i1 %2) 31 %vfn = getelementptr inbounds i1 (%class.C*)*, i1 (%class.C*)** %vtable, i64 2 32 %3 = load i1 (%class.C*)*, i1 (%class.C*)** %vfn 33 %call = tail call zeroext i1 %3(%class.C* %this) 34 br i1 %call, label %if.then, label %return 35 36if.then: 37 %vtable2 = load i1 (%class.C*)**, i1 (%class.C*)*** %0 38 %4 = bitcast i1 (%class.C*)** %vtable2 to i8* 39 %5 = tail call i1 @llvm.type.test(i8* %4, metadata !"_ZTS1C") 40 tail call void @llvm.assume(i1 %5) 41 %vfn3 = getelementptr inbounds i1 (%class.C*)*, i1 (%class.C*)** %vtable2, i64 3 42 %6 = load i1 (%class.C*)*, i1 (%class.C*)** %vfn3 43 ; The method being called here and the method being called before 44 ; the branch above both return true in the same vtable and only that 45 ; vtable. Therefore, if this call is reached, we must select 46 ; 20074028. Earlier versions of LLVM mistakenly concluded that 47 ; this code *never* selects 200744028. 48 %call4 = tail call zeroext i1 %6(%class.C* nonnull %this) 49 %. = select i1 %call4, i32 20074028, i32 3007762 50 br label %return 51 52return: 53 %retval.0 = phi i32 [ %., %if.then ], [ 1008434, %entry ] 54 ret i32 %retval.0 55} 56 57declare i1 @llvm.type.test(i8*, metadata) 58 59declare void @llvm.assume(i1) 60