1
0
mirror of https://github.com/golang/go synced 2024-10-05 20:21:21 -06:00

[dev.ssa] cmd/compile/internal/ssa: Split OpConst into an OpConst8, OpConst16, ...

Convert the polymorphic OpConst into monomorphic variants.

Change-Id: I90bb8894fbac04ca5e5484ea260c131ef8b506fb
Reviewed-on: https://go-review.googlesource.com/12798
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
This commit is contained in:
Keith Randall 2015-07-28 14:19:20 -07:00
parent 25d1916816
commit 9cb332efd4
16 changed files with 546 additions and 313 deletions

View File

@ -347,9 +347,33 @@ func (s *state) entryNewValue2(op ssa.Op, t ssa.Type, arg0, arg1 *ssa.Value) *ss
return s.f.Entry.NewValue2(s.peekLine(), op, t, arg0, arg1) return s.f.Entry.NewValue2(s.peekLine(), op, t, arg0, arg1)
} }
// constInt adds a new const int value to the entry block. // constInt* routines add a new const int value to the entry block.
func (s *state) constInt8(t ssa.Type, c int8) *ssa.Value {
return s.f.ConstInt8(s.peekLine(), t, c)
}
func (s *state) constInt16(t ssa.Type, c int16) *ssa.Value {
return s.f.ConstInt16(s.peekLine(), t, c)
}
func (s *state) constInt32(t ssa.Type, c int32) *ssa.Value {
return s.f.ConstInt32(s.peekLine(), t, c)
}
func (s *state) constInt64(t ssa.Type, c int64) *ssa.Value {
return s.f.ConstInt64(s.peekLine(), t, c)
}
func (s *state) constIntPtr(t ssa.Type, c int64) *ssa.Value {
if s.config.PtrSize == 4 && int64(int32(c)) != c {
s.Fatalf("pointer constant too big %d", c)
}
return s.f.ConstIntPtr(s.peekLine(), t, c)
}
func (s *state) constInt(t ssa.Type, c int64) *ssa.Value { func (s *state) constInt(t ssa.Type, c int64) *ssa.Value {
return s.f.ConstInt(s.peekLine(), t, c) if s.config.IntSize == 8 {
return s.constInt64(t, c)
}
if int64(int32(c)) != c {
s.Fatalf("integer constant too big %d", c)
}
return s.constInt32(t, int32(c))
} }
// ssaStmtList converts the statement n to SSA and adds it to s. // ssaStmtList converts the statement n to SSA and adds it to s.
@ -584,7 +608,7 @@ func (s *state) stmt(n *Node) {
if n.Left != nil { if n.Left != nil {
cond = s.expr(n.Left) cond = s.expr(n.Left)
} else { } else {
cond = s.entryNewValue0A(ssa.OpConst, Types[TBOOL], true) cond = s.entryNewValue0A(ssa.OpConstBool, Types[TBOOL], true)
} }
b = s.endBlock() b = s.endBlock()
b.Kind = ssa.BlockIf b.Kind = ssa.BlockIf
@ -862,11 +886,26 @@ func (s *state) expr(n *Node) *ssa.Value {
case OLITERAL: case OLITERAL:
switch n.Val().Ctype() { switch n.Val().Ctype() {
case CTINT: case CTINT:
return s.constInt(n.Type, Mpgetfix(n.Val().U.(*Mpint))) i := Mpgetfix(n.Val().U.(*Mpint))
case CTSTR, CTBOOL: switch n.Type.Size() {
return s.entryNewValue0A(ssa.OpConst, n.Type, n.Val().U) case 1:
return s.constInt8(n.Type, int8(i))
case 2:
return s.constInt16(n.Type, int16(i))
case 4:
return s.constInt32(n.Type, int32(i))
case 8:
return s.constInt64(n.Type, i)
default:
s.Fatalf("bad integer size %d", n.Type.Size())
return nil
}
case CTSTR:
return s.entryNewValue0A(ssa.OpConstString, n.Type, n.Val().U)
case CTBOOL:
return s.entryNewValue0A(ssa.OpConstBool, n.Type, n.Val().U)
case CTNIL: case CTNIL:
return s.entryNewValue0(ssa.OpConst, n.Type) return s.entryNewValue0(ssa.OpConstNil, n.Type)
default: default:
s.Unimplementedf("unhandled OLITERAL %v", n.Val().Ctype()) s.Unimplementedf("unhandled OLITERAL %v", n.Val().Ctype())
return nil return nil
@ -1020,7 +1059,7 @@ func (s *state) expr(n *Node) *ssa.Value {
case ODOTPTR: case ODOTPTR:
p := s.expr(n.Left) p := s.expr(n.Left)
s.nilCheck(p) s.nilCheck(p)
p = s.newValue2(ssa.OpAddPtr, p.Type, p, s.constInt(s.config.Uintptr, n.Xoffset)) p = s.newValue2(ssa.OpAddPtr, p.Type, p, s.constIntPtr(s.config.Uintptr, n.Xoffset))
return s.newValue2(ssa.OpLoad, n.Type, p, s.mem()) return s.newValue2(ssa.OpLoad, n.Type, p, s.mem())
case OINDEX: case OINDEX:
@ -1031,10 +1070,10 @@ func (s *state) expr(n *Node) *ssa.Value {
var elemtype *Type var elemtype *Type
var len *ssa.Value var len *ssa.Value
if n.Left.Type.IsString() { if n.Left.Type.IsString() {
len = s.newValue1(ssa.OpStringLen, s.config.Uintptr, a) len = s.newValue1(ssa.OpStringLen, s.config.Int, a)
elemtype = Types[TUINT8] elemtype = Types[TUINT8]
} else { } else {
len = s.constInt(s.config.Uintptr, n.Left.Type.Bound) len = s.constInt(s.config.Int, n.Left.Type.Bound)
elemtype = n.Left.Type.Type elemtype = n.Left.Type.Type
} }
s.boundsCheck(i, len) s.boundsCheck(i, len)
@ -1149,12 +1188,25 @@ func (s *state) assign(op uint8, left *Node, right *Node) {
// zeroVal returns the zero value for type t. // zeroVal returns the zero value for type t.
func (s *state) zeroVal(t *Type) *ssa.Value { func (s *state) zeroVal(t *Type) *ssa.Value {
switch { switch {
case t.IsInteger():
switch t.Size() {
case 1:
return s.constInt8(t, 0)
case 2:
return s.constInt16(t, 0)
case 4:
return s.constInt32(t, 0)
case 8:
return s.constInt64(t, 0)
default:
s.Fatalf("bad sized integer type %s", t)
}
case t.IsString(): case t.IsString():
return s.entryNewValue0A(ssa.OpConst, t, "") return s.entryNewValue0A(ssa.OpConstString, t, "")
case t.IsInteger() || t.IsPtr(): case t.IsPtr():
return s.entryNewValue0(ssa.OpConst, t) return s.entryNewValue0(ssa.OpConstNil, t)
case t.IsBoolean(): case t.IsBoolean():
return s.entryNewValue0A(ssa.OpConst, t, false) // TODO: store bools as 0/1 in AuxInt? return s.entryNewValue0A(ssa.OpConstBool, t, false) // TODO: store bools as 0/1 in AuxInt?
} }
s.Unimplementedf("zero for type %v not implemented", t) s.Unimplementedf("zero for type %v not implemented", t)
return nil return nil
@ -1212,7 +1264,7 @@ func (s *state) addr(n *Node) *ssa.Value {
a := s.addr(n.Left) a := s.addr(n.Left)
i := s.expr(n.Right) i := s.expr(n.Right)
i = s.extendIndex(i) i = s.extendIndex(i)
len := s.constInt(s.config.Uintptr, n.Left.Type.Bound) len := s.constInt(s.config.Int, n.Left.Type.Bound)
s.boundsCheck(i, len) s.boundsCheck(i, len)
return s.newValue2(ssa.OpPtrIndex, Ptrto(n.Left.Type.Type), a, i) return s.newValue2(ssa.OpPtrIndex, Ptrto(n.Left.Type.Type), a, i)
} }
@ -1222,11 +1274,11 @@ func (s *state) addr(n *Node) *ssa.Value {
return p return p
case ODOT: case ODOT:
p := s.addr(n.Left) p := s.addr(n.Left)
return s.newValue2(ssa.OpAddPtr, p.Type, p, s.constInt(s.config.Uintptr, n.Xoffset)) return s.newValue2(ssa.OpAddPtr, p.Type, p, s.constIntPtr(s.config.Uintptr, n.Xoffset))
case ODOTPTR: case ODOTPTR:
p := s.expr(n.Left) p := s.expr(n.Left)
s.nilCheck(p) s.nilCheck(p)
return s.newValue2(ssa.OpAddPtr, p.Type, p, s.constInt(s.config.Uintptr, n.Xoffset)) return s.newValue2(ssa.OpAddPtr, p.Type, p, s.constIntPtr(s.config.Uintptr, n.Xoffset))
default: default:
s.Unimplementedf("addr: bad op %v", Oconv(int(n.Op), 0)) s.Unimplementedf("addr: bad op %v", Oconv(int(n.Op), 0))
return nil return nil
@ -1570,7 +1622,7 @@ func genValue(v *ssa.Value) {
x := regnum(v.Args[0]) x := regnum(v.Args[0])
y := regnum(v.Args[1]) y := regnum(v.Args[1])
if x != r && y != r { if x != r && y != r {
p := Prog(x86.AMOVQ) p := Prog(regMoveAMD64(v.Type.Size()))
p.From.Type = obj.TYPE_REG p.From.Type = obj.TYPE_REG
p.From.Reg = x p.From.Reg = x
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
@ -1731,11 +1783,22 @@ func genValue(v *ssa.Value) {
p.From.Reg = regnum(v.Args[0]) p.From.Reg = regnum(v.Args[0])
p.To.Type = obj.TYPE_CONST p.To.Type = obj.TYPE_CONST
p.To.Offset = v.AuxInt p.To.Offset = v.AuxInt
case ssa.OpAMD64MOVQconst: case ssa.OpAMD64MOVBconst, ssa.OpAMD64MOVWconst, ssa.OpAMD64MOVLconst, ssa.OpAMD64MOVQconst:
x := regnum(v) x := regnum(v)
p := Prog(x86.AMOVQ) p := Prog(v.Op.Asm())
p.From.Type = obj.TYPE_CONST p.From.Type = obj.TYPE_CONST
p.From.Offset = v.AuxInt var i int64
switch v.Op {
case ssa.OpAMD64MOVBconst:
i = int64(int8(v.AuxInt))
case ssa.OpAMD64MOVWconst:
i = int64(int16(v.AuxInt))
case ssa.OpAMD64MOVLconst:
i = int64(int32(v.AuxInt))
case ssa.OpAMD64MOVQconst:
i = v.AuxInt
}
p.From.Offset = i
p.To.Type = obj.TYPE_REG p.To.Type = obj.TYPE_REG
p.To.Reg = x p.To.Reg = x
case ssa.OpAMD64MOVQload, ssa.OpAMD64MOVLload, ssa.OpAMD64MOVWload, ssa.OpAMD64MOVBload, ssa.OpAMD64MOVBQSXload, ssa.OpAMD64MOVBQZXload: case ssa.OpAMD64MOVQload, ssa.OpAMD64MOVLload, ssa.OpAMD64MOVWload, ssa.OpAMD64MOVBload, ssa.OpAMD64MOVBQSXload, ssa.OpAMD64MOVBQZXload:
@ -1836,7 +1899,7 @@ func genValue(v *ssa.Value) {
v.Fatalf("phi arg at different location than phi %v %v %v %v", v, loc, a, f.RegAlloc[a.ID]) v.Fatalf("phi arg at different location than phi %v %v %v %v", v, loc, a, f.RegAlloc[a.ID])
} }
} }
case ssa.OpConst: case ssa.OpConst8, ssa.OpConst16, ssa.OpConst32, ssa.OpConst64, ssa.OpConstString, ssa.OpConstNil, ssa.OpConstBool:
if v.Block.Func.RegAlloc[v.ID] != nil { if v.Block.Func.RegAlloc[v.ID] != nil {
v.Fatalf("const value %v shouldn't have a location", v) v.Fatalf("const value %v shouldn't have a location", v)
} }
@ -2079,6 +2142,23 @@ var ssaRegToReg = [...]int16{
// TODO: arch-dependent // TODO: arch-dependent
} }
// regMoveAMD64 returns the register->register move opcode for the given width.
// TODO: generalize for all architectures?
func regMoveAMD64(width int64) int {
switch width {
case 1:
return x86.AMOVB
case 2:
return x86.AMOVW
case 4:
return x86.AMOVL
case 8:
return x86.AMOVQ
default:
panic("bad register width")
}
}
// regnum returns the register (in cmd/internal/obj numbering) to // regnum returns the register (in cmd/internal/obj numbering) to
// which v has been allocated. Panics if v is not assigned to a // which v has been allocated. Panics if v is not assigned to a
// register. // register.

View File

@ -17,7 +17,7 @@ func TestDeadLoop(t *testing.T) {
// dead loop // dead loop
Bloc("deadblock", Bloc("deadblock",
// dead value in dead block // dead value in dead block
Valu("deadval", OpConst, TypeBool, 0, true), Valu("deadval", OpConstBool, TypeBool, 0, true),
If("deadval", "deadblock", "exit"))) If("deadval", "deadblock", "exit")))
CheckFunc(fun.f) CheckFunc(fun.f)
@ -41,7 +41,7 @@ func TestDeadValue(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("deadval", OpConst, TypeInt64, 37, nil), Valu("deadval", OpConst64, TypeInt64, 37, nil),
Goto("exit")), Goto("exit")),
Bloc("exit", Bloc("exit",
Exit("mem"))) Exit("mem")))
@ -63,7 +63,7 @@ func TestNeverTaken(t *testing.T) {
c := NewConfig("amd64", DummyFrontend{t}) c := NewConfig("amd64", DummyFrontend{t})
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("cond", OpConst, TypeBool, 0, false), Valu("cond", OpConstBool, TypeBool, 0, false),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
If("cond", "then", "else")), If("cond", "then", "else")),
Bloc("then", Bloc("then",
@ -99,7 +99,7 @@ func TestNestedDeadBlocks(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("cond", OpConst, TypeBool, 0, false), Valu("cond", OpConstBool, TypeBool, 0, false),
If("cond", "b2", "b4")), If("cond", "b2", "b4")),
Bloc("b2", Bloc("b2",
If("cond", "b3", "b4")), If("cond", "b3", "b4")),

View File

@ -15,7 +15,7 @@ func TestDeadStore(t *testing.T) {
Bloc("entry", Bloc("entry",
Valu("start", OpArg, TypeMem, 0, ".mem"), Valu("start", OpArg, TypeMem, 0, ".mem"),
Valu("sb", OpSB, TypeInvalid, 0, nil), Valu("sb", OpSB, TypeInvalid, 0, nil),
Valu("v", OpConst, TypeBool, 0, true), Valu("v", OpConstBool, TypeBool, 0, true),
Valu("addr1", OpAddr, ptrType, 0, nil, "sb"), Valu("addr1", OpAddr, ptrType, 0, nil, "sb"),
Valu("addr2", OpAddr, ptrType, 0, nil, "sb"), Valu("addr2", OpAddr, ptrType, 0, nil, "sb"),
Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "start"), Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "start"),
@ -42,7 +42,7 @@ func TestDeadStorePhi(t *testing.T) {
Bloc("entry", Bloc("entry",
Valu("start", OpArg, TypeMem, 0, ".mem"), Valu("start", OpArg, TypeMem, 0, ".mem"),
Valu("sb", OpSB, TypeInvalid, 0, nil), Valu("sb", OpSB, TypeInvalid, 0, nil),
Valu("v", OpConst, TypeBool, 0, true), Valu("v", OpConstBool, TypeBool, 0, true),
Valu("addr", OpAddr, ptrType, 0, nil, "sb"), Valu("addr", OpAddr, ptrType, 0, nil, "sb"),
Goto("loop")), Goto("loop")),
Bloc("loop", Bloc("loop",
@ -69,7 +69,7 @@ func TestDeadStoreTypes(t *testing.T) {
Bloc("entry", Bloc("entry",
Valu("start", OpArg, TypeMem, 0, ".mem"), Valu("start", OpArg, TypeMem, 0, ".mem"),
Valu("sb", OpSB, TypeInvalid, 0, nil), Valu("sb", OpSB, TypeInvalid, 0, nil),
Valu("v", OpConst, TypeBool, 0, true), Valu("v", OpConstBool, TypeBool, 0, true),
Valu("addr1", OpAddr, t1, 0, nil, "sb"), Valu("addr1", OpAddr, t1, 0, nil, "sb"),
Valu("addr2", OpAddr, t2, 0, nil, "sb"), Valu("addr2", OpAddr, t2, 0, nil, "sb"),
Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "start"), Valu("store1", OpStore, TypeMem, 0, nil, "addr1", "v", "start"),

View File

@ -44,7 +44,7 @@ func genFwdBack(size int) []bloc {
blocs = append(blocs, blocs = append(blocs,
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto(blockn(0)), Goto(blockn(0)),
), ),
) )
@ -74,7 +74,7 @@ func genManyPred(size int) []bloc {
blocs = append(blocs, blocs = append(blocs,
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto(blockn(0)), Goto(blockn(0)),
), ),
) )
@ -85,15 +85,15 @@ func genManyPred(size int) []bloc {
switch i % 3 { switch i % 3 {
case 0: case 0:
blocs = append(blocs, Bloc(blockn(i), blocs = append(blocs, Bloc(blockn(i),
Valu("a", OpConst, TypeBool, 0, true), Valu("a", OpConstBool, TypeBool, 0, true),
Goto(blockn(i+1)))) Goto(blockn(i+1))))
case 1: case 1:
blocs = append(blocs, Bloc(blockn(i), blocs = append(blocs, Bloc(blockn(i),
Valu("a", OpConst, TypeBool, 0, true), Valu("a", OpConstBool, TypeBool, 0, true),
If("p", blockn(i+1), blockn(0)))) If("p", blockn(i+1), blockn(0))))
case 2: case 2:
blocs = append(blocs, Bloc(blockn(i), blocs = append(blocs, Bloc(blockn(i),
Valu("a", OpConst, TypeBool, 0, true), Valu("a", OpConstBool, TypeBool, 0, true),
If("p", blockn(i+1), blockn(size)))) If("p", blockn(i+1), blockn(size))))
} }
} }
@ -112,7 +112,7 @@ func genMaxPred(size int) []bloc {
blocs = append(blocs, blocs = append(blocs,
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto(blockn(0)), Goto(blockn(0)),
), ),
) )
@ -137,14 +137,14 @@ func genMaxPredValue(size int) []bloc {
blocs = append(blocs, blocs = append(blocs,
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto(blockn(0)), Goto(blockn(0)),
), ),
) )
for i := 0; i < size; i++ { for i := 0; i < size; i++ {
blocs = append(blocs, Bloc(blockn(i), blocs = append(blocs, Bloc(blockn(i),
Valu("a", OpConst, TypeBool, 0, true), Valu("a", OpConstBool, TypeBool, 0, true),
If("p", blockn(i+1), "exit"))) If("p", blockn(i+1), "exit")))
} }
@ -267,7 +267,7 @@ func TestDominatorsMultPredFwd(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
If("p", "a", "c")), If("p", "a", "c")),
Bloc("a", Bloc("a",
If("p", "b", "c")), If("p", "b", "c")),
@ -295,7 +295,7 @@ func TestDominatorsDeadCode(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, false), Valu("p", OpConstBool, TypeBool, 0, false),
If("p", "b3", "b5")), If("p", "b3", "b5")),
Bloc("b2", Exit("mem")), Bloc("b2", Exit("mem")),
Bloc("b3", Goto("b2")), Bloc("b3", Goto("b2")),
@ -318,7 +318,7 @@ func TestDominatorsMultPredRev(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto("a")), Goto("a")),
Bloc("a", Bloc("a",
If("p", "b", "entry")), If("p", "b", "entry")),
@ -346,7 +346,7 @@ func TestDominatorsMultPred(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
If("p", "a", "c")), If("p", "a", "c")),
Bloc("a", Bloc("a",
If("p", "b", "c")), If("p", "b", "c")),
@ -374,7 +374,7 @@ func TestPostDominators(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
If("p", "a", "c")), If("p", "a", "c")),
Bloc("a", Bloc("a",
If("p", "b", "c")), If("p", "b", "c")),
@ -401,7 +401,7 @@ func TestInfiniteLoop(t *testing.T) {
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("p", OpConst, TypeBool, 0, true), Valu("p", OpConstBool, TypeBool, 0, true),
Goto("a")), Goto("a")),
Bloc("a", Bloc("a",
Goto("b")), Goto("b")),

