[PATCH] D134203: [PGO] Avoid assertion on degenerate profile
Rong Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 21 11:31:59 PDT 2022
xur added a comment.
In D134203#3801212 <https://reviews.llvm.org/D134203#3801212>, @xur wrote:
> This is an interesting example. When we design this, we assume there is at least one exit node in the function. And we create fake edges from exit node(s). This way we create a close graph.
>
> For this case, we don't have an exit node and I think the function exits from a non-return call to "zeroexit". So the edge propagation will terminate incompletely.
>
> I think this is a corner case but let me think how to handle this.
I read the code again and I think a closed graph is not required for the propagation. The flow will be inconsistent but there is little we can do about it.
The root cause is we don't break function call into a separated BB. So the implicit edges from non-return calls are not accountable.
We probably don't want to change this because it will slow down the instrumentation and the benefit is not minimal for PGO performance.
I think this fix is fine.
But there are a few minor things need to change
(1) the title: the problem is not from degenerate profile. I can create a prefect legal profile and reproduce the assertion
(2) add a waring or debug trace
You also probably want to use a reduce test case.
Here is the test case I created:
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
define void @bar(i32 noundef %s) {
entry:
%cmp = icmp sgt i32 %s, 20
br i1 %cmp, label %if.then, label %if.end
if.then:
call void @exit(i32 noundef 1)
unreachable
if.end:
ret void
}
declare void @exit(i32 noundef)
define void @foo(i32 noundef %n) {
entry:
%sum = alloca i32, align 4
store volatile i32 %n, ptr %sum, align 4
%sum.0.sum.0. = load volatile i32, ptr %sum, align 4
call void @bar(i32 noundef %sum.0.sum.0.)
%cmp = icmp slt i32 %n, 10
br i1 %cmp, label %if.then, label %if.end
if.then:
%sum.0.sum.0.1 = load volatile i32, ptr %sum, align 4
call void @bar(i32 noundef %sum.0.sum.0.1)
br label %if.end
if.end:
br label %for.cond
for.cond:
%sum.0.sum.0.2 = load volatile i32, ptr %sum, align 4
call void @bar(i32 noundef %sum.0.sum.0.2)
br label %for.cond
}
=
profile file === IR level Instrumentation Flag
----------------------------------------------
:ir
foo
Func Hash:
==========
146835645050580305
Num Counters:
=============
3
Counter Values:
===============
0
1
0
end
---
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D134203/new/
https://reviews.llvm.org/D134203
More information about the llvm-commits
mailing list