github.com/ltltlt/go-source-code@v0.0.0-20190830023027-95be009773aa/cmd/compile/internal/ssa/gen/ARM64.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  (AddPtr x y) -> (ADD x y)
     6  (Add64 x y) -> (ADD x y)
     7  (Add32 x y) -> (ADD x y)
     8  (Add16 x y) -> (ADD x y)
     9  (Add8 x y) -> (ADD x y)
    10  (Add32F x y) -> (FADDS x y)
    11  (Add64F x y) -> (FADDD x y)
    12  
    13  (SubPtr x y) -> (SUB x y)
    14  (Sub64 x y) -> (SUB x y)
    15  (Sub32 x y) -> (SUB x y)
    16  (Sub16 x y) -> (SUB x y)
    17  (Sub8 x y) -> (SUB x y)
    18  (Sub32F x y) -> (FSUBS x y)
    19  (Sub64F x y) -> (FSUBD x y)
    20  
    21  (Mul64 x y) -> (MUL x y)
    22  (Mul32 x y) -> (MULW x y)
    23  (Mul16 x y) -> (MULW x y)
    24  (Mul8 x y) -> (MULW x y)
    25  (Mul32F x y) -> (FMULS x y)
    26  (Mul64F x y) -> (FMULD x y)
    27  
    28  (Hmul64 x y) -> (MULH x y)
    29  (Hmul64u x y) -> (UMULH x y)
    30  (Hmul32 x y) -> (SRAconst (MULL <typ.Int64> x y) [32])
    31  (Hmul32u x y) -> (SRAconst (UMULL <typ.UInt64> x y) [32])
    32  
    33  (Div64 x y) -> (DIV x y)
    34  (Div64u x y) -> (UDIV x y)
    35  (Div32 x y) -> (DIVW x y)
    36  (Div32u x y) -> (UDIVW x y)
    37  (Div16 x y) -> (DIVW (SignExt16to32 x) (SignExt16to32 y))
    38  (Div16u x y) -> (UDIVW (ZeroExt16to32 x) (ZeroExt16to32 y))
    39  (Div8 x y) -> (DIVW (SignExt8to32 x) (SignExt8to32 y))
    40  (Div8u x y) -> (UDIVW (ZeroExt8to32 x) (ZeroExt8to32 y))
    41  (Div32F x y) -> (FDIVS x y)
    42  (Div64F x y) -> (FDIVD x y)
    43  
    44  (Mod64 x y) -> (MOD x y)
    45  (Mod64u x y) -> (UMOD x y)
    46  (Mod32 x y) -> (MODW x y)
    47  (Mod32u x y) -> (UMODW x y)
    48  (Mod16 x y) -> (MODW (SignExt16to32 x) (SignExt16to32 y))
    49  (Mod16u x y) -> (UMODW (ZeroExt16to32 x) (ZeroExt16to32 y))
    50  (Mod8 x y) -> (MODW (SignExt8to32 x) (SignExt8to32 y))
    51  (Mod8u x y) -> (UMODW (ZeroExt8to32 x) (ZeroExt8to32 y))
    52  
    53  // (x + y) / 2 with x>=y -> (x - y) / 2 + y
    54  (Avg64u <t> x y) -> (ADD (SRLconst <t> (SUB <t> x y) [1]) y)
    55  
    56  (And64 x y) -> (AND x y)
    57  (And32 x y) -> (AND x y)
    58  (And16 x y) -> (AND x y)
    59  (And8 x y) -> (AND x y)
    60  
    61  (Or64 x y) -> (OR x y)
    62  (Or32 x y) -> (OR x y)
    63  (Or16 x y) -> (OR x y)
    64  (Or8 x y) -> (OR x y)
    65  
    66  (Xor64 x y) -> (XOR x y)
    67  (Xor32 x y) -> (XOR x y)
    68  (Xor16 x y) -> (XOR x y)
    69  (Xor8 x y) -> (XOR x y)
    70  
    71  // unary ops
    72  (Neg64 x) -> (NEG x)
    73  (Neg32 x) -> (NEG x)
    74  (Neg16 x) -> (NEG x)
    75  (Neg8 x) -> (NEG x)
    76  (Neg32F x) -> (FNEGS x)
    77  (Neg64F x) -> (FNEGD x)
    78  
    79  (Com64 x) -> (MVN x)
    80  (Com32 x) -> (MVN x)
    81  (Com16 x) -> (MVN x)
    82  (Com8 x) -> (MVN x)
    83  
    84  (Sqrt x) -> (FSQRTD x)
    85  
    86  (Ctz64 <t> x) -> (CLZ (RBIT <t> x))
    87  (Ctz32 <t> x) -> (CLZW (RBITW <t> x))
    88  
    89  (BitLen64 x) -> (SUB (MOVDconst [64]) (CLZ <typ.Int> x))
    90  
    91  (Bswap64 x) -> (REV x)
    92  (Bswap32 x) -> (REVW x)
    93  
    94  (BitRev64 x) -> (RBIT x)
    95  (BitRev32 x) -> (RBITW x)
    96  (BitRev16 x) -> (SRLconst [48] (RBIT <typ.UInt64> x))
    97  (BitRev8 x) -> (SRLconst [56] (RBIT <typ.UInt64> x))
    98  
    99  // boolean ops -- booleans are represented with 0=false, 1=true
   100  (AndB x y) -> (AND x y)
   101  (OrB x y) -> (OR x y)
   102  (EqB x y) -> (XOR (MOVDconst [1]) (XOR <typ.Bool> x y))
   103  (NeqB x y) -> (XOR x y)
   104  (Not x) -> (XOR (MOVDconst [1]) x)
   105  
   106  // shifts
   107  // hardware instruction uses only the low 6 bits of the shift
   108  // we compare to 64 to ensure Go semantics for large shifts
   109  (Lsh64x64 <t> x y) -> (CSELULT (SLL <t> x y) (MOVDconst <t> [0]) (CMPconst [64] y))
   110  (Lsh64x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   111  (Lsh64x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   112  (Lsh64x8  <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   113  
   114  (Lsh32x64 <t> x y) -> (CSELULT (SLL <t> x y) (MOVDconst <t> [0]) (CMPconst [64] y))
   115  (Lsh32x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   116  (Lsh32x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   117  (Lsh32x8  <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   118  
   119  (Lsh16x64 <t> x y) -> (CSELULT (SLL <t> x y) (MOVDconst <t> [0]) (CMPconst [64] y))
   120  (Lsh16x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   121  (Lsh16x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   122  (Lsh16x8  <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   123  
   124  (Lsh8x64 <t> x y) -> (CSELULT (SLL <t> x y) (MOVDconst <t> [0]) (CMPconst [64] y))
   125  (Lsh8x32 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   126  (Lsh8x16 <t> x y) -> (CSELULT (SLL <t> x (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   127  (Lsh8x8  <t> x y) -> (CSELULT (SLL <t> x (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   128  
   129  (Rsh64Ux64 <t> x y) -> (CSELULT (SRL <t> x y) (MOVDconst <t> [0]) (CMPconst [64] y))
   130  (Rsh64Ux32 <t> x y) -> (CSELULT (SRL <t> x (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   131  (Rsh64Ux16 <t> x y) -> (CSELULT (SRL <t> x (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   132  (Rsh64Ux8  <t> x y) -> (CSELULT (SRL <t> x (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   133  
   134  (Rsh32Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) y) (MOVDconst <t> [0]) (CMPconst [64] y))
   135  (Rsh32Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   136  (Rsh32Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   137  (Rsh32Ux8  <t> x y) -> (CSELULT (SRL <t> (ZeroExt32to64 x) (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   138  
   139  (Rsh16Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) y) (MOVDconst <t> [0]) (CMPconst [64] y))
   140  (Rsh16Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   141  (Rsh16Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   142  (Rsh16Ux8  <t> x y) -> (CSELULT (SRL <t> (ZeroExt16to64 x) (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   143  
   144  (Rsh8Ux64 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) y) (MOVDconst <t> [0]) (CMPconst [64] y))
   145  (Rsh8Ux32 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt32to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt32to64 y)))
   146  (Rsh8Ux16 <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt16to64 y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt16to64 y)))
   147  (Rsh8Ux8  <t> x y) -> (CSELULT (SRL <t> (ZeroExt8to64 x) (ZeroExt8to64  y)) (MOVDconst <t> [0]) (CMPconst [64] (ZeroExt8to64  y)))
   148  
   149  (Rsh64x64 x y) -> (SRA x (CSELULT <y.Type> y (MOVDconst <y.Type> [63]) (CMPconst [64] y)))
   150  (Rsh64x32 x y) -> (SRA x (CSELULT <y.Type> (ZeroExt32to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y))))
   151  (Rsh64x16 x y) -> (SRA x (CSELULT <y.Type> (ZeroExt16to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y))))
   152  (Rsh64x8  x y) -> (SRA x (CSELULT <y.Type> (ZeroExt8to64  y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt8to64  y))))
   153  
   154  (Rsh32x64 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> y (MOVDconst <y.Type> [63]) (CMPconst [64] y)))
   155  (Rsh32x32 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y))))
   156  (Rsh32x16 x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y))))
   157  (Rsh32x8  x y) -> (SRA (SignExt32to64 x) (CSELULT <y.Type> (ZeroExt8to64  y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt8to64  y))))
   158  
   159  (Rsh16x64 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> y (MOVDconst <y.Type> [63]) (CMPconst [64] y)))
   160  (Rsh16x32 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y))))
   161  (Rsh16x16 x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y))))
   162  (Rsh16x8  x y) -> (SRA (SignExt16to64 x) (CSELULT <y.Type> (ZeroExt8to64  y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt8to64  y))))
   163  
   164  (Rsh8x64 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> y (MOVDconst <y.Type> [63]) (CMPconst [64] y)))
   165  (Rsh8x32 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt32to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt32to64 y))))
   166  (Rsh8x16 x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt16to64 y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt16to64 y))))
   167  (Rsh8x8  x y) -> (SRA (SignExt8to64 x) (CSELULT <y.Type> (ZeroExt8to64  y) (MOVDconst <y.Type> [63]) (CMPconst [64] (ZeroExt8to64  y))))
   168  
   169  // constants
   170  (Const64 [val]) -> (MOVDconst [val])
   171  (Const32 [val]) -> (MOVDconst [val])
   172  (Const16 [val]) -> (MOVDconst [val])
   173  (Const8 [val]) -> (MOVDconst [val])
   174  (Const32F [val]) -> (FMOVSconst [val])
   175  (Const64F [val]) -> (FMOVDconst [val])
   176  (ConstNil) -> (MOVDconst [0])
   177  (ConstBool [b]) -> (MOVDconst [b])
   178  
   179  (Slicemask <t> x) -> (SRAconst (NEG <t> x) [63])
   180  
   181  // truncations
   182  // Because we ignore high parts of registers, truncates are just copies.
   183  (Trunc16to8 x) -> x
   184  (Trunc32to8 x) -> x
   185  (Trunc32to16 x) -> x
   186  (Trunc64to8 x) -> x
   187  (Trunc64to16 x) -> x
   188  (Trunc64to32 x) -> x
   189  
   190  // Zero-/Sign-extensions
   191  (ZeroExt8to16 x) -> (MOVBUreg x)
   192  (ZeroExt8to32 x) -> (MOVBUreg x)
   193  (ZeroExt16to32 x) -> (MOVHUreg x)
   194  (ZeroExt8to64 x) -> (MOVBUreg x)
   195  (ZeroExt16to64 x) -> (MOVHUreg x)
   196  (ZeroExt32to64 x) -> (MOVWUreg x)
   197  
   198  (SignExt8to16 x) -> (MOVBreg x)
   199  (SignExt8to32 x) -> (MOVBreg x)
   200  (SignExt16to32 x) -> (MOVHreg x)
   201  (SignExt8to64 x) -> (MOVBreg x)
   202  (SignExt16to64 x) -> (MOVHreg x)
   203  (SignExt32to64 x) -> (MOVWreg x)
   204  
   205  // float <-> int conversion
   206  (Cvt32to32F x) -> (SCVTFWS x)
   207  (Cvt32to64F x) -> (SCVTFWD x)
   208  (Cvt64to32F x) -> (SCVTFS x)
   209  (Cvt64to64F x) -> (SCVTFD x)
   210  (Cvt32Uto32F x) -> (UCVTFWS x)
   211  (Cvt32Uto64F x) -> (UCVTFWD x)
   212  (Cvt64Uto32F x) -> (UCVTFS x)
   213  (Cvt64Uto64F x) -> (UCVTFD x)
   214  (Cvt32Fto32 x) -> (FCVTZSSW x)
   215  (Cvt64Fto32 x) -> (FCVTZSDW x)
   216  (Cvt32Fto64 x) -> (FCVTZSS x)
   217  (Cvt64Fto64 x) -> (FCVTZSD x)
   218  (Cvt32Fto32U x) -> (FCVTZUSW x)
   219  (Cvt64Fto32U x) -> (FCVTZUDW x)
   220  (Cvt32Fto64U x) -> (FCVTZUS x)
   221  (Cvt64Fto64U x) -> (FCVTZUD x)
   222  (Cvt32Fto64F x) -> (FCVTSD x)
   223  (Cvt64Fto32F x) -> (FCVTDS x)
   224  
   225  (Round32F x) -> x
   226  (Round64F x) -> x
   227  
   228  // comparisons
   229  (Eq8 x y)  -> (Equal (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   230  (Eq16 x y) -> (Equal (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   231  (Eq32 x y) -> (Equal (CMPW x y))
   232  (Eq64 x y) -> (Equal (CMP x y))
   233  (EqPtr x y) -> (Equal (CMP x y))
   234  (Eq32F x y) -> (Equal (FCMPS x y))
   235  (Eq64F x y) -> (Equal (FCMPD x y))
   236  
   237  (Neq8 x y)  -> (NotEqual (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   238  (Neq16 x y) -> (NotEqual (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   239  (Neq32 x y) -> (NotEqual (CMPW x y))
   240  (Neq64 x y) -> (NotEqual (CMP x y))
   241  (NeqPtr x y) -> (NotEqual (CMP x y))
   242  (Neq32F x y) -> (NotEqual (FCMPS x y))
   243  (Neq64F x y) -> (NotEqual (FCMPD x y))
   244  
   245  (Less8 x y)  -> (LessThan (CMPW (SignExt8to32 x) (SignExt8to32 y)))
   246  (Less16 x y) -> (LessThan (CMPW (SignExt16to32 x) (SignExt16to32 y)))
   247  (Less32 x y) -> (LessThan (CMPW x y))
   248  (Less64 x y) -> (LessThan (CMP x y))
   249  (Less32F x y) -> (GreaterThan (FCMPS y x)) // reverse operands to work around NaN
   250  (Less64F x y) -> (GreaterThan (FCMPD y x)) // reverse operands to work around NaN
   251  
   252  (Less8U x y)  -> (LessThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   253  (Less16U x y) -> (LessThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   254  (Less32U x y) -> (LessThanU (CMPW x y))
   255  (Less64U x y) -> (LessThanU (CMP x y))
   256  
   257  (Leq8 x y)  -> (LessEqual (CMPW (SignExt8to32 x) (SignExt8to32 y)))
   258  (Leq16 x y) -> (LessEqual (CMPW (SignExt16to32 x) (SignExt16to32 y)))
   259  (Leq32 x y) -> (LessEqual (CMPW x y))
   260  (Leq64 x y) -> (LessEqual (CMP x y))
   261  (Leq32F x y) -> (GreaterEqual (FCMPS y x)) // reverse operands to work around NaN
   262  (Leq64F x y) -> (GreaterEqual (FCMPD y x)) // reverse operands to work around NaN
   263  
   264  (Leq8U x y)  -> (LessEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   265  (Leq16U x y) -> (LessEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   266  (Leq32U x y) -> (LessEqualU (CMPW x y))
   267  (Leq64U x y) -> (LessEqualU (CMP x y))
   268  
   269  (Greater8 x y)  -> (GreaterThan (CMPW (SignExt8to32 x) (SignExt8to32 y)))
   270  (Greater16 x y) -> (GreaterThan (CMPW (SignExt16to32 x) (SignExt16to32 y)))
   271  (Greater32 x y) -> (GreaterThan (CMPW x y))
   272  (Greater64 x y) -> (GreaterThan (CMP x y))
   273  (Greater32F x y) -> (GreaterThan (FCMPS x y))
   274  (Greater64F x y) -> (GreaterThan (FCMPD x y))
   275  
   276  (Greater8U x y)  -> (GreaterThanU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   277  (Greater16U x y) -> (GreaterThanU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   278  (Greater32U x y) -> (GreaterThanU (CMPW x y))
   279  (Greater64U x y) -> (GreaterThanU (CMP x y))
   280  
   281  (Geq8 x y)  -> (GreaterEqual (CMPW (SignExt8to32 x) (SignExt8to32 y)))
   282  (Geq16 x y) -> (GreaterEqual (CMPW (SignExt16to32 x) (SignExt16to32 y)))
   283  (Geq32 x y) -> (GreaterEqual (CMPW x y))
   284  (Geq64 x y) -> (GreaterEqual (CMP x y))
   285  (Geq32F x y) -> (GreaterEqual (FCMPS x y))
   286  (Geq64F x y) -> (GreaterEqual (FCMPD x y))
   287  
   288  (Geq8U x y)  -> (GreaterEqualU (CMPW (ZeroExt8to32 x) (ZeroExt8to32 y)))
   289  (Geq16U x y) -> (GreaterEqualU (CMPW (ZeroExt16to32 x) (ZeroExt16to32 y)))
   290  (Geq32U x y) -> (GreaterEqualU (CMPW x y))
   291  (Geq64U x y) -> (GreaterEqualU (CMP x y))
   292  
   293  (OffPtr [off] ptr:(SP)) -> (MOVDaddr [off] ptr)
   294  (OffPtr [off] ptr) -> (ADDconst [off] ptr)
   295  
   296  (Addr {sym} base) -> (MOVDaddr {sym} base)
   297  
   298  // loads
   299  (Load <t> ptr mem) && t.IsBoolean() -> (MOVBUload ptr mem)
   300  (Load <t> ptr mem) && (is8BitInt(t) && isSigned(t)) -> (MOVBload ptr mem)
   301  (Load <t> ptr mem) && (is8BitInt(t) && !isSigned(t)) -> (MOVBUload ptr mem)
   302  (Load <t> ptr mem) && (is16BitInt(t) && isSigned(t)) -> (MOVHload ptr mem)
   303  (Load <t> ptr mem) && (is16BitInt(t) && !isSigned(t)) -> (MOVHUload ptr mem)
   304  (Load <t> ptr mem) && (is32BitInt(t) && isSigned(t)) -> (MOVWload ptr mem)
   305  (Load <t> ptr mem) && (is32BitInt(t) && !isSigned(t)) -> (MOVWUload ptr mem)
   306  (Load <t> ptr mem) && (is64BitInt(t) || isPtr(t)) -> (MOVDload ptr mem)
   307  (Load <t> ptr mem) && is32BitFloat(t) -> (FMOVSload ptr mem)
   308  (Load <t> ptr mem) && is64BitFloat(t) -> (FMOVDload ptr mem)
   309  
   310  // stores
   311  (Store {t} ptr val mem) && t.(*types.Type).Size() == 1 -> (MOVBstore ptr val mem)
   312  (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVHstore ptr val mem)
   313  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && !is32BitFloat(val.Type) -> (MOVWstore ptr val mem)
   314  (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && !is64BitFloat(val.Type) -> (MOVDstore ptr val mem)
   315  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (FMOVSstore ptr val mem)
   316  (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (FMOVDstore ptr val mem)
   317  
   318  // zeroing
   319  (Zero [0] _ mem) -> mem
   320  (Zero [1] ptr mem) -> (MOVBstore ptr (MOVDconst [0]) mem)
   321  (Zero [2] ptr mem) -> (MOVHstore ptr (MOVDconst [0]) mem)
   322  (Zero [4] ptr mem) -> (MOVWstore ptr (MOVDconst [0]) mem)
   323  (Zero [8] ptr mem) -> (MOVDstore ptr (MOVDconst [0]) mem)
   324  
   325  (Zero [3] ptr mem) ->
   326  	(MOVBstore [2] ptr (MOVDconst [0])
   327  		(MOVHstore ptr (MOVDconst [0]) mem))
   328  (Zero [5] ptr mem) ->
   329  	(MOVBstore [4] ptr (MOVDconst [0])
   330  		(MOVWstore ptr (MOVDconst [0]) mem))
   331  (Zero [6] ptr mem) ->
   332  	(MOVHstore [4] ptr (MOVDconst [0])
   333  		(MOVWstore ptr (MOVDconst [0]) mem))
   334  (Zero [7] ptr mem) ->
   335  	(MOVBstore [6] ptr (MOVDconst [0])
   336  		(MOVHstore [4] ptr (MOVDconst [0])
   337  			(MOVWstore ptr (MOVDconst [0]) mem)))
   338  (Zero [9] ptr mem) ->
   339  	(MOVBstore [8] ptr (MOVDconst [0])
   340  		(MOVDstore ptr (MOVDconst [0]) mem))
   341  (Zero [10] ptr mem) ->
   342  	(MOVHstore [8] ptr (MOVDconst [0])
   343  		(MOVDstore ptr (MOVDconst [0]) mem))
   344  (Zero [11] ptr mem) ->
   345  	(MOVBstore [10] ptr (MOVDconst [0])
   346  		(MOVHstore [8] ptr (MOVDconst [0])
   347  			(MOVDstore ptr (MOVDconst [0]) mem)))
   348  (Zero [12] ptr mem) ->
   349  	(MOVWstore [8] ptr (MOVDconst [0])
   350  		(MOVDstore ptr (MOVDconst [0]) mem))
   351  (Zero [13] ptr mem) ->
   352  	(MOVBstore [12] ptr (MOVDconst [0])
   353  		(MOVWstore [8] ptr (MOVDconst [0])
   354  			(MOVDstore ptr (MOVDconst [0]) mem)))
   355  (Zero [14] ptr mem) ->
   356  	(MOVHstore [12] ptr (MOVDconst [0])
   357  		(MOVWstore [8] ptr (MOVDconst [0])
   358  			(MOVDstore ptr (MOVDconst [0]) mem)))
   359  (Zero [15] ptr mem) ->
   360  	(MOVBstore [14] ptr (MOVDconst [0])
   361  		(MOVHstore [12] ptr (MOVDconst [0])
   362  			(MOVWstore [8] ptr (MOVDconst [0])
   363  				(MOVDstore ptr (MOVDconst [0]) mem))))
   364  (Zero [16] ptr mem) ->
   365  	(STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem)
   366  
   367  (Zero [32] ptr mem) ->
   368  	(STP [16] ptr (MOVDconst [0]) (MOVDconst [0])
   369  		(STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem))
   370  
   371  (Zero [48] ptr mem) ->
   372  	(STP [32] ptr (MOVDconst [0]) (MOVDconst [0])
   373  		(STP [16] ptr (MOVDconst [0]) (MOVDconst [0])
   374  			(STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem)))
   375  
   376  (Zero [64] ptr mem) ->
   377  	(STP [48] ptr (MOVDconst [0]) (MOVDconst [0])
   378  		(STP [32] ptr (MOVDconst [0]) (MOVDconst [0])
   379  			(STP [16] ptr (MOVDconst [0]) (MOVDconst [0])
   380  				(STP [0] ptr (MOVDconst [0]) (MOVDconst [0]) mem))))
   381  
   382  // strip off fractional word zeroing
   383  (Zero [s] ptr mem) && s%16 != 0 && s > 16 ->
   384  	(Zero [s-s%16]
   385  		(OffPtr <ptr.Type> ptr [s%16])
   386  		(Zero [s%16] ptr mem))
   387  
   388  // medium zeroing uses a duff device
   389  // 4, 16, and 64 are magic constants, see runtime/mkduff.go
   390  (Zero [s] ptr mem)
   391  	&& s%16 == 0 && s > 64 && s <= 16*64
   392  	&& !config.noDuffDevice ->
   393  	(DUFFZERO [4 * (64 - int64(s/16))] ptr mem)
   394  
   395  // large zeroing uses a loop
   396  (Zero [s] ptr mem)
   397  	&& s%16 == 0 && (s > 16*64 || config.noDuffDevice) ->
   398  	(LoweredZero
   399  		ptr
   400  		(ADDconst <ptr.Type> [s-16] ptr)
   401  		mem)
   402  
   403  // moves
   404  (Move [0] _ _ mem) -> mem
   405  (Move [1] dst src mem) -> (MOVBstore dst (MOVBUload src mem) mem)
   406  (Move [2] dst src mem) -> (MOVHstore dst (MOVHUload src mem) mem)
   407  (Move [4] dst src mem) -> (MOVWstore dst (MOVWUload src mem) mem)
   408  (Move [8] dst src mem) -> (MOVDstore dst (MOVDload src mem) mem)
   409  
   410  (Move [3] dst src mem) ->
   411  	(MOVBstore [2] dst (MOVBUload [2] src mem)
   412  		(MOVHstore dst (MOVHUload src mem) mem))
   413  (Move [5] dst src mem) ->
   414  	(MOVBstore [4] dst (MOVBUload [4] src mem)
   415  		(MOVWstore dst (MOVWUload src mem) mem))
   416  (Move [6] dst src mem) ->
   417  	(MOVHstore [4] dst (MOVHUload [4] src mem)
   418  		(MOVWstore dst (MOVWUload src mem) mem))
   419  (Move [7] dst src mem) ->
   420  	(MOVBstore [6] dst (MOVBUload [6] src mem)
   421  		(MOVHstore [4] dst (MOVHUload [4] src mem)
   422  			(MOVWstore dst (MOVWUload src mem) mem)))
   423  (Move [12] dst src mem) ->
   424  	(MOVWstore [8] dst (MOVWUload [8] src mem)
   425  		(MOVDstore dst (MOVDload src mem) mem))
   426  (Move [16] dst src mem) ->
   427  	(MOVDstore [8] dst (MOVDload [8] src mem)
   428  		(MOVDstore dst (MOVDload src mem) mem))
   429  (Move [24] dst src mem) ->
   430  	(MOVDstore [16] dst (MOVDload [16] src mem)
   431  		(MOVDstore [8] dst (MOVDload [8] src mem)
   432  			(MOVDstore dst (MOVDload src mem) mem)))
   433  
   434  // strip off fractional word move
   435  (Move [s] dst src mem) && s%8 != 0 && s > 8 ->
   436  	(Move [s%8]
   437  		(OffPtr <dst.Type> dst [s-s%8])
   438  		(OffPtr <src.Type> src [s-s%8])
   439  		(Move [s-s%8] dst src mem))
   440  
   441  // medium move uses a duff device
   442  // 8 and 128 are magic constants, see runtime/mkduff.go
   443  (Move [s] dst src mem)
   444  	&& s%8 == 0 && s > 24 && s <= 8*128
   445  	&& !config.noDuffDevice ->
   446  	(DUFFCOPY [8 * (128 - int64(s/8))] dst src mem)
   447  
   448  // large move uses a loop
   449  (Move [s] dst src mem)
   450  	&& s > 24 && s%8 == 0 ->
   451  	(LoweredMove
   452  		dst
   453  		src
   454  		(ADDconst <src.Type> src [s-8])
   455  		mem)
   456  
   457  // calls
   458  (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem)
   459  (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem)
   460  (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem)
   461  
   462  // checks
   463  (NilCheck ptr mem) -> (LoweredNilCheck ptr mem)
   464  (IsNonNil ptr) -> (NotEqual (CMPconst [0] ptr))
   465  (IsInBounds idx len) -> (LessThanU (CMP idx len))
   466  (IsSliceInBounds idx len) -> (LessEqualU (CMP idx len))
   467  
   468  // pseudo-ops
   469  (GetClosurePtr) -> (LoweredGetClosurePtr)
   470  (GetCallerSP) -> (LoweredGetCallerSP)
   471  (Convert x mem) -> (MOVDconvert x mem)
   472  
   473  // Absorb pseudo-ops into blocks.
   474  (If (Equal cc) yes no) -> (EQ cc yes no)
   475  (If (NotEqual cc) yes no) -> (NE cc yes no)
   476  (If (LessThan cc) yes no) -> (LT cc yes no)
   477  (If (LessThanU cc) yes no) -> (ULT cc yes no)
   478  (If (LessEqual cc) yes no) -> (LE cc yes no)
   479  (If (LessEqualU cc) yes no) -> (ULE cc yes no)
   480  (If (GreaterThan cc) yes no) -> (GT cc yes no)
   481  (If (GreaterThanU cc) yes no) -> (UGT cc yes no)
   482  (If (GreaterEqual cc) yes no) -> (GE cc yes no)
   483  (If (GreaterEqualU cc) yes no) -> (UGE cc yes no)
   484  
   485  (If cond yes no) -> (NZ cond yes no)
   486  
   487  // atomic intrinsics
   488  // Note: these ops do not accept offset.
   489  (AtomicLoad32  ptr mem) -> (LDARW ptr mem)
   490  (AtomicLoad64  ptr mem) -> (LDAR  ptr mem)
   491  (AtomicLoadPtr ptr mem) -> (LDAR  ptr mem)
   492  
   493  (AtomicStore32      ptr val mem) -> (STLRW ptr val mem)
   494  (AtomicStore64      ptr val mem) -> (STLR  ptr val mem)
   495  (AtomicStorePtrNoWB ptr val mem) -> (STLR  ptr val mem)
   496  
   497  (AtomicExchange32 ptr val mem) -> (LoweredAtomicExchange32 ptr val mem)
   498  (AtomicExchange64 ptr val mem) -> (LoweredAtomicExchange64 ptr val mem)
   499  
   500  (AtomicAdd32 ptr val mem) -> (LoweredAtomicAdd32 ptr val mem)
   501  (AtomicAdd64 ptr val mem) -> (LoweredAtomicAdd64 ptr val mem)
   502  
   503  (AtomicCompareAndSwap32 ptr old new_ mem) -> (LoweredAtomicCas32 ptr old new_ mem)
   504  (AtomicCompareAndSwap64 ptr old new_ mem) -> (LoweredAtomicCas64 ptr old new_ mem)
   505  
   506  (AtomicAnd8 ptr val mem) -> (LoweredAtomicAnd8 ptr val mem)
   507  (AtomicOr8  ptr val mem) -> (LoweredAtomicOr8  ptr val mem)
   508  
   509  // Optimizations
   510  
   511  // Absorb boolean tests into block
   512  (NZ (Equal cc) yes no) -> (EQ cc yes no)
   513  (NZ (NotEqual cc) yes no) -> (NE cc yes no)
   514  (NZ (LessThan cc) yes no) -> (LT cc yes no)
   515  (NZ (LessThanU cc) yes no) -> (ULT cc yes no)
   516  (NZ (LessEqual cc) yes no) -> (LE cc yes no)
   517  (NZ (LessEqualU cc) yes no) -> (ULE cc yes no)
   518  (NZ (GreaterThan cc) yes no) -> (GT cc yes no)
   519  (NZ (GreaterThanU cc) yes no) -> (UGT cc yes no)
   520  (NZ (GreaterEqual cc) yes no) -> (GE cc yes no)
   521  (NZ (GreaterEqualU cc) yes no) -> (UGE cc yes no)
   522  
   523  (EQ (CMPconst [0] x) yes no) -> (Z x yes no)
   524  (NE (CMPconst [0] x) yes no) -> (NZ x yes no)
   525  (EQ (CMPWconst [0] x) yes no) -> (ZW x yes no)
   526  (NE (CMPWconst [0] x) yes no) -> (NZW x yes no)
   527  
   528  // Absorb bit-tests into block
   529  (Z  (ANDconst [c] x) yes no) && oneBit(c) -> (TBZ  {ntz(c)} x yes no)
   530  (NZ (ANDconst [c] x) yes no) && oneBit(c) -> (TBNZ {ntz(c)} x yes no)
   531  (ZW  (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBZ  {ntz(int64(uint32(c)))} x yes no)
   532  (NZW (ANDconst [c] x) yes no) && oneBit(int64(uint32(c))) -> (TBNZ {ntz(int64(uint32(c)))} x yes no)
   533  
   534  // fold offset into address
   535  (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) -> (MOVDaddr [off1+off2] {sym} ptr)
   536  
   537  // fold address into load/store
   538  (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   539  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   540  	(MOVBload [off1+off2] {sym} ptr mem)
   541  (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   542  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   543  	(MOVBUload [off1+off2] {sym} ptr mem)
   544  (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   545  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   546  	(MOVHload [off1+off2] {sym} ptr mem)
   547  (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   548  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   549  	(MOVHUload [off1+off2] {sym} ptr mem)
   550  (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   551  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   552  	(MOVWload [off1+off2] {sym} ptr mem)
   553  (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   554  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   555  	(MOVWUload [off1+off2] {sym} ptr mem)
   556  (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   557  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   558  	(MOVDload [off1+off2] {sym} ptr mem)
   559  (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   560  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   561  	(FMOVSload [off1+off2] {sym} ptr mem)
   562  (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   563  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   564  	(FMOVDload [off1+off2] {sym} ptr mem)
   565  
   566  (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   567  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   568  	(MOVBstore [off1+off2] {sym} ptr val mem)
   569  (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   570  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   571  	(MOVHstore [off1+off2] {sym} ptr val mem)
   572  (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   573  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   574  	(MOVWstore [off1+off2] {sym} ptr val mem)
   575  (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   576  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   577  	(MOVDstore [off1+off2] {sym} ptr val mem)
   578  (STP [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) && is32Bit(off1+off2)
   579  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   580  	(STP [off1+off2] {sym} ptr val1 val2 mem)
   581  (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   582  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   583  	(FMOVSstore [off1+off2] {sym} ptr val mem)
   584  (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) && is32Bit(off1+off2)
   585  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   586  	(FMOVDstore [off1+off2] {sym} ptr val mem)
   587  (MOVBstorezero [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   588  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   589  	(MOVBstorezero [off1+off2] {sym} ptr mem)
   590  (MOVHstorezero [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   591  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   592  	(MOVHstorezero [off1+off2] {sym} ptr mem)
   593  (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   594  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   595  	(MOVWstorezero [off1+off2] {sym} ptr mem)
   596  (MOVDstorezero [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   597  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   598  	(MOVDstorezero [off1+off2] {sym} ptr mem)
   599  (MOVQstorezero [off1] {sym} (ADDconst [off2] ptr) mem) && is32Bit(off1+off2)
   600  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   601  	(MOVQstorezero [off1+off2] {sym} ptr mem)
   602  
   603  (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   604  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   605  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   606  	(MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   607  (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   608  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   609  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   610  	(MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   611  (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   612  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   613  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   614  	(MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   615  (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   616  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   617  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   618  	(MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   619  (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   620  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   621  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   622  	(MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   623  (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   624  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   625  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   626  	(MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   627  (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   628  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   629  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   630  	(MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   631  (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   632  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   633  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   634  	(FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   635  (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   636  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   637  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   638  	(FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   639  
   640  (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   641  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   642  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   643  	(MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   644  (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   645  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   646  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   647  	(MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   648  (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   649  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   650  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   651  	(MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   652  (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   653  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   654  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   655  	(MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   656  (STP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem)
   657  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   658  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   659  	(STP [off1+off2] {mergeSym(sym1,sym2)} ptr val1 val2 mem)
   660  (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   661  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   662  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   663  	(FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   664  (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem)
   665  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   666  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   667  	(FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   668  (MOVBstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   669  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   670  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   671  	(MOVBstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   672  (MOVHstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   673  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   674  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   675  	(MOVHstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   676  (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   677  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   678  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   679  	(MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   680  (MOVDstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   681  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   682  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   683  	(MOVDstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   684  (MOVQstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem)
   685  	&& canMergeSym(sym1,sym2) && is32Bit(off1+off2)
   686  	&& (ptr.Op != OpSB || !config.ctxt.Flag_shared) ->
   687  	(MOVQstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   688  
   689  // store zero
   690  (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVBstorezero [off] {sym} ptr mem)
   691  (MOVHstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVHstorezero [off] {sym} ptr mem)
   692  (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVWstorezero [off] {sym} ptr mem)
   693  (MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) -> (MOVDstorezero [off] {sym} ptr mem)
   694  (STP [off] {sym} ptr (MOVDconst [0]) (MOVDconst [0]) mem) -> (MOVQstorezero [off] {sym} ptr mem)
   695  
   696  // replace load from same location as preceding store with zero/sign extension (or copy in case of full width)
   697  // these seem to have bad interaction with other rules, resulting in slower code
   698  //(MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBreg x)
   699  //(MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBUreg x)
   700  //(MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHreg x)
   701  //(MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHUreg x)
   702  //(MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWreg x)
   703  //(MOVWUload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVWUreg x)
   704  //(MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   705  //(FMOVSload [off] {sym} ptr (FMOVSstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   706  //(FMOVDload [off] {sym} ptr (FMOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   707  
   708  (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   709  (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   710  (MOVHload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   711  (MOVHUload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   712  (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   713  (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   714  (MOVDload [off] {sym} ptr (MOVDstorezero [off2] {sym2} ptr2 _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVDconst [0])
   715  
   716  // don't extend after proper load
   717  (MOVBreg x:(MOVBload _ _)) -> (MOVDreg x)
   718  (MOVBUreg x:(MOVBUload _ _)) -> (MOVDreg x)
   719  (MOVHreg x:(MOVBload _ _)) -> (MOVDreg x)
   720  (MOVHreg x:(MOVBUload _ _)) -> (MOVDreg x)
   721  (MOVHreg x:(MOVHload _ _)) -> (MOVDreg x)
   722  (MOVHUreg x:(MOVBUload _ _)) -> (MOVDreg x)
   723  (MOVHUreg x:(MOVHUload _ _)) -> (MOVDreg x)
   724  (MOVWreg x:(MOVBload _ _)) -> (MOVDreg x)
   725  (MOVWreg x:(MOVBUload _ _)) -> (MOVDreg x)
   726  (MOVWreg x:(MOVHload _ _)) -> (MOVDreg x)
   727  (MOVWreg x:(MOVHUload _ _)) -> (MOVDreg x)
   728  (MOVWreg x:(MOVWload _ _)) -> (MOVDreg x)
   729  (MOVWUreg x:(MOVBUload _ _)) -> (MOVDreg x)
   730  (MOVWUreg x:(MOVHUload _ _)) -> (MOVDreg x)
   731  (MOVWUreg x:(MOVWUload _ _)) -> (MOVDreg x)
   732  
   733  // fold double extensions
   734  (MOVBreg x:(MOVBreg _)) -> (MOVDreg x)
   735  (MOVBUreg x:(MOVBUreg _)) -> (MOVDreg x)
   736  (MOVHreg x:(MOVBreg _)) -> (MOVDreg x)
   737  (MOVHreg x:(MOVBUreg _)) -> (MOVDreg x)
   738  (MOVHreg x:(MOVHreg _)) -> (MOVDreg x)
   739  (MOVHUreg x:(MOVBUreg _)) -> (MOVDreg x)
   740  (MOVHUreg x:(MOVHUreg _)) -> (MOVDreg x)
   741  (MOVWreg x:(MOVBreg _)) -> (MOVDreg x)
   742  (MOVWreg x:(MOVBUreg _)) -> (MOVDreg x)
   743  (MOVWreg x:(MOVHreg _)) -> (MOVDreg x)
   744  (MOVWreg x:(MOVHreg _)) -> (MOVDreg x)
   745  (MOVWreg x:(MOVWreg _)) -> (MOVDreg x)
   746  (MOVWUreg x:(MOVBUreg _)) -> (MOVDreg x)
   747  (MOVWUreg x:(MOVHUreg _)) -> (MOVDreg x)
   748  (MOVWUreg x:(MOVWUreg _)) -> (MOVDreg x)
   749  
   750  // don't extend before store
   751  (MOVBstore [off] {sym} ptr (MOVBreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   752  (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   753  (MOVBstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   754  (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   755  (MOVBstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   756  (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   757  (MOVHstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   758  (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   759  (MOVHstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   760  (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   761  (MOVWstore [off] {sym} ptr (MOVWreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   762  (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) -> (MOVWstore [off] {sym} ptr x mem)
   763  
   764  // if a register move has only 1 use, just use the same register without emitting instruction
   765  // MOVDnop doesn't emit instruction, only for ensuring the type.
   766  (MOVDreg x) && x.Uses == 1 -> (MOVDnop x)
   767  
   768  // fold constant into arithmatic ops
   769  (ADD x (MOVDconst [c])) -> (ADDconst [c] x)
   770  (SUB x (MOVDconst [c])) -> (SUBconst [c] x)
   771  (AND x (MOVDconst [c])) -> (ANDconst [c] x)
   772  (OR  x (MOVDconst [c])) -> (ORconst  [c] x)
   773  (XOR x (MOVDconst [c])) -> (XORconst [c] x)
   774  (BIC x (MOVDconst [c])) -> (BICconst [c] x)
   775  
   776  (SLL x (MOVDconst [c])) -> (SLLconst x [c&63]) // Note: I don't think we ever generate bad constant shifts (i.e. c>=64)
   777  (SRL x (MOVDconst [c])) -> (SRLconst x [c&63])
   778  (SRA x (MOVDconst [c])) -> (SRAconst x [c&63])
   779  
   780  (CMP x (MOVDconst [c])) -> (CMPconst [c] x)
   781  (CMP (MOVDconst [c]) x) -> (InvertFlags (CMPconst [c] x))
   782  (CMPW x (MOVDconst [c])) -> (CMPWconst [int64(int32(c))] x)
   783  (CMPW (MOVDconst [c]) x) -> (InvertFlags (CMPWconst [int64(int32(c))] x))
   784  
   785  // mul by constant
   786  (MUL x (MOVDconst [-1])) -> (NEG x)
   787  (MUL _ (MOVDconst [0])) -> (MOVDconst [0])
   788  (MUL x (MOVDconst [1])) -> x
   789  (MUL x (MOVDconst [c])) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x)
   790  (MUL x (MOVDconst [c])) && isPowerOfTwo(c-1) && c >= 3 -> (ADDshiftLL x x [log2(c-1)])
   791  (MUL x (MOVDconst [c])) && isPowerOfTwo(c+1) && c >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)])
   792  (MUL x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1]))
   793  (MUL x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2]))
   794  (MUL x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3]))
   795  (MUL x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3]))
   796  
   797  (MULW x (MOVDconst [c])) && int32(c)==-1 -> (NEG x)
   798  (MULW _ (MOVDconst [c])) && int32(c)==0 -> (MOVDconst [0])
   799  (MULW x (MOVDconst [c])) && int32(c)==1 -> x
   800  (MULW x (MOVDconst [c])) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x)
   801  (MULW x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADDshiftLL x x [log2(c-1)])
   802  (MULW x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (ADDshiftLL (NEG <x.Type> x) x [log2(c+1)])
   803  (MULW x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1]))
   804  (MULW x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2]))
   805  (MULW x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SLLconst [log2(c/7)] (ADDshiftLL <x.Type> (NEG <x.Type> x) x [3]))
   806  (MULW x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3]))
   807  
   808  // div by constant
   809  (UDIV x (MOVDconst [1])) -> x
   810  (UDIV x (MOVDconst [c])) && isPowerOfTwo(c) -> (SRLconst [log2(c)] x)
   811  (UDIVW x (MOVDconst [c])) && uint32(c)==1 -> x
   812  (UDIVW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) -> (SRLconst [log2(c)] x)
   813  (UMOD _ (MOVDconst [1])) -> (MOVDconst [0])
   814  (UMOD x (MOVDconst [c])) && isPowerOfTwo(c) -> (ANDconst [c-1] x)
   815  (UMODW _ (MOVDconst [c])) && uint32(c)==1 -> (MOVDconst [0])
   816  (UMODW x (MOVDconst [c])) && isPowerOfTwo(c) && is32Bit(c) -> (ANDconst [c-1] x)
   817  
   818  // generic simplifications
   819  (ADD x (NEG y)) -> (SUB x y)
   820  (SUB x x) -> (MOVDconst [0])
   821  (AND x x) -> x
   822  (OR  x x) -> x
   823  (XOR x x) -> (MOVDconst [0])
   824  (BIC x x) -> (MOVDconst [0])
   825  (AND x (MVN y)) -> (BIC x y)
   826  (CSELULT x (MOVDconst [0]) flag) -> (CSELULT0 x flag)
   827  (SUB x (SUB y z)) -> (SUB (ADD <v.Type> x z) y)
   828  (SUB (SUB x y) z) -> (SUB x (ADD <y.Type> y z))
   829  
   830  // remove redundant *const ops
   831  (ADDconst [0]  x) -> x
   832  (SUBconst [0]  x) -> x
   833  (ANDconst [0]  _) -> (MOVDconst [0])
   834  (ANDconst [-1] x) -> x
   835  (ORconst  [0]  x) -> x
   836  (ORconst  [-1] _) -> (MOVDconst [-1])
   837  (XORconst [0]  x) -> x
   838  (XORconst [-1] x) -> (MVN x)
   839  (BICconst [0]  x) -> x
   840  (BICconst [-1] _) -> (MOVDconst [0])
   841  
   842  // generic constant folding
   843  (ADDconst [c] (MOVDconst [d]))  -> (MOVDconst [c+d])
   844  (ADDconst [c] (ADDconst [d] x)) -> (ADDconst [c+d] x)
   845  (ADDconst [c] (SUBconst [d] x)) -> (ADDconst [c-d] x)
   846  (SUBconst [c] (MOVDconst [d]))  -> (MOVDconst [d-c])
   847  (SUBconst [c] (SUBconst [d] x)) -> (ADDconst [-c-d] x)
   848  (SUBconst [c] (ADDconst [d] x)) -> (ADDconst [-c+d] x)
   849  (SLLconst [c] (MOVDconst [d]))  -> (MOVDconst [int64(d)<<uint64(c)])
   850  (SRLconst [c] (MOVDconst [d]))  -> (MOVDconst [int64(uint64(d)>>uint64(c))])
   851  (SRAconst [c] (MOVDconst [d]))  -> (MOVDconst [int64(d)>>uint64(c)])
   852  (MUL   (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c*d])
   853  (MULW  (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)*int32(d))])
   854  (DIV   (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(c)/int64(d)])
   855  (UDIV  (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint64(c)/uint64(d))])
   856  (DIVW  (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)/int32(d))])
   857  (UDIVW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint32(c)/uint32(d))])
   858  (MOD   (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(c)%int64(d)])
   859  (UMOD  (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint64(c)%uint64(d))])
   860  (MODW  (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)%int32(d))])
   861  (UMODW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint32(c)%uint32(d))])
   862  (ANDconst [c] (MOVDconst [d]))  -> (MOVDconst [c&d])
   863  (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c&d] x)
   864  (ORconst  [c] (MOVDconst [d]))  -> (MOVDconst [c|d])
   865  (ORconst  [c] (ORconst [d] x))  -> (ORconst [c|d] x)
   866  (XORconst [c] (MOVDconst [d]))  -> (MOVDconst [c^d])
   867  (XORconst [c] (XORconst [d] x)) -> (XORconst [c^d] x)
   868  (BICconst [c] (MOVDconst [d]))  -> (MOVDconst [d&^c])
   869  (MVN (MOVDconst [c])) -> (MOVDconst [^c])
   870  (NEG (MOVDconst [c])) -> (MOVDconst [-c])
   871  (MOVBreg  (MOVDconst [c])) -> (MOVDconst [int64(int8(c))])
   872  (MOVBUreg (MOVDconst [c])) -> (MOVDconst [int64(uint8(c))])
   873  (MOVHreg  (MOVDconst [c])) -> (MOVDconst [int64(int16(c))])
   874  (MOVHUreg (MOVDconst [c])) -> (MOVDconst [int64(uint16(c))])
   875  (MOVWreg  (MOVDconst [c])) -> (MOVDconst [int64(int32(c))])
   876  (MOVWUreg (MOVDconst [c])) -> (MOVDconst [int64(uint32(c))])
   877  (MOVDreg  (MOVDconst [c])) -> (MOVDconst [c])
   878  
   879  // constant comparisons
   880  (CMPconst  (MOVDconst [x]) [y]) && x==y -> (FlagEQ)
   881  (CMPconst  (MOVDconst [x]) [y]) && int64(x)<int64(y) && uint64(x)<uint64(y) -> (FlagLT_ULT)
   882  (CMPconst  (MOVDconst [x]) [y]) && int64(x)<int64(y) && uint64(x)>uint64(y) -> (FlagLT_UGT)
   883  (CMPconst  (MOVDconst [x]) [y]) && int64(x)>int64(y) && uint64(x)<uint64(y) -> (FlagGT_ULT)
   884  (CMPconst  (MOVDconst [x]) [y]) && int64(x)>int64(y) && uint64(x)>uint64(y) -> (FlagGT_UGT)
   885  (CMPWconst (MOVDconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ)
   886  (CMPWconst (MOVDconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT)
   887  (CMPWconst (MOVDconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT)
   888  (CMPWconst (MOVDconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT)
   889  (CMPWconst (MOVDconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT)
   890  
   891  // other known comparisons
   892  (CMPconst (MOVBUreg _) [c]) && 0xff < c -> (FlagLT_ULT)
   893  (CMPconst (MOVHUreg _) [c]) && 0xffff < c -> (FlagLT_ULT)
   894  (CMPconst (MOVWUreg _) [c]) && 0xffffffff < c -> (FlagLT_ULT)
   895  (CMPconst (ANDconst _ [m]) [n]) && 0 <= m && m < n -> (FlagLT_ULT)
   896  (CMPconst (SRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 63 && (1<<uint64(64-c)) <= uint64(n) -> (FlagLT_ULT)
   897  (CMPWconst (MOVBUreg _) [c]) && 0xff < int32(c) -> (FlagLT_ULT)
   898  (CMPWconst (MOVHUreg _) [c]) && 0xffff < int32(c) -> (FlagLT_ULT)
   899  
   900  // absorb flag constants into branches
   901  (EQ (FlagEQ) yes no) -> (First nil yes no)
   902  (EQ (FlagLT_ULT) yes no) -> (First nil no yes)
   903  (EQ (FlagLT_UGT) yes no) -> (First nil no yes)
   904  (EQ (FlagGT_ULT) yes no) -> (First nil no yes)
   905  (EQ (FlagGT_UGT) yes no) -> (First nil no yes)
   906  
   907  (NE (FlagEQ) yes no) -> (First nil no yes)
   908  (NE (FlagLT_ULT) yes no) -> (First nil yes no)
   909  (NE (FlagLT_UGT) yes no) -> (First nil yes no)
   910  (NE (FlagGT_ULT) yes no) -> (First nil yes no)
   911  (NE (FlagGT_UGT) yes no) -> (First nil yes no)
   912  
   913  (LT (FlagEQ) yes no) -> (First nil no yes)
   914  (LT (FlagLT_ULT) yes no) -> (First nil yes no)
   915  (LT (FlagLT_UGT) yes no) -> (First nil yes no)
   916  (LT (FlagGT_ULT) yes no) -> (First nil no yes)
   917  (LT (FlagGT_UGT) yes no) -> (First nil no yes)
   918  
   919  (LE (FlagEQ) yes no) -> (First nil yes no)
   920  (LE (FlagLT_ULT) yes no) -> (First nil yes no)
   921  (LE (FlagLT_UGT) yes no) -> (First nil yes no)
   922  (LE (FlagGT_ULT) yes no) -> (First nil no yes)
   923  (LE (FlagGT_UGT) yes no) -> (First nil no yes)
   924  
   925  (GT (FlagEQ) yes no) -> (First nil no yes)
   926  (GT (FlagLT_ULT) yes no) -> (First nil no yes)
   927  (GT (FlagLT_UGT) yes no) -> (First nil no yes)
   928  (GT (FlagGT_ULT) yes no) -> (First nil yes no)
   929  (GT (FlagGT_UGT) yes no) -> (First nil yes no)
   930  
   931  (GE (FlagEQ) yes no) -> (First nil yes no)
   932  (GE (FlagLT_ULT) yes no) -> (First nil no yes)
   933  (GE (FlagLT_UGT) yes no) -> (First nil no yes)
   934  (GE (FlagGT_ULT) yes no) -> (First nil yes no)
   935  (GE (FlagGT_UGT) yes no) -> (First nil yes no)
   936  
   937  (ULT (FlagEQ) yes no) -> (First nil no yes)
   938  (ULT (FlagLT_ULT) yes no) -> (First nil yes no)
   939  (ULT (FlagLT_UGT) yes no) -> (First nil no yes)
   940  (ULT (FlagGT_ULT) yes no) -> (First nil yes no)
   941  (ULT (FlagGT_UGT) yes no) -> (First nil no yes)
   942  
   943  (ULE (FlagEQ) yes no) -> (First nil yes no)
   944  (ULE (FlagLT_ULT) yes no) -> (First nil yes no)
   945  (ULE (FlagLT_UGT) yes no) -> (First nil no yes)
   946  (ULE (FlagGT_ULT) yes no) -> (First nil yes no)
   947  (ULE (FlagGT_UGT) yes no) -> (First nil no yes)
   948  
   949  (UGT (FlagEQ) yes no) -> (First nil no yes)
   950  (UGT (FlagLT_ULT) yes no) -> (First nil no yes)
   951  (UGT (FlagLT_UGT) yes no) -> (First nil yes no)
   952  (UGT (FlagGT_ULT) yes no) -> (First nil no yes)
   953  (UGT (FlagGT_UGT) yes no) -> (First nil yes no)
   954  
   955  (UGE (FlagEQ) yes no) -> (First nil yes no)
   956  (UGE (FlagLT_ULT) yes no) -> (First nil no yes)
   957  (UGE (FlagLT_UGT) yes no) -> (First nil yes no)
   958  (UGE (FlagGT_ULT) yes no) -> (First nil no yes)
   959  (UGE (FlagGT_UGT) yes no) -> (First nil yes no)
   960  
   961  (Z (MOVDconst [0]) yes no) -> (First nil yes no)
   962  (Z (MOVDconst [c]) yes no) && c != 0 -> (First nil no yes)
   963  (NZ (MOVDconst [0]) yes no) -> (First nil no yes)
   964  (NZ (MOVDconst [c]) yes no) && c != 0 -> (First nil yes no)
   965  (ZW (MOVDconst [c]) yes no) && int32(c) == 0 -> (First nil yes no)
   966  (ZW (MOVDconst [c]) yes no) && int32(c) != 0 -> (First nil no yes)
   967  (NZW (MOVDconst [c]) yes no) && int32(c) == 0 -> (First nil no yes)
   968  (NZW (MOVDconst [c]) yes no) && int32(c) != 0 -> (First nil yes no)
   969  
   970  // absorb InvertFlags into branches
   971  (LT (InvertFlags cmp) yes no) -> (GT cmp yes no)
   972  (GT (InvertFlags cmp) yes no) -> (LT cmp yes no)
   973  (LE (InvertFlags cmp) yes no) -> (GE cmp yes no)
   974  (GE (InvertFlags cmp) yes no) -> (LE cmp yes no)
   975  (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no)
   976  (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no)
   977  (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no)
   978  (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no)
   979  (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no)
   980  (NE (InvertFlags cmp) yes no) -> (NE cmp yes no)
   981  
   982  // absorb flag constants into boolean values
   983  (Equal (FlagEQ)) -> (MOVDconst [1])
   984  (Equal (FlagLT_ULT)) -> (MOVDconst [0])
   985  (Equal (FlagLT_UGT)) -> (MOVDconst [0])
   986  (Equal (FlagGT_ULT)) -> (MOVDconst [0])
   987  (Equal (FlagGT_UGT)) -> (MOVDconst [0])
   988  
   989  (NotEqual (FlagEQ)) -> (MOVDconst [0])
   990  (NotEqual (FlagLT_ULT)) -> (MOVDconst [1])
   991  (NotEqual (FlagLT_UGT)) -> (MOVDconst [1])
   992  (NotEqual (FlagGT_ULT)) -> (MOVDconst [1])
   993  (NotEqual (FlagGT_UGT)) -> (MOVDconst [1])
   994  
   995  (LessThan (FlagEQ)) -> (MOVDconst [0])
   996  (LessThan (FlagLT_ULT)) -> (MOVDconst [1])
   997  (LessThan (FlagLT_UGT)) -> (MOVDconst [1])
   998  (LessThan (FlagGT_ULT)) -> (MOVDconst [0])
   999  (LessThan (FlagGT_UGT)) -> (MOVDconst [0])
  1000  
  1001  (LessThanU (FlagEQ)) -> (MOVDconst [0])
  1002  (LessThanU (FlagLT_ULT)) -> (MOVDconst [1])
  1003  (LessThanU (FlagLT_UGT)) -> (MOVDconst [0])
  1004  (LessThanU (FlagGT_ULT)) -> (MOVDconst [1])
  1005  (LessThanU (FlagGT_UGT)) -> (MOVDconst [0])
  1006  
  1007  (LessEqual (FlagEQ)) -> (MOVDconst [1])
  1008  (LessEqual (FlagLT_ULT)) -> (MOVDconst [1])
  1009  (LessEqual (FlagLT_UGT)) -> (MOVDconst [1])
  1010  (LessEqual (FlagGT_ULT)) -> (MOVDconst [0])
  1011  (LessEqual (FlagGT_UGT)) -> (MOVDconst [0])
  1012  
  1013  (LessEqualU (FlagEQ)) -> (MOVDconst [1])
  1014  (LessEqualU (FlagLT_ULT)) -> (MOVDconst [1])
  1015  (LessEqualU (FlagLT_UGT)) -> (MOVDconst [0])
  1016  (LessEqualU (FlagGT_ULT)) -> (MOVDconst [1])
  1017  (LessEqualU (FlagGT_UGT)) -> (MOVDconst [0])
  1018  
  1019  (GreaterThan (FlagEQ)) -> (MOVDconst [0])
  1020  (GreaterThan (FlagLT_ULT)) -> (MOVDconst [0])
  1021  (GreaterThan (FlagLT_UGT)) -> (MOVDconst [0])
  1022  (GreaterThan (FlagGT_ULT)) -> (MOVDconst [1])
  1023  (GreaterThan (FlagGT_UGT)) -> (MOVDconst [1])
  1024  
  1025  (GreaterThanU (FlagEQ)) -> (MOVDconst [0])
  1026  (GreaterThanU (FlagLT_ULT)) -> (MOVDconst [0])
  1027  (GreaterThanU (FlagLT_UGT)) -> (MOVDconst [1])
  1028  (GreaterThanU (FlagGT_ULT)) -> (MOVDconst [0])
  1029  (GreaterThanU (FlagGT_UGT)) -> (MOVDconst [1])
  1030  
  1031  (GreaterEqual (FlagEQ)) -> (MOVDconst [1])
  1032  (GreaterEqual (FlagLT_ULT)) -> (MOVDconst [0])
  1033  (GreaterEqual (FlagLT_UGT)) -> (MOVDconst [0])
  1034  (GreaterEqual (FlagGT_ULT)) -> (MOVDconst [1])
  1035  (GreaterEqual (FlagGT_UGT)) -> (MOVDconst [1])
  1036  
  1037  (GreaterEqualU (FlagEQ)) -> (MOVDconst [1])
  1038  (GreaterEqualU (FlagLT_ULT)) -> (MOVDconst [0])
  1039  (GreaterEqualU (FlagLT_UGT)) -> (MOVDconst [1])
  1040  (GreaterEqualU (FlagGT_ULT)) -> (MOVDconst [0])
  1041  (GreaterEqualU (FlagGT_UGT)) -> (MOVDconst [1])
  1042  
  1043  // absorb InvertFlags into boolean values
  1044  (Equal (InvertFlags x)) -> (Equal x)
  1045  (NotEqual (InvertFlags x)) -> (NotEqual x)
  1046  (LessThan (InvertFlags x)) -> (GreaterThan x)
  1047  (LessThanU (InvertFlags x)) -> (GreaterThanU x)
  1048  (GreaterThan (InvertFlags x)) -> (LessThan x)
  1049  (GreaterThanU (InvertFlags x)) -> (LessThanU x)
  1050  (LessEqual (InvertFlags x)) -> (GreaterEqual x)
  1051  (LessEqualU (InvertFlags x)) -> (GreaterEqualU x)
  1052  (GreaterEqual (InvertFlags x)) -> (LessEqual x)
  1053  (GreaterEqualU (InvertFlags x)) -> (LessEqualU x)
  1054  
  1055  // Boolean-generating instructions always
  1056  // zero upper bit of the register; no need to zero-extend
  1057  (MOVBUreg x) && x.Type.IsBoolean() -> (MOVDreg x)
  1058  
  1059  // absorb flag constants into conditional instructions
  1060  (CSELULT _ y (FlagEQ)) -> y
  1061  (CSELULT x _ (FlagLT_ULT)) -> x
  1062  (CSELULT _ y (FlagLT_UGT)) -> y
  1063  (CSELULT x _ (FlagGT_ULT)) -> x
  1064  (CSELULT _ y (FlagGT_UGT)) -> y
  1065  (CSELULT0 _ (FlagEQ)) -> (MOVDconst [0])
  1066  (CSELULT0 x (FlagLT_ULT)) -> x
  1067  (CSELULT0 _ (FlagLT_UGT)) -> (MOVDconst [0])
  1068  (CSELULT0 x (FlagGT_ULT)) -> x
  1069  (CSELULT0 _ (FlagGT_UGT)) -> (MOVDconst [0])
  1070  
  1071  // absorb shifts into ops
  1072  (ADD x (SLLconst [c] y)) -> (ADDshiftLL x y [c])
  1073  (ADD x (SRLconst [c] y)) -> (ADDshiftRL x y [c])
  1074  (ADD x (SRAconst [c] y)) -> (ADDshiftRA x y [c])
  1075  (SUB x (SLLconst [c] y)) -> (SUBshiftLL x y [c])
  1076  (SUB x (SRLconst [c] y)) -> (SUBshiftRL x y [c])
  1077  (SUB x (SRAconst [c] y)) -> (SUBshiftRA x y [c])
  1078  (AND x (SLLconst [c] y)) -> (ANDshiftLL x y [c])
  1079  (AND x (SRLconst [c] y)) -> (ANDshiftRL x y [c])
  1080  (AND x (SRAconst [c] y)) -> (ANDshiftRA x y [c])
  1081  (OR  x (SLLconst [c] y)) -> (ORshiftLL  x y [c]) // useful for combined load
  1082  (OR  x (SRLconst [c] y)) -> (ORshiftRL  x y [c])
  1083  (OR  x (SRAconst [c] y)) -> (ORshiftRA  x y [c])
  1084  (XOR x (SLLconst [c] y)) -> (XORshiftLL x y [c])
  1085  (XOR x (SRLconst [c] y)) -> (XORshiftRL x y [c])
  1086  (XOR x (SRAconst [c] y)) -> (XORshiftRA x y [c])
  1087  (BIC x (SLLconst [c] y)) -> (BICshiftLL x y [c])
  1088  (BIC x (SRLconst [c] y)) -> (BICshiftRL x y [c])
  1089  (BIC x (SRAconst [c] y)) -> (BICshiftRA x y [c])
  1090  (CMP x (SLLconst [c] y)) -> (CMPshiftLL x y [c])
  1091  (CMP (SLLconst [c] y) x) -> (InvertFlags (CMPshiftLL x y [c]))
  1092  (CMP x (SRLconst [c] y)) -> (CMPshiftRL x y [c])
  1093  (CMP (SRLconst [c] y) x) -> (InvertFlags (CMPshiftRL x y [c]))
  1094  (CMP x (SRAconst [c] y)) -> (CMPshiftRA x y [c])
  1095  (CMP (SRAconst [c] y) x) -> (InvertFlags (CMPshiftRA x y [c]))
  1096  
  1097  // prefer *const ops to *shift ops
  1098  (ADDshiftLL (MOVDconst [c]) x [d]) -> (ADDconst [c] (SLLconst <x.Type> x [d]))
  1099  (ADDshiftRL (MOVDconst [c]) x [d]) -> (ADDconst [c] (SRLconst <x.Type> x [d]))
  1100  (ADDshiftRA (MOVDconst [c]) x [d]) -> (ADDconst [c] (SRAconst <x.Type> x [d]))
  1101  (ANDshiftLL (MOVDconst [c]) x [d]) -> (ANDconst [c] (SLLconst <x.Type> x [d]))
  1102  (ANDshiftRL (MOVDconst [c]) x [d]) -> (ANDconst [c] (SRLconst <x.Type> x [d]))
  1103  (ANDshiftRA (MOVDconst [c]) x [d]) -> (ANDconst [c] (SRAconst <x.Type> x [d]))
  1104  (ORshiftLL  (MOVDconst [c]) x [d]) -> (ORconst  [c] (SLLconst <x.Type> x [d]))
  1105  (ORshiftRL  (MOVDconst [c]) x [d]) -> (ORconst  [c] (SRLconst <x.Type> x [d]))
  1106  (ORshiftRA  (MOVDconst [c]) x [d]) -> (ORconst  [c] (SRAconst <x.Type> x [d]))
  1107  (XORshiftLL (MOVDconst [c]) x [d]) -> (XORconst [c] (SLLconst <x.Type> x [d]))
  1108  (XORshiftRL (MOVDconst [c]) x [d]) -> (XORconst [c] (SRLconst <x.Type> x [d]))
  1109  (XORshiftRA (MOVDconst [c]) x [d]) -> (XORconst [c] (SRAconst <x.Type> x [d]))
  1110  (CMPshiftLL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SLLconst <x.Type> x [d])))
  1111  (CMPshiftRL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRLconst <x.Type> x [d])))
  1112  (CMPshiftRA (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRAconst <x.Type> x [d])))
  1113  
  1114  // constant folding in *shift ops
  1115  (ADDshiftLL x (MOVDconst [c]) [d]) -> (ADDconst x [int64(uint64(c)<<uint64(d))])
  1116  (ADDshiftRL x (MOVDconst [c]) [d]) -> (ADDconst x [int64(uint64(c)>>uint64(d))])
  1117  (ADDshiftRA x (MOVDconst [c]) [d]) -> (ADDconst x [int64(int64(c)>>uint64(d))])
  1118  (SUBshiftLL x (MOVDconst [c]) [d]) -> (SUBconst x [int64(uint64(c)<<uint64(d))])
  1119  (SUBshiftRL x (MOVDconst [c]) [d]) -> (SUBconst x [int64(uint64(c)>>uint64(d))])
  1120  (SUBshiftRA x (MOVDconst [c]) [d]) -> (SUBconst x [int64(int64(c)>>uint64(d))])
  1121  (ANDshiftLL x (MOVDconst [c]) [d]) -> (ANDconst x [int64(uint64(c)<<uint64(d))])
  1122  (ANDshiftRL x (MOVDconst [c]) [d]) -> (ANDconst x [int64(uint64(c)>>uint64(d))])
  1123  (ANDshiftRA x (MOVDconst [c]) [d]) -> (ANDconst x [int64(int64(c)>>uint64(d))])
  1124  (ORshiftLL  x (MOVDconst [c]) [d]) -> (ORconst  x [int64(uint64(c)<<uint64(d))])
  1125  (ORshiftRL  x (MOVDconst [c]) [d]) -> (ORconst  x [int64(uint64(c)>>uint64(d))])
  1126  (ORshiftRA  x (MOVDconst [c]) [d]) -> (ORconst  x [int64(int64(c)>>uint64(d))])
  1127  (XORshiftLL x (MOVDconst [c]) [d]) -> (XORconst x [int64(uint64(c)<<uint64(d))])
  1128  (XORshiftRL x (MOVDconst [c]) [d]) -> (XORconst x [int64(uint64(c)>>uint64(d))])
  1129  (XORshiftRA x (MOVDconst [c]) [d]) -> (XORconst x [int64(int64(c)>>uint64(d))])
  1130  (BICshiftLL x (MOVDconst [c]) [d]) -> (BICconst x [int64(uint64(c)<<uint64(d))])
  1131  (BICshiftRL x (MOVDconst [c]) [d]) -> (BICconst x [int64(uint64(c)>>uint64(d))])
  1132  (BICshiftRA x (MOVDconst [c]) [d]) -> (BICconst x [int64(int64(c)>>uint64(d))])
  1133  (CMPshiftLL x (MOVDconst [c]) [d]) -> (CMPconst x [int64(uint64(c)<<uint64(d))])
  1134  (CMPshiftRL x (MOVDconst [c]) [d]) -> (CMPconst x [int64(uint64(c)>>uint64(d))])
  1135  (CMPshiftRA x (MOVDconst [c]) [d]) -> (CMPconst x [int64(int64(c)>>uint64(d))])
  1136  
  1137  // simplification with *shift ops
  1138  (SUBshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1139  (SUBshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1140  (SUBshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1141  (ANDshiftLL x y:(SLLconst x [c]) [d]) && c==d -> y
  1142  (ANDshiftRL x y:(SRLconst x [c]) [d]) && c==d -> y
  1143  (ANDshiftRA x y:(SRAconst x [c]) [d]) && c==d -> y
  1144  (ORshiftLL  x y:(SLLconst x [c]) [d]) && c==d -> y
  1145  (ORshiftRL  x y:(SRLconst x [c]) [d]) && c==d -> y
  1146  (ORshiftRA  x y:(SRAconst x [c]) [d]) && c==d -> y
  1147  (XORshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1148  (XORshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1149  (XORshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1150  (BICshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1151  (BICshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1152  (BICshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [0])
  1153  
  1154  // Generate rotates
  1155  (ADDshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x)
  1156  ( ORshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x)
  1157  (XORshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x)
  1158  (ADDshiftRL [c] (SLLconst x [64-c]) x) -> (RORconst [   c] x)
  1159  ( ORshiftRL [c] (SLLconst x [64-c]) x) -> (RORconst [   c] x)
  1160  (XORshiftRL [c] (SLLconst x [64-c]) x) -> (RORconst [   c] x)
  1161  
  1162  (ADDshiftLL <t> [c] (SRLconst (MOVWUreg x) [32-c]) x) && c < 32 && t.Size() == 4 -> (RORWconst [32-c] x)
  1163  ( ORshiftLL <t> [c] (SRLconst (MOVWUreg x) [32-c]) x) && c < 32 && t.Size() == 4 -> (RORWconst [32-c] x)
  1164  (XORshiftLL <t> [c] (SRLconst (MOVWUreg x) [32-c]) x) && c < 32 && t.Size() == 4 -> (RORWconst [32-c] x)
  1165  (ADDshiftRL <t> [c] (SLLconst x [32-c]) (MOVWUreg x)) && c < 32 && t.Size() == 4 -> (RORWconst [   c] x)
  1166  ( ORshiftRL <t> [c] (SLLconst x [32-c]) (MOVWUreg x)) && c < 32 && t.Size() == 4 -> (RORWconst [   c] x)
  1167  (XORshiftRL <t> [c] (SLLconst x [32-c]) (MOVWUreg x)) && c < 32 && t.Size() == 4 -> (RORWconst [   c] x)
  1168  
  1169  // Generic rules rewrite certain AND to a pair of shifts.
  1170  // However, on ARM64 the bitmask can fit into an instruction.
  1171  // Rewrite it back to AND.
  1172  (SRLconst [c] (SLLconst [c] x)) && 0 < c && c < 64 -> (ANDconst [1<<uint(64-c)-1] x) // mask out high bits
  1173  (SLLconst [c] (SRLconst [c] x)) && 0 < c && c < 64 -> (ANDconst [^(1<<uint(c)-1)] x) // mask out low bits
  1174  
  1175  // do combined loads
  1176  // little endian loads
  1177  // b[0] | b[1]<<8 -> load 16-bit
  1178  (ORshiftLL <t> [8]
  1179  	y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))
  1180  	y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem)))
  1181  	&& i1 == i0+1
  1182  	&& x0.Uses == 1 && x1.Uses == 1
  1183  	&& y0.Uses == 1 && y1.Uses == 1
  1184  	&& mergePoint(b,x0,x1) != nil
  1185  	&& clobber(x0) && clobber(x1)
  1186  	&& clobber(y0) && clobber(y1)
  1187  	-> @mergePoint(b,x0,x1) (MOVHUload <t> {s} (OffPtr <p.Type> [i0] p) mem)
  1188  
  1189  // b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24 -> load 32-bit
  1190  (ORshiftLL <t> [24] o0:(ORshiftLL [16]
  1191  	            x0:(MOVHUload [i0] {s} p mem)
  1192  	y1:(MOVDnop x1:(MOVBUload [i2] {s} p mem)))
  1193  	y2:(MOVDnop x2:(MOVBUload [i3] {s} p mem)))
  1194  	&& i2 == i0+2
  1195  	&& i3 == i0+3
  1196  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1
  1197  	&& y1.Uses == 1 && y2.Uses == 1
  1198  	&& o0.Uses == 1
  1199  	&& mergePoint(b,x0,x1,x2) != nil
  1200  	&& clobber(x0) && clobber(x1) && clobber(x2)
  1201  	&& clobber(y1) && clobber(y2)
  1202  	&& clobber(o0)
  1203  	-> @mergePoint(b,x0,x1,x2) (MOVWUload <t> {s} (OffPtr <p.Type> [i0] p) mem)
  1204  
  1205  // 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
  1206  (ORshiftLL <t> [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32]
  1207  	            x0:(MOVWUload [i0] {s} p mem)
  1208  	y1:(MOVDnop x1:(MOVBUload [i4] {s} p mem)))
  1209  	y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem)))
  1210  	y3:(MOVDnop x3:(MOVBUload [i6] {s} p mem)))
  1211  	y4:(MOVDnop x4:(MOVBUload [i7] {s} p mem)))
  1212  	&& i4 == i0+4
  1213  	&& i5 == i0+5
  1214  	&& i6 == i0+6
  1215  	&& i7 == i0+7
  1216  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1
  1217  	&& y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1
  1218  	&& o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1
  1219  	&& mergePoint(b,x0,x1,x2,x3,x4) != nil
  1220  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4)
  1221  	&& clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4)
  1222  	&& clobber(o0) && clobber(o1) && clobber(o2)
  1223  	-> @mergePoint(b,x0,x1,x2,x3,x4) (MOVDload <t> {s} (OffPtr <p.Type> [i0] p) mem)
  1224  
  1225  // b[3]<<24 | b[2]<<16 | b[1]<<8 | b[0] -> load 32-bit
  1226  (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24]
  1227  	y0:(MOVDnop x0:(MOVBUload [i3] {s} p mem)))
  1228  	y1:(MOVDnop x1:(MOVBUload [i2] {s} p mem)))
  1229  	y2:(MOVDnop x2:(MOVBUload [i1] {s} p mem)))
  1230  	y3:(MOVDnop x3:(MOVBUload [i0] {s} p mem)))
  1231  	&& i1 == i0+1
  1232  	&& i2 == i0+2
  1233  	&& i3 == i0+3
  1234  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1
  1235  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1
  1236  	&& o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1
  1237  	&& mergePoint(b,x0,x1,x2,x3) != nil
  1238  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3)
  1239  	&& clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3)
  1240  	&& clobber(o0) && clobber(o1) && clobber(s0)
  1241  	-> @mergePoint(b,x0,x1,x2,x3) (MOVWUload <t> {s} (OffPtr <p.Type> [i0] p) mem)
  1242  
  1243  // b[7]<<56 | b[6]<<48 | b[5]<<40 | b[4]<<32 | b[3]<<24 | b[2]<<16 | b[1]<<8 | b[0] -> load 64-bit, reverse
  1244  (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56]
  1245  	y0:(MOVDnop x0:(MOVBUload [i7] {s} p mem)))
  1246  	y1:(MOVDnop x1:(MOVBUload [i6] {s} p mem)))
  1247  	y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem)))
  1248  	y3:(MOVDnop x3:(MOVBUload [i4] {s} p mem)))
  1249  	y4:(MOVDnop x4:(MOVBUload [i3] {s} p mem)))
  1250  	y5:(MOVDnop x5:(MOVBUload [i2] {s} p mem)))
  1251  	y6:(MOVDnop x6:(MOVBUload [i1] {s} p mem)))
  1252  	y7:(MOVDnop x7:(MOVBUload [i0] {s} p mem)))
  1253  	&& i1 == i0+1
  1254  	&& i2 == i0+2
  1255  	&& i3 == i0+3
  1256  	&& i4 == i0+4
  1257  	&& i5 == i0+5
  1258  	&& i6 == i0+6
  1259  	&& i7 == i0+7
  1260  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1
  1261  	&& x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1
  1262  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1
  1263  	&& y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1
  1264  	&& o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1
  1265  	&& o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1
  1266  	&& mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1267  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3)
  1268  	&& clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7)
  1269  	&& clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3)
  1270  	&& clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7)
  1271  	&& clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3)
  1272  	&& clobber(o4) && clobber(o5) && clobber(s0)
  1273  	-> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i0] p) mem))
  1274  
  1275  // big endian loads
  1276  // b[1] | b[0]<<8 -> load 16-bit, reverse
  1277  (ORshiftLL <t> [8]
  1278  	y0:(MOVDnop x0:(MOVBUload [i1] {s} p mem))
  1279  	y1:(MOVDnop x1:(MOVBUload [i0] {s} p mem)))
  1280  	&& i1 == i0+1
  1281  	&& x0.Uses == 1 && x1.Uses == 1
  1282  	&& y0.Uses == 1 && y1.Uses == 1
  1283  	&& mergePoint(b,x0,x1) != nil
  1284  	&& clobber(x0) && clobber(x1)
  1285  	&& clobber(y0) && clobber(y1)
  1286  	-> @mergePoint(b,x0,x1) (REV16W <t> (MOVHUload <t> [i0] {s} p mem))
  1287  
  1288  // b[3] | b[2]<<8 | b[1]<<16 | b[0]<<24 -> load 32-bit, reverse
  1289  (ORshiftLL <t> [24] o0:(ORshiftLL [16]
  1290  	y0:(REV16W  x0:(MOVHUload [i2] {s} p mem))
  1291  	y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem)))
  1292  	y2:(MOVDnop x2:(MOVBUload [i0] {s} p mem)))
  1293  	&& i1 == i0+1
  1294  	&& i2 == i0+2
  1295  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1
  1296  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1
  1297  	&& o0.Uses == 1
  1298  	&& mergePoint(b,x0,x1,x2) != nil
  1299  	&& clobber(x0) && clobber(x1) && clobber(x2)
  1300  	&& clobber(y0) && clobber(y1) && clobber(y2)
  1301  	&& clobber(o0)
  1302  	-> @mergePoint(b,x0,x1,x2) (REVW <t> (MOVWUload <t> {s} (OffPtr <p.Type> [i0] p) mem))
  1303  
  1304  // 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, reverse
  1305  (ORshiftLL <t> [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32]
  1306  	y0:(REVW    x0:(MOVWUload [i4] {s} p mem))
  1307  	y1:(MOVDnop x1:(MOVBUload [i3] {s} p mem)))
  1308  	y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem)))
  1309  	y3:(MOVDnop x3:(MOVBUload [i1] {s} p mem)))
  1310  	y4:(MOVDnop x4:(MOVBUload [i0] {s} p mem)))
  1311  	&& i1 == i0+1
  1312  	&& i2 == i0+2
  1313  	&& i3 == i0+3
  1314  	&& i4 == i0+4
  1315  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1
  1316  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1
  1317  	&& o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1
  1318  	&& mergePoint(b,x0,x1,x2,x3,x4) != nil
  1319  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4)
  1320  	&& clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4)
  1321  	&& clobber(o0) && clobber(o1) && clobber(o2)
  1322  	-> @mergePoint(b,x0,x1,x2,x3,x4) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i0] p) mem))
  1323  
  1324  // b[0]<<24 | b[1]<<16 | b[2]<<8 | b[3] -> load 32-bit, reverse
  1325  (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24]
  1326  	y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem)))
  1327  	y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem)))
  1328  	y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem)))
  1329  	y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem)))
  1330  	&& i1 == i0+1
  1331  	&& i2 == i0+2
  1332  	&& i3 == i0+3
  1333  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1
  1334  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1
  1335  	&& o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1
  1336  	&& mergePoint(b,x0,x1,x2,x3) != nil
  1337  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3)
  1338  	&& clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3)
  1339  	&& clobber(o0) && clobber(o1) && clobber(s0)
  1340  	-> @mergePoint(b,x0,x1,x2,x3) (REVW <t> (MOVWUload <t> {s} (OffPtr <p.Type> [i0] p) mem))
  1341  
  1342  // b[0]<<56 | b[1]<<48 | b[2]<<40 | b[3]<<32 | b[4]<<24 | b[5]<<16 | b[6]<<8 | b[7] -> load 64-bit, reverse
  1343  (OR <t> o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56]
  1344  	y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem)))
  1345  	y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem)))
  1346  	y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem)))
  1347  	y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem)))
  1348  	y4:(MOVDnop x4:(MOVBUload [i4] {s} p mem)))
  1349  	y5:(MOVDnop x5:(MOVBUload [i5] {s} p mem)))
  1350  	y6:(MOVDnop x6:(MOVBUload [i6] {s} p mem)))
  1351  	y7:(MOVDnop x7:(MOVBUload [i7] {s} p mem)))
  1352  	&& i1 == i0+1
  1353  	&& i2 == i0+2
  1354  	&& i3 == i0+3
  1355  	&& i4 == i0+4
  1356  	&& i5 == i0+5
  1357  	&& i6 == i0+6
  1358  	&& i7 == i0+7
  1359  	&& x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1
  1360  	&& x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1
  1361  	&& y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1
  1362  	&& y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1
  1363  	&& o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1
  1364  	&& o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1
  1365  	&& mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil
  1366  	&& clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3)
  1367  	&& clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7)
  1368  	&& clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3)
  1369  	&& clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7)
  1370  	&& clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3)
  1371  	&& clobber(o4) && clobber(o5) && clobber(s0)
  1372  	-> @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV <t> (MOVDload <t> {s} (OffPtr <p.Type> [i0] p) mem))