1 ; RUN: opt -S -passes=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 { ptr, ptr }
15 %class.base = type { ptr }
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, ptr %agg.tmp, i64 0, i32 1
22 store ptr null, ptr %x.sroa.2.0..sroa_idx2, align 8
23 call void @_Z3foo3bar(ptr nonnull %agg.tmp)
24 %0 = load ptr, ptr %x.sroa.2.0..sroa_idx2, align 8
25 %1 = bitcast ptr %agg.tmp to ptr
26 %cmp.i = icmp eq ptr %0, %1
27 br i1 %cmp.i, label %if.then.i, label %if.else.i
29 if.then.i: ; preds = %entry
30 %2 = bitcast ptr %0 to ptr
31 %vtable.i = load ptr, ptr %2, align 8
32 %vfn.i = getelementptr inbounds ptr, ptr %vtable.i, i64 2
33 %3 = load ptr, ptr %vfn.i, align 8
35 br label %while.cond.preheader
37 if.else.i: ; preds = %entry
38 %tobool.i = icmp eq ptr %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 ptr %0 to ptr
43 %vtable6.i = load ptr, ptr %4, align 8
44 %vfn7.i = getelementptr inbounds ptr, ptr %vtable6.i, i64 3
45 %5 = load ptr, ptr %vfn7.i, align 8
46 call void %5(ptr 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(ptr) 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, ptr %agg.tmp, i64 0, i32 1
73 %0 = load ptr, ptr %x, align 8
74 %1 = bitcast ptr %agg.tmp to ptr
75 %cmp.i = icmp eq ptr %0, %1
76 br i1 %cmp.i, label %bb1, label %bb4
79 %b1 = bitcast ptr %0 to ptr
80 %i = load ptr, ptr %b1, align 8
81 %vfn.i = getelementptr inbounds ptr, ptr %i, i64 2
82 %cmp.j = icmp eq ptr %0, %1
83 br i1 %cmp.j, label %bb2, label %bb3
86 %l1 = load ptr, ptr %vfn.i, align 8
90 %l2 = load ptr, ptr %vfn.i, align 8
94 %b2 = bitcast ptr %0 to ptr