Skip to content

Conversation

@dianqk
Copy link
Member

@dianqk dianqk commented Dec 20, 2025

r? ghost (for perf)

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 20, 2025
@rust-log-analyzer

This comment has been minimized.

@dianqk dianqk force-pushed the gvn-range-if-assert branch from fad3972 to ef766e1 Compare December 21, 2025 12:05
@rust-log-analyzer

This comment has been minimized.

@dianqk dianqk force-pushed the gvn-range-if-assert branch from ef766e1 to bbf25db Compare December 21, 2025 12:52
@rust-log-analyzer

This comment has been minimized.

@dianqk dianqk force-pushed the gvn-range-if-assert branch from bbf25db to 5734996 Compare December 21, 2025 13:40
@rust-log-analyzer

This comment has been minimized.

@dianqk dianqk force-pushed the gvn-range-if-assert branch from 5734996 to 40d5520 Compare December 21, 2025 13:54
@dianqk
Copy link
Member Author

dianqk commented Dec 21, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

rust-bors bot added a commit that referenced this pull request Dec 21, 2025
[EXPERIMENT] GVN: Track known value ranges through assert and switchInt.
@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 21, 2025
@rust-bors
Copy link

rust-bors bot commented Dec 21, 2025

☀️ Try build successful (CI)
Build commit: f2bc50f (f2bc50f4689333c80bcd074203a0a387187d19d8, parent: d3f16d2f35d8d4b25bb15a85ae869eee70ffb4cd)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f2bc50f): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.1%, 0.4%] 3
Regressions ❌
(secondary)
0.5% [0.5%, 0.5%] 1
Improvements ✅
(primary)
-0.4% [-0.9%, -0.2%] 9
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -0.2% [-0.9%, 0.4%] 12

Max RSS (memory usage)

Results (primary -1.1%, secondary 0.8%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.5% [1.9%, 3.1%] 2
Regressions ❌
(secondary)
2.4% [2.4%, 2.4%] 1
Improvements ✅
(primary)
-2.9% [-4.2%, -1.4%] 4
Improvements ✅
(secondary)
-0.7% [-0.7%, -0.7%] 1
All ❌✅ (primary) -1.1% [-4.2%, 3.1%] 6

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary -0.0%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.3% [0.1%, 0.4%] 5
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.8%, -0.0%] 16
Improvements ✅
(secondary)
-0.1% [-0.8%, -0.0%] 19
All ❌✅ (primary) -0.0% [-0.8%, 0.4%] 21

Bootstrap: 481.777s -> 483.166s (0.29%)
Artifact size: 390.59 MiB -> 390.61 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 21, 2025
@bors
Copy link
Collaborator

bors commented Dec 22, 2025

☔ The latest upstream changes (presumably #150231) made this pull request unmergeable. Please resolve the merge conflicts.

@dianqk dianqk force-pushed the gvn-range-if-assert branch from 40d5520 to 5b217cf Compare December 22, 2025 14:00
@rustbot rustbot added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Dec 22, 2025
@dianqk dianqk force-pushed the gvn-range-if-assert branch from 5b217cf to cbc2bb0 Compare December 22, 2025 14:03
@dianqk dianqk removed the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Dec 22, 2025
@dianqk dianqk force-pushed the gvn-range-if-assert branch from cbc2bb0 to 3837576 Compare December 22, 2025 14:11
@dianqk
Copy link
Member Author

dianqk commented Dec 22, 2025

I don't think GVN is required here. A new pass with SSA locals may make sense. @cjgillot What do you think?

self.insert_range(value, successor, range);
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is wrong. Codegen can turn overflow checks into nops.

Copy link
Member Author

Choose a reason for hiding this comment

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

IIUC, they should be handled in instsimplify. This just does some useless work.

@cjgillot
Copy link
Contributor

This PR is very interesting. From a cursory glance, I see 2 features in this PR:

  1. computing value ranges in GVN;
  2. handling assumes and other dataflow-dependent equations.

I have no issue about (1). My recommendation would be to copy what eval_to_const does.

I'm a bit skeptical about (2). GVN is designed to handle structural equality that is independent of dataflow. So I'm not sure how the two are going to fit together in full generality.

For this specific case, my first reflex would be to finish DataflowConstProp (= make it fast enough) and generalize it to ranges to make it worth the cost. This is pretty much what is advised in #76579.

But a separate SSA pass could be a much simpler and straightforward way to get some of the same improvements.

Do you have an idea where those improvements come from? Assertions disappearing? Switches in cleanup blocks disappearing?

@dianqk
Copy link
Member Author

dianqk commented Dec 23, 2025

Do you have an idea where those improvements come from? Assertions disappearing? Switches in cleanup blocks disappearing?

Most matched patterns in std are bool. I guess they are from assertions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

perf-regression Performance regression. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants