-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
cmd/compile: hoist some loop invariants #59194
Conversation
Conservatively hoist some loop invariants outside the loop. Updates golang#15808
This PR (HEAD: 0672dff) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/go/+/478815 to see it. Tip: You can toggle comments from me using the |
Message from Iskander Sharipov: Patch Set 6: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Yi Yang: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Wayne Zuo: Patch Set 7: Run-TryBot+1 Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Gopher Robot: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Gopher Robot: Patch Set 7: TryBot-Result+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from David Chase: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from David Chase: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from David Chase: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Fahad King: Patch Set 7: Code-Review+1 (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Yi Yang: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Yi Yang: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Keith Randall: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Yi Yang: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
Message from Yi Yang: Patch Set 7: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/478815. |
This patch tries to conservatively hoist profitable loop invariant to block that dominates the entire loop. Value is considered as loop invariant if all its inputs are defined outside the loop or all its inputs are loop invariants. Since loop invariant will immediately moved to dominator block of loop, the first rule actually already implies the second rule.
The following limitations make this optimization tend to be conservative, it could be more aggressive in the future.
The ad-hoc and go1 benchmark show slight improvements:
darwin + amd64 +cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
│ old.log │ new.log │
│ sec/op │ sec/op vs base │
BinaryTree17-12 2.306 ± 10% 2.313 ± 6% ~ (p=0.912 n=10)
Fannkuch11-12 2.005 ± 7% 2.002 ± 2% ~ (p=0.853 n=10)
FmtFprintfEmpty-12 23.89n ± 10% 24.52n ± 9% ~ (p=0.393 n=10)
FmtFprintfString-12 40.36n ± 11% 43.68n ± 27% +8.25% (p=0.035 n=10)
FmtFprintfInt-12 49.09n ± 10% 49.88n ± 7% ~ (p=0.796 n=10)
FmtFprintfIntInt-12 81.09n ± 32% 78.13n ± 5% ~ (p=0.052 n=10)
FmtFprintfPrefixedInt-12 85.78n ± 3% 86.34n ± 1% ~ (p=0.955 n=10)
FmtFprintfFloat-12 132.9n ± 7% 128.0n ± 3% -3.69% (p=0.045 n=10)
FmtManyArgs-12 320.7n ± 33% 342.6n ± 19% +6.84% (p=0.042 n=10)
GobDecode-12 4.052m ± 13% 3.984m ± 8% ~ (p=0.579 n=10)
GobEncode-12 2.831m ± 20% 2.691m ± 6% -4.95% (p=0.043 n=10)
Gzip-12 183.5m ± 1% 190.1m ± 6% ~ (p=0.063 n=10)
Gunzip-12 21.17m ± 13% 21.22m ± 17% ~ (p=1.000 n=10)
HTTPClientServer-12 91.00µ ± 22% 78.75µ ± 1% -13.47% (p=0.000 n=10)
JSONEncode-12 5.527m ± 1% 5.575m ± 5% ~ (p=0.631 n=10)
JSONDecode-12 26.01m ± 1% 26.02m ± 5% ~ (p=0.684 n=10)
Mandelbrot200-12 3.188m ± 9% 3.333m ± 4% ~ (p=0.218 n=10)
GoParse-12 2.276m ± 10% 2.281m ± 5% ~ (p=0.739 n=10)
RegexpMatchEasy0_32-12 42.69n ± 7% 39.21n ± 5% -8.15% (p=0.009 n=10)
RegexpMatchEasy0_1K-12 128.5n ± 4% 127.9n ± 12% ~ (p=0.926 n=10)
RegexpMatchEasy1_32-12 36.29n ± 6% 36.19n ± 2% ~ (p=0.724 n=10)
RegexpMatchEasy1_1K-12 195.8n ± 16% 191.0n ± 10% ~ (p=0.739 n=10)
RegexpMatchMedium_32-12 600.1n ± 2% 629.7n ± 1% +4.93% (p=0.002 n=10)
RegexpMatchMedium_1K-12 20.81µ ± 3% 20.74µ ± 8% ~ (p=0.971 n=10)
RegexpMatchHard_32-12 915.1n ± 2% 910.1n ± 4% ~ (p=1.000 n=10)
RegexpMatchHard_1K-12 28.35µ ± 11% 27.26µ ± 3% -3.83% (p=0.003 n=10)
Revcomp-12 290.9m ± 15% 279.2m ± 11% ~ (p=0.353 n=10)
Template-12 36.29m ± 16% 34.43m ± 2% -5.13% (p=0.043 n=10)
TimeParse-12 199.4n ± 40% 187.4n ± 42% ~ (p=0.579 n=10)
TimeFormat-12 168.2n ± 10% 178.6n ± 42% ~ (p=0.289 n=10)
geomean 31.84µ 31.62µ -0.70%
linux + amd64 + cpu: Intel(R) Xeon(R) Platinum 8163 CPU @ 2.50GHz
│ old.log │ new.log │
│ sec/op │ sec/op vs base │
BinaryTree17-96 5.097 ± 3% 5.159 ± 2% ~ (p=0.315 n=10)
Fannkuch11-96 3.189 ± 0% 3.191 ± 1% +0.07% (p=0.023 n=10)
FmtFprintfEmpty-96 38.04n ± 2% 37.44n ± 1% -1.58% (p=0.003 n=10)
FmtFprintfString-96 66.65n ± 4% 63.49n ± 1% -4.74% (p=0.000 n=10)
FmtFprintfInt-96 81.01n ± 2% 80.96n ± 1% ~ (p=0.493 n=10)
FmtFprintfIntInt-96 118.7n ± 1% 119.0n ± 2% ~ (p=0.614 n=10)
FmtFprintfPrefixedInt-96 144.0n ± 1% 142.6n ± 1% ~ (p=0.169 n=10)
FmtFprintfFloat-96 203.9n ± 1% 201.0n ± 1% -1.42% (p=0.004 n=10)
FmtManyArgs-96 505.2n ± 1% 506.9n ± 1% ~ (p=0.101 n=10)
GobDecode-96 6.602m ± 3% 6.675m ± 3% ~ (p=0.631 n=10)
GobEncode-96 5.847m ± 3% 5.808m ± 3% ~ (p=0.796 n=10)
Gzip-96 284.2m ± 1% 284.8m ± 4% ~ (p=0.247 n=10)
Gunzip-96 33.25m ± 2% 33.28m ± 1% ~ (p=0.971 n=10)
HTTPClientServer-96 64.59µ ± 1% 64.10µ ± 3% -0.76% (p=0.023 n=10)
JSONEncode-96 9.262m ± 4% 9.617m ± 3% +3.83% (p=0.043 n=10)
JSONDecode-96 41.17m ± 1% 41.17m ± 1% ~ (p=0.631 n=10)
Mandelbrot200-96 5.063m ± 1% 5.059m ± 0% ~ (p=0.280 n=10)
GoParse-96 4.374m ± 3% 4.284m ± 1% ~ (p=0.052 n=10)
RegexpMatchEasy0_32-96 61.80n ± 2% 61.31n ± 2% ~ (p=0.363 n=10)
RegexpMatchEasy0_1K-96 187.1n ± 1% 189.9n ± 2% ~ (p=0.065 n=10)
RegexpMatchEasy1_32-96 55.92n ± 3% 55.05n ± 2% -1.54% (p=0.023 n=10)
RegexpMatchEasy1_1K-96 295.4n ± 1% 294.6n ± 1% ~ (p=0.160 n=10)
RegexpMatchMedium_32-96 1.023µ ± 1% 1.016µ ± 1% ~ (p=0.091 n=10)
RegexpMatchMedium_1K-96 31.80µ ± 1% 31.67µ ± 1% ~ (p=0.190 n=10)
RegexpMatchHard_32-96 1.450µ ± 1% 1.450µ ± 1% ~ (p=0.925 n=10)
RegexpMatchHard_1K-96 44.25µ ± 4% 43.88µ ± 1% ~ (p=0.190 n=10)
Revcomp-96 500.1m ± 7% 464.4m ± 10% ~ (p=0.315 n=10)
Template-96 58.88m ± 4% 58.86m ± 6% ~ (p=0.853 n=10)
TimeParse-96 252.0n ± 5% 251.9n ± 1% ~ (p=0.537 n=10)
TimeFormat-96 272.0n ± 2% 274.8n ± 2% ~ (p=0.147 n=10)
geomean 50.02µ 49.77µ -0.50%
Updates #15808