Index: llvm/include/llvm/IR/IntrinsicsAMDGPU.td =================================================================== --- llvm/include/llvm/IR/IntrinsicsAMDGPU.td +++ llvm/include/llvm/IR/IntrinsicsAMDGPU.td @@ -345,12 +345,6 @@ def int_amdgcn_rsq_clamp : DefaultAttrsIntrinsic< [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable]>; -// For int_amdgcn_ldexp_f16, only the low 16 bits of the i32 src1 operand will used. -def int_amdgcn_ldexp : DefaultAttrsIntrinsic< - [llvm_anyfloat_ty], [LLVMMatchType<0>, llvm_i32_ty], - [IntrNoMem, IntrSpeculatable] ->; - def int_amdgcn_frexp_mant : DefaultAttrsIntrinsic< [llvm_anyfloat_ty], [LLVMMatchType<0>], [IntrNoMem, IntrSpeculatable] >; Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -834,6 +834,13 @@ {F->getReturnType()}); return true; } + if (Name == "amdgcn.ldexp") { + // Target specific intrinsic became redundant + NewFn = Intrinsic::getDeclaration( + F->getParent(), Intrinsic::ldexp, + {F->getReturnType(), F->getArg(1)->getType()}); + return true; + } break; } Index: llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUISelLowering.cpp @@ -3207,8 +3207,7 @@ case Intrinsic::amdgcn_rsq: case Intrinsic::amdgcn_rcp_legacy: case Intrinsic::amdgcn_rsq_legacy: - case Intrinsic::amdgcn_rsq_clamp: - case Intrinsic::amdgcn_ldexp: { + case Intrinsic::amdgcn_rsq_clamp: { // FIXME: This is probably wrong. If src is an sNaN, it won't be quieted SDValue Src = N->getOperand(1); return Src.isUndef() ? Src : SDValue(); Index: llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp =================================================================== --- llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp +++ llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp @@ -954,50 +954,6 @@ break; } - case Intrinsic::amdgcn_ldexp: { - // FIXME: This doesn't introduce new instructions and belongs in - // InstructionSimplify. - Type *Ty = II.getType(); - Value *Op0 = II.getArgOperand(0); - Value *Op1 = II.getArgOperand(1); - - // Folding undef to qnan is safe regardless of the FP mode. - if (isa(Op0)) { - auto *QNaN = ConstantFP::get(Ty, APFloat::getQNaN(Ty->getFltSemantics())); - return IC.replaceInstUsesWith(II, QNaN); - } - - const APFloat *C = nullptr; - match(Op0, PatternMatch::m_APFloat(C)); - - // FIXME: Should flush denorms depending on FP mode, but that's ignored - // everywhere else. - // - // These cases should be safe, even with strictfp. - // ldexp(0.0, x) -> 0.0 - // ldexp(-0.0, x) -> -0.0 - // ldexp(inf, x) -> inf - // ldexp(-inf, x) -> -inf - if (C && (C->isZero() || C->isInfinity())) { - return IC.replaceInstUsesWith(II, Op0); - } - - // With strictfp, be more careful about possibly needing to flush denormals - // or not, and snan behavior depends on ieee_mode. - if (II.isStrictFP()) - break; - - if (C && C->isNaN()) - return IC.replaceInstUsesWith(II, ConstantFP::get(Ty, C->makeQuiet())); - - // ldexp(x, 0) -> x - // ldexp(x, undef) -> x - if (isa(Op1) || match(Op1, PatternMatch::m_ZeroInt())) { - return IC.replaceInstUsesWith(II, Op0); - } - - break; - } case Intrinsic::amdgcn_fmul_legacy: { Value *Op0 = II.getArgOperand(0); Value *Op1 = II.getArgOperand(1); Index: llvm/lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- llvm/lib/Target/AMDGPU/SIISelLowering.cpp +++ llvm/lib/Target/AMDGPU/SIISelLowering.cpp @@ -7079,9 +7079,6 @@ return emitRemovedIntrinsicError(DAG, DL, VT); } - case Intrinsic::amdgcn_ldexp: - return DAG.getNode(ISD::FLDEXP, DL, VT, Op.getOperand(1), Op.getOperand(2)); - case Intrinsic::amdgcn_fract: return DAG.getNode(AMDGPUISD::FRACT, DL, VT, Op.getOperand(1)); @@ -10435,7 +10432,6 @@ case Intrinsic::amdgcn_div_fmas: case Intrinsic::amdgcn_div_fixup: case Intrinsic::amdgcn_fract: - case Intrinsic::amdgcn_ldexp: case Intrinsic::amdgcn_cvt_pkrtz: case Intrinsic::amdgcn_cubeid: case Intrinsic::amdgcn_cubema: Index: llvm/test/Bitcode/amdgcn-ldexp.ll =================================================================== --- /dev/null +++ llvm/test/Bitcode/amdgcn-ldexp.ll @@ -0,0 +1,28 @@ +; RUN: llvm-as < %s | llvm-dis | FileCheck %s + +define float @f32(float %a, i32 %b) { + ; CHECK: %call = call float @llvm.ldexp.f32.i32(float %a, i32 %b) + ; CHECK-NOT: amdgcn.ldexp + %call = call float @llvm.amdgcn.ldexp.f32(float %a, i32 %b) + ret float %call +} + +define double @f64(double %a, i32 %b) { + ; CHECK: %call = call double @llvm.ldexp.f64.i32(double %a, i32 %b) + ; CHECK-NOT: amdgcn.ldexp + %call = call double @llvm.amdgcn.ldexp.f64(double %a, i32 %b) + ret double %call +} + +define half @f16(half %a, i32 %b) { + ; CHECK: %call = call half @llvm.ldexp.f16.i32(half %a, i32 %b) + ; CHECK-NOT: amdgcn.ldexp + %call = call half @llvm.amdgcn.ldexp.f16(half %a, i32 %b) + ret half %call +} + +declare half @llvm.amdgcn.ldexp.f16(half, i32) +declare float @llvm.amdgcn.ldexp.f32(float, i32) +declare double @llvm.amdgcn.ldexp.f64(double, i32) +; CHECK: declare i32 @llvm.ldexp.f32.i32(float, i32) #0 +; CHECK-NOT: amdgcn.ldexp Index: llvm/test/CodeGen/AMDGPU/known-never-snan.ll =================================================================== --- llvm/test/CodeGen/AMDGPU/known-never-snan.ll +++ llvm/test/CodeGen/AMDGPU/known-never-snan.ll @@ -516,7 +516,7 @@ ; GCN-NEXT: v_ldexp_f32 v0, v0, v1 ; GCN-NEXT: v_med3_f32 v0, v0, 2.0, 4.0 ; GCN-NEXT: s_setpc_b64 s[30:31] - %known.not.snan = call float @llvm.amdgcn.ldexp.f32(float %a, i32 %b) + %known.not.snan = call float @llvm.ldexp.f32.i32(float %a, i32 %b) %max = call float @llvm.maxnum.f32(float %known.not.snan, float 2.0) %med = call float @llvm.minnum.f32(float %max, float 4.0) ret float %med @@ -658,7 +658,7 @@ declare float @llvm.copysign.f32(float, float) #1 declare float @llvm.fma.f32(float, float, float) #1 declare float @llvm.fmuladd.f32(float, float, float) #1 -declare float @llvm.amdgcn.ldexp.f32(float, i32) #1 +declare float @llvm.ldexp.f32.i32(float, i32) #1 declare float @llvm.amdgcn.fmul.legacy(float, float) #1 declare float @llvm.amdgcn.fmed3.f32(float, float, float) #1 declare float @llvm.amdgcn.frexp.mant.f32(float) #1