Commit 01ddc8bd authored by Dave Cheney's avatar Dave Cheney

cmd/5g: avoid temporary in slice bounds check

before

func addr(s[]int) *int {
        return &s[2]
   10c1c:       e28d0008        add     r0, sp, #8
   10c20:       e5901004        ldr     r1, [r0, #4]
   10c24:       e3a02002        mov     r2, #2
   10c28:       e1510002        cmp     r1, r2
   10c2c:       8a000000        bhi     10c34 <main.addr+0x34>
   10c30:       eb0035e6        bl      1e3d0 <runtime.panicindex>
   10c34:       e5900000        ldr     r0, [r0]
   10c38:       e2800008        add     r0, r0, #8
   10c3c:       e58d0014        str     r0, [sp, #20]
   10c40:       e49df004        pop     {pc}            ; (ldr pc, [sp], #4)

after

func addr(s[]int) *int {
	return &s[2]
   10c1c:       e28d0008        add     r0, sp, #8
   10c20:       e5901004        ldr     r1, [r0, #4]
   10c24:       e3510002        cmp     r1, #2
   10c28:       8a000000        bhi     10c30 <main.addr+0x30>
   10c2c:       eb0035e6        bl      1e3cc <runtime.panicindex>
   10c30:       e5900000        ldr     r0, [r0]
   10c34:       e2800008        add     r0, r0, #8
   10c38:       e58d0014        str     r0, [sp, #20]
   10c3c:       e49df004        pop     {pc}            ; (ldr pc, [sp], #4)

Also, relax gcmp restriction that 2nd operand must be a register. A followup
CL will address the remaining TODO items.

R=rsc, remyoudompheng, minux.ma
CC=golang-dev
https://golang.org/cl/6620064
parent 0b9fe6d2
......@@ -573,7 +573,7 @@ void
agen(Node *n, Node *res)
{
Node *nl, *nr;
Node n1, n2, n3, n4, n5, tmp;
Node n1, n2, n3, n4, tmp;
Prog *p1, *p2;
uint32 w;
uint64 v;
......@@ -715,11 +715,8 @@ agen(Node *n, Node *res)
regalloc(&n4, n1.type, N);
cgen(&n1, &n4);
nodconst(&n2, types[TUINT32], v);
regalloc(&n5, n2.type, N);
gmove(&n2, &n5);
gcmp(optoas(OCMP, types[TUINT32]), &n4, &n5);
gcmp(optoas(OCMP, types[TUINT32]), &n4, &n2);
regfree(&n4);
regfree(&n5);
p1 = gbranch(optoas(OGT, types[TUINT32]), T, +1);
ginscall(panicindex, 0);
patch(p1, pc);
......
......@@ -1103,7 +1103,7 @@ gcmp(int as, Node *lhs, Node *rhs)
{
Prog *p;
if(lhs->op != OREGISTER || rhs->op != OREGISTER)
if(lhs->op != OREGISTER)
fatal("bad operands to gcmp: %O %O", lhs->op, rhs->op);
p = gins(as, rhs, N);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment