[llvm] [SandboxIR] Add utility function to find the base Value for Mem instructions (PR #112030)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 11 11:20:39 PDT 2024
================
@@ -215,3 +215,35 @@ define void @foo(float %arg0, double %arg1, i8 %arg2, i64 %arg3, ptr %arg4) {
EXPECT_EQ(sandboxir::Utils::getNumBits(L2), 8u);
EXPECT_EQ(sandboxir::Utils::getNumBits(L3), 64u);
}
+
+TEST_F(UtilsTest, GetMemBase) {
+ parseIR(C, R"IR(
+define void @foo(ptr %ptrA, float %val, ptr %ptrB) {
+bb:
+ %gepA0 = getelementptr float, ptr %ptrA, i32 0
+ %gepA1 = getelementptr float, ptr %ptrA, i32 1
+ %gepB0 = getelementptr float, ptr %ptrB, i32 0
+ %gepB1 = getelementptr float, ptr %ptrB, i32 1
+ store float %val, ptr %gepA0
+ store float %val, ptr %gepA1
+ store float %val, ptr %gepB0
+ store float %val, ptr %gepB1
+ ret void
+}
+)IR");
+ llvm::Function &Foo = *M->getFunction("foo");
+ sandboxir::Context Ctx(C);
+ sandboxir::Function *F = Ctx.createFunction(&Foo);
+
+ auto It = std::next(F->begin()->begin(), 4);
+ auto *St0 = cast<sandboxir::StoreInst>(&*It++);
+ auto *St1 = cast<sandboxir::StoreInst>(&*It++);
+ auto *St2 = cast<sandboxir::StoreInst>(&*It++);
+ auto *St3 = cast<sandboxir::StoreInst>(&*It++);
+ EXPECT_EQ(sandboxir::Utils::getMemInstructionBase(St0),
+ sandboxir::Utils::getMemInstructionBase(St1));
+ EXPECT_EQ(sandboxir::Utils::getMemInstructionBase(St2),
+ sandboxir::Utils::getMemInstructionBase(St3));
+ EXPECT_NE(sandboxir::Utils::getMemInstructionBase(St0),
+ sandboxir::Utils::getMemInstructionBase(St3));
----------------
vporpo wrote:
These checks are OK, but we are not actually checking what the returned value actually is.
Some checks like this would also help:
```
EXPECT_EQ(sandboxir::Utils::getMemInsructionBase(St0), Ctx.getValue(LLVMSt0));
```
https://github.com/llvm/llvm-project/pull/112030
More information about the llvm-commits
mailing list