-
Notifications
You must be signed in to change notification settings - Fork 446
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
Teach functions inliner to inline into if condition #5073
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Anton Korobeynikov <anton@korobeynikov.info>
cdbbbc8
to
7ba5781
Compare
What happens today, without these enhancements? Do function calls within |
We're having a compiler internal error. So, this is not a performance enhancement, rather then ability to compile certain code (see testcase :) ) To be precise, this |
One would expect that side-effect ordering would pull the function call out of the if condition into a separate assignment to a temp, but perhaps if running with a backend that disables side-effect ordering. The change just looks like it is duplicating the effect of side-effect ordering of calls in if conditions as part of the inline, which is perhaps more efficient -- only create one temp bool instead of two, though later local-copyprop will get rid of the extra one. |
It is not a backend that disables side effect ordering. The testcase reproduces with plain p4c. Side effect ordering is "broken" after actions inlining: see, there are no "side effects" for Overall, relying on side effect ordering seems to be a huge downside as it is pretty fragile (in terms of optimizations), it does create lots of temporaries that make memory consumption of e.g. use-def to skyrocket. It looks like side effect ordering is an alternative to e.g. SSA form, however, it does not hold the same invariants as proper SSA form, so one cannot rely on them. |
BUG_CHECK(bool(RTTI::isAny<IR::MethodCallStatement, IR::AssignmentStatement>(stat)), | ||
"%1%: unexpected statement with call", stat); | ||
BUG_CHECK( | ||
bool(RTTI::isAny<IR::MethodCallStatement, IR::AssignmentStatement, IR::IfStatement>(stat)), |
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.
The bool(
cast should not be necessary.
The problem is hidden in many cases by side effects ordering, however, it could be further exposed for action arguments after actions inlining.
Without this PR we're ending in ICE trying to perform an inline as inliner can only do this for plain
MethodCallStatement
andAssignmentStatement
.