@@ -5841,9 +5841,9 @@ define void @foo(i32 %i0, i32 %i1) {
58415841 EXPECT_EQ (ICmp->getSignedPredicate (), LLVMICmp->getSignedPredicate ());
58425842 EXPECT_EQ (ICmp->getUnsignedPredicate (), LLVMICmp->getUnsignedPredicate ());
58435843 }
5844- auto *NewCmp =
5844+ auto *NewCmp = cast<sandboxir::CmpInst>(
58455845 sandboxir::CmpInst::create (llvm::CmpInst::ICMP_ULE, F.getArg (0 ),
5846- F.getArg (1 ), BB->begin (), Ctx, " NewCmp" );
5846+ F.getArg (1 ), BB->begin (), Ctx, " NewCmp" )) ;
58475847 EXPECT_EQ (NewCmp, &*BB->begin ());
58485848 EXPECT_EQ (NewCmp->getPredicate (), llvm::CmpInst::ICMP_ULE);
58495849 EXPECT_EQ (NewCmp->getOperand (0 ), F.getArg (0 ));
@@ -5856,6 +5856,16 @@ define void @foo(i32 %i0, i32 %i1) {
58565856 sandboxir::Type *RT =
58575857 sandboxir::CmpInst::makeCmpResultType (F.getArg (0 )->getType ());
58585858 EXPECT_TRUE (RT->isIntegerTy (1 )); // Only one bit in a single comparison
5859+
5860+ {
5861+ // Check create() when operands are constant.
5862+ auto *Const42 =
5863+ sandboxir::ConstantInt::get (sandboxir::Type::getInt32Ty (Ctx), 42 );
5864+ auto *NewConstCmp =
5865+ sandboxir::CmpInst::create (llvm::CmpInst::ICMP_ULE, Const42, Const42,
5866+ BB->begin (), Ctx, " NewConstCmp" );
5867+ EXPECT_TRUE (isa<sandboxir::Constant>(NewConstCmp));
5868+ }
58595869}
58605870
58615871TEST_F (SandboxIRTest, FCmpInst) {
@@ -5906,8 +5916,8 @@ define void @foo(float %f0, float %f1) {
59065916 CopyFrom->setFastMathFlags (FastMathFlags::getFast ());
59075917
59085918 // create with default flags
5909- auto *NewFCmp = sandboxir::CmpInst::create (
5910- llvm::CmpInst::FCMP_ONE, F.getArg (0 ), F.getArg (1 ), It1, Ctx, " NewFCmp" );
5919+ auto *NewFCmp = cast<sandboxir::CmpInst>( sandboxir::CmpInst::create (
5920+ llvm::CmpInst::FCMP_ONE, F.getArg (0 ), F.getArg (1 ), It1, Ctx, " NewFCmp" )) ;
59115921 EXPECT_EQ (NewFCmp->getPredicate (), llvm::CmpInst::FCMP_ONE);
59125922 EXPECT_EQ (NewFCmp->getOperand (0 ), F.getArg (0 ));
59135923 EXPECT_EQ (NewFCmp->getOperand (1 ), F.getArg (1 ));
@@ -5917,9 +5927,10 @@ define void @foo(float %f0, float %f1) {
59175927 FastMathFlags DefaultFMF = NewFCmp->getFastMathFlags ();
59185928 EXPECT_TRUE (CopyFrom->getFastMathFlags () != DefaultFMF);
59195929 // create with copied flags
5920- auto *NewFCmpFlags = sandboxir::CmpInst::createWithCopiedFlags (
5921- llvm::CmpInst::FCMP_ONE, F.getArg (0 ), F.getArg (1 ), CopyFrom, It1, Ctx,
5922- " NewFCmpFlags" );
5930+ auto *NewFCmpFlags =
5931+ cast<sandboxir::CmpInst>(sandboxir::CmpInst::createWithCopiedFlags (
5932+ llvm::CmpInst::FCMP_ONE, F.getArg (0 ), F.getArg (1 ), CopyFrom, It1, Ctx,
5933+ " NewFCmpFlags" ));
59235934 EXPECT_FALSE (NewFCmpFlags->getFastMathFlags () !=
59245935 CopyFrom->getFastMathFlags ());
59255936 EXPECT_EQ (NewFCmpFlags->getPredicate (), llvm::CmpInst::FCMP_ONE);
@@ -5928,6 +5939,16 @@ define void @foo(float %f0, float %f1) {
59285939#ifndef NDEBUG
59295940 EXPECT_EQ (NewFCmpFlags->getName (), " NewFCmpFlags" );
59305941#endif // NDEBUG
5942+
5943+ {
5944+ // Check create() when operands are constant.
5945+ auto *Const42 =
5946+ sandboxir::ConstantFP::get (sandboxir::Type::getFloatTy (Ctx), 42.0 );
5947+ auto *NewConstCmp =
5948+ sandboxir::CmpInst::create (llvm::CmpInst::FCMP_ULE, Const42, Const42,
5949+ BB->begin (), Ctx, " NewConstCmp" );
5950+ EXPECT_TRUE (isa<sandboxir::Constant>(NewConstCmp));
5951+ }
59315952}
59325953
59335954TEST_F (SandboxIRTest, UnreachableInst) {
0 commit comments