unsigned long f(unsigned int n) { unsigned long total = 0; for (unsigned int i = 0; i < n; ++i) total += i; return total; } It may not be terribly useful to report this, as I can (and arguably should) write n(n-1)/2 manually, but clang does successfully transform this into: lea eax, [rdi - 1] add edi, -2 imul rdi, rax shr rdi add rdi, rax whereas GCC tries instead to vectorize and process the loop as written. Obviously, O(1) is preferable to O(n) here. This applies to both C and C++.
Isn't this bug 65855?
(In reply to joseph@codesourcery.com from comment #1) > Isn't this bug 65855? Yes *** This bug has been marked as a duplicate of bug 65855 ***