]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.ssa] cmd/compile: get rid of converts in unsafe.Pointer arithmetic
authorKeith Randall <khr@golang.org>
Fri, 23 Oct 2015 21:08:50 +0000 (14:08 -0700)
committerKeith Randall <khr@golang.org>
Fri, 23 Oct 2015 21:43:38 +0000 (21:43 +0000)
unsafe.Pointer->uintptr, add, then uintptr->unsafe.Pointer.
Do the add directly on the pointer type instead.

Change-Id: I5a3a32691d0a000e16975857974ed9a1039c6d28
Reviewed-on: https://go-review.googlesource.com/16281
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/ssa/gen/generic.rules
src/cmd/compile/internal/ssa/rewritegeneric.go

index 42eec3dd756bc6560e885baf661999ebf630c0e0..4dd7ac586af8dc83e900deddadb051b4d13df261 100644 (file)
 (If (Not cond) yes no) -> (If cond no yes)
 (If (ConstBool [c]) yes no) && c == 1 -> (First nil yes no)
 (If (ConstBool [c]) yes no) && c == 0 -> (First nil no yes)
+
+// Get rid of Convert ops for pointer arithmetic on unsafe.Pointer.
+(Convert (Add64 (Convert ptr) off)) -> (Add64 ptr off)
index 7f9c8559488db01c6e6d282050f3d3ce4d14e3a1..91427e2f2a334eb83aa277c17d77f26d563bd7f2 100644 (file)
@@ -354,6 +354,30 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
                goto end2eb756398dd4c6b6d126012a26284c89
        end2eb756398dd4c6b6d126012a26284c89:
                ;
+       case OpConvert:
+               // match: (Convert (Add64 (Convert ptr) off))
+               // cond:
+               // result: (Add64 ptr off)
+               {
+                       if v.Args[0].Op != OpAdd64 {
+                               goto end913a7ecf456c00ffbee36c2dbbf0e1af
+                       }
+                       if v.Args[0].Args[0].Op != OpConvert {
+                               goto end913a7ecf456c00ffbee36c2dbbf0e1af
+                       }
+                       ptr := v.Args[0].Args[0].Args[0]
+                       off := v.Args[0].Args[1]
+                       v.Op = OpAdd64
+                       v.AuxInt = 0
+                       v.Aux = nil
+                       v.resetArgs()
+                       v.AddArg(ptr)
+                       v.AddArg(off)
+                       return true
+               }
+               goto end913a7ecf456c00ffbee36c2dbbf0e1af
+       end913a7ecf456c00ffbee36c2dbbf0e1af:
+               ;
        case OpEq16:
                // match: (Eq16 x x)
                // cond: