github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/compile/internal/ssa/gen/ARM.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  (Add(Ptr|32|16|8) x y) -> (ADD x y)
     6  (Add(32|64)F x y) -> (ADD(F|D) x y)
     7  (Add32carry x y) -> (ADDS x y)
     8  (Add32withcarry x y c) -> (ADC x y c)
     9  
    10  (Sub(Ptr|32|16|8) x y) -> (SUB x y)
    11  (Sub(32|64)F x y) -> (SUB(F|D) x y)
    12  (Sub32carry x y) -> (SUBS x y)
    13  (Sub32withcarry x y c) -> (SBC x y c)
    14  
    15  (Mul(32|16|8) x y) -> (MUL x y)
    16  (Mul(32|64)F x y) -> (MUL(F|D) x y)
    17  (Hmul(32|32u) x y) -> (HMU(L|LU) x y)
    18  (Mul32uhilo x y) -> (MULLU x y)
    19  
    20  (Div32 x y) ->
    21  	(SUB (XOR <typ.UInt32>                                                        // negate the result if one operand is negative
    22  		(Select0 <typ.UInt32> (CALLudiv
    23  			(SUB <typ.UInt32> (XOR x <typ.UInt32> (Signmask x)) (Signmask x))   // negate x if negative
    24  			(SUB <typ.UInt32> (XOR y <typ.UInt32> (Signmask y)) (Signmask y)))) // negate y if negative
    25  		(Signmask (XOR <typ.UInt32> x y))) (Signmask (XOR <typ.UInt32> x y)))
    26  (Div32u x y) -> (Select0 <typ.UInt32> (CALLudiv x y))
    27  (Div16 x y) -> (Div32 (SignExt16to32 x) (SignExt16to32 y))
    28  (Div16u x y) -> (Div32u (ZeroExt16to32 x) (ZeroExt16to32 y))
    29  (Div8 x y) -> (Div32 (SignExt8to32 x) (SignExt8to32 y))
    30  (Div8u x y) -> (Div32u (ZeroExt8to32 x) (ZeroExt8to32 y))
    31  (Div(32|64)F x y) -> (DIV(F|D) x y)
    32  
    33  (Mod32 x y) ->
    34  	(SUB (XOR <typ.UInt32>                                                        // negate the result if x is negative
    35  		(Select1 <typ.UInt32> (CALLudiv
    36  			(SUB <typ.UInt32> (XOR <typ.UInt32> x (Signmask x)) (Signmask x))   // negate x if negative
    37  			(SUB <typ.UInt32> (XOR <typ.UInt32> y (Signmask y)) (Signmask y)))) // negate y if negative
    38  		(Signmask x)) (Signmask x))
    39  (Mod32u x y) -> (Select1 <typ.UInt32> (CALLudiv x y))
    40  (Mod16 x y) -> (Mod32 (SignExt16to32 x) (SignExt16to32 y))
    41  (Mod16u x y) -> (Mod32u (ZeroExt16to32 x) (ZeroExt16to32 y))
    42  (Mod8 x y) -> (Mod32 (SignExt8to32 x) (SignExt8to32 y))
    43  (Mod8u x y) -> (Mod32u (ZeroExt8to32 x) (ZeroExt8to32 y))
    44  
    45  // (x + y) / 2 with x>=y -> (x - y) / 2 + y
    46  (Avg32u <t> x y) -> (ADD (SRLconst <t> (SUB <t> x y) [1]) y)
    47  
    48  (And(32|16|8) x y) -> (AND x y)
    49  (Or(32|16|8) x y) -> (OR x y)
    50  (Xor(32|16|8) x y) -> (XOR x y)
    51  
    52  // unary ops
    53  (Neg(32|16|8) x) -> (RSBconst [0] x)
    54  (Neg(32|64)F x) -> (NEG(F|D) x)
    55  
    56  (Com(32|16|8) x) -> (MVN x)
    57  
    58  (Sqrt x) -> (SQRTD x)
    59  (Abs x) -> (ABSD x)
    60  
    61  // TODO: optimize this for ARMv5 and ARMv6
    62  (Ctz32NonZero x) -> (Ctz32 x)
    63  (Ctz16NonZero x) -> (Ctz32 x)
    64  (Ctz8NonZero x) -> (Ctz32 x)
    65  
    66  // count trailing zero for ARMv5 and ARMv6
    67  // 32 - CLZ(x&-x - 1)
    68  (Ctz32 <t> x) && objabi.GOARM<=6 ->
    69  	(RSBconst [32] (CLZ <t> (SUBconst <t> (AND <t> x (RSBconst <t> [0] x)) [1])))
    70  (Ctz16 <t> x) && objabi.GOARM<=6 ->
    71  	(RSBconst [32] (CLZ <t> (SUBconst <typ.UInt32> (AND <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x) (RSBconst <typ.UInt32> [0] (ORconst <typ.UInt32> [0x10000] x))) [1])))
    72  (Ctz8 <t> x) && objabi.GOARM<=6 ->
    73  	(RSBconst [32] (CLZ <t> (SUBconst <typ.UInt32> (AND <typ.UInt32> (ORconst <typ.UInt32> [0x100] x) (RSBconst <typ.UInt32> [0] (ORconst <typ.UInt32> [0x100] x))) [1])))
    74  
    75  // count trailing zero for ARMv7
    76  (Ctz32 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <t> x))
    77  (Ctz16 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x10000] x)))
    78  (Ctz8 <t> x) && objabi.GOARM==7 -> (CLZ <t> (RBIT <typ.UInt32> (ORconst <typ.UInt32> [0x100] x)))
    79  
    80  // bit length
    81  (BitLen32 <t> x) -> (RSBconst [32] (CLZ <t> x))
    82  
    83  // byte swap for ARMv5
    84  // let (a, b, c, d) be the bytes of x from high to low
    85  // t1 = x right rotate 16 bits -- (c,   d,   a,   b  )
    86  // t2 = x ^ t1                 -- (a^c, b^d, a^c, b^d)
    87  // t3 = t2 &^ 0xff0000         -- (a^c, 0,   a^c, b^d)
    88  // t4 = t3 >> 8                -- (0,   a^c, 0,   a^c)
    89  // t5 = x right rotate 8 bits  -- (d,   a,   b,   c  )
    90  // result = t4 ^ t5            -- (d,   c,   b,   a  )
    91  // using shifted ops this can be done in 4 instructions.
    92  (Bswap32 <t> x) && objabi.GOARM==5 ->
    93  	(XOR <t>
    94  		(SRLconst <t> (BICconst <t> (XOR <t> x (SRRconst <t> [16] x)) [0xff0000]) [8])
    95  		(SRRconst <t> x [8]))
    96  
    97  // byte swap for ARMv6 and above
    98  (Bswap32 x) && objabi.GOARM>=6 -> (REV x)
    99  
   100  // boolean ops -- booleans are represented with 0=false, 1=true
   101  (AndB x y) -> (AND x y)
   102  (OrB x y) -> (OR x y)
   103  (EqB x y) -> (XORconst [1] (XOR <typ.Bool> x y))
   104  (NeqB x y) -> (XOR x y)
   105  (Not x) -> (XORconst [1] x)
   106  
   107  // shifts
   108  // hardware instruction uses only the low byte of the shift
   109  // we compare to 256 to ensure Go semantics for large shifts
   110  (Lsh32x32 x y) -> (CMOVWHSconst (SLL <x.Type> x y) (CMPconst [256] y) [0])
   111  (Lsh32x16 x y) -> (CMOVWHSconst (SLL <x.Type> x (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   112  (Lsh32x8  x y) -> (SLL x (ZeroExt8to32 y))
   113  
   114  (Lsh16x32 x y) -> (CMOVWHSconst (SLL <x.Type> x y) (CMPconst [256] y) [0])
   115  (Lsh16x16 x y) -> (CMOVWHSconst (SLL <x.Type> x (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   116  (Lsh16x8  x y) -> (SLL x (ZeroExt8to32 y))
   117  
   118  (Lsh8x32 x y) -> (CMOVWHSconst (SLL <x.Type> x y) (CMPconst [256] y) [0])
   119  (Lsh8x16 x y) -> (CMOVWHSconst (SLL <x.Type> x (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   120  (Lsh8x8  x y) -> (SLL x (ZeroExt8to32 y))
   121  
   122  (Rsh32Ux32 x y) -> (CMOVWHSconst (SRL <x.Type> x y) (CMPconst [256] y) [0])
   123  (Rsh32Ux16 x y) -> (CMOVWHSconst (SRL <x.Type> x (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   124  (Rsh32Ux8  x y) -> (SRL x (ZeroExt8to32 y))
   125  
   126  (Rsh16Ux32 x y) -> (CMOVWHSconst (SRL <x.Type> (ZeroExt16to32 x) y) (CMPconst [256] y) [0])
   127  (Rsh16Ux16 x y) -> (CMOVWHSconst (SRL <x.Type> (ZeroExt16to32 x) (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   128  (Rsh16Ux8  x y) -> (SRL (ZeroExt16to32 x) (ZeroExt8to32 y))
   129  
   130  (Rsh8Ux32 x y) -> (CMOVWHSconst (SRL <x.Type> (ZeroExt8to32 x) y) (CMPconst [256] y) [0])
   131  (Rsh8Ux16 x y) -> (CMOVWHSconst (SRL <x.Type> (ZeroExt8to32 x) (ZeroExt16to32 y)) (CMPconst [256] (ZeroExt16to32 y)) [0])
   132  (Rsh8Ux8  x y) -> (SRL (ZeroExt8to32 x) (ZeroExt8to32 y))
   133  
   134  (Rsh32x32 x y) -> (SRAcond x y (CMPconst [256] y))
   135  (Rsh32x16 x y) -> (SRAcond x (ZeroExt16to32 y) (CMPconst [256] (ZeroExt16to32 y)))
   136  (Rsh32x8  x y) -> (SRA x (ZeroExt8to32 y))
   137  
   138  (Rsh16x32 x y) -> (SRAcond (SignExt16to32 x) y (CMPconst [256] y))
   139  (Rsh16x16 x y) -> (SRAcond (SignExt16to32 x) (ZeroExt16to32 y) (CMPconst [256] (ZeroExt16to32 y)))
   140  (Rsh16x8  x y) -> (SRA (SignExt16to32 x) (ZeroExt8to32 y))
   141  
   142  (Rsh8x32 x y) -> (SRAcond (SignExt8to32 x) y (CMPconst [256] y))
   143  (Rsh8x16 x y) -> (SRAcond (SignExt8to32 x) (ZeroExt16to32 y) (CMPconst [256] (ZeroExt16to32 y)))
   144  (Rsh8x8  x y) -> (SRA (SignExt8to32 x) (ZeroExt8to32 y))
   145  
   146  // constant shifts
   147  // generic opt rewrites all constant shifts to shift by Const64
   148  (Lsh32x64 x (Const64 [c])) && uint64(c) < 32 -> (SLLconst x [c])
   149  (Rsh32x64 x (Const64 [c])) && uint64(c) < 32 -> (SRAconst x [c])
   150  (Rsh32Ux64 x (Const64 [c])) && uint64(c) < 32 -> (SRLconst x [c])
   151  (Lsh16x64 x (Const64 [c])) && uint64(c) < 16 -> (SLLconst x [c])
   152  (Rsh16x64 x (Const64 [c])) && uint64(c) < 16 -> (SRAconst (SLLconst <typ.UInt32> x [16]) [c+16])
   153  (Rsh16Ux64 x (Const64 [c])) && uint64(c) < 16 -> (SRLconst (SLLconst <typ.UInt32> x [16]) [c+16])
   154  (Lsh8x64 x (Const64 [c])) && uint64(c) < 8 -> (SLLconst x [c])
   155  (Rsh8x64 x (Const64 [c])) && uint64(c) < 8 -> (SRAconst (SLLconst <typ.UInt32> x [24]) [c+24])
   156  (Rsh8Ux64 x (Const64 [c])) && uint64(c) < 8 -> (SRLconst (SLLconst <typ.UInt32> x [24]) [c+24])
   157  
   158  // large constant shifts
   159  (Lsh32x64 _ (Const64 [c])) && uint64(c) >= 32 -> (Const32 [0])
   160  (Rsh32Ux64 _ (Const64 [c])) && uint64(c) >= 32 -> (Const32 [0])
   161  (Lsh16x64 _ (Const64 [c])) && uint64(c) >= 16 -> (Const16 [0])
   162  (Rsh16Ux64 _ (Const64 [c])) && uint64(c) >= 16 -> (Const16 [0])
   163  (Lsh8x64 _ (Const64 [c])) && uint64(c) >= 8 -> (Const8 [0])
   164  (Rsh8Ux64 _ (Const64 [c])) && uint64(c) >= 8 -> (Const8 [0])
   165  
   166  // large constant signed right shift, we leave the sign bit
   167  (Rsh32x64 x (Const64 [c])) && uint64(c) >= 32 -> (SRAconst x [31])
   168  (Rsh16x64 x (Const64 [c])) && uint64(c) >= 16 -> (SRAconst (SLLconst <typ.UInt32> x [16]) [31])
   169  (Rsh8x64 x (Const64 [c])) && uint64(c) >= 8 -> (SRAconst (SLLconst <typ.UInt32> x [24]) [31])
   170  
   171  // constants
   172  (Const8 [val]) -> (MOVWconst [val])
   173  (Const16 [val]) -> (MOVWconst [val])
   174  (Const32 [val]) -> (MOVWconst [val])
   175  (Const32F [val]) -> (MOVFconst [val])
   176  (Const64F [val]) -> (MOVDconst [val])
   177  (ConstNil) -> (MOVWconst [0])
   178  (ConstBool [b]) -> (MOVWconst [b])
   179  
   180  // truncations
   181  // Because we ignore high parts of registers, truncates are just copies.
   182  (Trunc16to8 x) -> x
   183  (Trunc32to8 x) -> x
   184  (Trunc32to16 x) -> x
   185  
   186  // Zero-/Sign-extensions
   187  (ZeroExt8to16 x) -> (MOVBUreg x)
   188  (ZeroExt8to32 x) -> (MOVBUreg x)
   189  (ZeroExt16to32 x) -> (MOVHUreg x)
   190  
   191  (SignExt8to16 x) -> (MOVBreg x)
   192  (SignExt8to32 x) -> (MOVBreg x)
   193  (SignExt16to32 x) -> (MOVHreg x)
   194  
   195  (Signmask x) -> (SRAconst x [31])
   196  (Zeromask x) -> (SRAconst (RSBshiftRL <typ.Int32> x x [1]) [31]) // sign bit of uint32(x)>>1 - x
   197  (Slicemask <t> x) -> (SRAconst (RSBconst <t> [0] x) [31])
   198  
   199  // float <-> int conversion
   200  (Cvt32to32F x) -> (MOVWF x)
   201  (Cvt32to64F x) -> (MOVWD x)
   202  (Cvt32Uto32F x) -> (MOVWUF x)
   203  (Cvt32Uto64F x) -> (MOVWUD x)
   204  (Cvt32Fto32 x) -> (MOVFW x)
   205  (Cvt64Fto32 x) -> (MOVDW x)
   206  (Cvt32Fto32U x) -> (MOVFWU x)
   207  (Cvt64Fto32U x) -> (MOVDWU x)
   208  (Cvt32Fto64F x) -> (MOVFD x)
   209  (Cvt64Fto32F x) -> (MOVDF x)
   210  
   211  (Round(32|64)F x) -> x
   212  
   213  // fused-multiply-add
   214  (FMA x y z) -> (FMULAD z x y)
   215  
   216  // comparisons
   217  (Eq8 x y)  -> (Equal (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   218  (Eq16 x y) -> (Equal (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   219  (Eq32 x y) -> (Equal (CMP x y))
   220  (EqPtr x y) -> (Equal (CMP x y))
   221  (Eq(32|64)F x y) -> (Equal (CMP(F|D) x y))
   222  
   223  (Neq8 x y)  -> (NotEqual (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   224  (Neq16 x y) -> (NotEqual (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   225  (Neq32 x y) -> (NotEqual (CMP x y))
   226  (NeqPtr x y) -> (NotEqual (CMP x y))
   227  (Neq(32|64)F x y) -> (NotEqual (CMP(F|D) x y))
   228  
   229  (Less8 x y)  -> (LessThan (CMP (SignExt8to32 x) (SignExt8to32 y)))
   230  (Less16 x y) -> (LessThan (CMP (SignExt16to32 x) (SignExt16to32 y)))
   231  (Less32 x y) -> (LessThan (CMP x y))
   232  (Less(32|64)F x y) -> (GreaterThan (CMP(F|D) y x)) // reverse operands to work around NaN
   233  
   234  (Less8U x y)  -> (LessThanU (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   235  (Less16U x y) -> (LessThanU (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   236  (Less32U x y) -> (LessThanU (CMP x y))
   237  
   238  (Leq8 x y)  -> (LessEqual (CMP (SignExt8to32 x) (SignExt8to32 y)))
   239  (Leq16 x y) -> (LessEqual (CMP (SignExt16to32 x) (SignExt16to32 y)))
   240  (Leq32 x y) -> (LessEqual (CMP x y))
   241  (Leq(32|64)F x y) -> (GreaterEqual (CMP(F|D) y x)) // reverse operands to work around NaN
   242  
   243  (Leq8U x y)  -> (LessEqualU (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   244  (Leq16U x y) -> (LessEqualU (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   245  (Leq32U x y) -> (LessEqualU (CMP x y))
   246  
   247  (Greater8 x y)  -> (GreaterThan (CMP (SignExt8to32 x) (SignExt8to32 y)))
   248  (Greater16 x y) -> (GreaterThan (CMP (SignExt16to32 x) (SignExt16to32 y)))
   249  (Greater32 x y) -> (GreaterThan (CMP x y))
   250  (Greater(32|64)F x y) -> (GreaterThan (CMP(F|D) x y))
   251  
   252  (Greater8U x y)  -> (GreaterThanU (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   253  (Greater16U x y) -> (GreaterThanU (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   254  (Greater32U x y) -> (GreaterThanU (CMP x y))
   255  
   256  (Geq8 x y)  -> (GreaterEqual (CMP (SignExt8to32 x) (SignExt8to32 y)))
   257  (Geq16 x y) -> (GreaterEqual (CMP (SignExt16to32 x) (SignExt16to32 y)))
   258  (Geq32 x y) -> (GreaterEqual (CMP x y))
   259  (Geq(32|64)F x y) -> (GreaterEqual (CMP(F|D) x y))
   260  
   261  (Geq8U x y)  -> (GreaterEqualU (CMP (ZeroExt8to32 x) (ZeroExt8to32 y)))
   262  (Geq16U x y) -> (GreaterEqualU (CMP (ZeroExt16to32 x) (ZeroExt16to32 y)))
   263  (Geq32U x y) -> (GreaterEqualU (CMP x y))
   264  
   265  (OffPtr [off] ptr:(SP)) -> (MOVWaddr [off] ptr)
   266  (OffPtr [off] ptr) -> (ADDconst [off] ptr)
   267  
   268  (Addr {sym} base) -> (MOVWaddr {sym} base)
   269  (LocalAddr {sym} base _) -> (MOVWaddr {sym} base)
   270  
   271  // loads
   272  (Load <t> ptr mem) && t.IsBoolean() -> (MOVBUload ptr mem)
   273  (Load <t> ptr mem) && (is8BitInt(t) && isSigned(t)) -> (MOVBload ptr mem)
   274  (Load <t> ptr mem) && (is8BitInt(t) && !isSigned(t)) -> (MOVBUload ptr mem)
   275  (Load <t> ptr mem) && (is16BitInt(t) && isSigned(t)) -> (MOVHload ptr mem)
   276  (Load <t> ptr mem) && (is16BitInt(t) && !isSigned(t)) -> (MOVHUload ptr mem)
   277  (Load <t> ptr mem) && (is32BitInt(t) || isPtr(t)) -> (MOVWload ptr mem)
   278  (Load <t> ptr mem) && is32BitFloat(t) -> (MOVFload ptr mem)
   279  (Load <t> ptr mem) && is64BitFloat(t) -> (MOVDload ptr mem)
   280  
   281  // stores
   282  (Store {t} ptr val mem) && t.(*types.Type).Size() == 1 -> (MOVBstore ptr val mem)
   283  (Store {t} ptr val mem) && t.(*types.Type).Size() == 2 -> (MOVHstore ptr val mem)
   284  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && !is32BitFloat(val.Type) -> (MOVWstore ptr val mem)
   285  (Store {t} ptr val mem) && t.(*types.Type).Size() == 4 && is32BitFloat(val.Type) -> (MOVFstore ptr val mem)
   286  (Store {t} ptr val mem) && t.(*types.Type).Size() == 8 && is64BitFloat(val.Type) -> (MOVDstore ptr val mem)
   287  
   288  // zero instructions
   289  (Zero [0] _ mem) -> mem
   290  (Zero [1] ptr mem) -> (MOVBstore ptr (MOVWconst [0]) mem)
   291  (Zero [2] {t} ptr mem) && t.(*types.Type).Alignment()%2 == 0 ->
   292  	(MOVHstore ptr (MOVWconst [0]) mem)
   293  (Zero [2] ptr mem) ->
   294  	(MOVBstore [1] ptr (MOVWconst [0])
   295  		(MOVBstore [0] ptr (MOVWconst [0]) mem))
   296  (Zero [4] {t} ptr mem) && t.(*types.Type).Alignment()%4 == 0 ->
   297  	(MOVWstore ptr (MOVWconst [0]) mem)
   298  (Zero [4] {t} ptr mem) && t.(*types.Type).Alignment()%2 == 0 ->
   299  	(MOVHstore [2] ptr (MOVWconst [0])
   300  		(MOVHstore [0] ptr (MOVWconst [0]) mem))
   301  (Zero [4] ptr mem) ->
   302  	(MOVBstore [3] ptr (MOVWconst [0])
   303  		(MOVBstore [2] ptr (MOVWconst [0])
   304  			(MOVBstore [1] ptr (MOVWconst [0])
   305  				(MOVBstore [0] ptr (MOVWconst [0]) mem))))
   306  
   307  (Zero [3] ptr mem) ->
   308  	(MOVBstore [2] ptr (MOVWconst [0])
   309  		(MOVBstore [1] ptr (MOVWconst [0])
   310  			(MOVBstore [0] ptr (MOVWconst [0]) mem)))
   311  
   312  // Medium zeroing uses a duff device
   313  // 4 and 128 are magic constants, see runtime/mkduff.go
   314  (Zero [s] {t} ptr mem)
   315  	&& s%4 == 0 && s > 4 && s <= 512
   316  	&& t.(*types.Type).Alignment()%4 == 0 && !config.noDuffDevice ->
   317  	(DUFFZERO [4 * (128 - s/4)] ptr (MOVWconst [0]) mem)
   318  
   319  // Large zeroing uses a loop
   320  (Zero [s] {t} ptr mem)
   321  	&& (s > 512 || config.noDuffDevice) || t.(*types.Type).Alignment()%4 != 0 ->
   322  	(LoweredZero [t.(*types.Type).Alignment()]
   323  		ptr
   324  		(ADDconst <ptr.Type> ptr [s-moveSize(t.(*types.Type).Alignment(), config)])
   325  		(MOVWconst [0])
   326  		mem)
   327  
   328  // moves
   329  (Move [0] _ _ mem) -> mem
   330  (Move [1] dst src mem) -> (MOVBstore dst (MOVBUload src mem) mem)
   331  (Move [2] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 ->
   332  	(MOVHstore dst (MOVHUload src mem) mem)
   333  (Move [2] dst src mem) ->
   334  	(MOVBstore [1] dst (MOVBUload [1] src mem)
   335  		(MOVBstore dst (MOVBUload src mem) mem))
   336  (Move [4] {t} dst src mem) && t.(*types.Type).Alignment()%4 == 0 ->
   337  	(MOVWstore dst (MOVWload src mem) mem)
   338  (Move [4] {t} dst src mem) && t.(*types.Type).Alignment()%2 == 0 ->
   339  	(MOVHstore [2] dst (MOVHUload [2] src mem)
   340  		(MOVHstore dst (MOVHUload src mem) mem))
   341  (Move [4] dst src mem) ->
   342  	(MOVBstore [3] dst (MOVBUload [3] src mem)
   343  		(MOVBstore [2] dst (MOVBUload [2] src mem)
   344  			(MOVBstore [1] dst (MOVBUload [1] src mem)
   345  				(MOVBstore dst (MOVBUload src mem) mem))))
   346  
   347  (Move [3] dst src mem) ->
   348  	(MOVBstore [2] dst (MOVBUload [2] src mem)
   349  		(MOVBstore [1] dst (MOVBUload [1] src mem)
   350  			(MOVBstore dst (MOVBUload src mem) mem)))
   351  
   352  // Medium move uses a duff device
   353  // 8 and 128 are magic constants, see runtime/mkduff.go
   354  (Move [s] {t} dst src mem)
   355  	&& s%4 == 0 && s > 4 && s <= 512
   356  	&& t.(*types.Type).Alignment()%4 == 0 && !config.noDuffDevice ->
   357  	(DUFFCOPY [8 * (128 - s/4)] dst src mem)
   358  
   359  // Large move uses a loop
   360  (Move [s] {t} dst src mem)
   361  	&& (s > 512 || config.noDuffDevice) || t.(*types.Type).Alignment()%4 != 0 ->
   362  	(LoweredMove [t.(*types.Type).Alignment()]
   363  		dst
   364  		src
   365  		(ADDconst <src.Type> src [s-moveSize(t.(*types.Type).Alignment(), config)])
   366  		mem)
   367  
   368  // calls
   369  (StaticCall [argwid] {target} mem) -> (CALLstatic [argwid] {target} mem)
   370  (ClosureCall [argwid] entry closure mem) -> (CALLclosure [argwid] entry closure mem)
   371  (InterCall [argwid] entry mem) -> (CALLinter [argwid] entry mem)
   372  
   373  // checks
   374  (NilCheck ptr mem) -> (LoweredNilCheck ptr mem)
   375  (IsNonNil ptr) -> (NotEqual (CMPconst [0] ptr))
   376  (IsInBounds idx len) -> (LessThanU (CMP idx len))
   377  (IsSliceInBounds idx len) -> (LessEqualU (CMP idx len))
   378  
   379  // pseudo-ops
   380  (GetClosurePtr) -> (LoweredGetClosurePtr)
   381  (GetCallerSP) -> (LoweredGetCallerSP)
   382  (GetCallerPC) -> (LoweredGetCallerPC)
   383  
   384  // Absorb pseudo-ops into blocks.
   385  (If (Equal cc) yes no) -> (EQ cc yes no)
   386  (If (NotEqual cc) yes no) -> (NE cc yes no)
   387  (If (LessThan cc) yes no) -> (LT cc yes no)
   388  (If (LessThanU cc) yes no) -> (ULT cc yes no)
   389  (If (LessEqual cc) yes no) -> (LE cc yes no)
   390  (If (LessEqualU cc) yes no) -> (ULE cc yes no)
   391  (If (GreaterThan cc) yes no) -> (GT cc yes no)
   392  (If (GreaterThanU cc) yes no) -> (UGT cc yes no)
   393  (If (GreaterEqual cc) yes no) -> (GE cc yes no)
   394  (If (GreaterEqualU cc) yes no) -> (UGE cc yes no)
   395  
   396  (If cond yes no) -> (NE (CMPconst [0] cond) yes no)
   397  
   398  // Absorb boolean tests into block
   399  (NE (CMPconst [0] (Equal cc)) yes no) -> (EQ cc yes no)
   400  (NE (CMPconst [0] (NotEqual cc)) yes no) -> (NE cc yes no)
   401  (NE (CMPconst [0] (LessThan cc)) yes no) -> (LT cc yes no)
   402  (NE (CMPconst [0] (LessThanU cc)) yes no) -> (ULT cc yes no)
   403  (NE (CMPconst [0] (LessEqual cc)) yes no) -> (LE cc yes no)
   404  (NE (CMPconst [0] (LessEqualU cc)) yes no) -> (ULE cc yes no)
   405  (NE (CMPconst [0] (GreaterThan cc)) yes no) -> (GT cc yes no)
   406  (NE (CMPconst [0] (GreaterThanU cc)) yes no) -> (UGT cc yes no)
   407  (NE (CMPconst [0] (GreaterEqual cc)) yes no) -> (GE cc yes no)
   408  (NE (CMPconst [0] (GreaterEqualU cc)) yes no) -> (UGE cc yes no)
   409  
   410  // Write barrier.
   411  (WB {fn} destptr srcptr mem) -> (LoweredWB {fn} destptr srcptr mem)
   412  
   413  (PanicBounds [kind] x y mem) && boundsABI(kind) == 0 -> (LoweredPanicBoundsA [kind] x y mem)
   414  (PanicBounds [kind] x y mem) && boundsABI(kind) == 1 -> (LoweredPanicBoundsB [kind] x y mem)
   415  (PanicBounds [kind] x y mem) && boundsABI(kind) == 2 -> (LoweredPanicBoundsC [kind] x y mem)
   416  
   417  (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 0 -> (LoweredPanicExtendA [kind] hi lo y mem)
   418  (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 1 -> (LoweredPanicExtendB [kind] hi lo y mem)
   419  (PanicExtend [kind] hi lo y mem) && boundsABI(kind) == 2 -> (LoweredPanicExtendC [kind] hi lo y mem)
   420  
   421  // Optimizations
   422  
   423  // fold offset into address
   424  (ADDconst [off1] (MOVWaddr [off2] {sym} ptr)) -> (MOVWaddr [off1+off2] {sym} ptr)
   425  (SUBconst [off1] (MOVWaddr [off2] {sym} ptr)) -> (MOVWaddr [off2-off1] {sym} ptr)
   426  
   427  // fold address into load/store
   428  (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVBload [off1+off2] {sym} ptr mem)
   429  (MOVBload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVBload [off1-off2] {sym} ptr mem)
   430  (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVBUload [off1+off2] {sym} ptr mem)
   431  (MOVBUload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVBUload [off1-off2] {sym} ptr mem)
   432  (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVHload [off1+off2] {sym} ptr mem)
   433  (MOVHload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVHload [off1-off2] {sym} ptr mem)
   434  (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVHUload [off1+off2] {sym} ptr mem)
   435  (MOVHUload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVHUload [off1-off2] {sym} ptr mem)
   436  (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVWload [off1+off2] {sym} ptr mem)
   437  (MOVWload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVWload [off1-off2] {sym} ptr mem)
   438  (MOVFload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVFload [off1+off2] {sym} ptr mem)
   439  (MOVFload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVFload [off1-off2] {sym} ptr mem)
   440  (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) -> (MOVDload [off1+off2] {sym} ptr mem)
   441  (MOVDload [off1] {sym} (SUBconst [off2] ptr) mem) -> (MOVDload [off1-off2] {sym} ptr mem)
   442  
   443  (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVBstore [off1+off2] {sym} ptr val mem)
   444  (MOVBstore [off1] {sym} (SUBconst [off2] ptr) val mem) -> (MOVBstore [off1-off2] {sym} ptr val mem)
   445  (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVHstore [off1+off2] {sym} ptr val mem)
   446  (MOVHstore [off1] {sym} (SUBconst [off2] ptr) val mem) -> (MOVHstore [off1-off2] {sym} ptr val mem)
   447  (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVWstore [off1+off2] {sym} ptr val mem)
   448  (MOVWstore [off1] {sym} (SUBconst [off2] ptr) val mem) -> (MOVWstore [off1-off2] {sym} ptr val mem)
   449  (MOVFstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVFstore [off1+off2] {sym} ptr val mem)
   450  (MOVFstore [off1] {sym} (SUBconst [off2] ptr) val mem) -> (MOVFstore [off1-off2] {sym} ptr val mem)
   451  (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) -> (MOVDstore [off1+off2] {sym} ptr val mem)
   452  (MOVDstore [off1] {sym} (SUBconst [off2] ptr) val mem) -> (MOVDstore [off1-off2] {sym} ptr val mem)
   453  
   454  (MOVBload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   455  	(MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   456  (MOVBUload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   457  	(MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   458  (MOVHload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   459  	(MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   460  (MOVHUload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   461  	(MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   462  (MOVWload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   463  	(MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   464  (MOVFload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   465  	(MOVFload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   466  (MOVDload [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) mem) && canMergeSym(sym1,sym2) ->
   467  	(MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem)
   468  
   469  (MOVBstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) ->
   470  	(MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   471  (MOVHstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) ->
   472  	(MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   473  (MOVWstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) ->
   474  	(MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   475  (MOVFstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) ->
   476  	(MOVFstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   477  (MOVDstore [off1] {sym1} (MOVWaddr [off2] {sym2} ptr) val mem) && canMergeSym(sym1,sym2) ->
   478  	(MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem)
   479  
   480  // replace load from same location as preceding store with zero/sign extension (or copy in case of full width)
   481  (MOVBload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBreg x)
   482  (MOVBUload [off] {sym} ptr (MOVBstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVBUreg x)
   483  (MOVHload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHreg x)
   484  (MOVHUload [off] {sym} ptr (MOVHstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> (MOVHUreg x)
   485  (MOVWload [off] {sym} ptr (MOVWstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   486  
   487  (MOVFload [off] {sym} ptr (MOVFstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   488  (MOVDload [off] {sym} ptr (MOVDstore [off2] {sym2} ptr2 x _)) && sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) -> x
   489  
   490  (MOVWloadidx ptr idx (MOVWstoreidx ptr2 idx x _)) && isSamePtr(ptr, ptr2) -> x
   491  (MOVWloadshiftLL ptr idx [c] (MOVWstoreshiftLL ptr2 idx [d] x _)) && c==d && isSamePtr(ptr, ptr2) -> x
   492  (MOVWloadshiftRL ptr idx [c] (MOVWstoreshiftRL ptr2 idx [d] x _)) && c==d && isSamePtr(ptr, ptr2) -> x
   493  (MOVWloadshiftRA ptr idx [c] (MOVWstoreshiftRA ptr2 idx [d] x _)) && c==d && isSamePtr(ptr, ptr2) -> x
   494  (MOVBUloadidx ptr idx (MOVBstoreidx ptr2 idx x _)) && isSamePtr(ptr, ptr2) -> (MOVBUreg x)
   495  (MOVBloadidx ptr idx (MOVBstoreidx ptr2 idx x _)) && isSamePtr(ptr, ptr2) -> (MOVBreg x)
   496  (MOVHUloadidx ptr idx (MOVHstoreidx ptr2 idx x _)) && isSamePtr(ptr, ptr2) -> (MOVHUreg x)
   497  (MOVHloadidx ptr idx (MOVHstoreidx ptr2 idx x _)) && isSamePtr(ptr, ptr2) -> (MOVHreg x)
   498  
   499  // fold constant into arithmatic ops
   500  (ADD x (MOVWconst [c])) -> (ADDconst [c] x)
   501  (SUB (MOVWconst [c]) x) -> (RSBconst [c] x)
   502  (SUB x (MOVWconst [c])) -> (SUBconst [c] x)
   503  (RSB (MOVWconst [c]) x) -> (SUBconst [c] x)
   504  (RSB x (MOVWconst [c])) -> (RSBconst [c] x)
   505  
   506  (ADDS x (MOVWconst [c])) -> (ADDSconst [c] x)
   507  (SUBS x (MOVWconst [c])) -> (SUBSconst [c] x)
   508  
   509  (ADC (MOVWconst [c]) x flags) -> (ADCconst [c] x flags)
   510  (ADC x (MOVWconst [c]) flags) -> (ADCconst [c] x flags)
   511  (SBC (MOVWconst [c]) x flags) -> (RSCconst [c] x flags)
   512  (SBC x (MOVWconst [c]) flags) -> (SBCconst [c] x flags)
   513  
   514  (AND x (MOVWconst [c])) -> (ANDconst [c] x)
   515  (OR  x (MOVWconst [c])) -> (ORconst [c] x)
   516  (XOR x (MOVWconst [c])) -> (XORconst [c] x)
   517  (BIC x (MOVWconst [c])) -> (BICconst [c] x)
   518  
   519  (SLL x (MOVWconst [c])) -> (SLLconst x [c&31]) // Note: I don't think we ever generate bad constant shifts (i.e. c>=32)
   520  (SRL x (MOVWconst [c])) -> (SRLconst x [c&31])
   521  (SRA x (MOVWconst [c])) -> (SRAconst x [c&31])
   522  
   523  (CMP x (MOVWconst [c])) -> (CMPconst [c] x)
   524  (CMP (MOVWconst [c]) x) -> (InvertFlags (CMPconst [c] x))
   525  (CMN x (MOVWconst [c])) -> (CMNconst [c] x)
   526  (TST x (MOVWconst [c])) -> (TSTconst [c] x)
   527  (TEQ x (MOVWconst [c])) -> (TEQconst [c] x)
   528  
   529  // don't extend after proper load
   530  // MOVWreg instruction is not emitted if src and dst registers are same, but it ensures the type.
   531  (MOVBreg x:(MOVBload _ _)) -> (MOVWreg x)
   532  (MOVBUreg x:(MOVBUload _ _)) -> (MOVWreg x)
   533  (MOVHreg x:(MOVBload _ _)) -> (MOVWreg x)
   534  (MOVHreg x:(MOVBUload _ _)) -> (MOVWreg x)
   535  (MOVHreg x:(MOVHload _ _)) -> (MOVWreg x)
   536  (MOVHUreg x:(MOVBUload _ _)) -> (MOVWreg x)
   537  (MOVHUreg x:(MOVHUload _ _)) -> (MOVWreg x)
   538  
   539  // fold extensions and ANDs together
   540  (MOVBUreg (ANDconst [c] x)) -> (ANDconst [c&0xff] x)
   541  (MOVHUreg (ANDconst [c] x)) -> (ANDconst [c&0xffff] x)
   542  (MOVBreg (ANDconst [c] x)) && c & 0x80 == 0 -> (ANDconst [c&0x7f] x)
   543  (MOVHreg (ANDconst [c] x)) && c & 0x8000 == 0 -> (ANDconst [c&0x7fff] x)
   544  
   545  // fold double extensions
   546  (MOVBreg x:(MOVBreg _)) -> (MOVWreg x)
   547  (MOVBUreg x:(MOVBUreg _)) -> (MOVWreg x)
   548  (MOVHreg x:(MOVBreg _)) -> (MOVWreg x)
   549  (MOVHreg x:(MOVBUreg _)) -> (MOVWreg x)
   550  (MOVHreg x:(MOVHreg _)) -> (MOVWreg x)
   551  (MOVHUreg x:(MOVBUreg _)) -> (MOVWreg x)
   552  (MOVHUreg x:(MOVHUreg _)) -> (MOVWreg x)
   553  
   554  // don't extend before store
   555  (MOVBstore [off] {sym} ptr (MOVBreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   556  (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   557  (MOVBstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   558  (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVBstore [off] {sym} ptr x mem)
   559  (MOVHstore [off] {sym} ptr (MOVHreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   560  (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) -> (MOVHstore [off] {sym} ptr x mem)
   561  
   562  // if a register move has only 1 use, just use the same register without emitting instruction
   563  // MOVWnop doesn't emit instruction, only for ensuring the type.
   564  (MOVWreg x) && x.Uses == 1 -> (MOVWnop x)
   565  
   566  // mul by constant
   567  (MUL x (MOVWconst [c])) && int32(c) == -1 -> (RSBconst [0] x)
   568  (MUL _ (MOVWconst [0])) -> (MOVWconst [0])
   569  (MUL x (MOVWconst [1])) -> x
   570  (MUL x (MOVWconst [c])) && isPowerOfTwo(c) -> (SLLconst [log2(c)] x)
   571  (MUL x (MOVWconst [c])) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADDshiftLL x x [log2(c-1)])
   572  (MUL x (MOVWconst [c])) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (RSBshiftLL x x [log2(c+1)])
   573  (MUL x (MOVWconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SLLconst [log2(c/3)] (ADDshiftLL <x.Type> x x [1]))
   574  (MUL x (MOVWconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SLLconst [log2(c/5)] (ADDshiftLL <x.Type> x x [2]))
   575  (MUL x (MOVWconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SLLconst [log2(c/7)] (RSBshiftLL <x.Type> x x [3]))
   576  (MUL x (MOVWconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SLLconst [log2(c/9)] (ADDshiftLL <x.Type> x x [3]))
   577  
   578  (MULA x (MOVWconst [c]) a) && int32(c) == -1 -> (SUB a x)
   579  (MULA _ (MOVWconst [0]) a) -> a
   580  (MULA x (MOVWconst [1]) a) -> (ADD x a)
   581  (MULA x (MOVWconst [c]) a) && isPowerOfTwo(c) -> (ADD (SLLconst <x.Type> [log2(c)] x) a)
   582  (MULA x (MOVWconst [c]) a) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADD (ADDshiftLL <x.Type> x x [log2(c-1)]) a)
   583  (MULA x (MOVWconst [c]) a) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (ADD (RSBshiftLL <x.Type> x x [log2(c+1)]) a)
   584  (MULA x (MOVWconst [c]) a) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) a)
   585  (MULA x (MOVWconst [c]) a) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) a)
   586  (MULA x (MOVWconst [c]) a) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/7)] (RSBshiftLL <x.Type> x x [3])) a)
   587  (MULA x (MOVWconst [c]) a) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) a)
   588  
   589  (MULA (MOVWconst [c]) x a) && int32(c) == -1 -> (SUB a x)
   590  (MULA (MOVWconst [0]) _ a) -> a
   591  (MULA (MOVWconst [1]) x a) -> (ADD x a)
   592  (MULA (MOVWconst [c]) x a) && isPowerOfTwo(c) -> (ADD (SLLconst <x.Type> [log2(c)] x) a)
   593  (MULA (MOVWconst [c]) x a) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (ADD (ADDshiftLL <x.Type> x x [log2(c-1)]) a)
   594  (MULA (MOVWconst [c]) x a) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (ADD (RSBshiftLL <x.Type> x x [log2(c+1)]) a)
   595  (MULA (MOVWconst [c]) x a) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) a)
   596  (MULA (MOVWconst [c]) x a) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) a)
   597  (MULA (MOVWconst [c]) x a) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/7)] (RSBshiftLL <x.Type> x x [3])) a)
   598  (MULA (MOVWconst [c]) x a) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (ADD (SLLconst <x.Type> [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) a)
   599  
   600  (MULS x (MOVWconst [c]) a) && int32(c) == -1 -> (ADD a x)
   601  (MULS _ (MOVWconst [0]) a) -> a
   602  (MULS x (MOVWconst [1]) a) -> (RSB x a)
   603  (MULS x (MOVWconst [c]) a) && isPowerOfTwo(c) -> (RSB (SLLconst <x.Type> [log2(c)] x) a)
   604  (MULS x (MOVWconst [c]) a) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (RSB (ADDshiftLL <x.Type> x x [log2(c-1)]) a)
   605  (MULS x (MOVWconst [c]) a) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (RSB (RSBshiftLL <x.Type> x x [log2(c+1)]) a)
   606  (MULS x (MOVWconst [c]) a) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) a)
   607  (MULS x (MOVWconst [c]) a) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) a)
   608  (MULS x (MOVWconst [c]) a) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/7)] (RSBshiftLL <x.Type> x x [3])) a)
   609  (MULS x (MOVWconst [c]) a) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) a)
   610  
   611  (MULS (MOVWconst [c]) x a) && int32(c) == -1 -> (ADD a x)
   612  (MULS (MOVWconst [0]) _ a) -> a
   613  (MULS (MOVWconst [1]) x a) -> (RSB x a)
   614  (MULS (MOVWconst [c]) x a) && isPowerOfTwo(c) -> (RSB (SLLconst <x.Type> [log2(c)] x) a)
   615  (MULS (MOVWconst [c]) x a) && isPowerOfTwo(c-1) && int32(c) >= 3 -> (RSB (ADDshiftLL <x.Type> x x [log2(c-1)]) a)
   616  (MULS (MOVWconst [c]) x a) && isPowerOfTwo(c+1) && int32(c) >= 7 -> (RSB (RSBshiftLL <x.Type> x x [log2(c+1)]) a)
   617  (MULS (MOVWconst [c]) x a) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/3)] (ADDshiftLL <x.Type> x x [1])) a)
   618  (MULS (MOVWconst [c]) x a) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/5)] (ADDshiftLL <x.Type> x x [2])) a)
   619  (MULS (MOVWconst [c]) x a) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/7)] (RSBshiftLL <x.Type> x x [3])) a)
   620  (MULS (MOVWconst [c]) x a) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (RSB (SLLconst <x.Type> [log2(c/9)] (ADDshiftLL <x.Type> x x [3])) a)
   621  
   622  // div by constant
   623  (Select0 (CALLudiv x (MOVWconst [1]))) -> x
   624  (Select1 (CALLudiv _ (MOVWconst [1]))) -> (MOVWconst [0])
   625  (Select0 (CALLudiv x (MOVWconst [c]))) && isPowerOfTwo(c) -> (SRLconst [log2(c)] x)
   626  (Select1 (CALLudiv x (MOVWconst [c]))) && isPowerOfTwo(c) -> (ANDconst [c-1] x)
   627  
   628  // constant comparisons
   629  (CMPconst (MOVWconst [x]) [y]) && int32(x)==int32(y) -> (FlagEQ)
   630  (CMPconst (MOVWconst [x]) [y]) && int32(x)<int32(y) && uint32(x)<uint32(y) -> (FlagLT_ULT)
   631  (CMPconst (MOVWconst [x]) [y]) && int32(x)<int32(y) && uint32(x)>uint32(y) -> (FlagLT_UGT)
   632  (CMPconst (MOVWconst [x]) [y]) && int32(x)>int32(y) && uint32(x)<uint32(y) -> (FlagGT_ULT)
   633  (CMPconst (MOVWconst [x]) [y]) && int32(x)>int32(y) && uint32(x)>uint32(y) -> (FlagGT_UGT)
   634  (CMNconst (MOVWconst [x]) [y]) && int32(x)==int32(-y) -> (FlagEQ)
   635  (CMNconst (MOVWconst [x]) [y]) && int32(x)<int32(-y) && uint32(x)<uint32(-y) -> (FlagLT_ULT)
   636  (CMNconst (MOVWconst [x]) [y]) && int32(x)<int32(-y) && uint32(x)>uint32(-y) -> (FlagLT_UGT)
   637  (CMNconst (MOVWconst [x]) [y]) && int32(x)>int32(-y) && uint32(x)<uint32(-y) -> (FlagGT_ULT)
   638  (CMNconst (MOVWconst [x]) [y]) && int32(x)>int32(-y) && uint32(x)>uint32(-y) -> (FlagGT_UGT)
   639  (TSTconst (MOVWconst [x]) [y]) && int32(x&y)==0 -> (FlagEQ)
   640  (TSTconst (MOVWconst [x]) [y]) && int32(x&y)<0 -> (FlagLT_UGT)
   641  (TSTconst (MOVWconst [x]) [y]) && int32(x&y)>0 -> (FlagGT_UGT)
   642  (TEQconst (MOVWconst [x]) [y]) && int32(x^y)==0 -> (FlagEQ)
   643  (TEQconst (MOVWconst [x]) [y]) && int32(x^y)<0 -> (FlagLT_UGT)
   644  (TEQconst (MOVWconst [x]) [y]) && int32(x^y)>0 -> (FlagGT_UGT)
   645  
   646  // other known comparisons
   647  (CMPconst (MOVBUreg _) [c]) && 0xff < c -> (FlagLT_ULT)
   648  (CMPconst (MOVHUreg _) [c]) && 0xffff < c -> (FlagLT_ULT)
   649  (CMPconst (ANDconst _ [m]) [n]) && 0 <= int32(m) && int32(m) < int32(n) -> (FlagLT_ULT)
   650  (CMPconst (SRLconst _ [c]) [n]) && 0 <= n && 0 < c && c <= 32 && (1<<uint32(32-c)) <= uint32(n) -> (FlagLT_ULT)
   651  
   652  // absorb flag constants into branches
   653  (EQ (FlagEQ) yes no) -> (First yes no)
   654  (EQ (FlagLT_ULT) yes no) -> (First no yes)
   655  (EQ (FlagLT_UGT) yes no) -> (First no yes)
   656  (EQ (FlagGT_ULT) yes no) -> (First no yes)
   657  (EQ (FlagGT_UGT) yes no) -> (First no yes)
   658  
   659  (NE (FlagEQ) yes no) -> (First no yes)
   660  (NE (FlagLT_ULT) yes no) -> (First yes no)
   661  (NE (FlagLT_UGT) yes no) -> (First yes no)
   662  (NE (FlagGT_ULT) yes no) -> (First yes no)
   663  (NE (FlagGT_UGT) yes no) -> (First yes no)
   664  
   665  (LT (FlagEQ) yes no) -> (First no yes)
   666  (LT (FlagLT_ULT) yes no) -> (First yes no)
   667  (LT (FlagLT_UGT) yes no) -> (First yes no)
   668  (LT (FlagGT_ULT) yes no) -> (First no yes)
   669  (LT (FlagGT_UGT) yes no) -> (First no yes)
   670  
   671  (LE (FlagEQ) yes no) -> (First yes no)
   672  (LE (FlagLT_ULT) yes no) -> (First yes no)
   673  (LE (FlagLT_UGT) yes no) -> (First yes no)
   674  (LE (FlagGT_ULT) yes no) -> (First no yes)
   675  (LE (FlagGT_UGT) yes no) -> (First no yes)
   676  
   677  (GT (FlagEQ) yes no) -> (First no yes)
   678  (GT (FlagLT_ULT) yes no) -> (First no yes)
   679  (GT (FlagLT_UGT) yes no) -> (First no yes)
   680  (GT (FlagGT_ULT) yes no) -> (First yes no)
   681  (GT (FlagGT_UGT) yes no) -> (First yes no)
   682  
   683  (GE (FlagEQ) yes no) -> (First yes no)
   684  (GE (FlagLT_ULT) yes no) -> (First no yes)
   685  (GE (FlagLT_UGT) yes no) -> (First no yes)
   686  (GE (FlagGT_ULT) yes no) -> (First yes no)
   687  (GE (FlagGT_UGT) yes no) -> (First yes no)
   688  
   689  (ULT (FlagEQ) yes no) -> (First no yes)
   690  (ULT (FlagLT_ULT) yes no) -> (First yes no)
   691  (ULT (FlagLT_UGT) yes no) -> (First no yes)
   692  (ULT (FlagGT_ULT) yes no) -> (First yes no)
   693  (ULT (FlagGT_UGT) yes no) -> (First no yes)
   694  
   695  (ULE (FlagEQ) yes no) -> (First yes no)
   696  (ULE (FlagLT_ULT) yes no) -> (First yes no)
   697  (ULE (FlagLT_UGT) yes no) -> (First no yes)
   698  (ULE (FlagGT_ULT) yes no) -> (First yes no)
   699  (ULE (FlagGT_UGT) yes no) -> (First no yes)
   700  
   701  (UGT (FlagEQ) yes no) -> (First no yes)
   702  (UGT (FlagLT_ULT) yes no) -> (First no yes)
   703  (UGT (FlagLT_UGT) yes no) -> (First yes no)
   704  (UGT (FlagGT_ULT) yes no) -> (First no yes)
   705  (UGT (FlagGT_UGT) yes no) -> (First yes no)
   706  
   707  (UGE (FlagEQ) yes no) -> (First yes no)
   708  (UGE (FlagLT_ULT) yes no) -> (First no yes)
   709  (UGE (FlagLT_UGT) yes no) -> (First yes no)
   710  (UGE (FlagGT_ULT) yes no) -> (First no yes)
   711  (UGE (FlagGT_UGT) yes no) -> (First yes no)
   712  
   713  // absorb InvertFlags into branches
   714  (LT (InvertFlags cmp) yes no) -> (GT cmp yes no)
   715  (GT (InvertFlags cmp) yes no) -> (LT cmp yes no)
   716  (LE (InvertFlags cmp) yes no) -> (GE cmp yes no)
   717  (GE (InvertFlags cmp) yes no) -> (LE cmp yes no)
   718  (ULT (InvertFlags cmp) yes no) -> (UGT cmp yes no)
   719  (UGT (InvertFlags cmp) yes no) -> (ULT cmp yes no)
   720  (ULE (InvertFlags cmp) yes no) -> (UGE cmp yes no)
   721  (UGE (InvertFlags cmp) yes no) -> (ULE cmp yes no)
   722  (EQ (InvertFlags cmp) yes no) -> (EQ cmp yes no)
   723  (NE (InvertFlags cmp) yes no) -> (NE cmp yes no)
   724  
   725  // absorb flag constants into boolean values
   726  (Equal (FlagEQ)) -> (MOVWconst [1])
   727  (Equal (FlagLT_ULT)) -> (MOVWconst [0])
   728  (Equal (FlagLT_UGT)) -> (MOVWconst [0])
   729  (Equal (FlagGT_ULT)) -> (MOVWconst [0])
   730  (Equal (FlagGT_UGT)) -> (MOVWconst [0])
   731  
   732  (NotEqual (FlagEQ)) -> (MOVWconst [0])
   733  (NotEqual (FlagLT_ULT)) -> (MOVWconst [1])
   734  (NotEqual (FlagLT_UGT)) -> (MOVWconst [1])
   735  (NotEqual (FlagGT_ULT)) -> (MOVWconst [1])
   736  (NotEqual (FlagGT_UGT)) -> (MOVWconst [1])
   737  
   738  (LessThan (FlagEQ)) -> (MOVWconst [0])
   739  (LessThan (FlagLT_ULT)) -> (MOVWconst [1])
   740  (LessThan (FlagLT_UGT)) -> (MOVWconst [1])
   741  (LessThan (FlagGT_ULT)) -> (MOVWconst [0])
   742  (LessThan (FlagGT_UGT)) -> (MOVWconst [0])
   743  
   744  (LessThanU (FlagEQ)) -> (MOVWconst [0])
   745  (LessThanU (FlagLT_ULT)) -> (MOVWconst [1])
   746  (LessThanU (FlagLT_UGT)) -> (MOVWconst [0])
   747  (LessThanU (FlagGT_ULT)) -> (MOVWconst [1])
   748  (LessThanU (FlagGT_UGT)) -> (MOVWconst [0])
   749  
   750  (LessEqual (FlagEQ)) -> (MOVWconst [1])
   751  (LessEqual (FlagLT_ULT)) -> (MOVWconst [1])
   752  (LessEqual (FlagLT_UGT)) -> (MOVWconst [1])
   753  (LessEqual (FlagGT_ULT)) -> (MOVWconst [0])
   754  (LessEqual (FlagGT_UGT)) -> (MOVWconst [0])
   755  
   756  (LessEqualU (FlagEQ)) -> (MOVWconst [1])
   757  (LessEqualU (FlagLT_ULT)) -> (MOVWconst [1])
   758  (LessEqualU (FlagLT_UGT)) -> (MOVWconst [0])
   759  (LessEqualU (FlagGT_ULT)) -> (MOVWconst [1])
   760  (LessEqualU (FlagGT_UGT)) -> (MOVWconst [0])
   761  
   762  (GreaterThan (FlagEQ)) -> (MOVWconst [0])
   763  (GreaterThan (FlagLT_ULT)) -> (MOVWconst [0])
   764  (GreaterThan (FlagLT_UGT)) -> (MOVWconst [0])
   765  (GreaterThan (FlagGT_ULT)) -> (MOVWconst [1])
   766  (GreaterThan (FlagGT_UGT)) -> (MOVWconst [1])
   767  
   768  (GreaterThanU (FlagEQ)) -> (MOVWconst [0])
   769  (GreaterThanU (FlagLT_ULT)) -> (MOVWconst [0])
   770  (GreaterThanU (FlagLT_UGT)) -> (MOVWconst [1])
   771  (GreaterThanU (FlagGT_ULT)) -> (MOVWconst [0])
   772  (GreaterThanU (FlagGT_UGT)) -> (MOVWconst [1])
   773  
   774  (GreaterEqual (FlagEQ)) -> (MOVWconst [1])
   775  (GreaterEqual (FlagLT_ULT)) -> (MOVWconst [0])
   776  (GreaterEqual (FlagLT_UGT)) -> (MOVWconst [0])
   777  (GreaterEqual (FlagGT_ULT)) -> (MOVWconst [1])
   778  (GreaterEqual (FlagGT_UGT)) -> (MOVWconst [1])
   779  
   780  (GreaterEqualU (FlagEQ)) -> (MOVWconst [1])
   781  (GreaterEqualU (FlagLT_ULT)) -> (MOVWconst [0])
   782  (GreaterEqualU (FlagLT_UGT)) -> (MOVWconst [1])
   783  (GreaterEqualU (FlagGT_ULT)) -> (MOVWconst [0])
   784  (GreaterEqualU (FlagGT_UGT)) -> (MOVWconst [1])
   785  
   786  // absorb InvertFlags into boolean values
   787  (Equal (InvertFlags x)) -> (Equal x)
   788  (NotEqual (InvertFlags x)) -> (NotEqual x)
   789  (LessThan (InvertFlags x)) -> (GreaterThan x)
   790  (LessThanU (InvertFlags x)) -> (GreaterThanU x)
   791  (GreaterThan (InvertFlags x)) -> (LessThan x)
   792  (GreaterThanU (InvertFlags x)) -> (LessThanU x)
   793  (LessEqual (InvertFlags x)) -> (GreaterEqual x)
   794  (LessEqualU (InvertFlags x)) -> (GreaterEqualU x)
   795  (GreaterEqual (InvertFlags x)) -> (LessEqual x)
   796  (GreaterEqualU (InvertFlags x)) -> (LessEqualU x)
   797  
   798  // absorb flag constants into conditional instructions
   799  (CMOVWLSconst _ (FlagEQ) [c]) -> (MOVWconst [c])
   800  (CMOVWLSconst _ (FlagLT_ULT) [c]) -> (MOVWconst [c])
   801  (CMOVWLSconst x (FlagLT_UGT)) -> x
   802  (CMOVWLSconst _ (FlagGT_ULT) [c]) -> (MOVWconst [c])
   803  (CMOVWLSconst x (FlagGT_UGT)) -> x
   804  
   805  (CMOVWHSconst _ (FlagEQ) [c]) -> (MOVWconst [c])
   806  (CMOVWHSconst x (FlagLT_ULT)) -> x
   807  (CMOVWHSconst _ (FlagLT_UGT) [c]) -> (MOVWconst [c])
   808  (CMOVWHSconst x (FlagGT_ULT)) -> x
   809  (CMOVWHSconst _ (FlagGT_UGT) [c]) -> (MOVWconst [c])
   810  
   811  (CMOVWLSconst x (InvertFlags flags) [c]) -> (CMOVWHSconst x flags [c])
   812  (CMOVWHSconst x (InvertFlags flags) [c]) -> (CMOVWLSconst x flags [c])
   813  
   814  (SRAcond x _ (FlagEQ)) -> (SRAconst x [31])
   815  (SRAcond x y (FlagLT_ULT)) -> (SRA x y)
   816  (SRAcond x _ (FlagLT_UGT)) -> (SRAconst x [31])
   817  (SRAcond x y (FlagGT_ULT)) -> (SRA x y)
   818  (SRAcond x _ (FlagGT_UGT)) -> (SRAconst x [31])
   819  
   820  // remove redundant *const ops
   821  (ADDconst [0] x) -> x
   822  (SUBconst [0] x) -> x
   823  (ANDconst [0] _) -> (MOVWconst [0])
   824  (ANDconst [c] x) && int32(c)==-1 -> x
   825  (ORconst [0] x) -> x
   826  (ORconst [c] _) && int32(c)==-1 -> (MOVWconst [-1])
   827  (XORconst [0] x) -> x
   828  (BICconst [0] x) -> x
   829  (BICconst [c] _) && int32(c)==-1 -> (MOVWconst [0])
   830  
   831  // generic constant folding
   832  (ADDconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(uint32(-c)) -> (SUBconst [int64(int32(-c))] x)
   833  (SUBconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(uint32(-c)) -> (ADDconst [int64(int32(-c))] x)
   834  (ANDconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(^uint32(c)) -> (BICconst [int64(int32(^uint32(c)))] x)
   835  (BICconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(^uint32(c)) -> (ANDconst [int64(int32(^uint32(c)))] x)
   836  (ADDconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff -> (SUBconst [int64(int32(-c))] x)
   837  (SUBconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff -> (ANDconst [int64(int32(-c))] x)
   838  (ANDconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff -> (BICconst [int64(int32(^uint32(c)))] x)
   839  (BICconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff -> (ANDconst [int64(int32(^uint32(c)))] x)
   840  (ADDconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(c+d))])
   841  (ADDconst [c] (ADDconst [d] x)) -> (ADDconst [int64(int32(c+d))] x)
   842  (ADDconst [c] (SUBconst [d] x)) -> (ADDconst [int64(int32(c-d))] x)
   843  (ADDconst [c] (RSBconst [d] x)) -> (RSBconst [int64(int32(c+d))] x)
   844  (ADCconst [c] (ADDconst [d] x) flags) -> (ADCconst [int64(int32(c+d))] x flags)
   845  (ADCconst [c] (SUBconst [d] x) flags) -> (ADCconst [int64(int32(c-d))] x flags)
   846  (SUBconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d-c))])
   847  (SUBconst [c] (SUBconst [d] x)) -> (ADDconst [int64(int32(-c-d))] x)
   848  (SUBconst [c] (ADDconst [d] x)) -> (ADDconst [int64(int32(-c+d))] x)
   849  (SUBconst [c] (RSBconst [d] x)) -> (RSBconst [int64(int32(-c+d))] x)
   850  (SBCconst [c] (ADDconst [d] x) flags) -> (SBCconst [int64(int32(c-d))] x flags)
   851  (SBCconst [c] (SUBconst [d] x) flags) -> (SBCconst [int64(int32(c+d))] x flags)
   852  (RSBconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(c-d))])
   853  (RSBconst [c] (RSBconst [d] x)) -> (ADDconst [int64(int32(c-d))] x)
   854  (RSBconst [c] (ADDconst [d] x)) -> (RSBconst [int64(int32(c-d))] x)
   855  (RSBconst [c] (SUBconst [d] x)) -> (RSBconst [int64(int32(c+d))] x)
   856  (RSCconst [c] (ADDconst [d] x) flags) -> (RSCconst [int64(int32(c-d))] x flags)
   857  (RSCconst [c] (SUBconst [d] x) flags) -> (RSCconst [int64(int32(c+d))] x flags)
   858  (SLLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)<<uint64(c)))])
   859  (SRLconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)>>uint64(c)))])
   860  (SRAconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d)>>uint64(c))])
   861  (MUL (MOVWconst [c]) (MOVWconst [d])) -> (MOVWconst [int64(int32(c*d))])
   862  (MULA (MOVWconst [c]) (MOVWconst [d]) a) -> (ADDconst [int64(int32(c*d))] a)
   863  (MULS (MOVWconst [c]) (MOVWconst [d]) a) -> (SUBconst [int64(int32(c*d))] a)
   864  (Select0 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)/uint32(d)))])
   865  (Select1 (CALLudiv (MOVWconst [c]) (MOVWconst [d]))) -> (MOVWconst [int64(int32(uint32(c)%uint32(d)))])
   866  (ANDconst [c] (MOVWconst [d])) -> (MOVWconst [c&d])
   867  (ANDconst [c] (ANDconst [d] x)) -> (ANDconst [c&d] x)
   868  (ORconst [c] (MOVWconst [d])) -> (MOVWconst [c|d])
   869  (ORconst [c] (ORconst [d] x)) -> (ORconst [c|d] x)
   870  (XORconst [c] (MOVWconst [d])) -> (MOVWconst [c^d])
   871  (XORconst [c] (XORconst [d] x)) -> (XORconst [c^d] x)
   872  (BICconst [c] (MOVWconst [d])) -> (MOVWconst [d&^c])
   873  (BICconst [c] (BICconst [d] x)) -> (BICconst [int64(int32(c|d))] x)
   874  (MVN (MOVWconst [c])) -> (MOVWconst [^c])
   875  (MOVBreg (MOVWconst [c])) -> (MOVWconst [int64(int8(c))])
   876  (MOVBUreg (MOVWconst [c])) -> (MOVWconst [int64(uint8(c))])
   877  (MOVHreg (MOVWconst [c])) -> (MOVWconst [int64(int16(c))])
   878  (MOVHUreg (MOVWconst [c])) -> (MOVWconst [int64(uint16(c))])
   879  (MOVWreg (MOVWconst [c])) -> (MOVWconst [c])
   880  // BFX: Width = c >> 8, LSB = c & 0xff, result = d << (32 - Width - LSB) >> (32 - Width)
   881  (BFX [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8)))])
   882  (BFXU [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(uint32(d)<<(32-uint32(c&0xff)-uint32(c>>8))>>(32-uint32(c>>8))))])
   883  
   884  // absorb shifts into ops
   885  (ADD x (SLLconst [c] y)) -> (ADDshiftLL x y [c])
   886  (ADD x (SRLconst [c] y)) -> (ADDshiftRL x y [c])
   887  (ADD x (SRAconst [c] y)) -> (ADDshiftRA x y [c])
   888  (ADD x (SLL y z)) -> (ADDshiftLLreg x y z)
   889  (ADD x (SRL y z)) -> (ADDshiftRLreg x y z)
   890  (ADD x (SRA y z)) -> (ADDshiftRAreg x y z)
   891  (ADC x (SLLconst [c] y) flags) -> (ADCshiftLL x y [c] flags)
   892  (ADC (SLLconst [c] y) x flags) -> (ADCshiftLL x y [c] flags)
   893  (ADC x (SRLconst [c] y) flags) -> (ADCshiftRL x y [c] flags)
   894  (ADC (SRLconst [c] y) x flags) -> (ADCshiftRL x y [c] flags)
   895  (ADC x (SRAconst [c] y) flags) -> (ADCshiftRA x y [c] flags)
   896  (ADC (SRAconst [c] y) x flags) -> (ADCshiftRA x y [c] flags)
   897  (ADC x (SLL y z) flags) -> (ADCshiftLLreg x y z flags)
   898  (ADC (SLL y z) x flags) -> (ADCshiftLLreg x y z flags)
   899  (ADC x (SRL y z) flags) -> (ADCshiftRLreg x y z flags)
   900  (ADC (SRL y z) x flags) -> (ADCshiftRLreg x y z flags)
   901  (ADC x (SRA y z) flags) -> (ADCshiftRAreg x y z flags)
   902  (ADC (SRA y z) x flags) -> (ADCshiftRAreg x y z flags)
   903  (ADDS x (SLLconst [c] y)) -> (ADDSshiftLL x y [c])
   904  (ADDS x (SRLconst [c] y)) -> (ADDSshiftRL x y [c])
   905  (ADDS x (SRAconst [c] y)) -> (ADDSshiftRA x y [c])
   906  (ADDS x (SLL y z)) -> (ADDSshiftLLreg x y z)
   907  (ADDS x (SRL y z)) -> (ADDSshiftRLreg x y z)
   908  (ADDS x (SRA y z)) -> (ADDSshiftRAreg x y z)
   909  (SUB x (SLLconst [c] y)) -> (SUBshiftLL x y [c])
   910  (SUB (SLLconst [c] y) x) -> (RSBshiftLL x y [c])
   911  (SUB x (SRLconst [c] y)) -> (SUBshiftRL x y [c])
   912  (SUB (SRLconst [c] y) x) -> (RSBshiftRL x y [c])
   913  (SUB x (SRAconst [c] y)) -> (SUBshiftRA x y [c])
   914  (SUB (SRAconst [c] y) x) -> (RSBshiftRA x y [c])
   915  (SUB x (SLL y z)) -> (SUBshiftLLreg x y z)
   916  (SUB (SLL y z) x) -> (RSBshiftLLreg x y z)
   917  (SUB x (SRL y z)) -> (SUBshiftRLreg x y z)
   918  (SUB (SRL y z) x) -> (RSBshiftRLreg x y z)
   919  (SUB x (SRA y z)) -> (SUBshiftRAreg x y z)
   920  (SUB (SRA y z) x) -> (RSBshiftRAreg x y z)
   921  (SBC x (SLLconst [c] y) flags) -> (SBCshiftLL x y [c] flags)
   922  (SBC (SLLconst [c] y) x flags) -> (RSCshiftLL x y [c] flags)
   923  (SBC x (SRLconst [c] y) flags) -> (SBCshiftRL x y [c] flags)
   924  (SBC (SRLconst [c] y) x flags) -> (RSCshiftRL x y [c] flags)
   925  (SBC x (SRAconst [c] y) flags) -> (SBCshiftRA x y [c] flags)
   926  (SBC (SRAconst [c] y) x flags) -> (RSCshiftRA x y [c] flags)
   927  (SBC x (SLL y z) flags) -> (SBCshiftLLreg x y z flags)
   928  (SBC (SLL y z) x flags) -> (RSCshiftLLreg x y z flags)
   929  (SBC x (SRL y z) flags) -> (SBCshiftRLreg x y z flags)
   930  (SBC (SRL y z) x flags) -> (RSCshiftRLreg x y z flags)
   931  (SBC x (SRA y z) flags) -> (SBCshiftRAreg x y z flags)
   932  (SBC (SRA y z) x flags) -> (RSCshiftRAreg x y z flags)
   933  (SUBS x (SLLconst [c] y)) -> (SUBSshiftLL x y [c])
   934  (SUBS (SLLconst [c] y) x) -> (RSBSshiftLL x y [c])
   935  (SUBS x (SRLconst [c] y)) -> (SUBSshiftRL x y [c])
   936  (SUBS (SRLconst [c] y) x) -> (RSBSshiftRL x y [c])
   937  (SUBS x (SRAconst [c] y)) -> (SUBSshiftRA x y [c])
   938  (SUBS (SRAconst [c] y) x) -> (RSBSshiftRA x y [c])
   939  (SUBS x (SLL y z)) -> (SUBSshiftLLreg x y z)
   940  (SUBS (SLL y z) x) -> (RSBSshiftLLreg x y z)
   941  (SUBS x (SRL y z)) -> (SUBSshiftRLreg x y z)
   942  (SUBS (SRL y z) x) -> (RSBSshiftRLreg x y z)
   943  (SUBS x (SRA y z)) -> (SUBSshiftRAreg x y z)
   944  (SUBS (SRA y z) x) -> (RSBSshiftRAreg x y z)
   945  (RSB x (SLLconst [c] y)) -> (RSBshiftLL x y [c])
   946  (RSB (SLLconst [c] y) x) -> (SUBshiftLL x y [c])
   947  (RSB x (SRLconst [c] y)) -> (RSBshiftRL x y [c])
   948  (RSB (SRLconst [c] y) x) -> (SUBshiftRL x y [c])
   949  (RSB x (SRAconst [c] y)) -> (RSBshiftRA x y [c])
   950  (RSB (SRAconst [c] y) x) -> (SUBshiftRA x y [c])
   951  (RSB x (SLL y z)) -> (RSBshiftLLreg x y z)
   952  (RSB (SLL y z) x) -> (SUBshiftLLreg x y z)
   953  (RSB x (SRL y z)) -> (RSBshiftRLreg x y z)
   954  (RSB (SRL y z) x) -> (SUBshiftRLreg x y z)
   955  (RSB x (SRA y z)) -> (RSBshiftRAreg x y z)
   956  (RSB (SRA y z) x) -> (SUBshiftRAreg x y z)
   957  (AND x (SLLconst [c] y)) -> (ANDshiftLL x y [c])
   958  (AND x (SRLconst [c] y)) -> (ANDshiftRL x y [c])
   959  (AND x (SRAconst [c] y)) -> (ANDshiftRA x y [c])
   960  (AND x (SLL y z)) -> (ANDshiftLLreg x y z)
   961  (AND x (SRL y z)) -> (ANDshiftRLreg x y z)
   962  (AND x (SRA y z)) -> (ANDshiftRAreg x y z)
   963  (OR x (SLLconst [c] y)) -> (ORshiftLL x y [c])
   964  (OR x (SRLconst [c] y)) -> (ORshiftRL x y [c])
   965  (OR x (SRAconst [c] y)) -> (ORshiftRA x y [c])
   966  (OR x (SLL y z)) -> (ORshiftLLreg x y z)
   967  (OR x (SRL y z)) -> (ORshiftRLreg x y z)
   968  (OR x (SRA y z)) -> (ORshiftRAreg x y z)
   969  (XOR x (SLLconst [c] y)) -> (XORshiftLL x y [c])
   970  (XOR x (SRLconst [c] y)) -> (XORshiftRL x y [c])
   971  (XOR x (SRAconst [c] y)) -> (XORshiftRA x y [c])
   972  (XOR x (SRRconst [c] y)) -> (XORshiftRR x y [c])
   973  (XOR x (SLL y z)) -> (XORshiftLLreg x y z)
   974  (XOR x (SRL y z)) -> (XORshiftRLreg x y z)
   975  (XOR x (SRA y z)) -> (XORshiftRAreg x y z)
   976  (BIC x (SLLconst [c] y)) -> (BICshiftLL x y [c])
   977  (BIC x (SRLconst [c] y)) -> (BICshiftRL x y [c])
   978  (BIC x (SRAconst [c] y)) -> (BICshiftRA x y [c])
   979  (BIC x (SLL y z)) -> (BICshiftLLreg x y z)
   980  (BIC x (SRL y z)) -> (BICshiftRLreg x y z)
   981  (BIC x (SRA y z)) -> (BICshiftRAreg x y z)
   982  (MVN (SLLconst [c] x)) -> (MVNshiftLL x [c])
   983  (MVN (SRLconst [c] x)) -> (MVNshiftRL x [c])
   984  (MVN (SRAconst [c] x)) -> (MVNshiftRA x [c])
   985  (MVN (SLL x y)) -> (MVNshiftLLreg x y)
   986  (MVN (SRL x y)) -> (MVNshiftRLreg x y)
   987  (MVN (SRA x y)) -> (MVNshiftRAreg x y)
   988  
   989  (CMP x (SLLconst [c] y)) -> (CMPshiftLL x y [c])
   990  (CMP (SLLconst [c] y) x) -> (InvertFlags (CMPshiftLL x y [c]))
   991  (CMP x (SRLconst [c] y)) -> (CMPshiftRL x y [c])
   992  (CMP (SRLconst [c] y) x) -> (InvertFlags (CMPshiftRL x y [c]))
   993  (CMP x (SRAconst [c] y)) -> (CMPshiftRA x y [c])
   994  (CMP (SRAconst [c] y) x) -> (InvertFlags (CMPshiftRA x y [c]))
   995  (CMP x (SLL y z)) -> (CMPshiftLLreg x y z)
   996  (CMP (SLL y z) x) -> (InvertFlags (CMPshiftLLreg x y z))
   997  (CMP x (SRL y z)) -> (CMPshiftRLreg x y z)
   998  (CMP (SRL y z) x) -> (InvertFlags (CMPshiftRLreg x y z))
   999  (CMP x (SRA y z)) -> (CMPshiftRAreg x y z)
  1000  (CMP (SRA y z) x) -> (InvertFlags (CMPshiftRAreg x y z))
  1001  (TST x (SLLconst [c] y)) -> (TSTshiftLL x y [c])
  1002  (TST x (SRLconst [c] y)) -> (TSTshiftRL x y [c])
  1003  (TST x (SRAconst [c] y)) -> (TSTshiftRA x y [c])
  1004  (TST x (SLL y z)) -> (TSTshiftLLreg x y z)
  1005  (TST x (SRL y z)) -> (TSTshiftRLreg x y z)
  1006  (TST x (SRA y z)) -> (TSTshiftRAreg x y z)
  1007  (TEQ x (SLLconst [c] y)) -> (TEQshiftLL x y [c])
  1008  (TEQ x (SRLconst [c] y)) -> (TEQshiftRL x y [c])
  1009  (TEQ x (SRAconst [c] y)) -> (TEQshiftRA x y [c])
  1010  (TEQ x (SLL y z)) -> (TEQshiftLLreg x y z)
  1011  (TEQ x (SRL y z)) -> (TEQshiftRLreg x y z)
  1012  (TEQ x (SRA y z)) -> (TEQshiftRAreg x y z)
  1013  (CMN x (SLLconst [c] y)) -> (CMNshiftLL x y [c])
  1014  (CMN x (SRLconst [c] y)) -> (CMNshiftRL x y [c])
  1015  (CMN x (SRAconst [c] y)) -> (CMNshiftRA x y [c])
  1016  (CMN x (SLL y z)) -> (CMNshiftLLreg x y z)
  1017  (CMN x (SRL y z)) -> (CMNshiftRLreg x y z)
  1018  (CMN x (SRA y z)) -> (CMNshiftRAreg x y z)
  1019  
  1020  // prefer *const ops to *shift ops
  1021  (ADDshiftLL (MOVWconst [c]) x [d]) -> (ADDconst [c] (SLLconst <x.Type> x [d]))
  1022  (ADDshiftRL (MOVWconst [c]) x [d]) -> (ADDconst [c] (SRLconst <x.Type> x [d]))
  1023  (ADDshiftRA (MOVWconst [c]) x [d]) -> (ADDconst [c] (SRAconst <x.Type> x [d]))
  1024  (ADCshiftLL (MOVWconst [c]) x [d] flags) -> (ADCconst [c] (SLLconst <x.Type> x [d]) flags)
  1025  (ADCshiftRL (MOVWconst [c]) x [d] flags) -> (ADCconst [c] (SRLconst <x.Type> x [d]) flags)
  1026  (ADCshiftRA (MOVWconst [c]) x [d] flags) -> (ADCconst [c] (SRAconst <x.Type> x [d]) flags)
  1027  (ADDSshiftLL (MOVWconst [c]) x [d]) -> (ADDSconst [c] (SLLconst <x.Type> x [d]))
  1028  (ADDSshiftRL (MOVWconst [c]) x [d]) -> (ADDSconst [c] (SRLconst <x.Type> x [d]))
  1029  (ADDSshiftRA (MOVWconst [c]) x [d]) -> (ADDSconst [c] (SRAconst <x.Type> x [d]))
  1030  (SUBshiftLL (MOVWconst [c]) x [d]) -> (RSBconst [c] (SLLconst <x.Type> x [d]))
  1031  (SUBshiftRL (MOVWconst [c]) x [d]) -> (RSBconst [c] (SRLconst <x.Type> x [d]))
  1032  (SUBshiftRA (MOVWconst [c]) x [d]) -> (RSBconst [c] (SRAconst <x.Type> x [d]))
  1033  (SBCshiftLL (MOVWconst [c]) x [d] flags) -> (RSCconst [c] (SLLconst <x.Type> x [d]) flags)
  1034  (SBCshiftRL (MOVWconst [c]) x [d] flags) -> (RSCconst [c] (SRLconst <x.Type> x [d]) flags)
  1035  (SBCshiftRA (MOVWconst [c]) x [d] flags) -> (RSCconst [c] (SRAconst <x.Type> x [d]) flags)
  1036  (SUBSshiftLL (MOVWconst [c]) x [d]) -> (RSBSconst [c] (SLLconst <x.Type> x [d]))
  1037  (SUBSshiftRL (MOVWconst [c]) x [d]) -> (RSBSconst [c] (SRLconst <x.Type> x [d]))
  1038  (SUBSshiftRA (MOVWconst [c]) x [d]) -> (RSBSconst [c] (SRAconst <x.Type> x [d]))
  1039  (RSBshiftLL (MOVWconst [c]) x [d]) -> (SUBconst [c] (SLLconst <x.Type> x [d]))
  1040  (RSBshiftRL (MOVWconst [c]) x [d]) -> (SUBconst [c] (SRLconst <x.Type> x [d]))
  1041  (RSBshiftRA (MOVWconst [c]) x [d]) -> (SUBconst [c] (SRAconst <x.Type> x [d]))
  1042  (RSCshiftLL (MOVWconst [c]) x [d] flags) -> (SBCconst [c] (SLLconst <x.Type> x [d]) flags)
  1043  (RSCshiftRL (MOVWconst [c]) x [d] flags) -> (SBCconst [c] (SRLconst <x.Type> x [d]) flags)
  1044  (RSCshiftRA (MOVWconst [c]) x [d] flags) -> (SBCconst [c] (SRAconst <x.Type> x [d]) flags)
  1045  (RSBSshiftLL (MOVWconst [c]) x [d]) -> (SUBSconst [c] (SLLconst <x.Type> x [d]))
  1046  (RSBSshiftRL (MOVWconst [c]) x [d]) -> (SUBSconst [c] (SRLconst <x.Type> x [d]))
  1047  (RSBSshiftRA (MOVWconst [c]) x [d]) -> (SUBSconst [c] (SRAconst <x.Type> x [d]))
  1048  (ANDshiftLL (MOVWconst [c]) x [d]) -> (ANDconst [c] (SLLconst <x.Type> x [d]))
  1049  (ANDshiftRL (MOVWconst [c]) x [d]) -> (ANDconst [c] (SRLconst <x.Type> x [d]))
  1050  (ANDshiftRA (MOVWconst [c]) x [d]) -> (ANDconst [c] (SRAconst <x.Type> x [d]))
  1051  (ORshiftLL (MOVWconst [c]) x [d]) -> (ORconst [c] (SLLconst <x.Type> x [d]))
  1052  (ORshiftRL (MOVWconst [c]) x [d]) -> (ORconst [c] (SRLconst <x.Type> x [d]))
  1053  (ORshiftRA (MOVWconst [c]) x [d]) -> (ORconst [c] (SRAconst <x.Type> x [d]))
  1054  (XORshiftLL (MOVWconst [c]) x [d]) -> (XORconst [c] (SLLconst <x.Type> x [d]))
  1055  (XORshiftRL (MOVWconst [c]) x [d]) -> (XORconst [c] (SRLconst <x.Type> x [d]))
  1056  (XORshiftRA (MOVWconst [c]) x [d]) -> (XORconst [c] (SRAconst <x.Type> x [d]))
  1057  (XORshiftRR (MOVWconst [c]) x [d]) -> (XORconst [c] (SRRconst <x.Type> x [d]))
  1058  (CMPshiftLL (MOVWconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SLLconst <x.Type> x [d])))
  1059  (CMPshiftRL (MOVWconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRLconst <x.Type> x [d])))
  1060  (CMPshiftRA (MOVWconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRAconst <x.Type> x [d])))
  1061  (TSTshiftLL (MOVWconst [c]) x [d]) -> (TSTconst [c] (SLLconst <x.Type> x [d]))
  1062  (TSTshiftRL (MOVWconst [c]) x [d]) -> (TSTconst [c] (SRLconst <x.Type> x [d]))
  1063  (TSTshiftRA (MOVWconst [c]) x [d]) -> (TSTconst [c] (SRAconst <x.Type> x [d]))
  1064  (TEQshiftLL (MOVWconst [c]) x [d]) -> (TEQconst [c] (SLLconst <x.Type> x [d]))
  1065  (TEQshiftRL (MOVWconst [c]) x [d]) -> (TEQconst [c] (SRLconst <x.Type> x [d]))
  1066  (TEQshiftRA (MOVWconst [c]) x [d]) -> (TEQconst [c] (SRAconst <x.Type> x [d]))
  1067  (CMNshiftLL (MOVWconst [c]) x [d]) -> (CMNconst [c] (SLLconst <x.Type> x [d]))
  1068  (CMNshiftRL (MOVWconst [c]) x [d]) -> (CMNconst [c] (SRLconst <x.Type> x [d]))
  1069  (CMNshiftRA (MOVWconst [c]) x [d]) -> (CMNconst [c] (SRAconst <x.Type> x [d]))
  1070  
  1071  (ADDshiftLLreg (MOVWconst [c]) x y) -> (ADDconst [c] (SLL <x.Type> x y))
  1072  (ADDshiftRLreg (MOVWconst [c]) x y) -> (ADDconst [c] (SRL <x.Type> x y))
  1073  (ADDshiftRAreg (MOVWconst [c]) x y) -> (ADDconst [c] (SRA <x.Type> x y))
  1074  (ADCshiftLLreg (MOVWconst [c]) x y flags) -> (ADCconst [c] (SLL <x.Type> x y) flags)
  1075  (ADCshiftRLreg (MOVWconst [c]) x y flags) -> (ADCconst [c] (SRL <x.Type> x y) flags)
  1076  (ADCshiftRAreg (MOVWconst [c]) x y flags) -> (ADCconst [c] (SRA <x.Type> x y) flags)
  1077  (ADDSshiftLLreg (MOVWconst [c]) x y) -> (ADDSconst [c] (SLL <x.Type> x y))
  1078  (ADDSshiftRLreg (MOVWconst [c]) x y) -> (ADDSconst [c] (SRL <x.Type> x y))
  1079  (ADDSshiftRAreg (MOVWconst [c]) x y) -> (ADDSconst [c] (SRA <x.Type> x y))
  1080  (SUBshiftLLreg (MOVWconst [c]) x y) -> (RSBconst [c] (SLL <x.Type> x y))
  1081  (SUBshiftRLreg (MOVWconst [c]) x y) -> (RSBconst [c] (SRL <x.Type> x y))
  1082  (SUBshiftRAreg (MOVWconst [c]) x y) -> (RSBconst [c] (SRA <x.Type> x y))
  1083  (SBCshiftLLreg (MOVWconst [c]) x y flags) -> (RSCconst [c] (SLL <x.Type> x y) flags)
  1084  (SBCshiftRLreg (MOVWconst [c]) x y flags) -> (RSCconst [c] (SRL <x.Type> x y) flags)
  1085  (SBCshiftRAreg (MOVWconst [c]) x y flags) -> (RSCconst [c] (SRA <x.Type> x y) flags)
  1086  (SUBSshiftLLreg (MOVWconst [c]) x y) -> (RSBSconst [c] (SLL <x.Type> x y))
  1087  (SUBSshiftRLreg (MOVWconst [c]) x y) -> (RSBSconst [c] (SRL <x.Type> x y))
  1088  (SUBSshiftRAreg (MOVWconst [c]) x y) -> (RSBSconst [c] (SRA <x.Type> x y))
  1089  (RSBshiftLLreg (MOVWconst [c]) x y) -> (SUBconst [c] (SLL <x.Type> x y))
  1090  (RSBshiftRLreg (MOVWconst [c]) x y) -> (SUBconst [c] (SRL <x.Type> x y))
  1091  (RSBshiftRAreg (MOVWconst [c]) x y) -> (SUBconst [c] (SRA <x.Type> x y))
  1092  (RSCshiftLLreg (MOVWconst [c]) x y flags) -> (SBCconst [c] (SLL <x.Type> x y) flags)
  1093  (RSCshiftRLreg (MOVWconst [c]) x y flags) -> (SBCconst [c] (SRL <x.Type> x y) flags)
  1094  (RSCshiftRAreg (MOVWconst [c]) x y flags) -> (SBCconst [c] (SRA <x.Type> x y) flags)
  1095  (RSBSshiftLLreg (MOVWconst [c]) x y) -> (SUBSconst [c] (SLL <x.Type> x y))
  1096  (RSBSshiftRLreg (MOVWconst [c]) x y) -> (SUBSconst [c] (SRL <x.Type> x y))
  1097  (RSBSshiftRAreg (MOVWconst [c]) x y) -> (SUBSconst [c] (SRA <x.Type> x y))
  1098  (ANDshiftLLreg (MOVWconst [c]) x y) -> (ANDconst [c] (SLL <x.Type> x y))
  1099  (ANDshiftRLreg (MOVWconst [c]) x y) -> (ANDconst [c] (SRL <x.Type> x y))
  1100  (ANDshiftRAreg (MOVWconst [c]) x y) -> (ANDconst [c] (SRA <x.Type> x y))
  1101  (ORshiftLLreg (MOVWconst [c]) x y) -> (ORconst [c] (SLL <x.Type> x y))
  1102  (ORshiftRLreg (MOVWconst [c]) x y) -> (ORconst [c] (SRL <x.Type> x y))
  1103  (ORshiftRAreg (MOVWconst [c]) x y) -> (ORconst [c] (SRA <x.Type> x y))
  1104  (XORshiftLLreg (MOVWconst [c]) x y) -> (XORconst [c] (SLL <x.Type> x y))
  1105  (XORshiftRLreg (MOVWconst [c]) x y) -> (XORconst [c] (SRL <x.Type> x y))
  1106  (XORshiftRAreg (MOVWconst [c]) x y) -> (XORconst [c] (SRA <x.Type> x y))
  1107  (CMPshiftLLreg (MOVWconst [c]) x y) -> (InvertFlags (CMPconst [c] (SLL <x.Type> x y)))
  1108  (CMPshiftRLreg (MOVWconst [c]) x y) -> (InvertFlags (CMPconst [c] (SRL <x.Type> x y)))
  1109  (CMPshiftRAreg (MOVWconst [c]) x y) -> (InvertFlags (CMPconst [c] (SRA <x.Type> x y)))
  1110  (TSTshiftLLreg (MOVWconst [c]) x y) -> (TSTconst [c] (SLL <x.Type> x y))
  1111  (TSTshiftRLreg (MOVWconst [c]) x y) -> (TSTconst [c] (SRL <x.Type> x y))
  1112  (TSTshiftRAreg (MOVWconst [c]) x y) -> (TSTconst [c] (SRA <x.Type> x y))
  1113  (TEQshiftLLreg (MOVWconst [c]) x y) -> (TEQconst [c] (SLL <x.Type> x y))
  1114  (TEQshiftRLreg (MOVWconst [c]) x y) -> (TEQconst [c] (SRL <x.Type> x y))
  1115  (TEQshiftRAreg (MOVWconst [c]) x y) -> (TEQconst [c] (SRA <x.Type> x y))
  1116  (CMNshiftLLreg (MOVWconst [c]) x y) -> (CMNconst [c] (SLL <x.Type> x y))
  1117  (CMNshiftRLreg (MOVWconst [c]) x y) -> (CMNconst [c] (SRL <x.Type> x y))
  1118  (CMNshiftRAreg (MOVWconst [c]) x y) -> (CMNconst [c] (SRA <x.Type> x y))
  1119  
  1120  // constant folding in *shift ops
  1121  (ADDshiftLL x (MOVWconst [c]) [d]) -> (ADDconst x [int64(int32(uint32(c)<<uint64(d)))])
  1122  (ADDshiftRL x (MOVWconst [c]) [d]) -> (ADDconst x [int64(int32(uint32(c)>>uint64(d)))])
  1123  (ADDshiftRA x (MOVWconst [c]) [d]) -> (ADDconst x [int64(int32(c)>>uint64(d))])
  1124  (ADCshiftLL x (MOVWconst [c]) [d] flags) -> (ADCconst x [int64(int32(uint32(c)<<uint64(d)))] flags)
  1125  (ADCshiftRL x (MOVWconst [c]) [d] flags) -> (ADCconst x [int64(int32(uint32(c)>>uint64(d)))] flags)
  1126  (ADCshiftRA x (MOVWconst [c]) [d] flags) -> (ADCconst x [int64(int32(c)>>uint64(d))] flags)
  1127  (ADDSshiftLL x (MOVWconst [c]) [d]) -> (ADDSconst x [int64(int32(uint32(c)<<uint64(d)))])
  1128  (ADDSshiftRL x (MOVWconst [c]) [d]) -> (ADDSconst x [int64(int32(uint32(c)>>uint64(d)))])
  1129  (ADDSshiftRA x (MOVWconst [c]) [d]) -> (ADDSconst x [int64(int32(c)>>uint64(d))])
  1130  (SUBshiftLL x (MOVWconst [c]) [d]) -> (SUBconst x [int64(int32(uint32(c)<<uint64(d)))])
  1131  (SUBshiftRL x (MOVWconst [c]) [d]) -> (SUBconst x [int64(int32(uint32(c)>>uint64(d)))])
  1132  (SUBshiftRA x (MOVWconst [c]) [d]) -> (SUBconst x [int64(int32(c)>>uint64(d))])
  1133  (SBCshiftLL x (MOVWconst [c]) [d] flags) -> (SBCconst x [int64(int32(uint32(c)<<uint64(d)))] flags)
  1134  (SBCshiftRL x (MOVWconst [c]) [d] flags) -> (SBCconst x [int64(int32(uint32(c)>>uint64(d)))] flags)
  1135  (SBCshiftRA x (MOVWconst [c]) [d] flags) -> (SBCconst x [int64(int32(c)>>uint64(d))] flags)
  1136  (SUBSshiftLL x (MOVWconst [c]) [d]) -> (SUBSconst x [int64(int32(uint32(c)<<uint64(d)))])
  1137  (SUBSshiftRL x (MOVWconst [c]) [d]) -> (SUBSconst x [int64(int32(uint32(c)>>uint64(d)))])
  1138  (SUBSshiftRA x (MOVWconst [c]) [d]) -> (SUBSconst x [int64(int32(c)>>uint64(d))])
  1139  (RSBshiftLL x (MOVWconst [c]) [d]) -> (RSBconst x [int64(int32(uint32(c)<<uint64(d)))])
  1140  (RSBshiftRL x (MOVWconst [c]) [d]) -> (RSBconst x [int64(int32(uint32(c)>>uint64(d)))])
  1141  (RSBshiftRA x (MOVWconst [c]) [d]) -> (RSBconst x [int64(int32(c)>>uint64(d))])
  1142  (RSCshiftLL x (MOVWconst [c]) [d] flags) -> (RSCconst x [int64(int32(uint32(c)<<uint64(d)))] flags)
  1143  (RSCshiftRL x (MOVWconst [c]) [d] flags) -> (RSCconst x [int64(int32(uint32(c)>>uint64(d)))] flags)
  1144  (RSCshiftRA x (MOVWconst [c]) [d] flags) -> (RSCconst x [int64(int32(c)>>uint64(d))] flags)
  1145  (RSBSshiftLL x (MOVWconst [c]) [d]) -> (RSBSconst x [int64(int32(uint32(c)<<uint64(d)))])
  1146  (RSBSshiftRL x (MOVWconst [c]) [d]) -> (RSBSconst x [int64(int32(uint32(c)>>uint64(d)))])
  1147  (RSBSshiftRA x (MOVWconst [c]) [d]) -> (RSBSconst x [int64(int32(c)>>uint64(d))])
  1148  (ANDshiftLL x (MOVWconst [c]) [d]) -> (ANDconst x [int64(int32(uint32(c)<<uint64(d)))])
  1149  (ANDshiftRL x (MOVWconst [c]) [d]) -> (ANDconst x [int64(int32(uint32(c)>>uint64(d)))])
  1150  (ANDshiftRA x (MOVWconst [c]) [d]) -> (ANDconst x [int64(int32(c)>>uint64(d))])
  1151  (ORshiftLL x (MOVWconst [c]) [d]) -> (ORconst x [int64(int32(uint32(c)<<uint64(d)))])
  1152  (ORshiftRL x (MOVWconst [c]) [d]) -> (ORconst x [int64(int32(uint32(c)>>uint64(d)))])
  1153  (ORshiftRA x (MOVWconst [c]) [d]) -> (ORconst x [int64(int32(c)>>uint64(d))])
  1154  (XORshiftLL x (MOVWconst [c]) [d]) -> (XORconst x [int64(int32(uint32(c)<<uint64(d)))])
  1155  (XORshiftRL x (MOVWconst [c]) [d]) -> (XORconst x [int64(int32(uint32(c)>>uint64(d)))])
  1156  (XORshiftRA x (MOVWconst [c]) [d]) -> (XORconst x [int64(int32(c)>>uint64(d))])
  1157  (XORshiftRR x (MOVWconst [c]) [d]) -> (XORconst x [int64(int32(uint32(c)>>uint64(d)|uint32(c)<<uint64(32-d)))])
  1158  (BICshiftLL x (MOVWconst [c]) [d]) -> (BICconst x [int64(int32(uint32(c)<<uint64(d)))])
  1159  (BICshiftRL x (MOVWconst [c]) [d]) -> (BICconst x [int64(int32(uint32(c)>>uint64(d)))])
  1160  (BICshiftRA x (MOVWconst [c]) [d]) -> (BICconst x [int64(int32(c)>>uint64(d))])
  1161  (MVNshiftLL (MOVWconst [c]) [d]) -> (MOVWconst [^int64(uint32(c)<<uint64(d))])
  1162  (MVNshiftRL (MOVWconst [c]) [d]) -> (MOVWconst [^int64(uint32(c)>>uint64(d))])
  1163  (MVNshiftRA (MOVWconst [c]) [d]) -> (MOVWconst [^int64(int32(c)>>uint64(d))])
  1164  (CMPshiftLL x (MOVWconst [c]) [d]) -> (CMPconst x [int64(int32(uint32(c)<<uint64(d)))])
  1165  (CMPshiftRL x (MOVWconst [c]) [d]) -> (CMPconst x [int64(int32(uint32(c)>>uint64(d)))])
  1166  (CMPshiftRA x (MOVWconst [c]) [d]) -> (CMPconst x [int64(int32(c)>>uint64(d))])
  1167  (TSTshiftLL x (MOVWconst [c]) [d]) -> (TSTconst x [int64(int32(uint32(c)<<uint64(d)))])
  1168  (TSTshiftRL x (MOVWconst [c]) [d]) -> (TSTconst x [int64(int32(uint32(c)>>uint64(d)))])
  1169  (TSTshiftRA x (MOVWconst [c]) [d]) -> (TSTconst x [int64(int32(c)>>uint64(d))])
  1170  (TEQshiftLL x (MOVWconst [c]) [d]) -> (TEQconst x [int64(int32(uint32(c)<<uint64(d)))])
  1171  (TEQshiftRL x (MOVWconst [c]) [d]) -> (TEQconst x [int64(int32(uint32(c)>>uint64(d)))])
  1172  (TEQshiftRA x (MOVWconst [c]) [d]) -> (TEQconst x [int64(int32(c)>>uint64(d))])
  1173  (CMNshiftLL x (MOVWconst [c]) [d]) -> (CMNconst x [int64(int32(uint32(c)<<uint64(d)))])
  1174  (CMNshiftRL x (MOVWconst [c]) [d]) -> (CMNconst x [int64(int32(uint32(c)>>uint64(d)))])
  1175  (CMNshiftRA x (MOVWconst [c]) [d]) -> (CMNconst x [int64(int32(c)>>uint64(d))])
  1176  
  1177  (ADDshiftLLreg x y (MOVWconst [c])) -> (ADDshiftLL x y [c])
  1178  (ADDshiftRLreg x y (MOVWconst [c])) -> (ADDshiftRL x y [c])
  1179  (ADDshiftRAreg x y (MOVWconst [c])) -> (ADDshiftRA x y [c])
  1180  (ADCshiftLLreg x y (MOVWconst [c]) flags) -> (ADCshiftLL x y [c] flags)
  1181  (ADCshiftRLreg x y (MOVWconst [c]) flags) -> (ADCshiftRL x y [c] flags)
  1182  (ADCshiftRAreg x y (MOVWconst [c]) flags) -> (ADCshiftRA x y [c] flags)
  1183  (ADDSshiftLLreg x y (MOVWconst [c])) -> (ADDSshiftLL x y [c])
  1184  (ADDSshiftRLreg x y (MOVWconst [c])) -> (ADDSshiftRL x y [c])
  1185  (ADDSshiftRAreg x y (MOVWconst [c])) -> (ADDSshiftRA x y [c])
  1186  (SUBshiftLLreg x y (MOVWconst [c])) -> (SUBshiftLL x y [c])
  1187  (SUBshiftRLreg x y (MOVWconst [c])) -> (SUBshiftRL x y [c])
  1188  (SUBshiftRAreg x y (MOVWconst [c])) -> (SUBshiftRA x y [c])
  1189  (SBCshiftLLreg x y (MOVWconst [c]) flags) -> (SBCshiftLL x y [c] flags)
  1190  (SBCshiftRLreg x y (MOVWconst [c]) flags) -> (SBCshiftRL x y [c] flags)
  1191  (SBCshiftRAreg x y (MOVWconst [c]) flags) -> (SBCshiftRA x y [c] flags)
  1192  (SUBSshiftLLreg x y (MOVWconst [c])) -> (SUBSshiftLL x y [c])
  1193  (SUBSshiftRLreg x y (MOVWconst [c])) -> (SUBSshiftRL x y [c])
  1194  (SUBSshiftRAreg x y (MOVWconst [c])) -> (SUBSshiftRA x y [c])
  1195  (RSBshiftLLreg x y (MOVWconst [c])) -> (RSBshiftLL x y [c])
  1196  (RSBshiftRLreg x y (MOVWconst [c])) -> (RSBshiftRL x y [c])
  1197  (RSBshiftRAreg x y (MOVWconst [c])) -> (RSBshiftRA x y [c])
  1198  (RSCshiftLLreg x y (MOVWconst [c]) flags) -> (RSCshiftLL x y [c] flags)
  1199  (RSCshiftRLreg x y (MOVWconst [c]) flags) -> (RSCshiftRL x y [c] flags)
  1200  (RSCshiftRAreg x y (MOVWconst [c]) flags) -> (RSCshiftRA x y [c] flags)
  1201  (RSBSshiftLLreg x y (MOVWconst [c])) -> (RSBSshiftLL x y [c])
  1202  (RSBSshiftRLreg x y (MOVWconst [c])) -> (RSBSshiftRL x y [c])
  1203  (RSBSshiftRAreg x y (MOVWconst [c])) -> (RSBSshiftRA x y [c])
  1204  (ANDshiftLLreg x y (MOVWconst [c])) -> (ANDshiftLL x y [c])
  1205  (ANDshiftRLreg x y (MOVWconst [c])) -> (ANDshiftRL x y [c])
  1206  (ANDshiftRAreg x y (MOVWconst [c])) -> (ANDshiftRA x y [c])
  1207  (ORshiftLLreg x y (MOVWconst [c])) -> (ORshiftLL x y [c])
  1208  (ORshiftRLreg x y (MOVWconst [c])) -> (ORshiftRL x y [c])
  1209  (ORshiftRAreg x y (MOVWconst [c])) -> (ORshiftRA x y [c])
  1210  (XORshiftLLreg x y (MOVWconst [c])) -> (XORshiftLL x y [c])
  1211  (XORshiftRLreg x y (MOVWconst [c])) -> (XORshiftRL x y [c])
  1212  (XORshiftRAreg x y (MOVWconst [c])) -> (XORshiftRA x y [c])
  1213  (BICshiftLLreg x y (MOVWconst [c])) -> (BICshiftLL x y [c])
  1214  (BICshiftRLreg x y (MOVWconst [c])) -> (BICshiftRL x y [c])
  1215  (BICshiftRAreg x y (MOVWconst [c])) -> (BICshiftRA x y [c])
  1216  (MVNshiftLLreg x (MOVWconst [c])) -> (MVNshiftLL x [c])
  1217  (MVNshiftRLreg x (MOVWconst [c])) -> (MVNshiftRL x [c])
  1218  (MVNshiftRAreg x (MOVWconst [c])) -> (MVNshiftRA x [c])
  1219  (CMPshiftLLreg x y (MOVWconst [c])) -> (CMPshiftLL x y [c])
  1220  (CMPshiftRLreg x y (MOVWconst [c])) -> (CMPshiftRL x y [c])
  1221  (CMPshiftRAreg x y (MOVWconst [c])) -> (CMPshiftRA x y [c])
  1222  (TSTshiftLLreg x y (MOVWconst [c])) -> (TSTshiftLL x y [c])
  1223  (TSTshiftRLreg x y (MOVWconst [c])) -> (TSTshiftRL x y [c])
  1224  (TSTshiftRAreg x y (MOVWconst [c])) -> (TSTshiftRA x y [c])
  1225  (TEQshiftLLreg x y (MOVWconst [c])) -> (TEQshiftLL x y [c])
  1226  (TEQshiftRLreg x y (MOVWconst [c])) -> (TEQshiftRL x y [c])
  1227  (TEQshiftRAreg x y (MOVWconst [c])) -> (TEQshiftRA x y [c])
  1228  (CMNshiftLLreg x y (MOVWconst [c])) -> (CMNshiftLL x y [c])
  1229  (CMNshiftRLreg x y (MOVWconst [c])) -> (CMNshiftRL x y [c])
  1230  (CMNshiftRAreg x y (MOVWconst [c])) -> (CMNshiftRA x y [c])
  1231  
  1232  // Generate rotates
  1233  (ADDshiftLL [c] (SRLconst x [32-c]) x) -> (SRRconst [32-c] x)
  1234  ( ORshiftLL [c] (SRLconst x [32-c]) x) -> (SRRconst [32-c] x)
  1235  (XORshiftLL [c] (SRLconst x [32-c]) x) -> (SRRconst [32-c] x)
  1236  (ADDshiftRL [c] (SLLconst x [32-c]) x) -> (SRRconst [   c] x)
  1237  ( ORshiftRL [c] (SLLconst x [32-c]) x) -> (SRRconst [   c] x)
  1238  (XORshiftRL [c] (SLLconst x [32-c]) x) -> (SRRconst [   c] x)
  1239  
  1240  (RotateLeft32 x (MOVWconst [c])) -> (SRRconst [-c&31] x)
  1241  (RotateLeft16 <t> x (MOVWconst [c])) -> (Or16 (Lsh16x32 <t> x (MOVWconst [c&15])) (Rsh16Ux32 <t> x (MOVWconst [-c&15])))
  1242  (RotateLeft8 <t> x (MOVWconst [c])) -> (Or8 (Lsh8x32 <t> x (MOVWconst [c&7])) (Rsh8Ux32 <t> x (MOVWconst [-c&7])))
  1243  (RotateLeft32 x y) -> (SRR x (RSBconst [0] <y.Type> y))
  1244  
  1245  // ((x>>8) | (x<<8)) -> (REV16 x), the type of x is uint16, "|" can also be "^" or "+".
  1246  // UBFX instruction is supported by ARMv6T2, ARMv7 and above versions, REV16 is supported by
  1247  // ARMv6 and above versions. So for ARMv6, we need to match SLLconst, SRLconst and ORshiftLL.
  1248  ((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (BFXU <typ.UInt16> [armBFAuxInt(8, 8)] x) x) -> (REV16 x)
  1249  ((ADDshiftLL|ORshiftLL|XORshiftLL) <typ.UInt16> [8] (SRLconst <typ.UInt16> [24] (SLLconst [16] x)) x) && objabi.GOARM>=6 -> (REV16 x)
  1250  
  1251  // use indexed loads and stores
  1252  (MOVWload [0] {sym} (ADD ptr idx) mem) && sym == nil -> (MOVWloadidx ptr idx mem)
  1253  (MOVWstore [0] {sym} (ADD ptr idx) val mem) && sym == nil -> (MOVWstoreidx ptr idx val mem)
  1254  (MOVWload [0] {sym} (ADDshiftLL ptr idx [c]) mem) && sym == nil -> (MOVWloadshiftLL ptr idx [c] mem)
  1255  (MOVWload [0] {sym} (ADDshiftRL ptr idx [c]) mem) && sym == nil -> (MOVWloadshiftRL ptr idx [c] mem)
  1256  (MOVWload [0] {sym} (ADDshiftRA ptr idx [c]) mem) && sym == nil -> (MOVWloadshiftRA ptr idx [c] mem)
  1257  (MOVWstore [0] {sym} (ADDshiftLL ptr idx [c]) val mem) && sym == nil -> (MOVWstoreshiftLL ptr idx [c] val mem)
  1258  (MOVWstore [0] {sym} (ADDshiftRL ptr idx [c]) val mem) && sym == nil -> (MOVWstoreshiftRL ptr idx [c] val mem)
  1259  (MOVWstore [0] {sym} (ADDshiftRA ptr idx [c]) val mem) && sym == nil -> (MOVWstoreshiftRA ptr idx [c] val mem)
  1260  (MOVBUload [0] {sym} (ADD ptr idx) mem) && sym == nil -> (MOVBUloadidx ptr idx mem)
  1261  (MOVBload [0] {sym} (ADD ptr idx) mem) && sym == nil -> (MOVBloadidx ptr idx mem)
  1262  (MOVBstore [0] {sym} (ADD ptr idx) val mem) && sym == nil -> (MOVBstoreidx ptr idx val mem)
  1263  (MOVHUload [0] {sym} (ADD ptr idx) mem) && sym == nil -> (MOVHUloadidx ptr idx mem)
  1264  (MOVHload [0] {sym} (ADD ptr idx) mem) && sym == nil -> (MOVHloadidx ptr idx mem)
  1265  (MOVHstore [0] {sym} (ADD ptr idx) val mem) && sym == nil -> (MOVHstoreidx ptr idx val mem)
  1266  
  1267  // constant folding in indexed loads and stores
  1268  (MOVWloadidx ptr (MOVWconst [c]) mem) -> (MOVWload [c] ptr mem)
  1269  (MOVWloadidx (MOVWconst [c]) ptr mem) -> (MOVWload [c] ptr mem)
  1270  (MOVBloadidx ptr (MOVWconst [c]) mem) -> (MOVBload [c] ptr mem)
  1271  (MOVBloadidx (MOVWconst [c]) ptr mem) -> (MOVBload [c] ptr mem)
  1272  (MOVBUloadidx ptr (MOVWconst [c]) mem) -> (MOVBUload [c] ptr mem)
  1273  (MOVBUloadidx (MOVWconst [c]) ptr mem) -> (MOVBUload [c] ptr mem)
  1274  (MOVHUloadidx ptr (MOVWconst [c]) mem) -> (MOVHUload [c] ptr mem)
  1275  (MOVHUloadidx (MOVWconst [c]) ptr mem) -> (MOVHUload [c] ptr mem)
  1276  (MOVHloadidx ptr (MOVWconst [c]) mem) -> (MOVHload [c] ptr mem)
  1277  (MOVHloadidx (MOVWconst [c]) ptr mem) -> (MOVHload [c] ptr mem)
  1278  
  1279  (MOVWstoreidx ptr (MOVWconst [c]) val mem) -> (MOVWstore [c] ptr val mem)
  1280  (MOVWstoreidx (MOVWconst [c]) ptr val mem) -> (MOVWstore [c] ptr val mem)
  1281  (MOVBstoreidx ptr (MOVWconst [c]) val mem) -> (MOVBstore [c] ptr val mem)
  1282  (MOVBstoreidx (MOVWconst [c]) ptr val mem) -> (MOVBstore [c] ptr val mem)
  1283  (MOVHstoreidx ptr (MOVWconst [c]) val mem) -> (MOVHstore [c] ptr val mem)
  1284  (MOVHstoreidx (MOVWconst [c]) ptr val mem) -> (MOVHstore [c] ptr val mem)
  1285  
  1286  (MOVWloadidx ptr (SLLconst idx [c]) mem) -> (MOVWloadshiftLL ptr idx [c] mem)
  1287  (MOVWloadidx (SLLconst idx [c]) ptr mem) -> (MOVWloadshiftLL ptr idx [c] mem)
  1288  (MOVWloadidx ptr (SRLconst idx [c]) mem) -> (MOVWloadshiftRL ptr idx [c] mem)
  1289  (MOVWloadidx (SRLconst idx [c]) ptr mem) -> (MOVWloadshiftRL ptr idx [c] mem)
  1290  (MOVWloadidx ptr (SRAconst idx [c]) mem) -> (MOVWloadshiftRA ptr idx [c] mem)
  1291  (MOVWloadidx (SRAconst idx [c]) ptr mem) -> (MOVWloadshiftRA ptr idx [c] mem)
  1292  
  1293  (MOVWstoreidx ptr (SLLconst idx [c]) val mem) -> (MOVWstoreshiftLL ptr idx [c] val mem)
  1294  (MOVWstoreidx (SLLconst idx [c]) ptr val mem) -> (MOVWstoreshiftLL ptr idx [c] val mem)
  1295  (MOVWstoreidx ptr (SRLconst idx [c]) val mem) -> (MOVWstoreshiftRL ptr idx [c] val mem)
  1296  (MOVWstoreidx (SRLconst idx [c]) ptr val mem) -> (MOVWstoreshiftRL ptr idx [c] val mem)
  1297  (MOVWstoreidx ptr (SRAconst idx [c]) val mem) -> (MOVWstoreshiftRA ptr idx [c] val mem)
  1298  (MOVWstoreidx (SRAconst idx [c]) ptr val mem) -> (MOVWstoreshiftRA ptr idx [c] val mem)
  1299  
  1300  (MOVWloadshiftLL ptr (MOVWconst [c]) [d] mem) -> (MOVWload [int64(uint32(c)<<uint64(d))] ptr mem)
  1301  (MOVWloadshiftRL ptr (MOVWconst [c]) [d] mem) -> (MOVWload [int64(uint32(c)>>uint64(d))] ptr mem)
  1302  (MOVWloadshiftRA ptr (MOVWconst [c]) [d] mem) -> (MOVWload [int64(int32(c)>>uint64(d))] ptr mem)
  1303  
  1304  (MOVWstoreshiftLL ptr (MOVWconst [c]) [d] val mem) -> (MOVWstore [int64(uint32(c)<<uint64(d))] ptr val mem)
  1305  (MOVWstoreshiftRL ptr (MOVWconst [c]) [d] val mem) -> (MOVWstore [int64(uint32(c)>>uint64(d))] ptr val mem)
  1306  (MOVWstoreshiftRA ptr (MOVWconst [c]) [d] val mem) -> (MOVWstore [int64(int32(c)>>uint64(d))] ptr val mem)
  1307  
  1308  // generic simplifications
  1309  (ADD x (RSBconst [0] y)) -> (SUB x y)
  1310  (ADD <t> (RSBconst [c] x) (RSBconst [d] y)) -> (RSBconst [c+d] (ADD <t> x y))
  1311  (SUB x x) -> (MOVWconst [0])
  1312  (RSB x x) -> (MOVWconst [0])
  1313  (AND x x) -> x
  1314  (OR x x) -> x
  1315  (XOR x x) -> (MOVWconst [0])
  1316  (BIC x x) -> (MOVWconst [0])
  1317  
  1318  (ADD (MUL x y) a) -> (MULA x y a)
  1319  (SUB a (MUL x y)) && objabi.GOARM == 7 -> (MULS x y a)
  1320  (RSB (MUL x y) a) && objabi.GOARM == 7 -> (MULS x y a)
  1321  
  1322  (NEGF (MULF x y)) && objabi.GOARM >= 6 -> (NMULF x y)
  1323  (NEGD (MULD x y)) && objabi.GOARM >= 6 -> (NMULD x y)
  1324  (MULF (NEGF x) y) && objabi.GOARM >= 6 -> (NMULF x y)
  1325  (MULD (NEGD x) y) && objabi.GOARM >= 6 -> (NMULD x y)
  1326  (NMULF (NEGF x) y) -> (MULF x y)
  1327  (NMULD (NEGD x) y) -> (MULD x y)
  1328  
  1329  // the result will overwrite the addend, since they are in the same register
  1330  (ADDF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y)
  1331  (ADDF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y)
  1332  (ADDD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y)
  1333  (ADDD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y)
  1334  (SUBF a (MULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSF a x y)
  1335  (SUBF a (NMULF x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAF a x y)
  1336  (SUBD a (MULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULSD a x y)
  1337  (SUBD a (NMULD x y)) && a.Uses == 1 && objabi.GOARM >= 6 -> (MULAD a x y)
  1338  
  1339  (AND x (MVN y)) -> (BIC x y)
  1340  
  1341  // simplification with *shift ops
  1342  (SUBshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1343  (SUBshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1344  (SUBshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1345  (RSBshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1346  (RSBshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1347  (RSBshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1348  (ANDshiftLL x y:(SLLconst x [c]) [d]) && c==d -> y
  1349  (ANDshiftRL x y:(SRLconst x [c]) [d]) && c==d -> y
  1350  (ANDshiftRA x y:(SRAconst x [c]) [d]) && c==d -> y
  1351  (ORshiftLL x y:(SLLconst x [c]) [d]) && c==d -> y
  1352  (ORshiftRL x y:(SRLconst x [c]) [d]) && c==d -> y
  1353  (ORshiftRA x y:(SRAconst x [c]) [d]) && c==d -> y
  1354  (XORshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1355  (XORshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1356  (XORshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1357  (BICshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1358  (BICshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1359  (BICshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVWconst [0])
  1360  (AND x (MVNshiftLL y [c])) -> (BICshiftLL x y [c])
  1361  (AND x (MVNshiftRL y [c])) -> (BICshiftRL x y [c])
  1362  (AND x (MVNshiftRA y [c])) -> (BICshiftRA x y [c])
  1363  
  1364  // floating point optimizations
  1365  (CMPF x (MOVFconst [0])) -> (CMPF0 x)
  1366  (CMPD x (MOVDconst [0])) -> (CMPD0 x)
  1367  
  1368  // bit extraction
  1369  (SRAconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFX [(d-c)|(32-d)<<8] x)
  1370  (SRLconst (SLLconst x [c]) [d]) && objabi.GOARM==7 && uint64(d)>=uint64(c) && uint64(d)<=31 -> (BFXU [(d-c)|(32-d)<<8] x)
  1371  
  1372  // comparison simplification
  1373  (CMP x (RSBconst [0] y)) -> (CMN x y)
  1374  (CMN x (RSBconst [0] y)) -> (CMP x y)
  1375  (EQ (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (EQ (CMP x y) yes no)
  1376  (EQ (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (EQ (CMP a (MUL <x.Type> x y)) yes no)
  1377  (EQ (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (EQ (CMPconst [c] x) yes no)
  1378  (EQ (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftLL x y [c]) yes no)
  1379  (EQ (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftRL x y [c]) yes no)
  1380  (EQ (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftRA x y [c]) yes no)
  1381  (EQ (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftLLreg x y z) yes no)
  1382  (EQ (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftRLreg x y z) yes no)
  1383  (EQ (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftRAreg x y z) yes no)
  1384  (NE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (NE (CMP x y) yes no)
  1385  (NE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (NE (CMP a (MUL <x.Type> x y)) yes no)
  1386  (NE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (NE (CMPconst [c] x) yes no)
  1387  (NE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftLL x y [c]) yes no)
  1388  (NE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftRL x y [c]) yes no)
  1389  (NE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftRA x y [c]) yes no)
  1390  (NE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftLLreg x y z) yes no)
  1391  (NE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftRLreg x y z) yes no)
  1392  (NE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftRAreg x y z) yes no)
  1393  (EQ (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (EQ (CMN x y) yes no)
  1394  (EQ (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (EQ (CMN a (MUL <x.Type> x y)) yes no)
  1395  (EQ (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (EQ (CMNconst [c] x) yes no)
  1396  (EQ (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftLL x y [c]) yes no)
  1397  (EQ (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftRL x y [c]) yes no)
  1398  (EQ (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftRA x y [c]) yes no)
  1399  (EQ (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftLLreg x y z) yes no)
  1400  (EQ (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftRLreg x y z) yes no)
  1401  (EQ (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftRAreg x y z) yes no)
  1402  (NE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (NE (CMN x y) yes no)
  1403  (NE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (NE (CMN a (MUL <x.Type> x y)) yes no)
  1404  (NE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (NE (CMNconst [c] x) yes no)
  1405  (NE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftLL x y [c]) yes no)
  1406  (NE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftRL x y [c]) yes no)
  1407  (NE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftRA x y [c]) yes no)
  1408  (NE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftLLreg x y z) yes no)
  1409  (NE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftRLreg x y z) yes no)
  1410  (NE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftRAreg x y z) yes no)
  1411  (EQ (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (EQ (TST x y) yes no)
  1412  (EQ (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (EQ (TSTconst [c] x) yes no)
  1413  (EQ (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftLL x y [c]) yes no)
  1414  (EQ (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftRL x y [c]) yes no)
  1415  (EQ (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftRA x y [c]) yes no)
  1416  (EQ (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftLLreg x y z) yes no)
  1417  (EQ (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftRLreg x y z) yes no)
  1418  (EQ (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftRAreg x y z) yes no)
  1419  (NE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (NE (TST x y) yes no)
  1420  (NE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (NE (TSTconst [c] x) yes no)
  1421  (NE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftLL x y [c]) yes no)
  1422  (NE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftRL x y [c]) yes no)
  1423  (NE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftRA x y [c]) yes no)
  1424  (NE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftLLreg x y z) yes no)
  1425  (NE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftRLreg x y z) yes no)
  1426  (NE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftRAreg x y z) yes no)
  1427  (EQ (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (EQ (TEQ x y) yes no)
  1428  (EQ (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (EQ (TEQconst [c] x) yes no)
  1429  (EQ (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftLL x y [c]) yes no)
  1430  (EQ (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftRL x y [c]) yes no)
  1431  (EQ (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftRA x y [c]) yes no)
  1432  (EQ (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftLLreg x y z) yes no)
  1433  (EQ (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftRLreg x y z) yes no)
  1434  (EQ (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftRAreg x y z) yes no)
  1435  (NE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (NE (TEQ x y) yes no)
  1436  (NE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (NE (TEQconst [c] x) yes no)
  1437  (NE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftLL x y [c]) yes no)
  1438  (NE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftRL x y [c]) yes no)
  1439  (NE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftRA x y [c]) yes no)
  1440  (NE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftLLreg x y z) yes no)
  1441  (NE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftRLreg x y z) yes no)
  1442  (NE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftRAreg x y z) yes no)
  1443  (LT (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (LT (CMP x y) yes no)
  1444  (LT (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (LT (CMP a (MUL <x.Type> x y)) yes no)
  1445  (LT (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (LT (CMPconst [c] x) yes no)
  1446  (LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftLL x y [c]) yes no)
  1447  (LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftRL x y [c]) yes no)
  1448  (LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftRA x y [c]) yes no)
  1449  (LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftLLreg x y z) yes no)
  1450  (LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftRLreg x y z) yes no)
  1451  (LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftRAreg x y z) yes no)
  1452  (LE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (LE (CMP x y) yes no)
  1453  (LE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (LE (CMP a (MUL <x.Type> x y)) yes no)
  1454  (LE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (LE (CMPconst [c] x) yes no)
  1455  (LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftLL x y [c]) yes no)
  1456  (LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftRL x y [c]) yes no)
  1457  (LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftRA x y [c]) yes no)
  1458  (LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftLLreg x y z) yes no)
  1459  (LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftRLreg x y z) yes no)
  1460  (LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftRAreg x y z) yes no)
  1461  (LT (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (LT (CMN x y) yes no)
  1462  (LT (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (LT (CMN a (MUL <x.Type> x y)) yes no)
  1463  (LT (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (LT (CMNconst [c] x) yes no)
  1464  (LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftLL x y [c]) yes no)
  1465  (LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftRL x y [c]) yes no)
  1466  (LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftRA x y [c]) yes no)
  1467  (LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftLLreg x y z) yes no)
  1468  (LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftRLreg x y z) yes no)
  1469  (LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftRAreg x y z) yes no)
  1470  (LE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (LE (CMN x y) yes no)
  1471  (LE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (LE (CMN a (MUL <x.Type> x y)) yes no)
  1472  (LE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1  -> (LE (CMNconst [c] x) yes no)
  1473  (LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftLL x y [c]) yes no)
  1474  (LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftRL x y [c]) yes no)
  1475  (LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftRA x y [c]) yes no)
  1476  (LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftLLreg x y z) yes no)
  1477  (LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftRLreg x y z) yes no)
  1478  (LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftRAreg x y z) yes no)
  1479  (LT (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (LT (TST x y) yes no)
  1480  (LT (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (LT (TSTconst [c] x) yes no)
  1481  (LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftLL x y [c]) yes no)
  1482  (LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftRL x y [c]) yes no)
  1483  (LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftRA x y [c]) yes no)
  1484  (LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftLLreg x y z) yes no)
  1485  (LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftRLreg x y z) yes no)
  1486  (LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftRAreg x y z) yes no)
  1487  (LE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (LE (TST x y) yes no)
  1488  (LE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (LE (TSTconst [c] x) yes no)
  1489  (LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftLL x y [c]) yes no)
  1490  (LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftRL x y [c]) yes no)
  1491  (LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftRA x y [c]) yes no)
  1492  (LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftLLreg x y z) yes no)
  1493  (LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftRLreg x y z) yes no)
  1494  (LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftRAreg x y z) yes no)
  1495  (LT (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (LT (TEQ x y) yes no)
  1496  (LT (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (LT (TEQconst [c] x) yes no)
  1497  (LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftLL x y [c]) yes no)
  1498  (LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftRL x y [c]) yes no)
  1499  (LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftRA x y [c]) yes no)
  1500  (LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftLLreg x y z) yes no)
  1501  (LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftRLreg x y z) yes no)
  1502  (LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftRAreg x y z) yes no)
  1503  (LE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (LE (TEQ x y) yes no)
  1504  (LE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1  -> (LE (TEQconst [c] x) yes no)
  1505  (LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftLL x y [c]) yes no)
  1506  (LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftRL x y [c]) yes no)
  1507  (LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftRA x y [c]) yes no)
  1508  (LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftLLreg x y z) yes no)
  1509  (LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftRLreg x y z) yes no)
  1510  (LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftRAreg x y z) yes no)
  1511  (GT (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (GT (CMP x y) yes no)
  1512  (GT (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (GT (CMP a (MUL <x.Type> x y)) yes no)
  1513  (GT (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (GT (CMPconst [c] x) yes no)
  1514  (GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftLL x y [c]) yes no)
  1515  (GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftRL x y [c]) yes no)
  1516  (GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftRA x y [c]) yes no)
  1517  (GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftLLreg x y z) yes no)
  1518  (GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftRLreg x y z) yes no)
  1519  (GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftRAreg x y z) yes no)
  1520  (GE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (GE (CMP x y) yes no)
  1521  (GE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (GE (CMP a (MUL <x.Type> x y)) yes no)
  1522  (GE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (GE (CMPconst [c] x) yes no)
  1523  (GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftLL x y [c]) yes no)
  1524  (GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftRL x y [c]) yes no)
  1525  (GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftRA x y [c]) yes no)
  1526  (GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftLLreg x y z) yes no)
  1527  (GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftRLreg x y z) yes no)
  1528  (GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftRAreg x y z) yes no)
  1529  (GT (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (GT (CMN x y) yes no)
  1530  (GT (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (GT (CMNconst [c] x) yes no)
  1531  (GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftLL x y [c]) yes no)
  1532  (GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftRL x y [c]) yes no)
  1533  (GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftRA x y [c]) yes no)
  1534  (GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftLLreg x y z) yes no)
  1535  (GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftRLreg x y z) yes no)
  1536  (GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftRAreg x y z) yes no)
  1537  (GE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (GE (CMN x y) yes no)
  1538  (GE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (GE (CMN a (MUL <x.Type> x y)) yes no)
  1539  (GE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (GE (CMNconst [c] x) yes no)
  1540  (GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftLL x y [c]) yes no)
  1541  (GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftRL x y [c]) yes no)
  1542  (GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftRA x y [c]) yes no)
  1543  (GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftLLreg x y z) yes no)
  1544  (GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftRLreg x y z) yes no)
  1545  (GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftRAreg x y z) yes no)
  1546  (GT (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (GT (TST x y) yes no)
  1547  (GT (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (GT (CMN a (MUL <x.Type> x y)) yes no)
  1548  (GT (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (GT (TSTconst [c] x) yes no)
  1549  (GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftLL x y [c]) yes no)
  1550  (GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftRL x y [c]) yes no)
  1551  (GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftRA x y [c]) yes no)
  1552  (GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftLLreg x y z) yes no)
  1553  (GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftRLreg x y z) yes no)
  1554  (GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftRAreg x y z) yes no)
  1555  (GE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (GE (TST x y) yes no)
  1556  (GE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (GE (TSTconst [c] x) yes no)
  1557  (GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftLL x y [c]) yes no)
  1558  (GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftRL x y [c]) yes no)
  1559  (GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftRA x y [c]) yes no)
  1560  (GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftLLreg x y z) yes no)
  1561  (GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftRLreg x y z) yes no)
  1562  (GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftRAreg x y z) yes no)
  1563  (GT (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (GT (TEQ x y) yes no)
  1564  (GT (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (GT (TEQconst [c] x) yes no)
  1565  (GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftLL x y [c]) yes no)
  1566  (GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftRL x y [c]) yes no)
  1567  (GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftRA x y [c]) yes no)
  1568  (GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftLLreg x y z) yes no)
  1569  (GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftRLreg x y z) yes no)
  1570  (GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftRAreg x y z) yes no)
  1571  (GE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (GE (TEQ x y) yes no)
  1572  (GE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (GE (TEQconst [c] x) yes no)
  1573  (GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftLL x y [c]) yes no)
  1574  (GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftRL x y [c]) yes no)
  1575  (GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftRA x y [c]) yes no)
  1576  (GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftLLreg x y z) yes no)
  1577  (GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftRLreg x y z) yes no)
  1578  (GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftRAreg x y z) yes no)
  1579  
  1580  (MOVBUload [off] {sym} (SB) _) && symIsRO(sym) -> (MOVWconst [int64(read8(sym, off))])
  1581  (MOVHUload [off] {sym} (SB) _) && symIsRO(sym) -> (MOVWconst [int64(read16(sym, off, config.BigEndian))])
  1582  (MOVWload [off] {sym} (SB) _) && symIsRO(sym) -> (MOVWconst [int64(int32(read32(sym, off, config.BigEndian)))])