175 lines · plain
1; RUN: opt -passes=early-cse -earlycse-debug-hash -S < %s | FileCheck %s2; RUN: opt -passes='early-cse<memssa>' -S < %s | FileCheck %s3; Same as GVN/edge.ll, but updated to reflect EarlyCSE's less powerful4; implementation. EarlyCSE currently doesn't exploit equality comparisons5; against constants.6 7define i32 @f1(i32 %x) {8 ; CHECK-LABEL: define i32 @f1(9bb0:10 %cmp = icmp eq i32 %x, 011 br i1 %cmp, label %bb2, label %bb112bb1:13 br label %bb214bb2:15 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]16 %foo = add i32 %cond, %x17 ret i32 %foo18 ; CHECK: bb2:19 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]20}21 22define i32 @f2(i32 %x) {23 ; CHECK-LABEL: define i32 @f2(24bb0:25 %cmp = icmp ne i32 %x, 026 br i1 %cmp, label %bb1, label %bb227bb1:28 br label %bb229bb2:30 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]31 %foo = add i32 %cond, %x32 ret i32 %foo33 ; CHECK: bb2:34 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]35}36 37define i32 @f3(i32 %x) {38 ; CHECK-LABEL: define i32 @f3(39bb0:40 switch i32 %x, label %bb1 [ i32 0, label %bb2]41bb1:42 br label %bb243bb2:44 %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]45 %foo = add i32 %cond, %x46 ret i32 %foo47 ; CHECK: bb2:48 ; CHECK: %cond = phi i32 [ %x, %bb0 ], [ 0, %bb1 ]49}50 51declare void @g(i1)52define void @f4(ptr %x) {53; CHECK-LABEL: define void @f4(54bb0:55 %y = icmp eq ptr null, %x56 br i1 %y, label %bb2, label %bb157bb1:58 br label %bb259bb2:60 %zed = icmp eq ptr null, %x61 call void @g(i1 %zed)62; CHECK: call void @g(i1 %y)63 ret void64}65 66define double @fcmp_oeq_not_zero(double %x, double %y) {67entry:68 %cmp = fcmp oeq double %y, 2.069 br i1 %cmp, label %if, label %return70 71if:72 %div = fdiv double %x, %y73 br label %return74 75return:76 %retval = phi double [ %div, %if ], [ %x, %entry ]77 ret double %retval78 79; CHECK-LABEL: define double @fcmp_oeq_not_zero(80; CHECK: %div = fdiv double %x, %y81}82 83define double @fcmp_une_not_zero(double %x, double %y) {84entry:85 %cmp = fcmp une double %y, 2.086 br i1 %cmp, label %return, label %else87 88else:89 %div = fdiv double %x, %y90 br label %return91 92return:93 %retval = phi double [ %div, %else ], [ %x, %entry ]94 ret double %retval95 96; CHECK-LABEL: define double @fcmp_une_not_zero(97; CHECK: %div = fdiv double %x, %y98}99 100; PR22376 - We can't propagate zero constants because -0.0 101; compares equal to 0.0. If %y is -0.0 in this test case,102; we would produce the wrong sign on the infinity return value.103define double @fcmp_oeq_zero(double %x, double %y) {104entry:105 %cmp = fcmp oeq double %y, 0.0106 br i1 %cmp, label %if, label %return107 108if:109 %div = fdiv double %x, %y110 br label %return111 112return:113 %retval = phi double [ %div, %if ], [ %x, %entry ]114 ret double %retval115 116; CHECK-LABEL: define double @fcmp_oeq_zero(117; CHECK: %div = fdiv double %x, %y118}119 120define double @fcmp_une_zero(double %x, double %y) {121entry:122 %cmp = fcmp une double %y, -0.0123 br i1 %cmp, label %return, label %else124 125else:126 %div = fdiv double %x, %y127 br label %return128 129return:130 %retval = phi double [ %div, %else ], [ %x, %entry ]131 ret double %retval132 133; CHECK-LABEL: define double @fcmp_une_zero(134; CHECK: %div = fdiv double %x, %y135}136 137; We also cannot propagate a value if it's not a constant.138; This is because the value could be 0.0 or -0.0.139 140define double @fcmp_oeq_maybe_zero(double %x, double %y, double %z1, double %z2) {141entry:142 %z = fadd double %z1, %z2143 %cmp = fcmp oeq double %y, %z144 br i1 %cmp, label %if, label %return145 146if:147 %div = fdiv double %x, %z148 br label %return149 150return:151 %retval = phi double [ %div, %if ], [ %x, %entry ]152 ret double %retval153 154; CHECK-LABEL: define double @fcmp_oeq_maybe_zero(155; CHECK: %div = fdiv double %x, %z156}157 158define double @fcmp_une_maybe_zero(double %x, double %y, double %z1, double %z2) {159entry:160 %z = fadd double %z1, %z2161 %cmp = fcmp une double %y, %z162 br i1 %cmp, label %return, label %else163 164else:165 %div = fdiv double %x, %z166 br label %return167 168return:169 %retval = phi double [ %div, %else ], [ %x, %entry ]170 ret double %retval171 172; CHECK-LABEL: define double @fcmp_une_maybe_zero(173; CHECK: %div = fdiv double %x, %z174}175