]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: strength reduce *24
authorKeith Randall <khr@golang.org>
Sat, 12 Mar 2016 01:39:00 +0000 (17:39 -0800)
committerKeith Randall <khr@golang.org>
Sat, 12 Mar 2016 02:58:45 +0000 (02:58 +0000)
We use *24 a lot for pointer arithmetic when accessing slices
of slices ([][]T).  Rewrite to use an LEA and a shift.
The shift will likely be free, as it often gets folded into
an indexed load/store.

Update #14606

Change-Id: Ie0bf6dc1093876efd57e88ce5f62c26a9bf21cec
Reviewed-on: https://go-review.googlesource.com/20567
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Todd Neal <todd@tneal.org>
src/cmd/compile/internal/ssa/gen/AMD64.rules
src/cmd/compile/internal/ssa/rewriteAMD64.go

index a98301a3039b1402274df892fee02ff21bc71cc4..ae55d28c184312508b1cea990ca3868e12cbd75c 100644 (file)
 (MULQconst [3] x) -> (LEAQ2 x x)
 (MULQconst [5] x) -> (LEAQ4 x x)
 (MULQconst [9] x) -> (LEAQ8 x x)
+(MULQconst [24] x) -> (SHLQconst [3] (LEAQ2 <v.Type> x x)) // Useful for [][]T accesses
 (MULQconst [c] x) && isPowerOfTwo(c) -> (SHLQconst [log2(c)] x)
 
 // combine add/shift into LEAQ
index 698e6ab167cfa37e9e4278d019c8c8346470f54d..c98505cafe3f1111d04f099278508495b947e504 100644 (file)
@@ -8280,6 +8280,22 @@ func rewriteValueAMD64_OpAMD64MULQconst(v *Value, config *Config) bool {
                v.AddArg(x)
                return true
        }
+       // match: (MULQconst [24] x)
+       // cond:
+       // result: (SHLQconst [3] (LEAQ2 <v.Type> x x))
+       for {
+               if v.AuxInt != 24 {
+                       break
+               }
+               x := v.Args[0]
+               v.reset(OpAMD64SHLQconst)
+               v.AuxInt = 3
+               v0 := b.NewValue0(v.Line, OpAMD64LEAQ2, v.Type)
+               v0.AddArg(x)
+               v0.AddArg(x)
+               v.AddArg(v0)
+               return true
+       }
        // match: (MULQconst [c] x)
        // cond: isPowerOfTwo(c)
        // result: (SHLQconst [log2(c)] x)