You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Swift version 5.6-dev (LLVM 70b82c8b83f6294, Swift a66435c)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 9c6a3cc01b75038ff3323416c212d827
Issue Description:
Consider the following:
functest(_front: inoutInt8, _n: Int8) {
iffront > n, n >= 0 {
front -= n
}
}
There is no combination of values which can cause to "front -= n" to fail with overflow. I've used Int8 here because it's simple to test it exhaustively, but the same applies to Int:
forfinInt8.min...Int8.max {
forninInt8.min...Int8.max {
varfront = ftest(&front, n) // Does not trap
}
}
Unfortunately, Swift (latest nightly, -O) is unable to eliminate these simple traps:
output.test(inout Swift.Int8, Swift.Int8) -> ():
test sil, sil
js .LBB1_4
mov al, byte ptr [rdi]
sub al, sil
jle .LBB1_4
jo .LBB1_5
mov byte ptr [rdi], al
.LBB1_4:
ret
.LBB1_5:
ud2
This ends up having a huge impact on performance, meaning that in most cases, the onus falls on the user to prove overflow is impossible and use non-trapping arithmetic. The compiler should do a better job of automating that.
This is probably more of an LLVM deficiency, but it hits us hard due to the prevalence of signed integers and bounds-checking.
The text was updated successfully, but these errors were encountered:
Environment
Swift version 5.6-dev (LLVM 70b82c8b83f6294, Swift a66435c)
Target: x86_64-unknown-linux-gnu
Additional Detail from JIRA
md5: 9c6a3cc01b75038ff3323416c212d827
Issue Description:
Consider the following:
There is no combination of values which can cause to "front -= n" to fail with overflow. I've used Int8 here because it's simple to test it exhaustively, but the same applies to Int:
Unfortunately, Swift (latest nightly, -O) is unable to eliminate these simple traps:
Godbolt
This ends up having a huge impact on performance, meaning that in most cases, the onus falls on the user to prove overflow is impossible and use non-trapping arithmetic. The compiler should do a better job of automating that.
This is probably more of an LLVM deficiency, but it hits us hard due to the prevalence of signed integers and bounds-checking.
The text was updated successfully, but these errors were encountered: