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