Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Add support for the LLVM FNeg instruction
Browse files Browse the repository at this point in the history
Closes #216

COPYBARA_INTEGRATE_REVIEW=#216 from schweitzpgi:llvmir-fneg-op f9b5f18
PiperOrigin-RevId: 278795325
  • Loading branch information
schweitzpgi authored and tensorflower-gardener committed Nov 6, 2019
1 parent b289b88 commit 199f413
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ class LLVM_ArithmeticOp<string mnemonic, string builderFunc,
let parser = [{ return impl::parseOneResultSameOperandTypeOp(parser, result); }];
let printer = [{ mlir::impl::printOneResultOp(this->getOperation(), p); }];
}
class LLVM_UnaryArithmeticOp<string mnemonic, string builderFunc,
list<OpTrait> traits = []> :
LLVM_OneResultOp<mnemonic,
!listconcat([NoSideEffect, SameOperandsAndResultType], traits)>,
Arguments<(ins LLVM_Type:$operand)>,
LLVM_Builder<"$res = builder." # builderFunc # "($operand);"> {
let parser = [{ return impl::parseOneResultSameOperandTypeOp(parser, result); }];
let printer = [{ mlir::impl::printOneResultOp(this->getOperation(), p); }];
}

// Integer binary operations.
def LLVM_AddOp : LLVM_ArithmeticOp<"add", "CreateAdd", [Commutative]>;
Expand Down Expand Up @@ -247,6 +256,7 @@ def LLVM_FSubOp : LLVM_ArithmeticOp<"fsub", "CreateFSub">;
def LLVM_FMulOp : LLVM_ArithmeticOp<"fmul", "CreateFMul">;
def LLVM_FDivOp : LLVM_ArithmeticOp<"fdiv", "CreateFDiv">;
def LLVM_FRemOp : LLVM_ArithmeticOp<"frem", "CreateFRem">;
def LLVM_FNegOp : LLVM_UnaryArithmeticOp<"fneg", "CreateFNeg">;

// Memory-related operations.
def LLVM_AllocaOp :
Expand Down
3 changes: 3 additions & 0 deletions test/Dialect/LLVMIR/roundtrip.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func @ops(%arg0 : !llvm.i32, %arg1 : !llvm.float) {
%27 = llvm.fpext %arg1 : !llvm.float to !llvm.x86_fp80
%28 = llvm.fpext %arg1 : !llvm.float to !llvm.fp128

// CHECK: %29 = llvm.fneg %arg1 : !llvm.float
%29 = llvm.fneg %arg1 : !llvm.float

// CHECK: llvm.return
llvm.return
}
Expand Down
3 changes: 3 additions & 0 deletions test/Target/llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,9 @@ llvm.func @ops(%arg0: !llvm.float, %arg1: !llvm.float, %arg2: !llvm.i32, %arg3:
// CHECK-NEXT: %22 = ashr i32 %2, %3
%18 = llvm.ashr %arg2, %arg3 : !llvm.i32

// CHECK-NEXT: fneg float %0
%19 = llvm.fneg %arg0 : !llvm.float

llvm.return %10 : !llvm<"{ float, i32 }">
}

Expand Down

0 comments on commit 199f413

Please sign in to comment.