1; RUN: opt < %s -instcombine -S | FileCheck %s 2; <rdar://problem/10889741> 3 4define void @func(double %r, double %g, double %b, double* %outH, double* %outS, double* %outL) nounwind uwtable ssp { 5bb: 6 %tmp = alloca double, align 8 7 %tmp1 = alloca double, align 8 8 %tmp2 = alloca double, align 8 9 store double %r, double* %tmp, align 8 10 store double %g, double* %tmp1, align 8 11 store double %b, double* %tmp2, align 8 12 %tmp3 = fcmp ogt double %r, %g 13 br i1 %tmp3, label %bb4, label %bb8 14 15bb4: ; preds = %bb 16 %tmp5 = fcmp ogt double %r, %b 17 br i1 %tmp5, label %bb6, label %bb7 18 19bb6: ; preds = %bb4 20 br label %bb12 21 22bb7: ; preds = %bb4 23 br label %bb12 24 25bb8: ; preds = %bb 26 %tmp9 = fcmp ogt double %g, %b 27 br i1 %tmp9, label %bb10, label %bb11 28 29bb10: ; preds = %bb8 30 br label %bb12 31 32bb11: ; preds = %bb8 33 br label %bb12 34 35bb12: ; preds = %bb11, %bb10, %bb7, %bb6 36 %max.0 = phi double* [ %tmp, %bb6 ], [ %tmp2, %bb7 ], [ %tmp1, %bb10 ], [ %tmp2, %bb11 ] 37; CHECK: %tmp13 = load double, double* %tmp, align 8 38; CHECK: %tmp14 = load double, double* %tmp1, align 8 39; CHECK: %tmp15 = fcmp olt double %tmp13, %tmp14 40 %tmp13 = load double, double* %tmp, align 8 41 %tmp14 = load double, double* %tmp1, align 8 42 %tmp15 = fcmp olt double %tmp13, %tmp14 43 br i1 %tmp15, label %bb16, label %bb21 44 45bb16: ; preds = %bb12 46 %tmp17 = load double, double* %tmp2, align 8 47 %tmp18 = fcmp olt double %tmp13, %tmp17 48 br i1 %tmp18, label %bb19, label %bb20 49 50bb19: ; preds = %bb16 51 br label %bb26 52 53bb20: ; preds = %bb16 54 br label %bb26 55 56bb21: ; preds = %bb12 57 %tmp22 = load double, double* %tmp2, align 8 58 %tmp23 = fcmp olt double %tmp14, %tmp22 59 br i1 %tmp23, label %bb24, label %bb25 60 61bb24: ; preds = %bb21 62 br label %bb26 63 64bb25: ; preds = %bb21 65 br label %bb26 66 67bb26: ; preds = %bb25, %bb24, %bb20, %bb19 68 %min.0 = phi double* [ %tmp, %bb19 ], [ %tmp2, %bb20 ], [ %tmp1, %bb24 ], [ %tmp2, %bb25 ] 69; CHECK: %tmp27 = load double, double* %min.0, align 8 70; CHECK: %tmp28 = load double, double* %max.0 71; CHECK: %tmp29 = fadd double %tmp27, %tmp28 72 %tmp27 = load double, double* %min.0, align 8 73 %tmp28 = load double, double* %max.0 74 %tmp29 = fadd double %tmp27, %tmp28 75 %tmp30 = fdiv double %tmp29, 2.000000e+00 76 store double %tmp30, double* %outL 77 %tmp31 = load double, double* %min.0 78 %tmp32 = load double, double* %max.0 79 %tmp33 = fcmp oeq double %tmp31, %tmp32 80 br i1 %tmp33, label %bb34, label %bb35 81 82bb34: ; preds = %bb26 83 store double 0.000000e+00, double* %outS 84 store double 0.000000e+00, double* %outH 85 br label %bb81 86 87bb35: ; preds = %bb26 88 %tmp36 = fcmp olt double %tmp30, 5.000000e-01 89 %tmp37 = fsub double %tmp32, %tmp31 90 br i1 %tmp36, label %bb38, label %bb41 91 92bb38: ; preds = %bb35 93 %tmp39 = fadd double %tmp32, %tmp31 94 %tmp40 = fdiv double %tmp37, %tmp39 95 store double %tmp40, double* %outS 96 br label %bb45 97 98bb41: ; preds = %bb35 99 %tmp42 = fsub double 2.000000e+00, %tmp32 100 %tmp43 = fsub double %tmp42, %tmp31 101 %tmp44 = fdiv double %tmp37, %tmp43 102 store double %tmp44, double* %outS 103 br label %bb45 104 105bb45: ; preds = %bb41, %bb38 106 %tmp46 = icmp eq double* %max.0, %tmp 107 br i1 %tmp46, label %bb47, label %bb55 108 109bb47: ; preds = %bb45 110 %tmp48 = load double, double* %tmp1, align 8 111 %tmp49 = load double, double* %tmp2, align 8 112 %tmp50 = fsub double %tmp48, %tmp49 113 %tmp51 = load double, double* %max.0 114 %tmp52 = load double, double* %min.0 115 %tmp53 = fsub double %tmp51, %tmp52 116 %tmp54 = fdiv double %tmp50, %tmp53 117 store double %tmp54, double* %outH 118 br label %bb75 119 120bb55: ; preds = %bb45 121 %tmp56 = icmp eq double* %max.0, %tmp1 122 br i1 %tmp56, label %bb57, label %bb66 123 124bb57: ; preds = %bb55 125 %tmp58 = load double, double* %tmp2, align 8 126 %tmp59 = load double, double* %tmp, align 8 127 %tmp60 = fsub double %tmp58, %tmp59 128 %tmp61 = load double, double* %max.0 129 %tmp62 = load double, double* %min.0 130 %tmp63 = fsub double %tmp61, %tmp62 131 %tmp64 = fdiv double %tmp60, %tmp63 132 %tmp65 = fadd double 2.000000e+00, %tmp64 133 store double %tmp65, double* %outH 134 br label %bb75 135 136bb66: ; preds = %bb55 137 %tmp67 = load double, double* %tmp, align 8 138 %tmp68 = load double, double* %tmp1, align 8 139 %tmp69 = fsub double %tmp67, %tmp68 140 %tmp70 = load double, double* %max.0 141 %tmp71 = load double, double* %min.0 142 %tmp72 = fsub double %tmp70, %tmp71 143 %tmp73 = fdiv double %tmp69, %tmp72 144 %tmp74 = fadd double 4.000000e+00, %tmp73 145 store double %tmp74, double* %outH 146 br label %bb75 147 148bb75: ; preds = %bb66, %bb57, %bb47 149 %tmp76 = load double, double* %outH 150 %tmp77 = fdiv double %tmp76, 6.000000e+00 151 store double %tmp77, double* %outH 152 %tmp78 = fcmp olt double %tmp77, 0.000000e+00 153 br i1 %tmp78, label %bb79, label %bb81 154 155bb79: ; preds = %bb75 156 %tmp80 = fadd double %tmp77, 1.000000e+00 157 store double %tmp80, double* %outH 158 br label %bb81 159 160bb81: ; preds = %bb79, %bb75, %bb34 161 ret void 162} 163