FAQ
I'm trying to get rid of the bounds check from this code

func g(a []int, b int) {
         for i := range a {
                 a[i] = b
         }
}


Now, this has to happen somewhere past cse in order to find the variables
properly. However the opt pass transforms SliceLen(a) into reading from an
argument:

before opt
     v8 = SliceLen <int> v7
     v11 = Less64 <bool> v9 v8
     If v11 -> b3 b5 (likely)

after opt
     v26 = Arg <int> {a} [8]
     v11 = Less64 <bool> v9 v26
     If v11 -> b3 b5 (likely)


This is very inconvenient because while v8 is always >= 0, for v26 it's not
obvious.

IsInBounds is lowered in the "lower pass". Maybe we can do SliceLen there,
too?

--
You received this message because you are subscribed to the Google Groups "golang-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Keith Randall at Mar 2, 2016 at 11:39 pm
    David ran into the same problem. We separated the user-type decomposing
    (structs) and the language-type decomposing (slice, string, interface,
    complex) into separate phases, with the intent that we could push the
    language-type decomposing later in the compiler. His bounds-check elim
    didn't go in so that hasn't been done yet. Maybe you can push the
    language-type decomposing later for your change. How late would you need
    it?

    On Wed, Mar 2, 2016 at 3:13 PM, Alexandru Moșoi wrote:

    I'm trying to get rid of the bounds check from this code

    func g(a []int, b int) {
    for i := range a {
    a[i] = b
    }
    }


    Now, this has to happen somewhere past cse in order to find the variables
    properly. However the opt pass transforms SliceLen(a) into reading from an
    argument:

    before opt
    v8 = SliceLen <int> v7
    v11 = Less64 <bool> v9 v8
    If v11 -> b3 b5 (likely)

    after opt
    v26 = Arg <int> {a} [8]
    v11 = Less64 <bool> v9 v26
    If v11 -> b3 b5 (likely)


    This is very inconvenient because while v8 is always >= 0, for v26 it's
    not obvious.

    IsInBounds is lowered in the "lower pass". Maybe we can do SliceLen there,
    too?
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Alexandru Moșoi at Mar 3, 2016 at 10:56 am
    I am thinking of something along these lines
    https://go-review.googlesource.com/#/c/20172/ (based
    on https://go-review.googlesource.com/#/c/20160): put lowering of
    SliceLen/SliceCap in a different pass. What do you think?

    However, after sleeping on it I realized that I can get away with lowering
    it later. I'm looking at induction variables like in for i := 0; i < n; i++
    { /* use i */ }. Regardless of the sign n all usages of i will be >= 0 and
    lower than n.

    joi, 3 martie 2016, 00:39:43 UTC+1, Keith Randall a scris:
    David ran into the same problem. We separated the user-type decomposing
    (structs) and the language-type decomposing (slice, string, interface,
    complex) into separate phases, with the intent that we could push the
    language-type decomposing later in the compiler. His bounds-check elim
    didn't go in so that hasn't been done yet. Maybe you can push the
    language-type decomposing later for your change. How late would you need
    it?


    On Wed, Mar 2, 2016 at 3:13 PM, Alexandru Moșoi <alex...@mosoi.ro
    <javascript:>> wrote:
    I'm trying to get rid of the bounds check from this code

    func g(a []int, b int) {
    for i := range a {
    a[i] = b
    }
    }


    Now, this has to happen somewhere past cse in order to find the variables
    properly. However the opt pass transforms SliceLen(a) into reading from an
    argument:

    before opt
    v8 = SliceLen <int> v7
    v11 = Less64 <bool> v9 v8
    If v11 -> b3 b5 (likely)

    after opt
    v26 = Arg <int> {a} [8]
    v11 = Less64 <bool> v9 v26
    If v11 -> b3 b5 (likely)


    This is very inconvenient because while v8 is always >= 0, for v26 it's
    not obvious.

    IsInBounds is lowered in the "lower pass". Maybe we can do SliceLen
    there, too?
    --
    You received this message because you are subscribed to the Google Groups "golang-dev" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to golang-dev+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedMar 2, '16 at 11:13p
activeMar 3, '16 at 10:56a
posts3
users2
websitegolang.org

2 users in discussion

Alexandru Moșoi: 2 posts Keith Randall: 1 post

People

Translate

site design / logo © 2021 Grokbase