[IRTranslator] Add G_SUB opcode.

This commit adds a generic SUB opcode to global-isel.

llvm-svn: 276308
This commit is contained in:
Quentin Colombet 2016-07-21 17:26:50 +00:00
parent a4bcc3f069
commit 2b59eab79f
4 changed files with 36 additions and 0 deletions

View File

@ -23,6 +23,14 @@ def G_ADD : Instruction {
let isCommutable = 1;
}
// Generic subtraction.
def G_SUB : Instruction {
let OutOperandList = (outs unknown:$dst);
let InOperandList = (ins unknown:$src1, unknown:$src2);
let hasSideEffects = 0;
let isCommutable = 0;
}
// Generic bitwise and.
def G_AND : Instruction {
let OutOperandList = (outs unknown:$dst);

View File

@ -159,6 +159,9 @@ HANDLE_TARGET_OPCODE(PATCHABLE_RET)
HANDLE_TARGET_OPCODE(G_ADD)
HANDLE_TARGET_OPCODE_MARKER(PRE_ISEL_GENERIC_OPCODE_START, G_ADD)
/// Generic SUB instruction. This is an integer sub.
HANDLE_TARGET_OPCODE(G_SUB)
/// Generic Bitwise-AND instruction.
HANDLE_TARGET_OPCODE(G_AND)

View File

@ -105,6 +105,8 @@ bool IRTranslator::translate(const Instruction &Inst) {
// Arithmetic operations.
case Instruction::Add:
return translateBinaryOp(TargetOpcode::G_ADD, Inst);
case Instruction::Sub:
return translateBinaryOp(TargetOpcode::G_SUB, Inst);
// Bitwise operations.
case Instruction::And:
return translateBinaryOp(TargetOpcode::G_AND, Inst);

View File

@ -84,3 +84,26 @@ define i32 @andi32(i32 %arg1, i32 %arg2) {
%res = and i32 %arg1, %arg2
ret i32 %res
}
; Tests for sub.
; CHECK: name: subi64
; CHECK: [[ARG1:%[0-9]+]](64) = COPY %x0
; CHECK-NEXT: [[ARG2:%[0-9]+]](64) = COPY %x1
; CHECK-NEXT: [[RES:%[0-9]+]](64) = G_SUB s64 [[ARG1]], [[ARG2]]
; CHECK-NEXT: %x0 = COPY [[RES]]
; CHECK-NEXT: RET_ReallyLR implicit %x0
define i64 @subi64(i64 %arg1, i64 %arg2) {
%res = sub i64 %arg1, %arg2
ret i64 %res
}
; CHECK: name: subi32
; CHECK: [[ARG1:%[0-9]+]](32) = COPY %w0
; CHECK-NEXT: [[ARG2:%[0-9]+]](32) = COPY %w1
; CHECK-NEXT: [[RES:%[0-9]+]](32) = G_SUB s32 [[ARG1]], [[ARG2]]
; CHECK-NEXT: %w0 = COPY [[RES]]
; CHECK-NEXT: RET_ReallyLR implicit %w0
define i32 @subi32(i32 %arg1, i32 %arg2) {
%res = sub i32 %arg1, %arg2
ret i32 %res
}