https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91866
Bug ID: 91866 Summary: Sign extend of an int is not recognized Product: gcc Version: 10.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Consider the example: using size_t = unsigned long long; size_t index0(int i) { return size_t(i + 1) - 1; } GCC generates the following assembly: index0(int): lea eax, [rdi+1] cdqe sub rax, 1 ret However a more optimal assembly is possible: index0(int): # @index0(int) movsxd rax, edi ret Godbolt playground: https://godbolt.org/z/3j7_SE