[llvm] r279310 - GlobalISel: translate float/int conversion instructions.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 13:09:11 PDT 2016
Author: tnorthover
Date: Fri Aug 19 15:09:11 2016
New Revision: 279310
URL: http://llvm.org/viewvc/llvm-project?rev=279310&view=rev
Log:
GlobalISel: translate float/int conversion instructions.
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=279310&r1=279309&r2=279310&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/IRTranslator.h Fri Aug 19 15:09:11 2016
@@ -205,6 +205,19 @@ private:
bool translateTrunc(const User &U) {
return translateCast(TargetOpcode::G_TRUNC, U);
}
+ bool translateFPToUI(const User &U) {
+ return translateCast(TargetOpcode::G_FPTOUI, U);
+ }
+ bool translateFPToSI(const User &U) {
+ return translateCast(TargetOpcode::G_FPTOSI, U);
+ }
+ bool translateUIToFP(const User &U) {
+ return translateCast(TargetOpcode::G_UITOFP, U);
+ }
+ bool translateSIToFP(const User &U) {
+ return translateCast(TargetOpcode::G_SITOFP, U);
+ }
+
bool translateUnreachable(const User &U) { return true; }
bool translateSExt(const User &U) {
@@ -255,10 +268,6 @@ private:
bool translateFence(const User &U) { return false; }
bool translateAtomicCmpXchg(const User &U) { return false; }
bool translateAtomicRMW(const User &U) { return false; }
- bool translateFPToUI(const User &U) { return false; }
- bool translateFPToSI(const User &U) { return false; }
- bool translateUIToFP(const User &U) { return false; }
- bool translateSIToFP(const User &U) { return false; }
bool translateFPTrunc(const User &U) { return false; }
bool translateFPExt(const User &U) { return false; }
bool translateAddrSpaceCast(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=279310&r1=279309&r2=279310&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/GenericOpcodes.td (original)
+++ llvm/trunk/include/llvm/Target/GenericOpcodes.td Fri Aug 19 15:09:11 2016
@@ -248,6 +248,34 @@ def G_SMULO : Instruction {
}
//------------------------------------------------------------------------------
+// Floating Point Unary Ops.
+//------------------------------------------------------------------------------
+
+def G_FPTOSI : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src);
+ let hasSideEffects = 0;
+}
+
+def G_FPTOUI : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src);
+ let hasSideEffects = 0;
+}
+
+def G_SITOFP : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src);
+ let hasSideEffects = 0;
+}
+
+def G_UITOFP : Instruction {
+ let OutOperandList = (outs unknown:$dst);
+ let InOperandList = (ins unknown:$src);
+ let hasSideEffects = 0;
+}
+
+//------------------------------------------------------------------------------
// Floating Point Binary ops.
//------------------------------------------------------------------------------
Modified: llvm/trunk/include/llvm/Target/TargetOpcodes.def
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetOpcodes.def?rev=279310&r1=279309&r2=279310&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetOpcodes.def (original)
+++ llvm/trunk/include/llvm/Target/TargetOpcodes.def Fri Aug 19 15:09:11 2016
@@ -304,6 +304,17 @@ HANDLE_TARGET_OPCODE(G_FDIV)
/// Generic FP remainder.
HANDLE_TARGET_OPCODE(G_FREM)
+/// Generic float to signed-int conversion
+HANDLE_TARGET_OPCODE(G_FPTOSI)
+
+/// Generic float to unsigned-int conversion
+HANDLE_TARGET_OPCODE(G_FPTOUI)
+
+/// Generic signed-int to float conversion
+HANDLE_TARGET_OPCODE(G_SITOFP)
+
+/// Generic unsigned-int to float conversion
+HANDLE_TARGET_OPCODE(G_UITOFP)
/// 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=279310&r1=279309&r2=279310&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll Fri Aug 19 15:09:11 2016
@@ -740,3 +740,47 @@ define i32 @test_select(i1 %tst, i32 %lh
%res = select i1 %tst, i32 %lhs, i32 %rhs
ret i32 %res
}
+
+; CHECK-LABEL: name: test_fptosi
+; CHECK: [[FPADDR:%[0-9]+]](64) = COPY %x0
+; CHECK: [[FP:%[0-9]+]](32) = G_LOAD { s32, p0 } [[FPADDR]]
+; CHECK: [[RES:%[0-9]+]](64) = G_FPTOSI { s64, s32 } [[FP]]
+; CHECK: %x0 = COPY [[RES]]
+define i64 @test_fptosi(float* %fp.addr) {
+ %fp = load float, float* %fp.addr
+ %res = fptosi float %fp to i64
+ ret i64 %res
+}
+
+; CHECK-LABEL: name: test_fptoui
+; CHECK: [[FPADDR:%[0-9]+]](64) = COPY %x0
+; CHECK: [[FP:%[0-9]+]](32) = G_LOAD { s32, p0 } [[FPADDR]]
+; CHECK: [[RES:%[0-9]+]](64) = G_FPTOUI { s64, s32 } [[FP]]
+; CHECK: %x0 = COPY [[RES]]
+define i64 @test_fptoui(float* %fp.addr) {
+ %fp = load float, float* %fp.addr
+ %res = fptoui float %fp to i64
+ ret i64 %res
+}
+
+; CHECK-LABEL: name: test_sitofp
+; CHECK: [[ADDR:%[0-9]+]](64) = COPY %x0
+; CHECK: [[IN:%[0-9]+]](32) = COPY %w1
+; CHECK: [[FP:%[0-9]+]](64) = G_SITOFP { s64, s32 } [[IN]]
+; CHECK: G_STORE { s64, p0 } [[FP]], [[ADDR]]
+define void @test_sitofp(double* %addr, i32 %in) {
+ %fp = sitofp i32 %in to double
+ store double %fp, double* %addr
+ ret void
+}
+
+; CHECK-LABEL: name: test_uitofp
+; CHECK: [[ADDR:%[0-9]+]](64) = COPY %x0
+; CHECK: [[IN:%[0-9]+]](32) = COPY %w1
+; CHECK: [[FP:%[0-9]+]](64) = G_UITOFP { s64, s32 } [[IN]]
+; CHECK: G_STORE { s64, p0 } [[FP]], [[ADDR]]
+define void @test_uitofp(double* %addr, i32 %in) {
+ %fp = uitofp i32 %in to double
+ store double %fp, double* %addr
+ ret void
+}
More information about the llvm-commits
mailing list