1
0
mirror of https://github.com/golang/go synced 2024-11-19 22:54:39 -07:00

6c, 6g, 6l: add MOVQL to make truncation explicit

Without an explicit signal for a truncation, copy propagation
will sometimes propagate a 32-bit truncation and end up
overwriting uses of the original 64-bit value.

The case that arose in practice is in C but I believe
that the same could plausibly happen in Go.
The main reason we didn't run into the same in Go
is that I (perhaps incorrectly?) drop MOVL AX, AX
during gins, so the truncation was never generated, so
it didn't confuse the optimizer.

Fixes #1315.
Fixes #3488.

R=ken2
CC=golang-dev
https://golang.org/cl/6002043
This commit is contained in:
Russ Cox 2012-04-10 12:51:59 -04:00
parent b72c7e943c
commit e530d6a1e0
8 changed files with 54 additions and 29 deletions

View File

@ -383,6 +383,7 @@ subprop(Reg *r0)
case AMOVSB:
case AMOVSL:
case AMOVSQ:
case AMOVQL:
return 0;
case AMOVL:
@ -581,6 +582,7 @@ copyu(Prog *p, Adr *v, Adr *s)
case AMOVWLZX:
case AMOVWQSX:
case AMOVWQZX:
case AMOVQL:
case AMOVSS:
case AMOVSD:

View File

@ -211,6 +211,7 @@ regopt(Prog *p)
case AMOVWLZX:
case AMOVWQSX:
case AMOVWQZX:
case AMOVQL:
case AMOVSS:
case AMOVSD:

View File

