[llvm] r279341 - GlobalISel: support legalization of G_FCONSTANTs
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 19 15:40:08 PDT 2016
Author: tnorthover
Date: Fri Aug 19 17:40:08 2016
New Revision: 279341
URL: http://llvm.org/viewvc/llvm-project?rev=279341&view=rev
Log:
GlobalISel: support legalization of G_FCONSTANTs
Modified:
llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
llvm/trunk/lib/Target/AArch64/AArch64MachineLegalizer.cpp
llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir
Modified: llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h?rev=279341&r1=279340&r2=279341&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h (original)
+++ llvm/trunk/include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h Fri Aug 19 17:40:08 2016
@@ -302,6 +302,15 @@ public:
MachineInstrBuilder buildIntrinsic(ArrayRef<LLT> Tys, Intrinsic::ID ID,
unsigned Res, bool HasSideEffects);
+ /// Build and insert \p Res<def> = G_FPTRUNC \p Ty \p Op
+ ///
+ /// G_FPTRUNC converts a floating-point value into one with a smaller type.
+ ///
+ /// \pre setBasicBlock or setMI must have been called.
+ ///
+ /// \return The newly created instruction.
+ MachineInstrBuilder buildFPTrunc(LLT Ty, unsigned Res, unsigned Op);
+
/// Build and insert \p Res<def> = G_TRUNC \p Ty \p Op
///
/// G_TRUNC extracts the low bits of a type. For a vector type each element is
Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp?rev=279341&r1=279340&r2=279341&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineIRBuilder.cpp Fri Aug 19 17:40:08 2016
@@ -211,6 +211,11 @@ MachineInstrBuilder MachineIRBuilder::bu
return buildInstr(TargetOpcode::G_TRUNC, Ty).addDef(Res).addUse(Op);
}
+MachineInstrBuilder MachineIRBuilder::buildFPTrunc(LLT Ty, unsigned Res,
+ unsigned Op) {
+ return buildInstr(TargetOpcode::G_FPTRUNC, Ty).addDef(Res).addUse(Op);
+}
+
MachineInstrBuilder MachineIRBuilder::buildICmp(ArrayRef<LLT> Tys,
CmpInst::Predicate Pred,
unsigned Res, unsigned Op0,
Modified: llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp?rev=279341&r1=279340&r2=279341&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp (original)
+++ llvm/trunk/lib/CodeGen/GlobalISel/MachineLegalizeHelper.cpp Fri Aug 19 17:40:08 2016
@@ -141,6 +141,14 @@ MachineLegalizeHelper::widenScalar(Machi
MI.eraseFromParent();
return Legalized;
}
+ case TargetOpcode::G_FCONSTANT: {
+ MIRBuilder.setInstr(MI);
+ unsigned DstExt = MRI.createGenericVirtualRegister(WideSize);
+ MIRBuilder.buildFConstant(WideTy, DstExt, *MI.getOperand(1).getFPImm());
+ MIRBuilder.buildFPTrunc(MI.getType(), MI.getOperand(0).getReg(), DstExt);
+ MI.eraseFromParent();
+ return Legalized;
+ }
}
}
Modified: llvm/trunk/lib/Target/AArch64/AArch64MachineLegalizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64MachineLegalizer.cpp?rev=279341&r1=279340&r2=279341&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64MachineLegalizer.cpp (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64MachineLegalizer.cpp Fri Aug 19 17:40:08 2016
@@ -63,6 +63,7 @@ AArch64MachineLegalizer::AArch64MachineL
for (auto Ty : {s1, s8, s16})
setAction(TargetOpcode::G_CONSTANT, Ty, WidenScalar);
+ setAction(TargetOpcode::G_FCONSTANT, s16, WidenScalar);
setAction(G_BR, LLT::unsized(), Legal);
Modified: llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir?rev=279341&r1=279340&r2=279341&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir (original)
+++ llvm/trunk/test/CodeGen/AArch64/GlobalISel/legalize-constant.mir Fri Aug 19 17:40:08 2016
@@ -53,7 +53,10 @@ body: |
; CHECK-LABEL: name: test_fconstant
; CHECK: %0(32) = G_FCONSTANT s32 float 1.000000e+00
; CHECK: %1(64) = G_FCONSTANT s64 double 2.000000e+00
+ ; CHECK: [[TMP:%[0-9]+]](32) = G_FCONSTANT s32 half 0xH0000
+ ; CHECK; %2(16) = G_FPTRUNC s16 [[TMP]]
%0(32) = G_FCONSTANT s32 float 1.0
%1(64) = G_FCONSTANT s64 double 2.0
+ %2(16) = G_FCONSTANT s16 half 0.0
...
More information about the llvm-commits
mailing list