Skip to content

Commit

Permalink
[GISel]: Add G_FEXP, G_FEXP2 opcodes
Browse files Browse the repository at this point in the history
Also add IRTranslator support.
https://reviews.llvm.org/D34710

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306475 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Aditya Nandakumar committed Jun 27, 2017
1 parent c9c6332 commit 69d966c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/llvm/Target/GenericOpcodes.td
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,19 @@ def G_FPOW : Instruction {
let hasSideEffects = 0;
}

// Floating point base-e exponential of a value.
def G_FEXP : Instruction {
let OutOperandList = (outs type0:$dst);
let InOperandList = (ins type0:$src1);
let hasSideEffects = 0;
}

// Floating point base-2 exponential of a value.
def G_FEXP2 : Instruction {
let OutOperandList = (outs type0:$dst);
let InOperandList = (ins type0:$src1);
let hasSideEffects = 0;
}
//------------------------------------------------------------------------------
// Memory ops
//------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions include/llvm/Target/GlobalISel/SelectionDAGCompat.td
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def : GINodeEquiv<G_FMUL, fmul>;
def : GINodeEquiv<G_FDIV, fdiv>;
def : GINodeEquiv<G_FREM, frem>;
def : GINodeEquiv<G_FPOW, fpow>;
def : GINodeEquiv<G_FEXP2, fexp2>;
def : GINodeEquiv<G_BR, br>;

// Specifies the GlobalISel equivalents for SelectionDAG's ComplexPattern.
Expand Down
6 changes: 6 additions & 0 deletions include/llvm/Target/TargetOpcodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,12 @@ HANDLE_TARGET_OPCODE(G_FREM)
/// Generic FP exponentiation.
HANDLE_TARGET_OPCODE(G_FPOW)

/// Generic base-e exponential of a value.
HANDLE_TARGET_OPCODE(G_FEXP)

/// Generic base-2 exponential of a value.
HANDLE_TARGET_OPCODE(G_FEXP2)

/// Generic FP negation.
HANDLE_TARGET_OPCODE(G_FNEG)

Expand Down
10 changes: 10 additions & 0 deletions lib/CodeGen/GlobalISel/IRTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,16 @@ bool IRTranslator::translateKnownIntrinsic(const CallInst &CI, Intrinsic::ID ID,
.addUse(getOrCreateVReg(*CI.getArgOperand(0)))
.addUse(getOrCreateVReg(*CI.getArgOperand(1)));
return true;
case Intrinsic::exp:
MIRBuilder.buildInstr(TargetOpcode::G_FEXP)
.addDef(getOrCreateVReg(CI))
.addUse(getOrCreateVReg(*CI.getArgOperand(0)));
return true;
case Intrinsic::exp2:
MIRBuilder.buildInstr(TargetOpcode::G_FEXP2)
.addDef(getOrCreateVReg(CI))
.addUse(getOrCreateVReg(*CI.getArgOperand(0)));
return true;
case Intrinsic::fma:
MIRBuilder.buildInstr(TargetOpcode::G_FMA)
.addDef(getOrCreateVReg(CI))
Expand Down
20 changes: 20 additions & 0 deletions test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,26 @@ define float @test_fma_intrin(float %a, float %b, float %c) {
ret float %res
}

declare float @llvm.exp.f32(float)
define float @test_exp_intrin(float %a) {
; CHECK-LABEL: name: test_exp_intrin
; CHECK: [[A:%[0-9]+]](s32) = COPY %s0
; CHECK: [[RES:%[0-9]+]](s32) = G_FEXP [[A]]
; CHECK: %s0 = COPY [[RES]]
%res = call float @llvm.exp.f32(float %a)
ret float %res
}

declare float @llvm.exp2.f32(float)
define float @test_exp2_intrin(float %a) {
; CHECK-LABEL: name: test_exp2_intrin
; CHECK: [[A:%[0-9]+]](s32) = COPY %s0
; CHECK: [[RES:%[0-9]+]](s32) = G_FEXP2 [[A]]
; CHECK: %s0 = COPY [[RES]]
%res = call float @llvm.exp2.f32(float %a)
ret float %res
}

declare void @llvm.lifetime.start.p0i8(i64, i8*)
declare void @llvm.lifetime.end.p0i8(i64, i8*)
define void @test_lifetime_intrin() {
Expand Down

0 comments on commit 69d966c

Please sign in to comment.