[llvm] r278410 - GlobalISel: add translation support for shift operations.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 11 14:01:13 PDT 2016
Author: tnorthover
Date: Thu Aug 11 16:01:13 2016
New Revision: 278410
URL: http://llvm.org/viewvc/llvm-project?rev=278410&view=rev
Log:
GlobalISel: add translation support for shift operations.
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
llvm/trunk/include/llvm/Target/GenericOpcodes.td
llvm/trunk/include/llvm/Target/TargetOpcodes.def
llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h?rev=278410&r1=278409&r2=278410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Thu Aug 11 16:01:13 2016
@@ -144,6 +144,12 @@ private:
/// \pre \p U is a branch instruction.
bool translateBr(const User &U);
+ /// Translate return (ret) instruction.
+ /// The target needs to implement CallLowering::lowerReturn for
+ /// this to succeed.
+ /// \pre \p U is a return instruction.
+ bool translateRet(const User &U);
+
bool translateAdd(const User &U) {
return translateBinaryOp(TargetOpcode::G_ADD, U);
}
@@ -184,11 +190,15 @@ private:
return translateCast(TargetOpcode::G_ZEXT, U);
}
- /// Translate return (ret) instruction.
- /// The target needs to implement CallLowering::lowerReturn for
- /// this to succeed.
- /// \pre \p U is a return instruction.
- bool translateRet(const User &U);
+ bool translateShl(const User &U) {
+ return translateBinaryOp(TargetOpcode::G_SHL, U);
+ }
+ bool translateLShr(const User &U) {
+ return translateBinaryOp(TargetOpcode::G_LSHR, U);
+ }
+ bool translateAShr(const User &U) {
+ return translateBinaryOp(TargetOpcode::G_ASHR, U);
+ }
// Stubs to keep the compiler happy while we implement the rest of the
// translation.
@@ -208,9 +218,6 @@ private:
bool translateURem(const User &U) { return false; }
bool translateSRem(const User &U) { return false; }
bool translateFRem(const User &U) { return false; }
- bool translateShl(const User &U) { return false; }
- bool translateLShr(const User &U) { return false; }
- bool translateAShr(const User &U) { return false; }
bool translateGetElementPtr(const User &U) { return false; }
bool translateFence(const User &U) { return false; }
bool translateAtomicCmpXchg(const User &U) { return false; }
Modified: llvm/trunk/include/llvm/Target/GenericOpcodes.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/GenericOpcodes.td?rev=278410&r1=278409&r2=278410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GenericOpcodes.td (original)
+++ llvm/trunk/include/llvm/Target/GenericOpcodes.td Thu Aug 11 16:01:13 2016
@@ -139,6 +139,27 @@ def G_XOR : Instruction {
let isCommutable = 1;
}
+// Generic left-shift.
+def G_SHL : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src1, unknown:$src2);
+ let hasSideEffects = 0;
+}
+
+// Generic logical right-shift.
+def G_LSHR : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src1, unknown:$src2);
+ let hasSideEffects = 0;
+}
+
+// Generic arithmetic right-shift.
+def G_ASHR : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src1, unknown:$src2);
+ let hasSideEffects = 0;
+}
+
//------------------------------------------------------------------------------
// Memory ops
//------------------------------------------------------------------------------
Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.def?rev=278410&r1=278409&r2=278410&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOpcodes.def (original)
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.def Thu Aug 11 16:01:13 2016
@@ -238,6 +238,15 @@ HANDLE_TARGET_OPCODE(G_SEXT)
// Generic zero extend
HANDLE_TARGET_OPCODE(G_ZEXT)
+// Generic left-shift
+HANDLE_TARGET_OPCODE(G_SHL)
+
+// Generic logical right-shift
+HANDLE_TARGET_OPCODE(G_LSHR)
+
+// Generic arithmetic right-shift
+HANDLE_TARGET_OPCODE(G_ASHR)
+
/// Generic BRANCH instruction. This is an unconditional branch.
HANDLE_TARGET_OPCODE(G_BR)
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll?rev=278410&r1=278409&r2=278410&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Thu Aug 11 16:01:13 2016
@@ -424,3 +424,37 @@ define i64 @test_zext(i32 %in) {
%res = zext i32 %in to i64
ret i64 %res
}
+
+; CHECK-LABEL: name: test_shl
+; CHECK: [[ARG1:%[0-9]+]](32) = COPY %w0
+; CHECK-NEXT: [[ARG2:%[0-9]+]](32) = COPY %w1
+; CHECK-NEXT: [[RES:%[0-9]+]](32) = G_SHL s32 [[ARG1]], [[ARG2]]
+; CHECK-NEXT: %w0 = COPY [[RES]]
+; CHECK-NEXT: RET_ReallyLR implicit %w0
+define i32 @test_shl(i32 %arg1, i32 %arg2) {
+ %res = shl i32 %arg1, %arg2
+ ret i32 %res
+}
+
+
+; CHECK-LABEL: name: test_lshr
+; CHECK: [[ARG1:%[0-9]+]](32) = COPY %w0
+; CHECK-NEXT: [[ARG2:%[0-9]+]](32) = COPY %w1
+; CHECK-NEXT: [[RES:%[0-9]+]](32) = G_LSHR s32 [[ARG1]], [[ARG2]]
+; CHECK-NEXT: %w0 = COPY [[RES]]
+; CHECK-NEXT: RET_ReallyLR implicit %w0
+define i32 @test_lshr(i32 %arg1, i32 %arg2) {
+ %res = lshr i32 %arg1, %arg2
+ ret i32 %res
+}
+
+; CHECK-LABEL: name: test_ashr
+; CHECK: [[ARG1:%[0-9]+]](32) = COPY %w0
+; CHECK-NEXT: [[ARG2:%[0-9]+]](32) = COPY %w1
+; CHECK-NEXT: [[RES:%[0-9]+]](32) = G_ASHR s32 [[ARG1]], [[ARG2]]
+; CHECK-NEXT: %w0 = COPY [[RES]]
+; CHECK-NEXT: RET_ReallyLR implicit %w0
+define i32 @test_ashr(i32 %arg1, i32 %arg2) {
+ %res = ashr i32 %arg1, %arg2
+ ret i32 %res
+}
More information about the llvm-commits
mailing list