Skip to content
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

optimizer: move inlineable constants into argument position during compact!-ion #50767

Merged
merged 3 commits into from
Aug 3, 2023

Conversation

aviatesk
Copy link
Sponsor Member

@aviatesk aviatesk commented Aug 2, 2023

In code like below

Base.@assume_effects :nothrow function erase_before_inlining(x, y)
    z = sin(y)
    if x
        return "julia"
    end
    return z
end

let y::Float64
    length(erase_before_inlining(true, y))
end

the constant prop' can figure out the constant return type of
erase_before_inlining(true, y) while it is profitable not to inline
expand it since otherwise we left some !:nothrow callees there
(xref: #47305).

In order to workaround this problem, this commit makes compact!move
inlineable constants into argument positions so that the such
"inlineable, but safe as a whole" calls to be erased during compaction.
This should give us general compile-time performance improvement too
as we no longer need to expand the IR for those calls.

Requires:

@aviatesk aviatesk requested a review from Keno August 2, 2023 19:09
@oscardssmith oscardssmith added performance Must go faster compiler:effects effect analysis backport 1.10 Change should be backported to the 1.10 release labels Aug 2, 2023
@aviatesk aviatesk force-pushed the avi/const-inlining-compaction branch 2 times, most recently from 56ef06d to de49adc Compare August 2, 2023 20:02
Currently the `compact!`-ion pass fails to fold constant `PiNode` like
`PiNode(0.0, Float64)`. This commit fixes it up.
@aviatesk aviatesk force-pushed the avi/const-inlining-compaction branch from de49adc to e4e7317 Compare August 3, 2023 12:52
…compact!`-ion

In code like below
```julia
Base.@assume_effects :nothrow function erase_before_inlining(x, y)
    z = sin(y)
    if x
        return "julia"
    end
    return z
end

let y::Float64
    length(erase_before_inlining(true, y))
end
```
the constant prop' can figure out the constant return type of
`erase_before_inlining(true, y)` while it is profitable not to inline
expand it since otherwise we left some `!:nothrow` callees there
(xref: #47305).

In order to workaround this problem, this commit makes `compact!`move
inlineable constants into statement positions so that such "inlineable,
but safe as a whole" calls to be erased during compaction.
This should give us general compile-time performance improvement too
as we no longer need to expand the IR for those calls.
@aviatesk aviatesk force-pushed the avi/const-inlining-compaction branch from e4e7317 to 40339ac Compare August 3, 2023 13:01
@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Aug 3, 2023

@nanosoldier runbenchmarks("inference", vs=":master")

@aviatesk aviatesk changed the title optimizer: move inlineable constants into statement position during compact!-ion optimizer: move inlineable constants into argument position during compact!-ion Aug 3, 2023
Copy link
Sponsor Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to me

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here.

@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Aug 3, 2023

@nanosoldier runbenchmarks("inference", vs=":master")

@nanosoldier
Copy link
Collaborator

Your benchmark job has completed - no performance regressions were detected. A full report can be found here.

@aviatesk
Copy link
Sponsor Member Author

aviatesk commented Aug 3, 2023

The benchmark result looks nice.

@aviatesk aviatesk merged commit a2f3d77 into master Aug 3, 2023
5 of 7 checks passed
@aviatesk aviatesk deleted the avi/const-inlining-compaction branch August 3, 2023 18:03
aviatesk added a commit that referenced this pull request Aug 4, 2023
…ompact!`-ion (#50767)

In code like below
```julia
Base.@assume_effects :nothrow function erase_before_inlining(x, y)
    z = sin(y)
    if x
        return "julia"
    end
    return z
end

let y::Float64
    length(erase_before_inlining(true, y))
end
```
the constant prop' can figure out the constant return type of
`erase_before_inlining(true, y)` while it is profitable not to inline
expand it since otherwise we left some `!:nothrow` callees there
(xref: #47305).

In order to workaround this problem, this commit makes `compact!`move
inlineable constants into argument positions so that the such
"inlineable, but safe as a whole" calls to be erased during compaction.
This should give us general compile-time performance improvement too
as we no longer need to expand the IR for those calls.

Requires:
- #50764
- #50765
- #50768
@aviatesk aviatesk mentioned this pull request Aug 4, 2023
36 tasks
@aviatesk aviatesk removed the backport 1.10 Change should be backported to the 1.10 release label Aug 4, 2023
KristofferC added a commit that referenced this pull request Aug 16, 2023
Backported PRs:
- [x] #50637 <!-- Remove SparseArrays legacy code -->
- [x] #50665 <!-- print `@time` msg into print buffer -->
- [x] #50523 <!-- Avoid generic call in most cases for getproperty -->
- [x] #50635 <!-- `versioninfo()`: include build info and unofficial
warning -->
- [x] #50670 <!-- Make reinterpret specialize fully. -->
- [x] #50666 <!-- include `--pkgimage=no` caches for stdlibs -->
- [x] #50765 
- [x] #50764
- [x] #50768
- [x] #50767
- [x] #50618 <!-- inference: continue const-prop' when concrete-eval
returns non-inlineable -->
- [x] #50689 <!-- Attach `tanpi` docstring to method -->
- [x] #50671 <!-- Fix rdiv of complex lhs by real factorizations -->
- [x] #50598 <!-- only limit types in stack traces in the REPL -->
- [x] #50766 <!-- Don't partition alwaysinline functions -->
- [x] #50771 <!-- re-allow non-string values in ENV `get!` -->
- [x] #50682 <!-- Add fallback if we have make a weird GC decision. -->
- [x] #50781 <!-- fix `bit_map!` with aliasing -->
- [x] #50172 <!-- print feature flags used for matching pkgimage -->
- [x] #50844 <!-- Bump OpenBLAS binaries to use the new GEMM
multithreading threshold -->
- [x] #50826 <!-- Update dependency builds -->
- [x] #50845 <!-- fix #50438, use default pool for at-threads -->
- [x] #50568 <!-- `Array(::AbstractRange)` should return an `Array` -->
- [x] #50655 <!-- fix hashing regression. -->
- [x] #50779 <!-- Minor refactor to image generation -->
- [x] #50791 <!-- Make symbols internal in jl_create_native, and only
externalize them when partitioning -->
- [x] #50724 <!-- Merge opaque closure modules with the rest of the
workqueue -->
- [x] #50738 <!-- Add alignment to constant globals -->
- [x] #50871 <!-- macOS: Don't inspect dead threadtls during exception
handling. -->

Need manual backport:

Contains multiple commits, manual intervention needed:

Non-merged PRs with backport label:
- [ ] #50850 <!-- Remove weird Rational dispatch and add pi functions to
list -->
- [ ] #50823 <!-- Make ranges more robust with unsigned indexes. -->
- [ ] #50809 <!-- Limit type-printing in MethodError -->
- [ ] #50663 <!-- Fix Expr(:loopinfo) codegen -->
- [ ] #50594 <!-- Disallow non-index Integer types in isassigned -->
- [ ] #50385 <!-- Precompile pidlocks: add to NEWS and docs -->
- [ ] #49805 <!-- Limit TimeType subtraction to AbstractDateTime -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:effects effect analysis performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants