-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Open
Labels
SILOptimizerArea → compiler: SIL optimization passesArea → compiler: SIL optimization passesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfrun-time performanceswift 5.9unexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output
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
Metadata
Metadata
Assignees
Labels
SILOptimizerArea → compiler: SIL optimization passesArea → compiler: SIL optimization passesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfrun-time performanceswift 5.9unexpected behaviorBug: Unexpected behavior or incorrect outputBug: Unexpected behavior or incorrect output