diff --git a/src/cmd/compile/internal/gc/asm_test.go b/src/cmd/compile/internal/gc/asm_test.go
index f2d37e69c996b55a06de5a2ba480f5495d374971..ced465c65d78edf7079645684695546a0266e90b 100644
--- a/src/cmd/compile/internal/gc/asm_test.go
+++ b/src/cmd/compile/internal/gc/asm_test.go
@@ -578,58 +578,6 @@ var linuxAMD64Tests = []*asmTest{
 		`,
 		pos: []string{"\tSETHI\t.*\\(SP\\)"},
 	},
-	// Check that len() and cap() div by a constant power of two
-	// are compiled into SHRQ.
-	{
-		fn: `
-		func $(a []int) int {
-			return len(a) / 1024
-		}
-		`,
-		pos: []string{"\tSHRQ\t\\$10,"},
-	},
-	{
-		fn: `
-		func $(s string) int {
-			return len(s) / (4097 >> 1)
-		}
-		`,
-		pos: []string{"\tSHRQ\t\\$11,"},
-	},
-	{
-		fn: `
-		func $(a []int) int {
-			return cap(a) / ((1 << 11) + 2048)
-		}
-		`,
-		pos: []string{"\tSHRQ\t\\$12,"},
-	},
-	// Check that len() and cap() mod by a constant power of two
-	// are compiled into ANDQ.
-	{
-		fn: `
-		func $(a []int) int {
-			return len(a) % 1024
-		}
-		`,
-		pos: []string{"\tANDQ\t\\$1023,"},
-	},
-	{
-		fn: `
-		func $(s string) int {
-			return len(s) % (4097 >> 1)
-		}
-		`,
-		pos: []string{"\tANDQ\t\\$2047,"},
-	},
-	{
-		fn: `
-		func $(a []int) int {
-			return cap(a) % ((1 << 11) + 2048)
-		}
-		`,
-		pos: []string{"\tANDQ\t\\$4095,"},
-	},
 	{
 		fn: `
 		func $(p int, q *int) bool {
@@ -683,58 +631,6 @@ var linux386Tests = []*asmTest{
 		`,
 		pos: []string{"TEXT\t.*, [$]0-4"},
 	},
-	// Check that len() and cap() div by a constant power of two
-	// are compiled into SHRL.
-	{
-		fn: `
-		func $(a []int) int {
-			return len(a) / 1024
-		}
-		`,
-		pos: []string{"\tSHRL\t\\$10,"},
-	},
-	{
-		fn: `
-		func $(s string) int {
-			return len(s) / (4097 >> 1)
-		}
-		`,
-		pos: []string{"\tSHRL\t\\$11,"},
-	},
-	{
-		fn: `
-		func $(a []int) int {
-			return cap(a) / ((1 << 11) + 2048)
-		}
-		`,
-		pos: []string{"\tSHRL\t\\$12,"},
-	},
-	// Check that len() and cap() mod by a constant power of two
-	// are compiled into ANDL.
-	{
-		fn: `
-		func $(a []int) int {
-			return len(a) % 1024
-		}
-		`,
-		pos: []string{"\tANDL\t\\$1023,"},
-	},
-	{
-		fn: `
-		func $(s string) int {
-			return len(s) % (4097 >> 1)
-		}
-		`,
-		pos: []string{"\tANDL\t\\$2047,"},
-	},
-	{
-		fn: `
-		func $(a []int) int {
-			return cap(a) % ((1 << 11) + 2048)
-		}
-		`,
-		pos: []string{"\tANDL\t\\$4095,"},
-	},
 }
 
 var linuxS390XTests = []*asmTest{
diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go
index 20adc84beed9dd27b399b0b10847abe4dbe5be7f..16517cfac423c9f6d18be31d60e05bdee9cf84a0 100644
--- a/test/codegen/arithmetic.go
+++ b/test/codegen/arithmetic.go
@@ -118,3 +118,42 @@ func ConstMods(n1 uint, n2 int) (uint, int) {
 
 	return a, b
 }
+
+// Check that len() and cap() calls divided by powers of two are
+// optimized into shifts and ands
+
+func LenDiv1(a []int) int {
+	// 386:"SHRL\t[$]10"
+	// amd64:"SHRQ\t[$]10"
+	return len(a) / 1024
+}
+
+func LenDiv2(s string) int {
+	// 386:"SHRL\t[$]11"
+	// amd64:"SHRQ\t[$]11"
+	return len(s) / (4097 >> 1)
+}
+
+func LenMod1(a []int) int {
+	// 386:"ANDL\t[$]1023"
+	// amd64:"ANDQ\t[$]1023"
+	return len(a) % 1024
+}
+
+func LenMod2(s string) int {
+	// 386:"ANDL\t[$]2047"
+	// amd64:"ANDQ\t[$]2047"
+	return len(s) % (4097 >> 1)
+}
+
+func CapDiv(a []int) int {
+	// 386:"SHRL\t[$]12"
+	// amd64:"SHRQ\t[$]12"
+	return cap(a) / ((1 << 11) + 2048)
+}
+
+func CapMod(a []int) int {
+	// 386:"ANDL\t[$]4095"
+	// amd64:"ANDQ\t[$]4095"
+	return cap(a) % ((1 << 11) + 2048)
+}