Missed constant propagation of unchanged struct field across call
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
LLVM fails to infer that a struct field remains unchanged across a call when the callee only modifies a different field of the same struct.
Godbolt: https://godbolt.org/z/xaaWK47Kj
In the example, `v.size` is initialized to 0 and `makeSize()` only writes to `v.capacity`. After the call, `v.size` is still known to be 0, so:
return (v.size == 0) ? 1 : 2;
could be folded to:
return 1;
GCC performs this optimization, while Clang reloads `v.size` from the stack and emits a runtime comparison.
Contributor guide
Research direction
Reproduce the supplied Godbolt example first and compare Clang’s output with GCC’s. The issue names no local files or tests, so locate the LLVM optimization pass responsible for constant propagation across calls and its regression tests. Done means the unchanged v.size comparison is folded to return 1 without a runtime reload.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100