Issue 143267
Summary Missing optimization: loop invariant memset should be hoisted if it's the only memory access in loop
Labels new issue
Assignees
Reporter WanderingAura
    Currently memset is unrolled and optimized within the body of the loop instead of being hoisted, which is suboptimal when the unrolling is less than the iteration number: https://godbolt.org/z/dK3a7xjPW.

This also means -fno-unroll-loops causes the memsets to not be optimized at all.

Previously discussed in https://github.com/llvm/llvm-project/issues/143015:

> The optimization happens as a result of unrolling, so it is affected by target-dependent heuristics. It would be legal to do it independently of unrolling by hoisting the memset out of the loop, it's just not implemented. It does work for a plain store, implemented here I believe: https://github.com/llvm/llvm-project/blob/470f456567fb6c6ee8b6e51c06a64536ca076d74/llvm/lib/Transforms/Scalar/LICM.cpp#L1269 It could be extended to the memset case. 

 _Originally posted by @nikic in [#143015](https://github.com/llvm/llvm-project/issues/143015#issuecomment-2948480418)_
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to