1 ; Make sure this doesn't turn into an infinite loop
3 ; RUN: opt < %s -simplifycfg -simplifycfg-require-and-preserve-domtree=1 -instsimplify -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | llvm-dis | FileCheck %s
5 %struct.anon = type { i32, i32, i32, i32, [1024 x i8] }
6 @_zero_ = external global %struct.anon* ; <%struct.anon**> [#uses=2]
7 @_one_ = external global %struct.anon* ; <%struct.anon**> [#uses=4]
8 @str = internal constant [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=0]
10 declare i32 @bc_compare(%struct.anon*, %struct.anon*)
12 declare void @free_num(%struct.anon**)
14 declare %struct.anon* @copy_num(%struct.anon*)
16 declare void @init_num(%struct.anon**)
18 declare %struct.anon* @new_num(i32, i32)
20 declare void @int2num(%struct.anon**, i32)
22 declare void @bc_multiply(%struct.anon*, %struct.anon*, %struct.anon**, i32)
24 declare void @bc_raise(%struct.anon*, %struct.anon*, %struct.anon**, i32)
26 declare i32 @bc_divide(%struct.anon*, %struct.anon*, %struct.anon**, i32)
28 declare void @bc_add(%struct.anon*, %struct.anon*, %struct.anon**)
30 declare i32 @_do_compare(%struct.anon*, %struct.anon*, i32, i32)
32 declare i32 @printf(i8*, ...)
34 define i32 @bc_sqrt(%struct.anon** %num, i32 %scale) {
36 %guess = alloca %struct.anon* ; <%struct.anon**> [#uses=7]
37 %guess1 = alloca %struct.anon* ; <%struct.anon**> [#uses=7]
38 %point5 = alloca %struct.anon* ; <%struct.anon**> [#uses=3]
39 %tmp = load %struct.anon*, %struct.anon** %num ; <%struct.anon*> [#uses=1]
40 %tmp1 = load %struct.anon*, %struct.anon** @_zero_ ; <%struct.anon*> [#uses=1]
41 %tmp.upgrd.1 = call i32 @bc_compare( %struct.anon* %tmp, %struct.anon* %tmp1 ) ; <i32> [#uses=2]
42 %tmp.upgrd.2 = icmp slt i32 %tmp.upgrd.1, 0 ; <i1> [#uses=1]
43 br i1 %tmp.upgrd.2, label %cond_true, label %cond_false
44 cond_true: ; preds = %entry
46 cond_false: ; preds = %entry
47 %tmp5 = icmp eq i32 %tmp.upgrd.1, 0 ; <i1> [#uses=1]
48 br i1 %tmp5, label %cond_true6, label %cond_next13
49 cond_true6: ; preds = %cond_false
50 call void @free_num( %struct.anon** %num )
51 %tmp8 = load %struct.anon*, %struct.anon** @_zero_ ; <%struct.anon*> [#uses=1]
52 %tmp9 = call %struct.anon* @copy_num( %struct.anon* %tmp8 ) ; <%struct.anon*> [#uses=1]
53 store %struct.anon* %tmp9, %struct.anon** %num
55 cond_next13: ; preds = %cond_false
56 %tmp15 = load %struct.anon*, %struct.anon** %num ; <%struct.anon*> [#uses=1]
57 %tmp16 = load %struct.anon*, %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
58 %tmp17 = call i32 @bc_compare( %struct.anon* %tmp15, %struct.anon* %tmp16 ) ; <i32> [#uses=2]
59 %tmp19 = icmp eq i32 %tmp17, 0 ; <i1> [#uses=1]
60 br i1 %tmp19, label %cond_true20, label %cond_next27
61 cond_true20: ; preds = %cond_next13
62 call void @free_num( %struct.anon** %num )
63 %tmp22 = load %struct.anon*, %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
64 %tmp23 = call %struct.anon* @copy_num( %struct.anon* %tmp22 ) ; <%struct.anon*> [#uses=1]
65 store %struct.anon* %tmp23, %struct.anon** %num
67 cond_next27: ; preds = %cond_next13
68 %tmp29 = load %struct.anon*, %struct.anon** %num ; <%struct.anon*> [#uses=1]
69 %tmp30 = getelementptr %struct.anon, %struct.anon* %tmp29, i32 0, i32 2 ; <i32*> [#uses=1]
70 %tmp31 = load i32, i32* %tmp30 ; <i32> [#uses=2]
71 %tmp33 = icmp sge i32 %tmp31, %scale ; <i1> [#uses=1]
72 %max = select i1 %tmp33, i32 %tmp31, i32 %scale ; <i32> [#uses=4]
73 %tmp35 = add i32 %max, 2 ; <i32> [#uses=0]
74 call void @init_num( %struct.anon** %guess )
75 call void @init_num( %struct.anon** %guess1 )
76 %tmp36 = call %struct.anon* @new_num( i32 1, i32 1 ) ; <%struct.anon*> [#uses=2]
77 store %struct.anon* %tmp36, %struct.anon** %point5
78 %tmp.upgrd.3 = getelementptr %struct.anon, %struct.anon* %tmp36, i32 0, i32 4, i32 1 ; <i8*> [#uses=1]
79 store i8 5, i8* %tmp.upgrd.3
80 %tmp39 = icmp slt i32 %tmp17, 0 ; <i1> [#uses=1]
81 br i1 %tmp39, label %cond_true40, label %cond_false43
82 cond_true40: ; preds = %cond_next27
83 %tmp41 = load %struct.anon*, %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
84 %tmp42 = call %struct.anon* @copy_num( %struct.anon* %tmp41 ) ; <%struct.anon*> [#uses=1]
85 store %struct.anon* %tmp42, %struct.anon** %guess
87 cond_false43: ; preds = %cond_next27
88 call void @int2num( %struct.anon** %guess, i32 10 )
89 %tmp45 = load %struct.anon*, %struct.anon** %num ; <%struct.anon*> [#uses=1]
90 %tmp46 = getelementptr %struct.anon, %struct.anon* %tmp45, i32 0, i32 1 ; <i32*> [#uses=1]
91 %tmp47 = load i32, i32* %tmp46 ; <i32> [#uses=1]
92 call void @int2num( %struct.anon** %guess1, i32 %tmp47 )
93 %tmp48 = load %struct.anon*, %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
94 %tmp49 = load %struct.anon*, %struct.anon** %point5 ; <%struct.anon*> [#uses=1]
95 call void @bc_multiply( %struct.anon* %tmp48, %struct.anon* %tmp49, %struct.anon** %guess1, i32 %max )
96 %tmp51 = load %struct.anon*, %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
97 %tmp52 = getelementptr %struct.anon, %struct.anon* %tmp51, i32 0, i32 2 ; <i32*> [#uses=1]
98 store i32 0, i32* %tmp52
99 %tmp53 = load %struct.anon*, %struct.anon** %guess ; <%struct.anon*> [#uses=1]
100 %tmp54 = load %struct.anon*, %struct.anon** %guess1 ; <%struct.anon*> [#uses=1]
101 call void @bc_raise( %struct.anon* %tmp53, %struct.anon* %tmp54, %struct.anon** %guess, i32 %max )
103 bb80.outer: ; preds = %cond_true83, %cond_false43, %cond_true40
104 %done.1.ph = phi i32 [ 1, %cond_true83 ], [ 0, %cond_true40 ], [ 0, %cond_false43 ] ; <i32> [#uses=1]
106 bb80: ; preds = %cond_true83, %bb80.outer
107 %tmp82 = icmp eq i32 %done.1.ph, 0 ; <i1> [#uses=1]
108 br i1 %tmp82, label %cond_true83, label %bb86
109 cond_true83: ; preds = %bb80
110 %tmp71 = call i32 @_do_compare( %struct.anon* null, %struct.anon* null, i32 0, i32 1 ) ; <i32> [#uses=1]
111 %tmp76 = icmp eq i32 %tmp71, 0 ; <i1> [#uses=1]
112 br i1 %tmp76, label %bb80.outer, label %bb80
114 bb86: ; preds = %bb80
115 call void @free_num( %struct.anon** %num )
116 %tmp88 = load %struct.anon*, %struct.anon** %guess ; <%struct.anon*> [#uses=1]
117 %tmp89 = load %struct.anon*, %struct.anon** @_one_ ; <%struct.anon*> [#uses=1]
118 %tmp92 = call i32 @bc_divide( %struct.anon* %tmp88, %struct.anon* %tmp89, %struct.anon** %num, i32 %max ) ; <i32> [#uses=0]
119 call void @free_num( %struct.anon** %guess )
120 call void @free_num( %struct.anon** %guess1 )
121 call void @free_num( %struct.anon** %point5 )