3 ms·
Rewriting it as follows, with an overflow check: void memzero_range(char* array, int start, int end) { int i = start; while (i < end) {
by gsnedders 12y ago
Rewriting it as follows, with an overflow check:
void memzero_range(char* array, int start, int end) {
int i = start;
while (i < end) {
array[i] = 0;
if (i == INT_MAX) {
assert("overflow!");
}
i++;
}
}
Clang does indeed manage to see that the check is equivalent to a start > end case (with -O1) and hoists it out of the loop. It also then rewrites the body of the loop to use the LLVM memset intrinsic!