[llvm] [SandboxIR] Implement CmpInst, FCmpInst, and ICmpInst (PR #106301)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 30 12:33:04 PDT 2024
================
@@ -4392,6 +4392,159 @@ define void @foo(i32 %arg) {
EXPECT_EQ(NewPHI->getNumIncomingValues(), PHI->getNumIncomingValues());
}
+static void checkSwapOperands(sandboxir::Context &Ctx,
+ llvm::sandboxir::CmpInst *Cmp,
+ llvm::CmpInst *LLVMCmp) {
+ auto OrigOp0 = Cmp->getOperand(0);
+ auto OrigOp1 = Cmp->getOperand(1);
+ EXPECT_EQ(Ctx.getValue(LLVMCmp->getOperand(0)), OrigOp0);
+ EXPECT_EQ(Ctx.getValue(LLVMCmp->getOperand(1)), OrigOp1);
+ // This checks the dispatch mechanism in CmpInst, as well as
+ // the specific implementations.
+ Cmp->swapOperands();
+ EXPECT_EQ(Ctx.getValue(LLVMCmp->getOperand(1)), OrigOp0);
+ EXPECT_EQ(Ctx.getValue(LLVMCmp->getOperand(0)), OrigOp1);
----------------
vporpo wrote:
We have already checked the predicates in CmpInst's tests, but I guess there is no harm in checking them here too?
```
auto OrigPred = LLVMCmp->getPredicate();
auto NewPred = sandboxir::CmpInst::getInversePredicate(OrigPred);
Cmp->swapOperands();
EXPECT_NE(NewPred, OrigPred);
EXPECT_EQ(Cmp->getPredicate(), NewPred)`
```
https://github.com/llvm/llvm-project/pull/106301
More information about the llvm-commits
mailing list