Allow AVX vrsqrtps generation.
authorSanjay Patel <spatel@rotateright.com>
Fri, 24 Oct 2014 17:59:18 +0000 (17:59 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 24 Oct 2014 17:59:18 +0000 (17:59 +0000)
This is a follow-on to r220570 that allows a 256-bit (v8f32)
version of vrsqrtps to be generated.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220579 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/sqrt-fastmath.ll

index b3541545403a5cc014d981be4513ae3e577abb3b..26b1e6d51ea1769f08067fb98ac6725d9a239e20 100644 (file)
@@ -14383,13 +14383,14 @@ SDValue X86TargetLowering::getRsqrtEstimate(SDValue Op,
   EVT VT = Op.getValueType();
   
   // SSE1 has rsqrtss and rsqrtps.
   EVT VT = Op.getValueType();
   
   // SSE1 has rsqrtss and rsqrtps.
-  // TODO: Add support for AVX (v8f32) and AVX512 (v16f32).
+  // TODO: Add support for AVX512 (v16f32).
   // It is likely not profitable to do this for f64 because a double-precision
   // rsqrt estimate with refinement on x86 prior to FMA requires at least 16
   // instructions: convert to single, rsqrtss, convert back to double, refine
   // (3 steps = at least 13 insts). If an 'rsqrtsd' variant was added to the ISA
   // along with FMA, this could be a throughput win.
   // It is likely not profitable to do this for f64 because a double-precision
   // rsqrt estimate with refinement on x86 prior to FMA requires at least 16
   // instructions: convert to single, rsqrtss, convert back to double, refine
   // (3 steps = at least 13 insts). If an 'rsqrtsd' variant was added to the ISA
   // along with FMA, this could be a throughput win.
-  if (Subtarget->hasSSE1() && (VT == MVT::f32 || VT == MVT::v4f32)) {
+  if ((Subtarget->hasSSE1() && (VT == MVT::f32 || VT == MVT::v4f32)) ||
+      (Subtarget->hasAVX() && VT == MVT::v8f32)) {
     RefinementSteps = 1;
     UseOneConstNR = false;
     return DCI.DAG.getNode(X86ISD::FRSQRT, SDLoc(Op), VT, Op);
     RefinementSteps = 1;
     UseOneConstNR = false;
     return DCI.DAG.getNode(X86ISD::FRSQRT, SDLoc(Op), VT, Op);
index 65f719e4e1721bcbe6b7238ec2251e3362b29067..24b175eed7a3c8faecec0f278fa28fa4649f345b 100644 (file)
@@ -55,9 +55,14 @@ entry:
 
 declare x86_fp80 @__sqrtl_finite(x86_fp80) #1
 
 
 declare x86_fp80 @__sqrtl_finite(x86_fp80) #1
 
+declare float @llvm.sqrt.f32(float) #1
+declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #1
+declare <8 x float> @llvm.sqrt.v8f32(<8 x float>) #1
+
 ; If the target's sqrtss and divss instructions are substantially
 ; slower than rsqrtss with a Newton-Raphson refinement, we should
 ; generate the estimate sequence.
 ; If the target's sqrtss and divss instructions are substantially
 ; slower than rsqrtss with a Newton-Raphson refinement, we should
 ; generate the estimate sequence.
+
 define float @reciprocal_square_root(float %x) #0 {
   %sqrt = tail call float @llvm.sqrt.f32(float %x)
   %div = fdiv fast float 1.0, %sqrt
 define float @reciprocal_square_root(float %x) #0 {
   %sqrt = tail call float @llvm.sqrt.f32(float %x)
   %div = fdiv fast float 1.0, %sqrt
@@ -78,11 +83,6 @@ define float @reciprocal_square_root(float %x) #0 {
 ; BTVER2-NEXT: retq
 }
 
 ; BTVER2-NEXT: retq
 }
 
-declare float @llvm.sqrt.f32(float) #1
-
-; If the target's sqrtps and divps instructions are substantially
-; slower than rsqrtps with a Newton-Raphson refinement, we should
-; generate the estimate sequence.
 define <4 x float> @reciprocal_square_root_v4f32(<4 x float> %x) #0 {
   %sqrt = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
   %div = fdiv fast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, %sqrt
 define <4 x float> @reciprocal_square_root_v4f32(<4 x float> %x) #0 {
   %sqrt = tail call <4 x float> @llvm.sqrt.v4f32(<4 x float> %x)
   %div = fdiv fast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0>, %sqrt
@@ -103,7 +103,28 @@ define <4 x float> @reciprocal_square_root_v4f32(<4 x float> %x) #0 {
 ; BTVER2-NEXT: retq
 }
 
 ; BTVER2-NEXT: retq
 }
 
-declare <4 x float> @llvm.sqrt.v4f32(<4 x float>) #1
+define <8 x float> @reciprocal_square_root_v8f32(<8 x float> %x) #0 {
+  %sqrt = tail call <8 x float> @llvm.sqrt.v8f32(<8 x float> %x)
+  %div = fdiv fast <8 x float> <float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0, float 1.0>, %sqrt
+  ret <8 x float> %div
+
+; CHECK-LABEL: reciprocal_square_root_v8f32:
+; CHECK: sqrtps
+; CHECK-NEXT: sqrtps
+; CHECK-NEXT: movaps
+; CHECK-NEXT: movaps
+; CHECK-NEXT: divps
+; CHECK-NEXT: divps
+; CHECK-NEXT: retq
+; BTVER2-LABEL: reciprocal_square_root_v8f32:
+; BTVER2: vrsqrtps
+; BTVER2-NEXT: vmulps
+; BTVER2-NEXT: vmulps
+; BTVER2-NEXT: vmulps
+; BTVER2-NEXT: vaddps
+; BTVER2-NEXT: vmulps
+; BTVER2-NEXT: retq
+}
 
 
 attributes #0 = { nounwind readnone uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" "use-soft-float"="false" }
 
 
 attributes #0 = { nounwind readnone uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="true" "no-nans-fp-math"="true" "unsafe-fp-math"="true" "use-soft-float"="false" }