Skip to content

Arithmetic not folded #41631

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
jrmuizel opened this issue Apr 29, 2017 · 3 comments
Closed

Arithmetic not folded #41631

jrmuizel opened this issue Apr 29, 2017 · 3 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@jrmuizel
Copy link
Contributor

The following program:

#![crate_type = "lib"]
use std::ptr;
use std::slice;
pub struct RawSlice<'a>
{
        s: &'a mut [u8]
}
impl<'a> RawSlice<'a> {
    fn write(&mut self, buf: &[u8])  {
        let dest_data = self.s.as_mut_ptr();
        let src_data = buf.as_ptr();
        unsafe {
            ptr::copy_nonoverlapping(src_data, dest_data, buf.len());
            self.s = slice::from_raw_parts_mut(dest_data.offset(buf.len() as isize), self.s.len() - buf.len());
        }
    }
}
pub fn do_write(r: &mut RawSlice, k: [u8; 4]) {
    r.write(&[1, 2, 3, 4]);
    r.write(&[1, 2, 3, 4]);
    r.write(&[1, 2, 3, 4]);
    r.write(&[1, 2, 3, 4]);
}

Compiles to:

        pushq   %rbp
        movq    %rsp, %rbp
        movq    (%rdi), %rax
        movl    $67305985, (%rax)
        addq    $-4, 8(%rdi)
        movl    $67305985, 4(%rax)
        addq    $-4, 8(%rdi)
        movl    $67305985, 8(%rax)
        addq    $-4, 8(%rdi)
        movl    $67305985, 12(%rax)
        addq    $16, %rax
        movq    8(%rdi), %rcx
        addq    $-4, %rcx
        movq    %rax, (%rdi)
        movq    %rcx, 8(%rdi)
        popq    %rbp
        retq

Ideally all of the addq -4 would be folded together. I suspect that either rust is emitting the wrong aliasing info or llvm is not properly dealing with the information.

@sfackler sfackler added the I-slow Issue: Problems and improvements with respect to performance of generated code. label Apr 29, 2017
@jrmuizel
Copy link
Contributor Author

jrmuizel commented May 1, 2017

I guess this might be #31681

@jrmuizel
Copy link
Contributor Author

jrmuizel commented May 1, 2017

I confirmed that reverting #31545 fixes this.

@Mark-Simulacrum Mark-Simulacrum added the A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. label Jun 22, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@steveklabnik
Copy link
Member

Triage:

  1. the code still does not optimize properly today
  2. @jrmuizel confirmed that it's because we removed the noalias stuff
  3. since this has been filed, we've re-enabled and then re-disabled noalias again.
  4. this means that this is an effective dup of Enable noalias annotations #54878; the new 're-enable noalias' bug.

Closing! Thanks for the report.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-enhancement Category: An issue proposing an enhancement or a PR with one. I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

4 participants