https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91329
Bug ID: 91329 Summary: Unnecessary call to __cxa_throw_bad_array_new_length Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- For the code int* test(int i) { return new int[i]; } The following assembly is generated: test(int): movsx rdi, edi sub rsp, 8 movabs rax, 2305843009213693950 cmp rdi, rax ja .L2 sal rdi, 2 add rsp, 8 jmp operator new[](unsigned long) test(int) [clone .cold]: .L2: call __cxa_throw_bad_array_new_length However the `i * sizeof(int)` can not be greater than `2305843009213693950`. So the checks should be skipped. Optimal assembly should look close to: test(int): movsx rdi, edi sal rdi, 2 jmp operator new[](unsigned long)