llvm / llvm/llvm-project

[libc++] Try applying __builtin_assume_separate_storage to std::vector's this and its allocated storage

Open
#181,249 1 comment 0 reactions 1 assignee Claimed by @cjdb View on GitHub
libc++ performance
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

From https://github.com/llvm/llvm-project/pull/180288:

> [...] In this case, we could add a `__builtin_assume_separate_storage(__begin_, this);` instead, which gives the optimizer the information to do the fold itself. I'm sure with this it will find more cases like the one here than if we do the optimization manually. I of course can't tell you whether we should do this, since assumes can block other optimizations, but I think we should at least look into it.

Inside `std::vector`, the `this` pointer and the `__begin_` pointer always definitely point to different objects. Telling the compiler could potentially lead to interesting optimizations. However, we should do due diligence and make sure it doesn't make things worse. I would suggest the following steps:

- [ ] Add `__builtin_assume_separate_storage(__begin_, this);`
- [ ] Run the microbenchmarks
- [ ] Run SPEC
- [ ] Run any other large scale testing we might be able to get our hands on
- [ ] Make a decision!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.