@ -809,7 +809,6 @@ gmove(Node *f, Node *t)
case CASE( TUINT, TCHAR):
case CASE( TLONG, TCHAR):
case CASE( TULONG, TCHAR):
case CASE( TIND, TCHAR):
case CASE( TCHAR, TUCHAR):
case CASE( TUCHAR, TUCHAR):
@ -819,7 +818,6 @@ gmove(Node *f, Node *t)
case CASE( TUINT, TUCHAR):
case CASE( TLONG, TUCHAR):
case CASE( TULONG, TUCHAR):
case CASE( TIND, TUCHAR):
case CASE( TSHORT, TSHORT):
case CASE( TUSHORT,TSHORT):
@ -827,7 +825,6 @@ gmove(Node *f, Node *t)
case CASE( TUINT, TSHORT):
case CASE( TLONG, TSHORT):
case CASE( TULONG, TSHORT):
case CASE( TIND, TSHORT):
case CASE( TSHORT, TUSHORT):
case CASE( TUSHORT,TUSHORT):
@ -835,42 +832,26 @@ gmove(Node *f, Node *t)
case CASE( TUINT, TUSHORT):
case CASE( TLONG, TUSHORT):
case CASE( TULONG, TUSHORT):
case CASE( TIND, TUSHORT):
case CASE( TINT, TINT):
case CASE( TUINT, TINT):
case CASE( TLONG, TINT):
case CASE( TULONG, TINT):
case CASE( TIND, TINT):
case CASE( TINT, TUINT):
case CASE( TUINT, TUINT):
case CASE( TLONG, TUINT):
case CASE( TULONG, TUINT):
case CASE( TIND, TUINT):
case CASE( TUINT, TIND):
case CASE( TVLONG, TUINT):
case CASE( TVLONG, TULONG):
case CASE( TUVLONG, TUINT):
case CASE( TUVLONG, TULONG):
*****/
a = AMOVL;
break;
case CASE( TVLONG, TCHAR):
case CASE( TVLONG, TSHORT):
case CASE( TVLONG, TINT):
case CASE( TVLONG, TLONG):
case CASE( TUVLONG, TCHAR):
case CASE( TUVLONG, TSHORT):
case CASE( TUVLONG, TINT):
case CASE( TUVLONG, TLONG):
case CASE( TINT, TIND):
case CASE( TINT, TVLONG):
case CASE( TINT, TUVLONG):
case CASE( TLONG, TVLONG):
case CASE( TINT, TIND):
case CASE( TLONG, TIND):
case CASE( TLONG, TVLONG):
case CASE( TLONG, TUVLONG):
a = AMOVLQSX;
if(f->op == OCONST) {
f->vconst &= (uvlong)0xffffffffU;
@ -886,22 +867,53 @@ gmove(Node *f, Node *t)
case CASE( TULONG, TVLONG):
case CASE( TULONG, TUVLONG):
case CASE( TULONG, TIND):
a = AMOVL; /* same effect as AMOVLQZX */
a = AMOVLQZX;
if(f->op == OCONST) {
f->vconst &= (uvlong)0xffffffffU;
a = AMOVQ;
}
break;
case CASE( TIND, TCHAR):
case CASE( TIND, TUCHAR):
case CASE( TIND, TSHORT):
case CASE( TIND, TUSHORT):
case CASE( TIND, TINT):
case CASE( TIND, TUINT):
case CASE( TIND, TLONG):
case CASE( TIND, TULONG):
case CASE( TVLONG, TCHAR):
case CASE( TVLONG, TUCHAR):
case CASE( TVLONG, TSHORT):
case CASE( TVLONG, TUSHORT):
case CASE( TVLONG, TINT):
case CASE( TVLONG, TUINT):
case CASE( TVLONG, TLONG):
case CASE( TVLONG, TULONG):
case CASE( TUVLONG, TCHAR):
case CASE( TUVLONG, TUCHAR):
case CASE( TUVLONG, TSHORT):
case CASE( TUVLONG, TUSHORT):
case CASE( TUVLONG, TINT):
case CASE( TUVLONG, TUINT):
case CASE( TUVLONG, TLONG):
case CASE( TUVLONG, TULONG):
a = AMOVQL;
if(f->op == OCONST) {
f->vconst &= (int)0xffffffffU;
a = AMOVL;
}
break;
case CASE( TIND, TIND):
case CASE( TIND, TVLONG):
case CASE( TVLONG, TVLONG):
case CASE( TUVLONG, TVLONG):
case CASE( TVLONG, TUVLONG):
case CASE( TUVLONG, TUVLONG):
case CASE( TIND, TUVLONG):
case CASE( TVLONG, TIND):
case CASE( TVLONG, TVLONG):
case CASE( TVLONG, TUVLONG):
case CASE( TUVLONG, TIND):
case CASE( TIND, TIND):
case CASE( TUVLONG, TVLONG):
case CASE( TUVLONG, TUVLONG):
a = AMOVQ;
break;

View File

@ -706,11 +706,14 @@ gmove(Node *f, Node *t)
case CASE(TINT32, TUINT32):
case CASE(TUINT32, TINT32):
case CASE(TUINT32, TUINT32):
a = AMOVL;
break;
case CASE(TINT64, TINT32): // truncate
case CASE(TUINT64, TINT32):
case CASE(TINT64, TUINT32):
case CASE(TUINT64, TUINT32):
a = AMOVL;
a = AMOVQL;
break;
case CASE(TINT64, TINT64): // same size

View File

@ -200,6 +200,7 @@ loop1:
case AMOVWQZX:
case AMOVLQSX:
case AMOVLQZX:
case AMOVQL:
if(regtyp(&p->to)) {
r1 = rnops(uniqs(r));
if(r1 != R) {
@ -636,6 +637,7 @@ copyu(Prog *p, Adr *v, Adr *s)
case AMOVWLZX:
case AMOVWQSX:
case AMOVWQZX:
case AMOVQL:
case AMOVSS:
case AMOVSD:

View File

@ -326,6 +326,7 @@ regopt(Prog *firstp)
case AMOVWLZX:
case AMOVWQSX:
case AMOVWQZX:
case AMOVQL:
case APOPQ:
case AMOVSS:

View File

@ -741,6 +741,8 @@ enum as
APREFETCHT1,
APREFETCHT2,
APREFETCHNTA,
AMOVQL,
ALAST
};

View File

@ -1282,6 +1282,8 @@ Optab optab[] =
{ APREFETCHT1, yprefetch, Pm, 0x18,(02) },
{ APREFETCHT2, yprefetch, Pm, 0x18,(03) },
{ APREFETCHNTA, yprefetch, Pm, 0x18,(00) },
{ AMOVQL, yrl_ml, Px, 0x89 },
{ AEND },
0