|
528 | 528 | (Phi (Const32 [c]) (Const32 [c])) -> (Const32 [c])
|
529 | 529 | (Phi (Const64 [c]) (Const64 [c])) -> (Const64 [c])
|
530 | 530 |
|
531 |
| -// user nil checks |
532 |
| -(NeqPtr p (ConstNil)) -> (IsNonNil p) |
533 |
| -(EqPtr p (ConstNil)) -> (Not (IsNonNil p)) |
534 |
| -(IsNonNil (ConstNil)) -> (ConstBool [0]) |
535 |
| - |
536 | 531 | // slice and interface comparisons
|
537 | 532 | // The frontend ensures that we can only compare against nil,
|
538 | 533 | // so we need only compare the first word (interface type or slice ptr).
|
|
1241 | 1236 | && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check")
|
1242 | 1237 | -> (Invalid)
|
1243 | 1238 |
|
1244 |
| -// Address comparison shows up in type assertions. |
1245 |
| -(EqPtr x x) -> (ConstBool [1]) |
1246 |
| -(EqPtr (Addr {a} x) (Addr {b} x)) -> (ConstBool [b2i(a == b)]) |
| 1239 | +// Evaluate constant address comparisons. |
| 1240 | +(EqPtr x x) -> (ConstBool [1]) |
1247 | 1241 | (NeqPtr x x) -> (ConstBool [0])
|
1248 |
| -(NeqPtr (Addr {a} x) (Addr {b} x)) -> (ConstBool [b2i(a != b)]) |
| 1242 | +(EqPtr (Addr {a} _) (Addr {b} _)) -> (ConstBool [b2i(a == b)]) |
| 1243 | +(NeqPtr (Addr {a} _) (Addr {b} _)) -> (ConstBool [b2i(a != b)]) |
| 1244 | +(EqPtr (OffPtr [o1] p1) p2) && isSamePtr(p1, p2) -> (ConstBool [b2i(o1 == 0)]) |
| 1245 | +(NeqPtr (OffPtr [o1] p1) p2) && isSamePtr(p1, p2) -> (ConstBool [b2i(o1 != 0)]) |
| 1246 | +(EqPtr (OffPtr [o1] p1) (OffPtr [o2] p2)) && isSamePtr(p1, p2) -> (ConstBool [b2i(o1 == o2)]) |
| 1247 | +(NeqPtr (OffPtr [o1] p1) (OffPtr [o2] p2)) && isSamePtr(p1, p2) -> (ConstBool [b2i(o1 != o2)]) |
| 1248 | +(EqPtr (Const(32|64) [c]) (Const(32|64) [d])) -> (ConstBool [b2i(c == d)]) |
| 1249 | +(NeqPtr (Const(32|64) [c]) (Const(32|64) [d])) -> (ConstBool [b2i(c != d)]) |
| 1250 | + |
| 1251 | +// Simplify address comparisons. |
| 1252 | +(EqPtr (AddPtr p1 o1) p2) && isSamePtr(p1, p2) -> (Not (IsNonNil o1)) |
| 1253 | +(NeqPtr (AddPtr p1 o1) p2) && isSamePtr(p1, p2) -> (IsNonNil o1) |
| 1254 | +(EqPtr (Const(32|64) [0]) p) -> (Not (IsNonNil p)) |
| 1255 | +(NeqPtr (Const(32|64) [0]) p) -> (IsNonNil p) |
| 1256 | +(EqPtr (ConstNil) p) -> (Not (IsNonNil p)) |
| 1257 | +(NeqPtr (ConstNil) p) -> (IsNonNil p) |
| 1258 | + |
| 1259 | +// Evaluate constant user nil checks. |
| 1260 | +(IsNonNil (ConstNil)) -> (ConstBool [0]) |
| 1261 | +(IsNonNil (Const(32|64) [c])) -> (ConstBool [b2i(c != 0)]) |
| 1262 | +(IsNonNil (Addr _)) -> (ConstBool [1]) |
1249 | 1263 |
|
1250 | 1264 | // Inline small runtime.memmove calls with constant length.
|
1251 | 1265 | (StaticCall {sym} s1:(Store _ (Const64 [sz]) s2:(Store _ src s3:(Store {t} _ dst mem))))
|
|
0 commit comments