// We need to fold LEAQ into the MOVx ops so that the live variable analysis knows
// what variables are being read/written by the ops.
-// Note: we turn off this merging for operations on globals when building position-independent code.
+// Note: we turn off this merging for operations on globals when building
+// position-independent code (when Flag_shared is set).
// PIC needs a spare register to load the PC into. For loads from globals into integer registers we use
// the target register, but for other loads and all stores, we need a free register. Having the LEAL be
// a separate instruction gives us that register.
argLength: 3,
reg: regInfo{
inputs: []regMask{buildReg("DI"), buildReg("AX")},
- clobbers: buildReg("DI"),
+ clobbers: buildReg("DI CX"),
+ // Note: CX is only clobbered when dynamic linking.
},
},
lea = ALEAL
mov = AMOVL
reg = REG_CX
+ if p.To.Type == obj.TYPE_REG && p.To.Reg != p.From.Reg && p.To.Reg != p.From.Index {
+ switch p.As {
+ case ALEAL, AMOVL, AMOVWLZX, AMOVBLZX, AMOVWLSX, AMOVBLSX:
+ // Special case: clobber the destination register with
+ // the PC so we don't have to clobber CX.
+ // The SSA backend depends on CX not being clobbered across these instructions.
+ // See cmd/compile/internal/ssa/gen/386.rules (search for Flag_shared).
+ reg = p.To.Reg
+ }
+ }
}
if p.As == obj.ADUFFCOPY || p.As == obj.ADUFFZERO {
dest = p.To
p.As = mov
p.To.Type = obj.TYPE_REG
- p.To.Reg = REG_CX
+ p.To.Reg = reg
p.To.Sym = nil
p.To.Name = obj.NAME_NONE
}
q.As = pAs
q.To = dest
q.From.Type = obj.TYPE_REG
- q.From.Reg = REG_CX
+ q.From.Reg = reg
}
}
if p.From3 != nil && p.From3.Name == obj.NAME_EXTERN {
return
}
var dst int16 = REG_CX
- if isName(&p.From) && p.To.Type == obj.TYPE_REG {
+ if p.To.Type == obj.TYPE_REG && p.To.Reg != p.From.Reg && p.To.Reg != p.From.Index {
switch p.As {
case ALEAL, AMOVL, AMOVWLZX, AMOVBLZX, AMOVWLSX, AMOVBLSX:
dst = p.To.Reg
- // Special case: clobber the destination register with
- // the PC so we don't have to clobber CX.
- // The SSA backend depends on CX not being clobbered across these instructions.
- // See cmd/compile/internal/ssa/gen/386.rules (search for Flag_shared).
+ // Why? See the comment near the top of rewriteToUseGot above.
}
}
q := obj.Appendp(ctxt, p)