[dev.ssa] cmd/compile/internal/ssa: handle returns correctly

Make sure that return blocks take a store as their control.  Without
this, code was getting inserted between the return and exit blocks.

Use AEND to mark the end of code.  The live variable analysis gets
confused when routines end like:
    JMP earlier
    RET
because the RET is unreachable.  The RET was incorrectly added to the
last basic block, rendering the JMP invisible to the CFG builder.

Change-Id: I91b32c8b37075347243ff039b4e4385856fba7cd
Reviewed-on: https://go-review.googlesource.com/14398
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go
index 96d6204..9791967 100644
--- a/src/cmd/compile/internal/gc/ssa.go
+++ b/src/cmd/compile/internal/gc/ssa.go
@@ -116,8 +116,11 @@
 	s.stmtList(fn.Nbody)
 
 	// fallthrough to exit
-	if b := s.endBlock(); b != nil {
+	if s.curBlock != nil {
+		m := s.mem()
+		b := s.endBlock()
 		b.Kind = ssa.BlockRet
+		b.Control = m
 		b.AddEdgeTo(s.exit)
 	}
 
@@ -575,8 +578,10 @@
 
 	case ORETURN:
 		s.stmtList(n.List)
+		m := s.mem()
 		b := s.endBlock()
 		b.Kind = ssa.BlockRet
+		b.Control = m
 		b.AddEdgeTo(s.exit)
 
 	case OCONTINUE, OBREAK:
@@ -2631,8 +2636,6 @@
 		p.To.Val = s.deferTarget
 	}
 
-	Pc.As = obj.ARET // overwrite AEND
-
 	if logProgs {
 		for p := ptxt; p != nil; p = p.Link {
 			var s string