1 ; RUN: opt -S -gvn-hoist < %s | FileCheck %s
3 ; Checking gvn-hoist in case of infinite loops and irreducible control flow.
5 ; Check that bitcast is not hoisted beacuse down safety is not guaranteed.
14 %class.bar = type { i8*, %class.base* }
15 %class.base = type { i32 (...)** }
17 ; Function Attrs: noreturn nounwind uwtable
18 define void @bazv1() local_unnamed_addr {
20 %agg.tmp = alloca %class.bar, align 8
21 %x.sroa.2.0..sroa_idx2 = getelementptr inbounds %class.bar, %class.bar* %agg.tmp, i64 0, i32 1
22 store %class.base* null, %class.base** %x.sroa.2.0..sroa_idx2, align 8
23 call void @_Z3foo3bar(%class.bar* nonnull %agg.tmp)
24 %0 = load %class.base*, %class.base** %x.sroa.2.0..sroa_idx2, align 8
25 %1 = bitcast %class.bar* %agg.tmp to %class.base*
26 %cmp.i = icmp eq %class.base* %0, %1
27 br i1 %cmp.i, label %if.then.i, label %if.else.i
29 if.then.i: ; preds = %entry
30 %2 = bitcast %class.base* %0 to void (%class.base*)***
31 %vtable.i = load void (%class.base*)**, void (%class.base*)*** %2, align 8
32 %vfn.i = getelementptr inbounds void (%class.base*)*, void (%class.base*)** %vtable.i, i64 2
33 %3 = load void (%class.base*)*, void (%class.base*)** %vfn.i, align 8
34 call void %3(%class.base* %0)
35 br label %while.cond.preheader
37 if.else.i: ; preds = %entry
38 %tobool.i = icmp eq %class.base* %0, null
39 br i1 %tobool.i, label %while.cond.preheader, label %if.then4.i
41 if.then4.i: ; preds = %if.else.i
42 %4 = bitcast %class.base* %0 to void (%class.base*)***
43 %vtable6.i = load void (%class.base*)**, void (%class.base*)*** %4, align 8
44 %vfn7.i = getelementptr inbounds void (%class.base*)*, void (%class.base*)** %vtable6.i, i64 3
45 %5 = load void (%class.base*)*, void (%class.base*)** %vfn7.i, align 8
46 call void %5(%class.base* nonnull %0)
47 br label %while.cond.preheader
49 while.cond.preheader: ; preds = %if.then.i, %if.else.i, %if.then4.i
52 while.cond: ; preds = %while.cond.preheader, %while.cond
53 %call = call i32 @sleep(i32 10)
57 declare void @_Z3foo3bar(%class.bar*) local_unnamed_addr
59 declare i32 @sleep(i32) local_unnamed_addr
61 ; Check that the load is hoisted even if it is inside an irreducible control flow
62 ; because the load is anticipable on all paths.
71 %agg.tmp = alloca %class.bar, align 8
72 %x= getelementptr inbounds %class.bar, %class.bar* %agg.tmp, i64 0, i32 1
73 %0 = load %class.base*, %class.base** %x, align 8
74 %1 = bitcast %class.bar* %agg.tmp to %class.base*
75 %cmp.i = icmp eq %class.base* %0, %1
76 br i1 %cmp.i, label %bb1, label %bb4
79 %b1 = bitcast %class.base* %0 to void (%class.base*)***
80 %i = load void (%class.base*)**, void (%class.base*)*** %b1, align 8
81 %vfn.i = getelementptr inbounds void (%class.base*)*, void (%class.base*)** %i, i64 2
82 %cmp.j = icmp eq %class.base* %0, %1
83 br i1 %cmp.j, label %bb2, label %bb3
86 %l1 = load void (%class.base*)*, void (%class.base*)** %vfn.i, align 8
90 %l2 = load void (%class.base*)*, void (%class.base*)** %vfn.i, align 8
94 %b2 = bitcast %class.base* %0 to void (%class.base*)***