]> granicus.if.org Git - llvm/commitdiff
GlobalISel: translate @llvm.pow intrinsic to G_FPOW.
authorTim Northover <tnorthover@apple.com>
Wed, 8 Feb 2017 23:23:32 +0000 (23:23 +0000)
committerTim Northover <tnorthover@apple.com>
Wed, 8 Feb 2017 23:23:32 +0000 (23:23 +0000)
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

include/llvm/Target/GenericOpcodes.td
include/llvm/Target/TargetOpcodes.def
lib/CodeGen/GlobalISel/IRTranslator.cpp
test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll

index 8d01bd2c5bdfc27dee59591dcc391d0cf3454334..09b03bcb20c8e1f6d19c12aa5279c063cc6cae07 100644 (file)
@@ -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
 //------------------------------------------------------------------------------
index 8f209ecb03b21d72a1fe61480ce01e2bd6281938..7987dddc5b2a65dd8593ec0c46e08761da454e28 100644 (file)
@@ -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)
 
index 8b06f4dc23498a394e4d40b9144507918cec5ab6..361efe6c1d6438a1a02dd9e46fb40cb93a858aa7 100644 (file)
@@ -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:
index 943a57f55cbca96aec5b735436e99e2bbdfbcca5..e658a09858da87bff1abd91f650da04d15c23605 100644 (file)
@@ -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
+}