Skip to content

Commit 211d014

Browse files
committed
find more constants
1 parent 3ed13b4 commit 211d014

File tree

1 file changed

+32
-3
lines changed
  • src/cmd/compile/internal/ssa

1 file changed

+32
-3
lines changed

src/cmd/compile/internal/ssa/sccp.go

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
//
2525
// It starts with optimistically assuming that all SSA values are initially Top
2626
// and then propagates constant facts only along reachable control flow paths.
27-
// Due to certain basic blocks being never accessed, some inputs of phi become
27+
// Since some basic blocks are not visited yet, corresponding inputs of phi become
2828
// Top, we use the meet(args...) for phi to compute its lattice.
2929
//
3030
// Top ∩ any = any
@@ -75,23 +75,40 @@ func possibleConst(val *Value) bool {
7575
case OpPhi:
7676
fallthrough
7777
case
78+
// negate
7879
OpNeg8, OpNeg16, OpNeg32, OpNeg64, OpNeg32F, OpNeg64F,
7980
OpCom8, OpCom16, OpCom32, OpCom64,
81+
// math
8082
OpFloor, OpCeil, OpTrunc, OpRoundToEven,
83+
// conversion
84+
OpTrunc16to8, OpTrunc32to8, OpTrunc32to16, OpTrunc64to8,
85+
OpTrunc64to16, OpTrunc64to32, OpCvt32to32F, OpCvt32to64F,
86+
OpCvt64to32F, OpCvt64to64F, OpCvt32Fto32, OpCvt32Fto64,
87+
OpCvt64Fto32, OpCvt64Fto64, OpCvt32Fto64F, OpCvt64Fto32F,
88+
OpCvtBoolToUint8,
89+
OpZeroExt8to16, OpZeroExt8to32, OpZeroExt8to64, OpZeroExt16to32,
90+
OpZeroExt16to64, OpZeroExt32to64, OpSignExt8to16, OpSignExt8to32,
91+
OpSignExt8to64, OpSignExt16to32, OpSignExt16to64, OpSignExt32to64,
92+
// not
8193
OpNot:
8294
fallthrough
8395
case
96+
// add
8497
OpAdd64, OpAdd32, OpAdd16, OpAdd8,
8598
OpAdd32F, OpAdd64F,
99+
// sub
86100
OpSub64, OpSub32, OpSub16, OpSub8,
87101
OpSub32F, OpSub64F,
102+
// mul
88103
OpMul64, OpMul32, OpMul16, OpMul8,
89104
OpMul32F, OpMul64F,
105+
// div
90106
OpDiv32F, OpDiv64F,
91107
OpDiv8, OpDiv16, OpDiv32, OpDiv64,
92108
OpDiv8u, OpDiv16u, OpDiv32u, OpDiv64u,
93109
OpMod8, OpMod16, OpMod32, OpMod64,
94110
OpMod8u, OpMod16u, OpMod32u, OpMod64u,
111+
// compare
95112
OpEq64, OpEq32, OpEq16, OpEq8,
96113
OpEq32F, OpEq64F,
97114
OpLess64, OpLess32, OpLess16, OpLess8,
@@ -101,10 +118,13 @@ func possibleConst(val *Value) bool {
101118
OpLeq64U, OpLeq32U, OpLeq16U, OpLeq8U,
102119
OpLeq32F, OpLeq64F,
103120
OpEqB, OpNeqB,
121+
// shift
104122
OpLsh64x64, OpRsh64x64, OpRsh64Ux64, OpLsh32x64,
105123
OpRsh32x64, OpRsh32Ux64, OpLsh16x64, OpRsh16x64,
106124
OpRsh16Ux64, OpLsh8x64, OpRsh8x64, OpRsh8Ux64,
125+
// inbound safety check
107126
OpIsInBounds, OpIsSliceInBounds,
127+
// bit
108128
OpAnd8, OpAnd16, OpAnd32, OpAnd64,
109129
OpOr8, OpOr16, OpOr32, OpOr64,
110130
OpXor8, OpXor16, OpXor32, OpXor64:
@@ -158,10 +178,10 @@ func (t *worklist) buildDefUses() {
158178
for _, block := range t.f.Blocks {
159179
for _, val := range block.Values {
160180
for _, arg := range val.Args {
161-
// find its uses, only uses that can become constant takes into account
181+
// find its uses, only uses that can become constants take into account
162182
if possibleConst(arg) && possibleConst(val) {
163183
if _, exist := t.defUse[arg]; !exist {
164-
t.defUse[arg] = make([]*Value, 0)
184+
t.defUse[arg] = make([]*Value, 0, arg.Uses)
165185
}
166186
t.defUse[arg] = append(t.defUse[arg], val)
167187
}
@@ -298,6 +318,15 @@ func (t *worklist) visitValue(val *Value) {
298318
OpCom8, OpCom16, OpCom32, OpCom64,
299319
// math
300320
OpFloor, OpCeil, OpTrunc, OpRoundToEven,
321+
// conversion
322+
OpTrunc16to8, OpTrunc32to8, OpTrunc32to16, OpTrunc64to8,
323+
OpTrunc64to16, OpTrunc64to32, OpCvt32to32F, OpCvt32to64F,
324+
OpCvt64to32F, OpCvt64to64F, OpCvt32Fto32, OpCvt32Fto64,
325+
OpCvt64Fto32, OpCvt64Fto64, OpCvt32Fto64F, OpCvt64Fto32F,
326+
OpCvtBoolToUint8,
327+
OpZeroExt8to16, OpZeroExt8to32, OpZeroExt8to64, OpZeroExt16to32,
328+
OpZeroExt16to64, OpZeroExt32to64, OpSignExt8to16, OpSignExt8to32,
329+
OpSignExt8to64, OpSignExt16to32, OpSignExt16to64, OpSignExt32to64,
301330
// not
302331
OpNot:
303332
var lt1 = t.getLatticeCell(val.Args[0])

0 commit comments

Comments
 (0)