Compiler does not propagate integer bounds information; misses bounds-check removal opportunities #71919
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
triage needed
This issue needs more specific labels
Description
Consider the following snippet:
When compiling with
-O, it produces the following assembly:Note that there is one trap, which occurs before the addition (corresponding to the explicit
precondition). The compiler is able to recognise that the addition cannot overflow.Now consider the following snippet:
From the first snippet, we know that
i + 8cannot overflow, and now we have introduced a variablek, which is even less thani. Therefore,k + 8also cannot overflow. However, the compiler is not able to recognise this:Reproduction
See description.
Alternatively, Goldbolt of those snippets.
Expected behavior
Expect the overflow check noted in the description to be optimised away.
Environment
Swift version 5.11-dev (LLVM 48dba337c6a2104, Swift 823db1f)
Target: x86_64-unknown-linux-gnu
Additional information
No response
The text was updated successfully, but these errors were encountered: