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

     1  // Copyright 2016 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  // Lowering arithmetic
     6  (Add64  x y) -> (ADD  x y)
     7  (AddPtr x y) -> (ADD  x y)
     8  (Add32  x y) -> (ADDW  x y)
     9  (Add16  x y) -> (ADDW  x y)
    10  (Add8   x y) -> (ADDW  x y)
    11  (Add32F x y) -> (FADDS x y)
    12  (Add64F x y) -> (FADD x y)
    13  
    14  (Sub64  x y) -> (SUB  x y)
    15  (SubPtr x y) -> (SUB  x y)
    16  (Sub32  x y) -> (SUBW  x y)
    17  (Sub16  x y) -> (SUBW  x y)
    18  (Sub8   x y) -> (SUBW  x y)
    19  (Sub32F x y) -> (FSUBS x y)
    20  (Sub64F x y) -> (FSUB x y)
    21  
    22  (Mul64  x y) -> (MULLD  x y)
    23  (Mul32  x y) -> (MULLW  x y)
    24  (Mul16  x y) -> (MULLW  x y)
    25  (Mul8   x y) -> (MULLW  x y)
    26  (Mul32F x y) -> (FMULS x y)
    27  (Mul64F x y) -> (FMUL x y)
    28  
    29  (Div32F x y) -> (FDIVS x y)
    30  (Div64F x y) -> (FDIV x y)
    31  
    32  (Div64  x y) -> (DIVD  x y)
    33  (Div64u x y) -> (DIVDU x y)
    34  // DIVW/DIVWU has a 64-bit dividend and a 32-bit divisor,
    35  // so a sign/zero extension of the dividend is required.
    36  (Div32  x y) -> (DIVW  (MOVWreg x) y)
    37  (Div32u x y) -> (DIVWU (MOVWZreg x) y)
    38  (Div16  x y) -> (DIVW  (MOVHreg x) (MOVHreg y))
    39  (Div16u x y) -> (DIVWU (MOVHZreg x) (MOVHZreg y))
    40  (Div8   x y) -> (DIVW  (MOVBreg x) (MOVBreg y))
    41  (Div8u  x y) -> (DIVWU (MOVBZreg x) (MOVBZreg y))
    42  
    43  (Hmul64  x y) -> (MULHD  x y)
    44  (Hmul64u x y) -> (MULHDU x y)
    45  (Hmul32  x y) -> (SRDconst [32] (MULLD (MOVWreg x) (MOVWreg y)))
    46  (Hmul32u x y) -> (SRDconst [32] (MULLD (MOVWZreg x) (MOVWZreg y)))
    47  (Hmul16  x y) -> (SRDconst [16] (MULLW (MOVHreg x) (MOVHreg y)))
    48  (Hmul16u x y) -> (SRDconst [16] (MULLW (MOVHZreg x) (MOVHZreg y)))
    49  (Hmul8   x y) -> (SRDconst [8] (MULLW (MOVBreg x) (MOVBreg y)))
    50  (Hmul8u  x y) -> (SRDconst [8] (MULLW (MOVBZreg x) (MOVBZreg y)))
    51  
    52  (Mod64  x y) -> (MODD  x y)
    53  (Mod64u x y) -> (MODDU x y)
    54  // MODW/MODWU has a 64-bit dividend and a 32-bit divisor,
    55  // so a sign/zero extension of the dividend is required.
    56  (Mod32  x y) -> (MODW  (MOVWreg x) y)
    57  (Mod32u x y) -> (MODWU (MOVWZreg x) y)
    58  (Mod16  x y) -> (MODW  (MOVHreg x) (MOVHreg y))
    59  (Mod16u x y) -> (MODWU (MOVHZreg x) (MOVHZreg y))
    60  (Mod8   x y) -> (MODW  (MOVBreg x) (MOVBreg y))
    61  (Mod8u  x y) -> (MODWU (MOVBZreg x) (MOVBZreg y))
    62  
    63  (Avg64u <t> x y) -> (ADD (ADD <t> (SRDconst <t> x [1]) (SRDconst <t> y [1])) (ANDconst <t> (AND <t> x y) [1]))
    64  
    65  (And64 x y) -> (AND x y)
    66  (And32 x y) -> (ANDW x y)
    67  (And16 x y) -> (ANDW x y)
    68  (And8  x y) -> (ANDW x y)
    69  
    70  (Or64 x y) -> (OR x y)
    71  (Or32 x y) -> (ORW x y)
    72  (Or16 x y) -> (ORW x y)
    73  (Or8  x y) -> (ORW x y)
    74  
    75  (Xor64 x y) -> (XOR x y)
    76  (Xor32 x y) -> (XORW x y)
    77  (Xor16 x y) -> (XORW x y)
    78  (Xor8  x y) -> (XORW x y)
    79  
    80  (Neg64  x) -> (NEG x)
    81  (Neg32  x) -> (NEGW x)
    82  (Neg16  x) -> (NEGW (MOVHreg x))
    83  (Neg8   x) -> (NEGW (MOVBreg x))
    84  (Neg32F x) -> (FNEGS x)
    85  (Neg64F x) -> (FNEG x)
    86  
    87  (Com64 x) -> (NOT x)
    88  (Com32 x) -> (NOTW x)
    89  (Com16 x) -> (NOTW x)
    90  (Com8  x) -> (NOTW x)
    91  (NOT x) && true -> (XOR (MOVDconst [-1]) x)
    92  (NOTW x) && true -> (XORWconst [-1] x)
    93  
    94  // Lowering boolean ops
    95  (AndB x y) -> (ANDW x y)
    96  (OrB x y) -> (ORW x y)
    97  (Not x) -> (XORWconst [1] x)
    98  
    99  // Lowering pointer arithmetic
   100  (OffPtr [off] ptr:(SP)) -> (MOVDaddr [off] ptr)
   101  (OffPtr [off] ptr) && is32Bit(off) -> (ADDconst [off] ptr)
   102  (OffPtr [off] ptr) -> (ADD (MOVDconst [off]) ptr)
   103  
   104  // Ctz(x) = 64 - findLeftmostOne((x-1)&^x)
   105  (Ctz64 <t> x) -> (SUB (MOVDconst [64]) (FLOGR (AND <t> (SUBconst <t> [1] x) (NOT <t> x))))
   106  (Ctz32 <t> x) -> (SUB (MOVDconst [64]) (FLOGR (MOVWZreg (ANDW <t> (SUBWconst <t> [1] x) (NOTW <t> x)))))
   107  
   108  (Bswap64 x) -> (MOVDBR x)
   109  (Bswap32 x) -> (MOVWBR x)
   110  
   111  (Sqrt x) -> (FSQRT x)
   112  
   113  // Atomic loads.
   114  (AtomicLoad32 ptr mem) -> (MOVWZatomicload ptr mem)
   115  (AtomicLoad64 ptr mem) -> (MOVDatomicload ptr mem)
   116  (AtomicLoadPtr ptr mem) -> (MOVDatomicload ptr mem)
   117  
   118  // Atomic stores.
   119  (AtomicStore32 ptr val mem) -> (MOVWatomicstore ptr val mem)
   120  (AtomicStore64 ptr val mem) -> (MOVDatomicstore ptr val mem)
   121  (AtomicStorePtrNoWB ptr val mem) -> (MOVDatomicstore ptr val mem)
   122  
   123  // Atomic adds.
   124  (AtomicAdd32 ptr val mem) -> (AddTupleFirst32 (LAA ptr val mem) val)
   125  (AtomicAdd64 ptr val mem) -> (AddTupleFirst64 (LAAG ptr val mem) val)
   126  (Select0 <t> (AddTupleFirst32 tuple val)) -> (ADDW val (Select0 <t> tuple))
   127  (Select1     (AddTupleFirst32 tuple _  )) -> (Select1 tuple)
   128  (Select0 <t> (AddTupleFirst64 tuple val)) -> (ADD val (Select0 <t> tuple))
   129  (Select1     (AddTupleFirst64 tuple _  )) -> (Select1 tuple)
   130  
   131  // Atomic exchanges.
   132  (AtomicExchange32 ptr val mem) -> (LoweredAtomicExchange32 ptr val mem)
   133  (AtomicExchange64 ptr val mem) -> (LoweredAtomicExchange64 ptr val mem)
   134  
   135  // Atomic compare and swap.
   136  (AtomicCompareAndSwap32 ptr old new_ mem) -> (LoweredAtomicCas32 ptr old new_ mem)
   137  (AtomicCompareAndSwap64 ptr old new_ mem) -> (LoweredAtomicCas64 ptr old new_ mem)
   138  
   139  // Lowering extension
   140  // Note: we always extend to 64 bits even though some ops don't need that many result bits.
   141  (SignExt8to16  x) -> (MOVBreg x)
   142  (SignExt8to32  x) -> (MOVBreg x)
   143  (SignExt8to64  x) -> (MOVBreg x)
   144  (SignExt16to32 x) -> (MOVHreg x)
   145  (SignExt16to64 x) -> (MOVHreg x)
   146  (SignExt32to64 x) -> (MOVWreg x)
   147  
   148  (ZeroExt8to16  x) -> (MOVBZreg x)
   149  (ZeroExt8to32  x) -> (MOVBZreg x)
   150  (ZeroExt8to64  x) -> (MOVBZreg x)
   151  (ZeroExt16to32 x) -> (MOVHZreg x)
   152  (ZeroExt16to64 x) -> (MOVHZreg x)
   153  (ZeroExt32to64 x) -> (MOVWZreg x)
   154  
   155  (Slicemask <t> x) -> (SRADconst (NEG <t> x) [63])
   156  
   157  // Lowering truncation
   158  // Because we ignore high parts of registers, truncates are just copies.
   159  (Trunc16to8  x) -> x
   160  (Trunc32to8  x) -> x
   161  (Trunc32to16 x) -> x
   162  (Trunc64to8  x) -> x
   163  (Trunc64to16 x) -> x
   164  (Trunc64to32 x) -> x
   165  
   166  // Lowering float <-> int
   167  (Cvt32to32F x) -> (CEFBRA x)
   168  (Cvt32to64F x) -> (CDFBRA x)
   169  (Cvt64to32F x) -> (CEGBRA x)
   170  (Cvt64to64F x) -> (CDGBRA x)
   171  
   172  (Cvt32Fto32 x) -> (CFEBRA x)
   173  (Cvt32Fto64 x) -> (CGEBRA x)
   174  (Cvt64Fto32 x) -> (CFDBRA x)
   175  (Cvt64Fto64 x) -> (CGDBRA x)
   176  
   177  (Cvt32Fto64F x) -> (LDEBR x)
   178  (Cvt64Fto32F x) -> (LEDBR x)
   179  
   180  // Lowering shifts
   181  // Unsigned shifts need to return 0 if shift amount is >= width of shifted value.
   182  //   result = (arg << shift) & (shift >= argbits ? 0 : 0xffffffffffffffff)
   183  (Lsh64x64 <t> x y) -> (AND (SLD <t> x y) (SUBEcarrymask <t> (CMPUconst y [63])))
   184  (Lsh64x32 <t> x y) -> (AND (SLD <t> x y) (SUBEcarrymask <t> (CMPWUconst y [63])))
   185  (Lsh64x16 <t> x y) -> (AND (SLD <t> x y) (SUBEcarrymask <t> (CMPWUconst (MOVHZreg y) [63])))
   186  (Lsh64x8  <t> x y) -> (AND (SLD <t> x y) (SUBEcarrymask <t> (CMPWUconst (MOVBZreg y) [63])))
   187  
   188  (Lsh32x64 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPUconst y [31])))
   189  (Lsh32x32 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst y [31])))
   190  (Lsh32x16 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [31])))
   191  (Lsh32x8  <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [31])))
   192  
   193  (Lsh16x64 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPUconst y [31])))
   194  (Lsh16x32 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst y [31])))
   195  (Lsh16x16 <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [31])))
   196  (Lsh16x8  <t> x y) -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [31])))
   197  
   198  (Lsh8x64 <t> x y)  -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPUconst y [31])))
   199  (Lsh8x32 <t> x y)  -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst y [31])))
   200  (Lsh8x16 <t> x y)  -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [31])))
   201  (Lsh8x8  <t> x y)  -> (ANDW (SLW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [31])))
   202  
   203  (Rsh64Ux64 <t> x y) -> (AND (SRD <t> x y) (SUBEcarrymask <t> (CMPUconst y [63])))
   204  (Rsh64Ux32 <t> x y) -> (AND (SRD <t> x y) (SUBEcarrymask <t> (CMPWUconst y [63])))
   205  (Rsh64Ux16 <t> x y) -> (AND (SRD <t> x y) (SUBEcarrymask <t> (CMPWUconst (MOVHZreg y) [63])))
   206  (Rsh64Ux8  <t> x y) -> (AND (SRD <t> x y) (SUBEcarrymask <t> (CMPWUconst (MOVBZreg y) [63])))
   207  
   208  (Rsh32Ux64 <t> x y) -> (ANDW (SRW <t> x y) (SUBEWcarrymask <t> (CMPUconst y [31])))
   209  (Rsh32Ux32 <t> x y) -> (ANDW (SRW <t> x y) (SUBEWcarrymask <t> (CMPWUconst y [31])))
   210  (Rsh32Ux16 <t> x y) -> (ANDW (SRW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [31])))
   211  (Rsh32Ux8  <t> x y) -> (ANDW (SRW <t> x y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [31])))
   212  
   213  (Rsh16Ux64 <t> x y) -> (ANDW (SRW <t> (MOVHZreg x) y) (SUBEWcarrymask <t> (CMPUconst y [15])))
   214  (Rsh16Ux32 <t> x y) -> (ANDW (SRW <t> (MOVHZreg x) y) (SUBEWcarrymask <t> (CMPWUconst y [15])))
   215  (Rsh16Ux16 <t> x y) -> (ANDW (SRW <t> (MOVHZreg x) y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [15])))
   216  (Rsh16Ux8  <t> x y) -> (ANDW (SRW <t> (MOVHZreg x) y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [15])))
   217  
   218  (Rsh8Ux64 <t> x y)  -> (ANDW (SRW <t> (MOVBZreg x) y) (SUBEWcarrymask <t> (CMPUconst y [7])))
   219  (Rsh8Ux32 <t> x y)  -> (ANDW (SRW <t> (MOVBZreg x) y) (SUBEWcarrymask <t> (CMPWUconst y [7])))
   220  (Rsh8Ux16 <t> x y)  -> (ANDW (SRW <t> (MOVBZreg x) y) (SUBEWcarrymask <t> (CMPWUconst (MOVHZreg y) [7])))
   221  (Rsh8Ux8  <t> x y)  -> (ANDW (SRW <t> (MOVBZreg x) y) (SUBEWcarrymask <t> (CMPWUconst (MOVBZreg y) [7])))
   222  
   223  // Signed right shift needs to return 0/-1 if shift amount is >= width of shifted value.
   224  // We implement this by setting the shift value to -1 (all ones) if the shift value is >= width.
   225  (Rsh64x64 <t> x y) -> (SRAD <t> x (OR <y.Type> y (NOT <y.Type> (SUBEcarrymask <y.Type> (CMPUconst y [63])))))
   226  (Rsh64x32 <t> x y) -> (SRAD <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst y [63])))))
   227  (Rsh64x16 <t> x y) -> (SRAD <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVHZreg y) [63])))))
   228  (Rsh64x8  <t> x y) -> (SRAD <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVBZreg y) [63])))))
   229  
   230  (Rsh32x64 <t> x y) -> (SRAW <t> x (OR <y.Type> y (NOT <y.Type> (SUBEcarrymask <y.Type> (CMPUconst y [31])))))
   231  (Rsh32x32 <t> x y) -> (SRAW <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst y [31])))))
   232  (Rsh32x16 <t> x y) -> (SRAW <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVHZreg y) [31])))))
   233  (Rsh32x8  <t> x y) -> (SRAW <t> x (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVBZreg y) [31])))))
   234  
   235  (Rsh16x64 <t> x y) -> (SRAW <t> (MOVHreg x) (OR <y.Type> y (NOT <y.Type> (SUBEcarrymask <y.Type> (CMPUconst y [15])))))
   236  (Rsh16x32 <t> x y) -> (SRAW <t> (MOVHreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst y [15])))))
   237  (Rsh16x16 <t> x y) -> (SRAW <t> (MOVHreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVHZreg y) [15])))))
   238  (Rsh16x8  <t> x y) -> (SRAW <t> (MOVHreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVBZreg y) [15])))))
   239  
   240  (Rsh8x64 <t> x y)  -> (SRAW <t> (MOVBreg x) (OR <y.Type> y (NOT <y.Type> (SUBEcarrymask <y.Type> (CMPUconst y [7])))))
   241  (Rsh8x32 <t> x y)  -> (SRAW <t> (MOVBreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst y [7])))))
   242  (Rsh8x16 <t> x y)  -> (SRAW <t> (MOVBreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVHZreg y) [7])))))
   243  (Rsh8x8  <t> x y)  -> (SRAW <t> (MOVBreg x) (ORW <y.Type> y (NOTW <y.Type> (SUBEWcarrymask <y.Type> (CMPWUconst (MOVBZreg y) [7])))))
   244  
   245  // Lowering comparisons
   246  (Less64  x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   247  (Less32  x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   248  (Less16  x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   249  (Less8   x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   250  (Less64U x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPU x y))
   251  (Less32U x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPWU x y))
   252  (Less16U x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVHZreg x) (MOVHZreg y)))
   253  (Less8U  x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVBZreg x) (MOVBZreg y)))
   254  // Use SETG with reversed operands to dodge NaN case.
   255  (Less64F x y) -> (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMP y x))
   256  (Less32F x y) -> (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMPS y x))
   257  
   258  (Leq64  x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   259  (Leq32  x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   260  (Leq16  x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   261  (Leq8   x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   262  (Leq64U x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPU x y))
   263  (Leq32U x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPWU x y))
   264  (Leq16U x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVHZreg x) (MOVHZreg y)))
   265  (Leq8U  x y) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVBZreg x) (MOVBZreg y)))
   266  // Use SETGE with reversed operands to dodge NaN case.
   267  (Leq64F x y) -> (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMP y x))
   268  (Leq32F x y) -> (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMPS y x))
   269  
   270  (Greater64  x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   271  (Greater32  x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   272  (Greater16  x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   273  (Greater8   x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   274  (Greater64U x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMPU x y))
   275  (Greater32U x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMPWU x y))
   276  (Greater16U x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVHZreg x) (MOVHZreg y)))
   277  (Greater8U  x y) -> (MOVDGT (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVBZreg x) (MOVBZreg y)))
   278  (Greater64F x y) -> (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMP x y))
   279  (Greater32F x y) -> (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMPS x y))
   280  
   281  (Geq64  x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   282  (Geq32  x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   283  (Geq16  x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   284  (Geq8   x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   285  (Geq64U x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMPU x y))
   286  (Geq32U x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMPWU x y))
   287  (Geq16U x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVHZreg x) (MOVHZreg y)))
   288  (Geq8U  x y) -> (MOVDGE (MOVDconst [0]) (MOVDconst [1]) (CMPU (MOVBZreg x) (MOVBZreg y)))
   289  (Geq64F x y) -> (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMP x y))
   290  (Geq32F x y) -> (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) (FCMPS x y))
   291  
   292  (Eq64  x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   293  (Eq32  x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   294  (Eq16  x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   295  (Eq8   x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   296  (EqB   x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   297  (EqPtr x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   298  (Eq64F x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (FCMP x y))
   299  (Eq32F x y) -> (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) (FCMPS x y))
   300  
   301  (Neq64  x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   302  (Neq32  x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMPW x y))
   303  (Neq16  x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVHreg x) (MOVHreg y)))
   304  (Neq8   x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   305  (NeqB   x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMP (MOVBreg x) (MOVBreg y)))
   306  (NeqPtr x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMP x y))
   307  (Neq64F x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (FCMP x y))
   308  (Neq32F x y) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (FCMPS x y))
   309  
   310  // Lowering loads
   311  (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) -> (MOVDload ptr mem)
   312  (Load <t> ptr mem) && is32BitInt(t) && isSigned(t) -> (MOVWload ptr mem)
   313  (Load <t> ptr mem) && is32BitInt(t) && !isSigned(t) -> (MOVWZload ptr mem)
   314  (Load <t> ptr mem) && is16BitInt(t) && isSigned(t) -> (MOVHload ptr mem)
   315  (Load <t> ptr mem) && is16BitInt(t) && !isSigned(t) -> (MOVHZload ptr mem)
   316  (Load <t> ptr mem) && is8BitInt(t) && isSigned(t) -> (MOVBload ptr mem)
   317  (Load <t> ptr mem) && (t.IsBoolean() || (is8BitInt(t) && !isSigned(t))) -> (MOVBZload ptr mem)
   318  (Load <t> ptr mem) && is32BitFloat(t) -> (FMOVSload ptr mem)
   319  (Load <t> ptr mem) && is64BitFloat(t) -> (FMOVDload ptr mem)
   320  
   321  // Lowering stores
   322  // These more-specific FP versions of Store pattern should come first.
   323  (Store [8] ptr val mem) && is64BitFloat(val.Type) -> (FMOVDstore ptr val mem)
   324  (Store [4] ptr val mem) && is32BitFloat(val.Type) -> (FMOVSstore ptr val mem)
   325  
   326  (Store [8] ptr val mem) -> (MOVDstore ptr val mem)
   327  (Store [4] ptr val mem) -> (MOVWstore ptr val mem)
   328  (Store [2] ptr val mem) -> (MOVHstore ptr val mem)
   329  (Store [1] ptr val mem) -> (MOVBstore ptr val mem)
   330  
   331  // Lowering moves
   332  
   333  // Load and store for small copies.
   334  (Move [s] _ _ mem) && SizeAndAlign(s).Size() == 0 -> mem
   335  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstore dst (MOVBZload src mem) mem)
   336  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 2 -> (MOVHstore dst (MOVHZload src mem) mem)
   337  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 4 -> (MOVWstore dst (MOVWZload src mem) mem)
   338  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 8 -> (MOVDstore dst (MOVDload src mem) mem)
   339  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 16 ->
   340  	(MOVDstore [8] dst (MOVDload [8] src mem)
   341  		(MOVDstore dst (MOVDload src mem) mem))
   342  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 24 ->
   343          (MOVDstore [16] dst (MOVDload [16] src mem)
   344  	        (MOVDstore [8] dst (MOVDload [8] src mem)
   345                  (MOVDstore dst (MOVDload src mem) mem)))
   346  (Move [s] dst src mem)  && SizeAndAlign(s).Size() == 3 ->
   347  	(MOVBstore [2] dst (MOVBZload [2] src mem)
   348  		(MOVHstore dst (MOVHZload src mem) mem))
   349  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 5 ->
   350  	(MOVBstore [4] dst (MOVBZload [4] src mem)
   351  		(MOVWstore dst (MOVWZload src mem) mem))
   352  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 6 ->
   353  	(MOVHstore [4] dst (MOVHZload [4] src mem)
   354  		(MOVWstore dst (MOVWZload src mem) mem))
   355  (Move [s] dst src mem) && SizeAndAlign(s).Size() == 7 ->
   356  	(MOVBstore [6] dst (MOVBZload [6] src mem)
   357  		(MOVHstore [4] dst (MOVHZload [4] src mem)
   358  			(MOVWstore dst (MOVWZload src mem) mem)))
   359  
   360  // MVC for other moves. Use up to 4 instructions (sizes up to 1024 bytes).
   361  (Move [s] dst src mem) && SizeAndAlign(s).Size() > 0 && SizeAndAlign(s).Size() <= 256 ->
   362  	(MVC [makeValAndOff(SizeAndAlign(s).Size(), 0)] dst src mem)
   363  (Move [s] dst src mem) && SizeAndAlign(s).Size() > 256 && SizeAndAlign(s).Size() <= 512 ->
   364  	(MVC [makeValAndOff(SizeAndAlign(s).Size()-256, 256)] dst src (MVC [makeValAndOff(256, 0)] dst src mem))
   365  (Move [s] dst src mem) && SizeAndAlign(s).Size() > 512 && SizeAndAlign(s).Size() <= 768 ->
   366  	(MVC [makeValAndOff(SizeAndAlign(s).Size()-512, 512)] dst src (MVC [makeValAndOff(256, 256)] dst src (MVC [makeValAndOff(256, 0)] dst src mem)))
   367  (Move [s] dst src mem) && SizeAndAlign(s).Size() > 768 && SizeAndAlign(s).Size() <= 1024 ->
   368  	(MVC [makeValAndOff(SizeAndAlign(s).Size()-768, 768)] dst src (MVC [makeValAndOff(256, 512)] dst src (MVC [makeValAndOff(256, 256)] dst src (MVC [makeValAndOff(256, 0)] dst src mem))))
   369  
   370  // Move more than 1024 bytes using a loop.
   371  (Move [s] dst src mem) && SizeAndAlign(s).Size() > 1024 ->
   372  	(LoweredMove [SizeAndAlign(s).Size()%256] dst src (ADDconst <src.Type> src [(SizeAndAlign(s).Size()/256)*256]) mem)
   373  
   374  // Lowering Zero instructions
   375  (Zero [s] _ mem) && SizeAndAlign(s).Size() == 0 -> mem
   376  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 1 -> (MOVBstoreconst [0] destptr mem)
   377  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 2 -> (MOVHstoreconst [0] destptr mem)
   378  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 4 -> (MOVWstoreconst [0] destptr mem)
   379  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 8 -> (MOVDstoreconst [0] destptr mem)
   380  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 3 ->
   381  	(MOVBstoreconst [makeValAndOff(0,2)] destptr
   382  		(MOVHstoreconst [0] destptr mem))
   383  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 5 ->
   384  	(MOVBstoreconst [makeValAndOff(0,4)] destptr
   385  		(MOVWstoreconst [0] destptr mem))
   386  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 6 ->
   387  	(MOVHstoreconst [makeValAndOff(0,4)] destptr
   388  		(MOVWstoreconst [0] destptr mem))
   389  (Zero [s] destptr mem) && SizeAndAlign(s).Size() == 7 ->
   390  	(MOVWstoreconst [makeValAndOff(0,3)] destptr
   391  		(MOVWstoreconst [0] destptr mem))
   392  
   393  (Zero [s] destptr mem) && SizeAndAlign(s).Size() > 0 && SizeAndAlign(s).Size() <= 1024 ->
   394  	(CLEAR [makeValAndOff(SizeAndAlign(s).Size(), 0)] destptr mem)
   395  
   396  // Move more than 1024 bytes using a loop.
   397  (Zero [s] destptr mem) && SizeAndAlign(s).Size() > 1024 ->
   398  	(LoweredZero [SizeAndAlign(s).Size()%256] destptr (ADDconst <destptr.Type> destptr [(SizeAndAlign(s).Size()/256)*256]) mem)
   399  
   400  // Lowering constants
   401  (Const8   [val]) -> (MOVDconst [val])
   402  (Const16  [val]) -> (MOVDconst [val])
   403  (Const32  [val]) -> (MOVDconst [val])
   404  (Const64  [val]) -> (MOVDconst [val])
   405  (Const32F [val]) -> (FMOVSconst [val])
   406  (Const64F [val]) -> (FMOVDconst [val])
   407  (ConstNil) -> (MOVDconst [0])
   408  (ConstBool [b]) -> (MOVDconst [b])
   409  
   410  // Lowering calls
   411  (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem)
   412  (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem)
   413  (DeferCall [argwid] mem) -> (CALLdefer [argwid] mem)
   414  (GoCall [argwid] mem) -> (CALLgo [argwid] mem)
   415  (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem)
   416  
   417  // Miscellaneous
   418  (Convert <t> x mem) -> (MOVDconvert <t> x mem)
   419  (IsNonNil p) -> (MOVDNE (MOVDconst [0]) (MOVDconst [1]) (CMPconst p [0]))
   420  (IsInBounds idx len) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPU idx len))
   421  (IsSliceInBounds idx len) -> (MOVDLE (MOVDconst [0]) (MOVDconst [1]) (CMPU idx len))
   422  (NilCheck ptr mem) -> (LoweredNilCheck ptr mem)
   423  (GetG mem) -> (LoweredGetG mem)
   424  (GetClosurePtr) -> (LoweredGetClosurePtr)
   425  (Addr {sym} base) -> (MOVDaddr {sym} base)
   426  (ITab (Load ptr mem)) -> (MOVDload ptr mem)
   427  
   428  // block rewrites
   429  (If (MOVDLT (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (LT cmp yes no)
   430  (If (MOVDLE (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (LE cmp yes no)
   431  (If (MOVDGT (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (GT cmp yes no)
   432  (If (MOVDGE (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (GE cmp yes no)
   433  (If (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (EQ cmp yes no)
   434  (If (MOVDNE (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (NE cmp yes no)
   435  
   436  // Special case for floating point - LF/LEF not generated.
   437  (If (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (GTF cmp yes no)
   438  (If (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) cmp) yes no) -> (GEF cmp yes no)
   439  
   440  (If cond yes no) -> (NE (CMPWconst [0] (MOVBZreg cond)) yes no)
   441  
   442  // ***************************
   443  // Above: lowering rules
   444  // Below: optimizations
   445  // ***************************
   446  // TODO: Should the optimizations be a separate pass?
   447  
   448  // if a register move has only 1 use, just use the same register without emitting instruction
   449  // MOVDnop doesn't emit instruction, only for ensuring the type.
   450  (MOVDreg x) && x.Uses == 1 -> (MOVDnop x)
   451  
   452  // Fold sign extensions into conditional moves of constants.
   453  // Designed to remove the MOVBZreg inserted by the If lowering.
   454  (MOVBZreg x:(MOVDLT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   455  (MOVBZreg x:(MOVDLE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   456  (MOVBZreg x:(MOVDGT (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   457  (MOVBZreg x:(MOVDGE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   458  (MOVBZreg x:(MOVDEQ (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   459  (MOVBZreg x:(MOVDNE (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   460  (MOVBZreg x:(MOVDGTnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   461  (MOVBZreg x:(MOVDGEnoinv (MOVDconst [c]) (MOVDconst [d]) _)) && int64(uint8(c)) == c && int64(uint8(d)) == d -> (MOVDreg x)
   462  
   463  // Fold boolean tests into blocks.
   464  (NE (CMPWconst [0] (MOVDLT (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (LT cmp yes no)
   465  (NE (CMPWconst [0] (MOVDLE (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (LE cmp yes no)
   466  (NE (CMPWconst [0] (MOVDGT (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (GT cmp yes no)
   467  (NE (CMPWconst [0] (MOVDGE (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (GE cmp yes no)
   468  (NE (CMPWconst [0] (MOVDEQ (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (EQ cmp yes no)
   469  (NE (CMPWconst [0] (MOVDNE (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (NE cmp yes no)
   470  (NE (CMPWconst [0] (MOVDGTnoinv (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (GTF cmp yes no)
   471  (NE (CMPWconst [0] (MOVDGEnoinv (MOVDconst [0]) (MOVDconst [1]) cmp)) yes no) -> (GEF cmp yes no)
   472  
   473  // Fold constants into instructions.
   474  (ADD x (MOVDconst [c])) && is32Bit(c) -> (ADDconst [c] x)
   475  (ADD (MOVDconst [c]) x) && is32Bit(c) -> (ADDconst [c] x)
   476  (ADDW x (MOVDconst [c])) -> (ADDWconst [c] x)
   477  (ADDW (MOVDconst [c]) x) -> (ADDWconst [c] x)
   478  
   479  (SUB x (MOVDconst [c])) && is32Bit(c) -> (SUBconst x [c])
   480  (SUB (MOVDconst [c]) x) && is32Bit(c) -> (NEG (SUBconst <v.Type> x [c]))
   481  (SUBW x (MOVDconst [c])) -> (SUBWconst x [c])
   482  (SUBW (MOVDconst [c]) x) -> (NEGW (SUBWconst <v.Type> x [c]))
   483  
   484  (MULLD x (MOVDconst [c])) && is32Bit(c) -> (MULLDconst [c] x)
   485  (MULLD (MOVDconst [c]) x) && is32Bit(c) -> (MULLDconst [c] x)
   486  (MULLW x (MOVDconst [c])) -> (MULLWconst [c] x)
   487  (MULLW (MOVDconst [c]) x) -> (MULLWconst [c] x)
   488  
   489  // NILF instructions leave the high 32 bits unchanged which is
   490  // equivalent to the leftmost 32 bits being set.
   491  // TODO(mundaym): modify the assembler to accept 64-bit values
   492  // and use isU32Bit(^c).
   493  (AND x (MOVDconst [c])) && is32Bit(c) && c < 0 -> (ANDconst [c] x)
   494  (AND (MOVDconst [c]) x) && is32Bit(c) && c < 0 -> (ANDconst [c] x)
   495  (ANDW x (MOVDconst [c])) -> (ANDWconst [c] x)
   496  (ANDW (MOVDconst [c]) x) -> (ANDWconst [c] x)
   497  
   498  (ANDWconst [c] (ANDWconst [d] x)) -> (ANDWconst [c & d] x)
   499  (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c & d] x)
   500  
   501  (OR x (MOVDconst [c])) && isU32Bit(c) -> (ORconst [c] x)
   502  (OR (MOVDconst [c]) x) && isU32Bit(c) -> (ORconst [c] x)
   503  (ORW x (MOVDconst [c])) -> (ORWconst [c] x)
   504  (ORW (MOVDconst [c]) x) -> (ORWconst [c] x)
   505  
   506  (XOR x (MOVDconst [c])) && isU32Bit(c) -> (XORconst [c] x)
   507  (XOR (MOVDconst [c]) x) && isU32Bit(c) -> (XORconst [c] x)
   508  (XORW x (MOVDconst [c])) -> (XORWconst [c] x)
   509  (XORW (MOVDconst [c]) x) -> (XORWconst [c] x)
   510  
   511  (SLD x (MOVDconst [c])) -> (SLDconst [c&63] x)
   512  (SLW x (MOVDconst [c])) -> (SLWconst [c&63] x)
   513  (SRD x (MOVDconst [c])) -> (SRDconst [c&63] x)
   514  (SRW x (MOVDconst [c])) -> (SRWconst [c&63] x)
   515  (SRAD x (MOVDconst [c])) -> (SRADconst [c&63] x)
   516  (SRAW x (MOVDconst [c])) -> (SRAWconst [c&63] x)
   517  
   518  (SRAW x (ANDWconst [63] y)) -> (SRAW x y)
   519  (SRAD x (ANDconst [63] y)) -> (SRAD x y)
   520  (SLW x (ANDWconst [63] y)) -> (SLW x y)
   521  (SLD x (ANDconst [63] y)) -> (SLD x y)
   522  (SRW x (ANDWconst [63] y)) -> (SRW x y)
   523  (SRD x (ANDconst [63] y)) -> (SRD x y)
   524  
   525  // Rotate generation
   526  (ADD (SLDconst x [c]) (SRDconst x [64-c])) -> (RLLGconst [   c] x)
   527  ( OR (SLDconst x [c]) (SRDconst x [64-c])) -> (RLLGconst [   c] x)
   528  (XOR (SLDconst x [c]) (SRDconst x [64-c])) -> (RLLGconst [   c] x)
   529  (ADD (SRDconst x [c]) (SLDconst x [64-c])) -> (RLLGconst [64-c] x)
   530  ( OR (SRDconst x [c]) (SLDconst x [64-c])) -> (RLLGconst [64-c] x)
   531  (XOR (SRDconst x [c]) (SLDconst x [64-c])) -> (RLLGconst [64-c] x)
   532  
   533  (ADDW (SLWconst x [c]) (SRWconst x [32-c])) -> (RLLconst [   c] x)
   534  ( ORW (SLWconst x [c]) (SRWconst x [32-c])) -> (RLLconst [   c] x)
   535  (XORW (SLWconst x [c]) (SRWconst x [32-c])) -> (RLLconst [   c] x)
   536  (ADDW (SRWconst x [c]) (SLWconst x [32-c])) -> (RLLconst [32-c] x)
   537  ( ORW (SRWconst x [c]) (SLWconst x [32-c])) -> (RLLconst [32-c] x)
   538  (XORW (SRWconst x [c]) (SLWconst x [32-c])) -> (RLLconst [32-c] x)
   539  
   540  (CMP x (MOVDconst [c])) && is32Bit(c) -> (CMPconst x [c])
   541  (CMP (MOVDconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPconst x [c]))
   542  (CMPW x (MOVDconst [c])) -> (CMPWconst x [c])
   543  (CMPW (MOVDconst [c]) x) -> (InvertFlags (CMPWconst x [c]))
   544  (CMPU x (MOVDconst [c])) && is32Bit(c) -> (CMPUconst x [int64(uint32(c))])
   545  (CMPU (MOVDconst [c]) x) && is32Bit(c) -> (InvertFlags (CMPUconst x [int64(uint32(c))]))
   546  (CMPWU x (MOVDconst [c])) -> (CMPWUconst x [int64(uint32(c))])
   547  (CMPWU (MOVDconst [c]) x) -> (InvertFlags (CMPWUconst x [int64(uint32(c))]))
   548  
   549  // Using MOV{W,H,B}Zreg instead of AND is cheaper.
   550  (AND (MOVDconst [0xFF]) x) -> (MOVBZreg x)
   551  (AND x (MOVDconst [0xFF])) -> (MOVBZreg x)
   552  (AND (MOVDconst [0xFFFF]) x) -> (MOVHZreg x)
   553  (AND x (MOVDconst [0xFFFF])) -> (MOVHZreg x)
   554  (AND (MOVDconst [0xFFFFFFFF]) x) -> (MOVWZreg x)
   555  (AND x (MOVDconst [0xFFFFFFFF])) -> (MOVWZreg x)
   556  (ANDWconst [0xFF] x) -> (MOVBZreg x)
   557  (ANDWconst [0xFFFF] x) -> (MOVHZreg x)
   558  
   559  // strength reduction
   560  (MULLDconst [-1] x) -> (NEG x)
   561  (MULLDconst [0] _) -> (MOVDconst [0])
   562  (MULLDconst [1] x) -> x
   563  (MULLDconst [c] x) && isPowerOfTwo(c) -> (SLDconst [log2(c)] x)
   564  (MULLDconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUB (SLDconst <v.Type> [log2(c+1)] x) x)
   565  (MULLDconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (ADD (SLDconst <v.Type> [log2(c-1)] x) x)
   566  
   567  (MULLWconst [-1] x) -> (NEGW x)
   568  (MULLWconst [0] _) -> (MOVDconst [0])
   569  (MULLWconst [1] x) -> x
   570  (MULLWconst [c] x) && isPowerOfTwo(c) -> (SLWconst [log2(c)] x)
   571  (MULLWconst [c] x) && isPowerOfTwo(c+1) && c >= 15 -> (SUBW (SLWconst <v.Type> [log2(c+1)] x) x)
   572  (MULLWconst [c] x) && isPowerOfTwo(c-1) && c >= 17 -> (ADDW (SLWconst <v.Type> [log2(c-1)] x) x)
   573  
   574  // Fold ADD into MOVDaddr. Odd offsets from SB shouldn't be folded (LARL can't handle them).
   575  (ADDconst [c] (MOVDaddr [d] {s} x:(SB))) && ((c+d)&1 == 0) && is32Bit(c+d) -> (MOVDaddr [c+d] {s} x)
   576  (ADDconst [c] (MOVDaddr [d] {s} x)) && x.Op != OpSB && is20Bit(c+d) -> (MOVDaddr [c+d] {s} x)
   577  (ADD x (MOVDaddr [c] {s} y)) && x.Op != OpSB && y.Op != OpSB -> (MOVDaddridx [c] {s} x y)
   578  (ADD (MOVDaddr [c] {s} x) y) && x.Op != OpSB && y.Op != OpSB -> (MOVDaddridx [c] {s} x y)
   579  
   580  // fold ADDconst into MOVDaddrx
   581  (ADDconst [c] (MOVDaddridx [d] {s} x y)) && is20Bit(c+d) -> (MOVDaddridx [c+d] {s} x y)
   582  (MOVDaddridx [c] {s} (ADDconst [d] x) y) && is20Bit(c+d) && x.Op != OpSB -> (MOVDaddridx [c+d] {s} x y)
   583  (MOVDaddridx [c] {s} x (ADDconst [d] y)) && is20Bit(c+d) && y.Op != OpSB -> (MOVDaddridx [c+d] {s} x y)
   584  
   585  // reverse ordering of compare instruction
   586  (MOVDLT x y (InvertFlags cmp)) -> (MOVDGT x y cmp)
   587  (MOVDGT x y (InvertFlags cmp)) -> (MOVDLT x y cmp)
   588  (MOVDLE x y (InvertFlags cmp)) -> (MOVDGE x y cmp)
   589  (MOVDGE x y (InvertFlags cmp)) -> (MOVDLE x y cmp)
   590  (MOVDEQ x y (InvertFlags cmp)) -> (MOVDEQ x y cmp)
   591  (MOVDNE x y (InvertFlags cmp)) -> (MOVDNE x y cmp)
   592  
   593  // don't extend after proper load
   594  (MOVBreg x:(MOVBload _ _)) -> (MOVDreg x)
   595  (MOVBZreg x:(MOVBZload _ _)) -> (MOVDreg x)
   596  (MOVHreg x:(MOVBload _ _)) -> (MOVDreg x)
   597  (MOVHreg x:(MOVBZload _ _)) -> (MOVDreg x)
   598  (MOVHreg x:(MOVHload _ _)) -> (MOVDreg x)
   599  (MOVHZreg x:(MOVBZload _ _)) -> (MOVDreg x)
   600  (MOVHZreg x:(MOVHZload _ _)) -> (MOVDreg x)
   601  (MOVWreg x:(MOVBload _ _)) -> (MOVDreg x)
   602  (MOVWreg x:(MOVBZload _ _)) -> (MOVDreg x)
   603  (MOVWreg x:(MOVHload _ _)) -> (MOVDreg x)
   604  (MOVWreg x:(MOVHZload _ _)) -> (MOVDreg x)
   605  (MOVWreg x:(MOVWload _ _)) -> (MOVDreg x)
   606  (MOVWZreg x:(MOVBZload _ _)) -> (MOVDreg x)
   607  (MOVWZreg x:(MOVHZload _ _)) -> (MOVDreg x)
   608  (MOVWZreg x:(MOVWZload _ _)) -> (MOVDreg x)
   609  
   610  // don't extend if argument is already extended
   611  (MOVBreg x:(Arg <t>)) && is8BitInt(t) && isSigned(t) -> (MOVDreg x)
   612  (MOVBZreg x:(Arg <t>)) && is8BitInt(t) && !isSigned(t) -> (MOVDreg x)
   613  (MOVHreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> (MOVDreg x)
   614  (MOVHZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> (MOVDreg x)
   615  (MOVWreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> (MOVDreg x)
   616  (MOVWZreg x:(Arg <t>)) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> (MOVDreg x)
   617  
   618  // fold double extensions
   619  (MOVBreg x:(MOVBreg _)) -> (MOVDreg x)
   620  (MOVBZreg x:(MOVBZreg _)) -> (MOVDreg x)
   621  (MOVHreg x:(MOVBreg _)) -> (MOVDreg x)
   622  (MOVHreg x:(MOVBZreg _)) -> (MOVDreg x)
   623  (MOVHreg x:(MOVHreg _)) -> (MOVDreg x)
   624  (MOVHZreg x:(MOVBZreg _)) -> (MOVDreg x)
   625  (MOVHZreg x:(MOVHZreg _)) -> (MOVDreg x)
   626  (MOVWreg x:(MOVBreg _)) -> (MOVDreg x)
   627  (MOVWreg x:(MOVBZreg _)) -> (MOVDreg x)
   628  (MOVWreg x:(MOVHreg _)) -> (MOVDreg x)
   629  (MOVWreg x:(MOVHreg _)) -> (MOVDreg x)
   630  (MOVWreg x:(MOVWreg _)) -> (MOVDreg x)
   631  (MOVWZreg x:(MOVBZreg _)) -> (MOVDreg x)
   632  (MOVWZreg x:(MOVHZreg _)) -> (MOVDreg x)
   633  (MOVWZreg x:(MOVWZreg _)) -> (MOVDreg x)
   634  
   635  // fold extensions into constants
   636  (MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))])
   637  (MOVBZreg (MOVDconst [c])) -> (MOVDconst [int64(uint8(c))])
   638  (MOVHreg (MOVDconst [c])) -> (MOVDconst [int64(int16(c))])
   639  (MOVHZreg (MOVDconst [c])) -> (MOVDconst [int64(uint16(c))])
   640  (MOVWreg (MOVDconst [c])) -> (MOVDconst [int64(int32(c))])
   641  (MOVWZreg (MOVDconst [c])) -> (MOVDconst [int64(uint32(c))])
   642  
   643  // sign extended loads
   644  // Note: The combined instruction must end up in the same block
   645  // as the original load. If not, we end up making a value with
   646  // memory type live in two different blocks, which can lead to
   647  // multiple memory values alive simultaneously.
   648  // Make sure we don't combine these ops if the load has another use.
   649  // This prevents a single load from being split into multiple loads
   650  // which then might return different values.  See test/atomicload.go.
   651  (MOVBreg x:(MOVBZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBload <v.Type> [off] {sym} ptr mem)
   652  (MOVBZreg x:(MOVBZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBZload <v.Type> [off] {sym} ptr mem)
   653  (MOVHreg x:(MOVHZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVHload <v.Type> [off] {sym} ptr mem)
   654  (MOVHZreg x:(MOVHZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVHZload <v.Type> [off] {sym} ptr mem)
   655  (MOVWreg x:(MOVWZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWload <v.Type> [off] {sym} ptr mem)
   656  (MOVWZreg x:(MOVWZload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWZload <v.Type> [off] {sym} ptr mem)
   657  
   658  (MOVBZreg x:(MOVBZloadidx [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBZloadidx <v.Type> [off] {sym} ptr idx mem)
   659  (MOVHZreg x:(MOVHZloadidx [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVHZloadidx <v.Type> [off] {sym} ptr idx mem)
   660  (MOVWZreg x:(MOVWZloadidx [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWZloadidx <v.Type> [off] {sym} ptr idx mem)
   661  
   662  // replace load from same location as preceding store with copy
   663  (MOVBZload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x)
   664  (MOVHZload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x)
   665  (MOVWZload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x)
   666  (MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDreg x)
   667  
   668  // Don't extend before storing
   669  (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   670  (MOVHstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   671  (MOVBstore [off] {sym} ptr (MOVBreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   672  (MOVWstore [off] {sym} ptr (MOVWZreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   673  (MOVHstore [off] {sym} ptr (MOVHZreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   674  (MOVBstore [off] {sym} ptr (MOVBZreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   675  
   676  // Fold constants into memory operations.
   677  // Note that this is not always a good idea because if not all the uses of
   678  // the ADDconst get eliminated, we still have to compute the ADDconst and we now
   679  // have potentially two live values (ptr and (ADDconst [off] ptr)) instead of one.
   680  // Nevertheless, let's do it!
   681  (MOVDload   [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVDload  [off1+off2] {sym} ptr mem)
   682  (MOVWload   [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVWload  [off1+off2] {sym} ptr mem)
   683  (MOVHload   [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVHload  [off1+off2] {sym} ptr mem)
   684  (MOVBload   [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVBload  [off1+off2] {sym} ptr mem)
   685  (MOVWZload  [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVWZload [off1+off2] {sym} ptr mem)
   686  (MOVHZload  [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVHZload [off1+off2] {sym} ptr mem)
   687  (MOVBZload  [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (MOVBZload [off1+off2] {sym} ptr mem)
   688  (FMOVSload  [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (FMOVSload [off1+off2] {sym} ptr mem)
   689  (FMOVDload  [off1] {sym} (ADDconst [off2] ptr) mem) && is20Bit(off1+off2) -> (FMOVDload [off1+off2] {sym} ptr mem)
   690  
   691  (MOVDstore  [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (MOVDstore  [off1+off2] {sym} ptr val mem)
   692  (MOVWstore  [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (MOVWstore  [off1+off2] {sym} ptr val mem)
   693  (MOVHstore  [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (MOVHstore  [off1+off2] {sym} ptr val mem)
   694  (MOVBstore  [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (MOVBstore  [off1+off2] {sym} ptr val mem)
   695  (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (FMOVSstore [off1+off2] {sym} ptr val mem)
   696  (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is20Bit(off1+off2) -> (FMOVDstore [off1+off2] {sym} ptr val mem)
   697  
   698  // Fold constants into stores.
   699  (MOVDstore [off] {sym} ptr (MOVDconst [c]) mem) && validValAndOff(c,off) && int64(int16(c)) == c && ptr.Op != OpSB ->
   700  	(MOVDstoreconst [makeValAndOff(c,off)] {sym} ptr mem)
   701  (MOVWstore [off] {sym} ptr (MOVDconst [c]) mem) && validOff(off) && int64(int16(c)) == c && ptr.Op != OpSB ->
   702  	(MOVWstoreconst [makeValAndOff(int64(int32(c)),off)] {sym} ptr mem)
   703  (MOVHstore [off] {sym} ptr (MOVDconst [c]) mem) && validOff(off) && ptr.Op != OpSB ->
   704  	(MOVHstoreconst [makeValAndOff(int64(int16(c)),off)] {sym} ptr mem)
   705  (MOVBstore [off] {sym} ptr (MOVDconst [c]) mem) && validOff(off) && ptr.Op != OpSB ->
   706  	(MOVBstoreconst [makeValAndOff(int64(int8(c)),off)] {sym} ptr mem)
   707  
   708  // Fold address offsets into constant stores.
   709  (MOVDstoreconst [sc] {s} (ADDconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
   710  	(MOVDstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
   711  (MOVWstoreconst [sc] {s} (ADDconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
   712  	(MOVWstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
   713  (MOVHstoreconst [sc] {s} (ADDconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
   714  	(MOVHstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
   715  (MOVBstoreconst [sc] {s} (ADDconst [off] ptr) mem) && ValAndOff(sc).canAdd(off) ->
   716  	(MOVBstoreconst [ValAndOff(sc).add(off)] {s} ptr mem)
   717  
   718  // We need to fold MOVDaddr into the MOVx ops so that the live variable analysis knows
   719  // what variables are being read/written by the ops.
   720  (MOVDload  [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   721  	(MOVDload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
   722  (MOVWZload  [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   723  	(MOVWZload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
   724  (MOVHZload  [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   725  	(MOVHZload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
   726  (MOVBZload  [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   727  	(MOVBZload  [off1+off2] {mergeSym(sym1,sym2)} base mem)
   728  (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   729  	(FMOVSload [off1+off2] {mergeSym(sym1,sym2)} base mem)
   730  (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   731  	(FMOVDload [off1+off2] {mergeSym(sym1,sym2)} base mem)
   732  
   733  (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   734  	(MOVBload [off1+off2] {mergeSym(sym1,sym2)} base mem)
   735  (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   736  	(MOVHload [off1+off2] {mergeSym(sym1,sym2)} base mem)
   737  (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   738  	(MOVWload [off1+off2] {mergeSym(sym1,sym2)} base mem)
   739  
   740  (MOVDstore  [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   741  	(MOVDstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   742  (MOVWstore  [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   743  	(MOVWstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   744  (MOVHstore  [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   745  	(MOVHstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   746  (MOVBstore  [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   747  	(MOVBstore  [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   748  (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   749  	(FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   750  (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   751  	(FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} base val mem)
   752  
   753  (MOVDstoreconst [sc] {sym1} (MOVDaddr [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
   754  	(MOVDstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
   755  (MOVWstoreconst [sc] {sym1} (MOVDaddr [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
   756  	(MOVWstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
   757  (MOVHstoreconst [sc] {sym1} (MOVDaddr [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
   758  	(MOVHstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
   759  (MOVBstoreconst [sc] {sym1} (MOVDaddr [off] {sym2} ptr) mem) && canMergeSym(sym1, sym2) && ValAndOff(sc).canAdd(off) ->
   760  	(MOVBstoreconst [ValAndOff(sc).add(off)] {mergeSym(sym1, sym2)} ptr mem)
   761  
   762  // generating indexed loads and stores
   763  (MOVBZload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   764  	(MOVBZloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   765  (MOVHZload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   766  	(MOVHZloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   767  (MOVWZload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   768  	(MOVWZloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   769  (MOVDload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   770  	(MOVDloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   771  (FMOVSload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   772  	(FMOVSloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   773  (FMOVDload [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   774  	(FMOVDloadidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx mem)
   775  
   776  (MOVBstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   777  	(MOVBstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   778  (MOVHstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   779  	(MOVHstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   780  (MOVWstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   781  	(MOVWstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   782  (MOVDstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   783  	(MOVDstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   784  (FMOVSstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   785  	(FMOVSstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   786  (FMOVDstore [off1] {sym1} (MOVDaddridx [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) ->
   787  	(FMOVDstoreidx [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem)
   788  
   789  (MOVBZload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (MOVBZloadidx [off] {sym} ptr idx mem)
   790  (MOVHZload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (MOVHZloadidx [off] {sym} ptr idx mem)
   791  (MOVWZload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (MOVWZloadidx [off] {sym} ptr idx mem)
   792  (MOVDload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (MOVDloadidx [off] {sym} ptr idx mem)
   793  (FMOVSload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (FMOVSloadidx [off] {sym} ptr idx mem)
   794  (FMOVDload [off] {sym} (ADD ptr idx) mem) && ptr.Op != OpSB -> (FMOVDloadidx [off] {sym} ptr idx mem)
   795  (MOVBstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (MOVBstoreidx [off] {sym} ptr idx val mem)
   796  (MOVHstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (MOVHstoreidx [off] {sym} ptr idx val mem)
   797  (MOVWstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (MOVWstoreidx [off] {sym} ptr idx val mem)
   798  (MOVDstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (MOVDstoreidx [off] {sym} ptr idx val mem)
   799  (FMOVSstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (FMOVSstoreidx [off] {sym} ptr idx val mem)
   800  (FMOVDstore [off] {sym} (ADD ptr idx) val mem) && ptr.Op != OpSB -> (FMOVDstoreidx [off] {sym} ptr idx val mem)
   801  
   802  // combine ADD into indexed loads and stores
   803  (MOVBZloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (MOVBZloadidx [c+d] {sym} ptr idx mem)
   804  (MOVHZloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (MOVHZloadidx [c+d] {sym} ptr idx mem)
   805  (MOVWZloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (MOVWZloadidx [c+d] {sym} ptr idx mem)
   806  (MOVDloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (MOVDloadidx [c+d] {sym} ptr idx mem)
   807  (FMOVSloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (FMOVSloadidx [c+d] {sym} ptr idx mem)
   808  (FMOVDloadidx [c] {sym} (ADDconst [d] ptr) idx mem) -> (FMOVDloadidx [c+d] {sym} ptr idx mem)
   809  
   810  (MOVBstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (MOVBstoreidx [c+d] {sym} ptr idx val mem)
   811  (MOVHstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (MOVHstoreidx [c+d] {sym} ptr idx val mem)
   812  (MOVWstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (MOVWstoreidx [c+d] {sym} ptr idx val mem)
   813  (MOVDstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (MOVDstoreidx [c+d] {sym} ptr idx val mem)
   814  (FMOVSstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (FMOVSstoreidx [c+d] {sym} ptr idx val mem)
   815  (FMOVDstoreidx [c] {sym} (ADDconst [d] ptr) idx val mem) -> (FMOVDstoreidx [c+d] {sym} ptr idx val mem)
   816  
   817  (MOVBZloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (MOVBZloadidx [c+d] {sym} ptr idx mem)
   818  (MOVHZloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (MOVHZloadidx [c+d] {sym} ptr idx mem)
   819  (MOVWZloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (MOVWZloadidx [c+d] {sym} ptr idx mem)
   820  (MOVDloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (MOVDloadidx [c+d] {sym} ptr idx mem)
   821  (FMOVSloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (FMOVSloadidx [c+d] {sym} ptr idx mem)
   822  (FMOVDloadidx [c] {sym} ptr (ADDconst [d] idx) mem) -> (FMOVDloadidx [c+d] {sym} ptr idx mem)
   823  
   824  (MOVBstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (MOVBstoreidx [c+d] {sym} ptr idx val mem)
   825  (MOVHstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (MOVHstoreidx [c+d] {sym} ptr idx val mem)
   826  (MOVWstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (MOVWstoreidx [c+d] {sym} ptr idx val mem)
   827  (MOVDstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (MOVDstoreidx [c+d] {sym} ptr idx val mem)
   828  (FMOVSstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (FMOVSstoreidx [c+d] {sym} ptr idx val mem)
   829  (FMOVDstoreidx [c] {sym} ptr (ADDconst [d] idx) val mem) -> (FMOVDstoreidx [c+d] {sym} ptr idx val mem)
   830  
   831  // MOVDaddr into MOVDaddridx
   832  (MOVDaddridx [off1] {sym1} (MOVDaddr [off2] {sym2} x) y) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && x.Op != OpSB ->
   833         (MOVDaddridx [off1+off2] {mergeSym(sym1,sym2)} x y)
   834  (MOVDaddridx [off1] {sym1} x (MOVDaddr [off2] {sym2} y)) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && y.Op != OpSB ->
   835         (MOVDaddridx [off1+off2] {mergeSym(sym1,sym2)} x y)
   836  
   837  // Absorb InvertFlags into branches.
   838  (LT (InvertFlags cmp) yes no) -> (GT cmp yes no)
   839  (GT (InvertFlags cmp) yes no) -> (LT cmp yes no)
   840  (LE (InvertFlags cmp) yes no) -> (GE cmp yes no)
   841  (GE (InvertFlags cmp) yes no) -> (LE cmp yes no)
   842  (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no)
   843  (NE (InvertFlags cmp) yes no) -> (NE cmp yes no)
   844  
   845  // Constant comparisons.
   846  (CMPconst (MOVDconst [x]) [y]) && x==y -> (FlagEQ)
   847  (CMPconst (MOVDconst [x]) [y]) && x<y -> (FlagLT)
   848  (CMPconst (MOVDconst [x]) [y]) && x>y -> (FlagGT)
   849  (CMPUconst (MOVDconst [x]) [y]) && uint64(x)==uint64(y) -> (FlagEQ)
   850  (CMPUconst (MOVDconst [x]) [y]) && uint64(x)<uint64(y) -> (FlagLT)
   851  (CMPUconst (MOVDconst [x]) [y]) && uint64(x)>uint64(y) -> (FlagGT)
   852  
   853  (CMPWconst (MOVDconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ)
   854  (CMPWconst (MOVDconst [x]) [y]) && int32(x)<int32(y) -> (FlagLT)
   855  (CMPWconst (MOVDconst [x]) [y]) && int32(x)>int32(y) -> (FlagGT)
   856  (CMPWUconst (MOVDconst [x]) [y]) && uint32(x)==uint32(y) -> (FlagEQ)
   857  (CMPWUconst (MOVDconst [x]) [y]) && uint32(x)<uint32(y) -> (FlagLT)
   858  (CMPWUconst (MOVDconst [x]) [y]) && uint32(x)>uint32(y) -> (FlagGT)
   859  
   860  // Other known comparisons.
   861  (CMPconst (MOVBZreg _) [c]) && 0xFF < c -> (FlagLT)
   862  (CMPconst (MOVHZreg _) [c]) && 0xFFFF < c -> (FlagLT)
   863  (CMPconst (MOVWZreg _) [c]) && 0xFFFFFFFF < c -> (FlagLT)
   864  (CMPWconst (SRWconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint64(32-c)) <= uint64(n) -> (FlagLT)
   865  (CMPconst (SRDconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 64 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT)
   866  (CMPconst (ANDconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT)
   867  (CMPWconst (ANDWconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT)
   868  
   869  // Absorb flag constants into SBB ops.
   870  (SUBEcarrymask (FlagEQ)) -> (MOVDconst [-1])
   871  (SUBEcarrymask (FlagLT)) -> (MOVDconst [-1])
   872  (SUBEcarrymask (FlagGT)) -> (MOVDconst [0])
   873  (SUBEWcarrymask (FlagEQ)) -> (MOVDconst [-1])
   874  (SUBEWcarrymask (FlagLT)) -> (MOVDconst [-1])
   875  (SUBEWcarrymask (FlagGT)) -> (MOVDconst [0])
   876  
   877  // Absorb flag constants into branches.
   878  (EQ (FlagEQ) yes no) -> (First nil yes no)
   879  (EQ (FlagLT) yes no) -> (First nil no yes)
   880  (EQ (FlagGT) yes no) -> (First nil no yes)
   881  
   882  (NE (FlagEQ) yes no) -> (First nil no yes)
   883  (NE (FlagLT) yes no) -> (First nil yes no)
   884  (NE (FlagGT) yes no) -> (First nil yes no)
   885  
   886  (LT (FlagEQ) yes no) -> (First nil no yes)
   887  (LT (FlagLT) yes no) -> (First nil yes no)
   888  (LT (FlagGT) yes no) -> (First nil no yes)
   889  
   890  (LE (FlagEQ) yes no) -> (First nil yes no)
   891  (LE (FlagLT) yes no) -> (First nil yes no)
   892  (LE (FlagGT) yes no) -> (First nil no yes)
   893  
   894  (GT (FlagEQ) yes no) -> (First nil no yes)
   895  (GT (FlagLT) yes no) -> (First nil no yes)
   896  (GT (FlagGT) yes no) -> (First nil yes no)
   897  
   898  (GE (FlagEQ) yes no) -> (First nil yes no)
   899  (GE (FlagLT) yes no) -> (First nil no yes)
   900  (GE (FlagGT) yes no) -> (First nil yes no)
   901  
   902  // Absorb flag constants into SETxx ops.
   903  (MOVDEQ _ x (FlagEQ)) -> x
   904  (MOVDEQ y _ (FlagLT)) -> y
   905  (MOVDEQ y _ (FlagGT)) -> y
   906  
   907  (MOVDNE y _ (FlagEQ)) -> y
   908  (MOVDNE _ x (FlagLT)) -> x
   909  (MOVDNE _ x (FlagGT)) -> x
   910  
   911  (MOVDLT y _ (FlagEQ)) -> y
   912  (MOVDLT _ x (FlagLT)) -> x
   913  (MOVDLT y _ (FlagGT)) -> y
   914  
   915  (MOVDLE _ x (FlagEQ)) -> x
   916  (MOVDLE _ x (FlagLT)) -> x
   917  (MOVDLE y _ (FlagGT)) -> y
   918  
   919  (MOVDGT y _ (FlagEQ)) -> y
   920  (MOVDGT y _ (FlagLT)) -> y
   921  (MOVDGT _ x (FlagGT)) -> x
   922  
   923  (MOVDGE _ x (FlagEQ)) -> x
   924  (MOVDGE y _ (FlagLT)) -> y
   925  (MOVDGE _ x (FlagGT)) -> x
   926  
   927  // Remove redundant *const ops
   928  (ADDconst [0] x) -> x
   929  (ADDWconst [c] x) && int32(c)==0 -> x
   930  (SUBconst [0] x) -> x
   931  (SUBWconst [c] x) && int32(c) == 0 -> x
   932  (ANDconst [0] _)                 -> (MOVDconst [0])
   933  (ANDWconst [c] _) && int32(c)==0  -> (MOVDconst [0])
   934  (ANDconst [-1] x)                -> x
   935  (ANDWconst [c] x) && int32(c)==-1 -> x
   936  (ORconst [0] x)                  -> x
   937  (ORWconst [c] x) && int32(c)==0   -> x
   938  (ORconst [-1] _)                 -> (MOVDconst [-1])
   939  (ORWconst [c] _) && int32(c)==-1  -> (MOVDconst [-1])
   940  (XORconst [0] x)                  -> x
   941  (XORWconst [c] x) && int32(c)==0   -> x
   942  
   943  // Convert constant subtracts to constant adds.
   944  (SUBconst [c] x) && c != -(1<<31) -> (ADDconst [-c] x)
   945  (SUBWconst [c] x) -> (ADDWconst [int64(int32(-c))] x)
   946  
   947  // generic constant folding
   948  // TODO: more of this
   949  (ADDconst [c] (MOVDconst [d])) -> (MOVDconst [c+d])
   950  (ADDWconst [c] (MOVDconst [d])) -> (MOVDconst [int64(int32(c+d))])
   951  (ADDconst [c] (ADDconst [d] x)) && is32Bit(c+d) -> (ADDconst [c+d] x)
   952  (ADDWconst [c] (ADDWconst [d] x)) -> (ADDWconst [int64(int32(c+d))] x)
   953  (SUBconst (MOVDconst [d]) [c]) -> (MOVDconst [d-c])
   954  (SUBconst (SUBconst x [d]) [c]) && is32Bit(-c-d) -> (ADDconst [-c-d] x)
   955  (SRADconst [c] (MOVDconst [d])) -> (MOVDconst [d>>uint64(c)])
   956  (SRAWconst [c] (MOVDconst [d])) -> (MOVDconst [d>>uint64(c)])
   957  (NEG (MOVDconst [c])) -> (MOVDconst [-c])
   958  (NEGW (MOVDconst [c])) -> (MOVDconst [int64(int32(-c))])
   959  (MULLDconst [c] (MOVDconst [d])) -> (MOVDconst [c*d])
   960  (MULLWconst [c] (MOVDconst [d])) -> (MOVDconst [int64(int32(c*d))])
   961  (AND (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c&d])
   962  (ANDconst [c] (MOVDconst [d])) -> (MOVDconst [c&d])
   963  (ANDWconst [c] (MOVDconst [d])) -> (MOVDconst [c&d])
   964  (OR (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c|d])
   965  (ORconst [c] (MOVDconst [d])) -> (MOVDconst [c|d])
   966  (ORWconst [c] (MOVDconst [d])) -> (MOVDconst [c|d])
   967  (XOR (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c^d])
   968  (XORconst [c] (MOVDconst [d])) -> (MOVDconst [c^d])
   969  (XORWconst [c] (MOVDconst [d])) -> (MOVDconst [c^d])
   970  
   971  // generic simplifications
   972  // TODO: more of this
   973  (ADD x (NEG y)) -> (SUB x y)
   974  (ADDW x (NEGW y)) -> (SUBW x y)
   975  (SUB x x) -> (MOVDconst [0])
   976  (SUBW x x) -> (MOVDconst [0])
   977  (AND x x) -> x
   978  (ANDW x x) -> x
   979  (OR x x) -> x
   980  (ORW x x) -> x
   981  (XOR x x) -> (MOVDconst [0])
   982  (XORW x x) -> (MOVDconst [0])
   983  
   984  // Fold memory operations into operations.
   985  // Exclude global data (SB) because these instructions cannot handle relative addresses.
   986  // TODO(mundaym): use LARL in the assembler to handle SB?
   987  // TODO(mundaym): indexed versions of these?
   988  (ADD <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   989  	-> (ADDload <t> [off] {sym} x ptr mem)
   990  (ADD <t> g:(MOVDload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   991  	-> (ADDload <t> [off] {sym} x ptr mem)
   992  (ADDW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   993  	-> (ADDWload <t> [off] {sym} x ptr mem)
   994  (ADDW <t> g:(MOVWload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   995  	-> (ADDWload <t> [off] {sym} x ptr mem)
   996  (ADDW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   997  	-> (ADDWload <t> [off] {sym} x ptr mem)
   998  (ADDW <t> g:(MOVWZload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
   999  	-> (ADDWload <t> [off] {sym} x ptr mem)
  1000  (MULLD <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1001  	-> (MULLDload <t> [off] {sym} x ptr mem)
  1002  (MULLD <t> g:(MOVDload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1003  	-> (MULLDload <t> [off] {sym} x ptr mem)
  1004  (MULLW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1005  	-> (MULLWload <t> [off] {sym} x ptr mem)
  1006  (MULLW <t> g:(MOVWload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1007  	-> (MULLWload <t> [off] {sym} x ptr mem)
  1008  (MULLW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1009  	-> (MULLWload <t> [off] {sym} x ptr mem)
  1010  (MULLW <t> g:(MOVWZload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1011  	-> (MULLWload <t> [off] {sym} x ptr mem)
  1012  (SUB <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1013  	-> (SUBload <t> [off] {sym} x ptr mem)
  1014  (SUBW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1015  	-> (SUBWload <t> [off] {sym} x ptr mem)
  1016  (SUBW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1017  	-> (SUBWload <t> [off] {sym} x ptr mem)
  1018  (AND <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1019  	-> (ANDload <t> [off] {sym} x ptr mem)
  1020  (AND <t> g:(MOVDload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1021  	-> (ANDload <t> [off] {sym} x ptr mem)
  1022  (ANDW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1023  	-> (ANDWload <t> [off] {sym} x ptr mem)
  1024  (ANDW <t> g:(MOVWload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1025  	-> (ANDWload <t> [off] {sym} x ptr mem)
  1026  (ANDW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1027  	-> (ANDWload <t> [off] {sym} x ptr mem)
  1028  (ANDW <t> g:(MOVWZload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1029  	-> (ANDWload <t> [off] {sym} x ptr mem)
  1030  (OR <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1031  	-> (ORload <t> [off] {sym} x ptr mem)
  1032  (OR <t> g:(MOVDload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1033  	-> (ORload <t> [off] {sym} x ptr mem)
  1034  (ORW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1035  	-> (ORWload <t> [off] {sym} x ptr mem)
  1036  (ORW <t> g:(MOVWload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1037  	-> (ORWload <t> [off] {sym} x ptr mem)
  1038  (ORW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1039  	-> (ORWload <t> [off] {sym} x ptr mem)
  1040  (ORW <t> g:(MOVWZload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1041  	-> (ORWload <t> [off] {sym} x ptr mem)
  1042  (XOR <t> x g:(MOVDload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1043  	-> (XORload <t> [off] {sym} x ptr mem)
  1044  (XOR <t> g:(MOVDload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1045  	-> (XORload <t> [off] {sym} x ptr mem)
  1046  (XORW <t> x g:(MOVWload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1047  	-> (XORWload <t> [off] {sym} x ptr mem)
  1048  (XORW <t> g:(MOVWload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1049  	-> (XORWload <t> [off] {sym} x ptr mem)
  1050  (XORW <t> x g:(MOVWZload [off] {sym} ptr mem)) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1051  	-> (XORWload <t> [off] {sym} x ptr mem)
  1052  (XORW <t> g:(MOVWZload [off] {sym} ptr mem) x) && g.Uses == 1 && ptr.Op != OpSB && is20Bit(off) && canMergeLoad(v, g) && clobber(g)
  1053  	-> (XORWload <t> [off] {sym} x ptr mem)
  1054  
  1055  // Combine constant stores into larger (unaligned) stores.
  1056  // It doesn't work to global data (based on SB),
  1057  // because STGRL doesn't support unaligned address
  1058  (MOVBstoreconst [c] {s} p x:(MOVBstoreconst [a] {s} p mem))
  1059    && p.Op != OpSB
  1060    && x.Uses == 1
  1061    && ValAndOff(a).Off() + 1 == ValAndOff(c).Off()
  1062    && clobber(x)
  1063    -> (MOVHstoreconst [makeValAndOff(ValAndOff(c).Val()&0xff | ValAndOff(a).Val()<<8, ValAndOff(a).Off())] {s} p mem)
  1064  (MOVHstoreconst [c] {s} p x:(MOVHstoreconst [a] {s} p mem))
  1065    && p.Op != OpSB
  1066    && x.Uses == 1
  1067    && ValAndOff(a).Off() + 2 == ValAndOff(c).Off()
  1068    && clobber(x)
  1069    -> (MOVWstoreconst [makeValAndOff(ValAndOff(c).Val()&0xffff | ValAndOff(a).Val()<<16, ValAndOff(a).Off())] {s} p mem)
  1070  (MOVWstoreconst [c] {s} p x:(MOVWstoreconst [a] {s} p mem))
  1071    && p.Op != OpSB
  1072    && x.Uses == 1
  1073    && ValAndOff(a).Off() + 4 == ValAndOff(c).Off()
  1074    && clobber(x)
  1075    -> (MOVDstore [ValAndOff(a).Off()] {s} p (MOVDconst [ValAndOff(c).Val()&0xffffffff | ValAndOff(a).Val()<<32]) mem)
  1076  
  1077  // Combine stores into larger (unaligned) stores.
  1078  // It doesn't work on global data (based on SB) because stores with relative addressing
  1079  // require that the memory operand be aligned.
  1080  (MOVBstore [i] {s} p w x:(MOVBstore [i-1] {s} p (SRDconst [8] w) mem))
  1081    && p.Op != OpSB
  1082    && x.Uses == 1
  1083    && clobber(x)
  1084    -> (MOVHstore [i-1] {s} p w mem)
  1085  (MOVBstore [i] {s} p w0:(SRDconst [j] w) x:(MOVBstore [i-1] {s} p (SRDconst [j+8] w) mem))
  1086    && p.Op != OpSB
  1087    && x.Uses == 1
  1088    && clobber(x)
  1089    -> (MOVHstore [i-1] {s} p w0 mem)
  1090  (MOVBstore [i] {s} p w x:(MOVBstore [i-1] {s} p (SRWconst [8] w) mem))
  1091    && p.Op != OpSB
  1092    && x.Uses == 1
  1093    && clobber(x)
  1094    -> (MOVHstore [i-1] {s} p w mem)
  1095  (MOVBstore [i] {s} p w0:(SRWconst [j] w) x:(MOVBstore [i-1] {s} p (SRWconst [j+8] w) mem))
  1096    && p.Op != OpSB
  1097    && x.Uses == 1
  1098    && clobber(x)
  1099    -> (MOVHstore [i-1] {s} p w0 mem)
  1100  (MOVHstore [i] {s} p w x:(MOVHstore [i-2] {s} p (SRDconst [16] w) mem))
  1101    && p.Op != OpSB
  1102    && x.Uses == 1
  1103    && clobber(x)
  1104    -> (MOVWstore [i-2] {s} p w mem)
  1105  (MOVHstore [i] {s} p w0:(SRDconst [j] w) x:(MOVHstore [i-2] {s} p (SRDconst [j+16] w) mem))
  1106    && p.Op != OpSB
  1107    && x.Uses == 1
  1108    && clobber(x)
  1109    -> (MOVWstore [i-2] {s} p w0 mem)
  1110  (MOVHstore [i] {s} p w x:(MOVHstore [i-2] {s} p (SRWconst [16] w) mem))
  1111    && p.Op != OpSB
  1112    && x.Uses == 1
  1113    && clobber(x)
  1114    -> (MOVWstore [i-2] {s} p w mem)
  1115  (MOVHstore [i] {s} p w0:(SRWconst [j] w) x:(MOVHstore [i-2] {s} p (SRWconst [j+16] w) mem))
  1116    && p.Op != OpSB
  1117    && x.Uses == 1
  1118    && clobber(x)
  1119    -> (MOVWstore [i-2] {s} p w0 mem)
  1120  (MOVWstore [i] {s} p (SRDconst [32] w) x:(MOVWstore [i-4] {s} p w mem))
  1121    && p.Op != OpSB
  1122    && x.Uses == 1
  1123    && clobber(x)
  1124    -> (MOVDstore [i-4] {s} p w mem)
  1125  (MOVWstore [i] {s} p w0:(SRDconst [j] w) x:(MOVWstore [i-4] {s} p (SRDconst [j+32] w) mem))
  1126    && p.Op != OpSB
  1127    && x.Uses == 1
  1128    && clobber(x)
  1129    -> (MOVDstore [i-4] {s} p w0 mem)
  1130  
  1131  (MOVBstoreidx [i] {s} p idx w x:(MOVBstoreidx [i-1] {s} p idx (SRDconst [8] w) mem))
  1132    && x.Uses == 1
  1133    && clobber(x)
  1134    -> (MOVHstoreidx [i-1] {s} p idx w mem)
  1135  (MOVBstoreidx [i] {s} p idx w0:(SRDconst [j] w) x:(MOVBstoreidx [i-1] {s} p idx (SRDconst [j+8] w) mem))
  1136    && x.Uses == 1
  1137    && clobber(x)
  1138    -> (MOVHstoreidx [i-1] {s} p idx w0 mem)
  1139  (MOVBstoreidx [i] {s} p idx w x:(MOVBstoreidx [i-1] {s} p idx (SRWconst [8] w) mem))
  1140    && x.Uses == 1
  1141    && clobber(x)
  1142    -> (MOVHstoreidx [i-1] {s} p idx w mem)
  1143  (MOVBstoreidx [i] {s} p idx w0:(SRWconst [j] w) x:(MOVBstoreidx [i-1] {s} p idx (SRWconst [j+8] w) mem))
  1144    && x.Uses == 1
  1145    && clobber(x)
  1146    -> (MOVHstoreidx [i-1] {s} p idx w0 mem)
  1147  (MOVHstoreidx [i] {s} p idx w x:(MOVHstoreidx [i-2] {s} p idx (SRDconst [16] w) mem))
  1148    && x.Uses == 1
  1149    && clobber(x)
  1150    -> (MOVWstoreidx [i-2] {s} p idx w mem)
  1151  (MOVHstoreidx [i] {s} p idx w0:(SRDconst [j] w) x:(MOVHstoreidx [i-2] {s} p idx (SRDconst [j+16] w) mem))
  1152    && x.Uses == 1
  1153    && clobber(x)
  1154    -> (MOVWstoreidx [i-2] {s} p idx w0 mem)
  1155  (MOVHstoreidx [i] {s} p idx w x:(MOVHstoreidx [i-2] {s} p idx (SRWconst [16] w) mem))
  1156    && x.Uses == 1
  1157    && clobber(x)
  1158    -> (MOVWstoreidx [i-2] {s} p idx w mem)
  1159  (MOVHstoreidx [i] {s} p idx w0:(SRWconst [j] w) x:(MOVHstoreidx [i-2] {s} p idx (SRWconst [j+16] w) mem))
  1160    && x.Uses == 1
  1161    && clobber(x)
  1162    -> (MOVWstoreidx [i-2] {s} p idx w0 mem)
  1163  (MOVWstoreidx [i] {s} p idx w x:(MOVWstoreidx [i-4] {s} p idx (SRDconst [32] w) mem))
  1164    && x.Uses == 1
  1165    && clobber(x)
  1166    -> (MOVDstoreidx [i-4] {s} p idx w mem)
  1167  (MOVWstoreidx [i] {s} p idx w0:(SRDconst [j] w) x:(MOVWstoreidx [i-4] {s} p idx (SRDconst [j+32] w) mem))
  1168    && x.Uses == 1
  1169    && clobber(x)
  1170    -> (MOVDstoreidx [i-4] {s} p idx w0 mem)
  1171  
  1172  // Combine stores into larger (unaligned) stores with the bytes reversed (little endian).
  1173  // Store-with-bytes-reversed instructions do not support relative memory addresses,
  1174  // so these stores can't operate on global data (SB).
  1175  (MOVBstore [i] {s} p (SRDconst [8] w) x:(MOVBstore [i-1] {s} p w mem))
  1176    && p.Op != OpSB
  1177    && x.Uses == 1
  1178    && clobber(x)
  1179    -> (MOVHBRstore [i-1] {s} p w mem)
  1180  (MOVBstore [i] {s} p (SRDconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SRDconst [j-8] w) mem))
  1181    && p.Op != OpSB
  1182    && x.Uses == 1
  1183    && clobber(x)
  1184    -> (MOVHBRstore [i-1] {s} p w0 mem)
  1185  (MOVBstore [i] {s} p (SRWconst [8] w) x:(MOVBstore [i-1] {s} p w mem))
  1186    && p.Op != OpSB
  1187    && x.Uses == 1
  1188    && clobber(x)
  1189    -> (MOVHBRstore [i-1] {s} p w mem)
  1190  (MOVBstore [i] {s} p (SRWconst [j] w) x:(MOVBstore [i-1] {s} p w0:(SRWconst [j-8] w) mem))
  1191    && p.Op != OpSB
  1192    && x.Uses == 1
  1193    && clobber(x)
  1194    -> (MOVHBRstore [i-1] {s} p w0 mem)
  1195  (MOVHBRstore [i] {s} p (SRDconst [16] w) x:(MOVHBRstore [i-2] {s} p w mem))
  1196    && x.Uses == 1
  1197    && clobber(x)
  1198    -> (MOVWBRstore [i-2] {s} p w mem)
  1199  (MOVHBRstore [i] {s} p (SRDconst [j] w) x:(MOVHBRstore [i-2] {s} p w0:(SRDconst [j-16] w) mem))
  1200    && x.Uses == 1
  1201    && clobber(x)
  1202    -> (MOVWBRstore [i-2] {s} p w0 mem)
  1203  (MOVHBRstore [i] {s} p (SRWconst [16] w) x:(MOVHBRstore [i-2] {s} p w mem))
  1204    && x.Uses == 1
  1205    && clobber(x)
  1206    -> (MOVWBRstore [i-2] {s} p w mem)
  1207  (MOVHBRstore [i] {s} p (SRWconst [j] w) x:(MOVHBRstore [i-2] {s} p w0:(SRWconst [j-16] w) mem))
  1208    && x.Uses == 1
  1209    && clobber(x)
  1210    -> (MOVWBRstore [i-2] {s} p w0 mem)
  1211  (MOVWBRstore [i] {s} p (SRDconst [32] w) x:(MOVWBRstore [i-4] {s} p w mem))
  1212    && x.Uses == 1
  1213    && clobber(x)
  1214    -> (MOVDBRstore [i-4] {s} p w mem)
  1215  (MOVWBRstore [i] {s} p (SRDconst [j] w) x:(MOVWBRstore [i-4] {s} p w0:(SRDconst [j-32] w) mem))
  1216    && x.Uses == 1
  1217    && clobber(x)
  1218    -> (MOVDBRstore [i-4] {s} p w0 mem)
  1219  
  1220  (MOVBstoreidx [i] {s} p idx (SRDconst [8] w) x:(MOVBstoreidx [i-1] {s} p idx w mem))
  1221    && x.Uses == 1
  1222    && clobber(x)
  1223    -> (MOVHBRstoreidx [i-1] {s} p idx w mem)
  1224  (MOVBstoreidx [i] {s} p idx (SRDconst [j] w) x:(MOVBstoreidx [i-1] {s} p idx w0:(SRDconst [j-8] w) mem))
  1225    && x.Uses == 1
  1226    && clobber(x)
  1227    -> (MOVHBRstoreidx [i-1] {s} p idx w0 mem)
  1228  (MOVBstoreidx [i] {s} p idx (SRWconst [8] w) x:(MOVBstoreidx [i-1] {s} p idx w mem))
  1229    && x.Uses == 1
  1230    && clobber(x)
  1231    -> (MOVHBRstoreidx [i-1] {s} p idx w mem)
  1232  (MOVBstoreidx [i] {s} p idx (SRWconst [j] w) x:(MOVBstoreidx [i-1] {s} p idx w0:(SRWconst [j-8] w) mem))
  1233    && x.Uses == 1
  1234    && clobber(x)
  1235    -> (MOVHBRstoreidx [i-1] {s} p idx w0 mem)
  1236  (MOVHBRstoreidx [i] {s} p idx (SRDconst [16] w) x:(MOVHBRstoreidx [i-2] {s} p idx w mem))
  1237    && x.Uses == 1
  1238    && clobber(x)
  1239    -> (MOVWBRstoreidx [i-2] {s} p idx w mem)
  1240  (MOVHBRstoreidx [i] {s} p idx (SRDconst [j] w) x:(MOVHBRstoreidx [i-2] {s} p idx w0:(SRDconst [j-16] w) mem))
  1241    && x.Uses == 1
  1242    && clobber(x)
  1243    -> (MOVWBRstoreidx [i-2] {s} p idx w0 mem)
  1244  (MOVHBRstoreidx [i] {s} p idx (SRWconst [16] w) x:(MOVHBRstoreidx [i-2] {s} p idx w mem))
  1245    && x.Uses == 1
  1246    && clobber(x)
  1247    -> (MOVWBRstoreidx [i-2] {s} p idx w mem)
  1248  (MOVHBRstoreidx [i] {s} p idx (SRWconst [j] w) x:(MOVHBRstoreidx [i-2] {s} p idx w0:(SRWconst [j-16] w) mem))
  1249    && x.Uses == 1
  1250    && clobber(x)
  1251    -> (MOVWBRstoreidx [i-2] {s} p idx w0 mem)
  1252  (MOVWBRstoreidx [i] {s} p idx (SRDconst [32] w) x:(MOVWBRstoreidx [i-4] {s} p idx w mem))
  1253    && x.Uses == 1
  1254    && clobber(x)
  1255    -> (MOVDBRstoreidx [i-4] {s} p idx w mem)
  1256  (MOVWBRstoreidx [i] {s} p idx (SRDconst [j] w) x:(MOVWBRstoreidx [i-4] {s} p idx w0:(SRDconst [j-32] w) mem))
  1257    && x.Uses == 1
  1258    && clobber(x)
  1259    -> (MOVDBRstoreidx [i-4] {s} p idx w0 mem)
  1260  
  1261  // Combining byte loads into larger (unaligned) loads.
  1262  
  1263  // Little endian loads.
  1264  
  1265  // b[0] | b[1]<<8 -> load 16-bit, reverse bytes
  1266  (ORW                 x0:(MOVBZload [i]   {s} p mem)
  1267      s0:(SLWconst [8] x1:(MOVBZload [i+1] {s} p mem)))
  1268    && p.Op != OpSB
  1269    && x0.Uses == 1
  1270    && x1.Uses == 1
  1271    && s0.Uses == 1
  1272    && mergePoint(b,x0,x1) != nil
  1273    && clobber(x0)
  1274    && clobber(x1)
  1275    && clobber(s0)
  1276    -> @mergePoint(b,x0,x1) (MOVHZreg (MOVHBRload [i] {s} p mem))
  1277  
  1278  // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 -> load 32-bit, reverse bytes
  1279  (ORW o0:(ORW z0:(MOVHZreg x0:(MOVHBRload [i] {s} p mem))
  1280      s0:(SLWconst [16] x1:(MOVBZload [i+2] {s} p mem)))
  1281      s1:(SLWconst [24] x2:(MOVBZload [i+3] {s} p mem)))
  1282    && p.Op != OpSB
  1283    && z0.Uses == 1
  1284    && x0.Uses == 1
  1285    && x1.Uses == 1
  1286    && x2.Uses == 1
  1287    && s0.Uses == 1
  1288    && s1.Uses == 1
  1289    && o0.Uses == 1
  1290    && mergePoint(b,x0,x1,x2) != nil
  1291    && clobber(z0)
  1292    && clobber(x0)
  1293    && clobber(x1)
  1294    && clobber(x2)
  1295    && clobber(s0)
  1296    && clobber(s1)
  1297    && clobber(o0)
  1298    -> @mergePoint(b,x0,x1,x2) (MOVWBRload [i] {s} p mem)
  1299  
  1300  // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 | b[4]<<32 | b[5]<<40 | b[6]<<48 | b[7]<<56 -> load 64-bit, reverse bytes
  1301  (OR o0:(OR o1:(OR o2:(OR o3:(OR o4:(OR o5:(OR
  1302                        x0:(MOVBZload [i]   {s} p mem)
  1303      s0:(SLDconst [8]  x1:(MOVBZload [i+1] {s} p mem)))
  1304      s1:(SLDconst [16] x2:(MOVBZload [i+2] {s} p mem)))
  1305      s2:(SLDconst [24] x3:(MOVBZload [i+3] {s} p mem)))
  1306      s3:(SLDconst [32] x4:(MOVBZload [i+4] {s} p mem)))
  1307      s4:(SLDconst [40] x5:(MOVBZload [i+5] {s} p mem)))
  1308      s5:(SLDconst [48] x6:(MOVBZload [i+6] {s} p mem)))
  1309      s6:(SLDconst [56] x7:(MOVBZload [i+7] {s} p mem)))
  1310    && p.Op != OpSB
  1311    && x0.Uses == 1
  1312    && x1.Uses == 1
  1313    && x2.Uses == 1
  1314    && x3.Uses == 1
  1315    && x4.Uses == 1
  1316    && x5.Uses == 1
  1317    && x6.Uses == 1
  1318    && x7.Uses == 1
  1319    && s0.Uses == 1
  1320    && s1.Uses == 1
  1321    && s2.Uses == 1
  1322    && s3.Uses == 1
  1323    && s4.Uses == 1
  1324    && s5.Uses == 1
  1325    && s6.Uses == 1
  1326    && o0.Uses == 1
  1327    && o1.Uses == 1
  1328    && o2.Uses == 1
  1329    && o3.Uses == 1
  1330    && o4.Uses == 1
  1331    && o5.Uses == 1
  1332    && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1333    && clobber(x0)
  1334    && clobber(x1)
  1335    && clobber(x2)
  1336    && clobber(x3)
  1337    && clobber(x4)
  1338    && clobber(x5)
  1339    && clobber(x6)
  1340    && clobber(x7)
  1341    && clobber(s0)
  1342    && clobber(s1)
  1343    && clobber(s2)
  1344    && clobber(s3)
  1345    && clobber(s4)
  1346    && clobber(s5)
  1347    && clobber(s6)
  1348    && clobber(o0)
  1349    && clobber(o1)
  1350    && clobber(o2)
  1351    && clobber(o3)
  1352    && clobber(o4)
  1353    && clobber(o5)
  1354    -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDBRload [i] {s} p mem)
  1355  
  1356  // b[0] | b[1]<<8 -> load 16-bit, reverse bytes
  1357  (ORW                 x0:(MOVBZloadidx [i]   {s} p idx mem)
  1358      s0:(SLWconst [8] x1:(MOVBZloadidx [i+1] {s} p idx mem)))
  1359    && x0.Uses == 1
  1360    && x1.Uses == 1
  1361    && s0.Uses == 1
  1362    && mergePoint(b,x0,x1) != nil
  1363    && clobber(x0)
  1364    && clobber(x1)
  1365    && clobber(s0)
  1366    -> @mergePoint(b,x0,x1) (MOVHZreg (MOVHBRloadidx <v.Type> [i] {s} p idx mem))
  1367  
  1368  // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 -> load 32-bit, reverse bytes
  1369  (ORW o0:(ORW z0:(MOVHZreg x0:(MOVHBRloadidx [i] {s} p idx mem))
  1370      s0:(SLWconst [16] x1:(MOVBZloadidx [i+2] {s} p idx mem)))
  1371      s1:(SLWconst [24] x2:(MOVBZloadidx [i+3] {s} p idx mem)))
  1372    && z0.Uses == 1
  1373    && x0.Uses == 1
  1374    && x1.Uses == 1
  1375    && x2.Uses == 1
  1376    && s0.Uses == 1
  1377    && s1.Uses == 1
  1378    && o0.Uses == 1
  1379    && mergePoint(b,x0,x1,x2) != nil
  1380    && clobber(z0)
  1381    && clobber(x0)
  1382    && clobber(x1)
  1383    && clobber(x2)
  1384    && clobber(s0)
  1385    && clobber(s1)
  1386    && clobber(o0)
  1387    -> @mergePoint(b,x0,x1,x2) (MOVWZreg (MOVWBRloadidx <v.Type> [i] {s} p idx mem))
  1388  
  1389  // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 | b[4]<<32 | b[5]<<40 | b[6]<<48 | b[7]<<56 -> load 64-bit, reverse bytes
  1390  (OR o0:(OR o1:(OR o2:(OR o3:(OR o4:(OR o5:(OR
  1391                        x0:(MOVBZloadidx [i]   {s} p idx mem)
  1392      s0:(SLDconst [8]  x1:(MOVBZloadidx [i+1] {s} p idx mem)))
  1393      s1:(SLDconst [16] x2:(MOVBZloadidx [i+2] {s} p idx mem)))
  1394      s2:(SLDconst [24] x3:(MOVBZloadidx [i+3] {s} p idx mem)))
  1395      s3:(SLDconst [32] x4:(MOVBZloadidx [i+4] {s} p idx mem)))
  1396      s4:(SLDconst [40] x5:(MOVBZloadidx [i+5] {s} p idx mem)))
  1397      s5:(SLDconst [48] x6:(MOVBZloadidx [i+6] {s} p idx mem)))
  1398      s6:(SLDconst [56] x7:(MOVBZloadidx [i+7] {s} p idx mem)))
  1399    && x0.Uses == 1
  1400    && x1.Uses == 1
  1401    && x2.Uses == 1
  1402    && x3.Uses == 1
  1403    && x4.Uses == 1
  1404    && x5.Uses == 1
  1405    && x6.Uses == 1
  1406    && x7.Uses == 1
  1407    && s0.Uses == 1
  1408    && s1.Uses == 1
  1409    && s2.Uses == 1
  1410    && s3.Uses == 1
  1411    && s4.Uses == 1
  1412    && s5.Uses == 1
  1413    && s6.Uses == 1
  1414    && o0.Uses == 1
  1415    && o1.Uses == 1
  1416    && o2.Uses == 1
  1417    && o3.Uses == 1
  1418    && o4.Uses == 1
  1419    && o5.Uses == 1
  1420    && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1421    && clobber(x0)
  1422    && clobber(x1)
  1423    && clobber(x2)
  1424    && clobber(x3)
  1425    && clobber(x4)
  1426    && clobber(x5)
  1427    && clobber(x6)
  1428    && clobber(x7)
  1429    && clobber(s0)
  1430    && clobber(s1)
  1431    && clobber(s2)
  1432    && clobber(s3)
  1433    && clobber(s4)
  1434    && clobber(s5)
  1435    && clobber(s6)
  1436    && clobber(o0)
  1437    && clobber(o1)
  1438    && clobber(o2)
  1439    && clobber(o3)
  1440    && clobber(o4)
  1441    && clobber(o5)
  1442    -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDBRloadidx <v.Type> [i] {s} p idx mem)
  1443  
  1444  // Big endian loads.
  1445  
  1446  // b[1] | b[0]<<8 -> load 16-bit
  1447  (ORW                  x0:(MOVBZload [i]   {s} p mem)
  1448      s0:(SLWconst [8] x1:(MOVBZload [i-1] {s} p mem)))
  1449    && p.Op != OpSB
  1450    && x0.Uses == 1
  1451    && x1.Uses == 1
  1452    && s0.Uses == 1
  1453    && mergePoint(b,x0,x1) != nil
  1454    && clobber(x0)
  1455    && clobber(x1)
  1456    && clobber(s0)
  1457    -> @mergePoint(b,x0,x1) (MOVHZload [i-1] {s} p mem)
  1458  
  1459  // b[3] | b[2]<<8 | b[1]<<16 | b[0]<<24 -> load 32-bit
  1460  (ORW o0:(ORW x0:(MOVHZload [i] {s} p mem)
  1461      s0:(SLWconst [16] x1:(MOVBZload [i-1] {s} p mem)))
  1462      s1:(SLWconst [24] x2:(MOVBZload [i-2] {s} p mem)))
  1463    && p.Op != OpSB
  1464    && x0.Uses == 1
  1465    && x1.Uses == 1
  1466    && x2.Uses == 1
  1467    && s0.Uses == 1
  1468    && s1.Uses == 1
  1469    && o0.Uses == 1
  1470    && mergePoint(b,x0,x1,x2) != nil
  1471    && clobber(x0)
  1472    && clobber(x1)
  1473    && clobber(x2)
  1474    && clobber(s0)
  1475    && clobber(s1)
  1476    && clobber(o0)
  1477    -> @mergePoint(b,x0,x1,x2) (MOVWZload [i-2] {s} p mem)
  1478  
  1479  // b[7] | b[6]<<8 | b[5]<<16 | b[4]<<24 | b[3]<<32 | b[2]<<40 | b[1]<<48 | b[0]<<56 -> load 64-bit
  1480  (OR o0:(OR o1:(OR o2:(OR o3:(OR o4:(OR o5:(OR
  1481                        x0:(MOVBZload [i]   {s} p mem)
  1482      s0:(SLDconst [8]  x1:(MOVBZload [i-1] {s} p mem)))
  1483      s1:(SLDconst [16] x2:(MOVBZload [i-2] {s} p mem)))
  1484      s2:(SLDconst [24] x3:(MOVBZload [i-3] {s} p mem)))
  1485      s3:(SLDconst [32] x4:(MOVBZload [i-4] {s} p mem)))
  1486      s4:(SLDconst [40] x5:(MOVBZload [i-5] {s} p mem)))
  1487      s5:(SLDconst [48] x6:(MOVBZload [i-6] {s} p mem)))
  1488      s6:(SLDconst [56] x7:(MOVBZload [i-7] {s} p mem)))
  1489    && p.Op != OpSB
  1490    && x0.Uses == 1
  1491    && x1.Uses == 1
  1492    && x2.Uses == 1
  1493    && x3.Uses == 1
  1494    && x4.Uses == 1
  1495    && x5.Uses == 1
  1496    && x6.Uses == 1
  1497    && x7.Uses == 1
  1498    && s0.Uses == 1
  1499    && s1.Uses == 1
  1500    && s2.Uses == 1
  1501    && s3.Uses == 1
  1502    && s4.Uses == 1
  1503    && s5.Uses == 1
  1504    && s6.Uses == 1
  1505    && o0.Uses == 1
  1506    && o1.Uses == 1
  1507    && o2.Uses == 1
  1508    && o3.Uses == 1
  1509    && o4.Uses == 1
  1510    && o5.Uses == 1
  1511    && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1512    && clobber(x0)
  1513    && clobber(x1)
  1514    && clobber(x2)
  1515    && clobber(x3)
  1516    && clobber(x4)
  1517    && clobber(x5)
  1518    && clobber(x6)
  1519    && clobber(x7)
  1520    && clobber(s0)
  1521    && clobber(s1)
  1522    && clobber(s2)
  1523    && clobber(s3)
  1524    && clobber(s4)
  1525    && clobber(s5)
  1526    && clobber(s6)
  1527    && clobber(o0)
  1528    && clobber(o1)
  1529    && clobber(o2)
  1530    && clobber(o3)
  1531    && clobber(o4)
  1532    && clobber(o5)
  1533    -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDload [i-7] {s} p mem)
  1534  
  1535  // b[1] | b[0]<<8 -> load 16-bit
  1536  (ORW                 x0:(MOVBZloadidx [i]   {s} p idx mem)
  1537      s0:(SLWconst [8] x1:(MOVBZloadidx [i-1] {s} p idx mem)))
  1538    && x0.Uses == 1
  1539    && x1.Uses == 1
  1540    && s0.Uses == 1
  1541    && mergePoint(b,x0,x1) != nil
  1542    && clobber(x0)
  1543    && clobber(x1)
  1544    && clobber(s0)
  1545    -> @mergePoint(b,x0,x1) (MOVHZloadidx <v.Type> [i-1] {s} p idx mem)
  1546  
  1547  // b[3] | b[2]<<8 | b[1]<<16 | b[0]<<24 -> load 32-bit
  1548  (ORW o0:(ORW x0:(MOVHZloadidx [i] {s} p idx mem)
  1549      s0:(SLWconst [16] x1:(MOVBZloadidx [i-1] {s} p idx mem)))
  1550      s1:(SLWconst [24] x2:(MOVBZloadidx [i-2] {s} p idx mem)))
  1551    && x0.Uses == 1
  1552    && x1.Uses == 1
  1553    && x2.Uses == 1
  1554    && s0.Uses == 1
  1555    && s1.Uses == 1
  1556    && o0.Uses == 1
  1557    && mergePoint(b,x0,x1,x2) != nil
  1558    && clobber(x0)
  1559    && clobber(x1)
  1560    && clobber(x2)
  1561    && clobber(s0)
  1562    && clobber(s1)
  1563    && clobber(o0)
  1564    -> @mergePoint(b,x0,x1,x2) (MOVWZloadidx <v.Type> [i-2] {s} p idx mem)
  1565  
  1566  // b[7] | b[6]<<8 | b[5]<<16 | b[4]<<24 | b[3]<<32 | b[2]<<40 | b[1]<<48 | b[0]<<56 -> load 64-bit
  1567  (OR o0:(OR o1:(OR o2:(OR o3:(OR o4:(OR o5:(OR
  1568                        x0:(MOVBZloadidx [i]   {s} p idx mem)
  1569      s0:(SLDconst [8]  x1:(MOVBZloadidx [i-1] {s} p idx mem)))
  1570      s1:(SLDconst [16] x2:(MOVBZloadidx [i-2] {s} p idx mem)))
  1571      s2:(SLDconst [24] x3:(MOVBZloadidx [i-3] {s} p idx mem)))
  1572      s3:(SLDconst [32] x4:(MOVBZloadidx [i-4] {s} p idx mem)))
  1573      s4:(SLDconst [40] x5:(MOVBZloadidx [i-5] {s} p idx mem)))
  1574      s5:(SLDconst [48] x6:(MOVBZloadidx [i-6] {s} p idx mem)))
  1575      s6:(SLDconst [56] x7:(MOVBZloadidx [i-7] {s} p idx mem)))
  1576    && x0.Uses == 1
  1577    && x1.Uses == 1
  1578    && x2.Uses == 1
  1579    && x3.Uses == 1
  1580    && x4.Uses == 1
  1581    && x5.Uses == 1
  1582    && x6.Uses == 1
  1583    && x7.Uses == 1
  1584    && s0.Uses == 1
  1585    && s1.Uses == 1
  1586    && s2.Uses == 1
  1587    && s3.Uses == 1
  1588    && s4.Uses == 1
  1589    && s5.Uses == 1
  1590    && s6.Uses == 1
  1591    && o0.Uses == 1
  1592    && o1.Uses == 1
  1593    && o2.Uses == 1
  1594    && o3.Uses == 1
  1595    && o4.Uses == 1
  1596    && o5.Uses == 1
  1597    && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1598    && clobber(x0)
  1599    && clobber(x1)
  1600    && clobber(x2)
  1601    && clobber(x3)
  1602    && clobber(x4)
  1603    && clobber(x5)
  1604    && clobber(x6)
  1605    && clobber(x7)
  1606    && clobber(s0)
  1607    && clobber(s1)
  1608    && clobber(s2)
  1609    && clobber(s3)
  1610    && clobber(s4)
  1611    && clobber(s5)
  1612    && clobber(s6)
  1613    && clobber(o0)
  1614    && clobber(o1)
  1615    && clobber(o2)
  1616    && clobber(o3)
  1617    && clobber(o4)
  1618    && clobber(o5)
  1619    -> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx <v.Type> [i-7] {s} p idx mem)
  1620  
  1621  // Combine stores into store multiples.
  1622  // 32-bit
  1623  (MOVWstore [i] {s} p w1 x:(MOVWstore [i-4] {s} p w0 mem))
  1624    && p.Op != OpSB
  1625    && x.Uses == 1
  1626    && is20Bit(i-4)
  1627    && clobber(x)
  1628    -> (STM2 [i-4] {s} p w0 w1 mem)
  1629  (MOVWstore [i] {s} p w2 x:(STM2 [i-8] {s} p w0 w1 mem))
  1630    && x.Uses == 1
  1631    && is20Bit(i-8)
  1632    && clobber(x)
  1633    -> (STM3 [i-8] {s} p w0 w1 w2 mem)
  1634  (MOVWstore [i] {s} p w3 x:(STM3 [i-12] {s} p w0 w1 w2 mem))
  1635    && x.Uses == 1
  1636    && is20Bit(i-12)
  1637    && clobber(x)
  1638    -> (STM4 [i-12] {s} p w0 w1 w2 w3 mem)
  1639  (STM2 [i] {s} p w2 w3 x:(STM2 [i-8] {s} p w0 w1 mem))
  1640    && x.Uses == 1
  1641    && is20Bit(i-8)
  1642    && clobber(x)
  1643    -> (STM4 [i-8] {s} p w0 w1 w2 w3 mem)
  1644  // 64-bit
  1645  (MOVDstore [i] {s} p w1 x:(MOVDstore [i-8] {s} p w0 mem))
  1646    && p.Op != OpSB
  1647    && x.Uses == 1
  1648    && is20Bit(i-8)
  1649    && clobber(x)
  1650    -> (STMG2 [i-8] {s} p w0 w1 mem)
  1651  (MOVDstore [i] {s} p w2 x:(STMG2 [i-16] {s} p w0 w1 mem))
  1652    && x.Uses == 1
  1653    && is20Bit(i-16)
  1654    && clobber(x)
  1655    -> (STMG3 [i-16] {s} p w0 w1 w2 mem)
  1656  (MOVDstore [i] {s} p w3 x:(STMG3 [i-24] {s} p w0 w1 w2 mem))
  1657    && x.Uses == 1
  1658    && is20Bit(i-24)
  1659    && clobber(x)
  1660    -> (STMG4 [i-24] {s} p w0 w1 w2 w3 mem)
  1661  (STMG2 [i] {s} p w2 w3 x:(STMG2 [i-16] {s} p w0 w1 mem))
  1662    && x.Uses == 1
  1663    && is20Bit(i-16)
  1664    && clobber(x)
  1665    -> (STMG4 [i-16] {s} p w0 w1 w2 w3 mem)
  1666  
  1667  // Convert 32-bit store multiples into 64-bit stores.
  1668  (STM2 [i] {s} p (SRDconst [32] x) x mem) -> (MOVDstore [i] {s} p x mem)