]> Cypherpunks.ru repositories - gostls13.git/blob - src/cmd/compile/internal/ssa/_gen/PPC64latelower.rules
d5fe1276aa20473b822b30a7d48da82a5e052da4
[gostls13.git] / src / cmd / compile / internal / ssa / _gen / PPC64latelower.rules
1 // Copyright 2022 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 // This file contains rules used by the laterLower pass.
6
7 // Simplify ISEL x $0 z into ISELZ
8 (ISEL [a] x (MOVDconst [0]) z) => (ISELZ [a] x z)
9 // Simplify ISEL $0 y z into ISELZ by inverting comparison and reversing arguments.
10 (ISEL [a] (MOVDconst [0]) y z) => (ISELZ [a^0x4] y z)
11
12 // SETBC, SETBCR is supported on ISA 3.1(Power10) and newer, use ISELZ for
13 // older targets
14 (SETBC [2] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [2] (MOVDconst [1]) cmp)
15 (SETBCR [2] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [6] (MOVDconst [1]) cmp)
16 (SETBC [0] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [0] (MOVDconst [1]) cmp)
17 (SETBCR [0] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [4] (MOVDconst [1]) cmp)
18 (SETBC [1] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [1] (MOVDconst [1]) cmp)
19 (SETBCR [1] cmp) && buildcfg.GOPPC64 <= 9 => (ISELZ [5] (MOVDconst [1]) cmp)
20
21 // Avoid using ANDCCconst if the value for CR0 is not needed, since ANDCCconst
22 // always sets it.
23 (Select0 z:(ANDCCconst [m] x)) && z.Uses == 1 && isPPC64ValidShiftMask(m) => (RLDICL [encodePPC64RotateMask(0,m,64)] x)
24 // The upper bits of the smaller than register values is undefined. Take advantage of that.
25 (AND <t> x:(MOVDconst [m]) n) && t.Size() <= 2 => (Select0 (ANDCCconst [int64(int16(m))] n))
26
27 // Convert simple bit masks to an equivalent rldic[lr] if possible.
28 (AND x:(MOVDconst [m]) n) && isPPC64ValidShiftMask(m) => (RLDICL [encodePPC64RotateMask(0,m,64)] n)
29 (AND x:(MOVDconst [m]) n) && m != 0 && isPPC64ValidShiftMask(^m) => (RLDICR [encodePPC64RotateMask(0,m,64)] n)
30
31 // If the RLDICL does not rotate its value, a shifted value can be merged.
32 (RLDICL [em] x:(SRDconst [s] a)) && (em&0xFF0000) == 0 => (RLDICL [mergePPC64RLDICLandSRDconst(em, s)] a)
33
34 // Convert rotated 32 bit masks on 32 bit values into rlwinm. In general, this leaves the upper 32 bits in an undefined state.
35 (AND <t> x:(MOVDconst [m]) n) && t.Size() == 4 && isPPC64WordRotateMask(m) => (RLWINM [encodePPC64RotateMask(0,m,32)] n)
36
37 // When PCRel is supported, paddi can add a 34b signed constant in one instruction.
38 (ADD (MOVDconst [m]) x) && supportsPPC64PCRel() && (m<<30)>>30 == m => (ADDconst [m] x)