Skip to content

Commit 734afe6

Browse files
authored
[CIR][CIRGen] Support for __builtin_elementwise_exp2 (#1656)
Implement base-2 exponential intrinsic as part of #1192
1 parent c21ed7f commit 734afe6

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
15041504
case Builtin::BI__builtin_elementwise_exp:
15051505
return emitUnaryFPBuiltin<cir::ExpOp>(*this, *E);
15061506
case Builtin::BI__builtin_elementwise_exp2:
1507-
llvm_unreachable("BI__builtin_elementwise_exp2 NYI");
1507+
return emitUnaryFPBuiltin<cir::Exp2Op>(*this, *E);
15081508
case Builtin::BI__builtin_elementwise_log:
15091509
return emitUnaryFPBuiltin<cir::LogOp>(*this, *E);
15101510
case Builtin::BI__builtin_elementwise_log2:

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ void test_builtin_elementwise_exp(float f, double d, vfloat4 vf4,
142142
vd4 = __builtin_elementwise_exp(vd4);
143143
}
144144

145+
void test_builtin_elementwise_exp2(float f, double d, vfloat4 vf4,
146+
vdouble4 vd4) {
147+
// CIR-LABEL: test_builtin_elementwise_exp
148+
// LLVM-LABEL: test_builtin_elementwise_exp
149+
// CIR: {{%.*}} = cir.exp2 {{%.*}} : !cir.float
150+
// LLVM: {{%.*}} = call float @llvm.exp2.f32(float {{%.*}})
151+
f = __builtin_elementwise_exp2(f);
152+
153+
// CIR: {{%.*}} = cir.exp2 {{%.*}} : !cir.double
154+
// LLVM: {{%.*}} = call double @llvm.exp2.f64(double {{%.*}})
155+
d = __builtin_elementwise_exp2(d);
156+
157+
// CIR: {{%.*}} = cir.exp2 {{%.*}} : !cir.vector<!cir.float x 4>
158+
// LLVM: {{%.*}} = call <4 x float> @llvm.exp2.v4f32(<4 x float> {{%.*}})
159+
vf4 = __builtin_elementwise_exp2(vf4);
160+
161+
// CIR: {{%.*}} = cir.exp2 {{%.*}} : !cir.vector<!cir.double x 4>
162+
// LLVM: {{%.*}} = call <4 x double> @llvm.exp2.v4f64(<4 x double> {{%.*}})
163+
vd4 = __builtin_elementwise_exp2(vd4);
164+
}
165+
145166
void test_builtin_elementwise_log(float f, double d, vfloat4 vf4,
146167
vdouble4 vd4) {
147168
// CIR-LABEL: test_builtin_elementwise_log

0 commit comments

Comments
 (0)