go/ssa: sanity check the types of phi nodes

Adds a sanity check that the types of phi edges are types.Identical
to the Phi instruction.

This would have caught golang/go#57790.

Change-Id: I9818fc47fda368bfc009bfe4de66e23de759f6ca
Reviewed-on: https://go-review.googlesource.com/c/tools/+/462050
gopls-CI: kokoro <noreply+kokoro@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Tim King <taking@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/go/ssa/sanity.go b/go/ssa/sanity.go
index 3fb3f39..994e263 100644
--- a/go/ssa/sanity.go
+++ b/go/ssa/sanity.go
@@ -108,6 +108,9 @@
 			for i, e := range instr.Edges {
 				if e == nil {
 					s.errorf("phi node '%s' has no value for edge #%d from %s", instr.Comment, i, s.block.Preds[i])
+				} else if !types.Identical(instr.typ, e.Type()) {
+					s.errorf("phi node '%s' has a different type (%s) for edge #%d from %s (%s)",
+						instr.Comment, instr.Type(), i, s.block.Preds[i], e.Type())
 				}
 			}
 		}