News for hackers. Stuff that matters.
Re:Push ifs up and fors down by makeitdouble on Wednesday November 15, 2023 @07:25PM (#38284340)
I think the lines gets blurred when doing early exits and guard conditions.

For instance

  if !condition_a && !conditon_b {
    return fn_d() // probably an error condition ?
  }

  if condition_a && condition_b {
    return fn_a()
  }

  if condition_a {
   fn_b()
  } else {
   fn_c()
  }
Re:Push ifs up and fors down by 1letterunixname on Wednesday November 15, 2023 @08:21PM (#38284777)
These 3 examples optimize to the the same thing because they generate identical instructions:

https://godbolt.org/z/a1Yq9rceE

Note: Inverting and rearranging conditions changes what LLVM decides to output, sometimes for the worse. --opt-level=s is counterproductive here.