Consider using llvm.invariant.* intrinsics for immutable memory

6ca1323
Opened by Huon Wilson at 2023-04-05 17:38:38

Non-mutable memory that doesn't contain UnsafeCell can be marked invariant: http://llvm.org/docs/LangRef.html#llvm-invariant-start-intrinsic

http://llvm.org/docs/Frontend/PerformanceTips.html

  1. As of now, it seems that those intrinsics are only used in the global opt pass (i.e. only useful for globals), and otherwise might just mess up alias/memory dependeny analysis.

    Björn Steinbrink at 2015-03-03 09:48:31

  2. I read some LLVM ml message saying that some additional passes were taught about llvm.invariant in 2016, but I couldn't find any actual patch about that and concluded that may have been just an off-by-one error.

    Does anyone know if this is still only useful for globals?

    Cc @rust-lang/wg-codegen

    Anthony Ramine at 2018-04-02 11:33:45

  3. It appears that LLVM now uses @llvm.invariant.start to assist reasoning about loop-invariant code motion, but I am not sure if this is profitable to emit in all locations. Maybe some. https://github.com/llvm/llvm-project/blob/40a4078e14c2c6c5e2d0a1776285aa7491e791b3/llvm/lib/Transforms/Scalar/LICM.cpp#L1025-L1030

    Jubilee at 2022-07-18 03:44:37