Remove redundant checks against 0 when performing "safe integer division" (ie y == 0 ? 0 : x / y). UDIV/SDIV return 0 when divisor is 0, so the CMP+CSEL instructions are unnecessary.
Before:
udiv w0, w0, w1 cmp w0, #0 csel w0, wzr, w0, eq
After:
udiv w0, w0, w1
This patch does not optimize cases where the UDIV/SDIV instruction is guarded by a conditional branch, such as
cbz w1, zero udiv w0, w0, w1 ret zero: mov w0, wzr ret
This case could be covered in a future patch.
This needn't add brackets around single statements according to the llvm code style