rust-lang / rust-lang/rustc_codegen_gcc
Don't apply the aligned attribute nedlessly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.2k
- Forks
- 105
- Avg merge
- 8h 20m
- Merged PRs (30d)
- 14
Description
Currently, we apply the aligned attribute to all integers, regardless of their actual aligement.
This leads to such gems as this:
__int8_t __attribute__((aligned(1)))
Since a byte-sized type has a size of 1(by definition), it's alignment can be 1 and only 1.
This attribute is thus unneeded, and only leads to increased memory consumption, and more confusing debug strings. It could also inhibit some optimizations(no examples of that yet, but it is not hard to imagine some of them can't deal with under / over aligned types, and ignore types with explicit alignment altogether).
While removing this attribute for byte-sized types is an easy fix, other types pose a bigger challenge.
Ideally, we'd need an API to query GCC about the aligement of intigers / floats / vectors, and then use that API to not emit this attribute when not necessary(eg. a structure composed of floats with aligement 4 is alteady correctly aligned by the virtue of containing floats).
For example, Builder::load could check if the requested align: Align differs from the one already guaranteed for a type(by checking the aligement on the rustc side of things). We could then call get_aligned if and only if this aligement differs, reducing the usage of this attribute(thus reducing memory usage).
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing Builder::load and the get_aligned call, then investigate how rustc exposes the alignment guaranteed for integer, float, vector, and composite types. Done means the backend emits alignment only when it differs from the type's guaranteed alignment, including avoiding it for byte-sized types and naturally aligned structures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100