Skip to content

SimplifyCFG: fix an infinite jump-threading loop. #35614

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

Merged
merged 1 commit into from
Jan 27, 2021

Conversation

eeckstein
Copy link
Contributor

@eeckstein eeckstein commented Jan 27, 2021

The JumpThreadingCost map in Simplify CFG is used to prevent infinite jump threading loops.
There was a missing update of the cost for blocks which are cloned:
Jump threading loops were prevented for infinitely cloning the original block, but not for re-cloning the cloned block.

A test case is already added in #35604

rdar://73357726, [SR-14068]

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

The JumpThreadingCost map in Simplify CFG is used to prevent infinite jump threading loops.
There was a missing update of the cost for blocks which are cloned:
Jump threading loops were prevented for infinitely cloning the original block, but not for re-cloning the cloned block.

A test case is already added in 8948f75

rdar://73357726, [SR-14068]
@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@eeckstein
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1628 2513 +54.4% 0.65x (?)
Data.append.Sequence.809B.Count.I 91 99 +8.8% 0.92x (?)
StringBuilderLong 1360 1470 +8.1% 0.93x (?)
UTF8Decode_InitFromBytes_ascii_as_ascii 497 537 +8.0% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
FlattenListFlatMap 5395 4192 -22.3% 1.29x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
FlattenListLoop 1630 2504 +53.6% 0.65x (?)
FlattenListFlatMap 5552 6586 +18.6% 0.84x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
UTF8Decode_InitFromData_ascii_as_ascii 723 785 +8.6% 0.92x (?)

Code size: -swiftlibs

How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - fe928d5

@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci test macOS

@atrick
Copy link
Contributor

atrick commented Jan 27, 2021

It looks like you want to use JumpThreadingCost to be an accumulator on any block that has been cloned so that the current cost is the original cost multiplied by the number of clones. That's not obvious from the comments.

I do think it's a good idea to generally limit run-away jump-threading. But I'm still worried about small loops, so still like this safeguard: #35608

The thing that is particularly baffling to me is that this cost is initialized in simplifyBranchBlock which is unreliable.

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

This looks good to me. I'll merge this PR and add the necessary comments in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants