forked from OSchip/llvm-project
GlobalISel: Add fp<->int casts to MachineIRBuilder
llvm-svn: 361019
This commit is contained in:
parent
7f8ea15ffa
commit
e1a2a28d6b
|
@ -1315,6 +1315,26 @@ public:
|
|||
return buildInstr(TargetOpcode::G_FCOPYSIGN, {Dst}, {Src0, Src1});
|
||||
}
|
||||
|
||||
/// Build and insert \p Res = G_UITOFP \p Src0
|
||||
MachineInstrBuilder buildUITOFP(const DstOp &Dst, const SrcOp &Src0) {
|
||||
return buildInstr(TargetOpcode::G_UITOFP, {Dst}, {Src0});
|
||||
}
|
||||
|
||||
/// Build and insert \p Res = G_SITOFP \p Src0
|
||||
MachineInstrBuilder buildSITOFP(const DstOp &Dst, const SrcOp &Src0) {
|
||||
return buildInstr(TargetOpcode::G_SITOFP, {Dst}, {Src0});
|
||||
}
|
||||
|
||||
/// Build and insert \p Res = G_FPTOUI \p Src0
|
||||
MachineInstrBuilder buildFPTOUI(const DstOp &Dst, const SrcOp &Src0) {
|
||||
return buildInstr(TargetOpcode::G_FPTOUI, {Dst}, {Src0});
|
||||
}
|
||||
|
||||
/// Build and insert \p Res = G_FPTOSI \p Src0
|
||||
MachineInstrBuilder buildFPTOSI(const DstOp &Dst, const SrcOp &Src0) {
|
||||
return buildInstr(TargetOpcode::G_FPTOSI, {Dst}, {Src0});
|
||||
}
|
||||
|
||||
virtual MachineInstrBuilder buildInstr(unsigned Opc, ArrayRef<DstOp> DstOps,
|
||||
ArrayRef<SrcOp> SrcOps,
|
||||
Optional<unsigned> Flags = None);
|
||||
|
|
|
@ -229,3 +229,27 @@ TEST_F(GISelMITest, BuildBitCounts) {
|
|||
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
||||
TEST_F(GISelMITest, BuildCasts) {
|
||||
if (!TM)
|
||||
return;
|
||||
|
||||
LLT S32 = LLT::scalar(32);
|
||||
SmallVector<unsigned, 4> Copies;
|
||||
collectCopies(Copies, MF);
|
||||
|
||||
B.buildUITOFP(S32, Copies[0]);
|
||||
B.buildSITOFP(S32, Copies[0]);
|
||||
B.buildFPTOUI(S32, Copies[0]);
|
||||
B.buildFPTOSI(S32, Copies[0]);
|
||||
|
||||
auto CheckStr = R"(
|
||||
; CHECK: [[COPY0:%[0-9]+]]:_(s64) = COPY $x0
|
||||
; CHECK: [[UITOFP:%[0-9]+]]:_(s32) = G_UITOFP [[COPY0]]:_
|
||||
; CHECK: [[SITOFP:%[0-9]+]]:_(s32) = G_SITOFP [[COPY0]]:_
|
||||
; CHECK: [[FPTOUI:%[0-9]+]]:_(s32) = G_FPTOUI [[COPY0]]:_
|
||||
; CHECK: [[FPTOSI:%[0-9]+]]:_(s32) = G_FPTOSI [[COPY0]]:_
|
||||
)";
|
||||
|
||||
EXPECT_TRUE(CheckMachineFunction(*MF, CheckStr)) << *MF;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue