Skip to content

Commit ec817c5

Browse files
ayokunle321lanza
authored andcommitted
[CIR][CodeGen] Support for __builtin_elementwise_atan (#1512)
Sub-issue of #1192. Adds CIR_ATanOp and support for __builtin_elementwise_atan.
1 parent a61a0d8 commit ec817c5

File tree

3 files changed

+41
-19
lines changed

3 files changed

+41
-19
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4737,9 +4737,10 @@ class UnaryFPToFPBuiltinOp<string mnemonic, string llvmOpName>
47374737
let llvmOp = llvmOpName;
47384738
}
47394739

4740+
def ACosOp : UnaryFPToFPBuiltinOp<"acos", "ACosOp">;
47404741
def ASinOp : UnaryFPToFPBuiltinOp<"asin", "ASinOp">;
4742+
def ATanOp : UnaryFPToFPBuiltinOp<"atan", "ATanOp">;
47414743
def CeilOp : UnaryFPToFPBuiltinOp<"ceil", "FCeilOp">;
4742-
def ACosOp : UnaryFPToFPBuiltinOp<"acos", "ACosOp">;
47434744
def CosOp : UnaryFPToFPBuiltinOp<"cos", "CosOp">;
47444745
def ExpOp : UnaryFPToFPBuiltinOp<"exp", "ExpOp">;
47454746
def Exp2Op : UnaryFPToFPBuiltinOp<"exp2", "Exp2Op">;

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
14061406
case Builtin::BI__builtin_elementwise_asin:
14071407
return emitUnaryFPBuiltin<cir::ASinOp>(*this, *E);
14081408
case Builtin::BI__builtin_elementwise_atan:
1409-
llvm_unreachable("BI__builtin_elementwise_atan NYI");
1409+
return emitUnaryFPBuiltin<cir::ATanOp>(*this, *E);
14101410
case Builtin::BI__builtin_elementwise_atan2:
14111411
llvm_unreachable("BI__builtin_elementwise_atan2 NYI");
14121412
case Builtin::BI__builtin_elementwise_ceil:

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

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,44 @@ void test_builtin_elementwise_acos(float f, double d, vfloat4 vf4,
6060

6161
void test_builtin_elementwise_asin(float f, double d, vfloat4 vf4,
6262
vdouble4 vd4) {
63-
// CIR-LABEL: test_builtin_elementwise_asin
64-
// LLVM-LABEL: test_builtin_elementwise_asin
65-
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.float
66-
// LLVM: {{%.*}} = call float @llvm.asin.f32(float {{%.*}})
67-
f = __builtin_elementwise_asin(f);
68-
69-
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.double
70-
// LLVM: {{%.*}} = call double @llvm.asin.f64(double {{%.*}})
71-
d = __builtin_elementwise_asin(d);
72-
73-
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.vector<!cir.float x 4>
74-
// LLVM: {{%.*}} = call <4 x float> @llvm.asin.v4f32(<4 x float> {{%.*}})
75-
vf4 = __builtin_elementwise_asin(vf4);
76-
77-
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.vector<!cir.double x 4>
78-
// LLVM: {{%.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> {{%.*}})
79-
vd4 = __builtin_elementwise_asin(vd4);
63+
// CIR-LABEL: test_builtin_elementwise_asin
64+
// LLVM-LABEL: test_builtin_elementwise_asin
65+
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.float
66+
// LLVM: {{%.*}} = call float @llvm.asin.f32(float {{%.*}})
67+
f = __builtin_elementwise_asin(f);
68+
69+
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.double
70+
// LLVM: {{%.*}} = call double @llvm.asin.f64(double {{%.*}})
71+
d = __builtin_elementwise_asin(d);
72+
73+
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.vector<!cir.float x 4>
74+
// LLVM: {{%.*}} = call <4 x float> @llvm.asin.v4f32(<4 x float> {{%.*}})
75+
vf4 = __builtin_elementwise_asin(vf4);
76+
77+
// CIR: {{%.*}} = cir.asin {{%.*}} : !cir.vector<!cir.double x 4>
78+
// LLVM: {{%.*}} = call <4 x double> @llvm.asin.v4f64(<4 x double> {{%.*}})
79+
vd4 = __builtin_elementwise_asin(vd4);
80+
}
81+
82+
void test_builtin_elementwise_atan(float f, double d, vfloat4 vf4,
83+
vdouble4 vd4) {
84+
// CIR-LABEL: test_builtin_elementwise_atan
85+
// LLVM-LABEL: test_builtin_elementwise_atan
86+
// CIR: {{%.*}} = cir.atan {{%.*}} : !cir.float
87+
// LLVM: {{%.*}} = call float @llvm.atan.f32(float {{%.*}})
88+
f = __builtin_elementwise_atan(f);
89+
90+
// CIR: {{%.*}} = cir.atan {{%.*}} : !cir.double
91+
// LLVM: {{%.*}} = call double @llvm.atan.f64(double {{%.*}})
92+
d = __builtin_elementwise_atan(d);
93+
94+
// CIR: {{%.*}} = cir.atan {{%.*}} : !cir.vector<!cir.float x 4>
95+
// LLVM: {{%.*}} = call <4 x float> @llvm.atan.v4f32(<4 x float> {{%.*}})
96+
vf4 = __builtin_elementwise_atan(vf4);
97+
98+
// CIR: {{%.*}} = cir.atan {{%.*}} : !cir.vector<!cir.double x 4>
99+
// LLVM: {{%.*}} = call <4 x double> @llvm.atan.v4f64(<4 x double> {{%.*}})
100+
vd4 = __builtin_elementwise_atan(vd4);
80101
}
81102

82103
void test_builtin_elementwise_exp(float f, double d, vfloat4 vf4,

0 commit comments

Comments
 (0)