1 ; RUN: opt -early-cse -S < %s | FileCheck %s 2 ; Same as GVN/edge.ll, but updated to reflect EarlyCSE's less powerful 3 ; implementation. EarlyCSE currently doesn't exploit equality comparisons 4 ; against constants. 5 6 define i32 @f1(i32 %x) { 7 ; CHECK-LABEL: define i32 @f1( 8 bb0: 9 %cmp = icmp eq i32 %x, 0 10 br i1 %cmp, label %bb2, label %bb1 11 bb1: 12 br label %bb2 13 bb2: 14 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 15 %foo = add i32 %cond, %x 16 ret i32 %foo 17 ; CHECK: bb2: 18 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 19 } 20 21 define i32 @f2(i32 %x) { 22 ; CHECK-LABEL: define i32 @f2( 23 bb0: 24 %cmp = icmp ne i32 %x, 0 25 br i1 %cmp, label %bb1, label %bb2 26 bb1: 27 br label %bb2 28 bb2: 29 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 30 %foo = add i32 %cond, %x 31 ret i32 %foo 32 ; CHECK: bb2: 33 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 34 } 35 36 define i32 @f3(i32 %x) { 37 ; CHECK-LABEL: define i32 @f3( 38 bb0: 39 switch i32 %x, label %bb1 [ i32 0, label %bb2] 40 bb1: 41 br label %bb2 42 bb2: 43 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 44 %foo = add i32 %cond, %x 45 ret i32 %foo 46 ; CHECK: bb2: 47 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ] 48 } 49 50 declare void @g(i1) 51 define void @f4(i8 * %x) { 52 ; CHECK-LABEL: define void @f4( 53 bb0: 54 %y = icmp eq i8* null, %x 55 br i1 %y, label %bb2, label %bb1 56 bb1: 57 br label %bb2 58 bb2: 59 %zed = icmp eq i8* null, %x 60 call void @g(i1 %zed) 61 ; CHECK: call void @g(i1 %y) 62 ret void 63 } 64 65 define double @fcmp_oeq_not_zero(double %x, double %y) { 66 entry: 67 %cmp = fcmp oeq double %y, 2.0 68 br i1 %cmp, label %if, label %return 69 70 if: 71 %div = fdiv double %x, %y 72 br label %return 73 74 return: 75 %retval = phi double [ %div, %if ], [ %x, %entry ] 76 ret double %retval 77 78 ; CHECK-LABEL: define double @fcmp_oeq_not_zero( 79 ; CHECK: %div = fdiv double %x, %y 80 } 81 82 define double @fcmp_une_not_zero(double %x, double %y) { 83 entry: 84 %cmp = fcmp une double %y, 2.0 85 br i1 %cmp, label %return, label %else 86 87 else: 88 %div = fdiv double %x, %y 89 br label %return 90 91 return: 92 %retval = phi double [ %div, %else ], [ %x, %entry ] 93 ret double %retval 94 95 ; CHECK-LABEL: define double @fcmp_une_not_zero( 96 ; CHECK: %div = fdiv double %x, %y 97 } 98 99 ; PR22376 - We can't propagate zero constants because -0.0 100 ; compares equal to 0.0. If %y is -0.0 in this test case, 101 ; we would produce the wrong sign on the infinity return value. 102 define double @fcmp_oeq_zero(double %x, double %y) { 103 entry: 104 %cmp = fcmp oeq double %y, 0.0 105 br i1 %cmp, label %if, label %return 106 107 if: 108 %div = fdiv double %x, %y 109 br label %return 110 111 return: 112 %retval = phi double [ %div, %if ], [ %x, %entry ] 113 ret double %retval 114 115 ; CHECK-LABEL: define double @fcmp_oeq_zero( 116 ; CHECK: %div = fdiv double %x, %y 117 } 118 119 define double @fcmp_une_zero(double %x, double %y) { 120 entry: 121 %cmp = fcmp une double %y, -0.0 122 br i1 %cmp, label %return, label %else 123 124 else: 125 %div = fdiv double %x, %y 126 br label %return 127 128 return: 129 %retval = phi double [ %div, %else ], [ %x, %entry ] 130 ret double %retval 131 132 ; CHECK-LABEL: define double @fcmp_une_zero( 133 ; CHECK: %div = fdiv double %x, %y 134 } 135 136 ; We also cannot propagate a value if it's not a constant. 137 ; This is because the value could be 0.0 or -0.0. 138 139 define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) { 140 entry: 141 %z = fadd double %z1, %z2 142 %cmp = fcmp oeq double %y, %z 143 br i1 %cmp, label %if, label %return 144 145 if: 146 %div = fdiv double %x, %z 147 br label %return 148 149 return: 150 %retval = phi double [ %div, %if ], [ %x, %entry ] 151 ret double %retval 152 153 ; CHECK-LABEL: define double @fcmp_oeq_maybe_zero( 154 ; CHECK: %div = fdiv double %x, %z 155 } 156 157 define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) { 158 entry: 159 %z = fadd double %z1, %z2 160 %cmp = fcmp une double %y, %z 161 br i1 %cmp, label %return, label %else 162 163 else: 164 %div = fdiv double %x, %z 165 br label %return 166 167 return: 168 %retval = phi double [ %div, %else ], [ %x, %entry ] 169 ret double %retval 170 171 ; CHECK-LABEL: define double @fcmp_une_maybe_zero( 172 ; CHECK: %div = fdiv double %x, %z 173 } 174