rust-lang / rust-lang/rustc_codegen_gcc

iter_mut codegen

Open
#105 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

perf
Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

https://godbolt.org/z/v7fq5q7q8
following code:

pub fn example(x: &mut [f32; 1024]) {
    for x in x.iter_mut() {
        *x *= 4.0;
    }
}

when compiled with codegen_gcc gives following assembly:

example::example:
        test    rdi, rdi
        je      .L6
        movss   xmm1, DWORD PTR .LC0[rip]
        lea     rax, 4092[rdi]
        jmp     .L9
.L19:
        add     rdi, 4
        je      .L6
.L9:
        movss   xmm0, DWORD PTR [rdi]
        mulss   xmm0, xmm1
        movss   DWORD PTR [rdi], xmm0
        cmp     rdi, rax
        jne     .L19
.L6:
        ret
.LC0:
        .long   1082130432

compared to llvm codegen, it seems (at least to me, but i'm definietly not an asm expert) that:

  • llvm version is vectorised, gcc not
  • while llvm version has 1 label and conditional jump (which is not suprisings for simple loop), gcc version seems unnecessary convoluted, with 3 labels and 4 jump instructions
  • gcc version starts with something that looks like a null check , which is strange given that &mut cannot be null

i'm not sure if this is really a problem, but i figured out it is worth asking :)

Anyway, thank you for working on this project, it is really exciting development :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked Godbolt example and reproduce the Rust iter_mut function using codegen_gcc, then compare its assembly with the LLVM output. Investigate whether the null check, extra labels, jumps, and lack of vectorisation are expected; done means explaining the differences or correcting the generated code.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.