[llvm] [InstCombine] Forward memcpy source to load instruction (PR #140249)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri May 16 09:24:23 PDT 2025
https://github.com/dtcxzyw commented:
Consider the following case:
```
memcpy(dst, src, len);
%x = load dst
br %cond, %then, %else
then:
%y = load dst
```
This patch forwards the memcpy source pointer to `%x`, but not for `%y`. If `%x` cannot be simplified eventually, the resulting IR is:
```
memcpy(dst, src, len);
%x = load src
br %cond, %then, %else
then:
%y = load dst
```
This regression is common in real-world programs: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2354#discussion_r2093327709
Can we start in a more conservative way, by ensuring that the load can be CSEed (query `FindAvailableLoadedValue` recursively with forwarded memcpy source), or the memcpy has only one user in MemorySSA?
https://github.com/llvm/llvm-project/pull/140249
More information about the llvm-commits
mailing list