View File

@ -248,9 +248,25 @@ func (b *Block) NewValue3(line int32, op Op, t Type, arg0, arg1, arg2 *Value) *V
} }
// ConstInt returns an int constant representing its argument. // ConstInt returns an int constant representing its argument.
func (f *Func) ConstInt(line int32, t Type, c int64) *Value { func (f *Func) ConstInt8(line int32, t Type, c int8) *Value {
// TODO: cache? // TODO: cache?
return f.Entry.NewValue0I(line, OpConst, t, c) return f.Entry.NewValue0I(line, OpConst8, t, int64(c))
}
func (f *Func) ConstInt16(line int32, t Type, c int16) *Value {
// TODO: cache?
return f.Entry.NewValue0I(line, OpConst16, t, int64(c))
}
func (f *Func) ConstInt32(line int32, t Type, c int32) *Value {
// TODO: cache?
return f.Entry.NewValue0I(line, OpConst32, t, int64(c))
}
func (f *Func) ConstInt64(line int32, t Type, c int64) *Value {
// TODO: cache?
return f.Entry.NewValue0I(line, OpConst64, t, c)
}
func (f *Func) ConstIntPtr(line int32, t Type, c int64) *Value {
// TODO: cache?
return f.Entry.NewValue0I(line, OpConstPtr, t, c)
} }
func (f *Func) Logf(msg string, args ...interface{}) { f.Config.Logf(msg, args...) } func (f *Func) Logf(msg string, args ...interface{}) { f.Config.Logf(msg, args...) }

