@@ -5841,9 +5841,9 @@ define void @foo(i32 %i0, i32 %i1) {
5841
5841
EXPECT_EQ (ICmp->getSignedPredicate (), LLVMICmp->getSignedPredicate ());
5842
5842
EXPECT_EQ (ICmp->getUnsignedPredicate (), LLVMICmp->getUnsignedPredicate ());
5843
5843
}
5844
- auto *NewCmp =
5844
+ auto *NewCmp = cast<sandboxir::CmpInst>(
5845
5845
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" )) ;
5847
5847
EXPECT_EQ (NewCmp, &*BB->begin ());
5848
5848
EXPECT_EQ (NewCmp->getPredicate (), llvm::CmpInst::ICMP_ULE);
5849
5849
EXPECT_EQ (NewCmp->getOperand (0 ), F.getArg (0 ));
@@ -5856,6 +5856,16 @@ define void @foo(i32 %i0, i32 %i1) {
5856
5856
sandboxir::Type *RT =
5857
5857
sandboxir::CmpInst::makeCmpResultType (F.getArg (0 )->getType ());
5858
5858
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
+ }
5859
5869
}
5860
5870
5861
5871
TEST_F (SandboxIRTest, FCmpInst) {
@@ -5906,8 +5916,8 @@ define void @foo(float %f0, float %f1) {
5906
5916
CopyFrom->setFastMathFlags (FastMathFlags::getFast ());
5907
5917
5908
5918
// 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" )) ;
5911
5921
EXPECT_EQ (NewFCmp->getPredicate (), llvm::CmpInst::FCMP_ONE);
5912
5922
EXPECT_EQ (NewFCmp->getOperand (0 ), F.getArg (0 ));
5913
5923
EXPECT_EQ (NewFCmp->getOperand (1 ), F.getArg (1 ));
@@ -5917,9 +5927,10 @@ define void @foo(float %f0, float %f1) {
5917
5927
FastMathFlags DefaultFMF = NewFCmp->getFastMathFlags ();
5918
5928
EXPECT_TRUE (CopyFrom->getFastMathFlags () != DefaultFMF);
5919
5929
// 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" ));
5923
5934
EXPECT_FALSE (NewFCmpFlags->getFastMathFlags () !=
5924
5935
CopyFrom->getFastMathFlags ());
5925
5936
EXPECT_EQ (NewFCmpFlags->getPredicate (), llvm::CmpInst::FCMP_ONE);
@@ -5928,6 +5939,16 @@ define void @foo(float %f0, float %f1) {
5928
5939
#ifndef NDEBUG
5929
5940
EXPECT_EQ (NewFCmpFlags->getName (), " NewFCmpFlags" );
5930
5941
#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
+ }
5931
5952
}
5932
5953
5933
5954
TEST_F (SandboxIRTest, UnreachableInst) {
0 commit comments