Skip to content

Commit e6c6df3

Browse files
committed
[Analysis] isTriviallyVectorizable add vectorization for atan2 intrinsic
This change is part of this proposal: https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294 This returns true from isTriviallyVectorizable for llvm.atan2 intrinsic. It also adds llvm atan2 intrinsic equivalents to VecFuncs.def for massv. Part of: Implement the atan2 HLSL Function #70096.
1 parent c03d09c commit e6c6df3

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

llvm/include/llvm/Analysis/VecFuncs.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ TLI_DEFINE_VECFUNC("acosf", "__acosf4", FIXED(4), "_ZGV_LLVM_N4v")
289289
TLI_DEFINE_VECFUNC("atan", "__atand2", FIXED(2), "_ZGV_LLVM_N2v")
290290
TLI_DEFINE_VECFUNC("atanf", "__atanf4", FIXED(4), "_ZGV_LLVM_N4v")
291291
TLI_DEFINE_VECFUNC("atan2", "__atan2d2", FIXED(2), "_ZGV_LLVM_N2vv")
292+
TLI_DEFINE_VECFUNC("llvm.atan2.f64", "__atan2d2", FIXED(2), "_ZGV_LLVM_N2vv")
292293
TLI_DEFINE_VECFUNC("atan2f", "__atan2f4", FIXED(4), "_ZGV_LLVM_N4vv")
294+
TLI_DEFINE_VECFUNC("llvm.atan2.f32", "__atan2f4", FIXED(4), "_ZGV_LLVM_N4vv")
293295

294296
// Hyperbolic Functions
295297
TLI_DEFINE_VECFUNC("sinh", "__sinhd2", FIXED(2), "_ZGV_LLVM_N2v")

llvm/lib/Analysis/VectorUtils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ bool llvm::isTriviallyVectorizable(Intrinsic::ID ID) {
6969
case Intrinsic::asin:
7070
case Intrinsic::acos:
7171
case Intrinsic::atan:
72+
case Intrinsic::atan2:
7273
case Intrinsic::sin:
7374
case Intrinsic::cos:
7475
case Intrinsic::tan:

llvm/test/Transforms/LoopVectorize/PowerPC/massv-calls.ll

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,52 @@ for.end:
12441244
ret void
12451245
}
12461246

1247+
define void @atan2_f64_intrinsic(ptr nocapture %varray) {
1248+
; CHECK-LABEL: @atan2_f64_intrinsic(
1249+
; CHECK: __atan2d2{{.*}}<2 x double>
1250+
; CHECK: ret void
1251+
;
1252+
entry:
1253+
br label %for.body
1254+
1255+
for.body:
1256+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
1257+
%tmp = trunc i64 %iv to i32
1258+
%conv = sitofp i32 %tmp to double
1259+
%call = tail call double @llvm.atan2.f64(double %conv, double %conv)
1260+
%arrayidx = getelementptr inbounds double, ptr %varray, i64 %iv
1261+
store double %call, ptr %arrayidx, align 4
1262+
%iv.next = add nuw nsw i64 %iv, 1
1263+
%exitcond = icmp eq i64 %iv.next, 1000
1264+
br i1 %exitcond, label %for.end, label %for.body
1265+
1266+
for.end:
1267+
ret void
1268+
}
1269+
1270+
define void @atan2_f32_intrinsic(ptr nocapture %varray) {
1271+
; CHECK-LABEL: @atan2_f32_intrinsic(
1272+
; CHECK: __atan2f4{{.*}}<4 x float>
1273+
; CHECK: ret void
1274+
;
1275+
entry:
1276+
br label %for.body
1277+
1278+
for.body:
1279+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
1280+
%tmp = trunc i64 %iv to i32
1281+
%conv = sitofp i32 %tmp to float
1282+
%call = tail call float @llvm.atan2.f32(float %conv, float %conv)
1283+
%arrayidx = getelementptr inbounds float, ptr %varray, i64 %iv
1284+
store float %call, ptr %arrayidx, align 4
1285+
%iv.next = add nuw nsw i64 %iv, 1
1286+
%exitcond = icmp eq i64 %iv.next, 1000
1287+
br i1 %exitcond, label %for.end, label %for.body
1288+
1289+
for.end:
1290+
ret void
1291+
}
1292+
12471293
define void @sinh_f64(ptr nocapture %varray) {
12481294
; CHECK-LABEL: @sinh_f64(
12491295
; CHECK: __sinhd2{{.*}}<2 x double>

0 commit comments

Comments
 (0)