-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[InlineCost]: Optimize inlining of recursive function. #139982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c219bb0
d4d36df
c4004e3
ae2a97f
0718158
6f7b1a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
; REQUIRES: asserts | ||
; RUN: opt -passes='cgscc(inline),instcombine,cgscc(inline)' -S -debug-only=inline -disable-output < %s 2>&1 | FileCheck %s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here I just want to show the difference between this approach and the old approach in the other patch. |
||
|
||
; This test shows that the recursive function will not get simplified | ||
; unless the caller is the function itself, not another different caller. | ||
|
||
; CHECK: Inlining calls in: test | ||
; CHECK: Function size: 2 | ||
; CHECK: NOT Inlining (cost=never): recursive, Call: %call = tail call float @inline_rec_true_successor(float %x, float %scale) | ||
|
||
; CHECK: Inlining calls in: inline_rec_true_successor | ||
; CHECK: Function size: 10 | ||
; CHECK: Inlining (cost=-35, threshold=337), Call: %call = tail call float @inline_rec_true_successor(float %fneg, float %scale) | ||
; CHECK: Size after inlining: 17 | ||
; CHECK: NOT Inlining (cost=never): noinline function attribute, Call: %call_test = tail call float @test(float %fneg, float %common.ret18.op.i) | ||
; CHECK: NOT Inlining (cost=never): noinline function attribute, Call: %call_test.i = tail call float @test(float %x, float %call.i) | ||
; CHECK: Skipping inlining due to history: inline_rec_true_successor -> inline_rec_true_successor | ||
; CHECK: Updated inlining SCC: (test, inline_rec_true_successor) | ||
|
||
; CHECK: Inlining calls in: test | ||
; CHECK: Function size: 2 | ||
; CHECK: Inlining (cost=25, threshold=225), Call: %call = tail call float @inline_rec_true_successor(float %x, float %scale) | ||
; CHECK: Size after inlining: 10 | ||
|
||
define float @test(float %x, float %scale) noinline { | ||
entry: | ||
%call = tail call float @inline_rec_true_successor(float %x, float %scale) | ||
ret float %call | ||
} | ||
|
||
define float @inline_rec_true_successor(float %x, float %scale) { | ||
entry: | ||
%cmp = fcmp olt float %x, 0.000000e+00 | ||
br i1 %cmp, label %if.then, label %if.end | ||
|
||
common.ret18: ; preds = %if.then, %if.end | ||
%common.ret18.op = phi float [ %call_test, %if.then ], [ %mul, %if.end ] | ||
ret float %common.ret18.op | ||
|
||
if.then: ; preds = %entry | ||
%fneg = fneg float %x | ||
%call = tail call float @inline_rec_true_successor(float %fneg, float %scale) | ||
%call_test = tail call float @test(float %fneg, float %call) | ||
br label %common.ret18 | ||
|
||
if.end: ; preds = %entry | ||
%mul = fmul float %x, %scale | ||
br label %common.ret18 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should also remove
llvm-project/llvm/lib/Analysis/InlineCost.cpp
Line 266 in 180244d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is used in other different places in InlineCost not related to my case. I think I shouldn't remove it unless I investigate its uses and that should be in a different patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you add this member in #119677?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, sorry.