[llvm] b6b0a24 - [SandboxIR] Implement the remaining CastInst sub-classes (#101537)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 1 11:35:46 PDT 2024
Author: vporpo
Date: 2024-08-01T11:35:43-07:00
New Revision: b6b0a240d0b51ce85624a65c6e43f501371bc61b
URL: https://github.com/llvm/llvm-project/commit/b6b0a240d0b51ce85624a65c6e43f501371bc61b
DIFF: https://github.com/llvm/llvm-project/commit/b6b0a240d0b51ce85624a65c6e43f501371bc61b.diff
LOG: [SandboxIR] Implement the remaining CastInst sub-classes (#101537)
This patch implements:
sandboxir::UIToFPInst
sandboxir::FPExtInst
sandboxir::FPTruncInst
sandboxir::SExtInst
sandboxir::ZExtInst
sandboxir::TruncInst
Added:
Modified:
llvm/include/llvm/SandboxIR/SandboxIR.h
llvm/unittests/SandboxIR/SandboxIRTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/SandboxIR/SandboxIR.h b/llvm/include/llvm/SandboxIR/SandboxIR.h
index 00794048c0d7f..0bd6cdac36f9a 100644
--- a/llvm/include/llvm/SandboxIR/SandboxIR.h
+++ b/llvm/include/llvm/SandboxIR/SandboxIR.h
@@ -32,15 +32,27 @@
// | |
// | +- BitCastInst
// | |
+// | +- FPExtInst
+// | |
// | +- FPToSIInst
// | |
// | +- FPToUIInst
// | |
+// | +- FPTruncInst
+// | |
// | +- IntToPtrInst
// | |
// | +- PtrToIntInst
// | |
+// | +- SExtInst
+// | |
// | +- SIToFPInst
+// | |
+// | +- TruncInst
+// | |
+// | +- UIToFPInst
+// | |
+// | +- ZExtInst
// |
// +- CallBase -----------+- CallBrInst
// | |
@@ -1458,6 +1470,12 @@ template <Instruction::Opcode Op> class CastInstImpl : public CastInst {
}
};
+class TruncInst final : public CastInstImpl<Instruction::Opcode::Trunc> {};
+class ZExtInst final : public CastInstImpl<Instruction::Opcode::ZExt> {};
+class SExtInst final : public CastInstImpl<Instruction::Opcode::SExt> {};
+class FPTruncInst final : public CastInstImpl<Instruction::Opcode::FPTrunc> {};
+class FPExtInst final : public CastInstImpl<Instruction::Opcode::FPExt> {};
+class UIToFPInst final : public CastInstImpl<Instruction::Opcode::UIToFP> {};
class SIToFPInst final : public CastInstImpl<Instruction::Opcode::SIToFP> {};
class FPToUIInst final : public CastInstImpl<Instruction::Opcode::FPToUI> {};
class FPToSIInst final : public CastInstImpl<Instruction::Opcode::FPToSI> {};
diff --git a/llvm/unittests/SandboxIR/SandboxIRTest.cpp b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
index cbf3952850880..5f858b47926ec 100644
--- a/llvm/unittests/SandboxIR/SandboxIRTest.cpp
+++ b/llvm/unittests/SandboxIR/SandboxIRTest.cpp
@@ -1489,11 +1489,13 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
// Check classof(), getOpcode(), getSrcTy(), getDstTy()
auto *ZExt = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::ZExtInst>(ZExt));
EXPECT_EQ(ZExt->getOpcode(), sandboxir::Instruction::Opcode::ZExt);
EXPECT_EQ(ZExt->getSrcTy(), Ti32);
EXPECT_EQ(ZExt->getDestTy(), Ti64);
auto *SExt = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::SExtInst>(SExt));
EXPECT_EQ(SExt->getOpcode(), sandboxir::Instruction::Opcode::SExt);
EXPECT_EQ(SExt->getSrcTy(), Ti32);
EXPECT_EQ(SExt->getDestTy(), Ti64);
@@ -1511,6 +1513,7 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
EXPECT_EQ(FPToSI->getDestTy(), Ti32);
auto *FPExt = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::FPExtInst>(FPExt));
EXPECT_EQ(FPExt->getOpcode(), sandboxir::Instruction::Opcode::FPExt);
EXPECT_EQ(FPExt->getSrcTy(), Tfloat);
EXPECT_EQ(FPExt->getDestTy(), Tdouble);
@@ -1534,16 +1537,19 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
EXPECT_EQ(SIToFP->getDestTy(), Tfloat);
auto *UIToFP = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::UIToFPInst>(UIToFP));
EXPECT_EQ(UIToFP->getOpcode(), sandboxir::Instruction::Opcode::UIToFP);
EXPECT_EQ(UIToFP->getSrcTy(), Ti32);
EXPECT_EQ(UIToFP->getDestTy(), Tfloat);
auto *Trunc = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::TruncInst>(Trunc));
EXPECT_EQ(Trunc->getOpcode(), sandboxir::Instruction::Opcode::Trunc);
EXPECT_EQ(Trunc->getSrcTy(), Ti32);
EXPECT_EQ(Trunc->getDestTy(), Ti16);
auto *FPTrunc = cast<sandboxir::CastInst>(&*It++);
+ EXPECT_TRUE(isa<sandboxir::FPTruncInst>(FPTrunc));
EXPECT_EQ(FPTrunc->getOpcode(), sandboxir::Instruction::Opcode::FPTrunc);
EXPECT_EQ(FPTrunc->getSrcTy(), Tdouble);
EXPECT_EQ(FPTrunc->getDestTy(), Tfloat);
@@ -1686,6 +1692,78 @@ void testCastInst(llvm::Module &M, Type *SrcTy, Type *DstTy) {
}
}
+TEST_F(SandboxIRTest, TruncInst) {
+ parseIR(C, R"IR(
+define void @foo(i64 %arg) {
+ %trunc = trunc i64 %arg to i32
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::TruncInst, sandboxir::Instruction::Opcode::Trunc>(
+ *M,
+ /*SrcTy=*/Type::getInt64Ty(C), /*DstTy=*/Type::getInt32Ty(C));
+}
+
+TEST_F(SandboxIRTest, ZExtInst) {
+ parseIR(C, R"IR(
+define void @foo(i32 %arg) {
+ %zext = zext i32 %arg to i64
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::ZExtInst, sandboxir::Instruction::Opcode::ZExt>(
+ *M,
+ /*SrcTy=*/Type::getInt32Ty(C), /*DstTy=*/Type::getInt64Ty(C));
+}
+
+TEST_F(SandboxIRTest, SExtInst) {
+ parseIR(C, R"IR(
+define void @foo(i32 %arg) {
+ %sext = sext i32 %arg to i64
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::SExtInst, sandboxir::Instruction::Opcode::SExt>(
+ *M,
+ /*SrcTy=*/Type::getInt32Ty(C), /*DstTy=*/Type::getInt64Ty(C));
+}
+
+TEST_F(SandboxIRTest, FPTruncInst) {
+ parseIR(C, R"IR(
+define void @foo(double %arg) {
+ %fptrunc = fptrunc double %arg to float
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::FPTruncInst, sandboxir::Instruction::Opcode::FPTrunc>(
+ *M,
+ /*SrcTy=*/Type::getDoubleTy(C), /*DstTy=*/Type::getFloatTy(C));
+}
+
+TEST_F(SandboxIRTest, FPExtInst) {
+ parseIR(C, R"IR(
+define void @foo(float %arg) {
+ %fpext = fpext float %arg to double
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::FPExtInst, sandboxir::Instruction::Opcode::FPExt>(
+ *M,
+ /*SrcTy=*/Type::getFloatTy(C), /*DstTy=*/Type::getDoubleTy(C));
+}
+
+TEST_F(SandboxIRTest, UIToFPInst) {
+ parseIR(C, R"IR(
+define void @foo(i32 %arg) {
+ %uitofp = uitofp i32 %arg to float
+ ret void
+}
+)IR");
+ testCastInst<sandboxir::UIToFPInst, sandboxir::Instruction::Opcode::UIToFP>(
+ *M,
+ /*SrcTy=*/Type::getInt32Ty(C), /*DstTy=*/Type::getFloatTy(C));
+}
+
TEST_F(SandboxIRTest, SIToFPInst) {
parseIR(C, R"IR(
define void @foo(i32 %arg) {
More information about the llvm-commits
mailing list