On 06/13/17 02:46 PM, Keith Randall wrote:
> I would encourage you not to rely on the ordering of application of
> rules. This can sometimes mean using additional rules to make sure that
> ordering doesn't matter.
>
> For your particular case, there's a simpler solution. Don't write
> optimization rules using the machine-independent rules. First lower the
> ops, then do optimizations on the lowered form. In your case, I would do:
>
> (Const64 [val]) -> (MOVDconst [val])
> (Rsh64x64 x y) -> (SRAmax x <y.Type> y [63])
>
> Then
>
> (SRAmax [max] x (MOVDconst [c])) && uint64(c) < uint64(max) ->
> (SRAconst x [c])
>
> It might take multiple rewrites to get the final result, but there's no
> ordering issue.
I was going by what ARM64 does:
(Rsh64x64 x (MOVDconst [c])) && uint64(c) < 64 -> (SRAconst x [c])
(Rsh64x64 x y) -> (SRA x (CSELULT <y.Type> y (Const64 <y.Type> [63])
(CMPconst [64] y)))
(Const64 [val]) -> (MOVDconst [val])
...and was puzzled as to why I got a very different result for the same
thing.
https://github.com/golang/go/blob/master/src/cmd/compile/internal/ssa/gen/ARM64.rules
So what you say makes sense, but is still mysterious to me.
-Shawn