1
0
mirror of https://github.com/golang/go synced 2024-11-26 17:56:55 -07:00

cmd/compile: check indirect connection between if block and phi block in addLocalInductiveFacts

CL 244579 added guard clauses to prevent a faulty state that was
possible under the incorrect logic of the uniquePred loop in
addLocalInductiveFacts. That faulty state was still making the
intended optimization, but not for the correct reason.
Removing the faulty state also removed the overly permissive application
of the optimization, and therefore made these two tests fail.
We disabled the tests of this optimization in CL 244579 to allow us to
quickly apply the fix in the CL. This CL now corrects the logic of the
uniquePred loop in order to apply the optimization correctly.

The comment above the uniquePred loop says that it will follow unique
predecessors until it reaches a join point. Without updating the child
node on each iteration, it cannot follow the chain of unique
predecessors more than one step. Adding the update to the child node
on each iteration of the loop allows the logic to follow the chain of
unique predecessors until reaching a join point (because a non-unique
predecessor will signify a join point).

Updates #40502.

Change-Id: I23d8367046a2ab3ce4be969631f9ba15dc533e6c
Reviewed-on: https://go-review.googlesource.com/c/go/+/246157
Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Trust: Dmitri Shuralyov <dmitshur@golang.org>
This commit is contained in:
Cholerae Hu 2020-07-31 13:57:48 +08:00 committed by Dmitri Shuralyov
parent d51ae66936
commit a6755fc0de
2 changed files with 3 additions and 5 deletions

View File

@ -1082,7 +1082,7 @@ func addLocalInductiveFacts(ft *factsTable, b *Block) {
return nil return nil
} }
pred, child := b.Preds[1].b, b pred, child := b.Preds[1].b, b
for ; pred != nil; pred = uniquePred(pred) { for ; pred != nil; pred, child = uniquePred(pred), pred {
if pred.Kind != BlockIf { if pred.Kind != BlockIf {
continue continue
} }

View File

@ -670,8 +670,7 @@ func oforuntil(b []int) {
i := 0 i := 0
if len(b) > i { if len(b) > i {
top: top:
// TODO: remove the todo of next line once we complete the following optimization of CL 244579 println(b[i]) // ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
// println(b[i]) // todo: ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
i++ i++
if i < len(b) { if i < len(b) {
goto top goto top
@ -721,8 +720,7 @@ func range1(b []int) {
// range2 elements are larger, so they use the general form of a range loop. // range2 elements are larger, so they use the general form of a range loop.
func range2(b [][32]int) { func range2(b [][32]int) {
for i, v := range b { for i, v := range b {
// TODO: remove the todo of next line once we complete the following optimization of CL 244579 b[i][0] = v[0] + 1 // ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
b[i][0] = v[0] + 1 // todo: ERROR "Induction variable: limits \[0,\?\), increment 1$" "Proved IsInBounds$"
if i < len(b) { // ERROR "Proved Less64$" if i < len(b) { // ERROR "Proved Less64$"
println("x") println("x")
} }