@@ -133,62 +133,38 @@ func (l limit) String() string {
133133}
134134
135135func (l limit ) intersect (l2 limit ) limit {
136- if l .min < l2 .min {
137- l .min = l2 .min
138- }
139- if l .umin < l2 .umin {
140- l .umin = l2 .umin
141- }
142- if l .max > l2 .max {
143- l .max = l2 .max
144- }
145- if l .umax > l2 .umax {
146- l .umax = l2 .umax
147- }
136+ l .min = max (l .min , l2 .min )
137+ l .umin = max (l .umin , l2 .umin )
138+ l .max = min (l .max , l2 .max )
139+ l .umax = min (l .umax , l2 .umax )
148140 return l
149141}
150142
151143func (l limit ) signedMin (m int64 ) limit {
152- if l .min < m {
153- l .min = m
154- }
144+ l .min = max (l .min , m )
155145 return l
156146}
157147func (l limit ) signedMax (m int64 ) limit {
158- if l .max > m {
159- l .max = m
160- }
148+ l .max = min (l .max , m )
161149 return l
162150}
163- func (l limit ) signedMinMax (min , max int64 ) limit {
164- if l .min < min {
165- l .min = min
166- }
167- if l .max > max {
168- l .max = max
169- }
151+ func (l limit ) signedMinMax (minimum , maximum int64 ) limit {
152+ l .min = max (l .min , minimum )
153+ l .max = min (l .max , maximum )
170154 return l
171155}
172156
173157func (l limit ) unsignedMin (m uint64 ) limit {
174- if l .umin < m {
175- l .umin = m
176- }
158+ l .umin = max (l .umin , m )
177159 return l
178160}
179161func (l limit ) unsignedMax (m uint64 ) limit {
180- if l .umax > m {
181- l .umax = m
182- }
162+ l .umax = min (l .umax , m )
183163 return l
184164}
185- func (l limit ) unsignedMinMax (min , max uint64 ) limit {
186- if l .umin < min {
187- l .umin = min
188- }
189- if l .umax > max {
190- l .umax = max
191- }
165+ func (l limit ) unsignedMinMax (minimum , maximum uint64 ) limit {
166+ l .umin = max (l .umin , minimum )
167+ l .umax = min (l .umax , maximum )
192168 return l
193169}
194170
@@ -688,7 +664,7 @@ func (ft *factsTable) newLimit(v *Value, newLim limit) bool {
688664 d |= unsigned
689665 }
690666 if ! isTrue {
691- r ^= ( lt | gt | eq )
667+ r ^= lt | gt | eq
692668 }
693669 // TODO: v.Block is wrong?
694670 addRestrictions (v .Block , ft , d , v .Args [0 ], v .Args [1 ], r )
@@ -721,7 +697,7 @@ func (ft *factsTable) newLimit(v *Value, newLim limit) bool {
721697 // But in the signed domain, we can't express the ||
722698 // condition, so check if a0 is non-negative instead,
723699 // to be able to learn something.
724- r ^= ( lt | gt | eq ) // >= (index) or > (slice)
700+ r ^= lt | gt | eq // >= (index) or > (slice)
725701 if ft .isNonNegative (v .Args [0 ]) {
726702 ft .update (v .Block , v .Args [0 ], v .Args [1 ], signed , r )
727703 }
@@ -1323,8 +1299,8 @@ func prove(f *Func) {
13231299 }
13241300
13251301 // try to rewrite to a downward counting loop checking against start if the
1326- // loop body does not depends on ind or nxt and end is known before the loop.
1327- // This reduce pressure on the register allocator because this do not need
1302+ // loop body does not depend on ind or nxt and end is known before the loop.
1303+ // This reduces pressure on the register allocator because this does not need
13281304 // to use end on each iteration anymore. We compare against the start constant instead.
13291305 // That means this code:
13301306 //
@@ -1356,7 +1332,7 @@ func prove(f *Func) {
13561332 //
13571333 // exit_loop:
13581334 //
1359- // this is better because it only require to keep ind then nxt alive while looping,
1335+ // this is better because it only requires to keep ind then nxt alive while looping,
13601336 // while the original form keeps ind then nxt and end alive
13611337 start , end := v .min , v .max
13621338 if v .flags & indVarCountDown != 0 {
@@ -1379,7 +1355,7 @@ func prove(f *Func) {
13791355
13801356 if end .Block == ind .Block {
13811357 // we can't rewrite loops where the condition depends on the loop body
1382- // this simple check is forced to work because if this is true a Phi in ind.Block must exists
1358+ // this simple check is forced to work because if this is true a Phi in ind.Block must exist
13831359 continue
13841360 }
13851361
0 commit comments