Skip to content

Commit fb381bb

Browse files
authored
[CIR][CIRGen] Support for __builtin_elementwise_atan2 (#1655)
Implement atan2 intrinsic as part of #1192
1 parent 209df5a commit fb381bb

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

clang/include/clang/CIR/Dialect/IR/CIROps.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4797,6 +4797,7 @@ def FMaximumOp : BinaryFPToFPBuiltinOp<"fmaximum", "MaximumOp">;
47974797
def FMinimumOp : BinaryFPToFPBuiltinOp<"fminimum", "MinimumOp">;
47984798
def FModOp : BinaryFPToFPBuiltinOp<"fmod", "FRemOp">;
47994799
def PowOp : BinaryFPToFPBuiltinOp<"pow", "PowOp">;
4800+
def ATan2Op : BinaryFPToFPBuiltinOp<"atan2", "ATan2Op">;
48004801

48014802
def IsFPClassOp : CIR_Op<"is_fp_class"> {
48024803
let summary = "Corresponding to the `__builtin_fpclassify` builtin function in clang";

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
14991499
case Builtin::BI__builtin_elementwise_atan:
15001500
return emitUnaryFPBuiltin<cir::ATanOp>(*this, *E);
15011501
case Builtin::BI__builtin_elementwise_atan2:
1502-
llvm_unreachable("BI__builtin_elementwise_atan2 NYI");
1502+
return emitBinaryFPBuiltin<cir::ATan2Op>(*this, *E);
15031503
case Builtin::BI__builtin_elementwise_ceil:
15041504
llvm_unreachable("BI__builtin_elementwise_ceil NYI");
15051505
case Builtin::BI__builtin_elementwise_exp:

clang/test/CIR/CodeGen/builtins-elementwise.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,27 @@ void test_builtin_elementwise_atan(float f, double d, vfloat4 vf4,
100100
vd4 = __builtin_elementwise_atan(vd4);
101101
}
102102

103+
void test_builtin_elementwise_atan2(float f, double d, vfloat4 vf4,
104+
vdouble4 vd4) {
105+
// CIR-LABEL: test_builtin_elementwise_atan2
106+
// LLVM-LABEL: test_builtin_elementwise_atan2
107+
// CIR: {{%.*}} = cir.atan2 {{%.*}}, {{%.*}} : !cir.float
108+
// LLVM: {{%.*}} = call float @llvm.atan2.f32(float {{%.*}}, float {{%.*}})
109+
f = __builtin_elementwise_atan2(f, f);
110+
111+
// CIR: {{%.*}} = cir.atan2 {{%.*}}, {{%.*}} : !cir.double
112+
// LLVM: {{%.*}} = call double @llvm.atan2.f64(double {{%.*}}, double {{%.*}})
113+
d = __builtin_elementwise_atan2(d, d);
114+
115+
// CIR: {{%.*}} = cir.atan2 {{%.*}}, {{%.*}} : !cir.vector<!cir.float x 4>
116+
// LLVM: {{%.*}} = call <4 x float> @llvm.atan2.v4f32(<4 x float> {{%.*}}, <4 x float> {{%.*}})
117+
vf4 = __builtin_elementwise_atan2(vf4, vf4);
118+
119+
// CIR: {{%.*}} = cir.atan2 {{%.*}}, {{%.*}} : !cir.vector<!cir.double x 4>
120+
// LLVM: {{%.*}} = call <4 x double> @llvm.atan2.v4f64(<4 x double> {{%.*}}, <4 x double> {{%.*}})
121+
vd4 = __builtin_elementwise_atan2(vd4, vd4);
122+
}
123+
103124
void test_builtin_elementwise_exp(float f, double d, vfloat4 vf4,
104125
vdouble4 vd4) {
105126
// CIR-LABEL: test_builtin_elementwise_exp

0 commit comments

Comments
 (0)