From 90f4c8ec299a19ec4c78166865e96c382cb32f92 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Tue, 20 Feb 2018 16:08:15 +0000 Subject: [InstCombine] fold fdiv with non-splat divisor to fmul: X/C --> X * (1/C) llvm-svn: 325590 --- llvm/test/Transforms/InstCombine/fast-math.ll | 7 ++++++- llvm/test/Transforms/InstCombine/fdiv.ll | 13 ++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'llvm/test/Transforms') diff --git a/llvm/test/Transforms/InstCombine/fast-math.ll b/llvm/test/Transforms/InstCombine/fast-math.ll index 4a0244561e0..1843a784ab8 100644 --- a/llvm/test/Transforms/InstCombine/fast-math.ll +++ b/llvm/test/Transforms/InstCombine/fast-math.ll @@ -229,6 +229,9 @@ define float @fmul_distribute1(float %f1) { } ; (X/C1 + C2) * C3 => X/(C1/C3) + C2*C3 +; TODO: We don't convert the fast fdiv to fmul because that would be multiplication +; by a denormal, but we could do better when we know that denormals are not a problem. + define double @fmul_distribute2(double %f1, double %f2) { ; CHECK-LABEL: @fmul_distribute2( ; CHECK-NEXT: [[TMP1:%.*]] = fdiv fast double [[F1:%.*]], 0x7FE8000000000000 @@ -345,7 +348,9 @@ define float @fmul4(float %f1, float %f2) { ; X / C1 * C2 => X / (C2/C1) if C1/C2 is either a special value of a denormal, ; and C2/C1 is a normal value. -; +; TODO: We don't convert the fast fdiv to fmul because that would be multiplication +; by a denormal, but we could do better when we know that denormals are not a problem. + define float @fmul5(float %f1, float %f2) { ; CHECK-LABEL: @fmul5( ; CHECK-NEXT: [[TMP1:%.*]] = fdiv fast float [[F1:%.*]], 0x47E8000000000000 diff --git a/llvm/test/Transforms/InstCombine/fdiv.ll b/llvm/test/Transforms/InstCombine/fdiv.ll index 90fea3baf1e..3a2c62c5071 100644 --- a/llvm/test/Transforms/InstCombine/fdiv.ll +++ b/llvm/test/Transforms/InstCombine/fdiv.ll @@ -86,11 +86,9 @@ define <2 x float> @not_exact_but_allow_recip_splat(<2 x float> %x) { ret <2 x float> %div } -; FIXME: Vector neglect. - define <2 x float> @exact_inverse_vec(<2 x float> %x) { ; CHECK-LABEL: @exact_inverse_vec( -; CHECK-NEXT: [[DIV:%.*]] = fdiv <2 x float> [[X:%.*]], +; CHECK-NEXT: [[DIV:%.*]] = fmul <2 x float> [[X:%.*]], ; CHECK-NEXT: ret <2 x float> [[DIV]] ; %div = fdiv <2 x float> %x, @@ -115,6 +113,15 @@ define <2 x float> @not_exact_inverse_vec(<2 x float> %x) { ret <2 x float> %div } +define <2 x float> @not_exact_inverse_vec_arcp(<2 x float> %x) { +; CHECK-LABEL: @not_exact_inverse_vec_arcp( +; CHECK-NEXT: [[DIV:%.*]] = fmul arcp <2 x float> [[X:%.*]], +; CHECK-NEXT: ret <2 x float> [[DIV]] +; + %div = fdiv arcp <2 x float> %x, + ret <2 x float> %div +} + ; (X / Y) / Z --> X / (Y * Z) define float @div_with_div_numerator(float %x, float %y, float %z) { -- cgit v1.2.3