Skip to content

Commit 1e6dff6

Browse files
committed
[CIR][AMDGPU] Add lowering for amdgcn trig preop builtins
1 parent 4916f0e commit 1e6dff6

File tree

3 files changed

+54
-1
lines changed

3 files changed

+54
-1
lines changed

clang/lib/CIR/CodeGen/CIRGenBuiltinAMDGPU.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ static llvm::StringRef getIntrinsicNameforWaveReduction(unsigned BuiltinID) {
5454
}
5555
}
5656

57+
// Emit an intrinsic that has 1 float or double operand, and 1 integer.
58+
static mlir::Value emitFPIntBuiltin(CIRGenFunction &CGF, const CallExpr *E,
59+
llvm::StringRef intrinsicName) {
60+
mlir::Value Src0 = CGF.emitScalarExpr(E->getArg(0));
61+
mlir::Value Src1 = CGF.emitScalarExpr(E->getArg(1));
62+
mlir::Value result =
63+
LLVMIntrinsicCallOp::create(CGF.getBuilder(), CGF.getLoc(E->getExprLoc()),
64+
CGF.getBuilder().getStringAttr(intrinsicName),
65+
Src0.getType(), {Src0, Src1})
66+
.getResult();
67+
return result;
68+
}
69+
5770
mlir::Value CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
5871
const CallExpr *expr) {
5972
switch (builtinId) {
@@ -163,7 +176,7 @@ mlir::Value CIRGenFunction::emitAMDGPUBuiltinExpr(unsigned builtinId,
163176
}
164177
case AMDGPU::BI__builtin_amdgcn_trig_preop:
165178
case AMDGPU::BI__builtin_amdgcn_trig_preopf: {
166-
llvm_unreachable("trig_preop_* NYI");
179+
return emitFPIntBuiltin(*this, expr, "amdgcn.trig.preop");
167180
}
168181
case AMDGPU::BI__builtin_amdgcn_rcp:
169182
case AMDGPU::BI__builtin_amdgcn_rcpf:

clang/test/CIR/CodeGen/HIP/builtins-amdgcn.hip

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,23 @@ __device__ void test_readlane(int* out, int a, int b) {
305305
__device__ void test_readfirstlane(int* out, int a) {
306306
*out = __builtin_amdgcn_readfirstlane(a);
307307
}
308+
309+
// CIR-LABEL: @_Z19test_trig_preop_f32Pffi
310+
// CIR: cir.llvm.intrinsic "amdgcn.trig.preop" {{.*}} : (!cir.float, !s32i) -> !cir.float
311+
// LLVM: define{{.*}} void @_Z19test_trig_preop_f32Pffi
312+
// LLVM: call{{.*}} float @llvm.amdgcn.trig.preop.f32(float %{{.+}}, i32 %{{.*}})
313+
// OGCG: define{{.*}} void @_Z19test_trig_preop_f32Pffi
314+
// OGCG: call{{.*}} float @llvm.amdgcn.trig.preop.f32(float %{{.+}}, i32 %{{.*}})
315+
__device__ void test_trig_preop_f32(float* out, float a, int b) {
316+
*out = __builtin_amdgcn_trig_preopf(a, b);
317+
}
318+
319+
// CIR-LABEL: @_Z19test_trig_preop_f64Pddi
320+
// CIR: cir.llvm.intrinsic "amdgcn.trig.preop" {{.*}} : (!cir.double, !s32i) -> !cir.double
321+
// LLVM: define{{.*}} void @_Z19test_trig_preop_f64Pddi
322+
// LLVM: call{{.*}} double @llvm.amdgcn.trig.preop.f64(double %{{.+}}, i32 %{{.*}})
323+
// OGCG: define{{.*}} void @_Z19test_trig_preop_f64Pddi
324+
// OGCG: call{{.*}} double @llvm.amdgcn.trig.preop.f64(double %{{.+}}, i32 %{{.*}})
325+
__device__ void test_trig_preop_f64(double* out, double a, int b) {
326+
*out = __builtin_amdgcn_trig_preop(a, b);
327+
}

clang/test/CIR/CodeGen/OpenCL/builtins_amdgcn.cl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,23 @@ void test_readlane(global int* out, int a, int b) {
318318
void test_readfirstlane(global int* out, int a) {
319319
*out = __builtin_amdgcn_readfirstlane(a);
320320
}
321+
322+
// CIR-LABEL: @test_trig_preop_f32
323+
// CIR: cir.llvm.intrinsic "amdgcn.trig.preop" {{.*}} : (!cir.float, !s32i) -> !cir.float
324+
// LLVM: define{{.*}} void @test_trig_preop_f32
325+
// LLVM: call{{.*}} float @llvm.amdgcn.trig.preop.f32(float %{{.+}}, i32 %{{.*}})
326+
// OGCG: define{{.*}} void @test_trig_preop_f32
327+
// OGCG: call{{.*}} float @llvm.amdgcn.trig.preop.f32(float %{{.+}}, i32 %{{.*}})
328+
void test_trig_preop_f32(global float* out, float a, int b) {
329+
*out = __builtin_amdgcn_trig_preopf(a, b);
330+
}
331+
332+
// CIR-LABEL: @test_trig_preop_f64
333+
// CIR: cir.llvm.intrinsic "amdgcn.trig.preop" {{.*}} : (!cir.double, !s32i) -> !cir.double
334+
// LLVM: define{{.*}} void @test_trig_preop_f64
335+
// LLVM: call{{.*}} double @llvm.amdgcn.trig.preop.f64(double %{{.+}}, i32 %{{.*}})
336+
// OGCG: define{{.*}} void @test_trig_preop_f64
337+
// OGCG: call{{.*}} double @llvm.amdgcn.trig.preop.f64(double %{{.+}}, i32 %{{.*}})
338+
void test_trig_preop_f64(global double* out, double a, int b) {
339+
*out = __builtin_amdgcn_trig_preop(a, b);
340+
}

0 commit comments

Comments
 (0)