@@ -1489,11 +1489,13 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
14891489
14901490 // Check classof(), getOpcode(), getSrcTy(), getDstTy()
14911491 auto *ZExt = cast<sandboxir::CastInst>(&*It++);
1492+ EXPECT_TRUE (isa<sandboxir::ZExtInst>(ZExt));
14921493 EXPECT_EQ (ZExt->getOpcode (), sandboxir::Instruction::Opcode::ZExt);
14931494 EXPECT_EQ (ZExt->getSrcTy (), Ti32);
14941495 EXPECT_EQ (ZExt->getDestTy (), Ti64);
14951496
14961497 auto *SExt = cast<sandboxir::CastInst>(&*It++);
1498+ EXPECT_TRUE (isa<sandboxir::SExtInst>(SExt));
14971499 EXPECT_EQ (SExt->getOpcode (), sandboxir::Instruction::Opcode::SExt);
14981500 EXPECT_EQ (SExt->getSrcTy (), Ti32);
14991501 EXPECT_EQ (SExt->getDestTy (), Ti64);
@@ -1511,6 +1513,7 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
15111513 EXPECT_EQ (FPToSI->getDestTy (), Ti32);
15121514
15131515 auto *FPExt = cast<sandboxir::CastInst>(&*It++);
1516+ EXPECT_TRUE (isa<sandboxir::FPExtInst>(FPExt));
15141517 EXPECT_EQ (FPExt->getOpcode (), sandboxir::Instruction::Opcode::FPExt);
15151518 EXPECT_EQ (FPExt->getSrcTy (), Tfloat);
15161519 EXPECT_EQ (FPExt->getDestTy (), Tdouble);
@@ -1534,16 +1537,19 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
15341537 EXPECT_EQ (SIToFP->getDestTy (), Tfloat);
15351538
15361539 auto *UIToFP = cast<sandboxir::CastInst>(&*It++);
1540+ EXPECT_TRUE (isa<sandboxir::UIToFPInst>(UIToFP));
15371541 EXPECT_EQ (UIToFP->getOpcode (), sandboxir::Instruction::Opcode::UIToFP);
15381542 EXPECT_EQ (UIToFP->getSrcTy (), Ti32);
15391543 EXPECT_EQ (UIToFP->getDestTy (), Tfloat);
15401544
15411545 auto *Trunc = cast<sandboxir::CastInst>(&*It++);
1546+ EXPECT_TRUE (isa<sandboxir::TruncInst>(Trunc));
15421547 EXPECT_EQ (Trunc->getOpcode (), sandboxir::Instruction::Opcode::Trunc);
15431548 EXPECT_EQ (Trunc->getSrcTy (), Ti32);
15441549 EXPECT_EQ (Trunc->getDestTy (), Ti16);
15451550
15461551 auto *FPTrunc = cast<sandboxir::CastInst>(&*It++);
1552+ EXPECT_TRUE (isa<sandboxir::FPTruncInst>(FPTrunc));
15471553 EXPECT_EQ (FPTrunc->getOpcode (), sandboxir::Instruction::Opcode::FPTrunc);
15481554 EXPECT_EQ (FPTrunc->getSrcTy (), Tdouble);
15491555 EXPECT_EQ (FPTrunc->getDestTy (), Tfloat);
@@ -1686,6 +1692,78 @@ void testCastInst(llvm::Module &M, Type *SrcTy, Type *DstTy) {
16861692 }
16871693}
16881694
1695+ TEST_F (SandboxIRTest, TruncInst) {
1696+ parseIR (C, R"IR(
1697+ define void @foo(i64 %arg) {
1698+ %trunc = trunc i64 %arg to i32
1699+ ret void
1700+ }
1701+ )IR" );
1702+ testCastInst<sandboxir::TruncInst, sandboxir::Instruction::Opcode::Trunc>(
1703+ *M,
1704+ /* SrcTy=*/ Type::getInt64Ty (C), /* DstTy=*/ Type::getInt32Ty (C));
1705+ }
1706+
1707+ TEST_F (SandboxIRTest, ZExtInst) {
1708+ parseIR (C, R"IR(
1709+ define void @foo(i32 %arg) {
1710+ %zext = zext i32 %arg to i64
1711+ ret void
1712+ }
1713+ )IR" );
1714+ testCastInst<sandboxir::ZExtInst, sandboxir::Instruction::Opcode::ZExt>(
1715+ *M,
1716+ /* SrcTy=*/ Type::getInt32Ty (C), /* DstTy=*/ Type::getInt64Ty (C));
1717+ }
1718+
1719+ TEST_F (SandboxIRTest, SExtInst) {
1720+ parseIR (C, R"IR(
1721+ define void @foo(i32 %arg) {
1722+ %sext = sext i32 %arg to i64
1723+ ret void
1724+ }
1725+ )IR" );
1726+ testCastInst<sandboxir::SExtInst, sandboxir::Instruction::Opcode::SExt>(
1727+ *M,
1728+ /* SrcTy=*/ Type::getInt32Ty (C), /* DstTy=*/ Type::getInt64Ty (C));
1729+ }
1730+
1731+ TEST_F (SandboxIRTest, FPTruncInst) {
1732+ parseIR (C, R"IR(
1733+ define void @foo(double %arg) {
1734+ %fptrunc = fptrunc double %arg to float
1735+ ret void
1736+ }
1737+ )IR" );
1738+ testCastInst<sandboxir::FPTruncInst, sandboxir::Instruction::Opcode::FPTrunc>(
1739+ *M,
1740+ /* SrcTy=*/ Type::getDoubleTy (C), /* DstTy=*/ Type::getFloatTy (C));
1741+ }
1742+
1743+ TEST_F (SandboxIRTest, FPExtInst) {
1744+ parseIR (C, R"IR(
1745+ define void @foo(float %arg) {
1746+ %fpext = fpext float %arg to double
1747+ ret void
1748+ }
1749+ )IR" );
1750+ testCastInst<sandboxir::FPExtInst, sandboxir::Instruction::Opcode::FPExt>(
1751+ *M,
1752+ /* SrcTy=*/ Type::getFloatTy (C), /* DstTy=*/ Type::getDoubleTy (C));
1753+ }
1754+
1755+ TEST_F (SandboxIRTest, UIToFPInst) {
1756+ parseIR (C, R"IR(
1757+ define void @foo(i32 %arg) {
1758+ %uitofp = uitofp i32 %arg to float
1759+ ret void
1760+ }
1761+ )IR" );
1762+ testCastInst<sandboxir::UIToFPInst, sandboxir::Instruction::Opcode::UIToFP>(
1763+ *M,
1764+ /* SrcTy=*/ Type::getInt32Ty (C), /* DstTy=*/ Type::getFloatTy (C));
1765+ }
1766+
16891767TEST_F (SandboxIRTest, SIToFPInst) {
16901768 parseIR (C, R"IR(
16911769define void @foo(i32 %arg) {
0 commit comments