blob: ea3832f70c1814c9ae6d90b14265ce6001eac705 [file] [log] [blame]
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001//===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that X86 uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#include "X86.h"
Evan Cheng0cc39452006-01-16 21:21:29 +000016#include "X86InstrBuilder.h"
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000017#include "X86ISelLowering.h"
18#include "X86TargetMachine.h"
19#include "llvm/CallingConv.h"
Evan Cheng223547a2006-01-31 22:28:30 +000020#include "llvm/Constants.h"
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000021#include "llvm/Function.h"
Evan Cheng30b37b52006-03-13 23:18:16 +000022#include "llvm/ADT/VectorExtras.h"
23#include "llvm/Analysis/ScalarEvolutionExpressions.h"
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000024#include "llvm/CodeGen/MachineFrameInfo.h"
Evan Cheng4a460802006-01-11 00:33:36 +000025#include "llvm/CodeGen/MachineFunction.h"
26#include "llvm/CodeGen/MachineInstrBuilder.h"
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000027#include "llvm/CodeGen/SelectionDAG.h"
28#include "llvm/CodeGen/SSARegMap.h"
Evan Chengef6ffb12006-01-31 03:14:29 +000029#include "llvm/Support/MathExtras.h"
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000030#include "llvm/Target/TargetOptions.h"
31using namespace llvm;
32
33// FIXME: temporary.
34#include "llvm/Support/CommandLine.h"
35static cl::opt<bool> EnableFastCC("enable-x86-fastcc", cl::Hidden,
36 cl::desc("Enable fastcc on X86"));
37
38X86TargetLowering::X86TargetLowering(TargetMachine &TM)
39 : TargetLowering(TM) {
Evan Cheng559806f2006-01-27 08:10:46 +000040 Subtarget = &TM.getSubtarget<X86Subtarget>();
41 X86ScalarSSE = Subtarget->hasSSE2();
42
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000043 // Set up the TargetLowering object.
44
45 // X86 is weird, it always uses i8 for shift amounts and setcc results.
46 setShiftAmountType(MVT::i8);
47 setSetCCResultType(MVT::i8);
48 setSetCCResultContents(ZeroOrOneSetCCResult);
Evan Cheng0b2afbd2006-01-25 09:15:17 +000049 setSchedulingPreference(SchedulingForRegPressure);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000050 setShiftAmountFlavor(Mask); // shl X, 32 == shl X, 0
Chris Lattner9edba762006-01-13 18:00:54 +000051 setStackPointerRegisterToSaveRestore(X86::ESP);
Evan Cheng714554d2006-03-16 21:47:42 +000052
Evan Chenga88973f2006-03-22 19:22:18 +000053 if (!Subtarget->isTargetDarwin())
Evan Chengdf57fa02006-03-17 20:31:41 +000054 // Darwin should use _setjmp/_longjmp instead of setjmp/longjmp.
55 setUseUnderscoreSetJmpLongJmp(true);
56
Evan Cheng714554d2006-03-16 21:47:42 +000057 // Add legal addressing mode scale values.
58 addLegalAddressScale(8);
59 addLegalAddressScale(4);
60 addLegalAddressScale(2);
61 // Enter the ones which require both scale + index last. These are more
62 // expensive.
63 addLegalAddressScale(9);
64 addLegalAddressScale(5);
65 addLegalAddressScale(3);
Chris Lattnera54aa942006-01-29 06:26:08 +000066
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000067 // Set up the register classes.
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000068 addRegisterClass(MVT::i8, X86::R8RegisterClass);
69 addRegisterClass(MVT::i16, X86::R16RegisterClass);
70 addRegisterClass(MVT::i32, X86::R32RegisterClass);
71
72 // Promote all UINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have this
73 // operation.
74 setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote);
75 setOperationAction(ISD::UINT_TO_FP , MVT::i8 , Promote);
76 setOperationAction(ISD::UINT_TO_FP , MVT::i16 , Promote);
Evan Cheng6892f282006-01-17 02:32:49 +000077
78 if (X86ScalarSSE)
79 // No SSE i64 SINT_TO_FP, so expand i32 UINT_TO_FP instead.
80 setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Expand);
81 else
82 setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000083
84 // Promote i1/i8 SINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have
85 // this operation.
86 setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote);
87 setOperationAction(ISD::SINT_TO_FP , MVT::i8 , Promote);
Nate Begeman4c5dcf52006-02-17 00:03:04 +000088 // SSE has no i16 to fp conversion, only i32
Evan Cheng02568ff2006-01-30 22:13:22 +000089 if (X86ScalarSSE)
Evan Cheng02568ff2006-01-30 22:13:22 +000090 setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Promote);
Evan Cheng5298bcc2006-02-17 07:01:52 +000091 else {
92 setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Custom);
93 setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Custom);
94 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000095
Evan Cheng6dab0532006-01-30 08:02:57 +000096 // We can handle SINT_TO_FP and FP_TO_SINT from/to i64 even though i64
97 // isn't legal.
98 setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom);
99 setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom);
100
Evan Cheng02568ff2006-01-30 22:13:22 +0000101 // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have
102 // this operation.
103 setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote);
104 setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote);
105
106 if (X86ScalarSSE) {
107 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote);
108 } else {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000109 setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom);
Evan Cheng02568ff2006-01-30 22:13:22 +0000110 setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000111 }
112
113 // Handle FP_TO_UINT by promoting the destination to a larger signed
114 // conversion.
115 setOperationAction(ISD::FP_TO_UINT , MVT::i1 , Promote);
116 setOperationAction(ISD::FP_TO_UINT , MVT::i8 , Promote);
117 setOperationAction(ISD::FP_TO_UINT , MVT::i16 , Promote);
118
Evan Cheng45af8fd2006-02-18 07:26:17 +0000119 if (X86ScalarSSE && !Subtarget->hasSSE3())
Evan Cheng02568ff2006-01-30 22:13:22 +0000120 // Expand FP_TO_UINT into a select.
121 // FIXME: We would like to use a Custom expander here eventually to do
122 // the optimal thing for SSE vs. the default expansion in the legalizer.
123 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand);
124 else
Evan Cheng45af8fd2006-02-18 07:26:17 +0000125 // With SSE3 we can use fisttpll to convert to a signed i64.
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000126 setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote);
127
Evan Cheng02568ff2006-01-30 22:13:22 +0000128 setOperationAction(ISD::BIT_CONVERT , MVT::f32 , Expand);
129 setOperationAction(ISD::BIT_CONVERT , MVT::i32 , Expand);
Chris Lattner21f66852005-12-23 05:15:23 +0000130
Evan Cheng5298bcc2006-02-17 07:01:52 +0000131 setOperationAction(ISD::BRCOND , MVT::Other, Custom);
Nate Begeman750ac1b2006-02-01 07:19:44 +0000132 setOperationAction(ISD::BR_CC , MVT::Other, Expand);
133 setOperationAction(ISD::SELECT_CC , MVT::Other, Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000134 setOperationAction(ISD::MEMMOVE , MVT::Other, Expand);
135 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16 , Expand);
Chris Lattnere80242a2005-12-07 17:59:14 +0000136 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000137 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand);
138 setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand);
139 setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand);
140 setOperationAction(ISD::FREM , MVT::f64 , Expand);
141 setOperationAction(ISD::CTPOP , MVT::i8 , Expand);
142 setOperationAction(ISD::CTTZ , MVT::i8 , Expand);
143 setOperationAction(ISD::CTLZ , MVT::i8 , Expand);
144 setOperationAction(ISD::CTPOP , MVT::i16 , Expand);
145 setOperationAction(ISD::CTTZ , MVT::i16 , Expand);
146 setOperationAction(ISD::CTLZ , MVT::i16 , Expand);
147 setOperationAction(ISD::CTPOP , MVT::i32 , Expand);
148 setOperationAction(ISD::CTTZ , MVT::i32 , Expand);
149 setOperationAction(ISD::CTLZ , MVT::i32 , Expand);
Andrew Lenharthb873ff32005-11-20 21:41:10 +0000150 setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom);
Nate Begemand88fc032006-01-14 03:14:10 +0000151 setOperationAction(ISD::BSWAP , MVT::i16 , Expand);
Nate Begeman35ef9132006-01-11 21:21:00 +0000152
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000153 // These should be promoted to a larger select which is supported.
154 setOperationAction(ISD::SELECT , MVT::i1 , Promote);
155 setOperationAction(ISD::SELECT , MVT::i8 , Promote);
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000156
157 // X86 wants to expand cmov itself.
Evan Cheng5298bcc2006-02-17 07:01:52 +0000158 setOperationAction(ISD::SELECT , MVT::i16 , Custom);
159 setOperationAction(ISD::SELECT , MVT::i32 , Custom);
160 setOperationAction(ISD::SELECT , MVT::f32 , Custom);
161 setOperationAction(ISD::SELECT , MVT::f64 , Custom);
162 setOperationAction(ISD::SETCC , MVT::i8 , Custom);
163 setOperationAction(ISD::SETCC , MVT::i16 , Custom);
164 setOperationAction(ISD::SETCC , MVT::i32 , Custom);
165 setOperationAction(ISD::SETCC , MVT::f32 , Custom);
166 setOperationAction(ISD::SETCC , MVT::f64 , Custom);
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000167 // X86 ret instruction may pop stack.
Evan Cheng5298bcc2006-02-17 07:01:52 +0000168 setOperationAction(ISD::RET , MVT::Other, Custom);
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000169 // Darwin ABI issue.
Evan Cheng7ccced62006-02-18 00:15:05 +0000170 setOperationAction(ISD::ConstantPool , MVT::i32 , Custom);
Evan Cheng5298bcc2006-02-17 07:01:52 +0000171 setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom);
Evan Cheng020d2e82006-02-23 20:41:18 +0000172 setOperationAction(ISD::ExternalSymbol , MVT::i32 , Custom);
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000173 // 64-bit addm sub, shl, sra, srl (iff 32-bit x86)
Evan Cheng5298bcc2006-02-17 07:01:52 +0000174 setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom);
175 setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom);
176 setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom);
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000177 // X86 wants to expand memset / memcpy itself.
Evan Cheng5298bcc2006-02-17 07:01:52 +0000178 setOperationAction(ISD::MEMSET , MVT::Other, Custom);
179 setOperationAction(ISD::MEMCPY , MVT::Other, Custom);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000180
Chris Lattnerf73bae12005-11-29 06:16:21 +0000181 // We don't have line number support yet.
182 setOperationAction(ISD::LOCATION, MVT::Other, Expand);
Jim Laskeye0bce712006-01-05 01:47:43 +0000183 setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand);
Evan Cheng3c992d22006-03-07 02:02:57 +0000184 // FIXME - use subtarget debug flags
Evan Chenga88973f2006-03-22 19:22:18 +0000185 if (!Subtarget->isTargetDarwin())
Evan Cheng3c992d22006-03-07 02:02:57 +0000186 setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand);
Chris Lattnerf73bae12005-11-29 06:16:21 +0000187
Nate Begemanacc398c2006-01-25 18:21:52 +0000188 // VASTART needs to be custom lowered to use the VarArgsFrameIndex
189 setOperationAction(ISD::VASTART , MVT::Other, Custom);
190
191 // Use the default implementation.
192 setOperationAction(ISD::VAARG , MVT::Other, Expand);
193 setOperationAction(ISD::VACOPY , MVT::Other, Expand);
194 setOperationAction(ISD::VAEND , MVT::Other, Expand);
Chris Lattnere1125522006-01-15 09:00:21 +0000195 setOperationAction(ISD::STACKSAVE, MVT::Other, Expand);
196 setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand);
197 setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand);
Chris Lattnerb99329e2006-01-13 02:42:53 +0000198
Chris Lattner9601a862006-03-05 05:08:37 +0000199 setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand);
200 setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand);
201
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000202 if (X86ScalarSSE) {
203 // Set up the FP register classes.
Evan Cheng5ee4ccc2006-01-12 08:27:59 +0000204 addRegisterClass(MVT::f32, X86::FR32RegisterClass);
205 addRegisterClass(MVT::f64, X86::FR64RegisterClass);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000206
207 // SSE has no load+extend ops
208 setOperationAction(ISD::EXTLOAD, MVT::f32, Expand);
209 setOperationAction(ISD::ZEXTLOAD, MVT::f32, Expand);
210
Evan Cheng223547a2006-01-31 22:28:30 +0000211 // Use ANDPD to simulate FABS.
212 setOperationAction(ISD::FABS , MVT::f64, Custom);
213 setOperationAction(ISD::FABS , MVT::f32, Custom);
214
215 // Use XORP to simulate FNEG.
216 setOperationAction(ISD::FNEG , MVT::f64, Custom);
217 setOperationAction(ISD::FNEG , MVT::f32, Custom);
218
Evan Chengd25e9e82006-02-02 00:28:23 +0000219 // We don't support sin/cos/fmod
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000220 setOperationAction(ISD::FSIN , MVT::f64, Expand);
221 setOperationAction(ISD::FCOS , MVT::f64, Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000222 setOperationAction(ISD::FREM , MVT::f64, Expand);
223 setOperationAction(ISD::FSIN , MVT::f32, Expand);
224 setOperationAction(ISD::FCOS , MVT::f32, Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000225 setOperationAction(ISD::FREM , MVT::f32, Expand);
226
Chris Lattnera54aa942006-01-29 06:26:08 +0000227 // Expand FP immediates into loads from the stack, except for the special
228 // cases we handle.
229 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
230 setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000231 addLegalFPImmediate(+0.0); // xorps / xorpd
232 } else {
233 // Set up the FP register classes.
234 addRegisterClass(MVT::f64, X86::RFPRegisterClass);
Chris Lattner44d9b9b2006-01-29 06:44:22 +0000235
236 setOperationAction(ISD::UNDEF, MVT::f64, Expand);
237
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000238 if (!UnsafeFPMath) {
239 setOperationAction(ISD::FSIN , MVT::f64 , Expand);
240 setOperationAction(ISD::FCOS , MVT::f64 , Expand);
241 }
242
Chris Lattnera54aa942006-01-29 06:26:08 +0000243 setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000244 addLegalFPImmediate(+0.0); // FLD0
245 addLegalFPImmediate(+1.0); // FLD1
246 addLegalFPImmediate(-0.0); // FLD0/FCHS
247 addLegalFPImmediate(-1.0); // FLD1/FCHS
248 }
Evan Cheng470a6ad2006-02-22 02:26:30 +0000249
Evan Chengd30bf012006-03-01 01:11:20 +0000250 // First set operation action for all vector types to expand. Then we
251 // will selectively turn on ones that can be effectively codegen'd.
252 for (unsigned VT = (unsigned)MVT::Vector + 1;
253 VT != (unsigned)MVT::LAST_VALUETYPE; VT++) {
254 setOperationAction(ISD::ADD , (MVT::ValueType)VT, Expand);
255 setOperationAction(ISD::SUB , (MVT::ValueType)VT, Expand);
256 setOperationAction(ISD::MUL , (MVT::ValueType)VT, Expand);
257 setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Expand);
Chris Lattner39afef32006-03-20 06:18:01 +0000258 setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Expand);
Chris Lattner9b3bd462006-03-21 20:51:05 +0000259 setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Expand);
Evan Chengd30bf012006-03-01 01:11:20 +0000260 }
261
Evan Chenga88973f2006-03-22 19:22:18 +0000262 if (Subtarget->hasMMX()) {
Evan Cheng470a6ad2006-02-22 02:26:30 +0000263 addRegisterClass(MVT::v8i8, X86::VR64RegisterClass);
264 addRegisterClass(MVT::v4i16, X86::VR64RegisterClass);
265 addRegisterClass(MVT::v2i32, X86::VR64RegisterClass);
266
Evan Chengd30bf012006-03-01 01:11:20 +0000267 // FIXME: add MMX packed arithmetics
Evan Cheng48090aa2006-03-21 23:01:21 +0000268 setOperationAction(ISD::BUILD_VECTOR, MVT::v8i8, Expand);
269 setOperationAction(ISD::BUILD_VECTOR, MVT::v4i16, Expand);
270 setOperationAction(ISD::BUILD_VECTOR, MVT::v2i32, Expand);
Evan Cheng470a6ad2006-02-22 02:26:30 +0000271 }
272
Evan Chenga88973f2006-03-22 19:22:18 +0000273 if (Subtarget->hasSSE1()) {
Evan Cheng470a6ad2006-02-22 02:26:30 +0000274 addRegisterClass(MVT::v4f32, X86::VR128RegisterClass);
275
Evan Cheng48090aa2006-03-21 23:01:21 +0000276 setOperationAction(ISD::ADD, MVT::v4f32, Legal);
277 setOperationAction(ISD::SUB, MVT::v4f32, Legal);
278 setOperationAction(ISD::MUL, MVT::v4f32, Legal);
279 setOperationAction(ISD::LOAD, MVT::v4f32, Legal);
280 setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Expand);
Evan Chengb9df0ca2006-03-22 02:53:00 +0000281 setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4f32, Custom);
Evan Cheng470a6ad2006-02-22 02:26:30 +0000282 }
283
Evan Chenga88973f2006-03-22 19:22:18 +0000284 if (Subtarget->hasSSE2()) {
Evan Cheng470a6ad2006-02-22 02:26:30 +0000285 addRegisterClass(MVT::v2f64, X86::VR128RegisterClass);
286 addRegisterClass(MVT::v16i8, X86::VR128RegisterClass);
287 addRegisterClass(MVT::v8i16, X86::VR128RegisterClass);
288 addRegisterClass(MVT::v4i32, X86::VR128RegisterClass);
289 addRegisterClass(MVT::v2i64, X86::VR128RegisterClass);
290
291
Evan Cheng48090aa2006-03-21 23:01:21 +0000292 setOperationAction(ISD::ADD, MVT::v2f64, Legal);
293 setOperationAction(ISD::SUB, MVT::v2f64, Legal);
294 setOperationAction(ISD::MUL, MVT::v2f64, Legal);
295 setOperationAction(ISD::LOAD, MVT::v2f64, Legal);
296 setOperationAction(ISD::BUILD_VECTOR, MVT::v2f64, Expand);
297 setOperationAction(ISD::BUILD_VECTOR, MVT::v16i8, Expand);
298 setOperationAction(ISD::BUILD_VECTOR, MVT::v8i16, Expand);
299 setOperationAction(ISD::BUILD_VECTOR, MVT::v4i32, Expand);
300 setOperationAction(ISD::BUILD_VECTOR, MVT::v2i64, Expand);
301 setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v16i8, Custom);
302 setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v8i16, Custom);
Evan Chengb9df0ca2006-03-22 02:53:00 +0000303 setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2f64, Custom);
Evan Cheng470a6ad2006-02-22 02:26:30 +0000304 }
305
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000306 computeRegisterProperties();
307
Evan Cheng87ed7162006-02-14 08:25:08 +0000308 // FIXME: These should be based on subtarget info. Plus, the values should
309 // be smaller when we are in optimizing for size mode.
Evan Chenga03a5dc2006-02-14 08:38:30 +0000310 maxStoresPerMemset = 16; // For %llvm.memset -> sequence of stores
311 maxStoresPerMemcpy = 16; // For %llvm.memcpy -> sequence of stores
312 maxStoresPerMemmove = 16; // For %llvm.memmove -> sequence of stores
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000313 allowUnalignedMemoryAccesses = true; // x86 supports it!
314}
315
316std::vector<SDOperand>
317X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) {
318 if (F.getCallingConv() == CallingConv::Fast && EnableFastCC)
319 return LowerFastCCArguments(F, DAG);
320 return LowerCCCArguments(F, DAG);
321}
322
323std::pair<SDOperand, SDOperand>
324X86TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy,
325 bool isVarArg, unsigned CallingConv,
326 bool isTailCall,
327 SDOperand Callee, ArgListTy &Args,
328 SelectionDAG &DAG) {
329 assert((!isVarArg || CallingConv == CallingConv::C) &&
330 "Only C takes varargs!");
Evan Chengd9558e02006-01-06 00:43:03 +0000331
332 // If the callee is a GlobalAddress node (quite common, every direct call is)
333 // turn it into a TargetGlobalAddress node so that legalize doesn't hack it.
334 if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
335 Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy());
Evan Cheng8700e142006-01-11 06:09:51 +0000336 else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee))
337 Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy());
Evan Chengd9558e02006-01-06 00:43:03 +0000338
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000339 if (CallingConv == CallingConv::Fast && EnableFastCC)
340 return LowerFastCCCallTo(Chain, RetTy, isTailCall, Callee, Args, DAG);
341 return LowerCCCCallTo(Chain, RetTy, isVarArg, isTailCall, Callee, Args, DAG);
342}
343
344//===----------------------------------------------------------------------===//
345// C Calling Convention implementation
346//===----------------------------------------------------------------------===//
347
348std::vector<SDOperand>
349X86TargetLowering::LowerCCCArguments(Function &F, SelectionDAG &DAG) {
350 std::vector<SDOperand> ArgValues;
351
352 MachineFunction &MF = DAG.getMachineFunction();
353 MachineFrameInfo *MFI = MF.getFrameInfo();
354
355 // Add DAG nodes to load the arguments... On entry to a function on the X86,
356 // the stack frame looks like this:
357 //
358 // [ESP] -- return address
359 // [ESP + 4] -- first argument (leftmost lexically)
360 // [ESP + 8] -- second argument, if first argument is four bytes in size
361 // ...
362 //
363 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
364 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
365 MVT::ValueType ObjectVT = getValueType(I->getType());
366 unsigned ArgIncrement = 4;
367 unsigned ObjSize;
368 switch (ObjectVT) {
369 default: assert(0 && "Unhandled argument type!");
370 case MVT::i1:
371 case MVT::i8: ObjSize = 1; break;
372 case MVT::i16: ObjSize = 2; break;
373 case MVT::i32: ObjSize = 4; break;
374 case MVT::i64: ObjSize = ArgIncrement = 8; break;
375 case MVT::f32: ObjSize = 4; break;
376 case MVT::f64: ObjSize = ArgIncrement = 8; break;
377 }
378 // Create the frame index object for this incoming parameter...
379 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
380
381 // Create the SelectionDAG nodes corresponding to a load from this parameter
382 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
383
384 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
385 // dead loads.
386 SDOperand ArgValue;
387 if (!I->use_empty())
388 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
389 DAG.getSrcValue(NULL));
390 else {
391 if (MVT::isInteger(ObjectVT))
392 ArgValue = DAG.getConstant(0, ObjectVT);
393 else
394 ArgValue = DAG.getConstantFP(0, ObjectVT);
395 }
396 ArgValues.push_back(ArgValue);
397
398 ArgOffset += ArgIncrement; // Move on to the next argument...
399 }
400
401 // If the function takes variable number of arguments, make a frame index for
402 // the start of the first vararg value... for expansion of llvm.va_start.
403 if (F.isVarArg())
404 VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset);
405 ReturnAddrIndex = 0; // No return address slot generated yet.
406 BytesToPopOnReturn = 0; // Callee pops nothing.
407 BytesCallerReserves = ArgOffset;
408
409 // Finally, inform the code generator which regs we return values in.
410 switch (getValueType(F.getReturnType())) {
411 default: assert(0 && "Unknown type!");
412 case MVT::isVoid: break;
413 case MVT::i1:
414 case MVT::i8:
415 case MVT::i16:
416 case MVT::i32:
417 MF.addLiveOut(X86::EAX);
418 break;
419 case MVT::i64:
420 MF.addLiveOut(X86::EAX);
421 MF.addLiveOut(X86::EDX);
422 break;
423 case MVT::f32:
424 case MVT::f64:
425 MF.addLiveOut(X86::ST0);
426 break;
427 }
428 return ArgValues;
429}
430
431std::pair<SDOperand, SDOperand>
432X86TargetLowering::LowerCCCCallTo(SDOperand Chain, const Type *RetTy,
433 bool isVarArg, bool isTailCall,
434 SDOperand Callee, ArgListTy &Args,
435 SelectionDAG &DAG) {
436 // Count how many bytes are to be pushed on the stack.
437 unsigned NumBytes = 0;
438
439 if (Args.empty()) {
440 // Save zero bytes.
Chris Lattner94dd2922006-02-13 09:00:43 +0000441 Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(0, getPointerTy()));
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000442 } else {
443 for (unsigned i = 0, e = Args.size(); i != e; ++i)
444 switch (getValueType(Args[i].second)) {
445 default: assert(0 && "Unknown value type!");
446 case MVT::i1:
447 case MVT::i8:
448 case MVT::i16:
449 case MVT::i32:
450 case MVT::f32:
451 NumBytes += 4;
452 break;
453 case MVT::i64:
454 case MVT::f64:
455 NumBytes += 8;
456 break;
457 }
458
Chris Lattner94dd2922006-02-13 09:00:43 +0000459 Chain = DAG.getCALLSEQ_START(Chain,
460 DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000461
462 // Arguments go on the stack in reverse order, as specified by the ABI.
463 unsigned ArgOffset = 0;
Evan Cheng8700e142006-01-11 06:09:51 +0000464 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000465 std::vector<SDOperand> Stores;
466
467 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
468 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
469 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
470
471 switch (getValueType(Args[i].second)) {
472 default: assert(0 && "Unexpected ValueType for argument!");
473 case MVT::i1:
474 case MVT::i8:
475 case MVT::i16:
476 // Promote the integer to 32 bits. If the input type is signed use a
477 // sign extend, otherwise use a zero extend.
478 if (Args[i].second->isSigned())
479 Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first);
480 else
481 Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first);
482
483 // FALL THROUGH
484 case MVT::i32:
485 case MVT::f32:
486 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
487 Args[i].first, PtrOff,
488 DAG.getSrcValue(NULL)));
489 ArgOffset += 4;
490 break;
491 case MVT::i64:
492 case MVT::f64:
493 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
494 Args[i].first, PtrOff,
495 DAG.getSrcValue(NULL)));
496 ArgOffset += 8;
497 break;
498 }
499 }
500 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
501 }
502
503 std::vector<MVT::ValueType> RetVals;
504 MVT::ValueType RetTyVT = getValueType(RetTy);
505 RetVals.push_back(MVT::Other);
506
507 // The result values produced have to be legal. Promote the result.
508 switch (RetTyVT) {
509 case MVT::isVoid: break;
510 default:
511 RetVals.push_back(RetTyVT);
512 break;
513 case MVT::i1:
514 case MVT::i8:
515 case MVT::i16:
516 RetVals.push_back(MVT::i32);
517 break;
518 case MVT::f32:
519 if (X86ScalarSSE)
520 RetVals.push_back(MVT::f32);
521 else
522 RetVals.push_back(MVT::f64);
523 break;
524 case MVT::i64:
525 RetVals.push_back(MVT::i32);
526 RetVals.push_back(MVT::i32);
527 break;
528 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000529
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000530 std::vector<MVT::ValueType> NodeTys;
531 NodeTys.push_back(MVT::Other); // Returns a chain
532 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
533 std::vector<SDOperand> Ops;
534 Ops.push_back(Chain);
535 Ops.push_back(Callee);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000536
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000537 // FIXME: Do not generate X86ISD::TAILCALL for now.
538 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
539 SDOperand InFlag = Chain.getValue(1);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000540
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000541 NodeTys.clear();
542 NodeTys.push_back(MVT::Other); // Returns a chain
543 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
544 Ops.clear();
545 Ops.push_back(Chain);
546 Ops.push_back(DAG.getConstant(NumBytes, getPointerTy()));
547 Ops.push_back(DAG.getConstant(0, getPointerTy()));
548 Ops.push_back(InFlag);
549 Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops);
550 InFlag = Chain.getValue(1);
551
552 SDOperand RetVal;
553 if (RetTyVT != MVT::isVoid) {
Evan Chengd90eb7f2006-01-05 00:27:02 +0000554 switch (RetTyVT) {
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000555 default: assert(0 && "Unknown value type to return!");
Evan Chengd90eb7f2006-01-05 00:27:02 +0000556 case MVT::i1:
557 case MVT::i8:
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000558 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
559 Chain = RetVal.getValue(1);
560 if (RetTyVT == MVT::i1)
561 RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal);
562 break;
Evan Chengd90eb7f2006-01-05 00:27:02 +0000563 case MVT::i16:
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000564 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
565 Chain = RetVal.getValue(1);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000566 break;
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000567 case MVT::i32:
568 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
569 Chain = RetVal.getValue(1);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000570 break;
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000571 case MVT::i64: {
572 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
573 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
574 Lo.getValue(2));
575 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
576 Chain = Hi.getValue(1);
Evan Chengd90eb7f2006-01-05 00:27:02 +0000577 break;
578 }
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000579 case MVT::f32:
580 case MVT::f64: {
581 std::vector<MVT::ValueType> Tys;
582 Tys.push_back(MVT::f64);
583 Tys.push_back(MVT::Other);
584 Tys.push_back(MVT::Flag);
585 std::vector<SDOperand> Ops;
586 Ops.push_back(Chain);
587 Ops.push_back(InFlag);
588 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
589 Chain = RetVal.getValue(1);
590 InFlag = RetVal.getValue(2);
591 if (X86ScalarSSE) {
592 // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This
593 // shouldn't be necessary except that RFP cannot be live across
594 // multiple blocks. When stackifier is fixed, they can be uncoupled.
595 MachineFunction &MF = DAG.getMachineFunction();
596 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
597 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
598 Tys.clear();
599 Tys.push_back(MVT::Other);
600 Ops.clear();
601 Ops.push_back(Chain);
602 Ops.push_back(RetVal);
603 Ops.push_back(StackSlot);
604 Ops.push_back(DAG.getValueType(RetTyVT));
605 Ops.push_back(InFlag);
606 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
607 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
608 DAG.getSrcValue(NULL));
609 Chain = RetVal.getValue(1);
610 }
Evan Chengd90eb7f2006-01-05 00:27:02 +0000611
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000612 if (RetTyVT == MVT::f32 && !X86ScalarSSE)
613 // FIXME: we would really like to remember that this FP_ROUND
614 // operation is okay to eliminate if we allow excess FP precision.
615 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
616 break;
617 }
618 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000619 }
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000620
621 return std::make_pair(RetVal, Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000622}
623
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000624//===----------------------------------------------------------------------===//
625// Fast Calling Convention implementation
626//===----------------------------------------------------------------------===//
627//
628// The X86 'fast' calling convention passes up to two integer arguments in
629// registers (an appropriate portion of EAX/EDX), passes arguments in C order,
630// and requires that the callee pop its arguments off the stack (allowing proper
631// tail calls), and has the same return value conventions as C calling convs.
632//
633// This calling convention always arranges for the callee pop value to be 8n+4
634// bytes, which is needed for tail recursion elimination and stack alignment
635// reasons.
636//
637// Note that this can be enhanced in the future to pass fp vals in registers
638// (when we have a global fp allocator) and do other tricks.
639//
640
641/// AddLiveIn - This helper function adds the specified physical register to the
642/// MachineFunction as a live in value. It also creates a corresponding virtual
643/// register for it.
644static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg,
645 TargetRegisterClass *RC) {
646 assert(RC->contains(PReg) && "Not the correct regclass!");
647 unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC);
648 MF.addLiveIn(PReg, VReg);
649 return VReg;
650}
651
Chris Lattner89fad2c2006-03-17 17:27:47 +0000652// FASTCC_NUM_INT_ARGS_INREGS - This is the max number of integer arguments
653// to pass in registers. 0 is none, 1 is is "use EAX", 2 is "use EAX and
654// EDX". Anything more is illegal.
655//
656// FIXME: The linscan register allocator currently has problem with
657// coallescing. At the time of this writing, whenever it decides to coallesce
658// a physreg with a virtreg, this increases the size of the physreg's live
659// range, and the live range cannot ever be reduced. This causes problems if
660// too many physregs are coalleced with virtregs, which can cause the register
661// allocator to wedge itself.
662//
663// This code triggers this problem more often if we pass args in registers,
664// so disable it until this is fixed.
665//
666// NOTE: this isn't marked const, so that GCC doesn't emit annoying warnings
667// about code being dead.
668//
669static unsigned FASTCC_NUM_INT_ARGS_INREGS = 0;
Chris Lattner1c636e92006-03-17 05:10:20 +0000670
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000671
672std::vector<SDOperand>
673X86TargetLowering::LowerFastCCArguments(Function &F, SelectionDAG &DAG) {
674 std::vector<SDOperand> ArgValues;
675
676 MachineFunction &MF = DAG.getMachineFunction();
677 MachineFrameInfo *MFI = MF.getFrameInfo();
678
679 // Add DAG nodes to load the arguments... On entry to a function the stack
680 // frame looks like this:
681 //
682 // [ESP] -- return address
683 // [ESP + 4] -- first nonreg argument (leftmost lexically)
684 // [ESP + 8] -- second nonreg argument, if first argument is 4 bytes in size
685 // ...
686 unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot
687
688 // Keep track of the number of integer regs passed so far. This can be either
689 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
690 // used).
691 unsigned NumIntRegs = 0;
Chris Lattner1c636e92006-03-17 05:10:20 +0000692
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000693 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) {
694 MVT::ValueType ObjectVT = getValueType(I->getType());
695 unsigned ArgIncrement = 4;
696 unsigned ObjSize = 0;
697 SDOperand ArgValue;
698
699 switch (ObjectVT) {
700 default: assert(0 && "Unhandled argument type!");
701 case MVT::i1:
702 case MVT::i8:
Chris Lattner1c636e92006-03-17 05:10:20 +0000703 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000704 if (!I->use_empty()) {
705 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DL : X86::AL,
706 X86::R8RegisterClass);
707 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i8);
708 DAG.setRoot(ArgValue.getValue(1));
Chris Lattnerf31d1932005-12-27 03:02:18 +0000709 if (ObjectVT == MVT::i1)
710 // FIXME: Should insert a assertzext here.
711 ArgValue = DAG.getNode(ISD::TRUNCATE, MVT::i1, ArgValue);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000712 }
713 ++NumIntRegs;
714 break;
715 }
716
717 ObjSize = 1;
718 break;
719 case MVT::i16:
Chris Lattner1c636e92006-03-17 05:10:20 +0000720 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000721 if (!I->use_empty()) {
722 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DX : X86::AX,
723 X86::R16RegisterClass);
724 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i16);
725 DAG.setRoot(ArgValue.getValue(1));
726 }
727 ++NumIntRegs;
728 break;
729 }
730 ObjSize = 2;
731 break;
732 case MVT::i32:
Chris Lattner1c636e92006-03-17 05:10:20 +0000733 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000734 if (!I->use_empty()) {
Chris Lattner1c636e92006-03-17 05:10:20 +0000735 unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::EDX : X86::EAX,
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000736 X86::R32RegisterClass);
737 ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32);
738 DAG.setRoot(ArgValue.getValue(1));
739 }
740 ++NumIntRegs;
741 break;
742 }
743 ObjSize = 4;
744 break;
745 case MVT::i64:
Chris Lattner1c636e92006-03-17 05:10:20 +0000746 if (NumIntRegs+2 <= FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000747 if (!I->use_empty()) {
748 unsigned BotReg = AddLiveIn(MF, X86::EAX, X86::R32RegisterClass);
749 unsigned TopReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
750
751 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
752 SDOperand Hi = DAG.getCopyFromReg(Low.getValue(1), TopReg, MVT::i32);
753 DAG.setRoot(Hi.getValue(1));
754
755 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
756 }
Chris Lattner1c636e92006-03-17 05:10:20 +0000757 NumIntRegs += 2;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000758 break;
Chris Lattner1c636e92006-03-17 05:10:20 +0000759 } else if (NumIntRegs+1 <= FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000760 if (!I->use_empty()) {
761 unsigned BotReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass);
762 SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32);
763 DAG.setRoot(Low.getValue(1));
764
765 // Load the high part from memory.
766 // Create the frame index object for this incoming parameter...
767 int FI = MFI->CreateFixedObject(4, ArgOffset);
768 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
769 SDOperand Hi = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN,
770 DAG.getSrcValue(NULL));
771 ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi);
772 }
773 ArgOffset += 4;
Chris Lattner1c636e92006-03-17 05:10:20 +0000774 NumIntRegs = FASTCC_NUM_INT_ARGS_INREGS;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000775 break;
776 }
777 ObjSize = ArgIncrement = 8;
778 break;
779 case MVT::f32: ObjSize = 4; break;
780 case MVT::f64: ObjSize = ArgIncrement = 8; break;
781 }
782
783 // Don't codegen dead arguments. FIXME: remove this check when we can nuke
784 // dead loads.
785 if (ObjSize && !I->use_empty()) {
786 // Create the frame index object for this incoming parameter...
787 int FI = MFI->CreateFixedObject(ObjSize, ArgOffset);
788
789 // Create the SelectionDAG nodes corresponding to a load from this
790 // parameter.
791 SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32);
792
793 ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN,
794 DAG.getSrcValue(NULL));
795 } else if (ArgValue.Val == 0) {
796 if (MVT::isInteger(ObjectVT))
797 ArgValue = DAG.getConstant(0, ObjectVT);
798 else
799 ArgValue = DAG.getConstantFP(0, ObjectVT);
800 }
801 ArgValues.push_back(ArgValue);
802
803 if (ObjSize)
804 ArgOffset += ArgIncrement; // Move on to the next argument.
805 }
806
807 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
808 // arguments and the arguments after the retaddr has been pushed are aligned.
809 if ((ArgOffset & 7) == 0)
810 ArgOffset += 4;
811
812 VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs.
813 ReturnAddrIndex = 0; // No return address slot generated yet.
814 BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments.
815 BytesCallerReserves = 0;
816
817 // Finally, inform the code generator which regs we return values in.
818 switch (getValueType(F.getReturnType())) {
819 default: assert(0 && "Unknown type!");
820 case MVT::isVoid: break;
821 case MVT::i1:
822 case MVT::i8:
823 case MVT::i16:
824 case MVT::i32:
825 MF.addLiveOut(X86::EAX);
826 break;
827 case MVT::i64:
828 MF.addLiveOut(X86::EAX);
829 MF.addLiveOut(X86::EDX);
830 break;
831 case MVT::f32:
832 case MVT::f64:
833 MF.addLiveOut(X86::ST0);
834 break;
835 }
836 return ArgValues;
837}
838
839std::pair<SDOperand, SDOperand>
840X86TargetLowering::LowerFastCCCallTo(SDOperand Chain, const Type *RetTy,
841 bool isTailCall, SDOperand Callee,
842 ArgListTy &Args, SelectionDAG &DAG) {
843 // Count how many bytes are to be pushed on the stack.
844 unsigned NumBytes = 0;
845
846 // Keep track of the number of integer regs passed so far. This can be either
847 // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both
848 // used).
849 unsigned NumIntRegs = 0;
850
851 for (unsigned i = 0, e = Args.size(); i != e; ++i)
852 switch (getValueType(Args[i].second)) {
853 default: assert(0 && "Unknown value type!");
854 case MVT::i1:
855 case MVT::i8:
856 case MVT::i16:
857 case MVT::i32:
Chris Lattner1c636e92006-03-17 05:10:20 +0000858 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000859 ++NumIntRegs;
860 break;
861 }
862 // fall through
863 case MVT::f32:
864 NumBytes += 4;
865 break;
866 case MVT::i64:
Chris Lattner1c636e92006-03-17 05:10:20 +0000867 if (NumIntRegs+2 <= FASTCC_NUM_INT_ARGS_INREGS) {
868 NumIntRegs += 2;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000869 break;
Chris Lattner1c636e92006-03-17 05:10:20 +0000870 } else if (NumIntRegs+1 <= FASTCC_NUM_INT_ARGS_INREGS) {
871 NumIntRegs = FASTCC_NUM_INT_ARGS_INREGS;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000872 NumBytes += 4;
873 break;
874 }
875
876 // fall through
877 case MVT::f64:
878 NumBytes += 8;
879 break;
880 }
881
882 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
883 // arguments and the arguments after the retaddr has been pushed are aligned.
884 if ((NumBytes & 7) == 0)
885 NumBytes += 4;
886
Chris Lattner94dd2922006-02-13 09:00:43 +0000887 Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy()));
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000888
889 // Arguments go on the stack in reverse order, as specified by the ABI.
890 unsigned ArgOffset = 0;
Chris Lattner91cacc82006-01-24 06:14:44 +0000891 SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000892 NumIntRegs = 0;
893 std::vector<SDOperand> Stores;
894 std::vector<SDOperand> RegValuesToPass;
895 for (unsigned i = 0, e = Args.size(); i != e; ++i) {
896 switch (getValueType(Args[i].second)) {
897 default: assert(0 && "Unexpected ValueType for argument!");
898 case MVT::i1:
Chris Lattnerf31d1932005-12-27 03:02:18 +0000899 Args[i].first = DAG.getNode(ISD::ANY_EXTEND, MVT::i8, Args[i].first);
900 // Fall through.
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000901 case MVT::i8:
902 case MVT::i16:
903 case MVT::i32:
Chris Lattner1c636e92006-03-17 05:10:20 +0000904 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000905 RegValuesToPass.push_back(Args[i].first);
906 ++NumIntRegs;
907 break;
908 }
909 // Fall through
910 case MVT::f32: {
911 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
912 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
913 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
914 Args[i].first, PtrOff,
915 DAG.getSrcValue(NULL)));
916 ArgOffset += 4;
917 break;
918 }
919 case MVT::i64:
Chris Lattner1c636e92006-03-17 05:10:20 +0000920 // Can pass (at least) part of it in regs?
921 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000922 SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
923 Args[i].first, DAG.getConstant(1, MVT::i32));
924 SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32,
925 Args[i].first, DAG.getConstant(0, MVT::i32));
926 RegValuesToPass.push_back(Lo);
927 ++NumIntRegs;
Chris Lattner1c636e92006-03-17 05:10:20 +0000928
929 // Pass both parts in regs?
930 if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) {
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000931 RegValuesToPass.push_back(Hi);
932 ++NumIntRegs;
933 } else {
934 // Pass the high part in memory.
935 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
936 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
937 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
938 Hi, PtrOff, DAG.getSrcValue(NULL)));
939 ArgOffset += 4;
940 }
941 break;
942 }
943 // Fall through
944 case MVT::f64:
945 SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy());
946 PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff);
947 Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain,
948 Args[i].first, PtrOff,
949 DAG.getSrcValue(NULL)));
950 ArgOffset += 8;
951 break;
952 }
953 }
954 if (!Stores.empty())
955 Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores);
956
957 // Make sure the instruction takes 8n+4 bytes to make sure the start of the
958 // arguments and the arguments after the retaddr has been pushed are aligned.
959 if ((ArgOffset & 7) == 0)
960 ArgOffset += 4;
961
962 std::vector<MVT::ValueType> RetVals;
963 MVT::ValueType RetTyVT = getValueType(RetTy);
964
965 RetVals.push_back(MVT::Other);
966
967 // The result values produced have to be legal. Promote the result.
968 switch (RetTyVT) {
969 case MVT::isVoid: break;
970 default:
971 RetVals.push_back(RetTyVT);
972 break;
973 case MVT::i1:
974 case MVT::i8:
975 case MVT::i16:
976 RetVals.push_back(MVT::i32);
977 break;
978 case MVT::f32:
979 if (X86ScalarSSE)
980 RetVals.push_back(MVT::f32);
981 else
982 RetVals.push_back(MVT::f64);
983 break;
984 case MVT::i64:
985 RetVals.push_back(MVT::i32);
986 RetVals.push_back(MVT::i32);
987 break;
988 }
989
Nate Begeman4c5dcf52006-02-17 00:03:04 +0000990 // Build a sequence of copy-to-reg nodes chained together with token chain
991 // and flag operands which copy the outgoing args into registers.
992 SDOperand InFlag;
993 for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) {
994 unsigned CCReg;
995 SDOperand RegToPass = RegValuesToPass[i];
996 switch (RegToPass.getValueType()) {
997 default: assert(0 && "Bad thing to pass in regs");
998 case MVT::i8:
999 CCReg = (i == 0) ? X86::AL : X86::DL;
Evan Chengd9558e02006-01-06 00:43:03 +00001000 break;
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001001 case MVT::i16:
1002 CCReg = (i == 0) ? X86::AX : X86::DX;
1003 break;
1004 case MVT::i32:
1005 CCReg = (i == 0) ? X86::EAX : X86::EDX;
1006 break;
1007 }
1008
1009 Chain = DAG.getCopyToReg(Chain, CCReg, RegToPass, InFlag);
1010 InFlag = Chain.getValue(1);
1011 }
1012
1013 std::vector<MVT::ValueType> NodeTys;
1014 NodeTys.push_back(MVT::Other); // Returns a chain
1015 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
1016 std::vector<SDOperand> Ops;
1017 Ops.push_back(Chain);
1018 Ops.push_back(Callee);
1019 if (InFlag.Val)
1020 Ops.push_back(InFlag);
1021
1022 // FIXME: Do not generate X86ISD::TAILCALL for now.
1023 Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops);
1024 InFlag = Chain.getValue(1);
1025
1026 NodeTys.clear();
1027 NodeTys.push_back(MVT::Other); // Returns a chain
1028 NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use.
1029 Ops.clear();
1030 Ops.push_back(Chain);
1031 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1032 Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy()));
1033 Ops.push_back(InFlag);
1034 Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops);
1035 InFlag = Chain.getValue(1);
1036
1037 SDOperand RetVal;
1038 if (RetTyVT != MVT::isVoid) {
1039 switch (RetTyVT) {
1040 default: assert(0 && "Unknown value type to return!");
Evan Chengd9558e02006-01-06 00:43:03 +00001041 case MVT::i1:
1042 case MVT::i8:
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001043 RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag);
1044 Chain = RetVal.getValue(1);
1045 if (RetTyVT == MVT::i1)
1046 RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal);
1047 break;
Evan Chengd9558e02006-01-06 00:43:03 +00001048 case MVT::i16:
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001049 RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag);
1050 Chain = RetVal.getValue(1);
Evan Chengd9558e02006-01-06 00:43:03 +00001051 break;
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001052 case MVT::i32:
1053 RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1054 Chain = RetVal.getValue(1);
Evan Chengd9558e02006-01-06 00:43:03 +00001055 break;
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001056 case MVT::i64: {
1057 SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag);
1058 SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32,
1059 Lo.getValue(2));
1060 RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi);
1061 Chain = Hi.getValue(1);
Evan Chengd9558e02006-01-06 00:43:03 +00001062 break;
1063 }
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001064 case MVT::f32:
1065 case MVT::f64: {
1066 std::vector<MVT::ValueType> Tys;
1067 Tys.push_back(MVT::f64);
1068 Tys.push_back(MVT::Other);
1069 Tys.push_back(MVT::Flag);
1070 std::vector<SDOperand> Ops;
1071 Ops.push_back(Chain);
1072 Ops.push_back(InFlag);
1073 RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops);
1074 Chain = RetVal.getValue(1);
1075 InFlag = RetVal.getValue(2);
1076 if (X86ScalarSSE) {
1077 // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This
1078 // shouldn't be necessary except that RFP cannot be live across
1079 // multiple blocks. When stackifier is fixed, they can be uncoupled.
1080 MachineFunction &MF = DAG.getMachineFunction();
1081 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
1082 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1083 Tys.clear();
1084 Tys.push_back(MVT::Other);
1085 Ops.clear();
1086 Ops.push_back(Chain);
1087 Ops.push_back(RetVal);
1088 Ops.push_back(StackSlot);
1089 Ops.push_back(DAG.getValueType(RetTyVT));
1090 Ops.push_back(InFlag);
1091 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1092 RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot,
1093 DAG.getSrcValue(NULL));
1094 Chain = RetVal.getValue(1);
1095 }
Evan Chengd9558e02006-01-06 00:43:03 +00001096
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001097 if (RetTyVT == MVT::f32 && !X86ScalarSSE)
1098 // FIXME: we would really like to remember that this FP_ROUND
1099 // operation is okay to eliminate if we allow excess FP precision.
1100 RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal);
1101 break;
1102 }
1103 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001104 }
Nate Begeman4c5dcf52006-02-17 00:03:04 +00001105
1106 return std::make_pair(RetVal, Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001107}
1108
1109SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) {
1110 if (ReturnAddrIndex == 0) {
1111 // Set up a frame object for the return address.
1112 MachineFunction &MF = DAG.getMachineFunction();
1113 ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4);
1114 }
1115
1116 return DAG.getFrameIndex(ReturnAddrIndex, MVT::i32);
1117}
1118
1119
1120
1121std::pair<SDOperand, SDOperand> X86TargetLowering::
1122LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth,
1123 SelectionDAG &DAG) {
1124 SDOperand Result;
1125 if (Depth) // Depths > 0 not supported yet!
1126 Result = DAG.getConstant(0, getPointerTy());
1127 else {
1128 SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG);
1129 if (!isFrameAddress)
1130 // Just load the return address
1131 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), RetAddrFI,
1132 DAG.getSrcValue(NULL));
1133 else
1134 Result = DAG.getNode(ISD::SUB, MVT::i32, RetAddrFI,
1135 DAG.getConstant(4, MVT::i32));
1136 }
1137 return std::make_pair(Result, Chain);
1138}
1139
Evan Cheng4a460802006-01-11 00:33:36 +00001140/// getCondBrOpcodeForX86CC - Returns the X86 conditional branch opcode
1141/// which corresponds to the condition code.
1142static unsigned getCondBrOpcodeForX86CC(unsigned X86CC) {
1143 switch (X86CC) {
1144 default: assert(0 && "Unknown X86 conditional code!");
1145 case X86ISD::COND_A: return X86::JA;
1146 case X86ISD::COND_AE: return X86::JAE;
1147 case X86ISD::COND_B: return X86::JB;
1148 case X86ISD::COND_BE: return X86::JBE;
1149 case X86ISD::COND_E: return X86::JE;
1150 case X86ISD::COND_G: return X86::JG;
1151 case X86ISD::COND_GE: return X86::JGE;
1152 case X86ISD::COND_L: return X86::JL;
1153 case X86ISD::COND_LE: return X86::JLE;
1154 case X86ISD::COND_NE: return X86::JNE;
1155 case X86ISD::COND_NO: return X86::JNO;
1156 case X86ISD::COND_NP: return X86::JNP;
1157 case X86ISD::COND_NS: return X86::JNS;
1158 case X86ISD::COND_O: return X86::JO;
1159 case X86ISD::COND_P: return X86::JP;
1160 case X86ISD::COND_S: return X86::JS;
1161 }
1162}
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001163
Evan Cheng6dfa9992006-01-30 23:41:35 +00001164/// translateX86CC - do a one to one translation of a ISD::CondCode to the X86
1165/// specific condition code. It returns a false if it cannot do a direct
1166/// translation. X86CC is the translated CondCode. Flip is set to true if the
1167/// the order of comparison operands should be flipped.
Chris Lattner259e97c2006-01-31 19:43:35 +00001168static bool translateX86CC(SDOperand CC, bool isFP, unsigned &X86CC,
1169 bool &Flip) {
Evan Chengd9558e02006-01-06 00:43:03 +00001170 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
Evan Cheng6dfa9992006-01-30 23:41:35 +00001171 Flip = false;
1172 X86CC = X86ISD::COND_INVALID;
Evan Chengd9558e02006-01-06 00:43:03 +00001173 if (!isFP) {
1174 switch (SetCCOpcode) {
1175 default: break;
1176 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
1177 case ISD::SETGT: X86CC = X86ISD::COND_G; break;
1178 case ISD::SETGE: X86CC = X86ISD::COND_GE; break;
1179 case ISD::SETLT: X86CC = X86ISD::COND_L; break;
1180 case ISD::SETLE: X86CC = X86ISD::COND_LE; break;
1181 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1182 case ISD::SETULT: X86CC = X86ISD::COND_B; break;
1183 case ISD::SETUGT: X86CC = X86ISD::COND_A; break;
1184 case ISD::SETULE: X86CC = X86ISD::COND_BE; break;
1185 case ISD::SETUGE: X86CC = X86ISD::COND_AE; break;
1186 }
1187 } else {
1188 // On a floating point condition, the flags are set as follows:
1189 // ZF PF CF op
1190 // 0 | 0 | 0 | X > Y
1191 // 0 | 0 | 1 | X < Y
1192 // 1 | 0 | 0 | X == Y
1193 // 1 | 1 | 1 | unordered
1194 switch (SetCCOpcode) {
1195 default: break;
1196 case ISD::SETUEQ:
1197 case ISD::SETEQ: X86CC = X86ISD::COND_E; break;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001198 case ISD::SETOLE: Flip = true; // Fallthrough
Evan Chengd9558e02006-01-06 00:43:03 +00001199 case ISD::SETOGT:
1200 case ISD::SETGT: X86CC = X86ISD::COND_A; break;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001201 case ISD::SETOLT: Flip = true; // Fallthrough
Evan Chengd9558e02006-01-06 00:43:03 +00001202 case ISD::SETOGE:
1203 case ISD::SETGE: X86CC = X86ISD::COND_AE; break;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001204 case ISD::SETUGE: Flip = true; // Fallthrough
Evan Chengd9558e02006-01-06 00:43:03 +00001205 case ISD::SETULT:
1206 case ISD::SETLT: X86CC = X86ISD::COND_B; break;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001207 case ISD::SETUGT: Flip = true; // Fallthrough
Evan Chengd9558e02006-01-06 00:43:03 +00001208 case ISD::SETULE:
1209 case ISD::SETLE: X86CC = X86ISD::COND_BE; break;
1210 case ISD::SETONE:
1211 case ISD::SETNE: X86CC = X86ISD::COND_NE; break;
1212 case ISD::SETUO: X86CC = X86ISD::COND_P; break;
1213 case ISD::SETO: X86CC = X86ISD::COND_NP; break;
1214 }
1215 }
Evan Cheng6dfa9992006-01-30 23:41:35 +00001216
1217 return X86CC != X86ISD::COND_INVALID;
Evan Chengd9558e02006-01-06 00:43:03 +00001218}
1219
Evan Cheng4a460802006-01-11 00:33:36 +00001220/// hasFPCMov - is there a floating point cmov for the specific X86 condition
1221/// code. Current x86 isa includes the following FP cmov instructions:
Evan Chengaaca22c2006-01-10 20:26:56 +00001222/// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu.
Evan Cheng4a460802006-01-11 00:33:36 +00001223static bool hasFPCMov(unsigned X86CC) {
Evan Chengaaca22c2006-01-10 20:26:56 +00001224 switch (X86CC) {
1225 default:
1226 return false;
1227 case X86ISD::COND_B:
1228 case X86ISD::COND_BE:
1229 case X86ISD::COND_E:
1230 case X86ISD::COND_P:
1231 case X86ISD::COND_A:
1232 case X86ISD::COND_AE:
1233 case X86ISD::COND_NE:
1234 case X86ISD::COND_NP:
1235 return true;
1236 }
1237}
1238
Evan Cheng4a460802006-01-11 00:33:36 +00001239MachineBasicBlock *
1240X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI,
1241 MachineBasicBlock *BB) {
Evan Cheng0cc39452006-01-16 21:21:29 +00001242 switch (MI->getOpcode()) {
1243 default: assert(false && "Unexpected instr type to insert");
1244 case X86::CMOV_FR32:
1245 case X86::CMOV_FR64: {
Chris Lattner259e97c2006-01-31 19:43:35 +00001246 // To "insert" a SELECT_CC instruction, we actually have to insert the
1247 // diamond control-flow pattern. The incoming instruction knows the
1248 // destination vreg to set, the condition code register to branch on, the
1249 // true/false values to select between, and a branch opcode to use.
Evan Cheng0cc39452006-01-16 21:21:29 +00001250 const BasicBlock *LLVM_BB = BB->getBasicBlock();
1251 ilist<MachineBasicBlock>::iterator It = BB;
1252 ++It;
1253
1254 // thisMBB:
1255 // ...
1256 // TrueVal = ...
1257 // cmpTY ccX, r1, r2
1258 // bCC copy1MBB
1259 // fallthrough --> copy0MBB
1260 MachineBasicBlock *thisMBB = BB;
1261 MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB);
1262 MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB);
1263 unsigned Opc = getCondBrOpcodeForX86CC(MI->getOperand(3).getImmedValue());
1264 BuildMI(BB, Opc, 1).addMBB(sinkMBB);
1265 MachineFunction *F = BB->getParent();
1266 F->getBasicBlockList().insert(It, copy0MBB);
1267 F->getBasicBlockList().insert(It, sinkMBB);
1268 // Update machine-CFG edges
1269 BB->addSuccessor(copy0MBB);
1270 BB->addSuccessor(sinkMBB);
1271
1272 // copy0MBB:
1273 // %FalseValue = ...
1274 // # fallthrough to sinkMBB
1275 BB = copy0MBB;
1276
1277 // Update machine-CFG edges
1278 BB->addSuccessor(sinkMBB);
1279
1280 // sinkMBB:
1281 // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ]
1282 // ...
1283 BB = sinkMBB;
1284 BuildMI(BB, X86::PHI, 4, MI->getOperand(0).getReg())
1285 .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB)
1286 .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB);
Evan Cheng4a460802006-01-11 00:33:36 +00001287
Evan Cheng0cc39452006-01-16 21:21:29 +00001288 delete MI; // The pseudo instruction is gone now.
1289 return BB;
1290 }
Evan Cheng4a460802006-01-11 00:33:36 +00001291
Evan Cheng0cc39452006-01-16 21:21:29 +00001292 case X86::FP_TO_INT16_IN_MEM:
1293 case X86::FP_TO_INT32_IN_MEM:
1294 case X86::FP_TO_INT64_IN_MEM: {
1295 // Change the floating point control register to use "round towards zero"
1296 // mode when truncating to an integer value.
1297 MachineFunction *F = BB->getParent();
1298 int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2);
1299 addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx);
1300
1301 // Load the old value of the high byte of the control word...
1302 unsigned OldCW =
1303 F->getSSARegMap()->createVirtualRegister(X86::R16RegisterClass);
1304 addFrameReference(BuildMI(BB, X86::MOV16rm, 4, OldCW), CWFrameIdx);
1305
1306 // Set the high part to be round to zero...
1307 addFrameReference(BuildMI(BB, X86::MOV16mi, 5), CWFrameIdx).addImm(0xC7F);
1308
1309 // Reload the modified control word now...
1310 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
1311
1312 // Restore the memory image of control word to original value
1313 addFrameReference(BuildMI(BB, X86::MOV16mr, 5), CWFrameIdx).addReg(OldCW);
1314
1315 // Get the X86 opcode to use.
1316 unsigned Opc;
1317 switch (MI->getOpcode()) {
Chris Lattner6b2469c2006-01-28 10:34:47 +00001318 default: assert(0 && "illegal opcode!");
Evan Cheng0cc39452006-01-16 21:21:29 +00001319 case X86::FP_TO_INT16_IN_MEM: Opc = X86::FpIST16m; break;
1320 case X86::FP_TO_INT32_IN_MEM: Opc = X86::FpIST32m; break;
1321 case X86::FP_TO_INT64_IN_MEM: Opc = X86::FpIST64m; break;
1322 }
1323
1324 X86AddressMode AM;
1325 MachineOperand &Op = MI->getOperand(0);
1326 if (Op.isRegister()) {
1327 AM.BaseType = X86AddressMode::RegBase;
1328 AM.Base.Reg = Op.getReg();
1329 } else {
1330 AM.BaseType = X86AddressMode::FrameIndexBase;
1331 AM.Base.FrameIndex = Op.getFrameIndex();
1332 }
1333 Op = MI->getOperand(1);
1334 if (Op.isImmediate())
1335 AM.Scale = Op.getImmedValue();
1336 Op = MI->getOperand(2);
1337 if (Op.isImmediate())
1338 AM.IndexReg = Op.getImmedValue();
1339 Op = MI->getOperand(3);
1340 if (Op.isGlobalAddress()) {
1341 AM.GV = Op.getGlobal();
1342 } else {
1343 AM.Disp = Op.getImmedValue();
1344 }
1345 addFullAddress(BuildMI(BB, Opc, 5), AM).addReg(MI->getOperand(4).getReg());
1346
1347 // Reload the original control word now.
1348 addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx);
1349
1350 delete MI; // The pseudo instruction is gone now.
1351 return BB;
1352 }
1353 }
Evan Cheng4a460802006-01-11 00:33:36 +00001354}
1355
1356
1357//===----------------------------------------------------------------------===//
1358// X86 Custom Lowering Hooks
1359//===----------------------------------------------------------------------===//
1360
Evan Cheng30b37b52006-03-13 23:18:16 +00001361/// DarwinGVRequiresExtraLoad - true if accessing the GV requires an extra
1362/// load. For Darwin, external and weak symbols are indirect, loading the value
1363/// at address GV rather then the value of GV itself. This means that the
1364/// GlobalAddress must be in the base or index register of the address, not the
1365/// GV offset field.
1366static bool DarwinGVRequiresExtraLoad(GlobalValue *GV) {
1367 return (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() ||
1368 (GV->isExternal() && !GV->hasNotBeenReadFromBytecode()));
1369}
1370
Evan Cheng0188ecb2006-03-22 18:59:22 +00001371/// isPSHUFDMask - Return true if the specified VECTOR_SHUFFLE operand
1372/// specifies a shuffle of elements that is suitable for input to PSHUFD.
1373bool X86::isPSHUFDMask(SDNode *N) {
1374 assert(N->getOpcode() == ISD::BUILD_VECTOR);
1375
1376 if (N->getNumOperands() != 4)
1377 return false;
1378
1379 // Check if the value doesn't reference the second vector.
1380 SDOperand Elt = N->getOperand(0);
1381 assert(isa<ConstantSDNode>(Elt) && "Invalid VECTOR_SHUFFLE mask!");
1382 for (unsigned i = 1, e = N->getNumOperands(); i != e; ++i) {
1383 assert(isa<ConstantSDNode>(N->getOperand(i)) &&
1384 "Invalid VECTOR_SHUFFLE mask!");
1385 if (cast<ConstantSDNode>(N->getOperand(i))->getValue() >= 4) return false;
1386 }
1387
1388 return true;
1389}
1390
Evan Chengb9df0ca2006-03-22 02:53:00 +00001391/// isSplatMask - Return true if the specified VECTOR_SHUFFLE operand specifies
1392/// a splat of a single element.
1393bool X86::isSplatMask(SDNode *N) {
1394 assert(N->getOpcode() == ISD::BUILD_VECTOR);
1395
1396 // We can only splat 64-bit, and 32-bit quantities.
1397 if (N->getNumOperands() != 4 && N->getNumOperands() != 2)
1398 return false;
1399
1400 // This is a splat operation if each element of the permute is the same, and
1401 // if the value doesn't reference the second vector.
1402 SDOperand Elt = N->getOperand(0);
1403 assert(isa<ConstantSDNode>(Elt) && "Invalid VECTOR_SHUFFLE mask!");
1404 for (unsigned i = 1, e = N->getNumOperands(); i != e; ++i) {
1405 assert(isa<ConstantSDNode>(N->getOperand(i)) &&
1406 "Invalid VECTOR_SHUFFLE mask!");
1407 if (N->getOperand(i) != Elt) return false;
1408 }
1409
1410 // Make sure it is a splat of the first vector operand.
1411 return cast<ConstantSDNode>(Elt)->getValue() < N->getNumOperands();
1412}
1413
Evan Cheng63d33002006-03-22 08:01:21 +00001414/// getShuffleSHUFImmediate - Return the appropriate immediate to shuffle
1415/// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUF* and SHUFP*
1416/// instructions.
1417unsigned X86::getShuffleSHUFImmediate(SDNode *N) {
Evan Chengb9df0ca2006-03-22 02:53:00 +00001418 unsigned NumOperands = N->getNumOperands();
1419 unsigned Shift = (NumOperands == 4) ? 2 : 1;
1420 unsigned Mask = 0;
1421 unsigned i = NumOperands - 1;
1422 do {
1423 Mask |= cast<ConstantSDNode>(N->getOperand(i))->getValue();
1424 Mask <<= Shift;
1425 --i;
1426 } while (i != 0);
1427
1428 return Mask;
1429}
1430
Evan Cheng63d33002006-03-22 08:01:21 +00001431/// getShufflePSHUFDImmediate - Return the appropriate immediate to shuffle
1432/// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFD instruction.
1433unsigned X86::getShufflePSHUFDImmediate(SDNode *N) {
1434 unsigned NumOperands = N->getNumOperands();
1435 unsigned Mask = 0;
1436
1437 assert(NumOperands == 4 && "Expect v4f32 / v4i32 vector operand");
1438
1439 unsigned i = NumOperands - 1;
1440 do {
1441 uint64_t Val = cast<ConstantSDNode>(N->getOperand(i))->getValue();
1442 // Second vector operand must be undef. We can have it point to anything
1443 // we want.
1444 if (Val >= NumOperands) Val = 0;
1445 Mask |= Val;
1446 Mask <<= 2;
1447 --i;
1448 } while (i != 0);
1449
1450 return Mask;
1451}
1452
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001453/// LowerOperation - Provide custom lowering hooks for some operations.
1454///
1455SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) {
1456 switch (Op.getOpcode()) {
1457 default: assert(0 && "Should not custom lower this!");
Evan Chenge3413162006-01-09 18:33:28 +00001458 case ISD::SHL_PARTS:
1459 case ISD::SRA_PARTS:
1460 case ISD::SRL_PARTS: {
1461 assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 &&
1462 "Not an i64 shift!");
1463 bool isSRA = Op.getOpcode() == ISD::SRA_PARTS;
1464 SDOperand ShOpLo = Op.getOperand(0);
1465 SDOperand ShOpHi = Op.getOperand(1);
1466 SDOperand ShAmt = Op.getOperand(2);
1467 SDOperand Tmp1 = isSRA ? DAG.getNode(ISD::SRA, MVT::i32, ShOpHi,
Evan Cheng99fa0a12006-01-18 09:26:46 +00001468 DAG.getConstant(31, MVT::i8))
Evan Chenge3413162006-01-09 18:33:28 +00001469 : DAG.getConstant(0, MVT::i32);
1470
1471 SDOperand Tmp2, Tmp3;
1472 if (Op.getOpcode() == ISD::SHL_PARTS) {
1473 Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt);
1474 Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt);
1475 } else {
1476 Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt);
Evan Chengb7b57062006-01-19 01:46:14 +00001477 Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SRL, MVT::i32, ShOpHi, ShAmt);
Evan Chenge3413162006-01-09 18:33:28 +00001478 }
1479
1480 SDOperand InFlag = DAG.getNode(X86ISD::TEST, MVT::Flag,
1481 ShAmt, DAG.getConstant(32, MVT::i8));
1482
1483 SDOperand Hi, Lo;
Evan Cheng82a24b92006-01-09 20:49:21 +00001484 SDOperand CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Chenge3413162006-01-09 18:33:28 +00001485
1486 std::vector<MVT::ValueType> Tys;
1487 Tys.push_back(MVT::i32);
1488 Tys.push_back(MVT::Flag);
1489 std::vector<SDOperand> Ops;
1490 if (Op.getOpcode() == ISD::SHL_PARTS) {
1491 Ops.push_back(Tmp2);
1492 Ops.push_back(Tmp3);
1493 Ops.push_back(CC);
1494 Ops.push_back(InFlag);
1495 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1496 InFlag = Hi.getValue(1);
1497
1498 Ops.clear();
1499 Ops.push_back(Tmp3);
1500 Ops.push_back(Tmp1);
1501 Ops.push_back(CC);
1502 Ops.push_back(InFlag);
1503 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1504 } else {
1505 Ops.push_back(Tmp2);
1506 Ops.push_back(Tmp3);
1507 Ops.push_back(CC);
Evan Cheng910cd3c2006-01-09 22:29:54 +00001508 Ops.push_back(InFlag);
Evan Chenge3413162006-01-09 18:33:28 +00001509 Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1510 InFlag = Lo.getValue(1);
1511
1512 Ops.clear();
1513 Ops.push_back(Tmp3);
1514 Ops.push_back(Tmp1);
1515 Ops.push_back(CC);
1516 Ops.push_back(InFlag);
1517 Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops);
1518 }
1519
1520 Tys.clear();
1521 Tys.push_back(MVT::i32);
1522 Tys.push_back(MVT::i32);
1523 Ops.clear();
1524 Ops.push_back(Lo);
1525 Ops.push_back(Hi);
1526 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
1527 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001528 case ISD::SINT_TO_FP: {
Evan Cheng02568ff2006-01-30 22:13:22 +00001529 assert(Op.getOperand(0).getValueType() <= MVT::i64 &&
Evan Chenga3195e82006-01-12 22:54:21 +00001530 Op.getOperand(0).getValueType() >= MVT::i16 &&
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001531 "Unknown SINT_TO_FP to lower!");
Evan Chenga3195e82006-01-12 22:54:21 +00001532
1533 SDOperand Result;
1534 MVT::ValueType SrcVT = Op.getOperand(0).getValueType();
1535 unsigned Size = MVT::getSizeInBits(SrcVT)/8;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001536 MachineFunction &MF = DAG.getMachineFunction();
Evan Chenga3195e82006-01-12 22:54:21 +00001537 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001538 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
Evan Chenga3195e82006-01-12 22:54:21 +00001539 SDOperand Chain = DAG.getNode(ISD::STORE, MVT::Other,
1540 DAG.getEntryNode(), Op.getOperand(0),
1541 StackSlot, DAG.getSrcValue(NULL));
1542
1543 // Build the FILD
1544 std::vector<MVT::ValueType> Tys;
1545 Tys.push_back(MVT::f64);
Evan Cheng6dab0532006-01-30 08:02:57 +00001546 Tys.push_back(MVT::Other);
Evan Chenge3de85b2006-02-04 02:20:30 +00001547 if (X86ScalarSSE) Tys.push_back(MVT::Flag);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001548 std::vector<SDOperand> Ops;
Evan Chenga3195e82006-01-12 22:54:21 +00001549 Ops.push_back(Chain);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001550 Ops.push_back(StackSlot);
Evan Chenga3195e82006-01-12 22:54:21 +00001551 Ops.push_back(DAG.getValueType(SrcVT));
Evan Chenge3de85b2006-02-04 02:20:30 +00001552 Result = DAG.getNode(X86ScalarSSE ? X86ISD::FILD_FLAG :X86ISD::FILD,
1553 Tys, Ops);
Evan Cheng6dab0532006-01-30 08:02:57 +00001554
1555 if (X86ScalarSSE) {
Evan Cheng6dab0532006-01-30 08:02:57 +00001556 Chain = Result.getValue(1);
1557 SDOperand InFlag = Result.getValue(2);
1558
Evan Chenge3de85b2006-02-04 02:20:30 +00001559 // FIXME: Currently the FST is flagged to the FILD_FLAG. This
Evan Cheng6dab0532006-01-30 08:02:57 +00001560 // shouldn't be necessary except that RFP cannot be live across
1561 // multiple blocks. When stackifier is fixed, they can be uncoupled.
1562 MachineFunction &MF = DAG.getMachineFunction();
1563 int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8);
1564 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1565 std::vector<MVT::ValueType> Tys;
1566 Tys.push_back(MVT::Other);
1567 std::vector<SDOperand> Ops;
1568 Ops.push_back(Chain);
1569 Ops.push_back(Result);
1570 Ops.push_back(StackSlot);
Evan Cheng02568ff2006-01-30 22:13:22 +00001571 Ops.push_back(DAG.getValueType(Op.getValueType()));
Evan Cheng6dab0532006-01-30 08:02:57 +00001572 Ops.push_back(InFlag);
1573 Chain = DAG.getNode(X86ISD::FST, Tys, Ops);
1574 Result = DAG.getLoad(Op.getValueType(), Chain, StackSlot,
1575 DAG.getSrcValue(NULL));
1576 }
1577
Evan Chenga3195e82006-01-12 22:54:21 +00001578 return Result;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001579 }
1580 case ISD::FP_TO_SINT: {
1581 assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 &&
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001582 "Unknown FP_TO_SINT to lower!");
1583 // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary
1584 // stack slot.
1585 MachineFunction &MF = DAG.getMachineFunction();
1586 unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8;
1587 int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1588 SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1589
1590 unsigned Opc;
1591 switch (Op.getValueType()) {
1592 default: assert(0 && "Invalid FP_TO_SINT to lower!");
1593 case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break;
1594 case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break;
1595 case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break;
1596 }
1597
Evan Cheng6dab0532006-01-30 08:02:57 +00001598 SDOperand Chain = DAG.getEntryNode();
1599 SDOperand Value = Op.getOperand(0);
1600 if (X86ScalarSSE) {
1601 assert(Op.getValueType() == MVT::i64 && "Invalid FP_TO_SINT to lower!");
1602 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, StackSlot,
1603 DAG.getSrcValue(0));
1604 std::vector<MVT::ValueType> Tys;
1605 Tys.push_back(MVT::f64);
1606 Tys.push_back(MVT::Other);
1607 std::vector<SDOperand> Ops;
1608 Ops.push_back(Chain);
1609 Ops.push_back(StackSlot);
Evan Cheng02568ff2006-01-30 22:13:22 +00001610 Ops.push_back(DAG.getValueType(Op.getOperand(0).getValueType()));
Evan Cheng6dab0532006-01-30 08:02:57 +00001611 Value = DAG.getNode(X86ISD::FLD, Tys, Ops);
1612 Chain = Value.getValue(1);
1613 SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize);
1614 StackSlot = DAG.getFrameIndex(SSFI, getPointerTy());
1615 }
1616
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001617 // Build the FP_TO_INT*_IN_MEM
1618 std::vector<SDOperand> Ops;
Evan Cheng6dab0532006-01-30 08:02:57 +00001619 Ops.push_back(Chain);
1620 Ops.push_back(Value);
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001621 Ops.push_back(StackSlot);
1622 SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops);
1623
1624 // Load the result.
1625 return DAG.getLoad(Op.getValueType(), FIST, StackSlot,
1626 DAG.getSrcValue(NULL));
1627 }
Andrew Lenharthb873ff32005-11-20 21:41:10 +00001628 case ISD::READCYCLECOUNTER: {
Chris Lattner81363c32005-11-20 22:01:40 +00001629 std::vector<MVT::ValueType> Tys;
1630 Tys.push_back(MVT::Other);
1631 Tys.push_back(MVT::Flag);
1632 std::vector<SDOperand> Ops;
1633 Ops.push_back(Op.getOperand(0));
1634 SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, Ops);
Chris Lattner81f803d2005-11-20 22:57:19 +00001635 Ops.clear();
1636 Ops.push_back(DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1)));
1637 Ops.push_back(DAG.getCopyFromReg(Ops[0].getValue(1), X86::EDX,
1638 MVT::i32, Ops[0].getValue(2)));
1639 Ops.push_back(Ops[1].getValue(1));
1640 Tys[0] = Tys[1] = MVT::i32;
1641 Tys.push_back(MVT::Other);
1642 return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops);
Andrew Lenharthb873ff32005-11-20 21:41:10 +00001643 }
Evan Chengef6ffb12006-01-31 03:14:29 +00001644 case ISD::FABS: {
1645 MVT::ValueType VT = Op.getValueType();
Evan Cheng223547a2006-01-31 22:28:30 +00001646 const Type *OpNTy = MVT::getTypeForValueType(VT);
1647 std::vector<Constant*> CV;
1648 if (VT == MVT::f64) {
1649 CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(~(1ULL << 63))));
1650 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1651 } else {
1652 CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(~(1U << 31))));
1653 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1654 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1655 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1656 }
1657 Constant *CS = ConstantStruct::get(CV);
1658 SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4);
1659 SDOperand Mask
1660 = DAG.getNode(X86ISD::LOAD_PACK,
1661 VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL));
Evan Chengef6ffb12006-01-31 03:14:29 +00001662 return DAG.getNode(X86ISD::FAND, VT, Op.getOperand(0), Mask);
1663 }
Evan Cheng223547a2006-01-31 22:28:30 +00001664 case ISD::FNEG: {
1665 MVT::ValueType VT = Op.getValueType();
1666 const Type *OpNTy = MVT::getTypeForValueType(VT);
1667 std::vector<Constant*> CV;
1668 if (VT == MVT::f64) {
1669 CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(1ULL << 63)));
1670 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1671 } else {
1672 CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(1U << 31)));
1673 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1674 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1675 CV.push_back(ConstantFP::get(OpNTy, 0.0));
1676 }
1677 Constant *CS = ConstantStruct::get(CV);
1678 SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4);
1679 SDOperand Mask
1680 = DAG.getNode(X86ISD::LOAD_PACK,
1681 VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL));
1682 return DAG.getNode(X86ISD::FXOR, VT, Op.getOperand(0), Mask);
1683 }
Evan Chengd5781fc2005-12-21 20:21:51 +00001684 case ISD::SETCC: {
1685 assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer");
Evan Cheng6dfa9992006-01-30 23:41:35 +00001686 SDOperand Cond;
1687 SDOperand CC = Op.getOperand(2);
Evan Chengd9558e02006-01-06 00:43:03 +00001688 ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get();
1689 bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType());
Evan Cheng6dfa9992006-01-30 23:41:35 +00001690 bool Flip;
1691 unsigned X86CC;
1692 if (translateX86CC(CC, isFP, X86CC, Flip)) {
1693 if (Flip)
1694 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1695 Op.getOperand(1), Op.getOperand(0));
1696 else
1697 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1698 Op.getOperand(0), Op.getOperand(1));
Evan Chengd9558e02006-01-06 00:43:03 +00001699 return DAG.getNode(X86ISD::SETCC, MVT::i8,
1700 DAG.getConstant(X86CC, MVT::i8), Cond);
1701 } else {
1702 assert(isFP && "Illegal integer SetCC!");
1703
Evan Cheng6dfa9992006-01-30 23:41:35 +00001704 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1705 Op.getOperand(0), Op.getOperand(1));
Evan Chengd9558e02006-01-06 00:43:03 +00001706 std::vector<MVT::ValueType> Tys;
1707 std::vector<SDOperand> Ops;
1708 switch (SetCCOpcode) {
1709 default: assert(false && "Illegal floating point SetCC!");
1710 case ISD::SETOEQ: { // !PF & ZF
1711 Tys.push_back(MVT::i8);
1712 Tys.push_back(MVT::Flag);
1713 Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8));
1714 Ops.push_back(Cond);
1715 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1716 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1717 DAG.getConstant(X86ISD::COND_E, MVT::i8),
1718 Tmp1.getValue(1));
1719 return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2);
1720 }
Evan Chengd9558e02006-01-06 00:43:03 +00001721 case ISD::SETUNE: { // PF | !ZF
1722 Tys.push_back(MVT::i8);
1723 Tys.push_back(MVT::Flag);
1724 Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8));
1725 Ops.push_back(Cond);
1726 SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1727 SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8,
1728 DAG.getConstant(X86ISD::COND_NE, MVT::i8),
1729 Tmp1.getValue(1));
1730 return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2);
1731 }
1732 }
1733 }
Evan Chengd5781fc2005-12-21 20:21:51 +00001734 }
Evan Cheng7df96d62005-12-17 01:21:05 +00001735 case ISD::SELECT: {
Evan Chengaaca22c2006-01-10 20:26:56 +00001736 MVT::ValueType VT = Op.getValueType();
1737 bool isFP = MVT::isFloatingPoint(VT);
Evan Cheng559806f2006-01-27 08:10:46 +00001738 bool isFPStack = isFP && !X86ScalarSSE;
1739 bool isFPSSE = isFP && X86ScalarSSE;
Evan Cheng1bcee362006-01-13 01:03:02 +00001740 bool addTest = false;
Evan Chengaaca22c2006-01-10 20:26:56 +00001741 SDOperand Op0 = Op.getOperand(0);
1742 SDOperand Cond, CC;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001743 if (Op0.getOpcode() == ISD::SETCC)
1744 Op0 = LowerOperation(Op0, DAG);
1745
Evan Chengaaca22c2006-01-10 20:26:56 +00001746 if (Op0.getOpcode() == X86ISD::SETCC) {
Evan Cheng1bcee362006-01-13 01:03:02 +00001747 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1748 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1749 // have another use it will be eliminated.
1750 // If the X86ISD::SETCC has more than one use, then it's probably better
1751 // to use a test instead of duplicating the X86ISD::CMP (for register
1752 // pressure reason).
Evan Cheng9bba8942006-01-26 02:13:10 +00001753 if (Op0.getOperand(1).getOpcode() == X86ISD::CMP) {
1754 if (!Op0.hasOneUse()) {
1755 std::vector<MVT::ValueType> Tys;
1756 for (unsigned i = 0; i < Op0.Val->getNumValues(); ++i)
1757 Tys.push_back(Op0.Val->getValueType(i));
1758 std::vector<SDOperand> Ops;
1759 for (unsigned i = 0; i < Op0.getNumOperands(); ++i)
1760 Ops.push_back(Op0.getOperand(i));
1761 Op0 = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1762 }
1763
Evan Cheng1bcee362006-01-13 01:03:02 +00001764 CC = Op0.getOperand(0);
1765 Cond = Op0.getOperand(1);
Evan Cheng0d718e92006-01-25 09:05:09 +00001766 // Make a copy as flag result cannot be used by more than one.
1767 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
1768 Cond.getOperand(0), Cond.getOperand(1));
Evan Cheng1bcee362006-01-13 01:03:02 +00001769 addTest =
Evan Cheng80ebe382006-01-13 01:17:24 +00001770 isFPStack && !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended());
Evan Cheng1bcee362006-01-13 01:03:02 +00001771 } else
1772 addTest = true;
Evan Cheng1bcee362006-01-13 01:03:02 +00001773 } else
1774 addTest = true;
Evan Chengaaca22c2006-01-10 20:26:56 +00001775
Evan Cheng189d01e2006-01-13 01:06:49 +00001776 if (addTest) {
Evan Chenge90da972006-01-13 19:51:46 +00001777 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Chengaaca22c2006-01-10 20:26:56 +00001778 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Op0, Op0);
Evan Cheng7df96d62005-12-17 01:21:05 +00001779 }
Evan Chenge3413162006-01-09 18:33:28 +00001780
1781 std::vector<MVT::ValueType> Tys;
1782 Tys.push_back(Op.getValueType());
1783 Tys.push_back(MVT::Flag);
1784 std::vector<SDOperand> Ops;
Evan Chenge90da972006-01-13 19:51:46 +00001785 // X86ISD::CMOV means set the result (which is operand 1) to the RHS if
1786 // condition is true.
Evan Chenge3413162006-01-09 18:33:28 +00001787 Ops.push_back(Op.getOperand(2));
Evan Chenge90da972006-01-13 19:51:46 +00001788 Ops.push_back(Op.getOperand(1));
Evan Chenge3413162006-01-09 18:33:28 +00001789 Ops.push_back(CC);
1790 Ops.push_back(Cond);
1791 return DAG.getNode(X86ISD::CMOV, Tys, Ops);
Evan Cheng7df96d62005-12-17 01:21:05 +00001792 }
Evan Cheng898101c2005-12-19 23:12:38 +00001793 case ISD::BRCOND: {
Evan Cheng1bcee362006-01-13 01:03:02 +00001794 bool addTest = false;
Evan Cheng898101c2005-12-19 23:12:38 +00001795 SDOperand Cond = Op.getOperand(1);
1796 SDOperand Dest = Op.getOperand(2);
1797 SDOperand CC;
Evan Cheng6dfa9992006-01-30 23:41:35 +00001798 if (Cond.getOpcode() == ISD::SETCC)
1799 Cond = LowerOperation(Cond, DAG);
1800
Evan Chengd5781fc2005-12-21 20:21:51 +00001801 if (Cond.getOpcode() == X86ISD::SETCC) {
Evan Cheng1bcee362006-01-13 01:03:02 +00001802 // If condition flag is set by a X86ISD::CMP, then make a copy of it
1803 // (since flag operand cannot be shared). If the X86ISD::SETCC does not
1804 // have another use it will be eliminated.
1805 // If the X86ISD::SETCC has more than one use, then it's probably better
1806 // to use a test instead of duplicating the X86ISD::CMP (for register
1807 // pressure reason).
Evan Cheng9bba8942006-01-26 02:13:10 +00001808 if (Cond.getOperand(1).getOpcode() == X86ISD::CMP) {
1809 if (!Cond.hasOneUse()) {
1810 std::vector<MVT::ValueType> Tys;
1811 for (unsigned i = 0; i < Cond.Val->getNumValues(); ++i)
1812 Tys.push_back(Cond.Val->getValueType(i));
1813 std::vector<SDOperand> Ops;
1814 for (unsigned i = 0; i < Cond.getNumOperands(); ++i)
1815 Ops.push_back(Cond.getOperand(i));
1816 Cond = DAG.getNode(X86ISD::SETCC, Tys, Ops);
1817 }
1818
Evan Cheng1bcee362006-01-13 01:03:02 +00001819 CC = Cond.getOperand(0);
Evan Cheng0d718e92006-01-25 09:05:09 +00001820 Cond = Cond.getOperand(1);
1821 // Make a copy as flag result cannot be used by more than one.
Evan Cheng1bcee362006-01-13 01:03:02 +00001822 Cond = DAG.getNode(X86ISD::CMP, MVT::Flag,
Evan Cheng0d718e92006-01-25 09:05:09 +00001823 Cond.getOperand(0), Cond.getOperand(1));
Evan Cheng1bcee362006-01-13 01:03:02 +00001824 } else
1825 addTest = true;
Evan Cheng1bcee362006-01-13 01:03:02 +00001826 } else
1827 addTest = true;
1828
1829 if (addTest) {
Evan Chengd9558e02006-01-06 00:43:03 +00001830 CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8);
Evan Cheng898101c2005-12-19 23:12:38 +00001831 Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Cond, Cond);
1832 }
1833 return DAG.getNode(X86ISD::BRCOND, Op.getValueType(),
1834 Op.getOperand(0), Op.getOperand(2), CC, Cond);
1835 }
Evan Cheng67f92a72006-01-11 22:15:48 +00001836 case ISD::MEMSET: {
Evan Cheng62bec2c2006-03-04 02:48:56 +00001837 SDOperand InFlag(0, 0);
Evan Cheng67f92a72006-01-11 22:15:48 +00001838 SDOperand Chain = Op.getOperand(0);
1839 unsigned Align =
1840 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1841 if (Align == 0) Align = 1;
1842
Evan Cheng18a84522006-02-16 00:21:07 +00001843 ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3));
1844 // If not DWORD aligned, call memset if size is less than the threshold.
1845 // It knows how to align to the right boundary first.
Evan Cheng62bec2c2006-03-04 02:48:56 +00001846 if ((Align & 3) != 0 ||
Evan Chengff909922006-03-07 23:29:39 +00001847 (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
Evan Cheng18a84522006-02-16 00:21:07 +00001848 MVT::ValueType IntPtr = getPointerTy();
1849 const Type *IntPtrTy = getTargetData().getIntPtrType();
1850 std::vector<std::pair<SDOperand, const Type*> > Args;
1851 Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
1852 // Extend the ubyte argument to be an int value for the call.
1853 SDOperand Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2));
1854 Args.push_back(std::make_pair(Val, IntPtrTy));
1855 Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy));
1856 std::pair<SDOperand,SDOperand> CallResult =
1857 LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false,
1858 DAG.getExternalSymbol("memset", IntPtr), Args, DAG);
1859 return CallResult.second;
1860 }
1861
Evan Cheng67f92a72006-01-11 22:15:48 +00001862 MVT::ValueType AVT;
1863 SDOperand Count;
Evan Cheng62bec2c2006-03-04 02:48:56 +00001864 ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2));
1865 unsigned BytesLeft = 0;
Evan Chengff909922006-03-07 23:29:39 +00001866 bool TwoRepStos = false;
Evan Cheng62bec2c2006-03-04 02:48:56 +00001867 if (ValC) {
Evan Cheng67f92a72006-01-11 22:15:48 +00001868 unsigned ValReg;
1869 unsigned Val = ValC->getValue() & 255;
1870
1871 // If the value is a constant, then we can potentially use larger sets.
1872 switch (Align & 3) {
1873 case 2: // WORD aligned
1874 AVT = MVT::i16;
Evan Cheng62bec2c2006-03-04 02:48:56 +00001875 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
1876 BytesLeft = I->getValue() % 2;
Evan Cheng67f92a72006-01-11 22:15:48 +00001877 Val = (Val << 8) | Val;
1878 ValReg = X86::AX;
1879 break;
1880 case 0: // DWORD aligned
1881 AVT = MVT::i32;
Evan Chengff909922006-03-07 23:29:39 +00001882 if (I) {
1883 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
1884 BytesLeft = I->getValue() % 4;
1885 } else {
1886 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
1887 DAG.getConstant(2, MVT::i8));
1888 TwoRepStos = true;
1889 }
Evan Cheng67f92a72006-01-11 22:15:48 +00001890 Val = (Val << 8) | Val;
1891 Val = (Val << 16) | Val;
1892 ValReg = X86::EAX;
1893 break;
1894 default: // Byte aligned
1895 AVT = MVT::i8;
1896 Count = Op.getOperand(3);
1897 ValReg = X86::AL;
1898 break;
1899 }
1900
1901 Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT),
1902 InFlag);
1903 InFlag = Chain.getValue(1);
1904 } else {
Evan Cheng18a84522006-02-16 00:21:07 +00001905 AVT = MVT::i8;
Evan Cheng67f92a72006-01-11 22:15:48 +00001906 Count = Op.getOperand(3);
1907 Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag);
1908 InFlag = Chain.getValue(1);
1909 }
1910
1911 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
1912 InFlag = Chain.getValue(1);
1913 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
1914 InFlag = Chain.getValue(1);
1915
Evan Chengff909922006-03-07 23:29:39 +00001916 std::vector<MVT::ValueType> Tys;
1917 Tys.push_back(MVT::Other);
1918 Tys.push_back(MVT::Flag);
1919 std::vector<SDOperand> Ops;
1920 Ops.push_back(Chain);
1921 Ops.push_back(DAG.getValueType(AVT));
1922 Ops.push_back(InFlag);
1923 Chain = DAG.getNode(X86ISD::REP_STOS, Tys, Ops);
1924
1925 if (TwoRepStos) {
1926 InFlag = Chain.getValue(1);
1927 Count = Op.getOperand(3);
1928 MVT::ValueType CVT = Count.getValueType();
1929 SDOperand Left = DAG.getNode(ISD::AND, CVT, Count,
1930 DAG.getConstant(3, CVT));
1931 Chain = DAG.getCopyToReg(Chain, X86::ECX, Left, InFlag);
1932 InFlag = Chain.getValue(1);
1933 Tys.clear();
1934 Tys.push_back(MVT::Other);
1935 Tys.push_back(MVT::Flag);
1936 Ops.clear();
1937 Ops.push_back(Chain);
1938 Ops.push_back(DAG.getValueType(MVT::i8));
1939 Ops.push_back(InFlag);
1940 Chain = DAG.getNode(X86ISD::REP_STOS, Tys, Ops);
1941 } else if (BytesLeft) {
Evan Cheng62bec2c2006-03-04 02:48:56 +00001942 // Issue stores for the last 1 - 3 bytes.
1943 SDOperand Value;
1944 unsigned Val = ValC->getValue() & 255;
1945 unsigned Offset = I->getValue() - BytesLeft;
1946 SDOperand DstAddr = Op.getOperand(1);
1947 MVT::ValueType AddrVT = DstAddr.getValueType();
1948 if (BytesLeft >= 2) {
1949 Value = DAG.getConstant((Val << 8) | Val, MVT::i16);
1950 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value,
1951 DAG.getNode(ISD::ADD, AddrVT, DstAddr,
1952 DAG.getConstant(Offset, AddrVT)),
1953 DAG.getSrcValue(NULL));
1954 BytesLeft -= 2;
1955 Offset += 2;
1956 }
1957
1958 if (BytesLeft == 1) {
1959 Value = DAG.getConstant(Val, MVT::i8);
1960 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value,
1961 DAG.getNode(ISD::ADD, AddrVT, DstAddr,
1962 DAG.getConstant(Offset, AddrVT)),
1963 DAG.getSrcValue(NULL));
1964 }
1965 }
1966
1967 return Chain;
Evan Cheng67f92a72006-01-11 22:15:48 +00001968 }
1969 case ISD::MEMCPY: {
1970 SDOperand Chain = Op.getOperand(0);
1971 unsigned Align =
1972 (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue();
1973 if (Align == 0) Align = 1;
1974
Evan Cheng18a84522006-02-16 00:21:07 +00001975 ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3));
1976 // If not DWORD aligned, call memcpy if size is less than the threshold.
1977 // It knows how to align to the right boundary first.
Evan Cheng62bec2c2006-03-04 02:48:56 +00001978 if ((Align & 3) != 0 ||
Evan Chengff909922006-03-07 23:29:39 +00001979 (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) {
Evan Cheng18a84522006-02-16 00:21:07 +00001980 MVT::ValueType IntPtr = getPointerTy();
1981 const Type *IntPtrTy = getTargetData().getIntPtrType();
1982 std::vector<std::pair<SDOperand, const Type*> > Args;
1983 Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy));
1984 Args.push_back(std::make_pair(Op.getOperand(2), IntPtrTy));
1985 Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy));
1986 std::pair<SDOperand,SDOperand> CallResult =
1987 LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false,
1988 DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG);
1989 return CallResult.second;
1990 }
1991
Evan Cheng67f92a72006-01-11 22:15:48 +00001992 MVT::ValueType AVT;
1993 SDOperand Count;
Evan Cheng62bec2c2006-03-04 02:48:56 +00001994 unsigned BytesLeft = 0;
Evan Chengff909922006-03-07 23:29:39 +00001995 bool TwoRepMovs = false;
Evan Cheng67f92a72006-01-11 22:15:48 +00001996 switch (Align & 3) {
1997 case 2: // WORD aligned
1998 AVT = MVT::i16;
Evan Cheng62bec2c2006-03-04 02:48:56 +00001999 Count = DAG.getConstant(I->getValue() / 2, MVT::i32);
2000 BytesLeft = I->getValue() % 2;
Evan Cheng67f92a72006-01-11 22:15:48 +00002001 break;
2002 case 0: // DWORD aligned
2003 AVT = MVT::i32;
Evan Chengff909922006-03-07 23:29:39 +00002004 if (I) {
2005 Count = DAG.getConstant(I->getValue() / 4, MVT::i32);
2006 BytesLeft = I->getValue() % 4;
2007 } else {
2008 Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3),
2009 DAG.getConstant(2, MVT::i8));
2010 TwoRepMovs = true;
2011 }
Evan Cheng67f92a72006-01-11 22:15:48 +00002012 break;
2013 default: // Byte aligned
2014 AVT = MVT::i8;
2015 Count = Op.getOperand(3);
2016 break;
2017 }
2018
Evan Cheng62bec2c2006-03-04 02:48:56 +00002019 SDOperand InFlag(0, 0);
Evan Cheng67f92a72006-01-11 22:15:48 +00002020 Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag);
2021 InFlag = Chain.getValue(1);
2022 Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag);
2023 InFlag = Chain.getValue(1);
2024 Chain = DAG.getCopyToReg(Chain, X86::ESI, Op.getOperand(2), InFlag);
2025 InFlag = Chain.getValue(1);
2026
Evan Chengff909922006-03-07 23:29:39 +00002027 std::vector<MVT::ValueType> Tys;
2028 Tys.push_back(MVT::Other);
2029 Tys.push_back(MVT::Flag);
2030 std::vector<SDOperand> Ops;
2031 Ops.push_back(Chain);
2032 Ops.push_back(DAG.getValueType(AVT));
2033 Ops.push_back(InFlag);
2034 Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, Ops);
2035
2036 if (TwoRepMovs) {
2037 InFlag = Chain.getValue(1);
2038 Count = Op.getOperand(3);
2039 MVT::ValueType CVT = Count.getValueType();
2040 SDOperand Left = DAG.getNode(ISD::AND, CVT, Count,
2041 DAG.getConstant(3, CVT));
2042 Chain = DAG.getCopyToReg(Chain, X86::ECX, Left, InFlag);
2043 InFlag = Chain.getValue(1);
2044 Tys.clear();
2045 Tys.push_back(MVT::Other);
2046 Tys.push_back(MVT::Flag);
2047 Ops.clear();
2048 Ops.push_back(Chain);
2049 Ops.push_back(DAG.getValueType(MVT::i8));
2050 Ops.push_back(InFlag);
2051 Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, Ops);
2052 } else if (BytesLeft) {
Evan Cheng62bec2c2006-03-04 02:48:56 +00002053 // Issue loads and stores for the last 1 - 3 bytes.
2054 unsigned Offset = I->getValue() - BytesLeft;
2055 SDOperand DstAddr = Op.getOperand(1);
2056 MVT::ValueType DstVT = DstAddr.getValueType();
2057 SDOperand SrcAddr = Op.getOperand(2);
2058 MVT::ValueType SrcVT = SrcAddr.getValueType();
2059 SDOperand Value;
2060 if (BytesLeft >= 2) {
2061 Value = DAG.getLoad(MVT::i16, Chain,
2062 DAG.getNode(ISD::ADD, SrcVT, SrcAddr,
2063 DAG.getConstant(Offset, SrcVT)),
2064 DAG.getSrcValue(NULL));
2065 Chain = Value.getValue(1);
2066 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value,
2067 DAG.getNode(ISD::ADD, DstVT, DstAddr,
2068 DAG.getConstant(Offset, DstVT)),
2069 DAG.getSrcValue(NULL));
2070 BytesLeft -= 2;
2071 Offset += 2;
2072 }
2073
2074 if (BytesLeft == 1) {
2075 Value = DAG.getLoad(MVT::i8, Chain,
2076 DAG.getNode(ISD::ADD, SrcVT, SrcAddr,
2077 DAG.getConstant(Offset, SrcVT)),
2078 DAG.getSrcValue(NULL));
2079 Chain = Value.getValue(1);
2080 Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value,
2081 DAG.getNode(ISD::ADD, DstVT, DstAddr,
2082 DAG.getConstant(Offset, DstVT)),
2083 DAG.getSrcValue(NULL));
2084 }
2085 }
2086
2087 return Chain;
Evan Cheng67f92a72006-01-11 22:15:48 +00002088 }
Evan Chengbbbb2fb2006-02-25 09:55:19 +00002089
2090 // ConstantPool, GlobalAddress, and ExternalSymbol are lowered as their
2091 // target countpart wrapped in the X86ISD::Wrapper node. Suppose N is
2092 // one of the above mentioned nodes. It has to be wrapped because otherwise
2093 // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only
2094 // be used to form addressing mode. These wrapped nodes will be selected
2095 // into MOV32ri.
Evan Cheng7ccced62006-02-18 00:15:05 +00002096 case ISD::ConstantPool: {
2097 ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op);
Evan Cheng020d2e82006-02-23 20:41:18 +00002098 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
2099 DAG.getTargetConstantPool(CP->get(), getPointerTy(),
2100 CP->getAlignment()));
Evan Chenga88973f2006-03-22 19:22:18 +00002101 if (Subtarget->isTargetDarwin()) {
Evan Cheng7ccced62006-02-18 00:15:05 +00002102 // With PIC, the address is actually $g + Offset.
Evan Cheng4c1aa862006-02-22 20:19:42 +00002103 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
Evan Cheng7ccced62006-02-18 00:15:05 +00002104 Result = DAG.getNode(ISD::ADD, getPointerTy(),
2105 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
2106 }
2107
2108 return Result;
2109 }
Evan Cheng38bcbaf2005-12-23 07:31:11 +00002110 case ISD::GlobalAddress: {
Evan Cheng020d2e82006-02-23 20:41:18 +00002111 GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal();
2112 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
2113 DAG.getTargetGlobalAddress(GV, getPointerTy()));
Evan Chenga88973f2006-03-22 19:22:18 +00002114 if (Subtarget->isTargetDarwin()) {
Evan Cheng7ccced62006-02-18 00:15:05 +00002115 // With PIC, the address is actually $g + Offset.
Evan Cheng4c1aa862006-02-22 20:19:42 +00002116 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
Evan Chenga0ea0532006-02-23 02:43:52 +00002117 Result = DAG.getNode(ISD::ADD, getPointerTy(),
2118 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
Evan Cheng7ccced62006-02-18 00:15:05 +00002119
2120 // For Darwin, external and weak symbols are indirect, so we want to load
Evan Cheng30b37b52006-03-13 23:18:16 +00002121 // the value at address GV, not the value of GV itself. This means that
Evan Cheng7ccced62006-02-18 00:15:05 +00002122 // the GlobalAddress must be in the base or index register of the address,
2123 // not the GV offset field.
Evan Cheng4c1aa862006-02-22 20:19:42 +00002124 if (getTargetMachine().getRelocationModel() != Reloc::Static &&
Evan Cheng30b37b52006-03-13 23:18:16 +00002125 DarwinGVRequiresExtraLoad(GV))
Evan Cheng2338c5c2006-02-07 08:38:37 +00002126 Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(),
Evan Chenga0ea0532006-02-23 02:43:52 +00002127 Result, DAG.getSrcValue(NULL));
Evan Cheng2338c5c2006-02-07 08:38:37 +00002128 }
Evan Cheng7ccced62006-02-18 00:15:05 +00002129
Evan Cheng002fe9b2006-01-12 07:56:47 +00002130 return Result;
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00002131 }
Evan Cheng020d2e82006-02-23 20:41:18 +00002132 case ISD::ExternalSymbol: {
2133 const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol();
2134 SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(),
2135 DAG.getTargetExternalSymbol(Sym, getPointerTy()));
Evan Chenga88973f2006-03-22 19:22:18 +00002136 if (Subtarget->isTargetDarwin()) {
Evan Cheng020d2e82006-02-23 20:41:18 +00002137 // With PIC, the address is actually $g + Offset.
2138 if (getTargetMachine().getRelocationModel() == Reloc::PIC)
2139 Result = DAG.getNode(ISD::ADD, getPointerTy(),
2140 DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result);
2141 }
2142
2143 return Result;
2144 }
Nate Begemanacc398c2006-01-25 18:21:52 +00002145 case ISD::VASTART: {
2146 // vastart just stores the address of the VarArgsFrameIndex slot into the
2147 // memory location argument.
2148 // FIXME: Replace MVT::i32 with PointerTy
2149 SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32);
2150 return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR,
2151 Op.getOperand(1), Op.getOperand(2));
2152 }
Nate Begemanee625572006-01-27 21:09:22 +00002153 case ISD::RET: {
2154 SDOperand Copy;
2155
2156 switch(Op.getNumOperands()) {
2157 default:
2158 assert(0 && "Do not know how to return this many arguments!");
2159 abort();
2160 case 1:
2161 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Op.getOperand(0),
2162 DAG.getConstant(getBytesToPopOnReturn(), MVT::i16));
2163 case 2: {
2164 MVT::ValueType ArgVT = Op.getOperand(1).getValueType();
2165 if (MVT::isInteger(ArgVT))
2166 Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EAX, Op.getOperand(1),
2167 SDOperand());
2168 else if (!X86ScalarSSE) {
2169 std::vector<MVT::ValueType> Tys;
2170 Tys.push_back(MVT::Other);
2171 Tys.push_back(MVT::Flag);
2172 std::vector<SDOperand> Ops;
2173 Ops.push_back(Op.getOperand(0));
2174 Ops.push_back(Op.getOperand(1));
2175 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
2176 } else {
Evan Cheng0d084c92006-02-01 00:20:21 +00002177 SDOperand MemLoc;
2178 SDOperand Chain = Op.getOperand(0);
Evan Cheng0e8671b2006-01-31 23:19:54 +00002179 SDOperand Value = Op.getOperand(1);
2180
Evan Cheng760df292006-02-01 01:19:32 +00002181 if (Value.getOpcode() == ISD::LOAD &&
2182 (Chain == Value.getValue(1) || Chain == Value.getOperand(0))) {
Evan Cheng0e8671b2006-01-31 23:19:54 +00002183 Chain = Value.getOperand(0);
2184 MemLoc = Value.getOperand(1);
2185 } else {
2186 // Spill the value to memory and reload it into top of stack.
2187 unsigned Size = MVT::getSizeInBits(ArgVT)/8;
2188 MachineFunction &MF = DAG.getMachineFunction();
2189 int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size);
2190 MemLoc = DAG.getFrameIndex(SSFI, getPointerTy());
2191 Chain = DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0),
2192 Value, MemLoc, DAG.getSrcValue(0));
2193 }
Nate Begemanee625572006-01-27 21:09:22 +00002194 std::vector<MVT::ValueType> Tys;
2195 Tys.push_back(MVT::f64);
2196 Tys.push_back(MVT::Other);
2197 std::vector<SDOperand> Ops;
2198 Ops.push_back(Chain);
Evan Cheng0e8671b2006-01-31 23:19:54 +00002199 Ops.push_back(MemLoc);
Nate Begemanee625572006-01-27 21:09:22 +00002200 Ops.push_back(DAG.getValueType(ArgVT));
2201 Copy = DAG.getNode(X86ISD::FLD, Tys, Ops);
2202 Tys.clear();
2203 Tys.push_back(MVT::Other);
2204 Tys.push_back(MVT::Flag);
2205 Ops.clear();
2206 Ops.push_back(Copy.getValue(1));
2207 Ops.push_back(Copy);
2208 Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops);
2209 }
2210 break;
2211 }
2212 case 3:
2213 Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EDX, Op.getOperand(2),
2214 SDOperand());
2215 Copy = DAG.getCopyToReg(Copy, X86::EAX,Op.getOperand(1),Copy.getValue(1));
2216 break;
2217 }
2218 return DAG.getNode(X86ISD::RET_FLAG, MVT::Other,
2219 Copy, DAG.getConstant(getBytesToPopOnReturn(), MVT::i16),
2220 Copy.getValue(1));
2221 }
Evan Cheng48090aa2006-03-21 23:01:21 +00002222 case ISD::SCALAR_TO_VECTOR: {
2223 SDOperand AnyExt = DAG.getNode(ISD::ANY_EXTEND, MVT::i32, Op.getOperand(0));
2224 return DAG.getNode(X86ISD::SCALAR_TO_VECTOR, Op.getValueType(), AnyExt);
2225 }
Evan Chengb9df0ca2006-03-22 02:53:00 +00002226 case ISD::VECTOR_SHUFFLE: {
2227 SDOperand V1 = Op.getOperand(0);
2228 SDOperand V2 = Op.getOperand(1);
2229 SDOperand PermMask = Op.getOperand(2);
2230 MVT::ValueType VT = Op.getValueType();
2231
Evan Cheng0188ecb2006-03-22 18:59:22 +00002232 // Handle splat cases.
2233 if (X86::isSplatMask(PermMask.Val)) {
2234 if (V2.getOpcode() == ISD::UNDEF)
Evan Chengb9df0ca2006-03-22 02:53:00 +00002235 // Leave the VECTOR_SHUFFLE alone. It matches SHUFP*.
Chris Lattner6df11542006-03-22 04:18:34 +00002236 return SDOperand();
Evan Cheng0188ecb2006-03-22 18:59:22 +00002237 else
2238 // Make it match SHUFP* or UNPCKLPD. Second vector is undef since it's
2239 // not needed.
2240 return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1,
2241 DAG.getNode(ISD::UNDEF, V1.getValueType()),
2242 PermMask);
Evan Cheng1bffadd2006-03-22 19:16:21 +00002243 } else if (Subtarget->hasSSE2() && X86::isPSHUFDMask(PermMask.Val)) {
Evan Cheng0188ecb2006-03-22 18:59:22 +00002244 if (V2.getOpcode() == ISD::UNDEF)
Evan Chengb9df0ca2006-03-22 02:53:00 +00002245 // Leave the VECTOR_SHUFFLE alone. It matches PSHUFD.
Chris Lattner6df11542006-03-22 04:18:34 +00002246 return SDOperand();
Evan Cheng0188ecb2006-03-22 18:59:22 +00002247 else
2248 // Make it match PSHUFD. Second vector is undef since it's not needed.
2249 return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1,
2250 DAG.getNode(ISD::UNDEF, V1.getValueType()),
2251 PermMask);
Evan Chengb9df0ca2006-03-22 02:53:00 +00002252 }
2253
2254 // TODO.
Chris Lattner6df11542006-03-22 04:18:34 +00002255 assert(0 && "TODO");
2256 abort();
Evan Chengb9df0ca2006-03-22 02:53:00 +00002257 }
Evan Cheng38bcbaf2005-12-23 07:31:11 +00002258 }
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00002259}
Evan Cheng72261582005-12-20 06:22:03 +00002260
2261const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const {
2262 switch (Opcode) {
2263 default: return NULL;
Evan Chenge3413162006-01-09 18:33:28 +00002264 case X86ISD::SHLD: return "X86ISD::SHLD";
2265 case X86ISD::SHRD: return "X86ISD::SHRD";
Evan Chengef6ffb12006-01-31 03:14:29 +00002266 case X86ISD::FAND: return "X86ISD::FAND";
Evan Cheng223547a2006-01-31 22:28:30 +00002267 case X86ISD::FXOR: return "X86ISD::FXOR";
Evan Chenga3195e82006-01-12 22:54:21 +00002268 case X86ISD::FILD: return "X86ISD::FILD";
Evan Chenge3de85b2006-02-04 02:20:30 +00002269 case X86ISD::FILD_FLAG: return "X86ISD::FILD_FLAG";
Evan Cheng72261582005-12-20 06:22:03 +00002270 case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM";
2271 case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM";
2272 case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM";
Evan Chengb077b842005-12-21 02:39:21 +00002273 case X86ISD::FLD: return "X86ISD::FLD";
Evan Chengd90eb7f2006-01-05 00:27:02 +00002274 case X86ISD::FST: return "X86ISD::FST";
2275 case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT";
Evan Chengb077b842005-12-21 02:39:21 +00002276 case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT";
Evan Cheng72261582005-12-20 06:22:03 +00002277 case X86ISD::CALL: return "X86ISD::CALL";
2278 case X86ISD::TAILCALL: return "X86ISD::TAILCALL";
2279 case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG";
2280 case X86ISD::CMP: return "X86ISD::CMP";
2281 case X86ISD::TEST: return "X86ISD::TEST";
Evan Chengd5781fc2005-12-21 20:21:51 +00002282 case X86ISD::SETCC: return "X86ISD::SETCC";
Evan Cheng72261582005-12-20 06:22:03 +00002283 case X86ISD::CMOV: return "X86ISD::CMOV";
2284 case X86ISD::BRCOND: return "X86ISD::BRCOND";
Evan Chengb077b842005-12-21 02:39:21 +00002285 case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG";
Evan Cheng8df346b2006-03-04 01:12:00 +00002286 case X86ISD::REP_STOS: return "X86ISD::REP_STOS";
2287 case X86ISD::REP_MOVS: return "X86ISD::REP_MOVS";
Evan Cheng223547a2006-01-31 22:28:30 +00002288 case X86ISD::LOAD_PACK: return "X86ISD::LOAD_PACK";
Evan Cheng7ccced62006-02-18 00:15:05 +00002289 case X86ISD::GlobalBaseReg: return "X86ISD::GlobalBaseReg";
Evan Cheng020d2e82006-02-23 20:41:18 +00002290 case X86ISD::Wrapper: return "X86ISD::Wrapper";
Evan Cheng48090aa2006-03-21 23:01:21 +00002291 case X86ISD::SCALAR_TO_VECTOR: return "X86ISD::SCALAR_TO_VECTOR";
Evan Cheng72261582005-12-20 06:22:03 +00002292 }
2293}
Evan Cheng3a03ebb2005-12-21 23:05:39 +00002294
Nate Begeman368e18d2006-02-16 21:11:51 +00002295void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op,
2296 uint64_t Mask,
2297 uint64_t &KnownZero,
2298 uint64_t &KnownOne,
2299 unsigned Depth) const {
Evan Cheng3a03ebb2005-12-21 23:05:39 +00002300
2301 unsigned Opc = Op.getOpcode();
Nate Begeman368e18d2006-02-16 21:11:51 +00002302 KnownZero = KnownOne = 0; // Don't know anything.
Evan Cheng3a03ebb2005-12-21 23:05:39 +00002303
2304 switch (Opc) {
2305 default:
2306 assert(Opc >= ISD::BUILTIN_OP_END && "Expected a target specific node");
2307 break;
Nate Begeman368e18d2006-02-16 21:11:51 +00002308 case X86ISD::SETCC:
2309 KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL);
2310 break;
Evan Cheng3a03ebb2005-12-21 23:05:39 +00002311 }
Evan Cheng3a03ebb2005-12-21 23:05:39 +00002312}
Chris Lattner259e97c2006-01-31 19:43:35 +00002313
2314std::vector<unsigned> X86TargetLowering::
Chris Lattner1efa40f2006-02-22 00:56:39 +00002315getRegClassForInlineAsmConstraint(const std::string &Constraint,
2316 MVT::ValueType VT) const {
Chris Lattner259e97c2006-01-31 19:43:35 +00002317 if (Constraint.size() == 1) {
2318 // FIXME: not handling fp-stack yet!
2319 // FIXME: not handling MMX registers yet ('y' constraint).
2320 switch (Constraint[0]) { // GCC X86 Constraint Letters
2321 default: break; // Unknown constriant letter
2322 case 'r': // GENERAL_REGS
2323 case 'R': // LEGACY_REGS
2324 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX,
2325 X86::ESI, X86::EDI, X86::EBP, X86::ESP, 0);
2326 case 'l': // INDEX_REGS
2327 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX,
2328 X86::ESI, X86::EDI, X86::EBP, 0);
2329 case 'q': // Q_REGS (GENERAL_REGS in 64-bit mode)
2330 case 'Q': // Q_REGS
2331 return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX, 0);
2332 case 'x': // SSE_REGS if SSE1 allowed
2333 if (Subtarget->hasSSE1())
2334 return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
2335 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7,
2336 0);
2337 return std::vector<unsigned>();
2338 case 'Y': // SSE_REGS if SSE2 allowed
2339 if (Subtarget->hasSSE2())
2340 return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3,
2341 X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7,
2342 0);
2343 return std::vector<unsigned>();
2344 }
2345 }
2346
Chris Lattner1efa40f2006-02-22 00:56:39 +00002347 return std::vector<unsigned>();
Chris Lattner259e97c2006-01-31 19:43:35 +00002348}
Evan Cheng30b37b52006-03-13 23:18:16 +00002349
2350/// isLegalAddressImmediate - Return true if the integer value or
2351/// GlobalValue can be used as the offset of the target addressing mode.
2352bool X86TargetLowering::isLegalAddressImmediate(int64_t V) const {
2353 // X86 allows a sign-extended 32-bit immediate field.
2354 return (V > -(1LL << 32) && V < (1LL << 32)-1);
2355}
2356
2357bool X86TargetLowering::isLegalAddressImmediate(GlobalValue *GV) const {
Evan Chenga88973f2006-03-22 19:22:18 +00002358 if (Subtarget->isTargetDarwin()) {
Evan Cheng30b37b52006-03-13 23:18:16 +00002359 Reloc::Model RModel = getTargetMachine().getRelocationModel();
2360 if (RModel == Reloc::Static)
2361 return true;
2362 else if (RModel == Reloc::DynamicNoPIC)
Evan Cheng2221de92006-03-16 22:02:48 +00002363 return !DarwinGVRequiresExtraLoad(GV);
Evan Cheng30b37b52006-03-13 23:18:16 +00002364 else
2365 return false;
2366 } else
2367 return true;
2368}
Evan Cheng0188ecb2006-03-22 18:59:22 +00002369
2370/// isShuffleMaskLegal - Targets can use this to indicate that they only
2371/// support *some* VECTOR_SHUFFLE operations, those with specific masks.
2372/// By default, if a target supports the VECTOR_SHUFFLE node, all mask values
2373/// are assumed to be legal.
Evan Chengca6e8ea2006-03-22 22:07:06 +00002374bool
2375X86TargetLowering::isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const {
2376 // Only do shuffles on 128-bit vector types for now.
2377 if (MVT::getSizeInBits(VT) == 64) return false;
Evan Cheng1bffadd2006-03-22 19:16:21 +00002378 return (X86::isSplatMask(Mask.Val) ||
2379 (Subtarget->hasSSE2() && X86::isPSHUFDMask(Mask.Val)));
Evan Cheng0188ecb2006-03-22 18:59:22 +00002380}