On Fri, Apr 30, 2021 at 7:51 PM 'Valentin Deleplace' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> I don't know exactly what SSA does in the compiler, but I thought it would
> be capable of optimizing f and g into the exact same generated code. Am I
> missing something?
>

Roughly, SSA would rewrite the g() function to something along the lines of

func g() string {
        s1 := "a"
        s2 = s1 + "b"
        return s
}

That is, it would make it easier to figure out where s1 is defined (since
it can only have a single static assignment in the program, we don't have
to worry if there is another path defining s := "x"). Yet, this is not a
guarantee for optimization. You still have to carry out an analysis for
when an optimization is safe to apply. The key point is that such an
analysis is far easier to perform in SSA-form. Furthermore, it is often
more efficient, so the compiler runs faster. My haphazard guess would be
that constant/value propagation happens for number-types but not for
strings.



-- 
J.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiWnmCnccg6476G-K3uxwsBHnhaQ1z%3DtkXz3zpW0bA%3D%2B6A%40mail.gmail.com.

Reply via email to