rust-lang / rustc_codegen_gcc

libgccjit AOT codegen for rustc
Apache License 2.0
906 stars 60 forks source link

Support #![feature(unchecked_math)] #389

Open antoyo opened 9 months ago

antoyo commented 9 months ago

The following code:

#![feature(unchecked_math)]

pub fn nop(num: i32) -> i32 {
    unsafe { (num.unchecked_mul(2)) / 2 }
}

gives:

example::nop:
        lea     eax, [rdi+rdi]
        sar     eax
        ret

while cg_llvm gives:

example::nop:
        mov     eax, edi
        ret

because it seems cg_gcc always enable checked maths.

antoyo commented 5 months ago

Done. Feel free to ask questions if you need help.

antoyo commented 5 months ago

This issue is actually much harder than I initially though, so I removed the good first issue tag.

It would be in this part of the code and would require changes to libgccjit.

You might want to pick another good first issue if you prefer.