Skip to content

Commit 5f541b1

Browse files
committed
test/codegen: port MULs merging tests to codegen
And delete them from asm_go. Change-Id: I0057cbd90ca55fa51c596e32406e190f3866f93e Reviewed-on: https://go-review.googlesource.com/99815 Reviewed-by: Keith Randall <[email protected]>
1 parent 91f7406 commit 5f541b1

File tree

2 files changed

+34
-66
lines changed

2 files changed

+34
-66
lines changed

src/cmd/compile/internal/gc/asm_test.go

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -499,43 +499,6 @@ var linuxAMD64Tests = []*asmTest{
499499
`,
500500
pos: []string{"\tBTQ\t\\$60"},
501501
},
502-
// multiplication merging tests
503-
{
504-
fn: `
505-
func mul1(n int) int {
506-
return 15*n + 31*n
507-
}`,
508-
pos: []string{"\tIMULQ\t[$]46"}, // 46*n
509-
},
510-
{
511-
fn: `
512-
func mul2(n int) int {
513-
return 5*n + 7*(n+1) + 11*(n+2)
514-
}`,
515-
pos: []string{"\tIMULQ\t[$]23", "\tADDQ\t[$]29"}, // 23*n + 29
516-
},
517-
{
518-
fn: `
519-
func mul3(a, n int) int {
520-
return a*n + 19*n
521-
}`,
522-
pos: []string{"\tADDQ\t[$]19", "\tIMULQ"}, // (a+19)*n
523-
},
524-
{
525-
fn: `
526-
func mul4(n int) int {
527-
return 23*n - 9*n
528-
}`,
529-
pos: []string{"\tIMULQ\t[$]14"}, // 14*n
530-
},
531-
{
532-
fn: `
533-
func mul5(a, n int) int {
534-
return a*n - 19*n
535-
}`,
536-
pos: []string{"\tADDQ\t[$]-19", "\tIMULQ"}, // (a-19)*n
537-
},
538-
539502
// see issue 19595.
540503
// We want to merge load+op in f58, but not in f59.
541504
{
@@ -906,21 +869,6 @@ var linuxAMD64Tests = []*asmTest{
906869
}
907870

908871
var linux386Tests = []*asmTest{
909-
// multiplication merging tests
910-
{
911-
fn: `
912-
func $(n int) int {
913-
return 9*n + 14*n
914-
}`,
915-
pos: []string{"\tIMULL\t[$]23"}, // 23*n
916-
},
917-
{
918-
fn: `
919-
func $(a, n int) int {
920-
return 19*a + a*n
921-
}`,
922-
pos: []string{"\tADDL\t[$]19", "\tIMULL"}, // (n+19)*a
923-
},
924872
{
925873
// check that stack store is optimized away
926874
fn: `
@@ -931,20 +879,6 @@ var linux386Tests = []*asmTest{
931879
`,
932880
pos: []string{"TEXT\t.*, [$]0-4"},
933881
},
934-
{
935-
fn: `
936-
func mul3(n int) int {
937-
return 23*n - 9*n
938-
}`,
939-
pos: []string{"\tIMULL\t[$]14"}, // 14*n
940-
},
941-
{
942-
fn: `
943-
func mul4(a, n int) int {
944-
return n*a - a*19
945-
}`,
946-
pos: []string{"\tADDL\t[$]-19", "\tIMULL"}, // (n-19)*a
947-
},
948882
// Check that len() and cap() div by a constant power of two
949883
// are compiled into SHRL.
950884
{

test/codegen/arithmetic.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,37 @@ func Pow2Muls(n1, n2 int) (int, int) {
2424

2525
return a, b
2626
}
27+
28+
// ------------------ //
29+
// MULs merging //
30+
// ------------------ //
31+
32+
func MergeMuls1(n int) int {
33+
// amd64:"IMULQ\t[$]46"
34+
// 386:"IMULL\t[$]46"
35+
return 15*n + 31*n // 46n
36+
}
37+
38+
func MergeMuls2(n int) int {
39+
// amd64:"IMULQ\t[$]23","ADDQ\t[$]29"
40+
// 386:"IMULL\t[$]23","ADDL\t[$]29"
41+
return 5*n + 7*(n+1) + 11*(n+2) // 23n + 29
42+
}
43+
44+
func MergeMuls3(a, n int) int {
45+
// amd64:"ADDQ\t[$]19",-"IMULQ\t[$]19"
46+
// 386:"ADDL\t[$]19",-"IMULL\t[$]19"
47+
return a*n + 19*n // (a+19)n
48+
}
49+
50+
func MergeMuls4(n int) int {
51+
// amd64:"IMULQ\t[$]14"
52+
// 386:"IMULL\t[$]14"
53+
return 23*n - 9*n // 14n
54+
}
55+
56+
func MergeMuls5(a, n int) int {
57+
// amd64:"ADDQ\t[$]-19",-"IMULQ\t[$]19"
58+
// 386:"ADDL\t[$]-19",-"IMULL\t[$]19"
59+
return a*n - 19*n // (a-19)n
60+
}

0 commit comments

Comments
 (0)