{{ message }}

# cmd/compile: teach prove about min#30584

Open
opened this issue Mar 5, 2019 · 1 comment
Open

# cmd/compile: teach prove about min#30584

opened this issue Mar 5, 2019 · 1 comment
Labels
Milestone

### josharian commented Mar 5, 2019

 ```package p func f(x, y []int) { n := len(x) if len(y) < n { n = len(y) } for i := 0; i < n; i++ { _ = x[i] _ = y[i] } }``` Ideally there would be no bounds checks in the loop. Right now there are. This grew out of a conversation in CL 164966. The text was updated successfully, but these errors were encountered:

### zdjones commented Mar 26, 2019

 I just took a preliminary peek, @josharian I think this may relate to #25086. Information from a non-control op (Phi) in a non-branching block is required to complete the inference from `i` back to `len(x)` and `len(y)`. This code: ``````n := len(x) if len(y) < n { n = len(y) } `````` concludes with a Plain SSA block containing just a Phi Op ``````b2: ← b3 b4 v47 = Phi v9 v8 (n[int]) Plain → b5 `````` where `v8/v9` are `len(x)/len(y)`. This block doesn't branch, so prove doesn't use it. Without the relationship between `v47` and `len(x)/len(y)`, the inferential chain from `i` back to `len(x)` and `len(y)` is broken. ``````v8 = SliceLen v6 (n[int]) v9 = SliceLen v7 ... v47 = Phi v9 v8 (n[int]) ... v16 = Less64 v14 v47 ... v20 = IsInBounds v14 v8 ... v30 = IsInBounds v14 v9 ``````