View File

@ -23,7 +23,7 @@
// Bloc("exit", // Bloc("exit",
// Exit("mem")), // Exit("mem")),
// Bloc("deadblock", // Bloc("deadblock",
// Valu("deadval", OpConst, TypeBool, 0, true), // Valu("deadval", OpConstBool, TypeBool, 0, true),
// If("deadval", "deadblock", "exit"))) // If("deadval", "deadblock", "exit")))
// //
// and the Blocks or Values used in the Func can be accessed // and the Blocks or Values used in the Func can be accessed
@ -265,8 +265,8 @@ func TestArgs(t *testing.T) {
c := NewConfig("amd64", DummyFrontend{t}) c := NewConfig("amd64", DummyFrontend{t})
fun := Fun(c, "entry", fun := Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Goto("exit")), Goto("exit")),
@ -288,8 +288,8 @@ func TestEquiv(t *testing.T) {
{ {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Goto("exit")), Goto("exit")),
@ -297,8 +297,8 @@ func TestEquiv(t *testing.T) {
Exit("mem"))), Exit("mem"))),
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Goto("exit")), Goto("exit")),
@ -309,8 +309,8 @@ func TestEquiv(t *testing.T) {
{ {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Goto("exit")), Goto("exit")),
@ -320,8 +320,8 @@ func TestEquiv(t *testing.T) {
Bloc("exit", Bloc("exit",
Exit("mem")), Exit("mem")),
Bloc("entry", Bloc("entry",
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Goto("exit"))), Goto("exit"))),
@ -354,14 +354,14 @@ func TestEquiv(t *testing.T) {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Exit("mem"))), Exit("mem"))),
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Exit("mem"))), Exit("mem"))),
}, },
// value auxint different // value auxint different
@ -369,12 +369,12 @@ func TestEquiv(t *testing.T) {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Exit("mem"))), Exit("mem"))),
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 26, nil), Valu("a", OpConst64, TypeInt64, 26, nil),
Exit("mem"))), Exit("mem"))),
}, },
// value aux different // value aux different
@ -382,12 +382,12 @@ func TestEquiv(t *testing.T) {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 0, 14), Valu("a", OpConst64, TypeInt64, 0, 14),
Exit("mem"))), Exit("mem"))),
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 0, 26), Valu("a", OpConst64, TypeInt64, 0, 26),
Exit("mem"))), Exit("mem"))),
}, },
// value args different // value args different
@ -395,15 +395,15 @@ func TestEquiv(t *testing.T) {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 14, nil), Valu("a", OpConst64, TypeInt64, 14, nil),
Valu("b", OpConst, TypeInt64, 26, nil), Valu("b", OpConst64, TypeInt64, 26, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "a", "b"),
Exit("mem"))), Exit("mem"))),
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem", OpArg, TypeMem, 0, ".mem"), Valu("mem", OpArg, TypeMem, 0, ".mem"),
Valu("a", OpConst, TypeInt64, 0, nil), Valu("a", OpConst64, TypeInt64, 0, nil),
Valu("b", OpConst, TypeInt64, 14, nil), Valu("b", OpConst64, TypeInt64, 14, nil),
Valu("sum", OpAdd64, TypeInt64, 0, nil, "b", "a"), Valu("sum", OpAdd64, TypeInt64, 0, nil, "b", "a"),
Exit("mem"))), Exit("mem"))),
}, },

View File

@ -82,7 +82,7 @@
(Rsh64 <t> x y) && y.Type.Size() == 8 -> (Rsh64 <t> x y) && y.Type.Size() == 8 ->
(SARQ <t> x (CMOVQCC <t> (SARQ <t> x (CMOVQCC <t>
(CMPQconst <TypeFlags> [64] y) (CMPQconst <TypeFlags> [64] y)
(Const <t> [63]) (MOVQconst <t> [63])
y)) y))
(Less64 x y) -> (SETL (CMPQ <TypeFlags> x y)) (Less64 x y) -> (SETL (CMPQ <TypeFlags> x y))
@ -116,16 +116,20 @@
(IsNonNil p) -> (SETNE (TESTQ <TypeFlags> p p)) (IsNonNil p) -> (SETNE (TESTQ <TypeFlags> p p))
(IsInBounds idx len) -> (SETB (CMPQ <TypeFlags> idx len)) (IsInBounds idx len) -> (SETB (CMPQ <TypeFlags> idx len))
(Move [size] dst src mem) -> (REPMOVSB dst src (Const <TypeUInt64> [size]) mem) (Move [size] dst src mem) -> (REPMOVSB dst src (MOVQconst <TypeUInt64> [size]) mem)
(Not x) -> (XORQconst [1] x) (Not x) -> (XORQconst [1] x)
(OffPtr [off] ptr) -> (ADDQconst [off] ptr) (OffPtr [off] ptr) -> (ADDQconst [off] ptr)
(Const <t> [val]) && t.IsInteger() -> (MOVQconst [val]) (Const8 [val]) -> (MOVBconst [val])
(Const <t>) && t.IsPtr() -> (MOVQconst [0]) // nil is the only const pointer (Const16 [val]) -> (MOVWconst [val])
(Const <t>) && t.IsBoolean() && !v.Aux.(bool) -> (MOVQconst [0]) (Const32 [val]) -> (MOVLconst [val])
(Const <t>) && t.IsBoolean() && v.Aux.(bool) -> (MOVQconst [1]) (Const64 [val]) -> (MOVQconst [val])
(ConstPtr [val]) -> (MOVQconst [val])
(ConstNil) -> (MOVQconst [0])
(ConstBool {b}) && !b.(bool) -> (MOVBconst [0])
(ConstBool {b}) && b.(bool) -> (MOVBconst [1])
(Addr {sym} base) -> (LEAQ {sym} base) (Addr {sym} base) -> (LEAQ {sym} base)
@ -226,15 +230,15 @@
// lower Zero instructions with word sizes // lower Zero instructions with word sizes
(Zero [0] _ mem) -> (Copy mem) (Zero [0] _ mem) -> (Copy mem)
(Zero [1] destptr mem) -> (MOVBstore destptr (Const <TypeInt8> [0]) mem) (Zero [1] destptr mem) -> (MOVBstore destptr (MOVBconst <TypeInt8> [0]) mem)
(Zero [2] destptr mem) -> (MOVWstore destptr (Const <TypeInt16> [0]) mem) (Zero [2] destptr mem) -> (MOVWstore destptr (MOVWconst <TypeInt16> [0]) mem)
(Zero [4] destptr mem) -> (MOVLstore destptr (Const <TypeInt32> [0]) mem) (Zero [4] destptr mem) -> (MOVLstore destptr (MOVLconst <TypeInt32> [0]) mem)
(Zero [8] destptr mem) -> (MOVQstore destptr (Const <TypeInt64> [0]) mem) (Zero [8] destptr mem) -> (MOVQstore destptr (MOVQconst <TypeInt64> [0]) mem)
// rewrite anything less than 4 words into a series of MOV[BWLQ] $0, ptr(off) instructions // rewrite anything less than 4 words into a series of MOV[BWLQ] $0, ptr(off) instructions
(Zero [size] destptr mem) && size < 4*8 -> (MOVXzero [size] destptr mem) (Zero [size] destptr mem) && size < 4*8 -> (MOVXzero [size] destptr mem)
// Use STOSQ to zero memory. Rewrite this into storing the words with REPSTOSQ and then filling in the remainder with linear moves // Use STOSQ to zero memory. Rewrite this into storing the words with REPSTOSQ and then filling in the remainder with linear moves
(Zero [size] destptr mem) && size >= 4*8 -> (Zero [size%8] (OffPtr <TypeUInt64> [size-(size%8)] destptr) (REPSTOSQ <TypeMem> destptr (Const <TypeUInt64> [size/8]) mem)) (Zero [size] destptr mem) && size >= 4*8 -> (Zero [size%8] (OffPtr <TypeUInt64> [size-(size%8)] destptr) (REPSTOSQ <TypeMem> destptr (MOVQconst <TypeUInt64> [size/8]) mem))
// Absorb InvertFlags into branches. // Absorb InvertFlags into branches.
(LT (InvertFlags cmp) yes no) -> (GT cmp yes no) (LT (InvertFlags cmp) yes no) -> (GT cmp yes no)
@ -249,8 +253,8 @@
(NE (InvertFlags cmp) yes no) -> (NE cmp yes no) (NE (InvertFlags cmp) yes no) -> (NE cmp yes no)
// get rid of >=64 code for constant shifts // get rid of >=64 code for constant shifts
(SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) && inBounds(d, c) -> (Const [-1]) (SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) && inBounds(d, c) -> (MOVQconst [-1])
(SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) && !inBounds(d, c) -> (Const [0]) (SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) && !inBounds(d, c) -> (MOVQconst [0])
(ANDQconst [0] _) -> (MOVQconst [0]) (ANDQconst [0] _) -> (MOVQconst [0])
(ANDQconst [-1] x) -> (Copy x) (ANDQconst [-1] x) -> (Copy x)
(CMOVQCC (CMPQconst [c] (MOVQconst [d])) _ x) && inBounds(d, c) -> (Copy x) (CMOVQCC (CMPQconst [c] (MOVQconst [d])) _ x) && inBounds(d, c) -> (Copy x)

View File

