Open
Description
Description
No response
Reproduction
for a in 0...Int8.max {
for b in 0...Int8.max {
let x = a.subtractingReportingOverflow(b).overflow
precondition(!x)
}
}
When written this way, the compiler knows that x
is always false
, and optimises away the entire loop. However, if I change the precondition to:
precondition(x == false)
Suddenly it seems unable to optimise this code. Both are compiled with -O
.
Check it out on this Godbolt
Expected behavior
When x
is a Bool
, !x
and x == false
are equivalent, so I expect the optimiser to handle them equally well.
Environment
Swift version 5.9 (swift-5.9-RELEASE)
Target: x86_64-unknown-linux-gnu
Godbolt link provided above for trying this version of the compiler on this target.
Additional information
No response