ldc icon indicating copy to clipboard operation
ldc copied to clipboard

Emit getelementptr inbounds nuw flag where possible

Open kubo39 opened this issue 7 months ago • 3 comments

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

kubo39 avatar May 19 '25 11:05 kubo39

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.

JohanEngelen avatar May 20 '25 22:05 JohanEngelen

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.

JohanEngelen avatar Aug 30 '25 11:08 JohanEngelen

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.)

kubo39 avatar Aug 31 '25 02:08 kubo39