Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit eece6ba

Browse files
committedJun 6, 2023
IR: Add llvm.ldexp and llvm.experimental.constrained.ldexp intrinsics
AMDGPU has native instructions and target intrinsics for this, but these really should be subject to legalization and generic optimizations. This will enable legalization of f16->f32 on targets without f16 support. Implement a somewhat horrible inline expansion for targets without libcall support. This could be better if we could introduce control flow (GlobalISel version not yet implemented). Support for strictfp legalization is less complete but works for the simple cases.
1 parent 5d361ad commit eece6ba

File tree

71 files changed

+3780
-422
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+3780
-422
lines changed
 

‎clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17146,8 +17146,13 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
1714617146
return emitUnaryBuiltin(*this, E, Intrinsic::amdgcn_log_clamp);
1714717147
case AMDGPU::BI__builtin_amdgcn_ldexp:
1714817148
case AMDGPU::BI__builtin_amdgcn_ldexpf:
17149-
case AMDGPU::BI__builtin_amdgcn_ldexph:
17150-
return emitFPIntBuiltin(*this, E, Intrinsic::amdgcn_ldexp);
17149+
case AMDGPU::BI__builtin_amdgcn_ldexph: {
17150+
llvm::Value *Src0 = EmitScalarExpr(E->getArg(0));
17151+
llvm::Value *Src1 = EmitScalarExpr(E->getArg(1));
17152+
llvm::Function *F =
17153+
CGM.getIntrinsic(Intrinsic::ldexp, {Src0->getType(), Src1->getType()});
17154+
return Builder.CreateCall(F, {Src0, Src1});
17155+
}
1715117156
case AMDGPU::BI__builtin_amdgcn_frexp_mant:
1715217157
case AMDGPU::BI__builtin_amdgcn_frexp_mantf:
1715317158
case AMDGPU::BI__builtin_amdgcn_frexp_manth:

‎clang/test/CodeGenOpenCL/builtins-amdgcn-vi.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void test_cos_f16(global half* out, half a)
5252
}
5353

5454
// CHECK-LABEL: @test_ldexp_f16
55-
// CHECK: call half @llvm.amdgcn.ldexp.f16
55+
// CHECK: call half @llvm.ldexp.f16.i32
5656
void test_ldexp_f16(global half* out, half a, int b)
5757
{
5858
*out = __builtin_amdgcn_ldexph(a, b);

0 commit comments

Comments
 (0)
Please sign in to comment.