You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
This adds checks in the SSA pass where if the first argument to a conditional is a 0 constant, and the second happens to be inverted from another variable that happened to already be compared to 0, it adds the knowlege that the inverted value it is </> than 0 (and only for 32 bits, and when its the 3rd block :P). This could be added for more constants, and in more advanced transformations.
I dont know how to actually run benchmarks in the gc, I get a bunch of "cannot access internal package" errors.
Activity
[-]cmd/compile: unnecesary shift-check [/-][+]cmd/compile: unnecessary shift-check [/+]JAicewizard commentedon Sep 12, 2021
another example:
https://godbolt.org/z/Ge9887jEr
JAicewizard commentedon Sep 12, 2021
Ive been investigating this second example.
at b5 it has a proof tree as follows:
It fails to utilize the intermediary values.
I added have a small patch that enables the compiler to add more data to the prove DAG, its very specific ATM but could be more general:
https://github.com/JAicewizard/go/tree/add_backwards_checks_ssa.
This adds checks in the SSA pass where if the first argument to a conditional is a 0 constant, and the second happens to be inverted from another variable that happened to already be compared to 0, it adds the knowlege that the inverted value it is
</>than 0 (and only for 32 bits, and when its the 3rd block :P). This could be added for more constants, and in more advanced transformations.I dont know how to actually run benchmarks in the gc, I get a bunch of "cannot access internal package" errors.
gopherbot commentedon Jul 17, 2024
Change https://go.dev/cl/599096 mentions this issue:
cmd/compile: rewrite the constant parts of the prove passcmd/compile: rewrite the constant parts of the prove pass