[llvm] r265493 - [SLPVectorizer] Vectorize libcalls of sqrt
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 5 17:15:01 PDT 2016
Author: majnemer
Date: Tue Apr 5 19:14:59 2016
New Revision: 265493
URL: http://llvm.org/viewvc/llvm-project?rev=265493&view=rev
Log:
[SLPVectorizer] Vectorize libcalls of sqrt
We didn't realize that we could transform the libcall into a vectorized
intrinsic.
Modified:
llvm/trunk/lib/Analysis/VectorUtils.cpp
llvm/trunk/test/Transforms/LoopVectorize/X86/veclib-calls.ll
llvm/trunk/test/Transforms/SLPVectorizer/X86/call.ll
Modified: llvm/trunk/lib/Analysis/VectorUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/VectorUtils.cpp?rev=265493&r1=265492&r2=265493&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/VectorUtils.cpp (original)
+++ llvm/trunk/lib/Analysis/VectorUtils.cpp Tue Apr 5 19:14:59 2016
@@ -220,6 +220,10 @@ Intrinsic::ID llvm::getIntrinsicIDForCal
case LibFunc::powf:
case LibFunc::powl:
return checkBinaryFloatSignature(*CI, Intrinsic::pow);
+ case LibFunc::sqrt:
+ case LibFunc::sqrtf:
+ case LibFunc::sqrtl:
+ return checkUnaryFloatSignature(*CI, Intrinsic::sqrt);
}
return Intrinsic::not_intrinsic;
Modified: llvm/trunk/test/Transforms/LoopVectorize/X86/veclib-calls.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopVectorize/X86/veclib-calls.ll?rev=265493&r1=265492&r2=265493&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LoopVectorize/X86/veclib-calls.ll (original)
+++ llvm/trunk/test/Transforms/LoopVectorize/X86/veclib-calls.ll Tue Apr 5 19:14:59 2016
@@ -3,31 +3,6 @@
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
-;CHECK-LABEL: @sqrt_f32(
-;CHECK: vsqrtf{{.*}}<4 x float>
-;CHECK: ret void
-declare float @sqrtf(float) nounwind readnone
-define void @sqrt_f32(i32 %n, float* noalias %y, float* noalias %x) nounwind uwtable {
-entry:
- %cmp6 = icmp sgt i32 %n, 0
- br i1 %cmp6, label %for.body, label %for.end
-
-for.body: ; preds = %entry, %for.body
- %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
- %arrayidx = getelementptr inbounds float, float* %y, i64 %indvars.iv
- %0 = load float, float* %arrayidx, align 4
- %call = tail call float @sqrtf(float %0) nounwind readnone
- %arrayidx2 = getelementptr inbounds float, float* %x, i64 %indvars.iv
- store float %call, float* %arrayidx2, align 4
- %indvars.iv.next = add i64 %indvars.iv, 1
- %lftr.wideiv = trunc i64 %indvars.iv.next to i32
- %exitcond = icmp eq i32 %lftr.wideiv, %n
- br i1 %exitcond, label %for.end, label %for.body
-
-for.end: ; preds = %for.body, %entry
- ret void
-}
-
;CHECK-LABEL: @exp_f32(
;CHECK: vexpf{{.*}}<4 x float>
;CHECK: ret void
@@ -160,6 +135,7 @@ for.end:
;CHECK-LABEL: @sqrt_f32_nobuiltin(
;CHECK-NOT: vsqrtf{{.*}}<4 x float>
;CHECK: ret void
+declare float @sqrtf(float) nounwind readnone
define void @sqrt_f32_nobuiltin(i32 %n, float* noalias %y, float* noalias %x) nounwind uwtable {
entry:
%cmp6 = icmp sgt i32 %n, 0
Modified: llvm/trunk/test/Transforms/SLPVectorizer/X86/call.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SLPVectorizer/X86/call.ll?rev=265493&r1=265492&r2=265493&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SLPVectorizer/X86/call.ll (original)
+++ llvm/trunk/test/Transforms/SLPVectorizer/X86/call.ll Tue Apr 5 19:14:59 2016
@@ -7,6 +7,7 @@ declare double @sin(double)
declare double @cos(double)
declare double @pow(double, double)
declare double @exp2(double)
+declare double @sqrt(double)
declare i64 @round(i64)
@@ -92,6 +93,28 @@ entry:
store double %call, double* %c, align 8
%arrayidx5 = getelementptr inbounds double, double* %c, i64 1
store double %call5, double* %arrayidx5, align 8
+ ret void
+}
+
+
+; CHECK: sqrt_libm
+; CHECK: call <2 x double> @llvm.sqrt.v2f64
+; CHECK: ret void
+define void @sqrt_libm(double* %a, double* %b, double* %c) {
+entry:
+ %i0 = load double, double* %a, align 8
+ %i1 = load double, double* %b, align 8
+ %mul = fmul double %i0, %i1
+ %call = tail call double @sqrt(double %mul) nounwind readnone
+ %arrayidx3 = getelementptr inbounds double, double* %a, i64 1
+ %i3 = load double, double* %arrayidx3, align 8
+ %arrayidx4 = getelementptr inbounds double, double* %b, i64 1
+ %i4 = load double, double* %arrayidx4, align 8
+ %mul5 = fmul double %i3, %i4
+ %call5 = tail call double @sqrt(double %mul5) nounwind readnone
+ store double %call, double* %c, align 8
+ %arrayidx5 = getelementptr inbounds double, double* %c, i64 1
+ store double %call5, double* %arrayidx5, align 8
ret void
}
More information about the llvm-commits
mailing list