What version of Go are you using (go version)?
$ go version
1.17.0
Does this issue reproduce with the latest release?
yes
What did you do?
See https://go.godbolt.org/z/o5PqscasE for code.
On line 11/12 panics when endreg, is bigger than 29.
On line 15 it is checked that h is negative.
On line 16 there is a branch that panics on negative -h.
This might make sense if h could be -128, but it cant because of the check on line 11.
What did you expect to see?
I expected the go compiler to combine these checks and to avoid the extra branch+2 instructions.
What did you see instead?
Out of the assembly I gather that the go compiler fails to link line 15 with 16.
The gc also check the same thing twice, it also fails to see that h < 0 is the same as -h >= 0.
https://go.godbolt.org/z/hsMnMa1W1 does what I expect, and the gc manages to proof that -h is less than 0x1f, but more importantly also that -h is non-negative.
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
yes
What did you do?
See https://go.godbolt.org/z/o5PqscasE for code.
On line 11/12 panics when
endreg, is bigger than 29.On line 15 it is checked that
his negative.On line 16 there is a branch that panics on negative
-h.This might make sense if
hcould be -128, but it cant because of the check on line 11.What did you expect to see?
I expected the go compiler to combine these checks and to avoid the extra branch+2 instructions.
What did you see instead?
Out of the assembly I gather that the go compiler fails to link line 15 with 16.
The gc also check the same thing twice, it also fails to see that
h < 0is the same as-h >= 0.https://go.godbolt.org/z/hsMnMa1W1 does what I expect, and the gc manages to proof that
-his less than0x1f, but more importantly also that-his non-negative.