[llvm] r357780 - [InstCombine] add tests for sqrt+fdiv+fmul; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 5 09:52:57 PDT 2019
Author: spatel
Date: Fri Apr 5 09:52:57 2019
New Revision: 357780
URL: http://llvm.org/viewvc/llvm-project?rev=357780&view=rev
Log:
[InstCombine] add tests for sqrt+fdiv+fmul; NFC
Examples based on recent llvm-dev thread. These are specific
patterns of more general enhancements that would solve these.
Modified:
llvm/trunk/test/Transforms/InstCombine/fmul-sqrt.ll
Modified: llvm/trunk/test/Transforms/InstCombine/fmul-sqrt.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fmul-sqrt.ll?rev=357780&r1=357779&r2=357780&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fmul-sqrt.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fmul-sqrt.ll Fri Apr 5 09:52:57 2019
@@ -2,6 +2,7 @@
; RUN: opt -S -instcombine < %s | FileCheck %s
declare double @llvm.sqrt.f64(double) nounwind readnone speculatable
+declare <2 x float> @llvm.sqrt.v2f32(<2 x float>)
declare void @use(double)
; sqrt(a) * sqrt(b) no math flags
@@ -87,3 +88,45 @@ define double @sqrt_a_sqrt_b_sqrt_c_sqrt
ret double %mul2
}
+define double @sqrt_squared(double %x) {
+; CHECK-LABEL: @sqrt_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]]
+; CHECK-NEXT: ret double [[SQUARED]]
+;
+ %sqrt = call fast double @llvm.sqrt.f64(double %x)
+ %rsqrt = fdiv fast double 1.0, %sqrt
+ %squared = fmul fast double %rsqrt, %rsqrt
+ 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:%.*]])
+; CHECK-NEXT: [[RSQRT:%.*]] = fdiv fast double 1.000000e+00, [[SQRT]]
+; CHECK-NEXT: call void @use(double [[RSQRT]])
+; CHECK-NEXT: [[SQUARED:%.*]] = fmul fast double [[RSQRT]], [[RSQRT]]
+; CHECK-NEXT: ret double [[SQUARED]]
+;
+ %sqrt = call fast double @llvm.sqrt.f64(double %x)
+ %rsqrt = fdiv fast double 1.0, %sqrt
+ call void @use(double %rsqrt)
+ %squared = fmul fast double %rsqrt, %rsqrt
+ ret double %squared
+}
+
+; Minimal FMF to reassociate fmul+fdiv.
+
+define <2 x float> @sqrt_squared_vec(<2 x float> %x) {
+; CHECK-LABEL: @sqrt_squared_vec(
+; CHECK-NEXT: [[SQRT:%.*]] = call <2 x float> @llvm.sqrt.v2f32(<2 x float> [[X:%.*]])
+; CHECK-NEXT: [[RSQRT:%.*]] = fdiv <2 x float> <float 1.000000e+00, float 1.000000e+00>, [[SQRT]]
+; CHECK-NEXT: [[SQUARED:%.*]] = fmul reassoc <2 x float> [[RSQRT]], [[RSQRT]]
+; CHECK-NEXT: ret <2 x float> [[SQUARED]]
+;
+ %sqrt = call <2 x float> @llvm.sqrt.v2f32(<2 x float> %x)
+ %rsqrt = fdiv <2 x float> <float 1.0, float 1.0>, %sqrt
+ %squared = fmul reassoc <2 x float> %rsqrt, %rsqrt
+ ret <2 x float> %squared
+}
More information about the llvm-commits
mailing list