[llvm] [FuncSpec] Handle ssa_copy intrinsic calls in InstCostVisitor (PR #114247)
Hari Limaye via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 05:17:53 PDT 2024
================
@@ -0,0 +1,79 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs --version 5
+; RUN: opt -passes="ipsccp<func-spec>" -funcspec-min-function-size=1 \
+; RUN: -funcspec-for-literal-constant=true \
+; RUN: -funcspec-min-codesize-savings=50 \
+; RUN: -funcspec-min-latency-savings=0 \
+; RUN: -S < %s | FileCheck %s
+
+; Verify that we are able to estimate the codesize savings by looking through
+; calls to ssa_copy intrinsics, which are inserted by PredicateInfo when IPSCCP
----------------
hazzlim wrote:
Perhaps I'm missing something, but I don't see how it would be possible to write a unit test for this with explicit calls to `@llvm.ssa.copy` intrinsics, for the same reason that we can't do this in the regression tests.
If we write a unit test such as the following:
```
TEST_F(FunctionSpecializationTest, SSACopy) {
const char *ModuleString = R"(
define i32 @foo(i32 %x, i32 %y) {
entry:
%x.copy = call i32 @llvm.ssa.copy.i32(i32 %x)
%add.x.y = add i32 %x.copy, %y
%cond = icmp eq i32 %add.x.y, 2
br i1 %cond, label %cond.true, label %cond.false
cond.true:
ret i32 %x
cond.false:
ret i32 %y
}
)";
Module &M = parseModule(ModuleString);
Function *F = M.getFunction("foo");
FunctionSpecializer Specializer = getSpecializerFor(F);
InstCostVisitor Visitor = Specializer.getInstCostVisitorFor(F);
...
```
We have to construct the InstCostVisitor via getSpecializerFor(F), which constructs an IPSCCPSolver and runs it on the Module (as the Solver is necessary for the InstCostVisitor to function). Therefore we will hit the assert regarding predicate info:
`void llvm::SCCPInstVisitor::handleCallResult(CallBase &): Assertion `PI && "Missing predicate info for ssa.copy"' failed.`
I could add a unit test with code similar to the regression test, that relies on IR that we know will trigger creation of the `@llvm.ssa.copy` intrinsics, but that seems perhaps redundant? Apologies if I'm missing something!
https://github.com/llvm/llvm-project/pull/114247
More information about the llvm-commits
mailing list