cmd/compile: unnecessary shift-check #48213
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Performance
Milestone
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
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 than0x1f
, but more importantly also that-h
is non-negative.The text was updated successfully, but these errors were encountered: