• Josh Bleecher Snyder's avatar
    cmd/compile: optimize integer "in range" expressions · 62861889
    Josh Bleecher Snyder authored
    Use unsigned comparisons to reduce from
    two comparisons to one for integer "in range"
    checks, such as a <= b && b < c.
    We already do this for bounds checks.
    Extend it to user code.
    
    This is much easier to do in the front end than SSA.
    A back end optimization would be more powerful,
    but this is a good start.
    
    This reduces the power of some of SSA prove
    inferences (#16653), but those regressions appear
    to be rare and not worth holding this CL for.
    
    Fixes #15844.
    Fixes #16697.
    
    strconv benchmarks:
    
    name                          old time/op  new time/op   delta
    Atof64Decimal-8               41.4ns ± 3%   38.9ns ± 2%   -5.89%  (p=0.000 n=24+25)
    Atof64Float-8                 48.5ns ± 0%   46.8ns ± 3%   -3.64%  (p=0.000 n=20+23)
    Atof64FloatExp-8              97.7ns ± 4%   93.5ns ± 1%   -4.25%  (p=0.000 n=25+20)
    Atof64Big-8                    187ns ± 8%    162ns ± 2%  -13.54%  (p=0.000 n=24+22)
    Atof64RandomBits-8             250ns ± 6%    233ns ± 5%   -6.76%  (p=0.000 n=25+25)
    Atof64RandomFloats-8           160ns ± 0%    152ns ± 0%   -5.00%  (p=0.000 n=21+22)
    Atof32Decimal-8               41.1ns ± 1%   38.7ns ± 2%   -5.86%  (p=0.000 n=24+24)
    Atof32Float-8                 46.1ns ± 1%   43.5ns ± 3%   -5.63%  (p=0.000 n=21+24)
    Atof32FloatExp-8               101ns ± 4%    100ns ± 2%   -1.59%  (p=0.000 n=24+23)
    Atof32Random-8                 136ns ± 3%    133ns ± 3%   -2.83%  (p=0.000 n=22+22)
    Atoi-8                        33.8ns ± 3%   30.6ns ± 3%   -9.51%  (p=0.000 n=24+25)
    AtoiNeg-8                     31.6ns ± 3%   29.1ns ± 2%   -8.05%  (p=0.000 n=23+24)
    Atoi64-8                      48.6ns ± 1%   43.8ns ± 1%   -9.81%  (p=0.000 n=20+23)
    Atoi64Neg-8                   47.1ns ± 4%   42.0ns ± 2%  -10.83%  (p=0.000 n=25+25)
    FormatFloatDecimal-8           177ns ± 9%    178ns ± 6%     ~     (p=0.460 n=25+25)
    FormatFloat-8                  282ns ± 6%    282ns ± 3%     ~     (p=0.954 n=25+22)
    FormatFloatExp-8               259ns ± 7%    255ns ± 6%     ~     (p=0.089 n=25+24)
    FormatFloatNegExp-8            253ns ± 6%    254ns ± 6%     ~     (p=0.941 n=25+24)
    FormatFloatBig-8               340ns ± 6%    341ns ± 8%     ~     (p=0.600 n=22+25)
    AppendFloatDecimal-8          79.4ns ± 0%   80.6ns ± 6%     ~     (p=0.861 n=20+25)
    AppendFloat-8                  175ns ± 3%    174ns ± 0%     ~     (p=0.722 n=25+20)
    AppendFloatExp-8               142ns ± 4%    142ns ± 2%     ~     (p=0.948 n=25+24)
    AppendFloatNegExp-8            137ns ± 2%    138ns ± 2%   +0.70%  (p=0.001 n=24+25)
    AppendFloatBig-8               218ns ± 3%    218ns ± 4%     ~     (p=0.596 n=25+25)
    AppendFloatBinaryExp-8        80.0ns ± 4%   78.0ns ± 1%   -2.43%  (p=0.000 n=24+21)
    AppendFloat32Integer-8        82.3ns ± 3%   79.3ns ± 4%   -3.69%  (p=0.000 n=24+25)
    AppendFloat32ExactFraction-8   143ns ± 2%    143ns ± 0%     ~     (p=0.177 n=23+19)
    AppendFloat32Point-8           175ns ± 3%    175ns ± 3%     ~     (p=0.062 n=24+25)
    AppendFloat32Exp-8             139ns ± 2%    137ns ± 4%   -1.05%  (p=0.001 n=24+24)
    AppendFloat32NegExp-8          134ns ± 0%    137ns ± 4%   +2.06%  (p=0.000 n=22+25)
    AppendFloat64Fixed1-8         97.8ns ± 0%   98.6ns ± 3%     ~     (p=0.711 n=20+25)
    AppendFloat64Fixed2-8          110ns ± 3%    110ns ± 5%   -0.45%  (p=0.037 n=24+24)
    AppendFloat64Fixed3-8          102ns ± 3%    102ns ± 3%     ~     (p=0.684 n=24+24)
    AppendFloat64Fixed4-8          112ns ± 3%    110ns ± 0%   -1.43%  (p=0.000 n=25+18)
    FormatInt-8                   3.18µs ± 4%   3.10µs ± 6%   -2.54%  (p=0.001 n=24+25)
    AppendInt-8                   1.81µs ± 5%   1.80µs ± 5%     ~     (p=0.648 n=25+25)
    FormatUint-8                   812ns ± 6%    816ns ± 6%     ~     (p=0.777 n=25+25)
    AppendUint-8                   536ns ± 4%    538ns ± 3%     ~     (p=0.798 n=20+22)
    Quote-8                        605ns ± 6%    602ns ± 9%     ~     (p=0.573 n=25+25)
    QuoteRune-8                   99.5ns ± 8%  100.2ns ± 7%     ~     (p=0.432 n=25+25)
    AppendQuote-8                  361ns ± 3%    363ns ± 4%     ~     (p=0.085 n=25+25)
    AppendQuoteRune-8             23.3ns ± 3%   22.4ns ± 2%   -3.79%  (p=0.000 n=25+24)
    UnquoteEasy-8                  146ns ± 4%    145ns ± 5%     ~     (p=0.112 n=24+24)
    UnquoteHard-8                  804ns ± 6%    771ns ± 6%   -4.10%  (p=0.000 n=25+24)
    
    Change-Id: Ibd384e46e90f1cfa40503c8c6352a54c65b72980
    Reviewed-on: https://go-review.googlesource.com/27652
    Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
    Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    62861889
Name
Last commit
Last update
..
bench Loading commit data...
bugs Loading commit data...
chan Loading commit data...
ddd2.dir Loading commit data...
dwarf Loading commit data...
fixedbugs Loading commit data...
import2.dir Loading commit data...
import4.dir Loading commit data...
interface Loading commit data...
intrinsic.dir Loading commit data...
ken Loading commit data...
method4.dir Loading commit data...
safe Loading commit data...
stress Loading commit data...
syntax Loading commit data...
uintptrescapes.dir Loading commit data...
235.go Loading commit data...
64bit.go Loading commit data...
alg.go Loading commit data...
alias.go Loading commit data...
alias1.go Loading commit data...
append.go Loading commit data...
args.go Loading commit data...
assign.go Loading commit data...
assign1.go Loading commit data...
atomicload.go Loading commit data...
bigalg.go Loading commit data...
bigmap.go Loading commit data...
blank.go Loading commit data...
blank1.go Loading commit data...
bom.go Loading commit data...
bombad.go Loading commit data...
bounds.go Loading commit data...
chancap.go Loading commit data...
chanlinear.go Loading commit data...
char_lit.go Loading commit data...
char_lit1.go Loading commit data...
checkbce.go Loading commit data...
clearfat.go Loading commit data...
closedchan.go Loading commit data...
closure.go Loading commit data...
closure1.go Loading commit data...
closure2.go Loading commit data...
cmp.go Loading commit data...
cmp6.go Loading commit data...
cmplx.go Loading commit data...
cmplxdivide.c Loading commit data...
cmplxdivide.go Loading commit data...
cmplxdivide1.go Loading commit data...
complit.go Loading commit data...
complit1.go Loading commit data...
compos.go Loading commit data...
const.go Loading commit data...
const1.go Loading commit data...
const2.go Loading commit data...
const3.go Loading commit data...
const4.go Loading commit data...
const5.go Loading commit data...
const6.go Loading commit data...
convT2X.go Loading commit data...
convert.go Loading commit data...
convert1.go Loading commit data...
convert3.go Loading commit data...
convlit.go Loading commit data...
convlit1.go Loading commit data...
copy.go Loading commit data...
crlf.go Loading commit data...
ddd.go Loading commit data...
ddd1.go Loading commit data...
ddd2.go Loading commit data...
decl.go Loading commit data...
declbad.go Loading commit data...
defer.go Loading commit data...
deferfin.go Loading commit data...
deferprint.go Loading commit data...
deferprint.out Loading commit data...
divide.go Loading commit data...
divmod.go Loading commit data...
empty.go Loading commit data...
env.go Loading commit data...
eof.go Loading commit data...
eof1.go Loading commit data...
errchk Loading commit data...
escape.go Loading commit data...
escape2.go Loading commit data...
escape2n.go Loading commit data...
escape3.go Loading commit data...
escape4.go Loading commit data...
escape5.go Loading commit data...
escape_array.go Loading commit data...
escape_because.go Loading commit data...
escape_calls.go Loading commit data...
escape_closure.go Loading commit data...
escape_field.go Loading commit data...
escape_iface.go Loading commit data...
escape_indir.go Loading commit data...
escape_level.go Loading commit data...
escape_map.go Loading commit data...
escape_param.go Loading commit data...
escape_slice.go Loading commit data...
escape_struct_param1.go Loading commit data...
escape_struct_param2.go Loading commit data...
escape_struct_return.go Loading commit data...
fibo.go Loading commit data...
finprofiled.go Loading commit data...
float_lit.go Loading commit data...
float_lit2.go Loading commit data...
float_lit3.go Loading commit data...
floatcmp.go Loading commit data...
for.go Loading commit data...
func.go Loading commit data...
func1.go Loading commit data...
func2.go Loading commit data...
func3.go Loading commit data...
func4.go Loading commit data...
func5.go Loading commit data...
func6.go Loading commit data...
func7.go Loading commit data...
func8.go Loading commit data...
funcdup.go Loading commit data...
funcdup2.go Loading commit data...
gc.go Loading commit data...
gc1.go Loading commit data...
gc2.go Loading commit data...
gcstring.go Loading commit data...
goprint.go Loading commit data...
goprint.out Loading commit data...
goto.go Loading commit data...
heapsampling.go Loading commit data...
helloworld.go Loading commit data...
helloworld.out Loading commit data...
if.go Loading commit data...
import.go Loading commit data...
import1.go Loading commit data...
import2.go Loading commit data...
import4.go Loading commit data...
import5.go Loading commit data...
index.go Loading commit data...
index0.go Loading commit data...
index1.go Loading commit data...
index2.go Loading commit data...
indirect.go Loading commit data...
indirect1.go Loading commit data...
init.go Loading commit data...
init1.go Loading commit data...
initcomma.go Loading commit data...
initialize.go Loading commit data...
initializerr.go Loading commit data...
initloop.go Loading commit data...
inline.go Loading commit data...
int_lit.go Loading commit data...
intcvt.go Loading commit data...
intrinsic.go Loading commit data...
iota.go Loading commit data...
label.go Loading commit data...
label1.go Loading commit data...
linkmain.go Loading commit data...
linkmain_run.go Loading commit data...
linkobj.go Loading commit data...
linkx.go Loading commit data...
linkx_run.go Loading commit data...
literal.go Loading commit data...
live.go Loading commit data...
live1.go Loading commit data...
live2.go Loading commit data...
live_ssa.go Loading commit data...
live_syscall.go Loading commit data...
loopbce.go Loading commit data...
mallocfin.go Loading commit data...
map.go Loading commit data...
map1.go Loading commit data...
maplinear.go Loading commit data...
method.go Loading commit data...
method1.go Loading commit data...
method2.go Loading commit data...
method3.go Loading commit data...
method4.go Loading commit data...
method5.go Loading commit data...
named.go Loading commit data...
named1.go Loading commit data...
nil.go Loading commit data...
nilcheck.go Loading commit data...
nilptr.go Loading commit data...
nilptr2.go Loading commit data...
nilptr3.go Loading commit data...
nilptr3_ssa.go Loading commit data...
nilptr4.go Loading commit data...
nosplit.go Loading commit data...
nul1.go Loading commit data...
opt_branchlikely.go Loading commit data...
parentype.go Loading commit data...
peano.go Loading commit data...
phiopt.go Loading commit data...
print.go Loading commit data...
print.out Loading commit data...
printbig.go Loading commit data...
printbig.out Loading commit data...
prove.go Loading commit data...
range.go Loading commit data...
recover.go Loading commit data...
recover1.go Loading commit data...
recover2.go Loading commit data...
recover3.go Loading commit data...
recover4.go Loading commit data...
reflectmethod1.go Loading commit data...
reflectmethod2.go Loading commit data...
reflectmethod3.go Loading commit data...
reflectmethod4.go Loading commit data...
rename.go Loading commit data...
rename1.go Loading commit data...
reorder.go Loading commit data...
reorder2.go Loading commit data...
return.go Loading commit data...
rotate.go Loading commit data...
rotate0.go Loading commit data...
rotate1.go Loading commit data...
rotate2.go Loading commit data...
rotate3.go Loading commit data...
run.go Loading commit data...
rune.go Loading commit data...
runtime.go Loading commit data...
shift1.go Loading commit data...
shift2.go Loading commit data...
sieve.go Loading commit data...
sigchld.go Loading commit data...
sigchld.out Loading commit data...
simassign.go Loading commit data...
sinit.go Loading commit data...
sinit_run.go Loading commit data...
sizeof.go Loading commit data...
slice3.go Loading commit data...
slice3err.go Loading commit data...
slicecap.go Loading commit data...
sliceopt.go Loading commit data...
solitaire.go Loading commit data...
stack.go Loading commit data...
strength.go Loading commit data...
string_lit.go Loading commit data...
stringrange.go Loading commit data...
struct0.go Loading commit data...
switch.go Loading commit data...
switch2.go Loading commit data...
switch3.go Loading commit data...
switch4.go Loading commit data...
switch5.go Loading commit data...
switch6.go Loading commit data...
tinyfin.go Loading commit data...
torture.go Loading commit data...
turing.go Loading commit data...
typecheck.go Loading commit data...
typecheckloop.go Loading commit data...
typeswitch.go Loading commit data...
typeswitch1.go Loading commit data...
typeswitch2.go Loading commit data...
typeswitch3.go Loading commit data...
uintptrescapes.go Loading commit data...
uintptrescapes2.go Loading commit data...
undef.go Loading commit data...
utf.go Loading commit data...
varerr.go Loading commit data...
varinit.go Loading commit data...
writebarrier.go Loading commit data...
zerodivide.go Loading commit data...