github.com/riscv/riscv-go@v0.0.0-20200123204226-124ebd6fcc8e/src/cmd/compile/internal/ssa/gen/generic.rules (about)

     1  // Copyright 2015 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Simplifications that apply to all backend architectures. As an example, this
     6  // Go source code
     7  //
     8  // y := 0 * x
     9  //
    10  // can be translated into y := 0 without losing any information, which saves a
    11  // pointless multiplication instruction. Other .rules files in this directory
    12  // (for example AMD64.rules) contain rules specific to the architecture in the
    13  // filename. The rules here apply to every architecture.
    14  //
    15  // The code for parsing this file lives in rulegen.go; this file generates
    16  // ssa/rewritegeneric.go.
    17  
    18  // values are specified using the following format:
    19  // (op <type> [auxint] {aux} arg0 arg1 ...)
    20  // the type, aux, and auxint fields are optional
    21  // on the matching side
    22  //  - the type, aux, and auxint fields must match if they are specified.
    23  //  - the first occurrence of a variable defines that variable.  Subsequent
    24  //    uses must match (be == to) the first use.
    25  //  - v is defined to be the value matched.
    26  //  - an additional conditional can be provided after the match pattern with "&&".
    27  // on the generated side
    28  //  - the type of the top-level expression is the same as the one on the left-hand side.
    29  //  - the type of any subexpressions must be specified explicitly (or
    30  //    be specified in the op's type field).
    31  //  - auxint will be 0 if not specified.
    32  //  - aux will be nil if not specified.
    33  
    34  // blocks are specified using the following format:
    35  // (kind controlvalue succ0 succ1 ...)
    36  // controlvalue must be "nil" or a value expression
    37  // succ* fields must be variables
    38  // For now, the generated successors must be a permutation of the matched successors.
    39  
    40  // constant folding
    41  (Trunc16to8  (Const16 [c]))  -> (Const8   [int64(int8(c))])
    42  (Trunc32to8  (Const32 [c]))  -> (Const8   [int64(int8(c))])
    43  (Trunc32to16 (Const32 [c]))  -> (Const16  [int64(int16(c))])
    44  (Trunc64to8  (Const64 [c]))  -> (Const8   [int64(int8(c))])
    45  (Trunc64to16 (Const64 [c]))  -> (Const16  [int64(int16(c))])
    46  (Trunc64to32 (Const64 [c]))  -> (Const32  [int64(int32(c))])
    47  (Cvt64Fto32F (Const64F [c])) -> (Const32F [f2i(float64(i2f32(c)))])
    48  (Cvt32Fto64F (Const32F [c])) -> (Const64F [c]) // c is already a 64 bit float
    49  
    50  (Trunc16to8  (ZeroExt8to16  x)) -> x
    51  (Trunc32to8  (ZeroExt8to32  x)) -> x
    52  (Trunc32to16 (ZeroExt8to32  x)) -> (ZeroExt8to16  x)
    53  (Trunc32to16 (ZeroExt16to32 x)) -> x
    54  (Trunc64to8  (ZeroExt8to64  x)) -> x
    55  (Trunc64to16 (ZeroExt8to64  x)) -> (ZeroExt8to16  x)
    56  (Trunc64to16 (ZeroExt16to64 x)) -> x
    57  (Trunc64to32 (ZeroExt8to64  x)) -> (ZeroExt8to32  x)
    58  (Trunc64to32 (ZeroExt16to64 x)) -> (ZeroExt16to32 x)
    59  (Trunc64to32 (ZeroExt32to64 x)) -> x
    60  (Trunc16to8  (SignExt8to16  x)) -> x
    61  (Trunc32to8  (SignExt8to32  x)) -> x
    62  (Trunc32to16 (SignExt8to32  x)) -> (SignExt8to16  x)
    63  (Trunc32to16 (SignExt16to32 x)) -> x
    64  (Trunc64to8  (SignExt8to64  x)) -> x
    65  (Trunc64to16 (SignExt8to64  x)) -> (SignExt8to16  x)
    66  (Trunc64to16 (SignExt16to64 x)) -> x
    67  (Trunc64to32 (SignExt8to64  x)) -> (SignExt8to32  x)
    68  (Trunc64to32 (SignExt16to64 x)) -> (SignExt16to32 x)
    69  (Trunc64to32 (SignExt32to64 x)) -> x
    70  
    71  (ZeroExt8to16  (Const8  [c])) -> (Const16 [int64( uint8(c))])
    72  (ZeroExt8to32  (Const8  [c])) -> (Const32 [int64( uint8(c))])
    73  (ZeroExt8to64  (Const8  [c])) -> (Const64 [int64( uint8(c))])
    74  (ZeroExt16to32 (Const16 [c])) -> (Const32 [int64(uint16(c))])
    75  (ZeroExt16to64 (Const16 [c])) -> (Const64 [int64(uint16(c))])
    76  (ZeroExt32to64 (Const32 [c])) -> (Const64 [int64(uint32(c))])
    77  (SignExt8to16  (Const8  [c])) -> (Const16 [int64(  int8(c))])
    78  (SignExt8to32  (Const8  [c])) -> (Const32 [int64(  int8(c))])
    79  (SignExt8to64  (Const8  [c])) -> (Const64 [int64(  int8(c))])
    80  (SignExt16to32 (Const16 [c])) -> (Const32 [int64( int16(c))])
    81  (SignExt16to64 (Const16 [c])) -> (Const64 [int64( int16(c))])
    82  (SignExt32to64 (Const32 [c])) -> (Const64 [int64( int32(c))])
    83  
    84  // const negation is currently handled by frontend
    85  //(Neg8 (Const8 [c])) -> (Const8 [-c])
    86  //(Neg16 (Const16 [c])) -> (Const16 [-c])
    87  //(Neg32 (Const32 [c])) -> (Const32 [-c])
    88  //(Neg64 (Const64 [c])) -> (Const64 [-c])
    89  //(Neg32F (Const32F [c])) -> (Const32F [f2i(-i2f(c))])
    90  //(Neg64F (Const64F [c])) -> (Const64F [f2i(-i2f(c))])
    91  
    92  (Add8   (Const8 [c])   (Const8 [d]))   -> (Const8  [int64(int8(c+d))])
    93  (Add16  (Const16 [c])  (Const16 [d]))  -> (Const16 [int64(int16(c+d))])
    94  (Add32  (Const32 [c])  (Const32 [d]))  -> (Const32 [int64(int32(c+d))])
    95  (Add64  (Const64 [c])  (Const64 [d]))  -> (Const64 [c+d])
    96  (Add32F (Const32F [c]) (Const32F [d])) ->
    97          (Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) // ensure we combine the operands with 32 bit precision
    98  (Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) + i2f(d))])
    99  (AddPtr <t> x (Const64 [c])) -> (OffPtr <t> x [c])
   100  
   101  (Sub8   (Const8 [c]) (Const8 [d]))     -> (Const8 [int64(int8(c-d))])
   102  (Sub16  (Const16 [c]) (Const16 [d]))   -> (Const16 [int64(int16(c-d))])
   103  (Sub32  (Const32 [c]) (Const32 [d]))   -> (Const32 [int64(int32(c-d))])
   104  (Sub64  (Const64 [c]) (Const64 [d]))   -> (Const64 [c-d])
   105  (Sub32F (Const32F [c]) (Const32F [d])) ->
   106          (Const32F [f2i(float64(i2f32(c) - i2f32(d)))])
   107  (Sub64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) - i2f(d))])
   108  
   109  (Mul8   (Const8 [c])   (Const8 [d]))   -> (Const8  [int64(int8(c*d))])
   110  (Mul16  (Const16 [c])  (Const16 [d]))  -> (Const16 [int64(int16(c*d))])
   111  (Mul32  (Const32 [c])  (Const32 [d]))  -> (Const32 [int64(int32(c*d))])
   112  (Mul64  (Const64 [c])  (Const64 [d]))  -> (Const64 [c*d])
   113  (Mul32F (Const32F [c]) (Const32F [d])) ->
   114          (Const32F [f2i(float64(i2f32(c) * i2f32(d)))])
   115  (Mul64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) * i2f(d))])
   116  
   117  // Convert x * -1 to -x. The front-end catches some but not all of these.
   118  (Mul8  (Const8  [-1]) x) -> (Neg8  x)
   119  (Mul16 (Const16 [-1]) x) -> (Neg16 x)
   120  (Mul32 (Const32 [-1]) x) -> (Neg32 x)
   121  (Mul64 (Const64 [-1]) x) -> (Neg64 x)
   122  
   123  (Mod8  (Const8  [c]) (Const8  [d])) && d != 0 -> (Const8  [int64(int8(c % d))])
   124  (Mod16 (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(int16(c % d))])
   125  (Mod32 (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(int32(c % d))])
   126  (Mod64 (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [c % d])
   127  
   128  (Mod8u  (Const8 [c])  (Const8  [d])) && d != 0 -> (Const8  [int64(uint8(c) % uint8(d))])
   129  (Mod16u (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(uint16(c) % uint16(d))])
   130  (Mod32u (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(uint32(c) % uint32(d))])
   131  (Mod64u (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [int64(uint64(c) % uint64(d))])
   132  
   133  (Lsh64x64  (Const64 [c]) (Const64 [d])) -> (Const64 [c << uint64(d)])
   134  (Rsh64x64  (Const64 [c]) (Const64 [d])) -> (Const64 [c >> uint64(d)])
   135  (Rsh64Ux64 (Const64 [c]) (Const64 [d])) -> (Const64 [int64(uint64(c) >> uint64(d))])
   136  (Lsh32x64  (Const32 [c]) (Const64 [d])) -> (Const32 [int64(int32(c) << uint64(d))])
   137  (Rsh32x64  (Const32 [c]) (Const64 [d])) -> (Const32 [int64(int32(c) >> uint64(d))])
   138  (Rsh32Ux64 (Const32 [c]) (Const64 [d])) -> (Const32 [int64(int32(uint32(c) >> uint64(d)))])
   139  (Lsh16x64  (Const16 [c]) (Const64 [d])) -> (Const16 [int64(int16(c) << uint64(d))])
   140  (Rsh16x64  (Const16 [c]) (Const64 [d])) -> (Const16 [int64(int16(c) >> uint64(d))])
   141  (Rsh16Ux64 (Const16 [c]) (Const64 [d])) -> (Const16 [int64(int16(uint16(c) >> uint64(d)))])
   142  (Lsh8x64   (Const8  [c]) (Const64 [d])) -> (Const8  [int64(int8(c) << uint64(d))])
   143  (Rsh8x64   (Const8  [c]) (Const64 [d])) -> (Const8  [int64(int8(c) >> uint64(d))])
   144  (Rsh8Ux64  (Const8  [c]) (Const64 [d])) -> (Const8  [int64(int8(uint8(c) >> uint64(d)))])
   145  
   146  // Fold IsInBounds when the range of the index cannot exceed the limit.
   147  (IsInBounds (ZeroExt8to32  _) (Const32 [c])) && (1 << 8)  <= c -> (ConstBool [1])
   148  (IsInBounds (ZeroExt8to64  _) (Const64 [c])) && (1 << 8)  <= c -> (ConstBool [1])
   149  (IsInBounds (ZeroExt16to32 _) (Const32 [c])) && (1 << 16) <= c -> (ConstBool [1])
   150  (IsInBounds (ZeroExt16to64 _) (Const64 [c])) && (1 << 16) <= c -> (ConstBool [1])
   151  (IsInBounds x x) -> (ConstBool [0])
   152  (IsInBounds (And32 (Const32 [c]) _) (Const32 [d])) && 0 <= c && c < d -> (ConstBool [1])
   153  (IsInBounds (And64 (Const64 [c]) _) (Const64 [d])) && 0 <= c && c < d -> (ConstBool [1])
   154  (IsInBounds (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(0 <= c && c < d)])
   155  (IsInBounds (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(0 <= c && c < d)])
   156  // (Mod64u x y) is always between 0 (inclusive) and y (exclusive).
   157  (IsInBounds (Mod32u _ y) y) -> (ConstBool [1])
   158  (IsInBounds (Mod64u _ y) y) -> (ConstBool [1])
   159  
   160  (IsSliceInBounds x x) -> (ConstBool [1])
   161  (IsSliceInBounds (And32 (Const32 [c]) _) (Const32 [d])) && 0 <= c && c <= d -> (ConstBool [1])
   162  (IsSliceInBounds (And64 (Const64 [c]) _) (Const64 [d])) && 0 <= c && c <= d -> (ConstBool [1])
   163  (IsSliceInBounds (Const32 [0]) _) -> (ConstBool [1])
   164  (IsSliceInBounds (Const64 [0]) _) -> (ConstBool [1])
   165  (IsSliceInBounds (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(0 <= c && c <= d)])
   166  (IsSliceInBounds (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(0 <= c && c <= d)])
   167  (IsSliceInBounds (SliceLen x) (SliceCap x)) -> (ConstBool [1])
   168  
   169  (Eq64 x x) -> (ConstBool [1])
   170  (Eq32 x x) -> (ConstBool [1])
   171  (Eq16 x x) -> (ConstBool [1])
   172  (Eq8  x x) -> (ConstBool [1])
   173  (EqB (ConstBool [c]) (ConstBool [d])) -> (ConstBool [b2i(c == d)])
   174  (EqB (ConstBool [0]) x) -> (Not x)
   175  (EqB (ConstBool [1]) x) -> x
   176  
   177  (Neq64 x x) -> (ConstBool [0])
   178  (Neq32 x x) -> (ConstBool [0])
   179  (Neq16 x x) -> (ConstBool [0])
   180  (Neq8  x x) -> (ConstBool [0])
   181  (NeqB (ConstBool [c]) (ConstBool [d])) -> (ConstBool [b2i(c != d)])
   182  (NeqB (ConstBool [0]) x) -> x
   183  (NeqB (ConstBool [1]) x) -> (Not x)
   184  
   185  (Eq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x)) -> (Eq64 (Const64 <t> [c-d]) x)
   186  (Eq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x)) -> (Eq32 (Const32 <t> [int64(int32(c-d))]) x)
   187  (Eq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x)) -> (Eq16 (Const16 <t> [int64(int16(c-d))]) x)
   188  (Eq8  (Const8  <t> [c]) (Add8  (Const8  <t> [d]) x)) -> (Eq8  (Const8 <t> [int64(int8(c-d))]) x)
   189  
   190  (Neq64 (Const64 <t> [c]) (Add64 (Const64 <t> [d]) x)) -> (Neq64 (Const64 <t> [c-d]) x)
   191  (Neq32 (Const32 <t> [c]) (Add32 (Const32 <t> [d]) x)) -> (Neq32 (Const32 <t> [int64(int32(c-d))]) x)
   192  (Neq16 (Const16 <t> [c]) (Add16 (Const16 <t> [d]) x)) -> (Neq16 (Const16 <t> [int64(int16(c-d))]) x)
   193  (Neq8  (Const8  <t> [c]) (Add8  (Const8  <t> [d]) x)) -> (Neq8 (Const8 <t> [int64(int8(c-d))]) x)
   194  
   195  // canonicalize: swap arguments for commutative operations when one argument is a constant.
   196  (Eq64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Eq64 (Const64 <t> [c]) x)
   197  (Eq32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Eq32 (Const32 <t> [c]) x)
   198  (Eq16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Eq16 (Const16 <t> [c]) x)
   199  (Eq8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Eq8  (Const8  <t> [c]) x)
   200  
   201  (Neq64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Neq64 (Const64 <t> [c]) x)
   202  (Neq32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Neq32 (Const32 <t> [c]) x)
   203  (Neq16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Neq16 (Const16 <t> [c]) x)
   204  (Neq8  x (Const8 <t>  [c])) && x.Op != OpConst8  -> (Neq8  (Const8  <t> [c]) x)
   205  
   206  // AddPtr is not canonicalized because nilcheck ptr checks the first argument to be non-nil.
   207  (Add64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Add64 (Const64 <t> [c]) x)
   208  (Add32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Add32 (Const32 <t> [c]) x)
   209  (Add16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Add16 (Const16 <t> [c]) x)
   210  (Add8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Add8  (Const8  <t> [c]) x)
   211  
   212  (Mul64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Mul64 (Const64 <t> [c]) x)
   213  (Mul32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Mul32 (Const32 <t> [c]) x)
   214  (Mul16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Mul16 (Const16 <t> [c]) x)
   215  (Mul8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Mul8  (Const8  <t> [c]) x)
   216  
   217  (Sub64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Add64 (Const64 <t> [-c]) x)
   218  (Sub32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Add32 (Const32 <t> [int64(int32(-c))]) x)
   219  (Sub16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Add16 (Const16 <t> [int64(int16(-c))]) x)
   220  (Sub8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Add8  (Const8  <t> [int64(int8(-c))]) x)
   221  
   222  (And64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (And64 (Const64 <t> [c]) x)
   223  (And32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (And32 (Const32 <t> [c]) x)
   224  (And16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (And16 (Const16 <t> [c]) x)
   225  (And8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (And8  (Const8  <t> [c]) x)
   226  
   227  (Or64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Or64 (Const64 <t> [c]) x)
   228  (Or32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Or32 (Const32 <t> [c]) x)
   229  (Or16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Or16 (Const16 <t> [c]) x)
   230  (Or8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Or8  (Const8  <t> [c]) x)
   231  
   232  (Xor64 x (Const64 <t> [c])) && x.Op != OpConst64 -> (Xor64 (Const64 <t> [c]) x)
   233  (Xor32 x (Const32 <t> [c])) && x.Op != OpConst32 -> (Xor32 (Const32 <t> [c]) x)
   234  (Xor16 x (Const16 <t> [c])) && x.Op != OpConst16 -> (Xor16 (Const16 <t> [c]) x)
   235  (Xor8  x (Const8  <t> [c])) && x.Op != OpConst8  -> (Xor8  (Const8  <t> [c]) x)
   236  
   237  // fold negation into comparison operators
   238  (Not (Eq64 x y)) -> (Neq64 x y)
   239  (Not (Eq32 x y)) -> (Neq32 x y)
   240  (Not (Eq16 x y)) -> (Neq16 x y)
   241  (Not (Eq8  x y)) -> (Neq8  x y)
   242  (Not (EqB  x y)) -> (NeqB  x y)
   243  
   244  (Not (Neq64 x y)) -> (Eq64 x y)
   245  (Not (Neq32 x y)) -> (Eq32 x y)
   246  (Not (Neq16 x y)) -> (Eq16 x y)
   247  (Not (Neq8  x y)) -> (Eq8  x y)
   248  (Not (NeqB  x y)) -> (EqB  x y)
   249  
   250  (Not (Greater64 x y)) -> (Leq64 x y)
   251  (Not (Greater32 x y)) -> (Leq32 x y)
   252  (Not (Greater16 x y)) -> (Leq16 x y)
   253  (Not (Greater8  x y)) -> (Leq8  x y)
   254  
   255  (Not (Greater64U x y)) -> (Leq64U x y)
   256  (Not (Greater32U x y)) -> (Leq32U x y)
   257  (Not (Greater16U x y)) -> (Leq16U x y)
   258  (Not (Greater8U  x y)) -> (Leq8U  x y)
   259  
   260  (Not (Geq64 x y)) -> (Less64 x y)
   261  (Not (Geq32 x y)) -> (Less32 x y)
   262  (Not (Geq16 x y)) -> (Less16 x y)
   263  (Not (Geq8  x y)) -> (Less8  x y)
   264  
   265  (Not (Geq64U x y)) -> (Less64U x y)
   266  (Not (Geq32U x y)) -> (Less32U x y)
   267  (Not (Geq16U x y)) -> (Less16U x y)
   268  (Not (Geq8U  x y)) -> (Less8U  x y)
   269  
   270  (Not (Less64 x y)) -> (Geq64 x y)
   271  (Not (Less32 x y)) -> (Geq32 x y)
   272  (Not (Less16 x y)) -> (Geq16 x y)
   273  (Not (Less8  x y)) -> (Geq8  x y)
   274  
   275  (Not (Less64U x y)) -> (Geq64U x y)
   276  (Not (Less32U x y)) -> (Geq32U x y)
   277  (Not (Less16U x y)) -> (Geq16U x y)
   278  (Not (Less8U  x y)) -> (Geq8U  x y)
   279  
   280  (Not (Leq64 x y)) -> (Greater64 x y)
   281  (Not (Leq32 x y)) -> (Greater32 x y)
   282  (Not (Leq16 x y)) -> (Greater16 x y)
   283  (Not (Leq8  x y)) -> (Greater8 x y)
   284  
   285  (Not (Leq64U x y)) -> (Greater64U x y)
   286  (Not (Leq32U x y)) -> (Greater32U x y)
   287  (Not (Leq16U x y)) -> (Greater16U x y)
   288  (Not (Leq8U  x y)) -> (Greater8U  x y)
   289  
   290  // Distribute multiplication c * (d+x) -> c*d + c*x. Useful for:
   291  // a[i].b = ...; a[i+1].b = ...
   292  (Mul64 (Const64 <t> [c]) (Add64 <t> (Const64 <t> [d]) x)) ->
   293    (Add64 (Const64 <t> [c*d]) (Mul64 <t> (Const64 <t> [c]) x))
   294  (Mul32 (Const32 <t> [c]) (Add32 <t> (Const32 <t> [d]) x)) ->
   295    (Add32 (Const32 <t> [int64(int32(c*d))]) (Mul32 <t> (Const32 <t> [c]) x))
   296  
   297  // rewrite shifts of 8/16/32 bit consts into 64 bit consts to reduce
   298  // the number of the other rewrite rules for const shifts
   299  (Lsh64x32  <t> x (Const32 [c])) -> (Lsh64x64  x (Const64 <t> [int64(uint32(c))]))
   300  (Lsh64x16  <t> x (Const16 [c])) -> (Lsh64x64  x (Const64 <t> [int64(uint16(c))]))
   301  (Lsh64x8   <t> x (Const8  [c])) -> (Lsh64x64  x (Const64 <t> [int64(uint8(c))]))
   302  (Rsh64x32  <t> x (Const32 [c])) -> (Rsh64x64  x (Const64 <t> [int64(uint32(c))]))
   303  (Rsh64x16  <t> x (Const16 [c])) -> (Rsh64x64  x (Const64 <t> [int64(uint16(c))]))
   304  (Rsh64x8   <t> x (Const8  [c])) -> (Rsh64x64  x (Const64 <t> [int64(uint8(c))]))
   305  (Rsh64Ux32 <t> x (Const32 [c])) -> (Rsh64Ux64 x (Const64 <t> [int64(uint32(c))]))
   306  (Rsh64Ux16 <t> x (Const16 [c])) -> (Rsh64Ux64 x (Const64 <t> [int64(uint16(c))]))
   307  (Rsh64Ux8  <t> x (Const8  [c])) -> (Rsh64Ux64 x (Const64 <t> [int64(uint8(c))]))
   308  
   309  (Lsh32x32  <t> x (Const32 [c])) -> (Lsh32x64  x (Const64 <t> [int64(uint32(c))]))
   310  (Lsh32x16  <t> x (Const16 [c])) -> (Lsh32x64  x (Const64 <t> [int64(uint16(c))]))
   311  (Lsh32x8   <t> x (Const8  [c])) -> (Lsh32x64  x (Const64 <t> [int64(uint8(c))]))
   312  (Rsh32x32  <t> x (Const32 [c])) -> (Rsh32x64  x (Const64 <t> [int64(uint32(c))]))
   313  (Rsh32x16  <t> x (Const16 [c])) -> (Rsh32x64  x (Const64 <t> [int64(uint16(c))]))
   314  (Rsh32x8   <t> x (Const8  [c])) -> (Rsh32x64  x (Const64 <t> [int64(uint8(c))]))
   315  (Rsh32Ux32 <t> x (Const32 [c])) -> (Rsh32Ux64 x (Const64 <t> [int64(uint32(c))]))
   316  (Rsh32Ux16 <t> x (Const16 [c])) -> (Rsh32Ux64 x (Const64 <t> [int64(uint16(c))]))
   317  (Rsh32Ux8  <t> x (Const8  [c])) -> (Rsh32Ux64 x (Const64 <t> [int64(uint8(c))]))
   318  
   319  (Lsh16x32  <t> x (Const32 [c])) -> (Lsh16x64  x (Const64 <t> [int64(uint32(c))]))
   320  (Lsh16x16  <t> x (Const16 [c])) -> (Lsh16x64  x (Const64 <t> [int64(uint16(c))]))
   321  (Lsh16x8   <t> x (Const8  [c])) -> (Lsh16x64  x (Const64 <t> [int64(uint8(c))]))
   322  (Rsh16x32  <t> x (Const32 [c])) -> (Rsh16x64  x (Const64 <t> [int64(uint32(c))]))
   323  (Rsh16x16  <t> x (Const16 [c])) -> (Rsh16x64  x (Const64 <t> [int64(uint16(c))]))
   324  (Rsh16x8   <t> x (Const8  [c])) -> (Rsh16x64  x (Const64 <t> [int64(uint8(c))]))
   325  (Rsh16Ux32 <t> x (Const32 [c])) -> (Rsh16Ux64 x (Const64 <t> [int64(uint32(c))]))
   326  (Rsh16Ux16 <t> x (Const16 [c])) -> (Rsh16Ux64 x (Const64 <t> [int64(uint16(c))]))
   327  (Rsh16Ux8  <t> x (Const8  [c])) -> (Rsh16Ux64 x (Const64 <t> [int64(uint8(c))]))
   328  
   329  (Lsh8x32  <t> x (Const32 [c])) -> (Lsh8x64  x (Const64 <t> [int64(uint32(c))]))
   330  (Lsh8x16  <t> x (Const16 [c])) -> (Lsh8x64  x (Const64 <t> [int64(uint16(c))]))
   331  (Lsh8x8   <t> x (Const8  [c])) -> (Lsh8x64  x (Const64 <t> [int64(uint8(c))]))
   332  (Rsh8x32  <t> x (Const32 [c])) -> (Rsh8x64  x (Const64 <t> [int64(uint32(c))]))
   333  (Rsh8x16  <t> x (Const16 [c])) -> (Rsh8x64  x (Const64 <t> [int64(uint16(c))]))
   334  (Rsh8x8   <t> x (Const8  [c])) -> (Rsh8x64  x (Const64 <t> [int64(uint8(c))]))
   335  (Rsh8Ux32 <t> x (Const32 [c])) -> (Rsh8Ux64 x (Const64 <t> [int64(uint32(c))]))
   336  (Rsh8Ux16 <t> x (Const16 [c])) -> (Rsh8Ux64 x (Const64 <t> [int64(uint16(c))]))
   337  (Rsh8Ux8  <t> x (Const8  [c])) -> (Rsh8Ux64 x (Const64 <t> [int64(uint8(c))]))
   338  
   339  // shifts by zero
   340  (Lsh64x64  x (Const64 [0])) -> x
   341  (Rsh64x64  x (Const64 [0])) -> x
   342  (Rsh64Ux64 x (Const64 [0])) -> x
   343  (Lsh32x64  x (Const64 [0])) -> x
   344  (Rsh32x64  x (Const64 [0])) -> x
   345  (Rsh32Ux64 x (Const64 [0])) -> x
   346  (Lsh16x64  x (Const64 [0])) -> x
   347  (Rsh16x64  x (Const64 [0])) -> x
   348  (Rsh16Ux64 x (Const64 [0])) -> x
   349  (Lsh8x64   x (Const64 [0])) -> x
   350  (Rsh8x64   x (Const64 [0])) -> x
   351  (Rsh8Ux64  x (Const64 [0])) -> x
   352  
   353  // zero shifted.
   354  (Lsh64x64  (Const64 [0]) _) -> (Const64 [0])
   355  (Lsh64x32  (Const64 [0]) _) -> (Const64 [0])
   356  (Lsh64x16  (Const64 [0]) _) -> (Const64 [0])
   357  (Lsh64x8  (Const64 [0]) _) -> (Const64 [0])
   358  (Rsh64x64  (Const64 [0]) _) -> (Const64 [0])
   359  (Rsh64x32  (Const64 [0]) _) -> (Const64 [0])
   360  (Rsh64x16  (Const64 [0]) _) -> (Const64 [0])
   361  (Rsh64x8  (Const64 [0]) _) -> (Const64 [0])
   362  (Rsh64Ux64 (Const64 [0]) _) -> (Const64 [0])
   363  (Rsh64Ux32 (Const64 [0]) _) -> (Const64 [0])
   364  (Rsh64Ux16 (Const64 [0]) _) -> (Const64 [0])
   365  (Rsh64Ux8 (Const64 [0]) _) -> (Const64 [0])
   366  (Lsh32x64  (Const32 [0]) _) -> (Const32 [0])
   367  (Lsh32x32  (Const32 [0]) _) -> (Const32 [0])
   368  (Lsh32x16  (Const32 [0]) _) -> (Const32 [0])
   369  (Lsh32x8  (Const32 [0]) _) -> (Const32 [0])
   370  (Rsh32x64  (Const32 [0]) _) -> (Const32 [0])
   371  (Rsh32x32  (Const32 [0]) _) -> (Const32 [0])
   372  (Rsh32x16  (Const32 [0]) _) -> (Const32 [0])
   373  (Rsh32x8  (Const32 [0]) _) -> (Const32 [0])
   374  (Rsh32Ux64 (Const32 [0]) _) -> (Const32 [0])
   375  (Rsh32Ux32 (Const32 [0]) _) -> (Const32 [0])
   376  (Rsh32Ux16 (Const32 [0]) _) -> (Const32 [0])
   377  (Rsh32Ux8 (Const32 [0]) _) -> (Const32 [0])
   378  (Lsh16x64  (Const16 [0]) _) -> (Const16 [0])
   379  (Lsh16x32  (Const16 [0]) _) -> (Const16 [0])
   380  (Lsh16x16  (Const16 [0]) _) -> (Const16 [0])
   381  (Lsh16x8  (Const16 [0]) _) -> (Const16 [0])
   382  (Rsh16x64  (Const16 [0]) _) -> (Const16 [0])
   383  (Rsh16x32  (Const16 [0]) _) -> (Const16 [0])
   384  (Rsh16x16  (Const16 [0]) _) -> (Const16 [0])
   385  (Rsh16x8  (Const16 [0]) _) -> (Const16 [0])
   386  (Rsh16Ux64 (Const16 [0]) _) -> (Const16 [0])
   387  (Rsh16Ux32 (Const16 [0]) _) -> (Const16 [0])
   388  (Rsh16Ux16 (Const16 [0]) _) -> (Const16 [0])
   389  (Rsh16Ux8 (Const16 [0]) _) -> (Const16 [0])
   390  (Lsh8x64   (Const8 [0]) _) -> (Const8  [0])
   391  (Lsh8x32   (Const8 [0]) _) -> (Const8  [0])
   392  (Lsh8x16   (Const8 [0]) _) -> (Const8  [0])
   393  (Lsh8x8   (Const8 [0]) _) -> (Const8  [0])
   394  (Rsh8x64   (Const8 [0]) _) -> (Const8  [0])
   395  (Rsh8x32   (Const8 [0]) _) -> (Const8  [0])
   396  (Rsh8x16   (Const8 [0]) _) -> (Const8  [0])
   397  (Rsh8x8   (Const8 [0]) _) -> (Const8  [0])
   398  (Rsh8Ux64  (Const8 [0]) _) -> (Const8  [0])
   399  (Rsh8Ux32  (Const8 [0]) _) -> (Const8  [0])
   400  (Rsh8Ux16  (Const8 [0]) _) -> (Const8  [0])
   401  (Rsh8Ux8  (Const8 [0]) _) -> (Const8  [0])
   402  
   403  // large left shifts of all values, and right shifts of unsigned values
   404  (Lsh64x64  _ (Const64 [c])) && uint64(c) >= 64 -> (Const64 [0])
   405  (Rsh64Ux64 _ (Const64 [c])) && uint64(c) >= 64 -> (Const64 [0])
   406  (Lsh32x64  _ (Const64 [c])) && uint64(c) >= 32 -> (Const32 [0])
   407  (Rsh32Ux64 _ (Const64 [c])) && uint64(c) >= 32 -> (Const32 [0])
   408  (Lsh16x64  _ (Const64 [c])) && uint64(c) >= 16 -> (Const16 [0])
   409  (Rsh16Ux64 _ (Const64 [c])) && uint64(c) >= 16 -> (Const16 [0])
   410  (Lsh8x64   _ (Const64 [c])) && uint64(c) >= 8  -> (Const8  [0])
   411  (Rsh8Ux64  _ (Const64 [c])) && uint64(c) >= 8  -> (Const8  [0])
   412  
   413  // combine const shifts
   414  (Lsh64x64 <t> (Lsh64x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Lsh64x64 x (Const64 <t> [c+d]))
   415  (Lsh32x64 <t> (Lsh32x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Lsh32x64 x (Const64 <t> [c+d]))
   416  (Lsh16x64 <t> (Lsh16x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Lsh16x64 x (Const64 <t> [c+d]))
   417  (Lsh8x64  <t> (Lsh8x64  x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Lsh8x64  x (Const64 <t> [c+d]))
   418  
   419  (Rsh64x64 <t> (Rsh64x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh64x64 x (Const64 <t> [c+d]))
   420  (Rsh32x64 <t> (Rsh32x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh32x64 x (Const64 <t> [c+d]))
   421  (Rsh16x64 <t> (Rsh16x64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh16x64 x (Const64 <t> [c+d]))
   422  (Rsh8x64  <t> (Rsh8x64  x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh8x64  x (Const64 <t> [c+d]))
   423  
   424  (Rsh64Ux64 <t> (Rsh64Ux64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh64Ux64 x (Const64 <t> [c+d]))
   425  (Rsh32Ux64 <t> (Rsh32Ux64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh32Ux64 x (Const64 <t> [c+d]))
   426  (Rsh16Ux64 <t> (Rsh16Ux64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh16Ux64 x (Const64 <t> [c+d]))
   427  (Rsh8Ux64  <t> (Rsh8Ux64  x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh8Ux64  x (Const64 <t> [c+d]))
   428  
   429  // ((x >> c1) << c2) >> c3
   430  (Rsh64Ux64 (Lsh64x64 (Rsh64Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   431    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   432    -> (Rsh64Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   433  (Rsh32Ux64 (Lsh32x64 (Rsh32Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   434    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   435    -> (Rsh32Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   436  (Rsh16Ux64 (Lsh16x64 (Rsh16Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   437    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   438    -> (Rsh16Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   439  (Rsh8Ux64 (Lsh8x64 (Rsh8Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   440    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   441    -> (Rsh8Ux64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   442  
   443  // ((x << c1) >> c2) << c3
   444  (Lsh64x64 (Rsh64Ux64 (Lsh64x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   445    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   446    -> (Lsh64x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   447  (Lsh32x64 (Rsh32Ux64 (Lsh32x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   448    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   449    -> (Lsh32x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   450  (Lsh16x64 (Rsh16Ux64 (Lsh16x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   451    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   452    -> (Lsh16x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   453  (Lsh8x64 (Rsh8Ux64 (Lsh8x64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3]))
   454    && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3)
   455    -> (Lsh8x64 x (Const64 <config.fe.TypeUInt64()> [c1-c2+c3]))
   456  
   457  // constant comparisons
   458  (Eq64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c == d)])
   459  (Eq32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c == d)])
   460  (Eq16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c == d)])
   461  (Eq8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c == d)])
   462  
   463  (Neq64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c != d)])
   464  (Neq32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c != d)])
   465  (Neq16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c != d)])
   466  (Neq8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c != d)])
   467  
   468  (Greater64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c > d)])
   469  (Greater32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c > d)])
   470  (Greater16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c > d)])
   471  (Greater8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c > d)])
   472  
   473  (Greater64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) > uint64(d))])
   474  (Greater32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) > uint32(d))])
   475  (Greater16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) > uint16(d))])
   476  (Greater8U  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(uint8(c)  > uint8(d))])
   477  
   478  (Geq64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c >= d)])
   479  (Geq32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c >= d)])
   480  (Geq16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c >= d)])
   481  (Geq8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c >= d)])
   482  
   483  (Geq64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) >= uint64(d))])
   484  (Geq32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) >= uint32(d))])
   485  (Geq16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) >= uint16(d))])
   486  (Geq8U  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(uint8(c)  >= uint8(d))])
   487  
   488  (Less64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c < d)])
   489  (Less32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c < d)])
   490  (Less16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c < d)])
   491  (Less8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c < d)])
   492  
   493  (Less64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) < uint64(d))])
   494  (Less32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) < uint32(d))])
   495  (Less16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) < uint16(d))])
   496  (Less8U  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(uint8(c)  < uint8(d))])
   497  
   498  (Leq64 (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(c <= d)])
   499  (Leq32 (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(c <= d)])
   500  (Leq16 (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(c <= d)])
   501  (Leq8  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(c <= d)])
   502  
   503  (Leq64U (Const64 [c]) (Const64 [d])) -> (ConstBool [b2i(uint64(c) <= uint64(d))])
   504  (Leq32U (Const32 [c]) (Const32 [d])) -> (ConstBool [b2i(uint32(c) <= uint32(d))])
   505  (Leq16U (Const16 [c]) (Const16 [d])) -> (ConstBool [b2i(uint16(c) <= uint16(d))])
   506  (Leq8U  (Const8  [c]) (Const8  [d])) -> (ConstBool [b2i(uint8(c)  <= uint8(d))])
   507  
   508  // simplifications
   509  (Or64 x x) -> x
   510  (Or32 x x) -> x
   511  (Or16 x x) -> x
   512  (Or8  x x) -> x
   513  (Or64 (Const64 [0]) x) -> x
   514  (Or32 (Const32 [0]) x) -> x
   515  (Or16 (Const16 [0]) x) -> x
   516  (Or8  (Const8  [0]) x) -> x
   517  (Or64 (Const64 [-1]) _) -> (Const64 [-1])
   518  (Or32 (Const32 [-1]) _) -> (Const32 [-1])
   519  (Or16 (Const16 [-1]) _) -> (Const16 [-1])
   520  (Or8  (Const8  [-1]) _) -> (Const8  [-1])
   521  (And64 x x) -> x
   522  (And32 x x) -> x
   523  (And16 x x) -> x
   524  (And8  x x) -> x
   525  (And64 (Const64 [-1]) x) -> x
   526  (And32 (Const32 [-1]) x) -> x
   527  (And16 (Const16 [-1]) x) -> x
   528  (And8  (Const8  [-1]) x) -> x
   529  (And64 (Const64 [0]) _) -> (Const64 [0])
   530  (And32 (Const32 [0]) _) -> (Const32 [0])
   531  (And16 (Const16 [0]) _) -> (Const16 [0])
   532  (And8  (Const8  [0]) _) -> (Const8  [0])
   533  (Xor64 x x) -> (Const64 [0])
   534  (Xor32 x x) -> (Const32 [0])
   535  (Xor16 x x) -> (Const16 [0])
   536  (Xor8  x x) -> (Const8  [0])
   537  (Xor64 (Const64 [0]) x) -> x
   538  (Xor32 (Const32 [0]) x) -> x
   539  (Xor16 (Const16 [0]) x) -> x
   540  (Xor8  (Const8  [0]) x) -> x
   541  (Add64 (Const64 [0]) x) -> x
   542  (Add32 (Const32 [0]) x) -> x
   543  (Add16 (Const16 [0]) x) -> x
   544  (Add8  (Const8  [0]) x) -> x
   545  (Sub64 x x) -> (Const64 [0])
   546  (Sub32 x x) -> (Const32 [0])
   547  (Sub16 x x) -> (Const16 [0])
   548  (Sub8  x x) -> (Const8  [0])
   549  (Mul64 (Const64 [0]) _) -> (Const64 [0])
   550  (Mul32 (Const32 [0]) _) -> (Const32 [0])
   551  (Mul16 (Const16 [0]) _) -> (Const16 [0])
   552  (Mul8  (Const8  [0]) _) -> (Const8  [0])
   553  (Com8  (Com8  x)) -> x
   554  (Com16 (Com16 x)) -> x
   555  (Com32 (Com32 x)) -> x
   556  (Com64 (Com64 x)) -> x
   557  (Neg8  (Sub8  x y)) -> (Sub8  y x)
   558  (Neg16 (Sub16 x y)) -> (Sub16 y x)
   559  (Neg32 (Sub32 x y)) -> (Sub32 y x)
   560  (Neg64 (Sub64 x y)) -> (Sub64 y x)
   561  
   562  (And64 x (And64 x y)) -> (And64 x y)
   563  (And32 x (And32 x y)) -> (And32 x y)
   564  (And16 x (And16 x y)) -> (And16 x y)
   565  (And8  x (And8  x y)) -> (And8  x y)
   566  (And64 x (And64 y x)) -> (And64 x y)
   567  (And32 x (And32 y x)) -> (And32 x y)
   568  (And16 x (And16 y x)) -> (And16 x y)
   569  (And8  x (And8  y x)) -> (And8  x y)
   570  (And64 (And64 x y) x) -> (And64 x y)
   571  (And32 (And32 x y) x) -> (And32 x y)
   572  (And16 (And16 x y) x) -> (And16 x y)
   573  (And8  (And8  x y) x) -> (And8  x y)
   574  (And64 (And64 x y) y) -> (And64 x y)
   575  (And32 (And32 x y) y) -> (And32 x y)
   576  (And16 (And16 x y) y) -> (And16 x y)
   577  (And8  (And8  x y) y) -> (And8  x y)
   578  (Or64 x (Or64 x y)) -> (Or64 x y)
   579  (Or32 x (Or32 x y)) -> (Or32 x y)
   580  (Or16 x (Or16 x y)) -> (Or16 x y)
   581  (Or8  x (Or8  x y)) -> (Or8  x y)
   582  (Or64 x (Or64 y x)) -> (Or64 x y)
   583  (Or32 x (Or32 y x)) -> (Or32 x y)
   584  (Or16 x (Or16 y x)) -> (Or16 x y)
   585  (Or8  x (Or8  y x)) -> (Or8  x y)
   586  (Or64 (Or64 x y) x) -> (Or64 x y)
   587  (Or32 (Or32 x y) x) -> (Or32 x y)
   588  (Or16 (Or16 x y) x) -> (Or16 x y)
   589  (Or8  (Or8  x y) x) -> (Or8  x y)
   590  (Or64 (Or64 x y) y) -> (Or64 x y)
   591  (Or32 (Or32 x y) y) -> (Or32 x y)
   592  (Or16 (Or16 x y) y) -> (Or16 x y)
   593  (Or8  (Or8  x y) y) -> (Or8  x y)
   594  (Xor64 x (Xor64 x y)) -> y
   595  (Xor32 x (Xor32 x y)) -> y
   596  (Xor16 x (Xor16 x y)) -> y
   597  (Xor8  x (Xor8  x y)) -> y
   598  (Xor64 x (Xor64 y x)) -> y
   599  (Xor32 x (Xor32 y x)) -> y
   600  (Xor16 x (Xor16 y x)) -> y
   601  (Xor8  x (Xor8  y x)) -> y
   602  (Xor64 (Xor64 x y) x) -> y
   603  (Xor32 (Xor32 x y) x) -> y
   604  (Xor16 (Xor16 x y) x) -> y
   605  (Xor8  (Xor8  x y) x) -> y
   606  (Xor64 (Xor64 x y) y) -> x
   607  (Xor32 (Xor32 x y) y) -> x
   608  (Xor16 (Xor16 x y) y) -> x
   609  (Xor8  (Xor8  x y) y) -> x
   610  
   611  (Trunc64to8  (And64 (Const64 [y]) x)) && y&0xFF == 0xFF -> (Trunc64to8 x)
   612  (Trunc64to16 (And64 (Const64 [y]) x)) && y&0xFFFF == 0xFFFF -> (Trunc64to16 x)
   613  (Trunc64to32 (And64 (Const64 [y]) x)) && y&0xFFFFFFFF == 0xFFFFFFFF -> (Trunc64to32 x)
   614  (Trunc32to8  (And32 (Const32 [y]) x)) && y&0xFF == 0xFF -> (Trunc32to8 x)
   615  (Trunc32to16 (And32 (Const32 [y]) x)) && y&0xFFFF == 0xFFFF -> (Trunc32to16 x)
   616  (Trunc16to8  (And16 (Const16 [y]) x)) && y&0xFF == 0xFF -> (Trunc16to8 x)
   617  
   618  (ZeroExt8to64  (Trunc64to8  x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 56 -> x
   619  (ZeroExt16to64 (Trunc64to16 x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 48 -> x
   620  (ZeroExt32to64 (Trunc64to32 x:(Rsh64Ux64 _ (Const64 [s])))) && s >= 32 -> x
   621  (ZeroExt8to32  (Trunc32to8  x:(Rsh32Ux64 _ (Const64 [s])))) && s >= 24 -> x
   622  (ZeroExt16to32 (Trunc32to16 x:(Rsh32Ux64 _ (Const64 [s])))) && s >= 16 -> x
   623  (ZeroExt8to16  (Trunc16to8  x:(Rsh16Ux64 _ (Const64 [s])))) && s >= 8 -> x
   624  
   625  (SignExt8to64  (Trunc64to8  x:(Rsh64x64 _ (Const64 [s])))) && s >= 56 -> x
   626  (SignExt16to64 (Trunc64to16 x:(Rsh64x64 _ (Const64 [s])))) && s >= 48 -> x
   627  (SignExt32to64 (Trunc64to32 x:(Rsh64x64 _ (Const64 [s])))) && s >= 32 -> x
   628  (SignExt8to32  (Trunc32to8  x:(Rsh32x64 _ (Const64 [s])))) && s >= 24 -> x
   629  (SignExt16to32 (Trunc32to16 x:(Rsh32x64 _ (Const64 [s])))) && s >= 16 -> x
   630  (SignExt8to16  (Trunc16to8  x:(Rsh16x64 _ (Const64 [s])))) && s >= 8 -> x
   631  
   632  (Slicemask (Const32 [x])) && x > 0 -> (Const32 [-1])
   633  (Slicemask (Const32 [0]))          -> (Const32 [0])
   634  (Slicemask (Const64 [x])) && x > 0 -> (Const64 [-1])
   635  (Slicemask (Const64 [0]))          -> (Const64 [0])
   636  
   637  // Rewrite AND of consts as shifts if possible, slightly faster for 64 bit operands
   638  // leading zeros can be shifted left, then right
   639  (And64 <t> (Const64 [y]) x) && nlz(y) + nto(y) == 64 && nto(y) >= 32
   640    -> (Rsh64Ux64 (Lsh64x64 <t> x (Const64 <t> [nlz(y)])) (Const64 <t> [nlz(y)]))
   641  // trailing zeros can be shifted right, then left
   642  (And64 <t> (Const64 [y]) x) && nlo(y) + ntz(y) == 64 && ntz(y) >= 32
   643    -> (Lsh64x64 (Rsh64Ux64 <t> x (Const64 <t> [ntz(y)])) (Const64 <t> [ntz(y)]))
   644  
   645  // simplifications often used for lengths.  e.g. len(s[i:i+5])==5
   646  (Sub64 (Add64 x y) x) -> y
   647  (Sub64 (Add64 x y) y) -> x
   648  (Sub32 (Add32 x y) x) -> y
   649  (Sub32 (Add32 x y) y) -> x
   650  (Sub16 (Add16 x y) x) -> y
   651  (Sub16 (Add16 x y) y) -> x
   652  (Sub8  (Add8  x y) x) -> y
   653  (Sub8  (Add8  x y) y) -> x
   654  
   655  // basic phi simplifications
   656  (Phi (Const8  [c]) (Const8  [c])) -> (Const8  [c])
   657  (Phi (Const16 [c]) (Const16 [c])) -> (Const16 [c])
   658  (Phi (Const32 [c]) (Const32 [c])) -> (Const32 [c])
   659  (Phi (Const64 [c]) (Const64 [c])) -> (Const64 [c])
   660  
   661  // user nil checks
   662  (NeqPtr p (ConstNil)) -> (IsNonNil p)
   663  (NeqPtr (ConstNil) p) -> (IsNonNil p)
   664  (EqPtr p (ConstNil)) -> (Not (IsNonNil p))
   665  (EqPtr (ConstNil) p) -> (Not (IsNonNil p))
   666  (IsNonNil (ConstNil)) -> (ConstBool [0])
   667  
   668  // slice and interface comparisons
   669  // The frontend ensures that we can only compare against nil,
   670  // so we need only compare the first word (interface type or slice ptr).
   671  (EqInter x y)  -> (EqPtr  (ITab x) (ITab y))
   672  (NeqInter x y) -> (NeqPtr (ITab x) (ITab y))
   673  (EqSlice x y)  -> (EqPtr  (SlicePtr x) (SlicePtr y))
   674  (NeqSlice x y) -> (NeqPtr (SlicePtr x) (SlicePtr y))
   675  
   676  // Load of store of same address, with compatibly typed value and same size
   677  (Load <t1> p1 (Store [w] p2 x _)) && isSamePtr(p1,p2) && t1.Compare(x.Type)==CMPeq && w == t1.Size() -> x
   678  
   679  // Collapse OffPtr
   680  (OffPtr (OffPtr p [b]) [a]) -> (OffPtr p [a+b])
   681  (OffPtr p [0]) && v.Type.Compare(p.Type) == CMPeq -> p
   682  
   683  // indexing operations
   684  // Note: bounds check has already been done
   685  (PtrIndex <t> ptr idx) && config.PtrSize == 4 -> (AddPtr ptr (Mul32 <config.fe.TypeInt()> idx (Const32 <config.fe.TypeInt()> [t.ElemType().Size()])))
   686  (PtrIndex <t> ptr idx) && config.PtrSize == 8 -> (AddPtr ptr (Mul64 <config.fe.TypeInt()> idx (Const64 <config.fe.TypeInt()> [t.ElemType().Size()])))
   687  
   688  // struct operations
   689  (StructSelect (StructMake1 x)) -> x
   690  (StructSelect [0] (StructMake2 x _)) -> x
   691  (StructSelect [1] (StructMake2 _ x)) -> x
   692  (StructSelect [0] (StructMake3 x _ _)) -> x
   693  (StructSelect [1] (StructMake3 _ x _)) -> x
   694  (StructSelect [2] (StructMake3 _ _ x)) -> x
   695  (StructSelect [0] (StructMake4 x _ _ _)) -> x
   696  (StructSelect [1] (StructMake4 _ x _ _)) -> x
   697  (StructSelect [2] (StructMake4 _ _ x _)) -> x
   698  (StructSelect [3] (StructMake4 _ _ _ x)) -> x
   699  
   700  (Load <t> _ _) && t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t) ->
   701    (StructMake0)
   702  (Load <t> ptr mem) && t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t) ->
   703    (StructMake1
   704      (Load <t.FieldType(0)> ptr mem))
   705  (Load <t> ptr mem) && t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t) ->
   706    (StructMake2
   707      (Load <t.FieldType(0)> ptr mem)
   708      (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem))
   709  (Load <t> ptr mem) && t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t) ->
   710    (StructMake3
   711      (Load <t.FieldType(0)> ptr mem)
   712      (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem)
   713      (Load <t.FieldType(2)> (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] ptr) mem))
   714  (Load <t> ptr mem) && t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t) ->
   715    (StructMake4
   716      (Load <t.FieldType(0)> ptr mem)
   717      (Load <t.FieldType(1)> (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] ptr) mem)
   718      (Load <t.FieldType(2)> (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] ptr) mem)
   719      (Load <t.FieldType(3)> (OffPtr <t.FieldType(3).PtrTo()> [t.FieldOff(3)] ptr) mem))
   720  
   721  (StructSelect [i] x:(Load <t> ptr mem)) && !config.fe.CanSSA(t) ->
   722    @x.Block (Load <v.Type> (OffPtr <v.Type.PtrTo()> [t.FieldOff(int(i))] ptr) mem)
   723  
   724  (Store _ (StructMake0) mem) -> mem
   725  (Store dst (StructMake1 <t> f0) mem) ->
   726    (Store [t.FieldType(0).Size()] dst f0 mem)
   727  (Store dst (StructMake2 <t> f0 f1) mem) ->
   728    (Store [t.FieldType(1).Size()]
   729      (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst)
   730      f1
   731      (Store [t.FieldType(0).Size()] dst f0 mem))
   732  (Store dst (StructMake3 <t> f0 f1 f2) mem) ->
   733    (Store [t.FieldType(2).Size()]
   734      (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] dst)
   735      f2
   736      (Store [t.FieldType(1).Size()]
   737        (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst)
   738        f1
   739        (Store [t.FieldType(0).Size()] dst f0 mem)))
   740  (Store dst (StructMake4 <t> f0 f1 f2 f3) mem) ->
   741    (Store [t.FieldType(3).Size()]
   742      (OffPtr <t.FieldType(3).PtrTo()> [t.FieldOff(3)] dst)
   743      f3
   744      (Store [t.FieldType(2).Size()]
   745        (OffPtr <t.FieldType(2).PtrTo()> [t.FieldOff(2)] dst)
   746        f2
   747        (Store [t.FieldType(1).Size()]
   748          (OffPtr <t.FieldType(1).PtrTo()> [t.FieldOff(1)] dst)
   749          f1
   750          (Store [t.FieldType(0).Size()] dst f0 mem))))
   751  
   752  // Putting struct{*byte} and similar into direct interfaces.
   753  (IMake typ (StructMake1 val)) -> (IMake typ val)
   754  (StructSelect [0] x:(IData _)) -> x
   755  
   756  // un-SSAable values use mem->mem copies
   757  (Store [size] dst (Load <t> src mem) mem) && !config.fe.CanSSA(t) ->
   758  	(Move [MakeSizeAndAlign(size, t.Alignment()).Int64()] dst src mem)
   759  (Store [size] dst (Load <t> src mem) (VarDef {x} mem)) && !config.fe.CanSSA(t) ->
   760  	(Move [MakeSizeAndAlign(size, t.Alignment()).Int64()] dst src (VarDef {x} mem))
   761  
   762  // array ops
   763  (ArraySelect (ArrayMake1 x)) -> x
   764  
   765  (Load <t> _ _) && t.IsArray() && t.NumElem() == 0 ->
   766    (ArrayMake0)
   767  
   768  (Load <t> ptr mem) && t.IsArray() && t.NumElem() == 1 && config.fe.CanSSA(t) ->
   769    (ArrayMake1 (Load <t.ElemType()> ptr mem))
   770  
   771  (Store _ (ArrayMake0) mem) -> mem
   772  (Store [size] dst (ArrayMake1 e) mem) -> (Store [size] dst e mem)
   773  
   774  (ArraySelect [0] (Load ptr mem)) -> (Load ptr mem)
   775  
   776  // Putting [1]{*byte} and similar into direct interfaces.
   777  (IMake typ (ArrayMake1 val)) -> (IMake typ val)
   778  (ArraySelect [0] x:(IData _)) -> x
   779  
   780  // string ops
   781  // Decomposing StringMake and lowering of StringPtr and StringLen
   782  // happens in a later pass, dec, so that these operations are available
   783  // to other passes for optimizations.
   784  (StringPtr (StringMake (Const64 <t> [c]) _)) -> (Const64 <t> [c])
   785  (StringLen (StringMake _ (Const64 <t> [c]))) -> (Const64 <t> [c])
   786  (ConstString {s}) && config.PtrSize == 4 && s.(string) == "" ->
   787    (StringMake (ConstNil) (Const32 <config.fe.TypeInt()> [0]))
   788  (ConstString {s}) && config.PtrSize == 8 && s.(string) == "" ->
   789    (StringMake (ConstNil) (Const64 <config.fe.TypeInt()> [0]))
   790  (ConstString {s}) && config.PtrSize == 4 && s.(string) != "" ->
   791    (StringMake
   792      (Addr <config.fe.TypeBytePtr()> {config.fe.StringData(s.(string))}
   793        (SB))
   794      (Const32 <config.fe.TypeInt()> [int64(len(s.(string)))]))
   795  (ConstString {s}) && config.PtrSize == 8 && s.(string) != "" ->
   796    (StringMake
   797      (Addr <config.fe.TypeBytePtr()> {config.fe.StringData(s.(string))}
   798        (SB))
   799      (Const64 <config.fe.TypeInt()> [int64(len(s.(string)))]))
   800  
   801  // slice ops
   802  // Only a few slice rules are provided here.  See dec.rules for
   803  // a more comprehensive set.
   804  (SliceLen (SliceMake _ (Const64 <t> [c]) _)) -> (Const64 <t> [c])
   805  (SliceCap (SliceMake _ _ (Const64 <t> [c]))) -> (Const64 <t> [c])
   806  (SliceLen (SliceMake _ (Const32 <t> [c]) _)) -> (Const32 <t> [c])
   807  (SliceCap (SliceMake _ _ (Const32 <t> [c]))) -> (Const32 <t> [c])
   808  (SlicePtr (SliceMake (SlicePtr x) _ _)) -> (SlicePtr x)
   809  (SliceLen (SliceMake _ (SliceLen x) _)) -> (SliceLen x)
   810  (SliceCap (SliceMake _ _ (SliceCap x))) -> (SliceCap x)
   811  (SliceCap (SliceMake _ _ (SliceLen x))) -> (SliceLen x)
   812  (ConstSlice) && config.PtrSize == 4 ->
   813    (SliceMake
   814      (ConstNil <v.Type.ElemType().PtrTo()>)
   815      (Const32 <config.fe.TypeInt()> [0])
   816      (Const32 <config.fe.TypeInt()> [0]))
   817  (ConstSlice) && config.PtrSize == 8 ->
   818    (SliceMake
   819      (ConstNil <v.Type.ElemType().PtrTo()>)
   820      (Const64 <config.fe.TypeInt()> [0])
   821      (Const64 <config.fe.TypeInt()> [0]))
   822  
   823  // interface ops
   824  (ConstInterface) ->
   825    (IMake
   826      (ConstNil <config.fe.TypeBytePtr()>)
   827      (ConstNil <config.fe.TypeBytePtr()>))
   828  
   829  (NilCheck (GetG mem) mem) -> mem
   830  
   831  (If (Not cond) yes no) -> (If cond no yes)
   832  (If (ConstBool [c]) yes no) && c == 1 -> (First nil yes no)
   833  (If (ConstBool [c]) yes no) && c == 0 -> (First nil no yes)
   834  
   835  // Get rid of Convert ops for pointer arithmetic on unsafe.Pointer.
   836  (Convert (Add64 (Convert ptr mem) off) mem) -> (Add64 ptr off)
   837  (Convert (Add64 off (Convert ptr mem)) mem) -> (Add64 ptr off)
   838  (Convert (Convert ptr mem) mem) -> ptr
   839  
   840  // Decompose compound argument values
   841  (Arg {n} [off]) && v.Type.IsString() ->
   842    (StringMake
   843      (Arg <config.fe.TypeBytePtr()> {n} [off])
   844      (Arg <config.fe.TypeInt()> {n} [off+config.PtrSize]))
   845  
   846  (Arg {n} [off]) && v.Type.IsSlice() ->
   847    (SliceMake
   848      (Arg <v.Type.ElemType().PtrTo()> {n} [off])
   849      (Arg <config.fe.TypeInt()> {n} [off+config.PtrSize])
   850      (Arg <config.fe.TypeInt()> {n} [off+2*config.PtrSize]))
   851  
   852  (Arg {n} [off]) && v.Type.IsInterface() ->
   853    (IMake
   854      (Arg <config.fe.TypeBytePtr()> {n} [off])
   855      (Arg <config.fe.TypeBytePtr()> {n} [off+config.PtrSize]))
   856  
   857  (Arg {n} [off]) && v.Type.IsComplex() && v.Type.Size() == 16 ->
   858    (ComplexMake
   859      (Arg <config.fe.TypeFloat64()> {n} [off])
   860      (Arg <config.fe.TypeFloat64()> {n} [off+8]))
   861  
   862  (Arg {n} [off]) && v.Type.IsComplex() && v.Type.Size() == 8 ->
   863    (ComplexMake
   864      (Arg <config.fe.TypeFloat32()> {n} [off])
   865      (Arg <config.fe.TypeFloat32()> {n} [off+4]))
   866  
   867  (Arg <t>) && t.IsStruct() && t.NumFields() == 0 && config.fe.CanSSA(t) ->
   868    (StructMake0)
   869  (Arg <t> {n} [off]) && t.IsStruct() && t.NumFields() == 1 && config.fe.CanSSA(t) ->
   870    (StructMake1
   871      (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)]))
   872  (Arg <t> {n} [off]) && t.IsStruct() && t.NumFields() == 2 && config.fe.CanSSA(t) ->
   873    (StructMake2
   874      (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)])
   875      (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)]))
   876  (Arg <t> {n} [off]) && t.IsStruct() && t.NumFields() == 3 && config.fe.CanSSA(t) ->
   877    (StructMake3
   878      (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)])
   879      (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)])
   880      (Arg <t.FieldType(2)> {n} [off+t.FieldOff(2)]))
   881  (Arg <t> {n} [off]) && t.IsStruct() && t.NumFields() == 4 && config.fe.CanSSA(t) ->
   882    (StructMake4
   883      (Arg <t.FieldType(0)> {n} [off+t.FieldOff(0)])
   884      (Arg <t.FieldType(1)> {n} [off+t.FieldOff(1)])
   885      (Arg <t.FieldType(2)> {n} [off+t.FieldOff(2)])
   886      (Arg <t.FieldType(3)> {n} [off+t.FieldOff(3)]))
   887  
   888  (Arg <t>) && t.IsArray() && t.NumElem() == 0 ->
   889    (ArrayMake0)
   890  (Arg <t> {n} [off]) && t.IsArray() && t.NumElem() == 1 && config.fe.CanSSA(t) ->
   891    (ArrayMake1 (Arg <t.ElemType()> {n} [off]))
   892  
   893  // strength reduction of divide by a constant.
   894  // Note: frontend does <=32 bits. We only need to do 64 bits here.
   895  // TODO: Do them all here?
   896  
   897  // Div/mod by 1.  Currently handled by frontend.
   898  //(Div64 n (Const64 [1])) -> n
   899  //(Div64u n (Const64 [1])) -> n
   900  //(Mod64 n (Const64 [1])) -> (Const64 [0])
   901  //(Mod64u n (Const64 [1])) -> (Const64 [0])
   902  
   903  // Unsigned divide by power of 2.
   904  (Div64u <t> n (Const64 [c])) && isPowerOfTwo(c) -> (Rsh64Ux64 n (Const64 <t> [log2(c)]))
   905  (Mod64u <t> n (Const64 [c])) && isPowerOfTwo(c) -> (And64 n (Const64 <t> [c-1]))
   906  
   907  // Signed divide by power of 2.  Currently handled by frontend.
   908  // n / c = n >> log(c)       if n >= 0
   909  //       = (n+c-1) >> log(c) if n < 0
   910  // We conditionally add c-1 by adding n>>63>>(64-log(c)) (first shift signed, second shift unsigned).
   911  //(Div64 <t> n (Const64 [c])) && isPowerOfTwo(c) ->
   912  //  (Rsh64x64
   913  //    (Add64 <t>
   914  //      n
   915  //      (Rsh64Ux64 <t>
   916  //        (Rsh64x64 <t> n (Const64 <t> [63]))
   917  //        (Const64 <t> [64-log2(c)])))
   918  //    (Const64 <t> [log2(c)]))
   919  
   920  // Unsigned divide, not a power of 2.  Strength reduce to a multiply.
   921  (Div64u <t> x (Const64 [c])) && umagic64ok(c) && !umagic64a(c) ->
   922    (Rsh64Ux64
   923      (Hmul64u <t>
   924        (Const64 <t> [umagic64m(c)])
   925        x)
   926      (Const64 <t> [umagic64s(c)]))
   927  (Div64u <t> x (Const64 [c])) && umagic64ok(c) && umagic64a(c) ->
   928    (Rsh64Ux64
   929      (Avg64u <t>
   930        (Hmul64u <t>
   931          x
   932          (Const64 <t> [umagic64m(c)]))
   933        x)
   934      (Const64 <t> [umagic64s(c)-1]))
   935  
   936  // Signed divide, not a power of 2.  Strength reduce to a multiply.
   937  (Div64 <t> x (Const64 [c])) && c > 0 && smagic64ok(c) && smagic64m(c) > 0 ->
   938    (Sub64 <t>
   939      (Rsh64x64 <t>
   940        (Hmul64 <t>
   941          (Const64 <t> [smagic64m(c)])
   942          x)
   943        (Const64 <t> [smagic64s(c)]))
   944      (Rsh64x64 <t>
   945        x
   946        (Const64 <t> [63])))
   947  (Div64 <t> x (Const64 [c])) && c > 0 && smagic64ok(c) && smagic64m(c) < 0 ->
   948    (Sub64 <t>
   949      (Rsh64x64 <t>
   950        (Add64 <t>
   951          (Hmul64 <t>
   952            (Const64 <t> [smagic64m(c)])
   953            x)
   954          x)
   955        (Const64 <t> [smagic64s(c)]))
   956      (Rsh64x64 <t>
   957        x
   958        (Const64 <t> [63])))
   959  (Div64 <t> x (Const64 [c])) && c < 0 && smagic64ok(c) && smagic64m(c) > 0 ->
   960    (Neg64 <t>
   961      (Sub64 <t>
   962        (Rsh64x64 <t>
   963          (Hmul64 <t>
   964            (Const64 <t> [smagic64m(c)])
   965            x)
   966          (Const64 <t> [smagic64s(c)]))
   967        (Rsh64x64 <t>
   968          x
   969          (Const64 <t> [63]))))
   970  (Div64 <t> x (Const64 [c])) && c < 0 && smagic64ok(c) && smagic64m(c) < 0 ->
   971    (Neg64 <t>
   972      (Sub64 <t>
   973        (Rsh64x64 <t>
   974          (Add64 <t>
   975            (Hmul64 <t>
   976              (Const64 <t> [smagic64m(c)])
   977              x)
   978            x)
   979          (Const64 <t> [smagic64s(c)]))
   980        (Rsh64x64 <t>
   981          x
   982          (Const64 <t> [63]))))
   983  
   984  // A%B = A-(A/B*B).
   985  // This implements % with two * and a bunch of ancillary ops.
   986  // One of the * is free if the user's code also computes A/B.
   987  (Mod64  <t> x (Const64 [c])) && x.Op != OpConst64 && smagic64ok(c)
   988    -> (Sub64 x (Mul64 <t> (Div64  <t> x (Const64 <t> [c])) (Const64 <t> [c])))
   989  (Mod64u <t> x (Const64 [c])) && x.Op != OpConst64 && umagic64ok(c)
   990    -> (Sub64 x (Mul64 <t> (Div64u <t> x (Const64 <t> [c])) (Const64 <t> [c])))
   991  
   992  // floating point optimizations
   993  (Add32F x (Const32F [0])) -> x
   994  (Add32F (Const32F [0]) x) -> x
   995  (Add64F x (Const64F [0])) -> x
   996  (Add64F (Const64F [0]) x) -> x
   997  (Sub32F x (Const32F [0])) -> x
   998  (Sub64F x (Const64F [0])) -> x
   999  (Mul32F x (Const32F [f2i(1)])) -> x
  1000  (Mul32F (Const32F [f2i(1)]) x) -> x
  1001  (Mul64F x (Const64F [f2i(1)])) -> x
  1002  (Mul64F (Const64F [f2i(1)]) x) -> x
  1003  (Mul32F x (Const32F [f2i(-1)])) -> (Neg32F x)
  1004  (Mul32F (Const32F [f2i(-1)]) x) -> (Neg32F x)
  1005  (Mul64F x (Const64F [f2i(-1)])) -> (Neg64F x)
  1006  (Mul64F (Const64F [f2i(-1)]) x) -> (Neg64F x)
  1007  (Div32F x (Const32F [f2i(1)])) -> x
  1008  (Div64F x (Const64F [f2i(1)])) -> x
  1009  (Div32F x (Const32F [f2i(-1)])) -> (Neg32F x)
  1010  (Div64F x (Const64F [f2i(-1)])) -> (Neg32F x)
  1011  
  1012  (Sqrt (Const64F [c])) -> (Const64F [f2i(math.Sqrt(i2f(c)))])
  1013  
  1014  // recognize runtime.newobject and don't Zero/Nilcheck it
  1015  (Zero (Load (OffPtr [c] (SP)) mem) mem)
  1016          && mem.Op == OpStaticCall
  1017  	&& isSameSym(mem.Aux, "runtime.newobject")
  1018  	&& c == config.ctxt.FixedFrameSize() + config.PtrSize // offset of return value
  1019  	-> mem
  1020  // nil checks just need to rewrite to something useless.
  1021  // they will be deadcode eliminated soon afterwards.
  1022  (NilCheck (Load (OffPtr [c] (SP)) mem) mem)
  1023  	&& mem.Op == OpStaticCall
  1024  	&& isSameSym(mem.Aux, "runtime.newobject")
  1025  	&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
  1026  	&& warnRule(config.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check")
  1027  	-> (Invalid)
  1028  (NilCheck (OffPtr (Load (OffPtr [c] (SP)) mem)) mem)
  1029  	&& mem.Op == OpStaticCall
  1030  	&& isSameSym(mem.Aux, "runtime.newobject")
  1031  	&& c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value
  1032  	&& warnRule(config.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check")
  1033  	-> (Invalid)