]> granicus.if.org Git - llvm/commitdiff
GlobalISel: Add fp<->int casts to MachineIRBuilder
authorMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 17 May 2019 11:49:39 +0000 (11:49 +0000)
committerMatt Arsenault <Matthew.Arsenault@amd.com>
Fri, 17 May 2019 11:49:39 +0000 (11:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@361019 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/GlobalISel/MachineIRBuilder.h
unittests/CodeGen/GlobalISel/MachineIRBuilderTest.cpp

index e45a07d231b14b173c7fb1d5da0e47ae31f40b66..10c3dc77e139bd1d688684391a6e0219a6a89b95 100644 (file)
@@ -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);
index c696620958d6ea34df8840f444f8d2f4fdfb2ef6..04f72708b5f5eaf65d46e5f9ccda668239b9abb2 100644 (file)
@@ -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;
+}