package runtime_test
 
 import (
+       "bytes"
+       "internal/testenv"
        "io"
+       "os/exec"
        . "runtime"
        "runtime/debug"
        "strings"
                t.Fatalf("cr/nl in version: %q", vers)
        }
 }
+
+// TestIntendedInlining tests that specific runtime functions are inlined.
+// This allows refactoring for code clarity and re-use without fear that
+// changes to the compiler will cause silent performance regressions.
+func TestIntendedInlining(t *testing.T) {
+       if testing.Short() {
+               t.Skip("skipping in short mode")
+       }
+       testenv.MustHaveGoRun(t)
+       t.Parallel()
+
+       // want is the list of function names that should be inlined.
+       want := []string{"tophash", "add"}
+
+       m := make(map[string]bool, len(want))
+       for _, s := range want {
+               m[s] = true
+       }
+
+       cmd := testEnv(exec.Command(testenv.GoToolPath(t), "build", "-gcflags=-m", "runtime"))
+       out, err := cmd.CombinedOutput()
+       if err != nil {
+               t.Logf("%s", out)
+               t.Fatal(err)
+       }
+       lines := bytes.Split(out, []byte{'\n'})
+       for _, x := range lines {
+               f := bytes.Split(x, []byte(": can inline "))
+               if len(f) < 2 {
+                       continue
+               }
+               fn := bytes.TrimSpace(f[1])
+               delete(m, string(fn))
+       }
+
+       for s := range m {
+               t.Errorf("function %s not inlined", s)
+       }
+}