Unable to achieve aligned writes

45e1b0d
Opened by Kirill Khazan at 2023-04-05 17:38:42

I am trying to implement an efficient memory move operation for a specific usage pattern: https://play.rust-lang.org/?gist=6ddd4e11d7f7b0f6503ddd398f0e665f&version=nightly&backtrace=1

In release mode, the loop in move_items() in the above example is compiled into a series of unaligned reads followed by unaligned writes, despite my efforts to have the writes aligned.

  1. Known limitation of LLVM IR representation of the llvm.memmove intrinsic; there's only one alignment parameter. There was an attempt to fix this in LLVM r253511, but it was reverted. Not sure what the current status is.

    eefriedman at 2016-05-28 07:32:19

  2. I don't know how to triage this since I don't really understand assembly, but this is what we get today: https://gist.github.com/Mark-Simulacrum/c1e2b1b651ed7c99a8257ee3f8b52fac.

    Mark Rousskov at 2017-05-04 12:30:45

  3. I am not sure how to triage either, as the OP didn't include the old asm output.

    @kirillkh is this issue still relevant?

    Steve Klabnik at 2018-10-31 20:11:16

  4. There's a huge block of movups instructions in the loop they mentioned, and no movaps ones, so I figure the issue is still present.

    Hanna Kruppe at 2018-10-31 20:18:30

  5. Yes, that is the issue.

    Kirill Khazan at 2018-11-04 05:43:20

  6. This is likely going to be fixed by #55633.

    Nikita Popov at 2018-11-04 09:27:37

  7. Unfortunately #55633 did not fix this, because LLVM is still missing support for differing src/dst alignment in SelectionDAG construction.

    Nikita Popov at 2018-11-11 11:56:43

  8. I've submitted https://reviews.llvm.org/D54471 for supporting src/dst alignment in SelectionDAG.

    Nikita Popov at 2018-11-14 18:36:33