[mypyc] Use optimized implementation for builtins.sum (#10268)
Partially fixes https://github.com/mypyc/mypyc/issues/796
This PR forces the computation of sum() to be been shown through benchmarking to speed up the execution of sum() over integers by about 2-5x.
There is some support for the start argument, but only for if 'start' is a literal expression (has a .value attribute). The current implementation doesn't work with arbitrary values for start, because I couldn't figure out how to get any Expression that could be given to be evaluated fully into something that you can initialize the retval Register to. So for example, these cases will not get optimized:
a = 1
sum((x == 0 for x in [0]), a) # won't get evaluated because a is a NameExpr
sum((x == 0 for x in [0], 0 + j) # won't get evaluated because 0 + j is an OpExpr
Co-authored-by: 97littleleaf11 <97littleleaf11@gmail.com>