I don't know all that much about compilers, but I'm slightly surprised that Go doesn't automatically optimize the first into being the same as the second.
Generally, any modern optimization pipeline that includes global value numbering and basic memory dependence analysis will perform that transformation, yes.