From: Tim Northover Date: Wed, 8 Feb 2017 23:23:32 +0000 (+0000) Subject: GlobalISel: translate @llvm.pow intrinsic to G_FPOW. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d8f030286c2549fb3fdc87de13b54513b1cfb835;p=llvm GlobalISel: translate @llvm.pow intrinsic to G_FPOW. It'll usually be immediately legalized back to a libcall, but occasionally something can be done with it so we'd just as well enable that flexibility from the start. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@294530 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Target/GenericOpcodes.td b/include/llvm/Target/GenericOpcodes.td index 8d01bd2c5bd..09b03bcb20c 100644 --- a/include/llvm/Target/GenericOpcodes.td +++ b/include/llvm/Target/GenericOpcodes.td @@ -380,6 +380,13 @@ def G_FREM : Instruction { let hasSideEffects = 0; } +// Floating point exponentiation. +def G_FPOW : Instruction { + let OutOperandList = (outs type0:$dst); + let InOperandList = (ins type0:$src1, type0:$src2); + let hasSideEffects = 0; +} + //------------------------------------------------------------------------------ // Memory ops //------------------------------------------------------------------------------ diff --git a/include/llvm/Target/TargetOpcodes.def b/include/llvm/Target/TargetOpcodes.def index 8f209ecb03b..7987dddc5b2 100644 --- a/include/llvm/Target/TargetOpcodes.def +++ b/include/llvm/Target/TargetOpcodes.def @@ -354,6 +354,9 @@ HANDLE_TARGET_OPCODE(G_FDIV) /// Generic FP remainder. HANDLE_TARGET_OPCODE(G_FREM) +/// Generic FP exponentiation. +HANDLE_TARGET_OPCODE(G_FPOW) + /// Generic float to signed-int conversion HANDLE_TARGET_OPCODE(G_FPEXT) diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index 8b06f4dc234..361efe6c1d6 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -636,6 +636,12 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID, return translateOverflowIntrinsic(CI, TargetOpcode::G_UMULO, MIRBuilder); case Intrinsic::smul_with_overflow: return translateOverflowIntrinsic(CI, TargetOpcode::G_SMULO, MIRBuilder); + case Intrinsic::pow: + MIRBuilder.buildInstr(TargetOpcode::G_FPOW) + .addDef(getOrCreateVReg(CI)) + .addUse(getOrCreateVReg(*CI.getArgOperand(0))) + .addUse(getOrCreateVReg(*CI.getArgOperand(1))); + return true; case Intrinsic::memcpy: case Intrinsic::memmove: case Intrinsic::memset: diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index 943a57f55cb..e658a09858d 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -1133,3 +1133,14 @@ define void @test_va_end(i8* %list) { call void @llvm.va_end(i8* %list) ret void } + +declare float @llvm.pow.f32(float, float) +define float @test_pow_intrin(float %l, float %r) { +; CHECK-LABEL: name: test_pow_intrin +; CHECK: [[LHS:%[0-9]+]](s32) = COPY %s0 +; CHECK: [[RHS:%[0-9]+]](s32) = COPY %s1 +; CHECK: [[RES:%[0-9]+]](s32) = G_FPOW [[LHS]], [[RHS]] +; CHECK: %s0 = COPY [[RES]] + %res = call float @llvm.pow.f32(float %l, float %r) + ret float %res +}