Skip to content

[BOLT] Provide backwards compatibility for YAML profile with std::hash #74253

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
Dec 11, 2023

Conversation

aaupov
Copy link
Contributor

@aaupov aaupov commented Dec 3, 2023

Provide backwards compatibility for YAML profile that uses std::hash:
xxh3 hash is the default for newly produced profile (sets std-hash: false),
whereas the profile that doesn't specify std-hash will be treated as
std-hash: true, preserving old behavior.

Same as profile-use-dfs in https://reviews.llvm.org/D156176.

@aaupov aaupov requested review from spupyrev and maksfb December 3, 2023 21:26
@aaupov aaupov added the BOLT label Dec 3, 2023
Copy link

github-actions bot commented Dec 3, 2023

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.

@aaupov aaupov force-pushed the revert-xxh branch 2 times, most recently from 268cc19 to c7c5bf9 Compare December 3, 2023 21:46
Copy link
Contributor

@maksfb maksfb left a comment

Choose a reason for hiding this comment

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

How about we write a new field to YAML with a hash function name/ID? In the reader, we default to std::hash for backwards compatibility as you already do. If we are not planning on using std::hash in the future (for writing), perhaps the option is not needed at all? We can likely have a couple of binary/YAML test cases that verify backwards compatibility.

Suggestion for the title: "Provide backwards compatibility for YAML profile with std::hash".

@aaupov aaupov changed the title [BOLT] Introduce profile-use-std-hash [BOLT] Provide backwards compatibility for YAML profile with std::hash Dec 6, 2023
@aaupov
Copy link
Contributor Author

aaupov commented Dec 7, 2023

We can likely have a couple of binary/YAML test cases that verify backwards compatibility

Added a YAML test checking backwards compatibility. It reuses the test bolt/test/X86/reader-stale-yaml.test and its input (bolt/test/X86/Inputs/blarge_profile_stale.yaml) from before xxh diff.

@aaupov
Copy link
Contributor Author

aaupov commented Dec 11, 2023

Renamed Xxh3 to XXH3.
Added the Default enum value aliased to XXH3 to avoid confusion which hash to use.

Summary:
xxh3 hash is the default for newly produced profile (sets `hash-func: xxh3`),
whereas the profile that doesn't specify `hash-func` will be treated as
`hash-func: std-hash`, preserving old behavior.
@aaupov aaupov merged commit b039ccc into llvm:main Dec 11, 2023
@aaupov aaupov deleted the revert-xxh branch December 11, 2023 20:27
@MaskRay
Copy link
Member

MaskRay commented Jul 1, 2024

bolt/test/X86/reader-stale-yaml-std.test introduced by this patch might rely on determinism of hash_value(StringRef), which is not guaranteed.

My Hashing.h change #96282 might cause bolt/test/X86/reader-stale-yaml-std.test to fail: #96282 (comment)
Perhaps the test can be temporarily disabled

BlendedHashes[I].InstrHash = (uint16_t)InstrHash;
if (HashFunction == HashFunction::StdHash) {
uint64_t InstrHash = std::hash<std::string>{}(InstrHashStr);
BlendedHashes[I].InstrHash = (uint16_t)hash_value(InstrHash);
Copy link
Member

Choose a reason for hiding this comment

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

std::hash<std::string> results are quite good and do not need another bit mixer.

llvm::hash_value is non-deterministic (#96282).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we realized that but couldn't make the change at the time (breaks profile matching). But now that the default has switched to xxh3 we can drop hash_value and adjust tests.

MaskRay added a commit that referenced this pull request Jul 1, 2024
This test from #74253 relies on particular hash values from Hashing.h.
The test fails in LLVM_ENABLE_ABI_BREAKING_CHECKS=on modes (#96282) or
whenever Hashing.h implementation changes.
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
This test from llvm#74253 relies on particular hash values from Hashing.h.
The test fails in LLVM_ENABLE_ABI_BREAKING_CHECKS=on modes (llvm#96282) or
whenever Hashing.h implementation changes.
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
This test from llvm#74253 relies on particular hash values from Hashing.h.
The test fails in LLVM_ENABLE_ABI_BREAKING_CHECKS=on modes (llvm#96282) or
whenever Hashing.h implementation changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants