1; NOTE: Assertions have been autogenerated by update_test_checks.py 2; RUN: opt < %s -instsimplify -S | FileCheck %s 3 4;; x * 0 ==> 0 when no-nans and no-signed-zero 5define float @mul_zero_1(float %a) { 6; CHECK-LABEL: @mul_zero_1( 7; CHECK: ret float 0.000000e+00 8; 9 %b = fmul nsz nnan float %a, 0.0 10 ret float %b 11} 12 13define float @mul_zero_2(float %a) { 14; CHECK-LABEL: @mul_zero_2( 15; CHECK: ret float 0.000000e+00 16; 17 %b = fmul fast float 0.0, %a 18 ret float %b 19} 20 21;; x * 0 =/=> 0 when there could be nans or -0 22define float @no_mul_zero_1(float %a) { 23; CHECK-LABEL: @no_mul_zero_1( 24; CHECK: [[B:%.*]] = fmul nsz float %a, 0.000000e+00 25; CHECK-NEXT: ret float [[B]] 26; 27 %b = fmul nsz float %a, 0.0 28 ret float %b 29} 30 31define float @no_mul_zero_2(float %a) { 32; CHECK-LABEL: @no_mul_zero_2( 33; CHECK: [[B:%.*]] = fmul nnan float %a, 0.000000e+00 34; CHECK-NEXT: ret float [[B]] 35; 36 %b = fmul nnan float %a, 0.0 37 ret float %b 38} 39 40define float @no_mul_zero_3(float %a) { 41; CHECK-LABEL: @no_mul_zero_3( 42; CHECK: [[B:%.*]] = fmul float %a, 0.000000e+00 43; CHECK-NEXT: ret float [[B]] 44; 45 %b = fmul float %a, 0.0 46 ret float %b 47} 48 49; fadd [nnan ninf] X, (fsub [nnan ninf] 0, X) ==> 0 50; where nnan and ninf have to occur at least once somewhere in this 51; expression 52define float @fadd_fsub_0(float %a) { 53; CHECK-LABEL: @fadd_fsub_0( 54; CHECK: [[NOFOLD:%.*]] = fsub float 0.000000e+00, %a 55; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd nnan float [[NOFOLD]], %a 56; CHECK-NEXT: ret float [[NO_ZERO]] 57; 58; X + -X ==> 0 59 %t1 = fsub nnan ninf float 0.0, %a 60 %zero1 = fadd nnan ninf float %t1, %a 61 62 %t2 = fsub nnan float 0.0, %a 63 %zero2 = fadd ninf float %t2, %a 64 65 %t3 = fsub nnan ninf float 0.0, %a 66 %zero3 = fadd float %t3, %a 67 68 %t4 = fsub float 0.0, %a 69 %zero4 = fadd nnan ninf float %t4, %a 70 71; Dont fold this 72 %nofold = fsub float 0.0, %a 73 %no_zero = fadd nnan float %nofold, %a 74 75; Coalesce the folded zeros 76 %zero5 = fadd float %zero1, %zero2 77 %zero6 = fadd float %zero3, %zero4 78 %zero7 = fadd float %zero5, %zero6 79 80; Should get folded 81 %ret = fadd nsz float %no_zero, %zero7 82 83 ret float %ret 84} 85 86; fsub nnan x, x ==> 0.0 87define float @fsub_x_x(float %a) { 88; CHECK-LABEL: @fsub_x_x( 89; CHECK: [[NO_ZERO1:%.*]] = fsub ninf float %a, %a 90; CHECK-NEXT: [[NO_ZERO2:%.*]] = fsub float %a, %a 91; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd float [[NO_ZERO1:%.*]], [[NO_ZERO2:%.*]] 92; CHECK-NEXT: ret float [[NO_ZERO]] 93; 94; X - X ==> 0 95 %zero1 = fsub nnan float %a, %a 96 97; Dont fold 98 %no_zero1 = fsub ninf float %a, %a 99 %no_zero2 = fsub float %a, %a 100 %no_zero = fadd float %no_zero1, %no_zero2 101 102; Should get folded 103 %ret = fadd nsz float %no_zero, %zero1 104 105 ret float %ret 106} 107 108; fsub nsz 0.0, (fsub 0.0, X) ==> X 109define float @fsub_0_0_x(float %a) { 110; CHECK-LABEL: @fsub_0_0_x( 111; CHECK: ret float %a 112; 113 %t1 = fsub float 0.0, %a 114 %ret = fsub nsz float 0.0, %t1 115 ret float %ret 116} 117 118; fadd nsz X, 0 ==> X 119define float @nofold_fadd_x_0(float %a) { 120; CHECK-LABEL: @nofold_fadd_x_0( 121; CHECK: [[NO_ZERO1:%.*]] = fadd ninf float %a, 0.000000e+00 122; CHECK-NEXT: [[NO_ZERO2:%.*]] = fadd nnan float %a, 0.000000e+00 123; CHECK-NEXT: [[NO_ZERO:%.*]] = fadd float [[NO_ZERO1:%.*]], [[NO_ZERO2:%.*]] 124; CHECK-NEXT: ret float [[NO_ZERO]] 125; 126; Dont fold 127 %no_zero1 = fadd ninf float %a, 0.0 128 %no_zero2 = fadd nnan float %a, 0.0 129 %no_zero = fadd float %no_zero1, %no_zero2 130 ret float %no_zero 131} 132 133; fdiv nsz nnan 0, X ==> 0 134define double @fdiv_zero_by_x(double %X) { 135; CHECK-LABEL: @fdiv_zero_by_x( 136; CHECK: ret double 0.000000e+00 137; 138; 0 / X -> 0 139 %r = fdiv nnan nsz double 0.0, %X 140 ret double %r 141} 142 143define float @fdiv_self(float %f) { 144; CHECK-LABEL: @fdiv_self( 145; CHECK: ret float 1.000000e+00 146; 147 %div = fdiv nnan float %f, %f 148 ret float %div 149} 150 151define float @fdiv_self_invalid(float %f) { 152; CHECK-LABEL: @fdiv_self_invalid( 153; CHECK: [[DIV:%.*]] = fdiv float %f, %f 154; CHECK-NEXT: ret float [[DIV]] 155; 156 %div = fdiv float %f, %f 157 ret float %div 158} 159 160define float @fdiv_neg1(float %f) { 161; CHECK-LABEL: @fdiv_neg1( 162; CHECK: ret float -1.000000e+00 163; 164 %neg = fsub fast float -0.000000e+00, %f 165 %div = fdiv nnan float %neg, %f 166 ret float %div 167} 168 169define float @fdiv_neg2(float %f) { 170; CHECK-LABEL: @fdiv_neg2( 171; CHECK: ret float -1.000000e+00 172; 173 %neg = fsub fast float 0.000000e+00, %f 174 %div = fdiv nnan float %neg, %f 175 ret float %div 176} 177 178define float @fdiv_neg_invalid(float %f) { 179; CHECK-LABEL: @fdiv_neg_invalid( 180; CHECK: [[NEG:%.*]] = fsub fast float -0.000000e+00, %f 181; CHECK-NEXT: [[DIV:%.*]] = fdiv float [[NEG]], %f 182; CHECK-NEXT: ret float [[DIV]] 183; 184 %neg = fsub fast float -0.000000e+00, %f 185 %div = fdiv float %neg, %f 186 ret float %div 187} 188 189define float @fdiv_neg_swapped1(float %f) { 190; CHECK-LABEL: @fdiv_neg_swapped1( 191; CHECK: ret float -1.000000e+00 192; 193 %neg = fsub float -0.000000e+00, %f 194 %div = fdiv nnan float %f, %neg 195 ret float %div 196} 197 198define float @fdiv_neg_swapped2(float %f) { 199; CHECK-LABEL: @fdiv_neg_swapped2( 200; CHECK: ret float -1.000000e+00 201; 202 %neg = fsub float 0.000000e+00, %f 203 %div = fdiv nnan float %f, %neg 204 ret float %div 205} 206