We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider the following simple code:
@require test_fn :: proc(s1: string, s2: string) -> int #no_bounds_check { if len(s1) != len(s2) do return 0 val := make([]int, len(s1)) for i := 0; i < len(s1); i += 1 { for j := 0; j < len(s2); j += 1 { val[i] = s1[i] != s2[j] ? 1 : 0 } } return val[len(s1) - 1]; }
The line val[i] = s1[i] != s2[j] ? 1 : 0 loads s1[i] and s2[j] from memory every single time even though s1[i] can be hoisted
val[i] = s1[i] != s2[j] ? 1 : 0
s1[i]
Link to compiler explorer: https://compiler-explorer.com/z/bsM33rc35
odin report
Odin: dev-2024-12-nightly OS: Manjaro Linux, Linux 6.6.63-1-MANJARO CPU: AMD Ryzen 7 4700U with Radeon Graphics RAM: 15355 MiB Backend: LLVM 18.1.6
Loads are hoisted such that the code becomes equivalent to:
for i := 0; i < len(s1); i += 1 { ch := s1[i] for j := 0; j < len(s2); j += 1 { val[i] = ch != s2[j] ? 1 : 0 } }
Loads are not hoisted
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Context
Consider the following simple code:
The line
val[i] = s1[i] != s2[j] ? 1 : 0
loads s1[i] and s2[j] from memory every single time even thoughs1[i]
can be hoistedLink to compiler explorer: https://compiler-explorer.com/z/bsM33rc35
odin report
output:Expected Behavior
Loads are hoisted such that the code becomes equivalent to:
Current Behavior
Loads are not hoisted
The text was updated successfully, but these errors were encountered: