Consider using llvm.invariant.* intrinsics for immutable memory
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
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
I read some LLVM ml message saying that some additional passes were taught about
llvm.invariantin 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
It appears that LLVM now uses
@llvm.invariant.startto 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-L1030Jubilee at 2022-07-18 03:44:37