mirror of https://github.com/golang/go.git
cmd/7g: remove loads that only load an immediate to be later used by ADD/SUB
Optimize the sequence: MOV $imm, Rt ADD Rt, Rs, Rd into: ADD $imm, Rs, Rd Saves 66k in godoc. Change-Id: I27b4aaa0ec80a59472fe2e5816efdf3db9c901ee Reviewed-on: https://go-review.googlesource.com/8632 Reviewed-by: Minux Ma <minux@golang.org>
This commit is contained in:
parent
4a71b91d29
commit
a6bade60b0
|
|
@ -129,6 +129,46 @@ loop1:
|
|||
goto ret /* allow following code improvement to be suppressed */
|
||||
}
|
||||
|
||||
// MOVD $c, R'; ADD R', R (R' unused) -> ADD $c, R
|
||||
for r := (*gc.Flow)(g.Start); r != nil; r = r.Link {
|
||||
p = r.Prog
|
||||
switch p.As {
|
||||
default:
|
||||
continue
|
||||
|
||||
case arm64.AMOVD:
|
||||
if p.To.Type != obj.TYPE_REG {
|
||||
continue
|
||||
}
|
||||
if p.From.Type != obj.TYPE_CONST {
|
||||
continue
|
||||
}
|
||||
if p.From.Offset < 0 || 4096 <= p.From.Offset {
|
||||
continue
|
||||
}
|
||||
}
|
||||
r1 = r.Link
|
||||
if r1 == nil {
|
||||
continue
|
||||
}
|
||||
p1 = r1.Prog
|
||||
if p1.As != arm64.AADD && p1.As != arm64.ASUB { // TODO(aram): also logical after we have bimm.
|
||||
continue
|
||||
}
|
||||
if p1.From.Type != obj.TYPE_REG || p1.From.Reg != p.To.Reg {
|
||||
continue
|
||||
}
|
||||
if p1.To.Type != obj.TYPE_REG {
|
||||
continue
|
||||
}
|
||||
if gc.Debug['P'] != 0 {
|
||||
fmt.Printf("encoding $%d directly into %v in:\n%v\n%v\n", p.From.Offset, obj.Aconv(int(p1.As)), p, p1)
|
||||
}
|
||||
p1.From.Type = obj.TYPE_CONST
|
||||
p1.From = p.From
|
||||
excise(r)
|
||||
}
|
||||
|
||||
/* TODO(minux):
|
||||
* look for OP x,y,R; CMP R, $0 -> OP.S x,y,R
|
||||
* when OP can set condition codes correctly
|
||||
|
|
|
|||
Loading…
Reference in New Issue