Emit getelementptr inbounds nuw flag where possible
LLVM 19 introduces new getelementptr flag nuw.
inbounds + nuw implies that the offset is non-negative, so this could be useful for eliminating bounds/overflow check.
see also: https://discourse.llvm.org/t/rfc-add-nusw-and-nuw-flags-for-getelementptr/78672
Please be very thorough in proving that this is correct. I fear that if this is slightly incorrect, that it can lead to hard to debug miscompiles at high optimization levels.
I know it is extra work, but perhaps it is best to put this behind a flag? Then we can "test" its correctness easily on large codebases and eliminate the risk of shipping a broken (default settings) compiler.
I know it is extra work, but perhaps it is best to put this behind a flag? Then we can "test" its correctness easily on large codebases and eliminate the risk of shipping a broken (default settings) compiler.
Agreed.
(The current implementation is conservative, so it shouldn't impact performance, but I think it's a good place to start.)