1 ; RUN: llc < %s -march=x86-64 | grep div | count 1 2 ; rdar://8168938 3 4 ; This testcase involves SCEV normalization with the exit value from 5 ; one loop involved with the increment value for an addrec on another 6 ; loop. The expression should be properly normalized and simplified, 7 ; and require only a single division. 8 9 %0 = type { %0*, %0* } 10 11 @0 = private constant [13 x i8] c"Result: %lu\0A\00" ; <[13 x i8]*> [#uses=1] 12 @1 = internal constant [5 x i8] c"Huh?\00" ; <[5 x i8]*> [#uses=1] 13 14 define i32 @main(i32 %arg, i8** nocapture %arg1) nounwind { 15 bb: 16 %tmp = alloca %0, align 8 ; <%0*> [#uses=11] 17 %tmp2 = bitcast %0* %tmp to i8* ; <i8*> [#uses=1] 18 call void @llvm.memset.p0i8.i64(i8* %tmp2, i8 0, i64 16, i32 8, i1 false) nounwind 19 %tmp3 = getelementptr inbounds %0* %tmp, i64 0, i32 0 ; <%0**> [#uses=3] 20 store %0* %tmp, %0** %tmp3 21 %tmp4 = getelementptr inbounds %0* %tmp, i64 0, i32 1 ; <%0**> [#uses=1] 22 store %0* %tmp, %0** %tmp4 23 %tmp5 = call noalias i8* @_Znwm(i64 24) nounwind ; <i8*> [#uses=2] 24 %tmp6 = getelementptr inbounds i8* %tmp5, i64 16 ; <i8*> [#uses=2] 25 %tmp7 = icmp eq i8* %tmp6, null ; <i1> [#uses=1] 26 br i1 %tmp7, label %bb10, label %bb8 27 28 bb8: ; preds = %bb 29 %tmp9 = bitcast i8* %tmp6 to i32* ; <i32*> [#uses=1] 30 store i32 1, i32* %tmp9 31 br label %bb10 32 33 bb10: ; preds = %bb8, %bb 34 %tmp11 = bitcast i8* %tmp5 to %0* ; <%0*> [#uses=1] 35 call void @_ZNSt15_List_node_base4hookEPS_(%0* %tmp11, %0* %tmp) nounwind 36 %tmp12 = load %0** %tmp3 ; <%0*> [#uses=3] 37 %tmp13 = icmp eq %0* %tmp12, %tmp ; <i1> [#uses=1] 38 br i1 %tmp13, label %bb14, label %bb16 39 40 bb14: ; preds = %bb10 41 %tmp15 = call i32 @puts(i8* getelementptr inbounds ([5 x i8]* @1, i64 0, i64 0)) 42 br label %bb35 43 44 bb16: ; preds = %bb16, %bb10 45 %tmp17 = phi i64 [ %tmp22, %bb16 ], [ 0, %bb10 ] ; <i64> [#uses=1] 46 %tmp18 = phi %0* [ %tmp20, %bb16 ], [ %tmp12, %bb10 ] ; <%0*> [#uses=1] 47 %tmp19 = getelementptr inbounds %0* %tmp18, i64 0, i32 0 ; <%0**> [#uses=1] 48 %tmp20 = load %0** %tmp19 ; <%0*> [#uses=2] 49 %tmp21 = icmp eq %0* %tmp20, %tmp ; <i1> [#uses=1] 50 %tmp22 = add i64 %tmp17, 1 ; <i64> [#uses=2] 51 br i1 %tmp21, label %bb23, label %bb16 52 53 bb23: ; preds = %bb16 54 %tmp24 = udiv i64 100, %tmp22 ; <i64> [#uses=1] 55 br label %bb25 56 57 bb25: ; preds = %bb25, %bb23 58 %tmp26 = phi i64 [ %tmp31, %bb25 ], [ 0, %bb23 ] ; <i64> [#uses=1] 59 %tmp27 = phi %0* [ %tmp29, %bb25 ], [ %tmp12, %bb23 ] ; <%0*> [#uses=1] 60 %tmp28 = getelementptr inbounds %0* %tmp27, i64 0, i32 0 ; <%0**> [#uses=1] 61 %tmp29 = load %0** %tmp28 ; <%0*> [#uses=2] 62 %tmp30 = icmp eq %0* %tmp29, %tmp ; <i1> [#uses=1] 63 %tmp31 = add i64 %tmp26, 1 ; <i64> [#uses=2] 64 br i1 %tmp30, label %bb32, label %bb25 65 66 bb32: ; preds = %bb25 67 %tmp33 = mul i64 %tmp31, %tmp24 ; <i64> [#uses=1] 68 %tmp34 = call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([13 x i8]* @0, i64 0, i64 0), i64 %tmp33) nounwind 69 br label %bb35 70 71 bb35: ; preds = %bb32, %bb14 72 %tmp36 = load %0** %tmp3 ; <%0*> [#uses=2] 73 %tmp37 = icmp eq %0* %tmp36, %tmp ; <i1> [#uses=1] 74 br i1 %tmp37, label %bb44, label %bb38 75 76 bb38: ; preds = %bb38, %bb35 77 %tmp39 = phi %0* [ %tmp41, %bb38 ], [ %tmp36, %bb35 ] ; <%0*> [#uses=2] 78 %tmp40 = getelementptr inbounds %0* %tmp39, i64 0, i32 0 ; <%0**> [#uses=1] 79 %tmp41 = load %0** %tmp40 ; <%0*> [#uses=2] 80 %tmp42 = bitcast %0* %tmp39 to i8* ; <i8*> [#uses=1] 81 call void @_ZdlPv(i8* %tmp42) nounwind 82 %tmp43 = icmp eq %0* %tmp41, %tmp ; <i1> [#uses=1] 83 br i1 %tmp43, label %bb44, label %bb38 84 85 bb44: ; preds = %bb38, %bb35 86 ret i32 0 87 } 88 89 declare i32 @printf(i8* nocapture, ...) nounwind 90 91 declare void @_ZNSt15_List_node_base4hookEPS_(%0*, %0*) 92 93 declare noalias i8* @_Znwm(i64) 94 95 declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind 96 97 declare void @_ZdlPv(i8*) nounwind 98 99 declare i32 @puts(i8* nocapture) nounwind 100