]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/X86/X86InstrExtension.td
MFV r316872: 7502 ztest should run zdb with -G (debug mode)
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / X86 / X86InstrExtension.td
1 //===-- X86InstrExtension.td - Sign and Zero Extensions ----*- tablegen -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the sign and zero extension operations.
11 //
12 //===----------------------------------------------------------------------===//
13
14 let hasSideEffects = 0 in {
15   let Defs = [AX], Uses = [AL] in // AX = signext(AL)
16   def CBW : I<0x98, RawFrm, (outs), (ins),
17               "{cbtw|cbw}", [], IIC_CBW>, OpSize16, Sched<[WriteALU]>;
18   let Defs = [EAX], Uses = [AX] in // EAX = signext(AX)
19   def CWDE : I<0x98, RawFrm, (outs), (ins),
20               "{cwtl|cwde}", [], IIC_CBW>, OpSize32, Sched<[WriteALU]>;
21
22   let Defs = [AX,DX], Uses = [AX] in // DX:AX = signext(AX)
23   def CWD : I<0x99, RawFrm, (outs), (ins),
24               "{cwtd|cwd}", [], IIC_CBW>, OpSize16, Sched<[WriteALU]>;
25   let Defs = [EAX,EDX], Uses = [EAX] in // EDX:EAX = signext(EAX)
26   def CDQ : I<0x99, RawFrm, (outs), (ins),
27               "{cltd|cdq}", [], IIC_CBW>, OpSize32, Sched<[WriteALU]>;
28
29
30   let Defs = [RAX], Uses = [EAX] in // RAX = signext(EAX)
31   def CDQE : RI<0x98, RawFrm, (outs), (ins),
32                "{cltq|cdqe}", [], IIC_CBW>, Sched<[WriteALU]>;
33
34   let Defs = [RAX,RDX], Uses = [RAX] in // RDX:RAX = signext(RAX)
35   def CQO  : RI<0x99, RawFrm, (outs), (ins),
36                 "{cqto|cqo}", [], IIC_CBW>, Sched<[WriteALU]>;
37 }
38
39 // Sign/Zero extenders
40 let hasSideEffects = 0 in {
41 def MOVSX16rr8 : I<0xBE, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
42                    "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_R8>,
43                    TB, OpSize16, Sched<[WriteALU]>;
44 let mayLoad = 1 in
45 def MOVSX16rm8 : I<0xBE, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
46                    "movs{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVSX_R16_M8>,
47                    TB, OpSize16, Sched<[WriteALULd]>;
48 } // hasSideEffects = 0
49 def MOVSX32rr8 : I<0xBE, MRMSrcReg, (outs GR32:$dst), (ins GR8:$src),
50                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
51                    [(set GR32:$dst, (sext GR8:$src))], IIC_MOVSX>, TB,
52                    OpSize32, Sched<[WriteALU]>;
53 def MOVSX32rm8 : I<0xBE, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
54                    "movs{bl|x}\t{$src, $dst|$dst, $src}",
55                    [(set GR32:$dst, (sextloadi32i8 addr:$src))], IIC_MOVSX>, TB,
56                    OpSize32, Sched<[WriteALULd]>;
57 def MOVSX32rr16: I<0xBF, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
58                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
59                    [(set GR32:$dst, (sext GR16:$src))], IIC_MOVSX>, TB,
60                    OpSize32, Sched<[WriteALU]>;
61 def MOVSX32rm16: I<0xBF, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
62                    "movs{wl|x}\t{$src, $dst|$dst, $src}",
63                    [(set GR32:$dst, (sextloadi32i16 addr:$src))], IIC_MOVSX>,
64                    OpSize32, TB, Sched<[WriteALULd]>;
65
66 let hasSideEffects = 0 in {
67 def MOVZX16rr8 : I<0xB6, MRMSrcReg, (outs GR16:$dst), (ins GR8:$src),
68                    "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_R8>,
69                    TB, OpSize16, Sched<[WriteALU]>;
70 let mayLoad = 1 in
71 def MOVZX16rm8 : I<0xB6, MRMSrcMem, (outs GR16:$dst), (ins i8mem:$src),
72                    "movz{bw|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX_R16_M8>,
73                    TB, OpSize16, Sched<[WriteALULd]>;
74 } // hasSideEffects = 0
75 def MOVZX32rr8 : I<0xB6, MRMSrcReg, (outs GR32:$dst), (ins GR8 :$src),
76                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
77                    [(set GR32:$dst, (zext GR8:$src))], IIC_MOVZX>, TB,
78                    OpSize32, Sched<[WriteALU]>;
79 def MOVZX32rm8 : I<0xB6, MRMSrcMem, (outs GR32:$dst), (ins i8mem :$src),
80                    "movz{bl|x}\t{$src, $dst|$dst, $src}",
81                    [(set GR32:$dst, (zextloadi32i8 addr:$src))], IIC_MOVZX>, TB,
82                    OpSize32, Sched<[WriteALULd]>;
83 def MOVZX32rr16: I<0xB7, MRMSrcReg, (outs GR32:$dst), (ins GR16:$src),
84                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
85                    [(set GR32:$dst, (zext GR16:$src))], IIC_MOVZX>, TB,
86                    OpSize32, Sched<[WriteALU]>;
87 def MOVZX32rm16: I<0xB7, MRMSrcMem, (outs GR32:$dst), (ins i16mem:$src),
88                    "movz{wl|x}\t{$src, $dst|$dst, $src}",
89                    [(set GR32:$dst, (zextloadi32i16 addr:$src))], IIC_MOVZX>,
90                    TB, OpSize32, Sched<[WriteALULd]>;
91
92 // These are the same as the regular MOVZX32rr8 and MOVZX32rm8
93 // except that they use GR32_NOREX for the output operand register class
94 // instead of GR32. This allows them to operate on h registers on x86-64.
95 let hasSideEffects = 0, isCodeGenOnly = 1 in {
96 def MOVZX32_NOREXrr8 : I<0xB6, MRMSrcReg,
97                          (outs GR32_NOREX:$dst), (ins GR8_NOREX:$src),
98                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
99                          [], IIC_MOVZX>, TB, OpSize32, Sched<[WriteALU]>;
100 let mayLoad = 1 in
101 def MOVZX32_NOREXrm8 : I<0xB6, MRMSrcMem,
102                          (outs GR32_NOREX:$dst), (ins i8mem_NOREX:$src),
103                          "movz{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
104                          [], IIC_MOVZX>, TB, OpSize32, Sched<[WriteALULd]>;
105
106 def MOVSX32_NOREXrr8 : I<0xBE, MRMSrcReg,
107                          (outs GR32_NOREX:$dst), (ins GR8_NOREX:$src),
108                          "movs{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
109                          [], IIC_MOVSX>, TB, OpSize32, Sched<[WriteALU]>;
110 let mayLoad = 1 in
111 def MOVSX32_NOREXrm8 : I<0xBE, MRMSrcMem,
112                          (outs GR32_NOREX:$dst), (ins i8mem_NOREX:$src),
113                          "movs{bl|x}\t{$src, $dst|$dst, $src}  # NOREX",
114                          [], IIC_MOVSX>, TB, OpSize32, Sched<[WriteALULd]>;
115 }
116
117 // MOVSX64rr8 always has a REX prefix and it has an 8-bit register
118 // operand, which makes it a rare instruction with an 8-bit register
119 // operand that can never access an h register. If support for h registers
120 // were generalized, this would require a special register class.
121 def MOVSX64rr8 : RI<0xBE, MRMSrcReg, (outs GR64:$dst), (ins GR8 :$src),
122                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
123                     [(set GR64:$dst, (sext GR8:$src))], IIC_MOVSX>, TB,
124                     Sched<[WriteALU]>;
125 def MOVSX64rm8 : RI<0xBE, MRMSrcMem, (outs GR64:$dst), (ins i8mem :$src),
126                     "movs{bq|x}\t{$src, $dst|$dst, $src}",
127                     [(set GR64:$dst, (sextloadi64i8 addr:$src))], IIC_MOVSX>,
128                     TB, Sched<[WriteALULd]>;
129 def MOVSX64rr16: RI<0xBF, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
130                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
131                     [(set GR64:$dst, (sext GR16:$src))], IIC_MOVSX>, TB,
132                     Sched<[WriteALU]>;
133 def MOVSX64rm16: RI<0xBF, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
134                     "movs{wq|x}\t{$src, $dst|$dst, $src}",
135                     [(set GR64:$dst, (sextloadi64i16 addr:$src))], IIC_MOVSX>,
136                     TB, Sched<[WriteALULd]>;
137 def MOVSX64rr32: RI<0x63, MRMSrcReg, (outs GR64:$dst), (ins GR32:$src),
138                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
139                     [(set GR64:$dst, (sext GR32:$src))], IIC_MOVSX>,
140                     Sched<[WriteALU]>, Requires<[In64BitMode]>;
141 def MOVSX64rm32: RI<0x63, MRMSrcMem, (outs GR64:$dst), (ins i32mem:$src),
142                     "movs{lq|xd}\t{$src, $dst|$dst, $src}",
143                     [(set GR64:$dst, (sextloadi64i32 addr:$src))], IIC_MOVSX>,
144                     Sched<[WriteALULd]>, Requires<[In64BitMode]>;
145
146 // movzbq and movzwq encodings for the disassembler
147 let hasSideEffects = 0 in {
148 def MOVZX64rr8 : RI<0xB6, MRMSrcReg, (outs GR64:$dst), (ins GR8:$src),
149                      "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
150                      TB, Sched<[WriteALU]>;
151 let mayLoad = 1 in
152 def MOVZX64rm8 : RI<0xB6, MRMSrcMem, (outs GR64:$dst), (ins i8mem:$src),
153                      "movz{bq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
154                      TB, Sched<[WriteALULd]>;
155 def MOVZX64rr16 : RI<0xB7, MRMSrcReg, (outs GR64:$dst), (ins GR16:$src),
156                      "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
157                      TB, Sched<[WriteALU]>;
158 let mayLoad = 1 in
159 def MOVZX64rm16 : RI<0xB7, MRMSrcMem, (outs GR64:$dst), (ins i16mem:$src),
160                      "movz{wq|x}\t{$src, $dst|$dst, $src}", [], IIC_MOVZX>,
161                      TB, Sched<[WriteALULd]>;
162 }
163
164 // 64-bit zero-extension patterns use SUBREG_TO_REG and an operation writing a
165 // 32-bit register.
166 def : Pat<(i64 (zext GR8:$src)),
167           (SUBREG_TO_REG (i64 0), (MOVZX32rr8 GR8:$src), sub_32bit)>;
168 def : Pat<(zextloadi64i8 addr:$src),
169           (SUBREG_TO_REG (i64 0), (MOVZX32rm8 addr:$src), sub_32bit)>;
170
171 def : Pat<(i64 (zext GR16:$src)),
172           (SUBREG_TO_REG (i64 0), (MOVZX32rr16 GR16:$src), sub_32bit)>;
173 def : Pat<(zextloadi64i16 addr:$src),
174           (SUBREG_TO_REG (i64 0), (MOVZX32rm16 addr:$src), sub_32bit)>;
175
176 // The preferred way to do 32-bit-to-64-bit zero extension on x86-64 is to use a
177 // SUBREG_TO_REG to utilize implicit zero-extension, however this isn't possible
178 // when the 32-bit value is defined by a truncate or is copied from something
179 // where the high bits aren't necessarily all zero. In such cases, we fall back
180 // to these explicit zext instructions.
181 def : Pat<(i64 (zext GR32:$src)),
182           (SUBREG_TO_REG (i64 0), (MOV32rr GR32:$src), sub_32bit)>;
183 def : Pat<(i64 (zextloadi64i32 addr:$src)),
184           (SUBREG_TO_REG (i64 0), (MOV32rm addr:$src), sub_32bit)>;