@@ -1489,11 +1489,13 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
1489
1489
1490
1490
// Check classof(), getOpcode(), getSrcTy(), getDstTy()
1491
1491
auto *ZExt = cast<sandboxir::CastInst>(&*It++);
1492
+ EXPECT_TRUE (isa<sandboxir::ZExtInst>(ZExt));
1492
1493
EXPECT_EQ (ZExt->getOpcode (), sandboxir::Instruction::Opcode::ZExt);
1493
1494
EXPECT_EQ (ZExt->getSrcTy (), Ti32);
1494
1495
EXPECT_EQ (ZExt->getDestTy (), Ti64);
1495
1496
1496
1497
auto *SExt = cast<sandboxir::CastInst>(&*It++);
1498
+ EXPECT_TRUE (isa<sandboxir::SExtInst>(SExt));
1497
1499
EXPECT_EQ (SExt->getOpcode (), sandboxir::Instruction::Opcode::SExt);
1498
1500
EXPECT_EQ (SExt->getSrcTy (), Ti32);
1499
1501
EXPECT_EQ (SExt->getDestTy (), Ti64);
@@ -1511,6 +1513,7 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
1511
1513
EXPECT_EQ (FPToSI->getDestTy (), Ti32);
1512
1514
1513
1515
auto *FPExt = cast<sandboxir::CastInst>(&*It++);
1516
+ EXPECT_TRUE (isa<sandboxir::FPExtInst>(FPExt));
1514
1517
EXPECT_EQ (FPExt->getOpcode (), sandboxir::Instruction::Opcode::FPExt);
1515
1518
EXPECT_EQ (FPExt->getSrcTy (), Tfloat);
1516
1519
EXPECT_EQ (FPExt->getDestTy (), Tdouble);
@@ -1534,16 +1537,19 @@ define void @foo(i32 %arg, float %farg, double %darg, ptr %ptr) {
1534
1537
EXPECT_EQ (SIToFP->getDestTy (), Tfloat);
1535
1538
1536
1539
auto *UIToFP = cast<sandboxir::CastInst>(&*It++);
1540
+ EXPECT_TRUE (isa<sandboxir::UIToFPInst>(UIToFP));
1537
1541
EXPECT_EQ (UIToFP->getOpcode (), sandboxir::Instruction::Opcode::UIToFP);
1538
1542
EXPECT_EQ (UIToFP->getSrcTy (), Ti32);
1539
1543
EXPECT_EQ (UIToFP->getDestTy (), Tfloat);
1540
1544
1541
1545
auto *Trunc = cast<sandboxir::CastInst>(&*It++);
1546
+ EXPECT_TRUE (isa<sandboxir::TruncInst>(Trunc));
1542
1547
EXPECT_EQ (Trunc->getOpcode (), sandboxir::Instruction::Opcode::Trunc);
1543
1548
EXPECT_EQ (Trunc->getSrcTy (), Ti32);
1544
1549
EXPECT_EQ (Trunc->getDestTy (), Ti16);
1545
1550
1546
1551
auto *FPTrunc = cast<sandboxir::CastInst>(&*It++);
1552
+ EXPECT_TRUE (isa<sandboxir::FPTruncInst>(FPTrunc));
1547
1553
EXPECT_EQ (FPTrunc->getOpcode (), sandboxir::Instruction::Opcode::FPTrunc);
1548
1554
EXPECT_EQ (FPTrunc->getSrcTy (), Tdouble);
1549
1555
EXPECT_EQ (FPTrunc->getDestTy (), Tfloat);
@@ -1686,6 +1692,78 @@ void testCastInst(llvm::Module &M, Type *SrcTy, Type *DstTy) {
1686
1692
}
1687
1693
}
1688
1694
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
+
1689
1767
TEST_F (SandboxIRTest, SIToFPInst) {
1690
1768
parseIR (C, R"IR(
1691
1769
define void @foo(i32 %arg) {
0 commit comments