Skip to content

Commit be2f6a0

Browse files
authored
[CIR][CIRGen][Builtin] Add __builtin_elementwise_{log, log2, log10} (#1543)
- Part of #1192
1 parent 3897030 commit be2f6a0

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltin.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1457,11 +1457,11 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
14571457
case Builtin::BI__builtin_elementwise_exp2:
14581458
llvm_unreachable("BI__builtin_elementwise_exp2 NYI");
14591459
case Builtin::BI__builtin_elementwise_log:
1460-
llvm_unreachable("BI__builtin_elementwise_log NYI");
1460+
return emitUnaryFPBuiltin<cir::LogOp>(*this, *E);
14611461
case Builtin::BI__builtin_elementwise_log2:
1462-
llvm_unreachable("BI__builtin_elementwise_log2 NYI");
1462+
return emitUnaryFPBuiltin<cir::Log2Op>(*this, *E);
14631463
case Builtin::BI__builtin_elementwise_log10:
1464-
llvm_unreachable("BI__builtin_elementwise_log10 NYI");
1464+
return emitUnaryFPBuiltin<cir::Log10Op>(*this, *E);
14651465
case Builtin::BI__builtin_elementwise_pow:
14661466
llvm_unreachable("BI__builtin_elementwise_pow NYI");
14671467
case Builtin::BI__builtin_elementwise_bitreverse:

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

+63
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,66 @@ void test_builtin_elementwise_exp(float f, double d, vfloat4 vf4,
120120
// LLVM: {{%.*}} = call <4 x double> @llvm.exp.v4f64(<4 x double> {{%.*}})
121121
vd4 = __builtin_elementwise_exp(vd4);
122122
}
123+
124+
void test_builtin_elementwise_log(float f, double d, vfloat4 vf4,
125+
vdouble4 vd4) {
126+
// CIR-LABEL: test_builtin_elementwise_log
127+
// LLVM-LABEL: test_builtin_elementwise_log
128+
// CIR: {{%.*}} = cir.log {{%.*}} : !cir.float
129+
// LLVM: {{%.*}} = call float @llvm.log.f32(float {{%.*}})
130+
f = __builtin_elementwise_log(f);
131+
132+
// CIR: {{%.*}} = cir.log {{%.*}} : !cir.double
133+
// LLVM: {{%.*}} = call double @llvm.log.f64(double {{%.*}})
134+
d = __builtin_elementwise_log(d);
135+
136+
// CIR: {{%.*}} = cir.log {{%.*}} : !cir.vector<!cir.float x 4>
137+
// LLVM: {{%.*}} = call <4 x float> @llvm.log.v4f32(<4 x float> {{%.*}})
138+
vf4 = __builtin_elementwise_log(vf4);
139+
140+
// CIR: {{%.*}} = cir.log {{%.*}} : !cir.vector<!cir.double x 4>
141+
// LLVM: {{%.*}} = call <4 x double> @llvm.log.v4f64(<4 x double> {{%.*}})
142+
vd4 = __builtin_elementwise_log(vd4);
143+
}
144+
145+
void test_builtin_elementwise_log2(float f, double d, vfloat4 vf4,
146+
vdouble4 vd4) {
147+
// CIR-LABEL: test_builtin_elementwise_log2
148+
// LLVM-LABEL: test_builtin_elementwise_log2
149+
// CIR: {{%.*}} = cir.log2 {{%.*}} : !cir.float
150+
// LLVM: {{%.*}} = call float @llvm.log2.f32(float {{%.*}})
151+
f = __builtin_elementwise_log2(f);
152+
153+
// CIR: {{%.*}} = cir.log2 {{%.*}} : !cir.double
154+
// LLVM: {{%.*}} = call double @llvm.log2.f64(double {{%.*}})
155+
d = __builtin_elementwise_log2(d);
156+
157+
// CIR: {{%.*}} = cir.log2 {{%.*}} : !cir.vector<!cir.float x 4>
158+
// LLVM: {{%.*}} = call <4 x float> @llvm.log2.v4f32(<4 x float> {{%.*}})
159+
vf4 = __builtin_elementwise_log2(vf4);
160+
161+
// CIR: {{%.*}} = cir.log2 {{%.*}} : !cir.vector<!cir.double x 4>
162+
// LLVM: {{%.*}} = call <4 x double> @llvm.log2.v4f64(<4 x double> {{%.*}})
163+
vd4 = __builtin_elementwise_log2(vd4);
164+
}
165+
166+
void test_builtin_elementwise_log10(float f, double d, vfloat4 vf4,
167+
vdouble4 vd4) {
168+
// CIR-LABEL: test_builtin_elementwise_log10
169+
// LLVM-LABEL: test_builtin_elementwise_log10
170+
// CIR: {{%.*}} = cir.log10 {{%.*}} : !cir.float
171+
// LLVM: {{%.*}} = call float @llvm.log10.f32(float {{%.*}})
172+
f = __builtin_elementwise_log10(f);
173+
174+
// CIR: {{%.*}} = cir.log10 {{%.*}} : !cir.double
175+
// LLVM: {{%.*}} = call double @llvm.log10.f64(double {{%.*}})
176+
d = __builtin_elementwise_log10(d);
177+
178+
// CIR: {{%.*}} = cir.log10 {{%.*}} : !cir.vector<!cir.float x 4>
179+
// LLVM: {{%.*}} = call <4 x float> @llvm.log10.v4f32(<4 x float> {{%.*}})
180+
vf4 = __builtin_elementwise_log10(vf4);
181+
182+
// CIR: {{%.*}} = cir.log10 {{%.*}} : !cir.vector<!cir.double x 4>
183+
// LLVM: {{%.*}} = call <4 x double> @llvm.log10.v4f64(<4 x double> {{%.*}})
184+
vd4 = __builtin_elementwise_log10(vd4);
185+
}

0 commit comments

Comments
 (0)