if p.As == x86.AMOVLQZX {
if regtyp(&p.From) {
if p.From.Type == p.To.Type && p.From.Reg == p.To.Reg {
- if prevl(r, int(p.From.Reg)) {
+ if prevl(r, p.From.Reg) {
excise(r)
}
}
}
// is reg guaranteed to be truncated by a previous L instruction?
-func prevl(r0 *gc.Flow, reg int) bool {
+func prevl(r0 *gc.Flow, reg int16) bool {
for r := gc.Uniqp(r0); r != nil; r = gc.Uniqp(r) {
p := r.Prog
- if p.To.Type == obj.TYPE_REG && int(p.To.Reg) == reg {
+ if p.To.Type == obj.TYPE_REG && p.To.Reg == reg {
flags := progflags(p)
if flags&gc.RightWrite != 0 {
if flags&gc.SizeL != 0 {
}
}
}
-
return false
}
}
if (p.Info.Flags&gc.Move != 0) && (p.Info.Flags&(gc.SizeL|gc.SizeQ|gc.SizeF|gc.SizeD) != 0) && p.To.Type == v1.Type && p.To.Reg == v1.Reg {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type && p.From.Reg == v2.Reg {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub(&p.To, v1, v2, false) {
if gc.Debug['P'] != 0 && gc.Debug['v'] != 0 {
fmt.Printf("\tcopysub failed\n")
}
return true
}
gactive++
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy %v->%v f=%d\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("copy %v->%v f=%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
- f = 1
+ if !f && gc.Uniqp(r) == nil {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %v rar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %v used+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %v used and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %v set and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %v set and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
}
}
}
-
return true
}
switch p.As {
case obj.AJMP:
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
if p.Info.Flags&gc.RightWrite != 0 {
if copyas(&p.To, v) {
if s != nil {
- return copysub(&p.From, v, s, 1)
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ return 0
}
if copyau(&p.From, v) {
return 4
if p.Info.Flags&(gc.LeftAddr|gc.LeftRead|gc.LeftWrite|gc.RightAddr|gc.RightRead|gc.RightWrite) != 0 {
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ if copysub(&p.To, v, s, true) {
return 1
}
- return copysub(&p.To, v, s, 1)
+ return 0
}
if copyau(&p.From, v) {
return 1
}
}
-
return 0
}
return true
}
}
-
return false
}
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
+// copysub substitute s for v in a.
+// copysub returns true on failure to substitute. TODO(dfc) reverse this logic, copysub should return false on failure
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
if copyas(a, v) {
if s.Reg >= x86.REG_AX && s.Reg <= x86.REG_R15 || s.Reg >= x86.REG_X0 && s.Reg <= x86.REG_X0+15 {
- if f != 0 {
+ if f {
a.Reg = s.Reg
}
}
- return 0
+ return false
}
if regtyp(v) {
if a.Type == obj.TYPE_MEM && a.Reg == v.Reg {
if (s.Reg == x86.REG_BP || s.Reg == x86.REG_R13) && a.Index != x86.REG_NONE {
- return 1 /* can't use BP-base with index */
+ return true /* can't use BP-base with index */
}
- if f != 0 {
+ if f {
a.Reg = s.Reg
}
}
if a.Index == v.Reg {
- if f != 0 {
+ if f {
a.Index = s.Reg
}
- return 0
}
- return 0
}
- return 0
+ return false
}
func conprop(r0 *gc.Flow) {
- var p *obj.Prog
- var t int
-
p0 := r0.Prog
v0 := &p0.To
r := r0
return
}
- p = r.Prog
- t = copyu(p, v0, nil)
+ p := r.Prog
+ t := copyu(p, v0, nil)
switch t {
case 0, // miss
1: // use
}
gactive = 0
- var r *gc.Flow
var p *obj.Prog
var t int
loop1:
}
t = 0
- for r = g.Start; r != nil; r = r.Link {
+ for r := g.Start; r != nil; r = r.Link {
p = r.Prog
switch p.As {
/*
if p.To.Type == v1.Type {
if p.To.Reg == v1.Reg {
if p.Scond == arm.C_SCOND_NONE {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub1(p, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub1(p, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
if copyau(&p.From, v2) || copyau1(p, v2) || copyau(&p.To, v2) {
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub1(p, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub1(p, v1, v2, false) || copysub(&p.To, v1, v2, false) {
break
}
}
return true
}
gactive++
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy %v->%v f=%d\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("copy %v->%v f=%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
- f = 1
+ if !f && gc.Uniqp(r) == nil {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %vrar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %vused+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %vused+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %vused and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %vused and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %vset and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %vset and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
}
}
}
-
return true
}
if p.From.Offset&(1<<uint(v.Reg)) != 0 {
return 1
}
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
if p.To.Offset&(1<<uint(v.Reg)) != 0 {
return 1
}
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
arm.ATST:
/* read,, */
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
- if copysub1(p, v, s, 1) != 0 {
+ if copysub1(p, v, s, true) {
return 1
}
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
arm.ABGT,
arm.ABLE:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ if copysub1(p, v, s, true) {
return 1
}
- return copysub1(p, v, s, 1)
+ return 0
}
if copyau(&p.From, v) {
case arm.AB: /* funny */
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
-
if copyau(&p.To, v) {
return 1
}
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
return 3
- // R0 is zero, used by DUFFZERO, cannot be substituted.
+ // R0 is zero, used by DUFFZERO, cannot be substituted.
// R1 is ptr to memory, used and set, cannot be substituted.
case obj.ADUFFZERO:
if v.Type == obj.TYPE_REG {
return 0
- // R0 is scratch, set by DUFFCOPY, cannot be substituted.
+ // R0 is scratch, set by DUFFCOPY, cannot be substituted.
// R1, R2 areptr to src, dst, used and set, cannot be substituted.
case obj.ADUFFCOPY:
if v.Type == obj.TYPE_REG {
return p.Reg == v.Reg
}
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau(a, v) {
- if a.Type == obj.TYPE_SHIFT {
- if a.Offset&0xf == int64(v.Reg-arm.REG_R0) {
- a.Offset = a.Offset&^0xf | int64(s.Reg)&0xf
- }
- if (a.Offset&(1<<4) != 0) && (a.Offset>>8)&0xf == int64(v.Reg-arm.REG_R0) {
- a.Offset = a.Offset&^(0xf<<8) | (int64(s.Reg)&0xf)<<8
- }
- } else if a.Type == obj.TYPE_REGREG || a.Type == obj.TYPE_REGREG2 {
- if a.Offset == int64(v.Reg) {
- a.Offset = int64(s.Reg)
- }
- if a.Reg == v.Reg {
- a.Reg = s.Reg
- }
- } else {
+// copysub substitute s for v in a.
+// copysub returns true on failure to substitute.
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau(a, v) {
+ if a.Type == obj.TYPE_SHIFT {
+ if a.Offset&0xf == int64(v.Reg-arm.REG_R0) {
+ a.Offset = a.Offset&^0xf | int64(s.Reg)&0xf
+ }
+ if (a.Offset&(1<<4) != 0) && (a.Offset>>8)&0xf == int64(v.Reg-arm.REG_R0) {
+ a.Offset = a.Offset&^(0xf<<8) | (int64(s.Reg)&0xf)<<8
+ }
+ } else if a.Type == obj.TYPE_REGREG || a.Type == obj.TYPE_REGREG2 {
+ if a.Offset == int64(v.Reg) {
+ a.Offset = int64(s.Reg)
+ }
+ if a.Reg == v.Reg {
a.Reg = s.Reg
}
+ } else {
+ a.Reg = s.Reg
}
}
-
- return 0
+ return false
}
-func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau1(p1, v) {
- p1.Reg = s.Reg
- }
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau1(p1, v) {
+ p1.Reg = s.Reg
}
- return 0
+ return false
}
var predinfo = []struct {
func successor(r *gc.Flow) *gc.Flow {
if r.S1 != nil {
return r.S1
- } else {
- return r.S2
}
+ return r.S2
}
func applypred(rstart *gc.Flow, j *Joininfo, cond int, branch int) {
if p.Info.Flags&(gc.RightRead|gc.RightWrite) == gc.RightWrite {
if p.To.Type == v1.Type {
if p.To.Reg == v1.Reg {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub1(p, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub1(p, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
if copyau(&p.From, v2) || copyau1(p, v2) || copyau(&p.To, v2) {
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub1(p, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub1(p, v1, v2, false) || copysub(&p.To, v1, v2, false) {
break
}
}
if gc.Debug['P'] != 0 {
fmt.Printf("trying to eliminate %v->%v move from:\n%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r0.Prog)
}
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
// copy1 replaces uses of v2 with v1 starting at r and returns 1 if
// all uses were rewritten.
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy1 replace %v with %v f=%d\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("copy1 replace %v with %v f=%v\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
+ if !f && gc.Uniqp(r) == nil {
// Multiple predecessors; conservatively
// assume v1 was set on other path
- f = 1
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %v rar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %v used+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %v used and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %v set and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %v set and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
}
}
}
-
return true
}
arm64.AFMOVD:
if p.Scond == 0 {
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
return 2
}
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
return 0
arm64.AFDIVD,
arm64.AFDIVS:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
- if copysub1(p, v, s, 1) != 0 {
+ if copysub1(p, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
arm64.AFCMPD,
arm64.AFCMPS:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ if copysub1(p, v, s, true) {
return 1
}
- return copysub1(p, v, s, 1)
+ return 0
}
if copyau(&p.From, v) {
case arm64.AB: /* read p->to */
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
}
-// copyas returns 1 if a and v address the same register.
+// copyas returns true if a and v address the same register.
//
// If a is the from operand, this means this operation reads the
// register in v. If a is the to operand, this means this operation
// writes the register in v.
func copyas(a *obj.Addr, v *obj.Addr) bool {
- if regtyp(v) {
- if a.Type == v.Type {
- if a.Reg == v.Reg {
- return true
- }
- }
- }
- return false
+ return regtyp(v) && a.Type == v.Type && a.Reg == v.Reg
}
-// copyau returns 1 if a either directly or indirectly addresses the
+// copyau returns true if a either directly or indirectly addresses the
// same register as v.
//
// If a is the from operand, this means this operation reads the
return false
}
-// copyau1 returns 1 if p->reg references the same register as v and v
+// copyau1 returns true if p->reg references the same register as v and v
// is a direct reference.
func copyau1(p *obj.Prog, v *obj.Addr) bool {
- if regtyp(v) && v.Reg != 0 {
- if p.Reg == v.Reg {
- return true
- }
- }
- return false
+ return regtyp(v) && v.Reg != 0 && p.Reg == v.Reg
}
-// copysub replaces v with s in a if f!=0 or indicates it if could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on arm64).
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau(a, v) {
- a.Reg = s.Reg
- }
+// copysub replaces v with s in a if f==true or indicates it if could if f==false.
+// Returns true on failure to substitute (it always succeeds on arm64).
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau(a, v) {
+ a.Reg = s.Reg
}
- return 0
+ return false
}
-// copysub1 replaces v with s in p1->reg if f!=0 or indicates if it could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on arm64).
-func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau1(p1, v) {
- p1.Reg = s.Reg
- }
+// copysub1 replaces v with s in p1->reg if f==true or indicates if it could if f==false.
+// Returns true on failure to substitute (it always succeeds on arm64).
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau1(p1, v) {
+ p1.Reg = s.Reg
}
- return 0
+ return false
}
func sameaddr(a *obj.Addr, v *obj.Addr) bool {
// Convert uses to $0 to uses of R0 and
// propagate R0
- if regzer(&p.From) != 0 {
+ if regzer(&p.From) {
if p.To.Type == obj.TYPE_REG && !isfreg(&p.To) {
p.From.Type = obj.TYPE_REG
p.From.Reg = mips.REGZERO
gc.Ostats.Ndelmov++
}
-/*
- * regzer returns 1 if a's value is 0 (a is R0 or $0)
- */
-func regzer(a *obj.Addr) int {
+// regzer returns true if a's value is 0 (a is R0 or $0)
+func regzer(a *obj.Addr) bool {
if a.Type == obj.TYPE_CONST || a.Type == obj.TYPE_ADDR {
if a.Sym == nil && a.Reg == 0 {
if a.Offset == 0 {
- return 1
+ return true
}
}
}
- if a.Type == obj.TYPE_REG {
- if a.Reg == mips.REGZERO {
- return 1
- }
- }
- return 0
+ return a.Type == obj.TYPE_REG && a.Reg == mips.REGZERO
}
func regtyp(a *obj.Addr) bool {
if p.Info.Flags&(gc.RightRead|gc.RightWrite) == gc.RightWrite {
if p.To.Type == v1.Type {
if p.To.Reg == v1.Reg {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub1(p, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub1(p, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
if copyau(&p.From, v2) || copyau1(p, v2) || copyau(&p.To, v2) {
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub1(p, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub1(p, v1, v2, false) || copysub(&p.To, v1, v2, false) {
break
}
}
if gc.Debug['P'] != 0 {
fmt.Printf("trying to eliminate %v->%v move from:\n%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r0.Prog)
}
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
-// copy1 replaces uses of v2 with v1 starting at r and returns 1 if
+// copy1 replaces uses of v2 with v1 starting at r and returns true if
// all uses were rewritten.
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy1 replace %v with %v f=%d\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("copy1 replace %v with %v f=%v\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
+ if !f && gc.Uniqp(r) == nil {
// Multiple predecessors; conservatively
// assume v1 was set on other path
- f = 1
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %v rar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %v used+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %v used and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %v set and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %v set and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
mips.ATRUNCFW,
mips.ATRUNCDW:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
mips.ADIVF,
mips.ADIVD:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
- if copysub1(p, v, s, 1) != 0 {
+ if copysub1(p, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
mips.ADIVV,
mips.ADIVVU:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
- return copysub1(p, v, s, 1)
+ if copysub1(p, v, s, true) {
+ return 1
+ }
+ return 0
}
if copyau(&p.From, v) {
case mips.AJMP: /* read p->to */
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
return false
}
-// copyau1 returns 1 if p->reg references the same register as v and v
+// copyau1 returns true if p->reg references the same register as v and v
// is a direct reference.
func copyau1(p *obj.Prog, v *obj.Addr) bool {
- if regtyp(v) && v.Reg != 0 {
- if p.Reg == v.Reg {
- return true
- }
- }
- return false
+ return regtyp(v) && v.Reg != 0 && p.Reg == v.Reg
}
-// copysub replaces v with s in a if f!=0 or indicates it if could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on mips).
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau(a, v) {
- a.Reg = s.Reg
- }
+// copysub replaces v with s in a if f==true or indicates it if could if f==false.
+// Returns true on failure to substitute (it always succeeds on mips).
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau(a, v) {
+ a.Reg = s.Reg
}
- return 0
+ return false
}
-// copysub1 replaces v with s in p1->reg if f!=0 or indicates if it could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on mips).
-func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau1(p1, v) {
- p1.Reg = s.Reg
- }
+// copysub1 replaces v with s in p1->reg if f==true or indicates if it could if f==false.
+// Returns true on failure to substitute (it always succeeds on mips).
+// TODO(dfc) remove unused return value, remove calls with f=false as they do nothing.
+func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau1(p1, v) {
+ p1.Reg = s.Reg
}
- return 0
+ return false
}
func sameaddr(a *obj.Addr, v *obj.Addr) bool {
// Convert uses to $0 to uses of R0 and
// propagate R0
- if regzer(&p.From) != 0 {
+ if regzer(&p.From) {
if p.To.Type == obj.TYPE_REG {
p.From.Type = obj.TYPE_REG
p.From.Reg = ppc64.REGZERO
switch p.As {
case ppc64.ACMP,
ppc64.ACMPW: /* always safe? */
- if regzer(&p.To) == 0 {
+ if !regzer(&p.To) {
continue
}
r1 = r.S1
gc.Ostats.Ndelmov++
}
-/*
- * regzer returns 1 if a's value is 0 (a is R0 or $0)
- */
-func regzer(a *obj.Addr) int {
+// regzer returns true if a's value is 0 (a is R0 or $0)
+func regzer(a *obj.Addr) bool {
if a.Type == obj.TYPE_CONST || a.Type == obj.TYPE_ADDR {
if a.Sym == nil && a.Reg == 0 {
if a.Offset == 0 {
- return 1
+ return true
}
}
}
- if a.Type == obj.TYPE_REG {
- if a.Reg == ppc64.REGZERO {
- return 1
- }
- }
- return 0
+ return a.Type == obj.TYPE_REG && a.Reg == ppc64.REGZERO
}
func regtyp(a *obj.Addr) bool {
if p.Info.Flags&(gc.RightRead|gc.RightWrite) == gc.RightWrite {
if p.To.Type == v1.Type {
if p.To.Reg == v1.Reg {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub1(p, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub1(p, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
if copyau(&p.From, v2) || copyau1(p, v2) || copyau(&p.To, v2) {
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub1(p, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub1(p, v1, v2, false) || copysub(&p.To, v1, v2, false) {
break
}
}
if gc.Debug['P'] != 0 {
fmt.Printf("trying to eliminate %v->%v move from:\n%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r0.Prog)
}
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
// copy1 replaces uses of v2 with v1 starting at r and returns 1 if
// all uses were rewritten.
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy1 replace %v with %v f=%d\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("copy1 replace %v with %v f=%v\n", gc.Ctxt.Dconv(v2), gc.Ctxt.Dconv(v1), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
+ if !f && gc.Uniqp(r) == nil {
// Multiple predecessors; conservatively
// assume v1 was set on other path
- f = 1
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %v rar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %v used+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %v used and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %v set and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %v set and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
ppc64.AFNEG,
ppc64.AFNEGCC:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
return 2
}
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
return 0
ppc64.AFDIVS,
ppc64.AFDIV:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
return 1
}
- if copysub1(p, v, s, 1) != 0 {
+ if copysub1(p, v, s, true) {
return 1
}
// Update only indirect uses of v in p->to
if !copyas(&p.To, v) {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
}
ppc64.AFCMPO,
ppc64.AFCMPU:
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ if copysub(&p.To, v, s, true) {
return 1
}
- return copysub(&p.To, v, s, 1)
+ return 0
}
if copyau(&p.From, v) {
// mov and a branch).
case ppc64.ABR: /* read p->to */
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
-
if copyau(&p.To, v) {
return 4
}
}
}
-// copyas returns 1 if a and v address the same register.
+// copyas returns true if a and v address the same register.
//
// If a is the from operand, this means this operation reads the
// register in v. If a is the to operand, this means this operation
// writes the register in v.
func copyas(a *obj.Addr, v *obj.Addr) bool {
- if regtyp(v) {
- if a.Type == v.Type {
- if a.Reg == v.Reg {
- return true
- }
- }
- }
- return false
+ return regtyp(v) && a.Type == v.Type && a.Reg == v.Reg
}
-// copyau returns 1 if a either directly or indirectly addresses the
+// copyau returns true if a either directly or indirectly addresses the
// same register as v.
//
// If a is the from operand, this means this operation reads the
return false
}
-// copyau1 returns 1 if p->reg references the same register as v and v
+// copyau1 returns true if p->reg references the same register as v and v
// is a direct reference.
func copyau1(p *obj.Prog, v *obj.Addr) bool {
- if regtyp(v) && v.Reg != 0 {
- if p.Reg == v.Reg {
- return true
- }
- }
- return false
+ return regtyp(v) && v.Reg != 0 && p.Reg == v.Reg
}
-// copysub replaces v with s in a if f!=0 or indicates it if could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on ppc64).
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau(a, v) {
- a.Reg = s.Reg
- }
+// copysub replaces v with s in a if f==true or indicates it if could if f==false.
+// Returns true on failure to substitute (it always succeeds on ppc64).
+// TODO(dfc) remove unused return value and callers where f=false.
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau(a, v) {
+ a.Reg = s.Reg
}
- return 0
+ return false
}
-// copysub1 replaces v with s in p1->reg if f!=0 or indicates if it could if f==0.
-// Returns 1 on failure to substitute (it always succeeds on ppc64).
-func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f int) int {
- if f != 0 {
- if copyau1(p1, v) {
- p1.Reg = s.Reg
- }
+// copysub1 replaces v with s in p1->reg if f==true or indicates if it could if f==false.
+// Returns true on failure to substitute (it always succeeds on ppc64).
+// TODO(dfc) remove unused return value and callers where f=false.
+func copysub1(p1 *obj.Prog, v *obj.Addr, s *obj.Addr, f bool) bool {
+ if f && copyau1(p1, v) {
+ p1.Reg = s.Reg
}
- return 0
+ return false
}
func sameaddr(a *obj.Addr, v *obj.Addr) bool {
}
if (p.Info.Flags&gc.Move != 0) && (p.Info.Flags&(gc.SizeL|gc.SizeQ|gc.SizeF|gc.SizeD) != 0) && p.To.Type == v1.Type && p.To.Reg == v1.Reg {
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("gotit: %v->%v\n%v", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), r.Prog)
if p.From.Type == v2.Type && p.From.Reg == v2.Reg {
for r = gc.Uniqs(r); r != r0; r = gc.Uniqs(r) {
p = r.Prog
- copysub(&p.From, v1, v2, 1)
- copysub(&p.To, v1, v2, 1)
+ copysub(&p.From, v1, v2, true)
+ copysub(&p.To, v1, v2, true)
if gc.Debug['P'] != 0 {
fmt.Printf("%v\n", r.Prog)
}
if copyau(&p.From, v2) || copyau(&p.To, v2) {
break
}
- if copysub(&p.From, v1, v2, 0) != 0 || copysub(&p.To, v1, v2, 0) != 0 {
+ if copysub(&p.From, v1, v2, false) || copysub(&p.To, v1, v2, false) {
break
}
}
return true
}
gactive++
- return copy1(v1, v2, r0.S1, 0)
+ return copy1(v1, v2, r0.S1, false)
}
-func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f int) bool {
+func copy1(v1 *obj.Addr, v2 *obj.Addr, r *gc.Flow, f bool) bool {
if uint32(r.Active) == gactive {
if gc.Debug['P'] != 0 {
fmt.Printf("act set; return 1\n")
r.Active = int32(gactive)
if gc.Debug['P'] != 0 {
- fmt.Printf("copy %v->%v f=%d\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("copy %v->%v f=%v\n", gc.Ctxt.Dconv(v1), gc.Ctxt.Dconv(v2), f)
}
- var t int
- var p *obj.Prog
for ; r != nil; r = r.S1 {
- p = r.Prog
+ p := r.Prog
if gc.Debug['P'] != 0 {
fmt.Printf("%v", p)
}
- if f == 0 && gc.Uniqp(r) == nil {
- f = 1
+ if !f && gc.Uniqp(r) == nil {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; merge; f=%d", f)
+ fmt.Printf("; merge; f=%v", f)
}
}
- t = copyu(p, v2, nil)
- switch t {
+ switch t := copyu(p, v2, nil); t {
case 2: /* rar, can't split */
if gc.Debug['P'] != 0 {
fmt.Printf("; %v rar; return 0\n", gc.Ctxt.Dconv(v2))
case 1, /* used, substitute */
4: /* use and set */
- if f != 0 {
+ if f {
if gc.Debug['P'] == 0 {
return false
}
if t == 4 {
- fmt.Printf("; %v used+set and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used+set and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
} else {
- fmt.Printf("; %v used and f=%d; return 0\n", gc.Ctxt.Dconv(v2), f)
+ fmt.Printf("; %v used and f=%v; return 0\n", gc.Ctxt.Dconv(v2), f)
}
return false
}
}
}
- if f == 0 {
- t = copyu(p, v1, nil)
- if f == 0 && (t == 2 || t == 3 || t == 4) {
- f = 1
+ if !f {
+ t := copyu(p, v1, nil)
+ if t == 2 || t == 3 || t == 4 {
+ f = true
if gc.Debug['P'] != 0 {
- fmt.Printf("; %v set and !f; f=%d", gc.Ctxt.Dconv(v1), f)
+ fmt.Printf("; %v set and !f; f=%v", gc.Ctxt.Dconv(v1), f)
}
}
}
}
}
}
-
return true
}
switch p.As {
case obj.AJMP:
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
}
if s != nil {
- if copysub(&p.To, v, s, 1) != 0 {
+ if copysub(&p.To, v, s, true) {
return 1
}
return 0
if p.Info.Flags&gc.RightWrite != 0 {
if copyas(&p.To, v) {
if s != nil {
- return copysub(&p.From, v, s, 1)
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ return 0
}
if copyau(&p.From, v) {
return 4
if p.Info.Flags&(gc.LeftAddr|gc.LeftRead|gc.LeftWrite|gc.RightAddr|gc.RightRead|gc.RightWrite) != 0 {
if s != nil {
- if copysub(&p.From, v, s, 1) != 0 {
+ if copysub(&p.From, v, s, true) {
+ return 1
+ }
+ if copysub(&p.To, v, s, true) {
return 1
}
- return copysub(&p.To, v, s, 1)
+ return 0
}
-
if copyau(&p.From, v) {
return 1
}
return 1
}
}
-
return 0
}
return false
}
-/*
- * substitute s for v in a
- * return failure to substitute
- */
-func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f int) int {
+// copysub substitute s for v in a.
+// copysub returns true on failure to substitute.
+// TODO(dfc) reverse this logic to return false on sunstitution failure.
+func copysub(a *obj.Addr, v *obj.Addr, s *obj.Addr, f bool) bool {
if copyas(a, v) {
- reg := int(s.Reg)
- if reg >= x86.REG_AX && reg <= x86.REG_DI || reg >= x86.REG_X0 && reg <= x86.REG_X7 {
- if f != 0 {
- a.Reg = int16(reg)
+ if s.Reg >= x86.REG_AX && s.Reg <= x86.REG_DI || s.Reg >= x86.REG_X0 && s.Reg <= x86.REG_X7 {
+ if f {
+ a.Reg = s.Reg
}
}
-
- return 0
+ return false
}
if regtyp(v) {
- reg := int(v.Reg)
- if (a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && int(a.Reg) == reg {
+ if (a.Type == obj.TYPE_MEM || a.Type == obj.TYPE_ADDR) && a.Reg == v.Reg {
if (s.Reg == x86.REG_BP) && a.Index != x86.REG_NONE {
- return 1 /* can't use BP-base with index */
+ return true /* can't use BP-base with index */
}
- if f != 0 {
+ if f {
a.Reg = s.Reg
}
}
- // return 0;
- if int(a.Index) == reg {
- if f != 0 {
+ if a.Index == v.Reg {
+ if f {
a.Index = s.Reg
}
- return 0
}
-
- return 0
}
-
- return 0
+ return false
}
func conprop(r0 *gc.Flow) {
var p *obj.Prog
- var t int
p0 := r0.Prog
v0 := &p0.To
}
p = r.Prog
- t = copyu(p, v0, nil)
- switch t {
+ switch copyu(p, v0, nil) {
case 0, // miss
1: // use
goto loop