From c538c501134c98f22513d5254c0b912e71107ef9 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Fri, 5 Apr 2019 20:54:35 +0000 Subject: [PATCH] [InstCombine] add more tests for fmul+fdiv+sqrt; NFC llvm-svn: 357816 --- llvm/test/Transforms/InstCombine/fmul-sqrt.ll | 45 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/llvm/test/Transforms/InstCombine/fmul-sqrt.ll b/llvm/test/Transforms/InstCombine/fmul-sqrt.ll index 8161e31..62e57cd 100644 --- a/llvm/test/Transforms/InstCombine/fmul-sqrt.ll +++ b/llvm/test/Transforms/InstCombine/fmul-sqrt.ll @@ -88,8 +88,8 @@ define double @sqrt_a_sqrt_b_sqrt_c_sqrt_d_reassoc(double %a, double %b, double ret double %mul2 } -define double @sqrt_squared(double %x) { -; CHECK-LABEL: @sqrt_squared( +define double @rsqrt_squared(double %x) { +; CHECK-LABEL: @rsqrt_squared( ; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[X:%.*]]) ; CHECK-NEXT: [[RSQRT:%.*]] = fdiv fast double 1.000000e+00, [[SQRT]] ; CHECK-NEXT: [[SQUARED:%.*]] = fmul fast double [[RSQRT]], [[RSQRT]] @@ -101,6 +101,47 @@ define double @sqrt_squared(double %x) { ret double %squared } +define double @sqrt_divisor_squared(double %x, double %y) { +; CHECK-LABEL: @sqrt_divisor_squared( +; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[X:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[Y:%.*]], [[SQRT]] +; CHECK-NEXT: [[SQUARED:%.*]] = fmul reassoc nnan nsz double [[DIV]], [[DIV]] +; CHECK-NEXT: ret double [[SQUARED]] +; + %sqrt = call double @llvm.sqrt.f64(double %x) + %div = fdiv double %y, %sqrt + %squared = fmul reassoc nnan nsz double %div, %div + ret double %squared +} + +define double @sqrt_dividend_squared(double %x, double %y) { +; CHECK-LABEL: @sqrt_dividend_squared( +; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[X:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv fast double [[SQRT]], [[Y:%.*]] +; CHECK-NEXT: [[SQUARED:%.*]] = fmul fast double [[DIV]], [[DIV]] +; CHECK-NEXT: ret double [[SQUARED]] +; + %sqrt = call double @llvm.sqrt.f64(double %x) + %div = fdiv fast double %sqrt, %y + %squared = fmul fast double %div, %div + ret double %squared +} + +; Negative test - require 'nsz'. + +define double @sqrt_divisor_not_enough_FMF(double %x, double %y) { +; CHECK-LABEL: @sqrt_divisor_not_enough_FMF( +; CHECK-NEXT: [[SQRT:%.*]] = call double @llvm.sqrt.f64(double [[X:%.*]]) +; CHECK-NEXT: [[DIV:%.*]] = fdiv double [[Y:%.*]], [[SQRT]] +; CHECK-NEXT: [[SQUARED:%.*]] = fmul reassoc nnan double [[DIV]], [[DIV]] +; CHECK-NEXT: ret double [[SQUARED]] +; + %sqrt = call double @llvm.sqrt.f64(double %x) + %div = fdiv double %y, %sqrt + %squared = fmul reassoc nnan double %div, %div + ret double %squared +} + define double @sqrt_squared_extra_use(double %x) { ; CHECK-LABEL: @sqrt_squared_extra_use( ; CHECK-NEXT: [[SQRT:%.*]] = call fast double @llvm.sqrt.f64(double [[X:%.*]]) -- 2.7.4