@ -138,7 +138,11 @@ func init() {
{name: "MOVLQSX", reg: gp11, asm: "MOVLQSX"}, // sign extend arg0 from int32 to int64 {name: "MOVLQSX", reg: gp11, asm: "MOVLQSX"}, // sign extend arg0 from int32 to int64
{name: "MOVLQZX", reg: gp11, asm: "MOVLQZX"}, // zero extend arg0 from int32 to int64 {name: "MOVLQZX", reg: gp11, asm: "MOVLQZX"}, // zero extend arg0 from int32 to int64
{name: "MOVQconst", reg: gp01}, // auxint {name: "MOVBconst", reg: gp01, asm: "MOVB"}, // 8 low bits of auxint
{name: "MOVWconst", reg: gp01, asm: "MOVW"}, // 16 low bits of auxint
{name: "MOVLconst", reg: gp01, asm: "MOVL"}, // 32 low bits of auxint
{name: "MOVQconst", reg: gp01, asm: "MOVQ"}, // auxint
{name: "LEAQ", reg: gp11sb}, // arg0 + auxint + offset encoded in aux {name: "LEAQ", reg: gp11sb}, // arg0 + auxint + offset encoded in aux
{name: "LEAQ1", reg: gp21sb}, // arg0 + arg1 + auxint {name: "LEAQ1", reg: gp21sb}, // arg0 + arg1 + auxint
{name: "LEAQ2", reg: gp21sb}, // arg0 + 2*arg1 + auxint {name: "LEAQ2", reg: gp21sb}, // arg0 + 2*arg1 + auxint

View File

@ -20,31 +20,31 @@
// For now, the generated successors must be a permutation of the matched successors. // For now, the generated successors must be a permutation of the matched successors.
// constant folding // constant folding
(Add64 (Const [c]) (Const [d])) -> (Const [c+d]) (Add64 (Const64 [c]) (Const64 [d])) -> (Const64 [c+d])
(AddPtr (Const [c]) (Const [d])) -> (Const [c+d]) (AddPtr (ConstPtr [c]) (ConstPtr [d])) -> (ConstPtr [c+d])
(Mul64 (Const [c]) (Const [d])) -> (Const [c*d]) (Mul64 (Const64 [c]) (Const64 [d])) -> (Const64 [c*d])
(MulPtr (Const [c]) (Const [d])) -> (Const [c*d]) (MulPtr (ConstPtr [c]) (ConstPtr [d])) -> (ConstPtr [c*d])
(IsInBounds (Const [c]) (Const [d])) -> (Const {inBounds(c,d)}) (IsInBounds (ConstPtr [c]) (ConstPtr [d])) -> (ConstPtr {inBounds(c,d)})
// tear apart slices // tear apart slices
// TODO: anything that generates a slice needs to go in here. // TODO: anything that generates a slice needs to go in here.
(SlicePtr (Load ptr mem)) -> (Load ptr mem) (SlicePtr (Load ptr mem)) -> (Load ptr mem)
(SliceLen (Load ptr mem)) -> (Load (AddPtr <ptr.Type> ptr (Const <config.Uintptr> [config.PtrSize])) mem) (SliceLen (Load ptr mem)) -> (Load (AddPtr <ptr.Type> ptr (ConstPtr <config.Uintptr> [config.PtrSize])) mem)
(SliceCap (Load ptr mem)) -> (Load (AddPtr <ptr.Type> ptr (Const <config.Uintptr> [config.PtrSize*2])) mem) (SliceCap (Load ptr mem)) -> (Load (AddPtr <ptr.Type> ptr (ConstPtr <config.Uintptr> [config.PtrSize*2])) mem)
// slice and interface comparisons // slice and interface comparisons
// the frontend ensures that we can only compare against nil // the frontend ensures that we can only compare against nil
// start by putting nil on the right to simplify the other rules // start by putting nil on the right to simplify the other rules
(EqFat x y) && x.Op == OpConst && y.Op != OpConst -> (EqFat y x) (EqFat x y) && x.Op == OpConstNil && y.Op != OpConstNil -> (EqFat y x)
(NeqFat x y) && x.Op == OpConst && y.Op != OpConst -> (NeqFat y x) (NeqFat x y) && x.Op == OpConstNil && y.Op != OpConstNil -> (NeqFat y x)
// it suffices to check the first word (backing array for slices, dynamic type for interfaces) // it suffices to check the first word (backing array for slices, dynamic type for interfaces)
(EqFat (Load ptr mem) y) && y.Op == OpConst -> (EqPtr (Load <config.Uintptr> ptr mem) (Const <config.Uintptr> [0])) (EqFat (Load ptr mem) (ConstNil)) -> (EqPtr (Load <config.Uintptr> ptr mem) (ConstPtr <config.Uintptr> [0]))
(NeqFat (Load ptr mem) y) && y.Op == OpConst -> (NeqPtr (Load <config.Uintptr> ptr mem) (Const <config.Uintptr> [0])) (NeqFat (Load ptr mem) (ConstNil)) -> (NeqPtr (Load <config.Uintptr> ptr mem) (ConstPtr <config.Uintptr> [0]))
// indexing operations // indexing operations
// Note: bounds check has already been done // Note: bounds check has already been done
(ArrayIndex (Load ptr mem) idx) -> (Load (PtrIndex <v.Type.PtrTo()> ptr idx) mem) (ArrayIndex (Load ptr mem) idx) -> (Load (PtrIndex <v.Type.PtrTo()> ptr idx) mem)
(PtrIndex <t> ptr idx) -> (AddPtr ptr (MulPtr <config.Uintptr> idx (Const <config.Uintptr> [t.Elem().Size()]))) (PtrIndex <t> ptr idx) -> (AddPtr ptr (MulPtr <config.Uintptr> idx (ConstPtr <config.Uintptr> [t.Elem().Size()])))
(StructSelect [idx] (Load ptr mem)) -> (Load (OffPtr <v.Type.PtrTo()> [idx] ptr) mem) (StructSelect [idx] (Load ptr mem)) -> (Load (OffPtr <v.Type.PtrTo()> [idx] ptr) mem)
// big-object moves // big-object moves
@ -52,12 +52,12 @@
(Store dst (Load <t> src mem) mem) && t.Size() > 8 -> (Move [t.Size()] dst src mem) (Store dst (Load <t> src mem) mem) && t.Size() > 8 -> (Move [t.Size()] dst src mem)
// string ops // string ops
(Const <t> {s}) && t.IsString() -> (StringMake (Addr <TypeBytePtr> {config.fe.StringData(s.(string))} (SB <config.Uintptr>)) (Const <config.Uintptr> [int64(len(s.(string)))])) (ConstString {s}) -> (StringMake (Addr <TypeBytePtr> {config.fe.StringData(s.(string))} (SB <config.Uintptr>)) (ConstPtr <config.Uintptr> [int64(len(s.(string)))]))
(Load <t> ptr mem) && t.IsString() -> (StringMake (Load <TypeBytePtr> ptr mem) (Load <config.Uintptr> (OffPtr <TypeBytePtr> [config.PtrSize] ptr) mem)) (Load <t> ptr mem) && t.IsString() -> (StringMake (Load <TypeBytePtr> ptr mem) (Load <config.Uintptr> (OffPtr <TypeBytePtr> [config.PtrSize] ptr) mem))
(StringPtr (StringMake ptr _)) -> ptr (StringPtr (StringMake ptr _)) -> ptr
(StringLen (StringMake _ len)) -> len (StringLen (StringMake _ len)) -> len
(Store dst str mem) && str.Type.IsString() -> (Store (OffPtr <TypeBytePtr> [config.PtrSize] dst) (StringLen <config.Uintptr> str) (Store <TypeMem> dst (StringPtr <TypeBytePtr> str) mem)) (Store dst str mem) && str.Type.IsString() -> (Store (OffPtr <TypeBytePtr> [config.PtrSize] dst) (StringLen <config.Uintptr> str) (Store <TypeMem> dst (StringPtr <TypeBytePtr> str) mem))
(If (Not cond) yes no) -> (If cond no yes) (If (Not cond) yes no) -> (If cond no yes)
(If (Const {c}) yes no) && c.(bool) -> (Plain nil yes) (If (ConstBool {c}) yes no) && c.(bool) -> (Plain nil yes)
(If (Const {c}) yes no) && !c.(bool) -> (Plain nil no) (If (ConstBool {c}) yes no) && !c.(bool) -> (Plain nil no)

View File

@ -115,7 +115,15 @@ var genericOps = []opData{
// in the AuxInt field as an int64 (including int, uint64, etc.). // in the AuxInt field as an int64 (including int, uint64, etc.).
// For integer types smaller than 64 bits, only the low-order // For integer types smaller than 64 bits, only the low-order
// bits of the AuxInt field matter. // bits of the AuxInt field matter.
{name: "Const"}, {name: "ConstBool"},
{name: "ConstString"},
{name: "ConstNil"},
{name: "Const8"},
{name: "Const16"},
{name: "Const32"},
{name: "Const64"},
{name: "ConstPtr"}, // pointer-sized integer constant
// TODO: Const32F, ...
// Constant-like things // Constant-like things
{name: "Arg"}, // memory input to the function. {name: "Arg"}, // memory input to the function.

View File

@ -81,6 +81,9 @@ func genRules(arch arch) {
continue continue
} }
op := strings.Split(rule, " ")[0][1:] op := strings.Split(rule, " ")[0][1:]
if op[len(op)-1] == ')' {
op = op[:len(op)-1] // rule has only opcode, e.g. (ConstNil) -> ...
}
if isBlock(op, arch) { if isBlock(op, arch) {
blockrules[op] = append(blockrules[op], rule) blockrules[op] = append(blockrules[op], rule)
} else { } else {

View File

@ -85,6 +85,9 @@ const (
OpAMD64MOVWQZX OpAMD64MOVWQZX
OpAMD64MOVLQSX OpAMD64MOVLQSX
OpAMD64MOVLQZX OpAMD64MOVLQZX
OpAMD64MOVBconst
OpAMD64MOVWconst
OpAMD64MOVLconst
OpAMD64MOVQconst OpAMD64MOVQconst
OpAMD64LEAQ OpAMD64LEAQ
OpAMD64LEAQ1 OpAMD64LEAQ1
@ -214,7 +217,14 @@ const (
OpNeg64 OpNeg64
OpPhi OpPhi
OpCopy OpCopy
OpConst OpConstBool
OpConstString
OpConstNil
OpConst8
OpConst16
OpConst32
OpConst64
OpConstPtr
OpArg OpArg
OpAddr OpAddr
OpSP OpSP
@ -685,8 +695,36 @@ var opcodeTable = [...]opInfo{
}, },
}, },
}, },
{
name: "MOVBconst",
asm: x86.AMOVB,
reg: regInfo{
outputs: []regMask{
65519, // .AX .CX .DX .BX .BP .SI .DI .R8 .R9 .R10 .R11 .R12 .R13 .R14 .R15
},
},
},
{
name: "MOVWconst",
asm: x86.AMOVW,
reg: regInfo{
outputs: []regMask{
65519, // .AX .CX .DX .BX .BP .SI .DI .R8 .R9 .R10 .R11 .R12 .R13 .R14 .R15
},
},
},
{
name: "MOVLconst",
asm: x86.AMOVL,
reg: regInfo{
outputs: []regMask{
65519, // .AX .CX .DX .BX .BP .SI .DI .R8 .R9 .R10 .R11 .R12 .R13 .R14 .R15
},
},
},
{ {
name: "MOVQconst", name: "MOVQconst",
asm: x86.AMOVQ,
reg: regInfo{ reg: regInfo{
outputs: []regMask{ outputs: []regMask{
65519, // .AX .CX .DX .BX .BP .SI .DI .R8 .R9 .R10 .R11 .R12 .R13 .R14 .R15 65519, // .AX .CX .DX .BX .BP .SI .DI .R8 .R9 .R10 .R11 .R12 .R13 .R14 .R15
@ -1546,7 +1584,35 @@ var opcodeTable = [...]opInfo{
generic: true, generic: true,
}, },
{ {
name: "Const", name: "ConstBool",
generic: true,
},
{
name: "ConstString",
generic: true,
},
{
name: "ConstNil",
generic: true,
},
{
name: "Const8",
generic: true,
},
{
name: "Const16",
generic: true,
},
{
name: "Const32",
generic: true,
},
{
name: "Const64",
generic: true,
},
{
name: "ConstPtr",
generic: true, generic: true,
}, },
{ {

View File

@ -492,16 +492,44 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
goto endfd75d26316012d86cb71d0dd1214259b goto endfd75d26316012d86cb71d0dd1214259b
endfd75d26316012d86cb71d0dd1214259b: endfd75d26316012d86cb71d0dd1214259b:
; ;
case OpConst: case OpConst16:
// match: (Const <t> [val]) // match: (Const16 [val])
// cond: t.IsInteger() // cond:
// result: (MOVWconst [val])
{
val := v.AuxInt
v.Op = OpAMD64MOVWconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = val
return true
}
goto end2c6c92f297873b8ac12bd035d56d001e
end2c6c92f297873b8ac12bd035d56d001e:
;
case OpConst32:
// match: (Const32 [val])
// cond:
// result: (MOVLconst [val])
{
val := v.AuxInt
v.Op = OpAMD64MOVLconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = val
return true
}
goto enddae5807662af67143a3ac3ad9c63bae5
enddae5807662af67143a3ac3ad9c63bae5:
;
case OpConst64:
// match: (Const64 [val])
// cond:
// result: (MOVQconst [val]) // result: (MOVQconst [val])
{ {
t := v.Type
val := v.AuxInt val := v.AuxInt
if !(t.IsInteger()) {
goto end4c8bfe9df26fc5aa2bd76b211792732a
}
v.Op = OpAMD64MOVQconst v.Op = OpAMD64MOVQconst
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
@ -509,62 +537,92 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.AuxInt = val v.AuxInt = val
return true return true
} }
goto end4c8bfe9df26fc5aa2bd76b211792732a goto endc630434ae7f143ab69d5f482a9b52b5f
end4c8bfe9df26fc5aa2bd76b211792732a: endc630434ae7f143ab69d5f482a9b52b5f:
; ;
// match: (Const <t>) case OpConst8:
// cond: t.IsPtr() // match: (Const8 [val])
// result: (MOVQconst [0]) // cond:
// result: (MOVBconst [val])
{ {
t := v.Type val := v.AuxInt
if !(t.IsPtr()) { v.Op = OpAMD64MOVBconst
goto endd23abe8d7061f11c260b162e24eec060 v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = val
return true
} }
v.Op = OpAMD64MOVQconst goto end200524c722ed14ca935ba47f8f30327d
end200524c722ed14ca935ba47f8f30327d:
;
case OpConstBool:
// match: (ConstBool {b})
// cond: !b.(bool)
// result: (MOVBconst [0])
{
b := v.Aux
if !(!b.(bool)) {
goto end876159ea073d2dcefcc251667c1a7780
}
v.Op = OpAMD64MOVBconst
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = 0 v.AuxInt = 0
return true return true
} }
goto endd23abe8d7061f11c260b162e24eec060 goto end876159ea073d2dcefcc251667c1a7780
endd23abe8d7061f11c260b162e24eec060: end876159ea073d2dcefcc251667c1a7780:
; ;
// match: (Const <t>) // match: (ConstBool {b})
// cond: t.IsBoolean() && !v.Aux.(bool) // cond: b.(bool)
// result: (MOVQconst [0]) // result: (MOVBconst [1])
{ {
t := v.Type b := v.Aux
if !(t.IsBoolean() && !v.Aux.(bool)) { if !(b.(bool)) {
goto end7b1347fd0902b990ee1e49145c7e8c31 goto end0dacad3f7cad53905aad5303391447f6
} }
v.Op = OpAMD64MOVQconst v.Op = OpAMD64MOVBconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto end7b1347fd0902b990ee1e49145c7e8c31
end7b1347fd0902b990ee1e49145c7e8c31:
;
// match: (Const <t>)
// cond: t.IsBoolean() && v.Aux.(bool)
// result: (MOVQconst [1])
{
t := v.Type
if !(t.IsBoolean() && v.Aux.(bool)) {
goto ende0d1c954b5ab5af7227bff9635774f1c
}
v.Op = OpAMD64MOVQconst
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = 1 v.AuxInt = 1
return true return true
} }
goto ende0d1c954b5ab5af7227bff9635774f1c goto end0dacad3f7cad53905aad5303391447f6
ende0d1c954b5ab5af7227bff9635774f1c: end0dacad3f7cad53905aad5303391447f6:
;
case OpConstNil:
// match: (ConstNil)
// cond:
// result: (MOVQconst [0])
{
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = 0
return true
}
goto endea557d921056c25b945a49649e4b9b91
endea557d921056c25b945a49649e4b9b91:
;
case OpConstPtr:
// match: (ConstPtr [val])
// cond:
// result: (MOVQconst [val])
{
val := v.AuxInt
v.Op = OpAMD64MOVQconst
v.AuxInt = 0
v.Aux = nil
v.resetArgs()
v.AuxInt = val
return true
}
goto endc395c0a53eeccf597e225a07b53047d1
endc395c0a53eeccf597e225a07b53047d1:
; ;
case OpConvNop: case OpConvNop:
// match: (ConvNop <t> x) // match: (ConvNop <t> x)
@ -1527,7 +1585,7 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
case OpMove: case OpMove:
// match: (Move [size] dst src mem) // match: (Move [size] dst src mem)
// cond: // cond:
// result: (REPMOVSB dst src (Const <TypeUInt64> [size]) mem) // result: (REPMOVSB dst src (MOVQconst <TypeUInt64> [size]) mem)
{ {
size := v.AuxInt size := v.AuxInt
dst := v.Args[0] dst := v.Args[0]
@ -1539,15 +1597,15 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.resetArgs() v.resetArgs()
v.AddArg(dst) v.AddArg(dst)
v.AddArg(src) v.AddArg(src)
v0 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAMD64MOVQconst, TypeInvalid)
v0.Type = TypeUInt64 v0.Type = TypeUInt64
v0.AuxInt = size v0.AuxInt = size
v.AddArg(v0) v.AddArg(v0)
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto end1b2d226705fd31dbbe74e3286af178ea goto end2aab774aedae2c616ee88bfa87cdf30e
end1b2d226705fd31dbbe74e3286af178ea: end2aab774aedae2c616ee88bfa87cdf30e:
; ;
case OpMul16: case OpMul16:
// match: (Mul16 x y) // match: (Mul16 x y)
@ -1846,13 +1904,13 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
case OpRsh64: case OpRsh64:
// match: (Rsh64 <t> x y) // match: (Rsh64 <t> x y)
// cond: y.Type.Size() == 8 // cond: y.Type.Size() == 8
// result: (SARQ <t> x (CMOVQCC <t> (CMPQconst <TypeFlags> [64] y) (Const <t> [63]) y)) // result: (SARQ <t> x (CMOVQCC <t> (CMPQconst <TypeFlags> [64] y) (MOVQconst <t> [63]) y))
{ {
t := v.Type t := v.Type
x := v.Args[0] x := v.Args[0]
y := v.Args[1] y := v.Args[1]
if !(y.Type.Size() == 8) { if !(y.Type.Size() == 8) {
goto end16bda9bd1611d415969fdbec55ed4330 goto endd5f88a8c4f11e0e844b35fd8677bd940
} }
v.Op = OpAMD64SARQ v.Op = OpAMD64SARQ
v.AuxInt = 0 v.AuxInt = 0
@ -1867,7 +1925,7 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v1.AuxInt = 64 v1.AuxInt = 64
v1.AddArg(y) v1.AddArg(y)
v0.AddArg(v1) v0.AddArg(v1)
v2 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v2 := v.Block.NewValue0(v.Line, OpAMD64MOVQconst, TypeInvalid)
v2.Type = t v2.Type = t
v2.AuxInt = 63 v2.AuxInt = 63
v0.AddArg(v2) v0.AddArg(v2)
@ -1875,8 +1933,8 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.AddArg(v0) v.AddArg(v0)
return true return true
} }
goto end16bda9bd1611d415969fdbec55ed4330 goto endd5f88a8c4f11e0e844b35fd8677bd940
end16bda9bd1611d415969fdbec55ed4330: endd5f88a8c4f11e0e844b35fd8677bd940:
; ;
case OpRsh64U: case OpRsh64U:
// match: (Rsh64U <t> x y) // match: (Rsh64U <t> x y)
@ -1935,53 +1993,53 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
case OpAMD64SBBQcarrymask: case OpAMD64SBBQcarrymask:
// match: (SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) // match: (SBBQcarrymask (CMPQconst [c] (MOVQconst [d])))
// cond: inBounds(d, c) // cond: inBounds(d, c)
// result: (Const [-1]) // result: (MOVQconst [-1])
{ {
if v.Args[0].Op != OpAMD64CMPQconst { if v.Args[0].Op != OpAMD64CMPQconst {
goto endf67d323ecef000dbcd15d7e031c3475e goto end378de7e659770f877c08b6b269073069
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[0].Args[0].Op != OpAMD64MOVQconst { if v.Args[0].Args[0].Op != OpAMD64MOVQconst {
goto endf67d323ecef000dbcd15d7e031c3475e goto end378de7e659770f877c08b6b269073069
} }
d := v.Args[0].Args[0].AuxInt d := v.Args[0].Args[0].AuxInt
if !(inBounds(d, c)) { if !(inBounds(d, c)) {
goto endf67d323ecef000dbcd15d7e031c3475e goto end378de7e659770f877c08b6b269073069
} }
v.Op = OpConst v.Op = OpAMD64MOVQconst
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = -1 v.AuxInt = -1
return true return true
} }
goto endf67d323ecef000dbcd15d7e031c3475e goto end378de7e659770f877c08b6b269073069
endf67d323ecef000dbcd15d7e031c3475e: end378de7e659770f877c08b6b269073069:
; ;
// match: (SBBQcarrymask (CMPQconst [c] (MOVQconst [d]))) // match: (SBBQcarrymask (CMPQconst [c] (MOVQconst [d])))
// cond: !inBounds(d, c) // cond: !inBounds(d, c)
// result: (Const [0]) // result: (MOVQconst [0])
{ {
if v.Args[0].Op != OpAMD64CMPQconst { if v.Args[0].Op != OpAMD64CMPQconst {
goto end4157ddea9c4f71bfabfd6fa50e1208ed goto enda7bfd1974bf83ca79653c560a718a86c
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[0].Args[0].Op != OpAMD64MOVQconst { if v.Args[0].Args[0].Op != OpAMD64MOVQconst {
goto end4157ddea9c4f71bfabfd6fa50e1208ed goto enda7bfd1974bf83ca79653c560a718a86c
} }
d := v.Args[0].Args[0].AuxInt d := v.Args[0].Args[0].AuxInt
if !(!inBounds(d, c)) { if !(!inBounds(d, c)) {
goto end4157ddea9c4f71bfabfd6fa50e1208ed goto enda7bfd1974bf83ca79653c560a718a86c
} }
v.Op = OpConst v.Op = OpAMD64MOVQconst
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = 0 v.AuxInt = 0
return true return true
} }
goto end4157ddea9c4f71bfabfd6fa50e1208ed goto enda7bfd1974bf83ca79653c560a718a86c
end4157ddea9c4f71bfabfd6fa50e1208ed: enda7bfd1974bf83ca79653c560a718a86c:
; ;
case OpAMD64SETA: case OpAMD64SETA:
// match: (SETA (InvertFlags x)) // match: (SETA (InvertFlags x))
@ -2676,10 +2734,10 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
; ;
// match: (Zero [1] destptr mem) // match: (Zero [1] destptr mem)
// cond: // cond:
// result: (MOVBstore destptr (Const <TypeInt8> [0]) mem) // result: (MOVBstore destptr (MOVBconst <TypeInt8> [0]) mem)
{ {
if v.AuxInt != 1 { if v.AuxInt != 1 {
goto end09ec7b1fc5ad40534e0e25c896323f5c goto end16839f51d2e9cf9548f216848406bd97
} }
destptr := v.Args[0] destptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
@ -2688,22 +2746,22 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(destptr) v.AddArg(destptr)
v0 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAMD64MOVBconst, TypeInvalid)
v0.Type = TypeInt8 v0.Type = TypeInt8
v0.AuxInt = 0 v0.AuxInt = 0
v.AddArg(v0) v.AddArg(v0)
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto end09ec7b1fc5ad40534e0e25c896323f5c goto end16839f51d2e9cf9548f216848406bd97
end09ec7b1fc5ad40534e0e25c896323f5c: end16839f51d2e9cf9548f216848406bd97:
; ;
// match: (Zero [2] destptr mem) // match: (Zero [2] destptr mem)
// cond: // cond:
// result: (MOVWstore destptr (Const <TypeInt16> [0]) mem) // result: (MOVWstore destptr (MOVWconst <TypeInt16> [0]) mem)
{ {
if v.AuxInt != 2 { if v.AuxInt != 2 {
goto end2dee246789dbd305bb1eaec768bdae14 goto enddc4a090329efde9ca19983ad18174cbb
} }
destptr := v.Args[0] destptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
@ -2712,22 +2770,22 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(destptr) v.AddArg(destptr)
v0 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAMD64MOVWconst, TypeInvalid)
v0.Type = TypeInt16 v0.Type = TypeInt16
v0.AuxInt = 0 v0.AuxInt = 0
v.AddArg(v0) v.AddArg(v0)
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto end2dee246789dbd305bb1eaec768bdae14 goto enddc4a090329efde9ca19983ad18174cbb
end2dee246789dbd305bb1eaec768bdae14: enddc4a090329efde9ca19983ad18174cbb:
; ;
// match: (Zero [4] destptr mem) // match: (Zero [4] destptr mem)
// cond: // cond:
// result: (MOVLstore destptr (Const <TypeInt32> [0]) mem) // result: (MOVLstore destptr (MOVLconst <TypeInt32> [0]) mem)
{ {
if v.AuxInt != 4 { if v.AuxInt != 4 {
goto ende2bf4ecf21bc9e76700a9c5f62546e78 goto end365a027b67399ad8d5d2d5eca847f7d8
} }
destptr := v.Args[0] destptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
@ -2736,22 +2794,22 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(destptr) v.AddArg(destptr)
v0 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAMD64MOVLconst, TypeInvalid)
v0.Type = TypeInt32 v0.Type = TypeInt32
v0.AuxInt = 0 v0.AuxInt = 0
v.AddArg(v0) v.AddArg(v0)
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto ende2bf4ecf21bc9e76700a9c5f62546e78 goto end365a027b67399ad8d5d2d5eca847f7d8
ende2bf4ecf21bc9e76700a9c5f62546e78: end365a027b67399ad8d5d2d5eca847f7d8:
; ;
// match: (Zero [8] destptr mem) // match: (Zero [8] destptr mem)
// cond: // cond:
// result: (MOVQstore destptr (Const <TypeInt64> [0]) mem) // result: (MOVQstore destptr (MOVQconst <TypeInt64> [0]) mem)
{ {
if v.AuxInt != 8 { if v.AuxInt != 8 {
goto enda65d5d60783daf9b9405f04c44f7adaf goto end5808a5e9c68555a82c3514db39017e56
} }
destptr := v.Args[0] destptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
@ -2760,15 +2818,15 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AddArg(destptr) v.AddArg(destptr)
v0 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAMD64MOVQconst, TypeInvalid)
v0.Type = TypeInt64 v0.Type = TypeInt64
v0.AuxInt = 0 v0.AuxInt = 0
v.AddArg(v0) v.AddArg(v0)
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto enda65d5d60783daf9b9405f04c44f7adaf goto end5808a5e9c68555a82c3514db39017e56
enda65d5d60783daf9b9405f04c44f7adaf: end5808a5e9c68555a82c3514db39017e56:
; ;
// match: (Zero [size] destptr mem) // match: (Zero [size] destptr mem)
// cond: size < 4*8 // cond: size < 4*8
@ -2794,13 +2852,13 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
; ;
// match: (Zero [size] destptr mem) // match: (Zero [size] destptr mem)
// cond: size >= 4*8 // cond: size >= 4*8
// result: (Zero [size%8] (OffPtr <TypeUInt64> [size-(size%8)] destptr) (REPSTOSQ <TypeMem> destptr (Const <TypeUInt64> [size/8]) mem)) // result: (Zero [size%8] (OffPtr <TypeUInt64> [size-(size%8)] destptr) (REPSTOSQ <TypeMem> destptr (MOVQconst <TypeUInt64> [size/8]) mem))
{ {
size := v.AuxInt size := v.AuxInt
destptr := v.Args[0] destptr := v.Args[0]
mem := v.Args[1] mem := v.Args[1]
if !(size >= 4*8) { if !(size >= 4*8) {
goto end7a358169d20d6834b21f2e03fbf351b2 goto endb3058a90f909821d5689fb358519828b
} }
v.Op = OpZero v.Op = OpZero
v.AuxInt = 0 v.AuxInt = 0
@ -2815,7 +2873,7 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v1 := v.Block.NewValue0(v.Line, OpAMD64REPSTOSQ, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpAMD64REPSTOSQ, TypeInvalid)
v1.Type = TypeMem v1.Type = TypeMem
v1.AddArg(destptr) v1.AddArg(destptr)
v2 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v2 := v.Block.NewValue0(v.Line, OpAMD64MOVQconst, TypeInvalid)
v2.Type = TypeUInt64 v2.Type = TypeUInt64
v2.AuxInt = size / 8 v2.AuxInt = size / 8
v1.AddArg(v2) v1.AddArg(v2)
@ -2823,8 +2881,8 @@ func rewriteValueAMD64(v *Value, config *Config) bool {
v.AddArg(v1) v.AddArg(v1)
return true return true
} }
goto end7a358169d20d6834b21f2e03fbf351b2 goto endb3058a90f909821d5689fb358519828b
end7a358169d20d6834b21f2e03fbf351b2: endb3058a90f909821d5689fb358519828b:
; ;
case OpZeroExt16to32: case OpZeroExt16to32:
// match: (ZeroExt16to32 x) // match: (ZeroExt16to32 x)

View File

@ -5,50 +5,50 @@ package ssa
func rewriteValuegeneric(v *Value, config *Config) bool { func rewriteValuegeneric(v *Value, config *Config) bool {
switch v.Op { switch v.Op {
case OpAdd64: case OpAdd64:
// match: (Add64 (Const [c]) (Const [d])) // match: (Add64 (Const64 [c]) (Const64 [d]))
// cond: // cond:
// result: (Const [c+d]) // result: (Const64 [c+d])
{ {
if v.Args[0].Op != OpConst { if v.Args[0].Op != OpConst64 {
goto endd2f4bfaaf6c937171a287b73e5c2f73e goto end8c46df6f85a11cb1d594076b0e467908
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[1].Op != OpConst { if v.Args[1].Op != OpConst64 {
goto endd2f4bfaaf6c937171a287b73e5c2f73e goto end8c46df6f85a11cb1d594076b0e467908
} }
d := v.Args[1].AuxInt d := v.Args[1].AuxInt
v.Op = OpConst v.Op = OpConst64
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = c + d v.AuxInt = c + d
return true return true
} }
goto endd2f4bfaaf6c937171a287b73e5c2f73e goto end8c46df6f85a11cb1d594076b0e467908
endd2f4bfaaf6c937171a287b73e5c2f73e: end8c46df6f85a11cb1d594076b0e467908:
; ;
case OpAddPtr: case OpAddPtr:
// match: (AddPtr (Const [c]) (Const [d])) // match: (AddPtr (ConstPtr [c]) (ConstPtr [d]))
// cond: // cond:
// result: (Const [c+d]) // result: (ConstPtr [c+d])
{ {
if v.Args[0].Op != OpConst { if v.Args[0].Op != OpConstPtr {
goto end67284cb7ae441d6c763096b49a3569a3 goto end145c1aec793b2befff34bc8983b48a38
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[1].Op != OpConst { if v.Args[1].Op != OpConstPtr {
goto end67284cb7ae441d6c763096b49a3569a3 goto end145c1aec793b2befff34bc8983b48a38
} }
d := v.Args[1].AuxInt d := v.Args[1].AuxInt
v.Op = OpConst v.Op = OpConstPtr
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = c + d v.AuxInt = c + d
return true return true
} }
goto end67284cb7ae441d6c763096b49a3569a3 goto end145c1aec793b2befff34bc8983b48a38
end67284cb7ae441d6c763096b49a3569a3: end145c1aec793b2befff34bc8983b48a38:
; ;
case OpArrayIndex: case OpArrayIndex:
// match: (ArrayIndex (Load ptr mem) idx) // match: (ArrayIndex (Load ptr mem) idx)
@ -76,16 +76,12 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
goto end4894dd7b58383fee5f8a92be08437c33 goto end4894dd7b58383fee5f8a92be08437c33
end4894dd7b58383fee5f8a92be08437c33: end4894dd7b58383fee5f8a92be08437c33:
; ;
case OpConst: case OpConstString:
// match: (Const <t> {s}) // match: (ConstString {s})
// cond: t.IsString() // cond:
// result: (StringMake (Addr <TypeBytePtr> {config.fe.StringData(s.(string))} (SB <config.Uintptr>)) (Const <config.Uintptr> [int64(len(s.(string)))])) // result: (StringMake (Addr <TypeBytePtr> {config.fe.StringData(s.(string))} (SB <config.Uintptr>)) (ConstPtr <config.Uintptr> [int64(len(s.(string)))]))
{ {
t := v.Type
s := v.Aux s := v.Aux
if !(t.IsString()) {
goto enda6f250a3c775ae5a239ece8074b46cea
}
v.Op = OpStringMake v.Op = OpStringMake
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
@ -97,24 +93,24 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v1.Type = config.Uintptr v1.Type = config.Uintptr
v0.AddArg(v1) v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
v2 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v2 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v2.Type = config.Uintptr v2.Type = config.Uintptr
v2.AuxInt = int64(len(s.(string))) v2.AuxInt = int64(len(s.(string)))
v.AddArg(v2) v.AddArg(v2)
return true return true
} }
goto enda6f250a3c775ae5a239ece8074b46cea goto end1a01fc02fad8727f9a3b716cfdac3a44
enda6f250a3c775ae5a239ece8074b46cea: end1a01fc02fad8727f9a3b716cfdac3a44:
; ;
case OpEqFat: case OpEqFat:
// match: (EqFat x y) // match: (EqFat x y)
// cond: x.Op == OpConst && y.Op != OpConst // cond: x.Op == OpConstNil && y.Op != OpConstNil
// result: (EqFat y x) // result: (EqFat y x)
{ {
x := v.Args[0] x := v.Args[0]
y := v.Args[1] y := v.Args[1]
if !(x.Op == OpConst && y.Op != OpConst) { if !(x.Op == OpConstNil && y.Op != OpConstNil) {
goto end4540bddcf0fc8e4b71fac6e9edbb8eec goto endcea7f7399afcff860c54d82230a9a934
} }
v.Op = OpEqFat v.Op = OpEqFat
v.AuxInt = 0 v.AuxInt = 0
@ -124,21 +120,20 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AddArg(x) v.AddArg(x)
return true return true
} }
goto end4540bddcf0fc8e4b71fac6e9edbb8eec goto endcea7f7399afcff860c54d82230a9a934
end4540bddcf0fc8e4b71fac6e9edbb8eec: endcea7f7399afcff860c54d82230a9a934:
; ;
// match: (EqFat (Load ptr mem) y) // match: (EqFat (Load ptr mem) (ConstNil))
// cond: y.Op == OpConst // cond:
// result: (EqPtr (Load <config.Uintptr> ptr mem) (Const <config.Uintptr> [0])) // result: (EqPtr (Load <config.Uintptr> ptr mem) (ConstPtr <config.Uintptr> [0]))
{ {
if v.Args[0].Op != OpLoad { if v.Args[0].Op != OpLoad {
goto end779b0e24e33d8eff668c368b90387caa goto end2597220d1792c84d362da7901d2065d2
} }
ptr := v.Args[0].Args[0] ptr := v.Args[0].Args[0]
mem := v.Args[0].Args[1] mem := v.Args[0].Args[1]
y := v.Args[1] if v.Args[1].Op != OpConstNil {
if !(y.Op == OpConst) { goto end2597220d1792c84d362da7901d2065d2
goto end779b0e24e33d8eff668c368b90387caa
} }
v.Op = OpEqPtr v.Op = OpEqPtr
v.AuxInt = 0 v.AuxInt = 0
@ -149,37 +144,37 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(mem) v0.AddArg(mem)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Uintptr v1.Type = config.Uintptr
v1.AuxInt = 0 v1.AuxInt = 0
v.AddArg(v1) v.AddArg(v1)
return true return true
} }
goto end779b0e24e33d8eff668c368b90387caa goto end2597220d1792c84d362da7901d2065d2
end779b0e24e33d8eff668c368b90387caa: end2597220d1792c84d362da7901d2065d2:
; ;
case OpIsInBounds: case OpIsInBounds:
// match: (IsInBounds (Const [c]) (Const [d])) // match: (IsInBounds (ConstPtr [c]) (ConstPtr [d]))
// cond: // cond:
// result: (Const {inBounds(c,d)}) // result: (ConstPtr {inBounds(c,d)})
{ {
if v.Args[0].Op != OpConst { if v.Args[0].Op != OpConstPtr {
goto enda96ccac78df2d17ae96c8baf2af2e189 goto enddfd340bc7103ca323354aec96b113c23
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[1].Op != OpConst { if v.Args[1].Op != OpConstPtr {
goto enda96ccac78df2d17ae96c8baf2af2e189 goto enddfd340bc7103ca323354aec96b113c23
} }
d := v.Args[1].AuxInt d := v.Args[1].AuxInt
v.Op = OpConst v.Op = OpConstPtr
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.Aux = inBounds(c, d) v.Aux = inBounds(c, d)
return true return true
} }
goto enda96ccac78df2d17ae96c8baf2af2e189 goto enddfd340bc7103ca323354aec96b113c23
enda96ccac78df2d17ae96c8baf2af2e189: enddfd340bc7103ca323354aec96b113c23:
; ;
case OpLoad: case OpLoad:
// match: (Load <t> ptr mem) // match: (Load <t> ptr mem)
@ -216,60 +211,60 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
endce3ba169a57b8a9f6b12751d49b4e23a: endce3ba169a57b8a9f6b12751d49b4e23a:
; ;
case OpMul64: case OpMul64:
// match: (Mul64 (Const [c]) (Const [d])) // match: (Mul64 (Const64 [c]) (Const64 [d]))
// cond: // cond:
// result: (Const [c*d]) // result: (Const64 [c*d])
{ {
if v.Args[0].Op != OpConst { if v.Args[0].Op != OpConst64 {
goto endf4ba5346dc8a624781afaa68a8096a9a goto end7aea1048b5d1230974b97f17238380ae
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[1].Op != OpConst { if v.Args[1].Op != OpConst64 {
goto endf4ba5346dc8a624781afaa68a8096a9a goto end7aea1048b5d1230974b97f17238380ae
} }
d := v.Args[1].AuxInt d := v.Args[1].AuxInt
v.Op = OpConst v.Op = OpConst64
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = c * d v.AuxInt = c * d
return true return true
} }
goto endf4ba5346dc8a624781afaa68a8096a9a goto end7aea1048b5d1230974b97f17238380ae
endf4ba5346dc8a624781afaa68a8096a9a: end7aea1048b5d1230974b97f17238380ae:
; ;
case OpMulPtr: case OpMulPtr:
// match: (MulPtr (Const [c]) (Const [d])) // match: (MulPtr (ConstPtr [c]) (ConstPtr [d]))
// cond: // cond:
// result: (Const [c*d]) // result: (ConstPtr [c*d])
{ {
if v.Args[0].Op != OpConst { if v.Args[0].Op != OpConstPtr {
goto end10541de7ea2bce703c1e372ac9a271e7 goto end808c190f346658bb1ad032bf37a1059f
} }
c := v.Args[0].AuxInt c := v.Args[0].AuxInt
if v.Args[1].Op != OpConst { if v.Args[1].Op != OpConstPtr {
goto end10541de7ea2bce703c1e372ac9a271e7 goto end808c190f346658bb1ad032bf37a1059f
} }
d := v.Args[1].AuxInt d := v.Args[1].AuxInt
v.Op = OpConst v.Op = OpConstPtr
v.AuxInt = 0 v.AuxInt = 0
v.Aux = nil v.Aux = nil
v.resetArgs() v.resetArgs()
v.AuxInt = c * d v.AuxInt = c * d
return true return true
} }
goto end10541de7ea2bce703c1e372ac9a271e7 goto end808c190f346658bb1ad032bf37a1059f
end10541de7ea2bce703c1e372ac9a271e7: end808c190f346658bb1ad032bf37a1059f:
; ;
case OpNeqFat: case OpNeqFat:
// match: (NeqFat x y) // match: (NeqFat x y)
// cond: x.Op == OpConst && y.Op != OpConst // cond: x.Op == OpConstNil && y.Op != OpConstNil
// result: (NeqFat y x) // result: (NeqFat y x)
{ {
x := v.Args[0] x := v.Args[0]
y := v.Args[1] y := v.Args[1]
if !(x.Op == OpConst && y.Op != OpConst) { if !(x.Op == OpConstNil && y.Op != OpConstNil) {
goto end5d2a9d3aa52fb6866825f35ac65c7cfd goto end94c68f7dc30c66ed42e507e01c4e5dc7
} }
v.Op = OpNeqFat v.Op = OpNeqFat
v.AuxInt = 0 v.AuxInt = 0
@ -279,21 +274,20 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AddArg(x) v.AddArg(x)
return true return true
} }
goto end5d2a9d3aa52fb6866825f35ac65c7cfd goto end94c68f7dc30c66ed42e507e01c4e5dc7
end5d2a9d3aa52fb6866825f35ac65c7cfd: end94c68f7dc30c66ed42e507e01c4e5dc7:
; ;
// match: (NeqFat (Load ptr mem) y) // match: (NeqFat (Load ptr mem) (ConstNil))
// cond: y.Op == OpConst // cond:
// result: (NeqPtr (Load <config.Uintptr> ptr mem) (Const <config.Uintptr> [0])) // result: (NeqPtr (Load <config.Uintptr> ptr mem) (ConstPtr <config.Uintptr> [0]))
{ {
if v.Args[0].Op != OpLoad { if v.Args[0].Op != OpLoad {
goto endf2f18052c2d999a7ac883c441c3b7ade goto end03a0fc8dde062c55439174f70c19e6ce
} }
ptr := v.Args[0].Args[0] ptr := v.Args[0].Args[0]
mem := v.Args[0].Args[1] mem := v.Args[0].Args[1]
y := v.Args[1] if v.Args[1].Op != OpConstNil {
if !(y.Op == OpConst) { goto end03a0fc8dde062c55439174f70c19e6ce
goto endf2f18052c2d999a7ac883c441c3b7ade
} }
v.Op = OpNeqPtr v.Op = OpNeqPtr
v.AuxInt = 0 v.AuxInt = 0
@ -304,19 +298,19 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v0.AddArg(ptr) v0.AddArg(ptr)
v0.AddArg(mem) v0.AddArg(mem)
v.AddArg(v0) v.AddArg(v0)
v1 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Uintptr v1.Type = config.Uintptr
v1.AuxInt = 0 v1.AuxInt = 0
v.AddArg(v1) v.AddArg(v1)
return true return true
} }
goto endf2f18052c2d999a7ac883c441c3b7ade goto end03a0fc8dde062c55439174f70c19e6ce
endf2f18052c2d999a7ac883c441c3b7ade: end03a0fc8dde062c55439174f70c19e6ce:
; ;
case OpPtrIndex: case OpPtrIndex:
// match: (PtrIndex <t> ptr idx) // match: (PtrIndex <t> ptr idx)
// cond: // cond:
// result: (AddPtr ptr (MulPtr <config.Uintptr> idx (Const <config.Uintptr> [t.Elem().Size()]))) // result: (AddPtr ptr (MulPtr <config.Uintptr> idx (ConstPtr <config.Uintptr> [t.Elem().Size()])))
{ {
t := v.Type t := v.Type
ptr := v.Args[0] ptr := v.Args[0]
@ -329,23 +323,23 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v0 := v.Block.NewValue0(v.Line, OpMulPtr, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpMulPtr, TypeInvalid)
v0.Type = config.Uintptr v0.Type = config.Uintptr
v0.AddArg(idx) v0.AddArg(idx)
v1 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Uintptr v1.Type = config.Uintptr
v1.AuxInt = t.Elem().Size() v1.AuxInt = t.Elem().Size()
v0.AddArg(v1) v0.AddArg(v1)
v.AddArg(v0) v.AddArg(v0)
return true return true
} }
goto endb39bbe157d1791123f6083b2cfc59ddc goto endfb3e605edaa4c3c0684c4fa9c8f150ee
endb39bbe157d1791123f6083b2cfc59ddc: endfb3e605edaa4c3c0684c4fa9c8f150ee:
; ;
case OpSliceCap: case OpSliceCap:
// match: (SliceCap (Load ptr mem)) // match: (SliceCap (Load ptr mem))
// cond: // cond:
// result: (Load (AddPtr <ptr.Type> ptr (Const <config.Uintptr> [config.PtrSize*2])) mem) // result: (Load (AddPtr <ptr.Type> ptr (ConstPtr <config.Uintptr> [config.PtrSize*2])) mem)
{ {
if v.Args[0].Op != OpLoad { if v.Args[0].Op != OpLoad {
goto end83c0ff7760465a4184bad9e4b47f7be8 goto end18c7acae3d96b30b9e5699194df4a687
} }
ptr := v.Args[0].Args[0] ptr := v.Args[0].Args[0]
mem := v.Args[0].Args[1] mem := v.Args[0].Args[1]
@ -356,7 +350,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid)
v0.Type = ptr.Type v0.Type = ptr.Type
v0.AddArg(ptr) v0.AddArg(ptr)
v1 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Uintptr v1.Type = config.Uintptr
v1.AuxInt = config.PtrSize * 2 v1.AuxInt = config.PtrSize * 2
v0.AddArg(v1) v0.AddArg(v1)
@ -364,16 +358,16 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto end83c0ff7760465a4184bad9e4b47f7be8 goto end18c7acae3d96b30b9e5699194df4a687
end83c0ff7760465a4184bad9e4b47f7be8: end18c7acae3d96b30b9e5699194df4a687:
; ;
case OpSliceLen: case OpSliceLen:
// match: (SliceLen (Load ptr mem)) // match: (SliceLen (Load ptr mem))
// cond: // cond:
// result: (Load (AddPtr <ptr.Type> ptr (Const <config.Uintptr> [config.PtrSize])) mem) // result: (Load (AddPtr <ptr.Type> ptr (ConstPtr <config.Uintptr> [config.PtrSize])) mem)
{ {
if v.Args[0].Op != OpLoad { if v.Args[0].Op != OpLoad {
goto end20579b262d017d875d579683996f0ef9 goto end2dc65aee31bb0d91847032be777777d2
} }
ptr := v.Args[0].Args[0] ptr := v.Args[0].Args[0]
mem := v.Args[0].Args[1] mem := v.Args[0].Args[1]
@ -384,7 +378,7 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid) v0 := v.Block.NewValue0(v.Line, OpAddPtr, TypeInvalid)
v0.Type = ptr.Type v0.Type = ptr.Type
v0.AddArg(ptr) v0.AddArg(ptr)
v1 := v.Block.NewValue0(v.Line, OpConst, TypeInvalid) v1 := v.Block.NewValue0(v.Line, OpConstPtr, TypeInvalid)
v1.Type = config.Uintptr v1.Type = config.Uintptr
v1.AuxInt = config.PtrSize v1.AuxInt = config.PtrSize
v0.AddArg(v1) v0.AddArg(v1)
@ -392,8 +386,8 @@ func rewriteValuegeneric(v *Value, config *Config) bool {
v.AddArg(mem) v.AddArg(mem)
return true return true
} }
goto end20579b262d017d875d579683996f0ef9 goto end2dc65aee31bb0d91847032be777777d2
end20579b262d017d875d579683996f0ef9: end2dc65aee31bb0d91847032be777777d2:
; ;
case OpSlicePtr: case OpSlicePtr:
// match: (SlicePtr (Load ptr mem)) // match: (SlicePtr (Load ptr mem))
@ -573,19 +567,19 @@ func rewriteBlockgeneric(b *Block) bool {
goto endebe19c1c3c3bec068cdb2dd29ef57f96 goto endebe19c1c3c3bec068cdb2dd29ef57f96
endebe19c1c3c3bec068cdb2dd29ef57f96: endebe19c1c3c3bec068cdb2dd29ef57f96:
; ;
// match: (If (Const {c}) yes no) // match: (If (ConstBool {c}) yes no)
// cond: c.(bool) // cond: c.(bool)
// result: (Plain nil yes) // result: (Plain nil yes)
{ {
v := b.Control v := b.Control
if v.Op != OpConst { if v.Op != OpConstBool {
goto end915e334b6388fed7d63e09aa69ecb05c goto end9ff0273f9b1657f4afc287562ca889f0
} }
c := v.Aux c := v.Aux
yes := b.Succs[0] yes := b.Succs[0]
no := b.Succs[1] no := b.Succs[1]
if !(c.(bool)) { if !(c.(bool)) {
goto end915e334b6388fed7d63e09aa69ecb05c goto end9ff0273f9b1657f4afc287562ca889f0
} }
v.Block.Func.removePredecessor(b, no) v.Block.Func.removePredecessor(b, no)
b.Kind = BlockPlain b.Kind = BlockPlain
@ -594,22 +588,22 @@ func rewriteBlockgeneric(b *Block) bool {
b.Succs[0] = yes b.Succs[0] = yes
return true return true
} }
goto end915e334b6388fed7d63e09aa69ecb05c goto end9ff0273f9b1657f4afc287562ca889f0
end915e334b6388fed7d63e09aa69ecb05c: end9ff0273f9b1657f4afc287562ca889f0:
; ;
// match: (If (Const {c}) yes no) // match: (If (ConstBool {c}) yes no)
// cond: !c.(bool) // cond: !c.(bool)
// result: (Plain nil no) // result: (Plain nil no)
{ {
v := b.Control v := b.Control
if v.Op != OpConst { if v.Op != OpConstBool {
goto end6452ee3a5bb02c708bddc3181c3ea3cb goto endf401a4553c3c7c6bed64801da7bba076
} }
c := v.Aux c := v.Aux
yes := b.Succs[0] yes := b.Succs[0]
no := b.Succs[1] no := b.Succs[1]
if !(!c.(bool)) { if !(!c.(bool)) {
goto end6452ee3a5bb02c708bddc3181c3ea3cb goto endf401a4553c3c7c6bed64801da7bba076
} }
v.Block.Func.removePredecessor(b, yes) v.Block.Func.removePredecessor(b, yes)
b.Kind = BlockPlain b.Kind = BlockPlain
@ -618,8 +612,8 @@ func rewriteBlockgeneric(b *Block) bool {
b.Succs[0] = no b.Succs[0] = no
return true return true
} }
goto end6452ee3a5bb02c708bddc3181c3ea3cb goto endf401a4553c3c7c6bed64801da7bba076
end6452ee3a5bb02c708bddc3181c3ea3cb: endf401a4553c3c7c6bed64801da7bba076:
} }
return false return false
} }

View File

@ -12,8 +12,8 @@ func TestSchedule(t *testing.T) {
Fun(c, "entry", Fun(c, "entry",
Bloc("entry", Bloc("entry",
Valu("mem0", OpArg, TypeMem, 0, ".mem"), Valu("mem0", OpArg, TypeMem, 0, ".mem"),
Valu("ptr", OpConst, TypeInt64, 0xABCD, nil), Valu("ptr", OpConst64, TypeInt64, 0xABCD, nil),
Valu("v", OpConst, TypeInt64, 12, nil), Valu("v", OpConst64, TypeInt64, 12, nil),
Valu("mem1", OpStore, TypeMem, 0, nil, "ptr", "v", "mem0"), Valu("mem1", OpStore, TypeMem, 0, nil, "ptr", "v", "mem0"),
Valu("mem2", OpStore, TypeMem, 0, nil, "ptr", "v", "mem1"), Valu("mem2", OpStore, TypeMem, 0, nil, "ptr", "v", "mem1"),
Valu("mem3", OpStore, TypeInt64, 0, nil, "ptr", "sum", "mem2"), Valu("mem3", OpStore, TypeInt64, 0, nil, "ptr", "sum", "mem2"),

View File

@ -33,7 +33,7 @@ func makeConstShiftFunc(c *Config, amount int64, op Op, typ Type) fun {
Valu("argptr", OpOffPtr, ptyp, 8, nil, "SP"), Valu("argptr", OpOffPtr, ptyp, 8, nil, "SP"),
Valu("resptr", OpOffPtr, ptyp, 16, nil, "SP"), Valu("resptr", OpOffPtr, ptyp, 16, nil, "SP"),
Valu("load", OpLoad, typ, 0, nil, "argptr", "mem"), Valu("load", OpLoad, typ, 0, nil, "argptr", "mem"),
Valu("c", OpConst, TypeUInt64, amount, nil), Valu("c", OpConst64, TypeUInt64, amount, nil),
Valu("shift", op, typ, 0, nil, "load", "c"), Valu("shift", op, typ, 0, nil, "load", "c"),
Valu("store", OpStore, TypeMem, 0, nil, "resptr", "shift", "mem"), Valu("store", OpStore, TypeMem, 0, nil, "resptr", "shift", "mem"),
Exit("store"))) Exit("store")))