Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1 | //===-- 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 Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 16 | #include "X86InstrBuilder.h" |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 17 | #include "X86ISelLowering.h" |
| 18 | #include "X86TargetMachine.h" |
| 19 | #include "llvm/CallingConv.h" |
Evan Cheng | 72d5c25 | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 20 | #include "llvm/Constants.h" |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 21 | #include "llvm/Function.h" |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 22 | #include "llvm/Intrinsics.h" |
Evan Cheng | af598d2 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/VectorExtras.h" |
| 24 | #include "llvm/Analysis/ScalarEvolutionExpressions.h" |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 25 | #include "llvm/CodeGen/MachineFrameInfo.h" |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/MachineFunction.h" |
| 27 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/SelectionDAG.h" |
| 29 | #include "llvm/CodeGen/SSARegMap.h" |
Evan Cheng | 2dd217b | 2006-01-31 03:14:29 +0000 | [diff] [blame] | 30 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 31 | #include "llvm/Target/TargetOptions.h" |
| 32 | using namespace llvm; |
| 33 | |
| 34 | // FIXME: temporary. |
| 35 | #include "llvm/Support/CommandLine.h" |
| 36 | static cl::opt<bool> EnableFastCC("enable-x86-fastcc", cl::Hidden, |
| 37 | cl::desc("Enable fastcc on X86")); |
| 38 | |
| 39 | X86TargetLowering::X86TargetLowering(TargetMachine &TM) |
| 40 | : TargetLowering(TM) { |
Evan Cheng | cde9e30 | 2006-01-27 08:10:46 +0000 | [diff] [blame] | 41 | Subtarget = &TM.getSubtarget<X86Subtarget>(); |
| 42 | X86ScalarSSE = Subtarget->hasSSE2(); |
| 43 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 44 | // Set up the TargetLowering object. |
| 45 | |
| 46 | // X86 is weird, it always uses i8 for shift amounts and setcc results. |
| 47 | setShiftAmountType(MVT::i8); |
| 48 | setSetCCResultType(MVT::i8); |
| 49 | setSetCCResultContents(ZeroOrOneSetCCResult); |
Evan Cheng | 83eeefb | 2006-01-25 09:15:17 +0000 | [diff] [blame] | 50 | setSchedulingPreference(SchedulingForRegPressure); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 51 | setShiftAmountFlavor(Mask); // shl X, 32 == shl X, 0 |
Chris Lattner | 1a8d918 | 2006-01-13 18:00:54 +0000 | [diff] [blame] | 52 | setStackPointerRegisterToSaveRestore(X86::ESP); |
Evan Cheng | 20931a7 | 2006-03-16 21:47:42 +0000 | [diff] [blame] | 53 | |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 54 | if (!Subtarget->isTargetDarwin()) |
Evan Cheng | b09a56f | 2006-03-17 20:31:41 +0000 | [diff] [blame] | 55 | // Darwin should use _setjmp/_longjmp instead of setjmp/longjmp. |
| 56 | setUseUnderscoreSetJmpLongJmp(true); |
| 57 | |
Evan Cheng | 20931a7 | 2006-03-16 21:47:42 +0000 | [diff] [blame] | 58 | // Add legal addressing mode scale values. |
| 59 | addLegalAddressScale(8); |
| 60 | addLegalAddressScale(4); |
| 61 | addLegalAddressScale(2); |
| 62 | // Enter the ones which require both scale + index last. These are more |
| 63 | // expensive. |
| 64 | addLegalAddressScale(9); |
| 65 | addLegalAddressScale(5); |
| 66 | addLegalAddressScale(3); |
Chris Lattner | 61c9a8e | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 67 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 68 | // Set up the register classes. |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 69 | addRegisterClass(MVT::i8, X86::R8RegisterClass); |
| 70 | addRegisterClass(MVT::i16, X86::R16RegisterClass); |
| 71 | addRegisterClass(MVT::i32, X86::R32RegisterClass); |
| 72 | |
| 73 | // Promote all UINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have this |
| 74 | // operation. |
| 75 | setOperationAction(ISD::UINT_TO_FP , MVT::i1 , Promote); |
| 76 | setOperationAction(ISD::UINT_TO_FP , MVT::i8 , Promote); |
| 77 | setOperationAction(ISD::UINT_TO_FP , MVT::i16 , Promote); |
Evan Cheng | 0d5b69f | 2006-01-17 02:32:49 +0000 | [diff] [blame] | 78 | |
| 79 | if (X86ScalarSSE) |
| 80 | // No SSE i64 SINT_TO_FP, so expand i32 UINT_TO_FP instead. |
| 81 | setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Expand); |
| 82 | else |
| 83 | setOperationAction(ISD::UINT_TO_FP , MVT::i32 , Promote); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 84 | |
| 85 | // Promote i1/i8 SINT_TO_FP to larger SINT_TO_FP's, as X86 doesn't have |
| 86 | // this operation. |
| 87 | setOperationAction(ISD::SINT_TO_FP , MVT::i1 , Promote); |
| 88 | setOperationAction(ISD::SINT_TO_FP , MVT::i8 , Promote); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 89 | // SSE has no i16 to fp conversion, only i32 |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 90 | if (X86ScalarSSE) |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 91 | setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Promote); |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 92 | else { |
| 93 | setOperationAction(ISD::SINT_TO_FP , MVT::i16 , Custom); |
| 94 | setOperationAction(ISD::SINT_TO_FP , MVT::i32 , Custom); |
| 95 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 96 | |
Evan Cheng | 5b97fcf | 2006-01-30 08:02:57 +0000 | [diff] [blame] | 97 | // We can handle SINT_TO_FP and FP_TO_SINT from/to i64 even though i64 |
| 98 | // isn't legal. |
| 99 | setOperationAction(ISD::SINT_TO_FP , MVT::i64 , Custom); |
| 100 | setOperationAction(ISD::FP_TO_SINT , MVT::i64 , Custom); |
| 101 | |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 102 | // Promote i1/i8 FP_TO_SINT to larger FP_TO_SINTS's, as X86 doesn't have |
| 103 | // this operation. |
| 104 | setOperationAction(ISD::FP_TO_SINT , MVT::i1 , Promote); |
| 105 | setOperationAction(ISD::FP_TO_SINT , MVT::i8 , Promote); |
| 106 | |
| 107 | if (X86ScalarSSE) { |
| 108 | setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Promote); |
| 109 | } else { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::FP_TO_SINT , MVT::i16 , Custom); |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 111 | setOperationAction(ISD::FP_TO_SINT , MVT::i32 , Custom); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | // Handle FP_TO_UINT by promoting the destination to a larger signed |
| 115 | // conversion. |
| 116 | setOperationAction(ISD::FP_TO_UINT , MVT::i1 , Promote); |
| 117 | setOperationAction(ISD::FP_TO_UINT , MVT::i8 , Promote); |
| 118 | setOperationAction(ISD::FP_TO_UINT , MVT::i16 , Promote); |
| 119 | |
Evan Cheng | d13778e | 2006-02-18 07:26:17 +0000 | [diff] [blame] | 120 | if (X86ScalarSSE && !Subtarget->hasSSE3()) |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 121 | // Expand FP_TO_UINT into a select. |
| 122 | // FIXME: We would like to use a Custom expander here eventually to do |
| 123 | // the optimal thing for SSE vs. the default expansion in the legalizer. |
| 124 | setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Expand); |
| 125 | else |
Evan Cheng | d13778e | 2006-02-18 07:26:17 +0000 | [diff] [blame] | 126 | // With SSE3 we can use fisttpll to convert to a signed i64. |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::FP_TO_UINT , MVT::i32 , Promote); |
| 128 | |
Evan Cheng | 08390f6 | 2006-01-30 22:13:22 +0000 | [diff] [blame] | 129 | setOperationAction(ISD::BIT_CONVERT , MVT::f32 , Expand); |
| 130 | setOperationAction(ISD::BIT_CONVERT , MVT::i32 , Expand); |
Chris Lattner | 30107e6 | 2005-12-23 05:15:23 +0000 | [diff] [blame] | 131 | |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 132 | setOperationAction(ISD::BRCOND , MVT::Other, Custom); |
Nate Begeman | 7e7f439 | 2006-02-01 07:19:44 +0000 | [diff] [blame] | 133 | setOperationAction(ISD::BR_CC , MVT::Other, Expand); |
| 134 | setOperationAction(ISD::SELECT_CC , MVT::Other, Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 135 | setOperationAction(ISD::MEMMOVE , MVT::Other, Expand); |
| 136 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16 , Expand); |
Chris Lattner | 3225733 | 2005-12-07 17:59:14 +0000 | [diff] [blame] | 137 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8 , Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 138 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1 , Expand); |
| 139 | setOperationAction(ISD::FP_ROUND_INREG , MVT::f32 , Expand); |
| 140 | setOperationAction(ISD::SEXTLOAD , MVT::i1 , Expand); |
| 141 | setOperationAction(ISD::FREM , MVT::f64 , Expand); |
| 142 | setOperationAction(ISD::CTPOP , MVT::i8 , Expand); |
| 143 | setOperationAction(ISD::CTTZ , MVT::i8 , Expand); |
| 144 | setOperationAction(ISD::CTLZ , MVT::i8 , Expand); |
| 145 | setOperationAction(ISD::CTPOP , MVT::i16 , Expand); |
| 146 | setOperationAction(ISD::CTTZ , MVT::i16 , Expand); |
| 147 | setOperationAction(ISD::CTLZ , MVT::i16 , Expand); |
| 148 | setOperationAction(ISD::CTPOP , MVT::i32 , Expand); |
| 149 | setOperationAction(ISD::CTTZ , MVT::i32 , Expand); |
| 150 | setOperationAction(ISD::CTLZ , MVT::i32 , Expand); |
Andrew Lenharth | 0bf68ae | 2005-11-20 21:41:10 +0000 | [diff] [blame] | 151 | setOperationAction(ISD::READCYCLECOUNTER , MVT::i64 , Custom); |
Nate Begeman | 2fba8a3 | 2006-01-14 03:14:10 +0000 | [diff] [blame] | 152 | setOperationAction(ISD::BSWAP , MVT::i16 , Expand); |
Nate Begeman | 1b8121b | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 153 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 154 | // These should be promoted to a larger select which is supported. |
| 155 | setOperationAction(ISD::SELECT , MVT::i1 , Promote); |
| 156 | setOperationAction(ISD::SELECT , MVT::i8 , Promote); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 157 | |
| 158 | // X86 wants to expand cmov itself. |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 159 | setOperationAction(ISD::SELECT , MVT::i16 , Custom); |
| 160 | setOperationAction(ISD::SELECT , MVT::i32 , Custom); |
| 161 | setOperationAction(ISD::SELECT , MVT::f32 , Custom); |
| 162 | setOperationAction(ISD::SELECT , MVT::f64 , Custom); |
| 163 | setOperationAction(ISD::SETCC , MVT::i8 , Custom); |
| 164 | setOperationAction(ISD::SETCC , MVT::i16 , Custom); |
| 165 | setOperationAction(ISD::SETCC , MVT::i32 , Custom); |
| 166 | setOperationAction(ISD::SETCC , MVT::f32 , Custom); |
| 167 | setOperationAction(ISD::SETCC , MVT::f64 , Custom); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 168 | // X86 ret instruction may pop stack. |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 169 | setOperationAction(ISD::RET , MVT::Other, Custom); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 170 | // Darwin ABI issue. |
Evan Cheng | 5588de9 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 171 | setOperationAction(ISD::ConstantPool , MVT::i32 , Custom); |
Nate Begeman | 4ca2ea5 | 2006-04-22 18:53:45 +0000 | [diff] [blame] | 172 | setOperationAction(ISD::JumpTable , MVT::i32 , Custom); |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 173 | setOperationAction(ISD::GlobalAddress , MVT::i32 , Custom); |
Evan Cheng | e0ed6ec | 2006-02-23 20:41:18 +0000 | [diff] [blame] | 174 | setOperationAction(ISD::ExternalSymbol , MVT::i32 , Custom); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 175 | // 64-bit addm sub, shl, sra, srl (iff 32-bit x86) |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 176 | setOperationAction(ISD::SHL_PARTS , MVT::i32 , Custom); |
| 177 | setOperationAction(ISD::SRA_PARTS , MVT::i32 , Custom); |
| 178 | setOperationAction(ISD::SRL_PARTS , MVT::i32 , Custom); |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 179 | // X86 wants to expand memset / memcpy itself. |
Evan Cheng | 593bea7 | 2006-02-17 07:01:52 +0000 | [diff] [blame] | 180 | setOperationAction(ISD::MEMSET , MVT::Other, Custom); |
| 181 | setOperationAction(ISD::MEMCPY , MVT::Other, Custom); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 182 | |
Chris Lattner | 9c41536 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 183 | // We don't have line number support yet. |
| 184 | setOperationAction(ISD::LOCATION, MVT::Other, Expand); |
Jim Laskey | deeafa0 | 2006-01-05 01:47:43 +0000 | [diff] [blame] | 185 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Evan Cheng | 30d7b70 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 186 | // FIXME - use subtarget debug flags |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 187 | if (!Subtarget->isTargetDarwin()) |
Evan Cheng | 30d7b70 | 2006-03-07 02:02:57 +0000 | [diff] [blame] | 188 | setOperationAction(ISD::DEBUG_LABEL, MVT::Other, Expand); |
Chris Lattner | 9c41536 | 2005-11-29 06:16:21 +0000 | [diff] [blame] | 189 | |
Nate Begeman | e74795c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 190 | // VASTART needs to be custom lowered to use the VarArgsFrameIndex |
| 191 | setOperationAction(ISD::VASTART , MVT::Other, Custom); |
| 192 | |
| 193 | // Use the default implementation. |
| 194 | setOperationAction(ISD::VAARG , MVT::Other, Expand); |
| 195 | setOperationAction(ISD::VACOPY , MVT::Other, Expand); |
| 196 | setOperationAction(ISD::VAEND , MVT::Other, Expand); |
Chris Lattner | 78c358d | 2006-01-15 09:00:21 +0000 | [diff] [blame] | 197 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 198 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| 199 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32 , Expand); |
Chris Lattner | 8e2f52e | 2006-01-13 02:42:53 +0000 | [diff] [blame] | 200 | |
Chris Lattner | 9c7f503 | 2006-03-05 05:08:37 +0000 | [diff] [blame] | 201 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 202 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Expand); |
| 203 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 204 | if (X86ScalarSSE) { |
| 205 | // Set up the FP register classes. |
Evan Cheng | 84dc9b5 | 2006-01-12 08:27:59 +0000 | [diff] [blame] | 206 | addRegisterClass(MVT::f32, X86::FR32RegisterClass); |
| 207 | addRegisterClass(MVT::f64, X86::FR64RegisterClass); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 208 | |
| 209 | // SSE has no load+extend ops |
| 210 | setOperationAction(ISD::EXTLOAD, MVT::f32, Expand); |
| 211 | setOperationAction(ISD::ZEXTLOAD, MVT::f32, Expand); |
| 212 | |
Evan Cheng | 72d5c25 | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 213 | // Use ANDPD to simulate FABS. |
| 214 | setOperationAction(ISD::FABS , MVT::f64, Custom); |
| 215 | setOperationAction(ISD::FABS , MVT::f32, Custom); |
| 216 | |
| 217 | // Use XORP to simulate FNEG. |
| 218 | setOperationAction(ISD::FNEG , MVT::f64, Custom); |
| 219 | setOperationAction(ISD::FNEG , MVT::f32, Custom); |
| 220 | |
Evan Cheng | d8fba3a | 2006-02-02 00:28:23 +0000 | [diff] [blame] | 221 | // We don't support sin/cos/fmod |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 222 | setOperationAction(ISD::FSIN , MVT::f64, Expand); |
| 223 | setOperationAction(ISD::FCOS , MVT::f64, Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 224 | setOperationAction(ISD::FREM , MVT::f64, Expand); |
| 225 | setOperationAction(ISD::FSIN , MVT::f32, Expand); |
| 226 | setOperationAction(ISD::FCOS , MVT::f32, Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 227 | setOperationAction(ISD::FREM , MVT::f32, Expand); |
| 228 | |
Chris Lattner | 61c9a8e | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 229 | // Expand FP immediates into loads from the stack, except for the special |
| 230 | // cases we handle. |
| 231 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
| 232 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 233 | addLegalFPImmediate(+0.0); // xorps / xorpd |
| 234 | } else { |
| 235 | // Set up the FP register classes. |
| 236 | addRegisterClass(MVT::f64, X86::RFPRegisterClass); |
Chris Lattner | 132177e | 2006-01-29 06:44:22 +0000 | [diff] [blame] | 237 | |
| 238 | setOperationAction(ISD::UNDEF, MVT::f64, Expand); |
| 239 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 240 | if (!UnsafeFPMath) { |
| 241 | setOperationAction(ISD::FSIN , MVT::f64 , Expand); |
| 242 | setOperationAction(ISD::FCOS , MVT::f64 , Expand); |
| 243 | } |
| 244 | |
Chris Lattner | 61c9a8e | 2006-01-29 06:26:08 +0000 | [diff] [blame] | 245 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 246 | addLegalFPImmediate(+0.0); // FLD0 |
| 247 | addLegalFPImmediate(+1.0); // FLD1 |
| 248 | addLegalFPImmediate(-0.0); // FLD0/FCHS |
| 249 | addLegalFPImmediate(-1.0); // FLD1/FCHS |
| 250 | } |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 251 | |
Evan Cheng | 1926427 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 252 | // First set operation action for all vector types to expand. Then we |
| 253 | // will selectively turn on ones that can be effectively codegen'd. |
| 254 | for (unsigned VT = (unsigned)MVT::Vector + 1; |
| 255 | VT != (unsigned)MVT::LAST_VALUETYPE; VT++) { |
| 256 | setOperationAction(ISD::ADD , (MVT::ValueType)VT, Expand); |
| 257 | setOperationAction(ISD::SUB , (MVT::ValueType)VT, Expand); |
| 258 | setOperationAction(ISD::MUL , (MVT::ValueType)VT, Expand); |
| 259 | setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Expand); |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 260 | setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Expand); |
Chris Lattner | 00f4683 | 2006-03-21 20:51:05 +0000 | [diff] [blame] | 261 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 262 | setOperationAction(ISD::INSERT_VECTOR_ELT, (MVT::ValueType)VT, Expand); |
Evan Cheng | 1926427 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 265 | if (Subtarget->hasMMX()) { |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 266 | addRegisterClass(MVT::v8i8, X86::VR64RegisterClass); |
| 267 | addRegisterClass(MVT::v4i16, X86::VR64RegisterClass); |
| 268 | addRegisterClass(MVT::v2i32, X86::VR64RegisterClass); |
| 269 | |
Evan Cheng | 1926427 | 2006-03-01 01:11:20 +0000 | [diff] [blame] | 270 | // FIXME: add MMX packed arithmetics |
Evan Cheng | d5e905d | 2006-03-21 23:01:21 +0000 | [diff] [blame] | 271 | setOperationAction(ISD::BUILD_VECTOR, MVT::v8i8, Expand); |
| 272 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4i16, Expand); |
| 273 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2i32, Expand); |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 276 | if (Subtarget->hasSSE1()) { |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 277 | addRegisterClass(MVT::v4f32, X86::VR128RegisterClass); |
| 278 | |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 279 | setOperationAction(ISD::AND, MVT::v4f32, Legal); |
| 280 | setOperationAction(ISD::OR, MVT::v4f32, Legal); |
| 281 | setOperationAction(ISD::XOR, MVT::v4f32, Legal); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 282 | setOperationAction(ISD::ADD, MVT::v4f32, Legal); |
| 283 | setOperationAction(ISD::SUB, MVT::v4f32, Legal); |
| 284 | setOperationAction(ISD::MUL, MVT::v4f32, Legal); |
| 285 | setOperationAction(ISD::LOAD, MVT::v4f32, Legal); |
| 286 | setOperationAction(ISD::BUILD_VECTOR, MVT::v4f32, Custom); |
| 287 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v4f32, Custom); |
Evan Cheng | ebf1006 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 288 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4f32, Custom); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 289 | setOperationAction(ISD::SELECT, MVT::v4f32, Custom); |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 292 | if (Subtarget->hasSSE2()) { |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 293 | addRegisterClass(MVT::v2f64, X86::VR128RegisterClass); |
| 294 | addRegisterClass(MVT::v16i8, X86::VR128RegisterClass); |
| 295 | addRegisterClass(MVT::v8i16, X86::VR128RegisterClass); |
| 296 | addRegisterClass(MVT::v4i32, X86::VR128RegisterClass); |
| 297 | addRegisterClass(MVT::v2i64, X86::VR128RegisterClass); |
| 298 | |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 299 | setOperationAction(ISD::ADD, MVT::v2f64, Legal); |
| 300 | setOperationAction(ISD::ADD, MVT::v16i8, Legal); |
| 301 | setOperationAction(ISD::ADD, MVT::v8i16, Legal); |
| 302 | setOperationAction(ISD::ADD, MVT::v4i32, Legal); |
| 303 | setOperationAction(ISD::SUB, MVT::v2f64, Legal); |
| 304 | setOperationAction(ISD::SUB, MVT::v16i8, Legal); |
| 305 | setOperationAction(ISD::SUB, MVT::v8i16, Legal); |
| 306 | setOperationAction(ISD::SUB, MVT::v4i32, Legal); |
Evan Cheng | e4f97cc | 2006-04-13 05:10:25 +0000 | [diff] [blame] | 307 | setOperationAction(ISD::MUL, MVT::v8i16, Legal); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 308 | setOperationAction(ISD::MUL, MVT::v2f64, Legal); |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 309 | |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 310 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v16i8, Custom); |
| 311 | setOperationAction(ISD::SCALAR_TO_VECTOR, MVT::v8i16, Custom); |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 312 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v8i16, Custom); |
Evan Cheng | 6e5e205 | 2006-04-17 22:04:06 +0000 | [diff] [blame] | 313 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4i32, Custom); |
| 314 | // Implement v4f32 insert_vector_elt in terms of SSE2 v8i16 ones. |
| 315 | setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4f32, Custom); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 316 | |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 317 | // Custom lower build_vector, vector_shuffle, and extract_vector_elt. |
| 318 | for (unsigned VT = (unsigned)MVT::v16i8; VT != (unsigned)MVT::v2i64; VT++) { |
| 319 | setOperationAction(ISD::BUILD_VECTOR, (MVT::ValueType)VT, Custom); |
| 320 | setOperationAction(ISD::VECTOR_SHUFFLE, (MVT::ValueType)VT, Custom); |
| 321 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, (MVT::ValueType)VT, Custom); |
| 322 | } |
| 323 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2f64, Custom); |
| 324 | setOperationAction(ISD::BUILD_VECTOR, MVT::v2i64, Custom); |
| 325 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2f64, Custom); |
| 326 | setOperationAction(ISD::VECTOR_SHUFFLE, MVT::v2i64, Custom); |
| 327 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f64, Custom); |
| 328 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2i64, Custom); |
| 329 | |
| 330 | // Promote v16i8, v8i16, v4i32 load, select, and, or, xor to v2i64. |
| 331 | for (unsigned VT = (unsigned)MVT::v16i8; VT != (unsigned)MVT::v2i64; VT++) { |
| 332 | setOperationAction(ISD::AND, (MVT::ValueType)VT, Promote); |
| 333 | AddPromotedToType (ISD::AND, (MVT::ValueType)VT, MVT::v2i64); |
| 334 | setOperationAction(ISD::OR, (MVT::ValueType)VT, Promote); |
| 335 | AddPromotedToType (ISD::OR, (MVT::ValueType)VT, MVT::v2i64); |
| 336 | setOperationAction(ISD::XOR, (MVT::ValueType)VT, Promote); |
| 337 | AddPromotedToType (ISD::XOR, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | e2157c6 | 2006-04-12 17:12:36 +0000 | [diff] [blame] | 338 | setOperationAction(ISD::LOAD, (MVT::ValueType)VT, Promote); |
| 339 | AddPromotedToType (ISD::LOAD, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 340 | setOperationAction(ISD::SELECT, (MVT::ValueType)VT, Promote); |
| 341 | AddPromotedToType (ISD::SELECT, (MVT::ValueType)VT, MVT::v2i64); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 342 | } |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 343 | |
| 344 | // Custom lower v2i64 and v2f64 selects. |
| 345 | setOperationAction(ISD::LOAD, MVT::v2f64, Legal); |
Evan Cheng | e2157c6 | 2006-04-12 17:12:36 +0000 | [diff] [blame] | 346 | setOperationAction(ISD::LOAD, MVT::v2i64, Legal); |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 347 | setOperationAction(ISD::SELECT, MVT::v2f64, Custom); |
Evan Cheng | 9223230 | 2006-04-12 21:21:57 +0000 | [diff] [blame] | 348 | setOperationAction(ISD::SELECT, MVT::v2i64, Custom); |
Evan Cheng | 9e252e3 | 2006-02-22 02:26:30 +0000 | [diff] [blame] | 349 | } |
| 350 | |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 351 | // We want to custom lower some of our intrinsics. |
| 352 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| 353 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 354 | computeRegisterProperties(); |
| 355 | |
Evan Cheng | 6a37456 | 2006-02-14 08:25:08 +0000 | [diff] [blame] | 356 | // FIXME: These should be based on subtarget info. Plus, the values should |
| 357 | // be smaller when we are in optimizing for size mode. |
Evan Cheng | 4b40a42 | 2006-02-14 08:38:30 +0000 | [diff] [blame] | 358 | maxStoresPerMemset = 16; // For %llvm.memset -> sequence of stores |
| 359 | maxStoresPerMemcpy = 16; // For %llvm.memcpy -> sequence of stores |
| 360 | maxStoresPerMemmove = 16; // For %llvm.memmove -> sequence of stores |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 361 | allowUnalignedMemoryAccesses = true; // x86 supports it! |
| 362 | } |
| 363 | |
| 364 | std::vector<SDOperand> |
| 365 | X86TargetLowering::LowerArguments(Function &F, SelectionDAG &DAG) { |
| 366 | if (F.getCallingConv() == CallingConv::Fast && EnableFastCC) |
| 367 | return LowerFastCCArguments(F, DAG); |
| 368 | return LowerCCCArguments(F, DAG); |
| 369 | } |
| 370 | |
| 371 | std::pair<SDOperand, SDOperand> |
| 372 | X86TargetLowering::LowerCallTo(SDOperand Chain, const Type *RetTy, |
| 373 | bool isVarArg, unsigned CallingConv, |
| 374 | bool isTailCall, |
| 375 | SDOperand Callee, ArgListTy &Args, |
| 376 | SelectionDAG &DAG) { |
| 377 | assert((!isVarArg || CallingConv == CallingConv::C) && |
| 378 | "Only C takes varargs!"); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 379 | |
| 380 | // If the callee is a GlobalAddress node (quite common, every direct call is) |
| 381 | // turn it into a TargetGlobalAddress node so that legalize doesn't hack it. |
| 382 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) |
| 383 | Callee = DAG.getTargetGlobalAddress(G->getGlobal(), getPointerTy()); |
Evan Cheng | bc7a0f44 | 2006-01-11 06:09:51 +0000 | [diff] [blame] | 384 | else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) |
| 385 | Callee = DAG.getTargetExternalSymbol(S->getSymbol(), getPointerTy()); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 386 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 387 | if (CallingConv == CallingConv::Fast && EnableFastCC) |
| 388 | return LowerFastCCCallTo(Chain, RetTy, isTailCall, Callee, Args, DAG); |
| 389 | return LowerCCCCallTo(Chain, RetTy, isVarArg, isTailCall, Callee, Args, DAG); |
| 390 | } |
| 391 | |
| 392 | //===----------------------------------------------------------------------===// |
| 393 | // C Calling Convention implementation |
| 394 | //===----------------------------------------------------------------------===// |
| 395 | |
| 396 | std::vector<SDOperand> |
| 397 | X86TargetLowering::LowerCCCArguments(Function &F, SelectionDAG &DAG) { |
| 398 | std::vector<SDOperand> ArgValues; |
| 399 | |
| 400 | MachineFunction &MF = DAG.getMachineFunction(); |
| 401 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 402 | |
| 403 | // Add DAG nodes to load the arguments... On entry to a function on the X86, |
| 404 | // the stack frame looks like this: |
| 405 | // |
| 406 | // [ESP] -- return address |
| 407 | // [ESP + 4] -- first argument (leftmost lexically) |
| 408 | // [ESP + 8] -- second argument, if first argument is four bytes in size |
| 409 | // ... |
| 410 | // |
| 411 | unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot |
| 412 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { |
| 413 | MVT::ValueType ObjectVT = getValueType(I->getType()); |
| 414 | unsigned ArgIncrement = 4; |
| 415 | unsigned ObjSize; |
| 416 | switch (ObjectVT) { |
| 417 | default: assert(0 && "Unhandled argument type!"); |
| 418 | case MVT::i1: |
| 419 | case MVT::i8: ObjSize = 1; break; |
| 420 | case MVT::i16: ObjSize = 2; break; |
| 421 | case MVT::i32: ObjSize = 4; break; |
| 422 | case MVT::i64: ObjSize = ArgIncrement = 8; break; |
| 423 | case MVT::f32: ObjSize = 4; break; |
| 424 | case MVT::f64: ObjSize = ArgIncrement = 8; break; |
| 425 | } |
| 426 | // Create the frame index object for this incoming parameter... |
| 427 | int FI = MFI->CreateFixedObject(ObjSize, ArgOffset); |
| 428 | |
| 429 | // Create the SelectionDAG nodes corresponding to a load from this parameter |
| 430 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 431 | |
| 432 | // Don't codegen dead arguments. FIXME: remove this check when we can nuke |
| 433 | // dead loads. |
| 434 | SDOperand ArgValue; |
| 435 | if (!I->use_empty()) |
| 436 | ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN, |
| 437 | DAG.getSrcValue(NULL)); |
| 438 | else { |
| 439 | if (MVT::isInteger(ObjectVT)) |
| 440 | ArgValue = DAG.getConstant(0, ObjectVT); |
| 441 | else |
| 442 | ArgValue = DAG.getConstantFP(0, ObjectVT); |
| 443 | } |
| 444 | ArgValues.push_back(ArgValue); |
| 445 | |
| 446 | ArgOffset += ArgIncrement; // Move on to the next argument... |
| 447 | } |
| 448 | |
| 449 | // If the function takes variable number of arguments, make a frame index for |
| 450 | // the start of the first vararg value... for expansion of llvm.va_start. |
| 451 | if (F.isVarArg()) |
| 452 | VarArgsFrameIndex = MFI->CreateFixedObject(1, ArgOffset); |
| 453 | ReturnAddrIndex = 0; // No return address slot generated yet. |
| 454 | BytesToPopOnReturn = 0; // Callee pops nothing. |
| 455 | BytesCallerReserves = ArgOffset; |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 456 | return ArgValues; |
| 457 | } |
| 458 | |
| 459 | std::pair<SDOperand, SDOperand> |
| 460 | X86TargetLowering::LowerCCCCallTo(SDOperand Chain, const Type *RetTy, |
| 461 | bool isVarArg, bool isTailCall, |
| 462 | SDOperand Callee, ArgListTy &Args, |
| 463 | SelectionDAG &DAG) { |
| 464 | // Count how many bytes are to be pushed on the stack. |
| 465 | unsigned NumBytes = 0; |
| 466 | |
| 467 | if (Args.empty()) { |
| 468 | // Save zero bytes. |
Chris Lattner | 62c3484 | 2006-02-13 09:00:43 +0000 | [diff] [blame] | 469 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getConstant(0, getPointerTy())); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 470 | } else { |
| 471 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
| 472 | switch (getValueType(Args[i].second)) { |
| 473 | default: assert(0 && "Unknown value type!"); |
| 474 | case MVT::i1: |
| 475 | case MVT::i8: |
| 476 | case MVT::i16: |
| 477 | case MVT::i32: |
| 478 | case MVT::f32: |
| 479 | NumBytes += 4; |
| 480 | break; |
| 481 | case MVT::i64: |
| 482 | case MVT::f64: |
| 483 | NumBytes += 8; |
| 484 | break; |
| 485 | } |
| 486 | |
Chris Lattner | 62c3484 | 2006-02-13 09:00:43 +0000 | [diff] [blame] | 487 | Chain = DAG.getCALLSEQ_START(Chain, |
| 488 | DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 489 | |
| 490 | // Arguments go on the stack in reverse order, as specified by the ABI. |
| 491 | unsigned ArgOffset = 0; |
Evan Cheng | bc7a0f44 | 2006-01-11 06:09:51 +0000 | [diff] [blame] | 492 | SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 493 | std::vector<SDOperand> Stores; |
| 494 | |
| 495 | for (unsigned i = 0, e = Args.size(); i != e; ++i) { |
| 496 | SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy()); |
| 497 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 498 | |
| 499 | switch (getValueType(Args[i].second)) { |
| 500 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 501 | case MVT::i1: |
| 502 | case MVT::i8: |
| 503 | case MVT::i16: |
| 504 | // Promote the integer to 32 bits. If the input type is signed use a |
| 505 | // sign extend, otherwise use a zero extend. |
| 506 | if (Args[i].second->isSigned()) |
| 507 | Args[i].first =DAG.getNode(ISD::SIGN_EXTEND, MVT::i32, Args[i].first); |
| 508 | else |
| 509 | Args[i].first =DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Args[i].first); |
| 510 | |
| 511 | // FALL THROUGH |
| 512 | case MVT::i32: |
| 513 | case MVT::f32: |
| 514 | Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 515 | Args[i].first, PtrOff, |
| 516 | DAG.getSrcValue(NULL))); |
| 517 | ArgOffset += 4; |
| 518 | break; |
| 519 | case MVT::i64: |
| 520 | case MVT::f64: |
| 521 | Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 522 | Args[i].first, PtrOff, |
| 523 | DAG.getSrcValue(NULL))); |
| 524 | ArgOffset += 8; |
| 525 | break; |
| 526 | } |
| 527 | } |
| 528 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores); |
| 529 | } |
| 530 | |
| 531 | std::vector<MVT::ValueType> RetVals; |
| 532 | MVT::ValueType RetTyVT = getValueType(RetTy); |
| 533 | RetVals.push_back(MVT::Other); |
| 534 | |
| 535 | // The result values produced have to be legal. Promote the result. |
| 536 | switch (RetTyVT) { |
| 537 | case MVT::isVoid: break; |
| 538 | default: |
| 539 | RetVals.push_back(RetTyVT); |
| 540 | break; |
| 541 | case MVT::i1: |
| 542 | case MVT::i8: |
| 543 | case MVT::i16: |
| 544 | RetVals.push_back(MVT::i32); |
| 545 | break; |
| 546 | case MVT::f32: |
| 547 | if (X86ScalarSSE) |
| 548 | RetVals.push_back(MVT::f32); |
| 549 | else |
| 550 | RetVals.push_back(MVT::f64); |
| 551 | break; |
| 552 | case MVT::i64: |
| 553 | RetVals.push_back(MVT::i32); |
| 554 | RetVals.push_back(MVT::i32); |
| 555 | break; |
| 556 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 557 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 558 | std::vector<MVT::ValueType> NodeTys; |
| 559 | NodeTys.push_back(MVT::Other); // Returns a chain |
| 560 | NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. |
| 561 | std::vector<SDOperand> Ops; |
| 562 | Ops.push_back(Chain); |
| 563 | Ops.push_back(Callee); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 564 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 565 | // FIXME: Do not generate X86ISD::TAILCALL for now. |
| 566 | Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops); |
| 567 | SDOperand InFlag = Chain.getValue(1); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 568 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 569 | NodeTys.clear(); |
| 570 | NodeTys.push_back(MVT::Other); // Returns a chain |
| 571 | NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. |
| 572 | Ops.clear(); |
| 573 | Ops.push_back(Chain); |
| 574 | Ops.push_back(DAG.getConstant(NumBytes, getPointerTy())); |
| 575 | Ops.push_back(DAG.getConstant(0, getPointerTy())); |
| 576 | Ops.push_back(InFlag); |
| 577 | Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops); |
| 578 | InFlag = Chain.getValue(1); |
| 579 | |
| 580 | SDOperand RetVal; |
| 581 | if (RetTyVT != MVT::isVoid) { |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 582 | switch (RetTyVT) { |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 583 | default: assert(0 && "Unknown value type to return!"); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 584 | case MVT::i1: |
| 585 | case MVT::i8: |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 586 | RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag); |
| 587 | Chain = RetVal.getValue(1); |
| 588 | if (RetTyVT == MVT::i1) |
| 589 | RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal); |
| 590 | break; |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 591 | case MVT::i16: |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 592 | RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag); |
| 593 | Chain = RetVal.getValue(1); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 594 | break; |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 595 | case MVT::i32: |
| 596 | RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag); |
| 597 | Chain = RetVal.getValue(1); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 598 | break; |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 599 | case MVT::i64: { |
| 600 | SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag); |
| 601 | SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32, |
| 602 | Lo.getValue(2)); |
| 603 | RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi); |
| 604 | Chain = Hi.getValue(1); |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 605 | break; |
| 606 | } |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 607 | case MVT::f32: |
| 608 | case MVT::f64: { |
| 609 | std::vector<MVT::ValueType> Tys; |
| 610 | Tys.push_back(MVT::f64); |
| 611 | Tys.push_back(MVT::Other); |
| 612 | Tys.push_back(MVT::Flag); |
| 613 | std::vector<SDOperand> Ops; |
| 614 | Ops.push_back(Chain); |
| 615 | Ops.push_back(InFlag); |
| 616 | RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops); |
| 617 | Chain = RetVal.getValue(1); |
| 618 | InFlag = RetVal.getValue(2); |
| 619 | if (X86ScalarSSE) { |
| 620 | // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This |
| 621 | // shouldn't be necessary except that RFP cannot be live across |
| 622 | // multiple blocks. When stackifier is fixed, they can be uncoupled. |
| 623 | MachineFunction &MF = DAG.getMachineFunction(); |
| 624 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
| 625 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 626 | Tys.clear(); |
| 627 | Tys.push_back(MVT::Other); |
| 628 | Ops.clear(); |
| 629 | Ops.push_back(Chain); |
| 630 | Ops.push_back(RetVal); |
| 631 | Ops.push_back(StackSlot); |
| 632 | Ops.push_back(DAG.getValueType(RetTyVT)); |
| 633 | Ops.push_back(InFlag); |
| 634 | Chain = DAG.getNode(X86ISD::FST, Tys, Ops); |
| 635 | RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot, |
| 636 | DAG.getSrcValue(NULL)); |
| 637 | Chain = RetVal.getValue(1); |
| 638 | } |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 639 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 640 | if (RetTyVT == MVT::f32 && !X86ScalarSSE) |
| 641 | // FIXME: we would really like to remember that this FP_ROUND |
| 642 | // operation is okay to eliminate if we allow excess FP precision. |
| 643 | RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal); |
| 644 | break; |
| 645 | } |
| 646 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 647 | } |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 648 | |
| 649 | return std::make_pair(RetVal, Chain); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 650 | } |
| 651 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 652 | //===----------------------------------------------------------------------===// |
| 653 | // Fast Calling Convention implementation |
| 654 | //===----------------------------------------------------------------------===// |
| 655 | // |
| 656 | // The X86 'fast' calling convention passes up to two integer arguments in |
| 657 | // registers (an appropriate portion of EAX/EDX), passes arguments in C order, |
| 658 | // and requires that the callee pop its arguments off the stack (allowing proper |
| 659 | // tail calls), and has the same return value conventions as C calling convs. |
| 660 | // |
| 661 | // This calling convention always arranges for the callee pop value to be 8n+4 |
| 662 | // bytes, which is needed for tail recursion elimination and stack alignment |
| 663 | // reasons. |
| 664 | // |
| 665 | // Note that this can be enhanced in the future to pass fp vals in registers |
| 666 | // (when we have a global fp allocator) and do other tricks. |
| 667 | // |
| 668 | |
| 669 | /// AddLiveIn - This helper function adds the specified physical register to the |
| 670 | /// MachineFunction as a live in value. It also creates a corresponding virtual |
| 671 | /// register for it. |
| 672 | static unsigned AddLiveIn(MachineFunction &MF, unsigned PReg, |
| 673 | TargetRegisterClass *RC) { |
| 674 | assert(RC->contains(PReg) && "Not the correct regclass!"); |
| 675 | unsigned VReg = MF.getSSARegMap()->createVirtualRegister(RC); |
| 676 | MF.addLiveIn(PReg, VReg); |
| 677 | return VReg; |
| 678 | } |
| 679 | |
Chris Lattner | 388fc4d | 2006-03-17 17:27:47 +0000 | [diff] [blame] | 680 | // FASTCC_NUM_INT_ARGS_INREGS - This is the max number of integer arguments |
| 681 | // to pass in registers. 0 is none, 1 is is "use EAX", 2 is "use EAX and |
| 682 | // EDX". Anything more is illegal. |
| 683 | // |
| 684 | // FIXME: The linscan register allocator currently has problem with |
Chris Lattner | f5efddf | 2006-03-24 07:12:19 +0000 | [diff] [blame] | 685 | // coalescing. At the time of this writing, whenever it decides to coalesce |
Chris Lattner | 388fc4d | 2006-03-17 17:27:47 +0000 | [diff] [blame] | 686 | // a physreg with a virtreg, this increases the size of the physreg's live |
| 687 | // range, and the live range cannot ever be reduced. This causes problems if |
Chris Lattner | f5efddf | 2006-03-24 07:12:19 +0000 | [diff] [blame] | 688 | // too many physregs are coaleced with virtregs, which can cause the register |
Chris Lattner | 388fc4d | 2006-03-17 17:27:47 +0000 | [diff] [blame] | 689 | // allocator to wedge itself. |
| 690 | // |
| 691 | // This code triggers this problem more often if we pass args in registers, |
| 692 | // so disable it until this is fixed. |
| 693 | // |
| 694 | // NOTE: this isn't marked const, so that GCC doesn't emit annoying warnings |
| 695 | // about code being dead. |
| 696 | // |
| 697 | static unsigned FASTCC_NUM_INT_ARGS_INREGS = 0; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 698 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 699 | |
| 700 | std::vector<SDOperand> |
| 701 | X86TargetLowering::LowerFastCCArguments(Function &F, SelectionDAG &DAG) { |
| 702 | std::vector<SDOperand> ArgValues; |
| 703 | |
| 704 | MachineFunction &MF = DAG.getMachineFunction(); |
| 705 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 706 | |
| 707 | // Add DAG nodes to load the arguments... On entry to a function the stack |
| 708 | // frame looks like this: |
| 709 | // |
| 710 | // [ESP] -- return address |
| 711 | // [ESP + 4] -- first nonreg argument (leftmost lexically) |
| 712 | // [ESP + 8] -- second nonreg argument, if first argument is 4 bytes in size |
| 713 | // ... |
| 714 | unsigned ArgOffset = 0; // Frame mechanisms handle retaddr slot |
| 715 | |
| 716 | // Keep track of the number of integer regs passed so far. This can be either |
| 717 | // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both |
| 718 | // used). |
| 719 | unsigned NumIntRegs = 0; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 720 | |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 721 | for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I) { |
| 722 | MVT::ValueType ObjectVT = getValueType(I->getType()); |
| 723 | unsigned ArgIncrement = 4; |
| 724 | unsigned ObjSize = 0; |
| 725 | SDOperand ArgValue; |
| 726 | |
| 727 | switch (ObjectVT) { |
| 728 | default: assert(0 && "Unhandled argument type!"); |
| 729 | case MVT::i1: |
| 730 | case MVT::i8: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 731 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 732 | if (!I->use_empty()) { |
| 733 | unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DL : X86::AL, |
| 734 | X86::R8RegisterClass); |
| 735 | ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i8); |
| 736 | DAG.setRoot(ArgValue.getValue(1)); |
Chris Lattner | 8258489 | 2005-12-27 03:02:18 +0000 | [diff] [blame] | 737 | if (ObjectVT == MVT::i1) |
| 738 | // FIXME: Should insert a assertzext here. |
| 739 | ArgValue = DAG.getNode(ISD::TRUNCATE, MVT::i1, ArgValue); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 740 | } |
| 741 | ++NumIntRegs; |
| 742 | break; |
| 743 | } |
| 744 | |
| 745 | ObjSize = 1; |
| 746 | break; |
| 747 | case MVT::i16: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 748 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 749 | if (!I->use_empty()) { |
| 750 | unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::DX : X86::AX, |
| 751 | X86::R16RegisterClass); |
| 752 | ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i16); |
| 753 | DAG.setRoot(ArgValue.getValue(1)); |
| 754 | } |
| 755 | ++NumIntRegs; |
| 756 | break; |
| 757 | } |
| 758 | ObjSize = 2; |
| 759 | break; |
| 760 | case MVT::i32: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 761 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 762 | if (!I->use_empty()) { |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 763 | unsigned VReg = AddLiveIn(MF, NumIntRegs ? X86::EDX : X86::EAX, |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 764 | X86::R32RegisterClass); |
| 765 | ArgValue = DAG.getCopyFromReg(DAG.getRoot(), VReg, MVT::i32); |
| 766 | DAG.setRoot(ArgValue.getValue(1)); |
| 767 | } |
| 768 | ++NumIntRegs; |
| 769 | break; |
| 770 | } |
| 771 | ObjSize = 4; |
| 772 | break; |
| 773 | case MVT::i64: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 774 | if (NumIntRegs+2 <= FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 775 | if (!I->use_empty()) { |
| 776 | unsigned BotReg = AddLiveIn(MF, X86::EAX, X86::R32RegisterClass); |
| 777 | unsigned TopReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass); |
| 778 | |
| 779 | SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32); |
| 780 | SDOperand Hi = DAG.getCopyFromReg(Low.getValue(1), TopReg, MVT::i32); |
| 781 | DAG.setRoot(Hi.getValue(1)); |
| 782 | |
| 783 | ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi); |
| 784 | } |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 785 | NumIntRegs += 2; |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 786 | break; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 787 | } else if (NumIntRegs+1 <= FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 788 | if (!I->use_empty()) { |
| 789 | unsigned BotReg = AddLiveIn(MF, X86::EDX, X86::R32RegisterClass); |
| 790 | SDOperand Low = DAG.getCopyFromReg(DAG.getRoot(), BotReg, MVT::i32); |
| 791 | DAG.setRoot(Low.getValue(1)); |
| 792 | |
| 793 | // Load the high part from memory. |
| 794 | // Create the frame index object for this incoming parameter... |
| 795 | int FI = MFI->CreateFixedObject(4, ArgOffset); |
| 796 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 797 | SDOperand Hi = DAG.getLoad(MVT::i32, DAG.getEntryNode(), FIN, |
| 798 | DAG.getSrcValue(NULL)); |
| 799 | ArgValue = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Low, Hi); |
| 800 | } |
| 801 | ArgOffset += 4; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 802 | NumIntRegs = FASTCC_NUM_INT_ARGS_INREGS; |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 803 | break; |
| 804 | } |
| 805 | ObjSize = ArgIncrement = 8; |
| 806 | break; |
| 807 | case MVT::f32: ObjSize = 4; break; |
| 808 | case MVT::f64: ObjSize = ArgIncrement = 8; break; |
| 809 | } |
| 810 | |
| 811 | // Don't codegen dead arguments. FIXME: remove this check when we can nuke |
| 812 | // dead loads. |
| 813 | if (ObjSize && !I->use_empty()) { |
| 814 | // Create the frame index object for this incoming parameter... |
| 815 | int FI = MFI->CreateFixedObject(ObjSize, ArgOffset); |
| 816 | |
| 817 | // Create the SelectionDAG nodes corresponding to a load from this |
| 818 | // parameter. |
| 819 | SDOperand FIN = DAG.getFrameIndex(FI, MVT::i32); |
| 820 | |
| 821 | ArgValue = DAG.getLoad(ObjectVT, DAG.getEntryNode(), FIN, |
| 822 | DAG.getSrcValue(NULL)); |
| 823 | } else if (ArgValue.Val == 0) { |
| 824 | if (MVT::isInteger(ObjectVT)) |
| 825 | ArgValue = DAG.getConstant(0, ObjectVT); |
| 826 | else |
| 827 | ArgValue = DAG.getConstantFP(0, ObjectVT); |
| 828 | } |
| 829 | ArgValues.push_back(ArgValue); |
| 830 | |
| 831 | if (ObjSize) |
| 832 | ArgOffset += ArgIncrement; // Move on to the next argument. |
| 833 | } |
| 834 | |
| 835 | // Make sure the instruction takes 8n+4 bytes to make sure the start of the |
| 836 | // arguments and the arguments after the retaddr has been pushed are aligned. |
| 837 | if ((ArgOffset & 7) == 0) |
| 838 | ArgOffset += 4; |
| 839 | |
| 840 | VarArgsFrameIndex = 0xAAAAAAA; // fastcc functions can't have varargs. |
| 841 | ReturnAddrIndex = 0; // No return address slot generated yet. |
| 842 | BytesToPopOnReturn = ArgOffset; // Callee pops all stack arguments. |
| 843 | BytesCallerReserves = 0; |
| 844 | |
| 845 | // Finally, inform the code generator which regs we return values in. |
| 846 | switch (getValueType(F.getReturnType())) { |
| 847 | default: assert(0 && "Unknown type!"); |
| 848 | case MVT::isVoid: break; |
| 849 | case MVT::i1: |
| 850 | case MVT::i8: |
| 851 | case MVT::i16: |
| 852 | case MVT::i32: |
| 853 | MF.addLiveOut(X86::EAX); |
| 854 | break; |
| 855 | case MVT::i64: |
| 856 | MF.addLiveOut(X86::EAX); |
| 857 | MF.addLiveOut(X86::EDX); |
| 858 | break; |
| 859 | case MVT::f32: |
| 860 | case MVT::f64: |
| 861 | MF.addLiveOut(X86::ST0); |
| 862 | break; |
| 863 | } |
| 864 | return ArgValues; |
| 865 | } |
| 866 | |
| 867 | std::pair<SDOperand, SDOperand> |
| 868 | X86TargetLowering::LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, |
| 869 | bool isTailCall, SDOperand Callee, |
| 870 | ArgListTy &Args, SelectionDAG &DAG) { |
| 871 | // Count how many bytes are to be pushed on the stack. |
| 872 | unsigned NumBytes = 0; |
| 873 | |
| 874 | // Keep track of the number of integer regs passed so far. This can be either |
| 875 | // 0 (neither EAX or EDX used), 1 (EAX is used) or 2 (EAX and EDX are both |
| 876 | // used). |
| 877 | unsigned NumIntRegs = 0; |
| 878 | |
| 879 | for (unsigned i = 0, e = Args.size(); i != e; ++i) |
| 880 | switch (getValueType(Args[i].second)) { |
| 881 | default: assert(0 && "Unknown value type!"); |
| 882 | case MVT::i1: |
| 883 | case MVT::i8: |
| 884 | case MVT::i16: |
| 885 | case MVT::i32: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 886 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 887 | ++NumIntRegs; |
| 888 | break; |
| 889 | } |
| 890 | // fall through |
| 891 | case MVT::f32: |
| 892 | NumBytes += 4; |
| 893 | break; |
| 894 | case MVT::i64: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 895 | if (NumIntRegs+2 <= FASTCC_NUM_INT_ARGS_INREGS) { |
| 896 | NumIntRegs += 2; |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 897 | break; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 898 | } else if (NumIntRegs+1 <= FASTCC_NUM_INT_ARGS_INREGS) { |
| 899 | NumIntRegs = FASTCC_NUM_INT_ARGS_INREGS; |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 900 | NumBytes += 4; |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | // fall through |
| 905 | case MVT::f64: |
| 906 | NumBytes += 8; |
| 907 | break; |
| 908 | } |
| 909 | |
| 910 | // Make sure the instruction takes 8n+4 bytes to make sure the start of the |
| 911 | // arguments and the arguments after the retaddr has been pushed are aligned. |
| 912 | if ((NumBytes & 7) == 0) |
| 913 | NumBytes += 4; |
| 914 | |
Chris Lattner | 62c3484 | 2006-02-13 09:00:43 +0000 | [diff] [blame] | 915 | Chain = DAG.getCALLSEQ_START(Chain,DAG.getConstant(NumBytes, getPointerTy())); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 916 | |
| 917 | // Arguments go on the stack in reverse order, as specified by the ABI. |
| 918 | unsigned ArgOffset = 0; |
Chris Lattner | 27d30a5 | 2006-01-24 06:14:44 +0000 | [diff] [blame] | 919 | SDOperand StackPtr = DAG.getRegister(X86::ESP, MVT::i32); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 920 | NumIntRegs = 0; |
| 921 | std::vector<SDOperand> Stores; |
| 922 | std::vector<SDOperand> RegValuesToPass; |
| 923 | for (unsigned i = 0, e = Args.size(); i != e; ++i) { |
| 924 | switch (getValueType(Args[i].second)) { |
| 925 | default: assert(0 && "Unexpected ValueType for argument!"); |
| 926 | case MVT::i1: |
Chris Lattner | 8258489 | 2005-12-27 03:02:18 +0000 | [diff] [blame] | 927 | Args[i].first = DAG.getNode(ISD::ANY_EXTEND, MVT::i8, Args[i].first); |
| 928 | // Fall through. |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 929 | case MVT::i8: |
| 930 | case MVT::i16: |
| 931 | case MVT::i32: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 932 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 933 | RegValuesToPass.push_back(Args[i].first); |
| 934 | ++NumIntRegs; |
| 935 | break; |
| 936 | } |
| 937 | // Fall through |
| 938 | case MVT::f32: { |
| 939 | SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy()); |
| 940 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 941 | Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 942 | Args[i].first, PtrOff, |
| 943 | DAG.getSrcValue(NULL))); |
| 944 | ArgOffset += 4; |
| 945 | break; |
| 946 | } |
| 947 | case MVT::i64: |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 948 | // Can pass (at least) part of it in regs? |
| 949 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 950 | SDOperand Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, |
| 951 | Args[i].first, DAG.getConstant(1, MVT::i32)); |
| 952 | SDOperand Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, MVT::i32, |
| 953 | Args[i].first, DAG.getConstant(0, MVT::i32)); |
| 954 | RegValuesToPass.push_back(Lo); |
| 955 | ++NumIntRegs; |
Chris Lattner | 4379885 | 2006-03-17 05:10:20 +0000 | [diff] [blame] | 956 | |
| 957 | // Pass both parts in regs? |
| 958 | if (NumIntRegs < FASTCC_NUM_INT_ARGS_INREGS) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 959 | RegValuesToPass.push_back(Hi); |
| 960 | ++NumIntRegs; |
| 961 | } else { |
| 962 | // Pass the high part in memory. |
| 963 | SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy()); |
| 964 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 965 | Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 966 | Hi, PtrOff, DAG.getSrcValue(NULL))); |
| 967 | ArgOffset += 4; |
| 968 | } |
| 969 | break; |
| 970 | } |
| 971 | // Fall through |
| 972 | case MVT::f64: |
| 973 | SDOperand PtrOff = DAG.getConstant(ArgOffset, getPointerTy()); |
| 974 | PtrOff = DAG.getNode(ISD::ADD, MVT::i32, StackPtr, PtrOff); |
| 975 | Stores.push_back(DAG.getNode(ISD::STORE, MVT::Other, Chain, |
| 976 | Args[i].first, PtrOff, |
| 977 | DAG.getSrcValue(NULL))); |
| 978 | ArgOffset += 8; |
| 979 | break; |
| 980 | } |
| 981 | } |
| 982 | if (!Stores.empty()) |
| 983 | Chain = DAG.getNode(ISD::TokenFactor, MVT::Other, Stores); |
| 984 | |
| 985 | // Make sure the instruction takes 8n+4 bytes to make sure the start of the |
| 986 | // arguments and the arguments after the retaddr has been pushed are aligned. |
| 987 | if ((ArgOffset & 7) == 0) |
| 988 | ArgOffset += 4; |
| 989 | |
| 990 | std::vector<MVT::ValueType> RetVals; |
| 991 | MVT::ValueType RetTyVT = getValueType(RetTy); |
| 992 | |
| 993 | RetVals.push_back(MVT::Other); |
| 994 | |
| 995 | // The result values produced have to be legal. Promote the result. |
| 996 | switch (RetTyVT) { |
| 997 | case MVT::isVoid: break; |
| 998 | default: |
| 999 | RetVals.push_back(RetTyVT); |
| 1000 | break; |
| 1001 | case MVT::i1: |
| 1002 | case MVT::i8: |
| 1003 | case MVT::i16: |
| 1004 | RetVals.push_back(MVT::i32); |
| 1005 | break; |
| 1006 | case MVT::f32: |
| 1007 | if (X86ScalarSSE) |
| 1008 | RetVals.push_back(MVT::f32); |
| 1009 | else |
| 1010 | RetVals.push_back(MVT::f64); |
| 1011 | break; |
| 1012 | case MVT::i64: |
| 1013 | RetVals.push_back(MVT::i32); |
| 1014 | RetVals.push_back(MVT::i32); |
| 1015 | break; |
| 1016 | } |
| 1017 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1018 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1019 | // and flag operands which copy the outgoing args into registers. |
| 1020 | SDOperand InFlag; |
| 1021 | for (unsigned i = 0, e = RegValuesToPass.size(); i != e; ++i) { |
| 1022 | unsigned CCReg; |
| 1023 | SDOperand RegToPass = RegValuesToPass[i]; |
| 1024 | switch (RegToPass.getValueType()) { |
| 1025 | default: assert(0 && "Bad thing to pass in regs"); |
| 1026 | case MVT::i8: |
| 1027 | CCReg = (i == 0) ? X86::AL : X86::DL; |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1028 | break; |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1029 | case MVT::i16: |
| 1030 | CCReg = (i == 0) ? X86::AX : X86::DX; |
| 1031 | break; |
| 1032 | case MVT::i32: |
| 1033 | CCReg = (i == 0) ? X86::EAX : X86::EDX; |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | Chain = DAG.getCopyToReg(Chain, CCReg, RegToPass, InFlag); |
| 1038 | InFlag = Chain.getValue(1); |
| 1039 | } |
| 1040 | |
| 1041 | std::vector<MVT::ValueType> NodeTys; |
| 1042 | NodeTys.push_back(MVT::Other); // Returns a chain |
| 1043 | NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. |
| 1044 | std::vector<SDOperand> Ops; |
| 1045 | Ops.push_back(Chain); |
| 1046 | Ops.push_back(Callee); |
| 1047 | if (InFlag.Val) |
| 1048 | Ops.push_back(InFlag); |
| 1049 | |
| 1050 | // FIXME: Do not generate X86ISD::TAILCALL for now. |
| 1051 | Chain = DAG.getNode(X86ISD::CALL, NodeTys, Ops); |
| 1052 | InFlag = Chain.getValue(1); |
| 1053 | |
| 1054 | NodeTys.clear(); |
| 1055 | NodeTys.push_back(MVT::Other); // Returns a chain |
| 1056 | NodeTys.push_back(MVT::Flag); // Returns a flag for retval copy to use. |
| 1057 | Ops.clear(); |
| 1058 | Ops.push_back(Chain); |
| 1059 | Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy())); |
| 1060 | Ops.push_back(DAG.getConstant(ArgOffset, getPointerTy())); |
| 1061 | Ops.push_back(InFlag); |
| 1062 | Chain = DAG.getNode(ISD::CALLSEQ_END, NodeTys, Ops); |
| 1063 | InFlag = Chain.getValue(1); |
| 1064 | |
| 1065 | SDOperand RetVal; |
| 1066 | if (RetTyVT != MVT::isVoid) { |
| 1067 | switch (RetTyVT) { |
| 1068 | default: assert(0 && "Unknown value type to return!"); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1069 | case MVT::i1: |
| 1070 | case MVT::i8: |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1071 | RetVal = DAG.getCopyFromReg(Chain, X86::AL, MVT::i8, InFlag); |
| 1072 | Chain = RetVal.getValue(1); |
| 1073 | if (RetTyVT == MVT::i1) |
| 1074 | RetVal = DAG.getNode(ISD::TRUNCATE, MVT::i1, RetVal); |
| 1075 | break; |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1076 | case MVT::i16: |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1077 | RetVal = DAG.getCopyFromReg(Chain, X86::AX, MVT::i16, InFlag); |
| 1078 | Chain = RetVal.getValue(1); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1079 | break; |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1080 | case MVT::i32: |
| 1081 | RetVal = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag); |
| 1082 | Chain = RetVal.getValue(1); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1083 | break; |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1084 | case MVT::i64: { |
| 1085 | SDOperand Lo = DAG.getCopyFromReg(Chain, X86::EAX, MVT::i32, InFlag); |
| 1086 | SDOperand Hi = DAG.getCopyFromReg(Lo.getValue(1), X86::EDX, MVT::i32, |
| 1087 | Lo.getValue(2)); |
| 1088 | RetVal = DAG.getNode(ISD::BUILD_PAIR, MVT::i64, Lo, Hi); |
| 1089 | Chain = Hi.getValue(1); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1090 | break; |
| 1091 | } |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1092 | case MVT::f32: |
| 1093 | case MVT::f64: { |
| 1094 | std::vector<MVT::ValueType> Tys; |
| 1095 | Tys.push_back(MVT::f64); |
| 1096 | Tys.push_back(MVT::Other); |
| 1097 | Tys.push_back(MVT::Flag); |
| 1098 | std::vector<SDOperand> Ops; |
| 1099 | Ops.push_back(Chain); |
| 1100 | Ops.push_back(InFlag); |
| 1101 | RetVal = DAG.getNode(X86ISD::FP_GET_RESULT, Tys, Ops); |
| 1102 | Chain = RetVal.getValue(1); |
| 1103 | InFlag = RetVal.getValue(2); |
| 1104 | if (X86ScalarSSE) { |
| 1105 | // FIXME: Currently the FST is flagged to the FP_GET_RESULT. This |
| 1106 | // shouldn't be necessary except that RFP cannot be live across |
| 1107 | // multiple blocks. When stackifier is fixed, they can be uncoupled. |
| 1108 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1109 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
| 1110 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 1111 | Tys.clear(); |
| 1112 | Tys.push_back(MVT::Other); |
| 1113 | Ops.clear(); |
| 1114 | Ops.push_back(Chain); |
| 1115 | Ops.push_back(RetVal); |
| 1116 | Ops.push_back(StackSlot); |
| 1117 | Ops.push_back(DAG.getValueType(RetTyVT)); |
| 1118 | Ops.push_back(InFlag); |
| 1119 | Chain = DAG.getNode(X86ISD::FST, Tys, Ops); |
| 1120 | RetVal = DAG.getLoad(RetTyVT, Chain, StackSlot, |
| 1121 | DAG.getSrcValue(NULL)); |
| 1122 | Chain = RetVal.getValue(1); |
| 1123 | } |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1124 | |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1125 | if (RetTyVT == MVT::f32 && !X86ScalarSSE) |
| 1126 | // FIXME: we would really like to remember that this FP_ROUND |
| 1127 | // operation is okay to eliminate if we allow excess FP precision. |
| 1128 | RetVal = DAG.getNode(ISD::FP_ROUND, MVT::f32, RetVal); |
| 1129 | break; |
| 1130 | } |
| 1131 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1132 | } |
Nate Begeman | 7e5496d | 2006-02-17 00:03:04 +0000 | [diff] [blame] | 1133 | |
| 1134 | return std::make_pair(RetVal, Chain); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | SDOperand X86TargetLowering::getReturnAddressFrameIndex(SelectionDAG &DAG) { |
| 1138 | if (ReturnAddrIndex == 0) { |
| 1139 | // Set up a frame object for the return address. |
| 1140 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1141 | ReturnAddrIndex = MF.getFrameInfo()->CreateFixedObject(4, -4); |
| 1142 | } |
| 1143 | |
| 1144 | return DAG.getFrameIndex(ReturnAddrIndex, MVT::i32); |
| 1145 | } |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | std::pair<SDOperand, SDOperand> X86TargetLowering:: |
| 1150 | LowerFrameReturnAddress(bool isFrameAddress, SDOperand Chain, unsigned Depth, |
| 1151 | SelectionDAG &DAG) { |
| 1152 | SDOperand Result; |
| 1153 | if (Depth) // Depths > 0 not supported yet! |
| 1154 | Result = DAG.getConstant(0, getPointerTy()); |
| 1155 | else { |
| 1156 | SDOperand RetAddrFI = getReturnAddressFrameIndex(DAG); |
| 1157 | if (!isFrameAddress) |
| 1158 | // Just load the return address |
| 1159 | Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), RetAddrFI, |
| 1160 | DAG.getSrcValue(NULL)); |
| 1161 | else |
| 1162 | Result = DAG.getNode(ISD::SUB, MVT::i32, RetAddrFI, |
| 1163 | DAG.getConstant(4, MVT::i32)); |
| 1164 | } |
| 1165 | return std::make_pair(Result, Chain); |
| 1166 | } |
| 1167 | |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1168 | /// getCondBrOpcodeForX86CC - Returns the X86 conditional branch opcode |
| 1169 | /// which corresponds to the condition code. |
| 1170 | static unsigned getCondBrOpcodeForX86CC(unsigned X86CC) { |
| 1171 | switch (X86CC) { |
| 1172 | default: assert(0 && "Unknown X86 conditional code!"); |
| 1173 | case X86ISD::COND_A: return X86::JA; |
| 1174 | case X86ISD::COND_AE: return X86::JAE; |
| 1175 | case X86ISD::COND_B: return X86::JB; |
| 1176 | case X86ISD::COND_BE: return X86::JBE; |
| 1177 | case X86ISD::COND_E: return X86::JE; |
| 1178 | case X86ISD::COND_G: return X86::JG; |
| 1179 | case X86ISD::COND_GE: return X86::JGE; |
| 1180 | case X86ISD::COND_L: return X86::JL; |
| 1181 | case X86ISD::COND_LE: return X86::JLE; |
| 1182 | case X86ISD::COND_NE: return X86::JNE; |
| 1183 | case X86ISD::COND_NO: return X86::JNO; |
| 1184 | case X86ISD::COND_NP: return X86::JNP; |
| 1185 | case X86ISD::COND_NS: return X86::JNS; |
| 1186 | case X86ISD::COND_O: return X86::JO; |
| 1187 | case X86ISD::COND_P: return X86::JP; |
| 1188 | case X86ISD::COND_S: return X86::JS; |
| 1189 | } |
| 1190 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1191 | |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 1192 | /// translateX86CC - do a one to one translation of a ISD::CondCode to the X86 |
| 1193 | /// specific condition code. It returns a false if it cannot do a direct |
| 1194 | /// translation. X86CC is the translated CondCode. Flip is set to true if the |
| 1195 | /// the order of comparison operands should be flipped. |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 1196 | static bool translateX86CC(ISD::CondCode SetCCOpcode, bool isFP, |
| 1197 | unsigned &X86CC, bool &Flip) { |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 1198 | Flip = false; |
| 1199 | X86CC = X86ISD::COND_INVALID; |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1200 | if (!isFP) { |
| 1201 | switch (SetCCOpcode) { |
| 1202 | default: break; |
| 1203 | case ISD::SETEQ: X86CC = X86ISD::COND_E; break; |
| 1204 | case ISD::SETGT: X86CC = X86ISD::COND_G; break; |
| 1205 | case ISD::SETGE: X86CC = X86ISD::COND_GE; break; |
| 1206 | case ISD::SETLT: X86CC = X86ISD::COND_L; break; |
| 1207 | case ISD::SETLE: X86CC = X86ISD::COND_LE; break; |
| 1208 | case ISD::SETNE: X86CC = X86ISD::COND_NE; break; |
| 1209 | case ISD::SETULT: X86CC = X86ISD::COND_B; break; |
| 1210 | case ISD::SETUGT: X86CC = X86ISD::COND_A; break; |
| 1211 | case ISD::SETULE: X86CC = X86ISD::COND_BE; break; |
| 1212 | case ISD::SETUGE: X86CC = X86ISD::COND_AE; break; |
| 1213 | } |
| 1214 | } else { |
| 1215 | // On a floating point condition, the flags are set as follows: |
| 1216 | // ZF PF CF op |
| 1217 | // 0 | 0 | 0 | X > Y |
| 1218 | // 0 | 0 | 1 | X < Y |
| 1219 | // 1 | 0 | 0 | X == Y |
| 1220 | // 1 | 1 | 1 | unordered |
| 1221 | switch (SetCCOpcode) { |
| 1222 | default: break; |
| 1223 | case ISD::SETUEQ: |
| 1224 | case ISD::SETEQ: X86CC = X86ISD::COND_E; break; |
Evan Cheng | b3b41c4 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1225 | case ISD::SETOLT: Flip = true; // Fallthrough |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1226 | case ISD::SETOGT: |
| 1227 | case ISD::SETGT: X86CC = X86ISD::COND_A; break; |
Evan Cheng | b3b41c4 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1228 | case ISD::SETOLE: Flip = true; // Fallthrough |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1229 | case ISD::SETOGE: |
| 1230 | case ISD::SETGE: X86CC = X86ISD::COND_AE; break; |
Evan Cheng | b3b41c4 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1231 | case ISD::SETUGT: Flip = true; // Fallthrough |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1232 | case ISD::SETULT: |
| 1233 | case ISD::SETLT: X86CC = X86ISD::COND_B; break; |
Evan Cheng | b3b41c4 | 2006-04-17 07:24:10 +0000 | [diff] [blame] | 1234 | case ISD::SETUGE: Flip = true; // Fallthrough |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1235 | case ISD::SETULE: |
| 1236 | case ISD::SETLE: X86CC = X86ISD::COND_BE; break; |
| 1237 | case ISD::SETONE: |
| 1238 | case ISD::SETNE: X86CC = X86ISD::COND_NE; break; |
| 1239 | case ISD::SETUO: X86CC = X86ISD::COND_P; break; |
| 1240 | case ISD::SETO: X86CC = X86ISD::COND_NP; break; |
| 1241 | } |
| 1242 | } |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 1243 | |
| 1244 | return X86CC != X86ISD::COND_INVALID; |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 1247 | static bool translateX86CC(SDOperand CC, bool isFP, unsigned &X86CC, |
| 1248 | bool &Flip) { |
| 1249 | return translateX86CC(cast<CondCodeSDNode>(CC)->get(), isFP, X86CC, Flip); |
| 1250 | } |
| 1251 | |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1252 | /// hasFPCMov - is there a floating point cmov for the specific X86 condition |
| 1253 | /// code. Current x86 isa includes the following FP cmov instructions: |
Evan Cheng | 73a1ad9 | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 1254 | /// fcmovb, fcomvbe, fcomve, fcmovu, fcmovae, fcmova, fcmovne, fcmovnu. |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1255 | static bool hasFPCMov(unsigned X86CC) { |
Evan Cheng | 73a1ad9 | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 1256 | switch (X86CC) { |
| 1257 | default: |
| 1258 | return false; |
| 1259 | case X86ISD::COND_B: |
| 1260 | case X86ISD::COND_BE: |
| 1261 | case X86ISD::COND_E: |
| 1262 | case X86ISD::COND_P: |
| 1263 | case X86ISD::COND_A: |
| 1264 | case X86ISD::COND_AE: |
| 1265 | case X86ISD::COND_NE: |
| 1266 | case X86ISD::COND_NP: |
| 1267 | return true; |
| 1268 | } |
| 1269 | } |
| 1270 | |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1271 | MachineBasicBlock * |
| 1272 | X86TargetLowering::InsertAtEndOfBasicBlock(MachineInstr *MI, |
| 1273 | MachineBasicBlock *BB) { |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1274 | switch (MI->getOpcode()) { |
| 1275 | default: assert(false && "Unexpected instr type to insert"); |
| 1276 | case X86::CMOV_FR32: |
Evan Cheng | 617a6a8 | 2006-04-10 07:23:14 +0000 | [diff] [blame] | 1277 | case X86::CMOV_FR64: |
| 1278 | case X86::CMOV_V4F32: |
| 1279 | case X86::CMOV_V2F64: |
| 1280 | case X86::CMOV_V2I64: { |
Chris Lattner | c642aa5 | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 1281 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 1282 | // diamond control-flow pattern. The incoming instruction knows the |
| 1283 | // destination vreg to set, the condition code register to branch on, the |
| 1284 | // true/false values to select between, and a branch opcode to use. |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1285 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 1286 | ilist<MachineBasicBlock>::iterator It = BB; |
| 1287 | ++It; |
| 1288 | |
| 1289 | // thisMBB: |
| 1290 | // ... |
| 1291 | // TrueVal = ... |
| 1292 | // cmpTY ccX, r1, r2 |
| 1293 | // bCC copy1MBB |
| 1294 | // fallthrough --> copy0MBB |
| 1295 | MachineBasicBlock *thisMBB = BB; |
| 1296 | MachineBasicBlock *copy0MBB = new MachineBasicBlock(LLVM_BB); |
| 1297 | MachineBasicBlock *sinkMBB = new MachineBasicBlock(LLVM_BB); |
| 1298 | unsigned Opc = getCondBrOpcodeForX86CC(MI->getOperand(3).getImmedValue()); |
| 1299 | BuildMI(BB, Opc, 1).addMBB(sinkMBB); |
| 1300 | MachineFunction *F = BB->getParent(); |
| 1301 | F->getBasicBlockList().insert(It, copy0MBB); |
| 1302 | F->getBasicBlockList().insert(It, sinkMBB); |
Nate Begeman | ed728c1 | 2006-03-27 01:32:24 +0000 | [diff] [blame] | 1303 | // Update machine-CFG edges by first adding all successors of the current |
| 1304 | // block to the new block which will contain the Phi node for the select. |
| 1305 | for(MachineBasicBlock::succ_iterator i = BB->succ_begin(), |
| 1306 | e = BB->succ_end(); i != e; ++i) |
| 1307 | sinkMBB->addSuccessor(*i); |
| 1308 | // Next, remove all successors of the current block, and add the true |
| 1309 | // and fallthrough blocks as its successors. |
| 1310 | while(!BB->succ_empty()) |
| 1311 | BB->removeSuccessor(BB->succ_begin()); |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1312 | BB->addSuccessor(copy0MBB); |
| 1313 | BB->addSuccessor(sinkMBB); |
| 1314 | |
| 1315 | // copy0MBB: |
| 1316 | // %FalseValue = ... |
| 1317 | // # fallthrough to sinkMBB |
| 1318 | BB = copy0MBB; |
| 1319 | |
| 1320 | // Update machine-CFG edges |
| 1321 | BB->addSuccessor(sinkMBB); |
| 1322 | |
| 1323 | // sinkMBB: |
| 1324 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 1325 | // ... |
| 1326 | BB = sinkMBB; |
| 1327 | BuildMI(BB, X86::PHI, 4, MI->getOperand(0).getReg()) |
| 1328 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 1329 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1330 | |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1331 | delete MI; // The pseudo instruction is gone now. |
| 1332 | return BB; |
| 1333 | } |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1334 | |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1335 | case X86::FP_TO_INT16_IN_MEM: |
| 1336 | case X86::FP_TO_INT32_IN_MEM: |
| 1337 | case X86::FP_TO_INT64_IN_MEM: { |
| 1338 | // Change the floating point control register to use "round towards zero" |
| 1339 | // mode when truncating to an integer value. |
| 1340 | MachineFunction *F = BB->getParent(); |
| 1341 | int CWFrameIdx = F->getFrameInfo()->CreateStackObject(2, 2); |
| 1342 | addFrameReference(BuildMI(BB, X86::FNSTCW16m, 4), CWFrameIdx); |
| 1343 | |
| 1344 | // Load the old value of the high byte of the control word... |
| 1345 | unsigned OldCW = |
| 1346 | F->getSSARegMap()->createVirtualRegister(X86::R16RegisterClass); |
| 1347 | addFrameReference(BuildMI(BB, X86::MOV16rm, 4, OldCW), CWFrameIdx); |
| 1348 | |
| 1349 | // Set the high part to be round to zero... |
| 1350 | addFrameReference(BuildMI(BB, X86::MOV16mi, 5), CWFrameIdx).addImm(0xC7F); |
| 1351 | |
| 1352 | // Reload the modified control word now... |
| 1353 | addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx); |
| 1354 | |
| 1355 | // Restore the memory image of control word to original value |
| 1356 | addFrameReference(BuildMI(BB, X86::MOV16mr, 5), CWFrameIdx).addReg(OldCW); |
| 1357 | |
| 1358 | // Get the X86 opcode to use. |
| 1359 | unsigned Opc; |
| 1360 | switch (MI->getOpcode()) { |
Chris Lattner | ccd2a20 | 2006-01-28 10:34:47 +0000 | [diff] [blame] | 1361 | default: assert(0 && "illegal opcode!"); |
Evan Cheng | 911c68d | 2006-01-16 21:21:29 +0000 | [diff] [blame] | 1362 | case X86::FP_TO_INT16_IN_MEM: Opc = X86::FpIST16m; break; |
| 1363 | case X86::FP_TO_INT32_IN_MEM: Opc = X86::FpIST32m; break; |
| 1364 | case X86::FP_TO_INT64_IN_MEM: Opc = X86::FpIST64m; break; |
| 1365 | } |
| 1366 | |
| 1367 | X86AddressMode AM; |
| 1368 | MachineOperand &Op = MI->getOperand(0); |
| 1369 | if (Op.isRegister()) { |
| 1370 | AM.BaseType = X86AddressMode::RegBase; |
| 1371 | AM.Base.Reg = Op.getReg(); |
| 1372 | } else { |
| 1373 | AM.BaseType = X86AddressMode::FrameIndexBase; |
| 1374 | AM.Base.FrameIndex = Op.getFrameIndex(); |
| 1375 | } |
| 1376 | Op = MI->getOperand(1); |
| 1377 | if (Op.isImmediate()) |
| 1378 | AM.Scale = Op.getImmedValue(); |
| 1379 | Op = MI->getOperand(2); |
| 1380 | if (Op.isImmediate()) |
| 1381 | AM.IndexReg = Op.getImmedValue(); |
| 1382 | Op = MI->getOperand(3); |
| 1383 | if (Op.isGlobalAddress()) { |
| 1384 | AM.GV = Op.getGlobal(); |
| 1385 | } else { |
| 1386 | AM.Disp = Op.getImmedValue(); |
| 1387 | } |
| 1388 | addFullAddress(BuildMI(BB, Opc, 5), AM).addReg(MI->getOperand(4).getReg()); |
| 1389 | |
| 1390 | // Reload the original control word now. |
| 1391 | addFrameReference(BuildMI(BB, X86::FLDCW16m, 4), CWFrameIdx); |
| 1392 | |
| 1393 | delete MI; // The pseudo instruction is gone now. |
| 1394 | return BB; |
| 1395 | } |
| 1396 | } |
Evan Cheng | 339edad | 2006-01-11 00:33:36 +0000 | [diff] [blame] | 1397 | } |
| 1398 | |
| 1399 | |
| 1400 | //===----------------------------------------------------------------------===// |
| 1401 | // X86 Custom Lowering Hooks |
| 1402 | //===----------------------------------------------------------------------===// |
| 1403 | |
Evan Cheng | af598d2 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 1404 | /// DarwinGVRequiresExtraLoad - true if accessing the GV requires an extra |
| 1405 | /// load. For Darwin, external and weak symbols are indirect, loading the value |
| 1406 | /// at address GV rather then the value of GV itself. This means that the |
| 1407 | /// GlobalAddress must be in the base or index register of the address, not the |
| 1408 | /// GV offset field. |
| 1409 | static bool DarwinGVRequiresExtraLoad(GlobalValue *GV) { |
| 1410 | return (GV->hasWeakLinkage() || GV->hasLinkOnceLinkage() || |
| 1411 | (GV->isExternal() && !GV->hasNotBeenReadFromBytecode())); |
| 1412 | } |
| 1413 | |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1414 | /// isUndefOrInRange - Op is either an undef node or a ConstantSDNode. Return |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1415 | /// true if Op is undef or if its value falls within the specified range (L, H]. |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1416 | static bool isUndefOrInRange(SDOperand Op, unsigned Low, unsigned Hi) { |
| 1417 | if (Op.getOpcode() == ISD::UNDEF) |
| 1418 | return true; |
| 1419 | |
| 1420 | unsigned Val = cast<ConstantSDNode>(Op)->getValue(); |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1421 | return (Val >= Low && Val < Hi); |
| 1422 | } |
| 1423 | |
| 1424 | /// isUndefOrEqual - Op is either an undef node or a ConstantSDNode. Return |
| 1425 | /// true if Op is undef or if its value equal to the specified value. |
| 1426 | static bool isUndefOrEqual(SDOperand Op, unsigned Val) { |
| 1427 | if (Op.getOpcode() == ISD::UNDEF) |
| 1428 | return true; |
| 1429 | return cast<ConstantSDNode>(Op)->getValue() == Val; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
Evan Cheng | 68ad48b | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 1432 | /// isPSHUFDMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1433 | /// specifies a shuffle of elements that is suitable for input to PSHUFD. |
| 1434 | bool X86::isPSHUFDMask(SDNode *N) { |
| 1435 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1436 | |
| 1437 | if (N->getNumOperands() != 4) |
| 1438 | return false; |
| 1439 | |
| 1440 | // Check if the value doesn't reference the second vector. |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1441 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1442 | SDOperand Arg = N->getOperand(i); |
| 1443 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1444 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1445 | if (cast<ConstantSDNode>(Arg)->getValue() >= 4) |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
| 1448 | |
| 1449 | return true; |
| 1450 | } |
| 1451 | |
| 1452 | /// isPSHUFHWMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | 59a6355 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 1453 | /// specifies a shuffle of elements that is suitable for input to PSHUFHW. |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1454 | bool X86::isPSHUFHWMask(SDNode *N) { |
| 1455 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1456 | |
| 1457 | if (N->getNumOperands() != 8) |
| 1458 | return false; |
| 1459 | |
| 1460 | // Lower quadword copied in order. |
| 1461 | for (unsigned i = 0; i != 4; ++i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1462 | SDOperand Arg = N->getOperand(i); |
| 1463 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1464 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1465 | if (cast<ConstantSDNode>(Arg)->getValue() != i) |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
| 1468 | |
| 1469 | // Upper quadword shuffled. |
| 1470 | for (unsigned i = 4; i != 8; ++i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1471 | SDOperand Arg = N->getOperand(i); |
| 1472 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1473 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1474 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1475 | if (Val < 4 || Val > 7) |
| 1476 | return false; |
| 1477 | } |
| 1478 | |
| 1479 | return true; |
| 1480 | } |
| 1481 | |
| 1482 | /// isPSHUFLWMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | 59a6355 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 1483 | /// specifies a shuffle of elements that is suitable for input to PSHUFLW. |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1484 | bool X86::isPSHUFLWMask(SDNode *N) { |
| 1485 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1486 | |
| 1487 | if (N->getNumOperands() != 8) |
| 1488 | return false; |
| 1489 | |
| 1490 | // Upper quadword copied in order. |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1491 | for (unsigned i = 4; i != 8; ++i) |
| 1492 | if (!isUndefOrEqual(N->getOperand(i), i)) |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1493 | return false; |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1494 | |
| 1495 | // Lower quadword shuffled. |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1496 | for (unsigned i = 0; i != 4; ++i) |
| 1497 | if (!isUndefOrInRange(N->getOperand(i), 0, 4)) |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1498 | return false; |
Evan Cheng | 68ad48b | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 1499 | |
| 1500 | return true; |
| 1501 | } |
| 1502 | |
Evan Cheng | d27fb3e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1503 | /// isSHUFPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1504 | /// specifies a shuffle of elements that is suitable for input to SHUFP*. |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1505 | static bool isSHUFPMask(std::vector<SDOperand> &N) { |
| 1506 | unsigned NumElems = N.size(); |
| 1507 | if (NumElems != 2 && NumElems != 4) return false; |
Evan Cheng | d27fb3e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1508 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1509 | unsigned Half = NumElems / 2; |
| 1510 | for (unsigned i = 0; i < Half; ++i) |
| 1511 | if (!isUndefOrInRange(N[i], 0, NumElems)) |
| 1512 | return false; |
| 1513 | for (unsigned i = Half; i < NumElems; ++i) |
| 1514 | if (!isUndefOrInRange(N[i], NumElems, NumElems*2)) |
| 1515 | return false; |
Evan Cheng | d27fb3e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1516 | |
| 1517 | return true; |
| 1518 | } |
| 1519 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1520 | bool X86::isSHUFPMask(SDNode *N) { |
| 1521 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1522 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 1523 | return ::isSHUFPMask(Ops); |
| 1524 | } |
| 1525 | |
| 1526 | /// isCommutedSHUFP - Returns true if the shuffle mask is except |
| 1527 | /// the reverse of what x86 shuffles want. x86 shuffles requires the lower |
| 1528 | /// half elements to come from vector 1 (which would equal the dest.) and |
| 1529 | /// the upper half to come from vector 2. |
| 1530 | static bool isCommutedSHUFP(std::vector<SDOperand> &Ops) { |
| 1531 | unsigned NumElems = Ops.size(); |
| 1532 | if (NumElems != 2 && NumElems != 4) return false; |
| 1533 | |
| 1534 | unsigned Half = NumElems / 2; |
| 1535 | for (unsigned i = 0; i < Half; ++i) |
| 1536 | if (!isUndefOrInRange(Ops[i], NumElems, NumElems*2)) |
| 1537 | return false; |
| 1538 | for (unsigned i = Half; i < NumElems; ++i) |
| 1539 | if (!isUndefOrInRange(Ops[i], 0, NumElems)) |
| 1540 | return false; |
| 1541 | return true; |
| 1542 | } |
| 1543 | |
| 1544 | static bool isCommutedSHUFP(SDNode *N) { |
| 1545 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1546 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 1547 | return isCommutedSHUFP(Ops); |
| 1548 | } |
| 1549 | |
Evan Cheng | 2595a68 | 2006-03-24 02:58:06 +0000 | [diff] [blame] | 1550 | /// isMOVHLPSMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1551 | /// specifies a shuffle of elements that is suitable for input to MOVHLPS. |
| 1552 | bool X86::isMOVHLPSMask(SDNode *N) { |
| 1553 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1554 | |
Evan Cheng | 1a194a5 | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1555 | if (N->getNumOperands() != 4) |
Evan Cheng | 2595a68 | 2006-03-24 02:58:06 +0000 | [diff] [blame] | 1556 | return false; |
| 1557 | |
Evan Cheng | 1a194a5 | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1558 | // Expect bit0 == 6, bit1 == 7, bit2 == 2, bit3 == 3 |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1559 | return isUndefOrEqual(N->getOperand(0), 6) && |
| 1560 | isUndefOrEqual(N->getOperand(1), 7) && |
| 1561 | isUndefOrEqual(N->getOperand(2), 2) && |
| 1562 | isUndefOrEqual(N->getOperand(3), 3); |
Evan Cheng | 1a194a5 | 2006-03-28 06:50:32 +0000 | [diff] [blame] | 1563 | } |
| 1564 | |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1565 | /// isMOVLPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1566 | /// specifies a shuffle of elements that is suitable for input to MOVLP{S|D}. |
| 1567 | bool X86::isMOVLPMask(SDNode *N) { |
| 1568 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1569 | |
| 1570 | unsigned NumElems = N->getNumOperands(); |
| 1571 | if (NumElems != 2 && NumElems != 4) |
| 1572 | return false; |
| 1573 | |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1574 | for (unsigned i = 0; i < NumElems/2; ++i) |
| 1575 | if (!isUndefOrEqual(N->getOperand(i), i + NumElems)) |
| 1576 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1577 | |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1578 | for (unsigned i = NumElems/2; i < NumElems; ++i) |
| 1579 | if (!isUndefOrEqual(N->getOperand(i), i)) |
| 1580 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1581 | |
| 1582 | return true; |
| 1583 | } |
| 1584 | |
| 1585 | /// isMOVHPMask - Return true if the specified VECTOR_SHUFFLE operand |
Evan Cheng | 7855e4d | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 1586 | /// specifies a shuffle of elements that is suitable for input to MOVHP{S|D} |
| 1587 | /// and MOVLHPS. |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1588 | bool X86::isMOVHPMask(SDNode *N) { |
| 1589 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1590 | |
| 1591 | unsigned NumElems = N->getNumOperands(); |
| 1592 | if (NumElems != 2 && NumElems != 4) |
| 1593 | return false; |
| 1594 | |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1595 | for (unsigned i = 0; i < NumElems/2; ++i) |
| 1596 | if (!isUndefOrEqual(N->getOperand(i), i)) |
| 1597 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1598 | |
| 1599 | for (unsigned i = 0; i < NumElems/2; ++i) { |
| 1600 | SDOperand Arg = N->getOperand(i + NumElems/2); |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1601 | if (!isUndefOrEqual(Arg, i + NumElems)) |
| 1602 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | return true; |
| 1606 | } |
| 1607 | |
Evan Cheng | 5df7588 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1608 | /// isUNPCKLMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1609 | /// specifies a shuffle of elements that is suitable for input to UNPCKL. |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1610 | bool static isUNPCKLMask(std::vector<SDOperand> &N, bool V2IsSplat = false) { |
| 1611 | unsigned NumElems = N.size(); |
Evan Cheng | 5df7588 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1612 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
| 1613 | return false; |
| 1614 | |
| 1615 | for (unsigned i = 0, j = 0; i != NumElems; i += 2, ++j) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1616 | SDOperand BitI = N[i]; |
| 1617 | SDOperand BitI1 = N[i+1]; |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1618 | if (!isUndefOrEqual(BitI, j)) |
| 1619 | return false; |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1620 | if (V2IsSplat) { |
| 1621 | if (isUndefOrEqual(BitI1, NumElems)) |
| 1622 | return false; |
| 1623 | } else { |
| 1624 | if (!isUndefOrEqual(BitI1, j + NumElems)) |
| 1625 | return false; |
| 1626 | } |
Evan Cheng | 5df7588 | 2006-03-28 00:39:58 +0000 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | return true; |
| 1630 | } |
| 1631 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1632 | bool X86::isUNPCKLMask(SDNode *N, bool V2IsSplat) { |
| 1633 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1634 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 1635 | return ::isUNPCKLMask(Ops, V2IsSplat); |
| 1636 | } |
| 1637 | |
Evan Cheng | 2bc3280 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1638 | /// isUNPCKHMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1639 | /// specifies a shuffle of elements that is suitable for input to UNPCKH. |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1640 | bool static isUNPCKHMask(std::vector<SDOperand> &N, bool V2IsSplat = false) { |
| 1641 | unsigned NumElems = N.size(); |
Evan Cheng | 2bc3280 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1642 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
| 1643 | return false; |
| 1644 | |
| 1645 | for (unsigned i = 0, j = 0; i != NumElems; i += 2, ++j) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1646 | SDOperand BitI = N[i]; |
| 1647 | SDOperand BitI1 = N[i+1]; |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1648 | if (!isUndefOrEqual(BitI, j + NumElems/2)) |
| 1649 | return false; |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1650 | if (V2IsSplat) { |
| 1651 | if (isUndefOrEqual(BitI1, NumElems)) |
| 1652 | return false; |
| 1653 | } else { |
| 1654 | if (!isUndefOrEqual(BitI1, j + NumElems/2 + NumElems)) |
| 1655 | return false; |
| 1656 | } |
Evan Cheng | 2bc3280 | 2006-03-28 02:43:26 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | return true; |
| 1660 | } |
| 1661 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1662 | bool X86::isUNPCKHMask(SDNode *N, bool V2IsSplat) { |
| 1663 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1664 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 1665 | return ::isUNPCKHMask(Ops, V2IsSplat); |
| 1666 | } |
| 1667 | |
Evan Cheng | f3b52c8 | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1668 | /// isUNPCKL_v_undef_Mask - Special case of isUNPCKLMask for canonical form |
| 1669 | /// of vector_shuffle v, v, <0, 4, 1, 5>, i.e. vector_shuffle v, undef, |
| 1670 | /// <0, 0, 1, 1> |
| 1671 | bool X86::isUNPCKL_v_undef_Mask(SDNode *N) { |
| 1672 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1673 | |
| 1674 | unsigned NumElems = N->getNumOperands(); |
| 1675 | if (NumElems != 4 && NumElems != 8 && NumElems != 16) |
| 1676 | return false; |
| 1677 | |
| 1678 | for (unsigned i = 0, j = 0; i != NumElems; i += 2, ++j) { |
| 1679 | SDOperand BitI = N->getOperand(i); |
| 1680 | SDOperand BitI1 = N->getOperand(i+1); |
| 1681 | |
Evan Cheng | ac84726 | 2006-04-07 21:53:05 +0000 | [diff] [blame] | 1682 | if (!isUndefOrEqual(BitI, j)) |
| 1683 | return false; |
| 1684 | if (!isUndefOrEqual(BitI1, j)) |
| 1685 | return false; |
Evan Cheng | f3b52c8 | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | return true; |
| 1689 | } |
| 1690 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1691 | /// isMOVLMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1692 | /// specifies a shuffle of elements that is suitable for input to MOVSS, |
| 1693 | /// MOVSD, and MOVD, i.e. setting the lowest element. |
| 1694 | static bool isMOVLMask(std::vector<SDOperand> &N) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1695 | unsigned NumElems = N.size(); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1696 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
Evan Cheng | 12ba3e2 | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1697 | return false; |
| 1698 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1699 | if (!isUndefOrEqual(N[0], NumElems)) |
Evan Cheng | 12ba3e2 | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1700 | return false; |
| 1701 | |
| 1702 | for (unsigned i = 1; i < NumElems; ++i) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1703 | SDOperand Arg = N[i]; |
Evan Cheng | 12ba3e2 | 2006-04-11 00:19:04 +0000 | [diff] [blame] | 1704 | if (!isUndefOrEqual(Arg, i)) |
| 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | return true; |
| 1709 | } |
Evan Cheng | f3b52c8 | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 1710 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1711 | bool X86::isMOVLMask(SDNode *N) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1712 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1713 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1714 | return ::isMOVLMask(Ops); |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1715 | } |
| 1716 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1717 | /// isCommutedMOVL - Returns true if the shuffle mask is except the reverse |
| 1718 | /// of what x86 movss want. X86 movs requires the lowest element to be lowest |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1719 | /// element of vector 2 and the other elements to come from vector 1 in order. |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1720 | static bool isCommutedMOVL(std::vector<SDOperand> &Ops, bool V2IsSplat = false) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1721 | unsigned NumElems = Ops.size(); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1722 | if (NumElems != 2 && NumElems != 4 && NumElems != 8 && NumElems != 16) |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1723 | return false; |
| 1724 | |
| 1725 | if (!isUndefOrEqual(Ops[0], 0)) |
| 1726 | return false; |
| 1727 | |
| 1728 | for (unsigned i = 1; i < NumElems; ++i) { |
| 1729 | SDOperand Arg = Ops[i]; |
| 1730 | if (V2IsSplat) { |
| 1731 | if (!isUndefOrEqual(Arg, NumElems)) |
| 1732 | return false; |
| 1733 | } else { |
| 1734 | if (!isUndefOrEqual(Arg, i+NumElems)) |
| 1735 | return false; |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | return true; |
| 1740 | } |
| 1741 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1742 | static bool isCommutedMOVL(SDNode *N, bool V2IsSplat = false) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1743 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1744 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 1745 | return isCommutedMOVL(Ops, V2IsSplat); |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 1746 | } |
| 1747 | |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1748 | /// isMOVSHDUPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1749 | /// specifies a shuffle of elements that is suitable for input to MOVSHDUP. |
| 1750 | bool X86::isMOVSHDUPMask(SDNode *N) { |
| 1751 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1752 | |
| 1753 | if (N->getNumOperands() != 4) |
| 1754 | return false; |
| 1755 | |
| 1756 | // Expect 1, 1, 3, 3 |
| 1757 | for (unsigned i = 0; i < 2; ++i) { |
| 1758 | SDOperand Arg = N->getOperand(i); |
| 1759 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1760 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1761 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1762 | if (Val != 1) return false; |
| 1763 | } |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1764 | |
| 1765 | bool HasHi = false; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1766 | for (unsigned i = 2; i < 4; ++i) { |
| 1767 | SDOperand Arg = N->getOperand(i); |
| 1768 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1769 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1770 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1771 | if (Val != 3) return false; |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1772 | HasHi = true; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1773 | } |
Evan Cheng | 65bb720 | 2006-04-15 03:13:24 +0000 | [diff] [blame] | 1774 | |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1775 | // Don't use movshdup if it can be done with a shufps. |
| 1776 | return HasHi; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | /// isMOVSLDUPMask - Return true if the specified VECTOR_SHUFFLE operand |
| 1780 | /// specifies a shuffle of elements that is suitable for input to MOVSLDUP. |
| 1781 | bool X86::isMOVSLDUPMask(SDNode *N) { |
| 1782 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1783 | |
| 1784 | if (N->getNumOperands() != 4) |
| 1785 | return false; |
| 1786 | |
| 1787 | // Expect 0, 0, 2, 2 |
| 1788 | for (unsigned i = 0; i < 2; ++i) { |
| 1789 | SDOperand Arg = N->getOperand(i); |
| 1790 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1791 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1792 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1793 | if (Val != 0) return false; |
| 1794 | } |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1795 | |
| 1796 | bool HasHi = false; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1797 | for (unsigned i = 2; i < 4; ++i) { |
| 1798 | SDOperand Arg = N->getOperand(i); |
| 1799 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1800 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1801 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1802 | if (Val != 2) return false; |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1803 | HasHi = true; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1804 | } |
Evan Cheng | 65bb720 | 2006-04-15 03:13:24 +0000 | [diff] [blame] | 1805 | |
Evan Cheng | 6222cf2 | 2006-04-15 05:37:34 +0000 | [diff] [blame] | 1806 | // Don't use movshdup if it can be done with a shufps. |
| 1807 | return HasHi; |
Evan Cheng | 5d247f8 | 2006-04-14 21:59:03 +0000 | [diff] [blame] | 1808 | } |
| 1809 | |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1810 | /// isSplatMask - Return true if the specified VECTOR_SHUFFLE operand specifies |
| 1811 | /// a splat of a single element. |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 1812 | static bool isSplatMask(SDNode *N) { |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1813 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1814 | |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1815 | // This is a splat operation if each element of the permute is the same, and |
| 1816 | // if the value doesn't reference the second vector. |
Evan Cheng | 4a1b0d3 | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 1817 | unsigned NumElems = N->getNumOperands(); |
| 1818 | SDOperand ElementBase; |
| 1819 | unsigned i = 0; |
| 1820 | for (; i != NumElems; ++i) { |
| 1821 | SDOperand Elt = N->getOperand(i); |
| 1822 | if (ConstantSDNode *EltV = dyn_cast<ConstantSDNode>(Elt)) { |
| 1823 | ElementBase = Elt; |
| 1824 | break; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | if (!ElementBase.Val) |
| 1829 | return false; |
| 1830 | |
| 1831 | for (; i != NumElems; ++i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1832 | SDOperand Arg = N->getOperand(i); |
| 1833 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1834 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
Evan Cheng | 4a1b0d3 | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 1835 | if (Arg != ElementBase) return false; |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
| 1838 | // Make sure it is a splat of the first vector operand. |
Evan Cheng | 4a1b0d3 | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 1839 | return cast<ConstantSDNode>(ElementBase)->getValue() < NumElems; |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 1842 | /// isSplatMask - Return true if the specified VECTOR_SHUFFLE operand specifies |
| 1843 | /// a splat of a single element and it's a 2 or 4 element mask. |
| 1844 | bool X86::isSplatMask(SDNode *N) { |
| 1845 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1846 | |
Evan Cheng | 4a1b0d3 | 2006-04-19 23:28:59 +0000 | [diff] [blame] | 1847 | // We can only splat 64-bit, and 32-bit quantities with a single instruction. |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 1848 | if (N->getNumOperands() != 4 && N->getNumOperands() != 2) |
| 1849 | return false; |
| 1850 | return ::isSplatMask(N); |
| 1851 | } |
| 1852 | |
Evan Cheng | 8fdbdf2 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 1853 | /// getShuffleSHUFImmediate - Return the appropriate immediate to shuffle |
| 1854 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUF* and SHUFP* |
| 1855 | /// instructions. |
| 1856 | unsigned X86::getShuffleSHUFImmediate(SDNode *N) { |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 1857 | unsigned NumOperands = N->getNumOperands(); |
| 1858 | unsigned Shift = (NumOperands == 4) ? 2 : 1; |
| 1859 | unsigned Mask = 0; |
Evan Cheng | 8160fd3 | 2006-03-28 23:41:33 +0000 | [diff] [blame] | 1860 | for (unsigned i = 0; i < NumOperands; ++i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1861 | unsigned Val = 0; |
| 1862 | SDOperand Arg = N->getOperand(NumOperands-i-1); |
| 1863 | if (Arg.getOpcode() != ISD::UNDEF) |
| 1864 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | d27fb3e | 2006-03-24 01:18:28 +0000 | [diff] [blame] | 1865 | if (Val >= NumOperands) Val -= NumOperands; |
Evan Cheng | 8fdbdf2 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 1866 | Mask |= Val; |
Evan Cheng | 8160fd3 | 2006-03-28 23:41:33 +0000 | [diff] [blame] | 1867 | if (i != NumOperands - 1) |
| 1868 | Mask <<= Shift; |
| 1869 | } |
Evan Cheng | 8fdbdf2 | 2006-03-22 08:01:21 +0000 | [diff] [blame] | 1870 | |
| 1871 | return Mask; |
| 1872 | } |
| 1873 | |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1874 | /// getShufflePSHUFHWImmediate - Return the appropriate immediate to shuffle |
| 1875 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFHW |
| 1876 | /// instructions. |
| 1877 | unsigned X86::getShufflePSHUFHWImmediate(SDNode *N) { |
| 1878 | unsigned Mask = 0; |
| 1879 | // 8 nodes, but we only care about the last 4. |
| 1880 | for (unsigned i = 7; i >= 4; --i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1881 | unsigned Val = 0; |
| 1882 | SDOperand Arg = N->getOperand(i); |
| 1883 | if (Arg.getOpcode() != ISD::UNDEF) |
| 1884 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1885 | Mask |= (Val - 4); |
| 1886 | if (i != 4) |
| 1887 | Mask <<= 2; |
| 1888 | } |
| 1889 | |
| 1890 | return Mask; |
| 1891 | } |
| 1892 | |
| 1893 | /// getShufflePSHUFLWImmediate - Return the appropriate immediate to shuffle |
| 1894 | /// the specified isShuffleMask VECTOR_SHUFFLE mask with PSHUFLW |
| 1895 | /// instructions. |
| 1896 | unsigned X86::getShufflePSHUFLWImmediate(SDNode *N) { |
| 1897 | unsigned Mask = 0; |
| 1898 | // 8 nodes, but we only care about the first 4. |
| 1899 | for (int i = 3; i >= 0; --i) { |
Evan Cheng | 99d7205 | 2006-03-31 00:30:29 +0000 | [diff] [blame] | 1900 | unsigned Val = 0; |
| 1901 | SDOperand Arg = N->getOperand(i); |
| 1902 | if (Arg.getOpcode() != ISD::UNDEF) |
| 1903 | Val = cast<ConstantSDNode>(Arg)->getValue(); |
Evan Cheng | b7fedff | 2006-03-29 23:07:14 +0000 | [diff] [blame] | 1904 | Mask |= Val; |
| 1905 | if (i != 0) |
| 1906 | Mask <<= 2; |
| 1907 | } |
| 1908 | |
| 1909 | return Mask; |
| 1910 | } |
| 1911 | |
Evan Cheng | 59a6355 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 1912 | /// isPSHUFHW_PSHUFLWMask - true if the specified VECTOR_SHUFFLE operand |
| 1913 | /// specifies a 8 element shuffle that can be broken into a pair of |
| 1914 | /// PSHUFHW and PSHUFLW. |
| 1915 | static bool isPSHUFHW_PSHUFLWMask(SDNode *N) { |
| 1916 | assert(N->getOpcode() == ISD::BUILD_VECTOR); |
| 1917 | |
| 1918 | if (N->getNumOperands() != 8) |
| 1919 | return false; |
| 1920 | |
| 1921 | // Lower quadword shuffled. |
| 1922 | for (unsigned i = 0; i != 4; ++i) { |
| 1923 | SDOperand Arg = N->getOperand(i); |
| 1924 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1925 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1926 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1927 | if (Val > 4) |
| 1928 | return false; |
| 1929 | } |
| 1930 | |
| 1931 | // Upper quadword shuffled. |
| 1932 | for (unsigned i = 4; i != 8; ++i) { |
| 1933 | SDOperand Arg = N->getOperand(i); |
| 1934 | if (Arg.getOpcode() == ISD::UNDEF) continue; |
| 1935 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1936 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1937 | if (Val < 4 || Val > 7) |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | return true; |
| 1942 | } |
| 1943 | |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1944 | /// CommuteVectorShuffle - Swap vector_shuffle operandsas well as |
| 1945 | /// values in ther permute mask. |
| 1946 | static SDOperand CommuteVectorShuffle(SDOperand Op, SelectionDAG &DAG) { |
| 1947 | SDOperand V1 = Op.getOperand(0); |
| 1948 | SDOperand V2 = Op.getOperand(1); |
| 1949 | SDOperand Mask = Op.getOperand(2); |
| 1950 | MVT::ValueType VT = Op.getValueType(); |
| 1951 | MVT::ValueType MaskVT = Mask.getValueType(); |
| 1952 | MVT::ValueType EltVT = MVT::getVectorBaseType(MaskVT); |
| 1953 | unsigned NumElems = Mask.getNumOperands(); |
| 1954 | std::vector<SDOperand> MaskVec; |
| 1955 | |
| 1956 | for (unsigned i = 0; i != NumElems; ++i) { |
| 1957 | SDOperand Arg = Mask.getOperand(i); |
Evan Cheng | a3caaee | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 1958 | if (Arg.getOpcode() == ISD::UNDEF) { |
| 1959 | MaskVec.push_back(DAG.getNode(ISD::UNDEF, EltVT)); |
| 1960 | continue; |
| 1961 | } |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1962 | assert(isa<ConstantSDNode>(Arg) && "Invalid VECTOR_SHUFFLE mask!"); |
| 1963 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 1964 | if (Val < NumElems) |
| 1965 | MaskVec.push_back(DAG.getConstant(Val + NumElems, EltVT)); |
| 1966 | else |
| 1967 | MaskVec.push_back(DAG.getConstant(Val - NumElems, EltVT)); |
| 1968 | } |
| 1969 | |
| 1970 | Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 1971 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V2, V1, Mask); |
| 1972 | } |
| 1973 | |
Evan Cheng | 7855e4d | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 1974 | /// ShouldXformToMOVHLPS - Return true if the node should be transformed to |
| 1975 | /// match movhlps. The lower half elements should come from upper half of |
| 1976 | /// V1 (and in order), and the upper half elements should come from the upper |
| 1977 | /// half of V2 (and in order). |
| 1978 | static bool ShouldXformToMOVHLPS(SDNode *Mask) { |
| 1979 | unsigned NumElems = Mask->getNumOperands(); |
| 1980 | if (NumElems != 4) |
| 1981 | return false; |
| 1982 | for (unsigned i = 0, e = 2; i != e; ++i) |
| 1983 | if (!isUndefOrEqual(Mask->getOperand(i), i+2)) |
| 1984 | return false; |
| 1985 | for (unsigned i = 2; i != 4; ++i) |
| 1986 | if (!isUndefOrEqual(Mask->getOperand(i), i+4)) |
| 1987 | return false; |
| 1988 | return true; |
| 1989 | } |
| 1990 | |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1991 | /// isScalarLoadToVector - Returns true if the node is a scalar load that |
| 1992 | /// is promoted to a vector. |
Evan Cheng | 7855e4d | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 1993 | static inline bool isScalarLoadToVector(SDNode *N) { |
| 1994 | if (N->getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 1995 | N = N->getOperand(0).Val; |
| 1996 | return (N->getOpcode() == ISD::LOAD); |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 1997 | } |
| 1998 | return false; |
| 1999 | } |
| 2000 | |
Evan Cheng | 7855e4d | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2001 | /// ShouldXformToMOVLP{S|D} - Return true if the node should be transformed to |
| 2002 | /// match movlp{s|d}. The lower half elements should come from lower half of |
| 2003 | /// V1 (and in order), and the upper half elements should come from the upper |
| 2004 | /// half of V2 (and in order). And since V1 will become the source of the |
| 2005 | /// MOVLP, it must be either a vector load or a scalar load to vector. |
| 2006 | static bool ShouldXformToMOVLP(SDNode *V1, SDNode *Mask) { |
| 2007 | if (V1->getOpcode() != ISD::LOAD && !isScalarLoadToVector(V1)) |
| 2008 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2009 | |
Evan Cheng | 7855e4d | 2006-04-19 20:35:22 +0000 | [diff] [blame] | 2010 | unsigned NumElems = Mask->getNumOperands(); |
| 2011 | if (NumElems != 2 && NumElems != 4) |
| 2012 | return false; |
| 2013 | for (unsigned i = 0, e = NumElems/2; i != e; ++i) |
| 2014 | if (!isUndefOrEqual(Mask->getOperand(i), i)) |
| 2015 | return false; |
| 2016 | for (unsigned i = NumElems/2; i != NumElems; ++i) |
| 2017 | if (!isUndefOrEqual(Mask->getOperand(i), i+NumElems)) |
| 2018 | return false; |
| 2019 | return true; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2022 | /// isSplatVector - Returns true if N is a BUILD_VECTOR node whose elements are |
| 2023 | /// all the same. |
| 2024 | static bool isSplatVector(SDNode *N) { |
| 2025 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 2026 | return false; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2027 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2028 | SDOperand SplatValue = N->getOperand(0); |
| 2029 | for (unsigned i = 1, e = N->getNumOperands(); i != e; ++i) |
| 2030 | if (N->getOperand(i) != SplatValue) |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 2031 | return false; |
| 2032 | return true; |
| 2033 | } |
| 2034 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2035 | /// NormalizeMask - V2 is a splat, modify the mask (if needed) so all elements |
| 2036 | /// that point to V2 points to its first element. |
| 2037 | static SDOperand NormalizeMask(SDOperand Mask, SelectionDAG &DAG) { |
| 2038 | assert(Mask.getOpcode() == ISD::BUILD_VECTOR); |
| 2039 | |
| 2040 | bool Changed = false; |
| 2041 | std::vector<SDOperand> MaskVec; |
| 2042 | unsigned NumElems = Mask.getNumOperands(); |
| 2043 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2044 | SDOperand Arg = Mask.getOperand(i); |
| 2045 | if (Arg.getOpcode() != ISD::UNDEF) { |
| 2046 | unsigned Val = cast<ConstantSDNode>(Arg)->getValue(); |
| 2047 | if (Val > NumElems) { |
| 2048 | Arg = DAG.getConstant(NumElems, Arg.getValueType()); |
| 2049 | Changed = true; |
| 2050 | } |
| 2051 | } |
| 2052 | MaskVec.push_back(Arg); |
| 2053 | } |
| 2054 | |
| 2055 | if (Changed) |
| 2056 | Mask = DAG.getNode(ISD::BUILD_VECTOR, Mask.getValueType(), MaskVec); |
| 2057 | return Mask; |
| 2058 | } |
| 2059 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2060 | /// getMOVLMask - Returns a vector_shuffle mask for an movs{s|d}, movd |
| 2061 | /// operation of specified width. |
| 2062 | static SDOperand getMOVLMask(unsigned NumElems, SelectionDAG &DAG) { |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2063 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2064 | MVT::ValueType BaseVT = MVT::getVectorBaseType(MaskVT); |
| 2065 | |
| 2066 | std::vector<SDOperand> MaskVec; |
| 2067 | MaskVec.push_back(DAG.getConstant(NumElems, BaseVT)); |
| 2068 | for (unsigned i = 1; i != NumElems; ++i) |
| 2069 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2070 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2071 | } |
| 2072 | |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2073 | /// getUnpacklMask - Returns a vector_shuffle mask for an unpackl operation |
| 2074 | /// of specified width. |
| 2075 | static SDOperand getUnpacklMask(unsigned NumElems, SelectionDAG &DAG) { |
| 2076 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2077 | MVT::ValueType BaseVT = MVT::getVectorBaseType(MaskVT); |
| 2078 | std::vector<SDOperand> MaskVec; |
| 2079 | for (unsigned i = 0, e = NumElems/2; i != e; ++i) { |
| 2080 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2081 | MaskVec.push_back(DAG.getConstant(i + NumElems, BaseVT)); |
| 2082 | } |
| 2083 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2084 | } |
| 2085 | |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 2086 | /// getUnpackhMask - Returns a vector_shuffle mask for an unpackh operation |
| 2087 | /// of specified width. |
| 2088 | static SDOperand getUnpackhMask(unsigned NumElems, SelectionDAG &DAG) { |
| 2089 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2090 | MVT::ValueType BaseVT = MVT::getVectorBaseType(MaskVT); |
| 2091 | unsigned Half = NumElems/2; |
| 2092 | std::vector<SDOperand> MaskVec; |
| 2093 | for (unsigned i = 0; i != Half; ++i) { |
| 2094 | MaskVec.push_back(DAG.getConstant(i + Half, BaseVT)); |
| 2095 | MaskVec.push_back(DAG.getConstant(i + NumElems + Half, BaseVT)); |
| 2096 | } |
| 2097 | return DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2098 | } |
| 2099 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2100 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| 2101 | /// |
| 2102 | static SDOperand getZeroVector(MVT::ValueType VT, SelectionDAG &DAG) { |
| 2103 | assert(MVT::isVector(VT) && "Expected a vector type"); |
| 2104 | unsigned NumElems = getVectorNumElements(VT); |
| 2105 | MVT::ValueType EVT = MVT::getVectorBaseType(VT); |
| 2106 | bool isFP = MVT::isFloatingPoint(EVT); |
| 2107 | SDOperand Zero = isFP ? DAG.getConstantFP(0.0, EVT) : DAG.getConstant(0, EVT); |
| 2108 | std::vector<SDOperand> ZeroVec(NumElems, Zero); |
| 2109 | return DAG.getNode(ISD::BUILD_VECTOR, VT, ZeroVec); |
| 2110 | } |
| 2111 | |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2112 | /// PromoteSplat - Promote a splat of v8i16 or v16i8 to v4i32. |
| 2113 | /// |
| 2114 | static SDOperand PromoteSplat(SDOperand Op, SelectionDAG &DAG) { |
| 2115 | SDOperand V1 = Op.getOperand(0); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2116 | SDOperand Mask = Op.getOperand(2); |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2117 | MVT::ValueType VT = Op.getValueType(); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2118 | unsigned NumElems = Mask.getNumOperands(); |
| 2119 | Mask = getUnpacklMask(NumElems, DAG); |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2120 | while (NumElems != 4) { |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2121 | V1 = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V1, Mask); |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2122 | NumElems >>= 1; |
| 2123 | } |
| 2124 | V1 = DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, V1); |
| 2125 | |
| 2126 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2127 | Mask = getZeroVector(MaskVT, DAG); |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2128 | SDOperand Shuffle = DAG.getNode(ISD::VECTOR_SHUFFLE, MVT::v4i32, V1, |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2129 | DAG.getNode(ISD::UNDEF, MVT::v4i32), Mask); |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 2130 | return DAG.getNode(ISD::BIT_CONVERT, VT, Shuffle); |
| 2131 | } |
| 2132 | |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2133 | /// isZeroNode - Returns true if Elt is a constant zero or a floating point |
| 2134 | /// constant +0.0. |
| 2135 | static inline bool isZeroNode(SDOperand Elt) { |
| 2136 | return ((isa<ConstantSDNode>(Elt) && |
| 2137 | cast<ConstantSDNode>(Elt)->getValue() == 0) || |
| 2138 | (isa<ConstantFPSDNode>(Elt) && |
| 2139 | cast<ConstantFPSDNode>(Elt)->isExactlyValue(0.0))); |
| 2140 | } |
| 2141 | |
Evan Cheng | 14215c3 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2142 | /// getShuffleVectorZeroOrUndef - Return a vector_shuffle of the specified |
| 2143 | /// vector and zero or undef vector. |
| 2144 | static SDOperand getShuffleVectorZeroOrUndef(SDOperand V2, MVT::ValueType VT, |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2145 | unsigned NumElems, unsigned Idx, |
Evan Cheng | 14215c3 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2146 | bool isZero, SelectionDAG &DAG) { |
| 2147 | SDOperand V1 = isZero ? getZeroVector(VT, DAG) : DAG.getNode(ISD::UNDEF, VT); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2148 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2149 | MVT::ValueType EVT = MVT::getVectorBaseType(MaskVT); |
| 2150 | SDOperand Zero = DAG.getConstant(0, EVT); |
| 2151 | std::vector<SDOperand> MaskVec(NumElems, Zero); |
| 2152 | MaskVec[Idx] = DAG.getConstant(NumElems, EVT); |
| 2153 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
Evan Cheng | 14215c3 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 2154 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 2155 | } |
| 2156 | |
Evan Cheng | b046108 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 2157 | /// LowerBuildVectorv16i8 - Custom lower build_vector of v16i8. |
| 2158 | /// |
| 2159 | static SDOperand LowerBuildVectorv16i8(SDOperand Op, unsigned NonZeros, |
| 2160 | unsigned NumNonZero, unsigned NumZero, |
| 2161 | SelectionDAG &DAG) { |
| 2162 | if (NumNonZero > 8) |
| 2163 | return SDOperand(); |
| 2164 | |
| 2165 | SDOperand V(0, 0); |
| 2166 | bool First = true; |
| 2167 | for (unsigned i = 0; i < 16; ++i) { |
| 2168 | bool ThisIsNonZero = (NonZeros & (1 << i)) != 0; |
| 2169 | if (ThisIsNonZero && First) { |
| 2170 | if (NumZero) |
| 2171 | V = getZeroVector(MVT::v8i16, DAG); |
| 2172 | else |
| 2173 | V = DAG.getNode(ISD::UNDEF, MVT::v8i16); |
| 2174 | First = false; |
| 2175 | } |
| 2176 | |
| 2177 | if ((i & 1) != 0) { |
| 2178 | SDOperand ThisElt(0, 0), LastElt(0, 0); |
| 2179 | bool LastIsNonZero = (NonZeros & (1 << (i-1))) != 0; |
| 2180 | if (LastIsNonZero) { |
| 2181 | LastElt = DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, Op.getOperand(i-1)); |
| 2182 | } |
| 2183 | if (ThisIsNonZero) { |
| 2184 | ThisElt = DAG.getNode(ISD::ZERO_EXTEND, MVT::i16, Op.getOperand(i)); |
| 2185 | ThisElt = DAG.getNode(ISD::SHL, MVT::i16, |
| 2186 | ThisElt, DAG.getConstant(8, MVT::i8)); |
| 2187 | if (LastIsNonZero) |
| 2188 | ThisElt = DAG.getNode(ISD::OR, MVT::i16, ThisElt, LastElt); |
| 2189 | } else |
| 2190 | ThisElt = LastElt; |
| 2191 | |
| 2192 | if (ThisElt.Val) |
| 2193 | V = DAG.getNode(ISD::INSERT_VECTOR_ELT, MVT::v8i16, V, ThisElt, |
| 2194 | DAG.getConstant(i/2, MVT::i32)); |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | return DAG.getNode(ISD::BIT_CONVERT, MVT::v16i8, V); |
| 2199 | } |
| 2200 | |
| 2201 | /// LowerBuildVectorv16i8 - Custom lower build_vector of v8i16. |
| 2202 | /// |
| 2203 | static SDOperand LowerBuildVectorv8i16(SDOperand Op, unsigned NonZeros, |
| 2204 | unsigned NumNonZero, unsigned NumZero, |
| 2205 | SelectionDAG &DAG) { |
| 2206 | if (NumNonZero > 4) |
| 2207 | return SDOperand(); |
| 2208 | |
| 2209 | SDOperand V(0, 0); |
| 2210 | bool First = true; |
| 2211 | for (unsigned i = 0; i < 8; ++i) { |
| 2212 | bool isNonZero = (NonZeros & (1 << i)) != 0; |
| 2213 | if (isNonZero) { |
| 2214 | if (First) { |
| 2215 | if (NumZero) |
| 2216 | V = getZeroVector(MVT::v8i16, DAG); |
| 2217 | else |
| 2218 | V = DAG.getNode(ISD::UNDEF, MVT::v8i16); |
| 2219 | First = false; |
| 2220 | } |
| 2221 | V = DAG.getNode(ISD::INSERT_VECTOR_ELT, MVT::v8i16, V, Op.getOperand(i), |
| 2222 | DAG.getConstant(i, MVT::i32)); |
| 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | return V; |
| 2227 | } |
| 2228 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2229 | SDOperand |
| 2230 | X86TargetLowering::LowerBUILD_VECTOR(SDOperand Op, SelectionDAG &DAG) { |
| 2231 | // All zero's are handled with pxor. |
| 2232 | if (ISD::isBuildVectorAllZeros(Op.Val)) |
| 2233 | return Op; |
| 2234 | |
| 2235 | // All one's are handled with pcmpeqd. |
| 2236 | if (ISD::isBuildVectorAllOnes(Op.Val)) |
| 2237 | return Op; |
| 2238 | |
| 2239 | MVT::ValueType VT = Op.getValueType(); |
| 2240 | MVT::ValueType EVT = MVT::getVectorBaseType(VT); |
| 2241 | unsigned EVTBits = MVT::getSizeInBits(EVT); |
| 2242 | |
| 2243 | unsigned NumElems = Op.getNumOperands(); |
| 2244 | unsigned NumZero = 0; |
| 2245 | unsigned NumNonZero = 0; |
| 2246 | unsigned NonZeros = 0; |
| 2247 | std::set<SDOperand> Values; |
| 2248 | for (unsigned i = 0; i < NumElems; ++i) { |
| 2249 | SDOperand Elt = Op.getOperand(i); |
| 2250 | if (Elt.getOpcode() != ISD::UNDEF) { |
| 2251 | Values.insert(Elt); |
| 2252 | if (isZeroNode(Elt)) |
| 2253 | NumZero++; |
| 2254 | else { |
| 2255 | NonZeros |= (1 << i); |
| 2256 | NumNonZero++; |
| 2257 | } |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | if (NumNonZero == 0) |
| 2262 | // Must be a mix of zero and undef. Return a zero vector. |
| 2263 | return getZeroVector(VT, DAG); |
| 2264 | |
| 2265 | // Splat is obviously ok. Let legalizer expand it to a shuffle. |
| 2266 | if (Values.size() == 1) |
| 2267 | return SDOperand(); |
| 2268 | |
| 2269 | // Special case for single non-zero element. |
| 2270 | if (NumNonZero == 1) { |
| 2271 | unsigned Idx = CountTrailingZeros_32(NonZeros); |
| 2272 | SDOperand Item = Op.getOperand(Idx); |
| 2273 | Item = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Item); |
| 2274 | if (Idx == 0) |
| 2275 | // Turn it into a MOVL (i.e. movss, movsd, or movd) to a zero vector. |
| 2276 | return getShuffleVectorZeroOrUndef(Item, VT, NumElems, Idx, |
| 2277 | NumZero > 0, DAG); |
| 2278 | |
| 2279 | if (EVTBits == 32) { |
| 2280 | // Turn it into a shuffle of zero and zero-extended scalar to vector. |
| 2281 | Item = getShuffleVectorZeroOrUndef(Item, VT, NumElems, 0, NumZero > 0, |
| 2282 | DAG); |
| 2283 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2284 | MVT::ValueType MaskEVT = MVT::getVectorBaseType(MaskVT); |
| 2285 | std::vector<SDOperand> MaskVec; |
| 2286 | for (unsigned i = 0; i < NumElems; i++) |
| 2287 | MaskVec.push_back(DAG.getConstant((i == Idx) ? 0 : 1, MaskEVT)); |
| 2288 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2289 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, Item, |
| 2290 | DAG.getNode(ISD::UNDEF, VT), Mask); |
| 2291 | } |
| 2292 | } |
| 2293 | |
| 2294 | // Let legalizer expand 2-widde build_vector's. |
| 2295 | if (EVTBits == 64) |
| 2296 | return SDOperand(); |
| 2297 | |
| 2298 | // If element VT is < 32 bits, convert it to inserts into a zero vector. |
| 2299 | if (EVTBits == 8) { |
| 2300 | SDOperand V = LowerBuildVectorv16i8(Op, NonZeros,NumNonZero,NumZero, DAG); |
| 2301 | if (V.Val) return V; |
| 2302 | } |
| 2303 | |
| 2304 | if (EVTBits == 16) { |
| 2305 | SDOperand V = LowerBuildVectorv8i16(Op, NonZeros,NumNonZero,NumZero, DAG); |
| 2306 | if (V.Val) return V; |
| 2307 | } |
| 2308 | |
| 2309 | // If element VT is == 32 bits, turn it into a number of shuffles. |
| 2310 | std::vector<SDOperand> V(NumElems); |
| 2311 | if (NumElems == 4 && NumZero > 0) { |
| 2312 | for (unsigned i = 0; i < 4; ++i) { |
| 2313 | bool isZero = !(NonZeros & (1 << i)); |
| 2314 | if (isZero) |
| 2315 | V[i] = getZeroVector(VT, DAG); |
| 2316 | else |
| 2317 | V[i] = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Op.getOperand(i)); |
| 2318 | } |
| 2319 | |
| 2320 | for (unsigned i = 0; i < 2; ++i) { |
| 2321 | switch ((NonZeros & (0x3 << i*2)) >> (i*2)) { |
| 2322 | default: break; |
| 2323 | case 0: |
| 2324 | V[i] = V[i*2]; // Must be a zero vector. |
| 2325 | break; |
| 2326 | case 1: |
| 2327 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2+1], V[i*2], |
| 2328 | getMOVLMask(NumElems, DAG)); |
| 2329 | break; |
| 2330 | case 2: |
| 2331 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2], V[i*2+1], |
| 2332 | getMOVLMask(NumElems, DAG)); |
| 2333 | break; |
| 2334 | case 3: |
| 2335 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i*2], V[i*2+1], |
| 2336 | getUnpacklMask(NumElems, DAG)); |
| 2337 | break; |
| 2338 | } |
| 2339 | } |
| 2340 | |
| 2341 | // Take advantage of the fact R32 to VR128 scalar_to_vector (i.e. movd) |
| 2342 | // clears the upper bits. |
| 2343 | // FIXME: we can do the same for v4f32 case when we know both parts of |
| 2344 | // the lower half come from scalar_to_vector (loadf32). We should do |
| 2345 | // that in post legalizer dag combiner with target specific hooks. |
| 2346 | if (MVT::isInteger(EVT) && (NonZeros & (0x3 << 2)) == 0) |
| 2347 | return V[0]; |
| 2348 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2349 | MVT::ValueType EVT = MVT::getVectorBaseType(MaskVT); |
| 2350 | std::vector<SDOperand> MaskVec; |
| 2351 | bool Reverse = (NonZeros & 0x3) == 2; |
| 2352 | for (unsigned i = 0; i < 2; ++i) |
| 2353 | if (Reverse) |
| 2354 | MaskVec.push_back(DAG.getConstant(1-i, EVT)); |
| 2355 | else |
| 2356 | MaskVec.push_back(DAG.getConstant(i, EVT)); |
| 2357 | Reverse = ((NonZeros & (0x3 << 2)) >> 2) == 2; |
| 2358 | for (unsigned i = 0; i < 2; ++i) |
| 2359 | if (Reverse) |
| 2360 | MaskVec.push_back(DAG.getConstant(1-i+NumElems, EVT)); |
| 2361 | else |
| 2362 | MaskVec.push_back(DAG.getConstant(i+NumElems, EVT)); |
| 2363 | SDOperand ShufMask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2364 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[0], V[1], ShufMask); |
| 2365 | } |
| 2366 | |
| 2367 | if (Values.size() > 2) { |
| 2368 | // Expand into a number of unpckl*. |
| 2369 | // e.g. for v4f32 |
| 2370 | // Step 1: unpcklps 0, 2 ==> X: <?, ?, 2, 0> |
| 2371 | // : unpcklps 1, 3 ==> Y: <?, ?, 3, 1> |
| 2372 | // Step 2: unpcklps X, Y ==> <3, 2, 1, 0> |
| 2373 | SDOperand UnpckMask = getUnpacklMask(NumElems, DAG); |
| 2374 | for (unsigned i = 0; i < NumElems; ++i) |
| 2375 | V[i] = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, Op.getOperand(i)); |
| 2376 | NumElems >>= 1; |
| 2377 | while (NumElems != 0) { |
| 2378 | for (unsigned i = 0; i < NumElems; ++i) |
| 2379 | V[i] = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V[i], V[i + NumElems], |
| 2380 | UnpckMask); |
| 2381 | NumElems >>= 1; |
| 2382 | } |
| 2383 | return V[0]; |
| 2384 | } |
| 2385 | |
| 2386 | return SDOperand(); |
| 2387 | } |
| 2388 | |
| 2389 | SDOperand |
| 2390 | X86TargetLowering::LowerVECTOR_SHUFFLE(SDOperand Op, SelectionDAG &DAG) { |
| 2391 | SDOperand V1 = Op.getOperand(0); |
| 2392 | SDOperand V2 = Op.getOperand(1); |
| 2393 | SDOperand PermMask = Op.getOperand(2); |
| 2394 | MVT::ValueType VT = Op.getValueType(); |
| 2395 | unsigned NumElems = PermMask.getNumOperands(); |
| 2396 | bool V1IsUndef = V1.getOpcode() == ISD::UNDEF; |
| 2397 | bool V2IsUndef = V2.getOpcode() == ISD::UNDEF; |
| 2398 | |
| 2399 | if (isSplatMask(PermMask.Val)) { |
| 2400 | if (NumElems <= 4) return Op; |
| 2401 | // Promote it to a v4i32 splat. |
| 2402 | return PromoteSplat(Op, DAG); |
| 2403 | } |
| 2404 | |
| 2405 | if (X86::isMOVLMask(PermMask.Val)) |
| 2406 | return (V1IsUndef) ? V2 : Op; |
| 2407 | |
| 2408 | if (X86::isMOVSHDUPMask(PermMask.Val) || |
| 2409 | X86::isMOVSLDUPMask(PermMask.Val) || |
| 2410 | X86::isMOVHLPSMask(PermMask.Val) || |
| 2411 | X86::isMOVHPMask(PermMask.Val) || |
| 2412 | X86::isMOVLPMask(PermMask.Val)) |
| 2413 | return Op; |
| 2414 | |
| 2415 | if (ShouldXformToMOVHLPS(PermMask.Val) || |
| 2416 | ShouldXformToMOVLP(V1.Val, PermMask.Val)) |
| 2417 | return CommuteVectorShuffle(Op, DAG); |
| 2418 | |
| 2419 | bool V1IsSplat = isSplatVector(V1.Val) || V1.getOpcode() == ISD::UNDEF; |
| 2420 | bool V2IsSplat = isSplatVector(V2.Val) || V2.getOpcode() == ISD::UNDEF; |
| 2421 | if (V1IsSplat && !V2IsSplat) { |
| 2422 | Op = CommuteVectorShuffle(Op, DAG); |
| 2423 | V1 = Op.getOperand(0); |
| 2424 | V2 = Op.getOperand(1); |
| 2425 | PermMask = Op.getOperand(2); |
| 2426 | V2IsSplat = true; |
| 2427 | } |
| 2428 | |
| 2429 | if (isCommutedMOVL(PermMask.Val, V2IsSplat)) { |
| 2430 | if (V2IsUndef) return V1; |
| 2431 | Op = CommuteVectorShuffle(Op, DAG); |
| 2432 | V1 = Op.getOperand(0); |
| 2433 | V2 = Op.getOperand(1); |
| 2434 | PermMask = Op.getOperand(2); |
| 2435 | if (V2IsSplat) { |
| 2436 | // V2 is a splat, so the mask may be malformed. That is, it may point |
| 2437 | // to any V2 element. The instruction selectior won't like this. Get |
| 2438 | // a corrected mask and commute to form a proper MOVS{S|D}. |
| 2439 | SDOperand NewMask = getMOVLMask(NumElems, DAG); |
| 2440 | if (NewMask.Val != PermMask.Val) |
| 2441 | Op = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
| 2442 | } |
| 2443 | return Op; |
| 2444 | } |
| 2445 | |
| 2446 | if (X86::isUNPCKL_v_undef_Mask(PermMask.Val) || |
| 2447 | X86::isUNPCKLMask(PermMask.Val) || |
| 2448 | X86::isUNPCKHMask(PermMask.Val)) |
| 2449 | return Op; |
| 2450 | |
| 2451 | if (V2IsSplat) { |
| 2452 | // Normalize mask so all entries that point to V2 points to its first |
| 2453 | // element then try to match unpck{h|l} again. If match, return a |
| 2454 | // new vector_shuffle with the corrected mask. |
| 2455 | SDOperand NewMask = NormalizeMask(PermMask, DAG); |
| 2456 | if (NewMask.Val != PermMask.Val) { |
| 2457 | if (X86::isUNPCKLMask(PermMask.Val, true)) { |
| 2458 | SDOperand NewMask = getUnpacklMask(NumElems, DAG); |
| 2459 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
| 2460 | } else if (X86::isUNPCKHMask(PermMask.Val, true)) { |
| 2461 | SDOperand NewMask = getUnpackhMask(NumElems, DAG); |
| 2462 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, NewMask); |
| 2463 | } |
| 2464 | } |
| 2465 | } |
| 2466 | |
| 2467 | // Normalize the node to match x86 shuffle ops if needed |
| 2468 | if (V2.getOpcode() != ISD::UNDEF) |
| 2469 | if (isCommutedSHUFP(PermMask.Val)) { |
| 2470 | Op = CommuteVectorShuffle(Op, DAG); |
| 2471 | V1 = Op.getOperand(0); |
| 2472 | V2 = Op.getOperand(1); |
| 2473 | PermMask = Op.getOperand(2); |
| 2474 | } |
| 2475 | |
| 2476 | // If VT is integer, try PSHUF* first, then SHUFP*. |
| 2477 | if (MVT::isInteger(VT)) { |
| 2478 | if (X86::isPSHUFDMask(PermMask.Val) || |
| 2479 | X86::isPSHUFHWMask(PermMask.Val) || |
| 2480 | X86::isPSHUFLWMask(PermMask.Val)) { |
| 2481 | if (V2.getOpcode() != ISD::UNDEF) |
| 2482 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, |
| 2483 | DAG.getNode(ISD::UNDEF, V1.getValueType()),PermMask); |
| 2484 | return Op; |
| 2485 | } |
| 2486 | |
| 2487 | if (X86::isSHUFPMask(PermMask.Val)) |
| 2488 | return Op; |
| 2489 | |
| 2490 | // Handle v8i16 shuffle high / low shuffle node pair. |
| 2491 | if (VT == MVT::v8i16 && isPSHUFHW_PSHUFLWMask(PermMask.Val)) { |
| 2492 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(NumElems); |
| 2493 | MVT::ValueType BaseVT = MVT::getVectorBaseType(MaskVT); |
| 2494 | std::vector<SDOperand> MaskVec; |
| 2495 | for (unsigned i = 0; i != 4; ++i) |
| 2496 | MaskVec.push_back(PermMask.getOperand(i)); |
| 2497 | for (unsigned i = 4; i != 8; ++i) |
| 2498 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2499 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2500 | V1 = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
| 2501 | MaskVec.clear(); |
| 2502 | for (unsigned i = 0; i != 4; ++i) |
| 2503 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2504 | for (unsigned i = 4; i != 8; ++i) |
| 2505 | MaskVec.push_back(PermMask.getOperand(i)); |
| 2506 | Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec); |
| 2507 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, Mask); |
| 2508 | } |
| 2509 | } else { |
| 2510 | // Floating point cases in the other order. |
| 2511 | if (X86::isSHUFPMask(PermMask.Val)) |
| 2512 | return Op; |
| 2513 | if (X86::isPSHUFDMask(PermMask.Val) || |
| 2514 | X86::isPSHUFHWMask(PermMask.Val) || |
| 2515 | X86::isPSHUFLWMask(PermMask.Val)) { |
| 2516 | if (V2.getOpcode() != ISD::UNDEF) |
| 2517 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, |
| 2518 | DAG.getNode(ISD::UNDEF, V1.getValueType()),PermMask); |
| 2519 | return Op; |
| 2520 | } |
| 2521 | } |
| 2522 | |
| 2523 | if (NumElems == 4) { |
| 2524 | // Break it into (shuffle shuffle_hi, shuffle_lo). |
| 2525 | MVT::ValueType MaskVT = PermMask.getValueType(); |
| 2526 | MVT::ValueType MaskEVT = MVT::getVectorBaseType(MaskVT); |
| 2527 | std::map<unsigned, std::pair<int, int> > Locs; |
| 2528 | std::vector<SDOperand> LoMask(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2529 | std::vector<SDOperand> HiMask(NumElems, DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2530 | std::vector<SDOperand> *MaskPtr = &LoMask; |
| 2531 | unsigned MaskIdx = 0; |
| 2532 | unsigned LoIdx = 0; |
| 2533 | unsigned HiIdx = NumElems/2; |
| 2534 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2535 | if (i == NumElems/2) { |
| 2536 | MaskPtr = &HiMask; |
| 2537 | MaskIdx = 1; |
| 2538 | LoIdx = 0; |
| 2539 | HiIdx = NumElems/2; |
| 2540 | } |
| 2541 | SDOperand Elt = PermMask.getOperand(i); |
| 2542 | if (Elt.getOpcode() == ISD::UNDEF) { |
| 2543 | Locs[i] = std::make_pair(-1, -1); |
| 2544 | } else if (cast<ConstantSDNode>(Elt)->getValue() < NumElems) { |
| 2545 | Locs[i] = std::make_pair(MaskIdx, LoIdx); |
| 2546 | (*MaskPtr)[LoIdx] = Elt; |
| 2547 | LoIdx++; |
| 2548 | } else { |
| 2549 | Locs[i] = std::make_pair(MaskIdx, HiIdx); |
| 2550 | (*MaskPtr)[HiIdx] = Elt; |
| 2551 | HiIdx++; |
| 2552 | } |
| 2553 | } |
| 2554 | |
| 2555 | SDOperand LoShuffle = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, |
| 2556 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, LoMask)); |
| 2557 | SDOperand HiShuffle = DAG.getNode(ISD::VECTOR_SHUFFLE, VT, V1, V2, |
| 2558 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, HiMask)); |
| 2559 | std::vector<SDOperand> MaskOps; |
| 2560 | for (unsigned i = 0; i != NumElems; ++i) { |
| 2561 | if (Locs[i].first == -1) { |
| 2562 | MaskOps.push_back(DAG.getNode(ISD::UNDEF, MaskEVT)); |
| 2563 | } else { |
| 2564 | unsigned Idx = Locs[i].first * NumElems + Locs[i].second; |
| 2565 | MaskOps.push_back(DAG.getConstant(Idx, MaskEVT)); |
| 2566 | } |
| 2567 | } |
| 2568 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, LoShuffle, HiShuffle, |
| 2569 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskOps)); |
| 2570 | } |
| 2571 | |
| 2572 | return SDOperand(); |
| 2573 | } |
| 2574 | |
| 2575 | SDOperand |
| 2576 | X86TargetLowering::LowerEXTRACT_VECTOR_ELT(SDOperand Op, SelectionDAG &DAG) { |
| 2577 | if (!isa<ConstantSDNode>(Op.getOperand(1))) |
| 2578 | return SDOperand(); |
| 2579 | |
| 2580 | MVT::ValueType VT = Op.getValueType(); |
| 2581 | // TODO: handle v16i8. |
| 2582 | if (MVT::getSizeInBits(VT) == 16) { |
| 2583 | // Transform it so it match pextrw which produces a 32-bit result. |
| 2584 | MVT::ValueType EVT = (MVT::ValueType)(VT+1); |
| 2585 | SDOperand Extract = DAG.getNode(X86ISD::PEXTRW, EVT, |
| 2586 | Op.getOperand(0), Op.getOperand(1)); |
| 2587 | SDOperand Assert = DAG.getNode(ISD::AssertZext, EVT, Extract, |
| 2588 | DAG.getValueType(VT)); |
| 2589 | return DAG.getNode(ISD::TRUNCATE, VT, Assert); |
| 2590 | } else if (MVT::getSizeInBits(VT) == 32) { |
| 2591 | SDOperand Vec = Op.getOperand(0); |
| 2592 | unsigned Idx = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
| 2593 | if (Idx == 0) |
| 2594 | return Op; |
| 2595 | |
| 2596 | // SHUFPS the element to the lowest double word, then movss. |
| 2597 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
| 2598 | SDOperand IdxNode = DAG.getConstant((Idx < 2) ? Idx : Idx+4, |
| 2599 | MVT::getVectorBaseType(MaskVT)); |
| 2600 | std::vector<SDOperand> IdxVec; |
| 2601 | IdxVec.push_back(DAG.getConstant(Idx, MVT::getVectorBaseType(MaskVT))); |
| 2602 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorBaseType(MaskVT))); |
| 2603 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorBaseType(MaskVT))); |
| 2604 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorBaseType(MaskVT))); |
| 2605 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, IdxVec); |
| 2606 | Vec = DAG.getNode(ISD::VECTOR_SHUFFLE, Vec.getValueType(), |
| 2607 | Vec, Vec, Mask); |
| 2608 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, VT, Vec, |
| 2609 | DAG.getConstant(0, MVT::i32)); |
| 2610 | } else if (MVT::getSizeInBits(VT) == 64) { |
| 2611 | SDOperand Vec = Op.getOperand(0); |
| 2612 | unsigned Idx = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); |
| 2613 | if (Idx == 0) |
| 2614 | return Op; |
| 2615 | |
| 2616 | // UNPCKHPD the element to the lowest double word, then movsd. |
| 2617 | // Note if the lower 64 bits of the result of the UNPCKHPD is then stored |
| 2618 | // to a f64mem, the whole operation is folded into a single MOVHPDmr. |
| 2619 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
| 2620 | std::vector<SDOperand> IdxVec; |
| 2621 | IdxVec.push_back(DAG.getConstant(1, MVT::getVectorBaseType(MaskVT))); |
| 2622 | IdxVec.push_back(DAG.getNode(ISD::UNDEF, MVT::getVectorBaseType(MaskVT))); |
| 2623 | SDOperand Mask = DAG.getNode(ISD::BUILD_VECTOR, MaskVT, IdxVec); |
| 2624 | Vec = DAG.getNode(ISD::VECTOR_SHUFFLE, Vec.getValueType(), |
| 2625 | Vec, DAG.getNode(ISD::UNDEF, Vec.getValueType()), Mask); |
| 2626 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, VT, Vec, |
| 2627 | DAG.getConstant(0, MVT::i32)); |
| 2628 | } |
| 2629 | |
| 2630 | return SDOperand(); |
| 2631 | } |
| 2632 | |
| 2633 | SDOperand |
| 2634 | X86TargetLowering::LowerINSERT_VECTOR_ELT(SDOperand Op, SelectionDAG &DAG) { |
| 2635 | // Transform it so it match pinsrw which expects a 16-bit value in a R32 |
| 2636 | // as its second argument. |
| 2637 | MVT::ValueType VT = Op.getValueType(); |
| 2638 | MVT::ValueType BaseVT = MVT::getVectorBaseType(VT); |
| 2639 | SDOperand N0 = Op.getOperand(0); |
| 2640 | SDOperand N1 = Op.getOperand(1); |
| 2641 | SDOperand N2 = Op.getOperand(2); |
| 2642 | if (MVT::getSizeInBits(BaseVT) == 16) { |
| 2643 | if (N1.getValueType() != MVT::i32) |
| 2644 | N1 = DAG.getNode(ISD::ANY_EXTEND, MVT::i32, N1); |
| 2645 | if (N2.getValueType() != MVT::i32) |
| 2646 | N2 = DAG.getConstant(cast<ConstantSDNode>(N2)->getValue(), MVT::i32); |
| 2647 | return DAG.getNode(X86ISD::PINSRW, VT, N0, N1, N2); |
| 2648 | } else if (MVT::getSizeInBits(BaseVT) == 32) { |
| 2649 | unsigned Idx = cast<ConstantSDNode>(N2)->getValue(); |
| 2650 | if (Idx == 0) { |
| 2651 | // Use a movss. |
| 2652 | N1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, VT, N1); |
| 2653 | MVT::ValueType MaskVT = MVT::getIntVectorWithNumElements(4); |
| 2654 | MVT::ValueType BaseVT = MVT::getVectorBaseType(MaskVT); |
| 2655 | std::vector<SDOperand> MaskVec; |
| 2656 | MaskVec.push_back(DAG.getConstant(4, BaseVT)); |
| 2657 | for (unsigned i = 1; i <= 3; ++i) |
| 2658 | MaskVec.push_back(DAG.getConstant(i, BaseVT)); |
| 2659 | return DAG.getNode(ISD::VECTOR_SHUFFLE, VT, N0, N1, |
| 2660 | DAG.getNode(ISD::BUILD_VECTOR, MaskVT, MaskVec)); |
| 2661 | } else { |
| 2662 | // Use two pinsrw instructions to insert a 32 bit value. |
| 2663 | Idx <<= 1; |
| 2664 | if (MVT::isFloatingPoint(N1.getValueType())) { |
| 2665 | if (N1.getOpcode() == ISD::LOAD) { |
| 2666 | // Just load directly from f32mem to R32. |
| 2667 | N1 = DAG.getLoad(MVT::i32, N1.getOperand(0), N1.getOperand(1), |
| 2668 | N1.getOperand(2)); |
| 2669 | } else { |
| 2670 | N1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, MVT::v4f32, N1); |
| 2671 | N1 = DAG.getNode(ISD::BIT_CONVERT, MVT::v4i32, N1); |
| 2672 | N1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, MVT::i32, N1, |
| 2673 | DAG.getConstant(0, MVT::i32)); |
| 2674 | } |
| 2675 | } |
| 2676 | N0 = DAG.getNode(ISD::BIT_CONVERT, MVT::v8i16, N0); |
| 2677 | N0 = DAG.getNode(X86ISD::PINSRW, MVT::v8i16, N0, N1, |
| 2678 | DAG.getConstant(Idx, MVT::i32)); |
| 2679 | N1 = DAG.getNode(ISD::SRL, MVT::i32, N1, DAG.getConstant(16, MVT::i8)); |
| 2680 | N0 = DAG.getNode(X86ISD::PINSRW, MVT::v8i16, N0, N1, |
| 2681 | DAG.getConstant(Idx+1, MVT::i32)); |
| 2682 | return DAG.getNode(ISD::BIT_CONVERT, VT, N0); |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | return SDOperand(); |
| 2687 | } |
| 2688 | |
| 2689 | SDOperand |
| 2690 | X86TargetLowering::LowerSCALAR_TO_VECTOR(SDOperand Op, SelectionDAG &DAG) { |
| 2691 | SDOperand AnyExt = DAG.getNode(ISD::ANY_EXTEND, MVT::i32, Op.getOperand(0)); |
| 2692 | return DAG.getNode(X86ISD::S2VEC, Op.getValueType(), AnyExt); |
| 2693 | } |
| 2694 | |
| 2695 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2696 | // their target countpart wrapped in the X86ISD::Wrapper node. Suppose N is |
| 2697 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2698 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2699 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2700 | // into MOV32ri. |
| 2701 | SDOperand |
| 2702 | X86TargetLowering::LowerConstantPool(SDOperand Op, SelectionDAG &DAG) { |
| 2703 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| 2704 | SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), |
| 2705 | DAG.getTargetConstantPool(CP->get(), getPointerTy(), |
| 2706 | CP->getAlignment())); |
| 2707 | if (Subtarget->isTargetDarwin()) { |
| 2708 | // With PIC, the address is actually $g + Offset. |
| 2709 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) |
| 2710 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 2711 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result); |
| 2712 | } |
| 2713 | |
| 2714 | return Result; |
| 2715 | } |
| 2716 | |
| 2717 | SDOperand |
| 2718 | X86TargetLowering::LowerGlobalAddress(SDOperand Op, SelectionDAG &DAG) { |
| 2719 | GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| 2720 | SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), |
| 2721 | DAG.getTargetGlobalAddress(GV, getPointerTy())); |
| 2722 | if (Subtarget->isTargetDarwin()) { |
| 2723 | // With PIC, the address is actually $g + Offset. |
| 2724 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) |
| 2725 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 2726 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result); |
| 2727 | |
| 2728 | // For Darwin, external and weak symbols are indirect, so we want to load |
| 2729 | // the value at address GV, not the value of GV itself. This means that |
| 2730 | // the GlobalAddress must be in the base or index register of the address, |
| 2731 | // not the GV offset field. |
| 2732 | if (getTargetMachine().getRelocationModel() != Reloc::Static && |
| 2733 | DarwinGVRequiresExtraLoad(GV)) |
| 2734 | Result = DAG.getLoad(MVT::i32, DAG.getEntryNode(), |
| 2735 | Result, DAG.getSrcValue(NULL)); |
| 2736 | } |
| 2737 | |
| 2738 | return Result; |
| 2739 | } |
| 2740 | |
| 2741 | SDOperand |
| 2742 | X86TargetLowering::LowerExternalSymbol(SDOperand Op, SelectionDAG &DAG) { |
| 2743 | const char *Sym = cast<ExternalSymbolSDNode>(Op)->getSymbol(); |
| 2744 | SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), |
| 2745 | DAG.getTargetExternalSymbol(Sym, getPointerTy())); |
| 2746 | if (Subtarget->isTargetDarwin()) { |
| 2747 | // With PIC, the address is actually $g + Offset. |
| 2748 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) |
| 2749 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 2750 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result); |
| 2751 | } |
| 2752 | |
| 2753 | return Result; |
| 2754 | } |
| 2755 | |
| 2756 | SDOperand X86TargetLowering::LowerShift(SDOperand Op, SelectionDAG &DAG) { |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 2757 | assert(Op.getNumOperands() == 3 && Op.getValueType() == MVT::i32 && |
| 2758 | "Not an i64 shift!"); |
| 2759 | bool isSRA = Op.getOpcode() == ISD::SRA_PARTS; |
| 2760 | SDOperand ShOpLo = Op.getOperand(0); |
| 2761 | SDOperand ShOpHi = Op.getOperand(1); |
| 2762 | SDOperand ShAmt = Op.getOperand(2); |
| 2763 | SDOperand Tmp1 = isSRA ? DAG.getNode(ISD::SRA, MVT::i32, ShOpHi, |
Evan Cheng | 621674a | 2006-01-18 09:26:46 +0000 | [diff] [blame] | 2764 | DAG.getConstant(31, MVT::i8)) |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 2765 | : DAG.getConstant(0, MVT::i32); |
| 2766 | |
| 2767 | SDOperand Tmp2, Tmp3; |
| 2768 | if (Op.getOpcode() == ISD::SHL_PARTS) { |
| 2769 | Tmp2 = DAG.getNode(X86ISD::SHLD, MVT::i32, ShOpHi, ShOpLo, ShAmt); |
| 2770 | Tmp3 = DAG.getNode(ISD::SHL, MVT::i32, ShOpLo, ShAmt); |
| 2771 | } else { |
| 2772 | Tmp2 = DAG.getNode(X86ISD::SHRD, MVT::i32, ShOpLo, ShOpHi, ShAmt); |
Evan Cheng | 267ba59 | 2006-01-19 01:46:14 +0000 | [diff] [blame] | 2773 | Tmp3 = DAG.getNode(isSRA ? ISD::SRA : ISD::SRL, MVT::i32, ShOpHi, ShAmt); |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | SDOperand InFlag = DAG.getNode(X86ISD::TEST, MVT::Flag, |
| 2777 | ShAmt, DAG.getConstant(32, MVT::i8)); |
| 2778 | |
| 2779 | SDOperand Hi, Lo; |
Evan Cheng | 77fa919 | 2006-01-09 20:49:21 +0000 | [diff] [blame] | 2780 | SDOperand CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8); |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 2781 | |
| 2782 | std::vector<MVT::ValueType> Tys; |
| 2783 | Tys.push_back(MVT::i32); |
| 2784 | Tys.push_back(MVT::Flag); |
| 2785 | std::vector<SDOperand> Ops; |
| 2786 | if (Op.getOpcode() == ISD::SHL_PARTS) { |
| 2787 | Ops.push_back(Tmp2); |
| 2788 | Ops.push_back(Tmp3); |
| 2789 | Ops.push_back(CC); |
| 2790 | Ops.push_back(InFlag); |
| 2791 | Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops); |
| 2792 | InFlag = Hi.getValue(1); |
| 2793 | |
| 2794 | Ops.clear(); |
| 2795 | Ops.push_back(Tmp3); |
| 2796 | Ops.push_back(Tmp1); |
| 2797 | Ops.push_back(CC); |
| 2798 | Ops.push_back(InFlag); |
| 2799 | Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops); |
| 2800 | } else { |
| 2801 | Ops.push_back(Tmp2); |
| 2802 | Ops.push_back(Tmp3); |
| 2803 | Ops.push_back(CC); |
Evan Cheng | 12181af | 2006-01-09 22:29:54 +0000 | [diff] [blame] | 2804 | Ops.push_back(InFlag); |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 2805 | Lo = DAG.getNode(X86ISD::CMOV, Tys, Ops); |
| 2806 | InFlag = Lo.getValue(1); |
| 2807 | |
| 2808 | Ops.clear(); |
| 2809 | Ops.push_back(Tmp3); |
| 2810 | Ops.push_back(Tmp1); |
| 2811 | Ops.push_back(CC); |
| 2812 | Ops.push_back(InFlag); |
| 2813 | Hi = DAG.getNode(X86ISD::CMOV, Tys, Ops); |
| 2814 | } |
| 2815 | |
| 2816 | Tys.clear(); |
| 2817 | Tys.push_back(MVT::i32); |
| 2818 | Tys.push_back(MVT::i32); |
| 2819 | Ops.clear(); |
| 2820 | Ops.push_back(Lo); |
| 2821 | Ops.push_back(Hi); |
| 2822 | return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2823 | } |
Evan Cheng | 6305e50 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 2824 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2825 | SDOperand X86TargetLowering::LowerSINT_TO_FP(SDOperand Op, SelectionDAG &DAG) { |
| 2826 | assert(Op.getOperand(0).getValueType() <= MVT::i64 && |
| 2827 | Op.getOperand(0).getValueType() >= MVT::i16 && |
| 2828 | "Unknown SINT_TO_FP to lower!"); |
| 2829 | |
| 2830 | SDOperand Result; |
| 2831 | MVT::ValueType SrcVT = Op.getOperand(0).getValueType(); |
| 2832 | unsigned Size = MVT::getSizeInBits(SrcVT)/8; |
| 2833 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2834 | int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size); |
| 2835 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 2836 | SDOperand Chain = DAG.getNode(ISD::STORE, MVT::Other, |
| 2837 | DAG.getEntryNode(), Op.getOperand(0), |
| 2838 | StackSlot, DAG.getSrcValue(NULL)); |
| 2839 | |
| 2840 | // Build the FILD |
| 2841 | std::vector<MVT::ValueType> Tys; |
| 2842 | Tys.push_back(MVT::f64); |
| 2843 | Tys.push_back(MVT::Other); |
| 2844 | if (X86ScalarSSE) Tys.push_back(MVT::Flag); |
| 2845 | std::vector<SDOperand> Ops; |
| 2846 | Ops.push_back(Chain); |
| 2847 | Ops.push_back(StackSlot); |
| 2848 | Ops.push_back(DAG.getValueType(SrcVT)); |
| 2849 | Result = DAG.getNode(X86ScalarSSE ? X86ISD::FILD_FLAG :X86ISD::FILD, |
| 2850 | Tys, Ops); |
| 2851 | |
| 2852 | if (X86ScalarSSE) { |
| 2853 | Chain = Result.getValue(1); |
| 2854 | SDOperand InFlag = Result.getValue(2); |
| 2855 | |
| 2856 | // FIXME: Currently the FST is flagged to the FILD_FLAG. This |
| 2857 | // shouldn't be necessary except that RFP cannot be live across |
| 2858 | // multiple blocks. When stackifier is fixed, they can be uncoupled. |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2859 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2860 | int SSFI = MF.getFrameInfo()->CreateStackObject(8, 8); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2861 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
Evan Cheng | 6305e50 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 2862 | std::vector<MVT::ValueType> Tys; |
Evan Cheng | 5b97fcf | 2006-01-30 08:02:57 +0000 | [diff] [blame] | 2863 | Tys.push_back(MVT::Other); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2864 | std::vector<SDOperand> Ops; |
Evan Cheng | 6305e50 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 2865 | Ops.push_back(Chain); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2866 | Ops.push_back(Result); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2867 | Ops.push_back(StackSlot); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2868 | Ops.push_back(DAG.getValueType(Op.getValueType())); |
| 2869 | Ops.push_back(InFlag); |
| 2870 | Chain = DAG.getNode(X86ISD::FST, Tys, Ops); |
| 2871 | Result = DAG.getLoad(Op.getValueType(), Chain, StackSlot, |
| 2872 | DAG.getSrcValue(NULL)); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2873 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2874 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2875 | return Result; |
| 2876 | } |
| 2877 | |
| 2878 | SDOperand X86TargetLowering::LowerFP_TO_SINT(SDOperand Op, SelectionDAG &DAG) { |
| 2879 | assert(Op.getValueType() <= MVT::i64 && Op.getValueType() >= MVT::i16 && |
| 2880 | "Unknown FP_TO_SINT to lower!"); |
| 2881 | // We lower FP->sint64 into FISTP64, followed by a load, all to a temporary |
| 2882 | // stack slot. |
| 2883 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2884 | unsigned MemSize = MVT::getSizeInBits(Op.getValueType())/8; |
| 2885 | int SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize); |
| 2886 | SDOperand StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 2887 | |
| 2888 | unsigned Opc; |
| 2889 | switch (Op.getValueType()) { |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2890 | default: assert(0 && "Invalid FP_TO_SINT to lower!"); |
| 2891 | case MVT::i16: Opc = X86ISD::FP_TO_INT16_IN_MEM; break; |
| 2892 | case MVT::i32: Opc = X86ISD::FP_TO_INT32_IN_MEM; break; |
| 2893 | case MVT::i64: Opc = X86ISD::FP_TO_INT64_IN_MEM; break; |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2894 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2895 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2896 | SDOperand Chain = DAG.getEntryNode(); |
| 2897 | SDOperand Value = Op.getOperand(0); |
| 2898 | if (X86ScalarSSE) { |
| 2899 | assert(Op.getValueType() == MVT::i64 && "Invalid FP_TO_SINT to lower!"); |
| 2900 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, StackSlot, |
| 2901 | DAG.getSrcValue(0)); |
| 2902 | std::vector<MVT::ValueType> Tys; |
| 2903 | Tys.push_back(MVT::f64); |
| 2904 | Tys.push_back(MVT::Other); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2905 | std::vector<SDOperand> Ops; |
Evan Cheng | 5b97fcf | 2006-01-30 08:02:57 +0000 | [diff] [blame] | 2906 | Ops.push_back(Chain); |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2907 | Ops.push_back(StackSlot); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2908 | Ops.push_back(DAG.getValueType(Op.getOperand(0).getValueType())); |
| 2909 | Value = DAG.getNode(X86ISD::FLD, Tys, Ops); |
| 2910 | Chain = Value.getValue(1); |
| 2911 | SSFI = MF.getFrameInfo()->CreateStackObject(MemSize, MemSize); |
| 2912 | StackSlot = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 2913 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 2914 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2915 | // Build the FP_TO_INT*_IN_MEM |
| 2916 | std::vector<SDOperand> Ops; |
| 2917 | Ops.push_back(Chain); |
| 2918 | Ops.push_back(Value); |
| 2919 | Ops.push_back(StackSlot); |
| 2920 | SDOperand FIST = DAG.getNode(Opc, MVT::Other, Ops); |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 2921 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2922 | // Load the result. |
| 2923 | return DAG.getLoad(Op.getValueType(), FIST, StackSlot, |
| 2924 | DAG.getSrcValue(NULL)); |
| 2925 | } |
| 2926 | |
| 2927 | SDOperand X86TargetLowering::LowerFABS(SDOperand Op, SelectionDAG &DAG) { |
| 2928 | MVT::ValueType VT = Op.getValueType(); |
| 2929 | const Type *OpNTy = MVT::getTypeForValueType(VT); |
| 2930 | std::vector<Constant*> CV; |
| 2931 | if (VT == MVT::f64) { |
| 2932 | CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(~(1ULL << 63)))); |
| 2933 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2934 | } else { |
| 2935 | CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(~(1U << 31)))); |
| 2936 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2937 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2938 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2939 | } |
| 2940 | Constant *CS = ConstantStruct::get(CV); |
| 2941 | SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4); |
| 2942 | SDOperand Mask |
| 2943 | = DAG.getNode(X86ISD::LOAD_PACK, |
| 2944 | VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL)); |
| 2945 | return DAG.getNode(X86ISD::FAND, VT, Op.getOperand(0), Mask); |
| 2946 | } |
| 2947 | |
| 2948 | SDOperand X86TargetLowering::LowerFNEG(SDOperand Op, SelectionDAG &DAG) { |
| 2949 | MVT::ValueType VT = Op.getValueType(); |
| 2950 | const Type *OpNTy = MVT::getTypeForValueType(VT); |
| 2951 | std::vector<Constant*> CV; |
| 2952 | if (VT == MVT::f64) { |
| 2953 | CV.push_back(ConstantFP::get(OpNTy, BitsToDouble(1ULL << 63))); |
| 2954 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2955 | } else { |
| 2956 | CV.push_back(ConstantFP::get(OpNTy, BitsToFloat(1U << 31))); |
| 2957 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2958 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2959 | CV.push_back(ConstantFP::get(OpNTy, 0.0)); |
| 2960 | } |
| 2961 | Constant *CS = ConstantStruct::get(CV); |
| 2962 | SDOperand CPIdx = DAG.getConstantPool(CS, getPointerTy(), 4); |
| 2963 | SDOperand Mask = DAG.getNode(X86ISD::LOAD_PACK, |
| 2964 | VT, DAG.getEntryNode(), CPIdx, DAG.getSrcValue(NULL)); |
| 2965 | return DAG.getNode(X86ISD::FXOR, VT, Op.getOperand(0), Mask); |
| 2966 | } |
| 2967 | |
| 2968 | SDOperand X86TargetLowering::LowerSETCC(SDOperand Op, SelectionDAG &DAG) { |
| 2969 | assert(Op.getValueType() == MVT::i8 && "SetCC type must be 8-bit integer"); |
| 2970 | SDOperand Cond; |
| 2971 | SDOperand CC = Op.getOperand(2); |
| 2972 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 2973 | bool isFP = MVT::isFloatingPoint(Op.getOperand(1).getValueType()); |
| 2974 | bool Flip; |
| 2975 | unsigned X86CC; |
| 2976 | if (translateX86CC(CC, isFP, X86CC, Flip)) { |
| 2977 | if (Flip) |
| 2978 | Cond = DAG.getNode(X86ISD::CMP, MVT::Flag, |
| 2979 | Op.getOperand(1), Op.getOperand(0)); |
| 2980 | else |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 2981 | Cond = DAG.getNode(X86ISD::CMP, MVT::Flag, |
| 2982 | Op.getOperand(0), Op.getOperand(1)); |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 2983 | return DAG.getNode(X86ISD::SETCC, MVT::i8, |
| 2984 | DAG.getConstant(X86CC, MVT::i8), Cond); |
| 2985 | } else { |
| 2986 | assert(isFP && "Illegal integer SetCC!"); |
| 2987 | |
| 2988 | Cond = DAG.getNode(X86ISD::CMP, MVT::Flag, |
| 2989 | Op.getOperand(0), Op.getOperand(1)); |
| 2990 | std::vector<MVT::ValueType> Tys; |
| 2991 | std::vector<SDOperand> Ops; |
| 2992 | switch (SetCCOpcode) { |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 2993 | default: assert(false && "Illegal floating point SetCC!"); |
| 2994 | case ISD::SETOEQ: { // !PF & ZF |
| 2995 | Tys.push_back(MVT::i8); |
| 2996 | Tys.push_back(MVT::Flag); |
| 2997 | Ops.push_back(DAG.getConstant(X86ISD::COND_NP, MVT::i8)); |
| 2998 | Ops.push_back(Cond); |
| 2999 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops); |
| 3000 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8, |
| 3001 | DAG.getConstant(X86ISD::COND_E, MVT::i8), |
| 3002 | Tmp1.getValue(1)); |
| 3003 | return DAG.getNode(ISD::AND, MVT::i8, Tmp1, Tmp2); |
| 3004 | } |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 3005 | case ISD::SETUNE: { // PF | !ZF |
| 3006 | Tys.push_back(MVT::i8); |
| 3007 | Tys.push_back(MVT::Flag); |
| 3008 | Ops.push_back(DAG.getConstant(X86ISD::COND_P, MVT::i8)); |
| 3009 | Ops.push_back(Cond); |
| 3010 | SDOperand Tmp1 = DAG.getNode(X86ISD::SETCC, Tys, Ops); |
| 3011 | SDOperand Tmp2 = DAG.getNode(X86ISD::SETCC, MVT::i8, |
| 3012 | DAG.getConstant(X86ISD::COND_NE, MVT::i8), |
| 3013 | Tmp1.getValue(1)); |
| 3014 | return DAG.getNode(ISD::OR, MVT::i8, Tmp1, Tmp2); |
| 3015 | } |
Evan Cheng | 172fce7 | 2006-01-06 00:43:03 +0000 | [diff] [blame] | 3016 | } |
Evan Cheng | c1583db | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 3017 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3018 | } |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 3019 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3020 | SDOperand X86TargetLowering::LowerSELECT(SDOperand Op, SelectionDAG &DAG) { |
| 3021 | MVT::ValueType VT = Op.getValueType(); |
| 3022 | bool isFPStack = MVT::isFloatingPoint(VT) && !X86ScalarSSE; |
| 3023 | bool addTest = false; |
| 3024 | SDOperand Op0 = Op.getOperand(0); |
| 3025 | SDOperand Cond, CC; |
| 3026 | if (Op0.getOpcode() == ISD::SETCC) |
| 3027 | Op0 = LowerOperation(Op0, DAG); |
Evan Cheng | 944d1e9 | 2006-01-26 02:13:10 +0000 | [diff] [blame] | 3028 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3029 | if (Op0.getOpcode() == X86ISD::SETCC) { |
| 3030 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
| 3031 | // (since flag operand cannot be shared). If the X86ISD::SETCC does not |
| 3032 | // have another use it will be eliminated. |
| 3033 | // If the X86ISD::SETCC has more than one use, then it's probably better |
| 3034 | // to use a test instead of duplicating the X86ISD::CMP (for register |
| 3035 | // pressure reason). |
| 3036 | unsigned CmpOpc = Op0.getOperand(1).getOpcode(); |
| 3037 | if (CmpOpc == X86ISD::CMP || CmpOpc == X86ISD::COMI || |
| 3038 | CmpOpc == X86ISD::UCOMI) { |
| 3039 | if (!Op0.hasOneUse()) { |
| 3040 | std::vector<MVT::ValueType> Tys; |
| 3041 | for (unsigned i = 0; i < Op0.Val->getNumValues(); ++i) |
| 3042 | Tys.push_back(Op0.Val->getValueType(i)); |
| 3043 | std::vector<SDOperand> Ops; |
| 3044 | for (unsigned i = 0; i < Op0.getNumOperands(); ++i) |
| 3045 | Ops.push_back(Op0.getOperand(i)); |
| 3046 | Op0 = DAG.getNode(X86ISD::SETCC, Tys, Ops); |
| 3047 | } |
| 3048 | |
| 3049 | CC = Op0.getOperand(0); |
| 3050 | Cond = Op0.getOperand(1); |
| 3051 | // Make a copy as flag result cannot be used by more than one. |
| 3052 | Cond = DAG.getNode(CmpOpc, MVT::Flag, |
| 3053 | Cond.getOperand(0), Cond.getOperand(1)); |
| 3054 | addTest = |
| 3055 | isFPStack && !hasFPCMov(cast<ConstantSDNode>(CC)->getSignExtended()); |
Evan Cheng | fb22e86 | 2006-01-13 01:03:02 +0000 | [diff] [blame] | 3056 | } else |
| 3057 | addTest = true; |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3058 | } else |
| 3059 | addTest = true; |
Evan Cheng | 73a1ad9 | 2006-01-10 20:26:56 +0000 | [diff] [blame] | 3060 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3061 | if (addTest) { |
| 3062 | CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8); |
| 3063 | Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Op0, Op0); |
Evan Cheng | 225a4d0 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 3064 | } |
Evan Cheng | 45df7f8 | 2006-01-30 23:41:35 +0000 | [diff] [blame] | 3065 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3066 | std::vector<MVT::ValueType> Tys; |
| 3067 | Tys.push_back(Op.getValueType()); |
| 3068 | Tys.push_back(MVT::Flag); |
| 3069 | std::vector<SDOperand> Ops; |
| 3070 | // X86ISD::CMOV means set the result (which is operand 1) to the RHS if |
| 3071 | // condition is true. |
| 3072 | Ops.push_back(Op.getOperand(2)); |
| 3073 | Ops.push_back(Op.getOperand(1)); |
| 3074 | Ops.push_back(CC); |
| 3075 | Ops.push_back(Cond); |
| 3076 | return DAG.getNode(X86ISD::CMOV, Tys, Ops); |
| 3077 | } |
Evan Cheng | 944d1e9 | 2006-01-26 02:13:10 +0000 | [diff] [blame] | 3078 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3079 | SDOperand X86TargetLowering::LowerBRCOND(SDOperand Op, SelectionDAG &DAG) { |
| 3080 | bool addTest = false; |
| 3081 | SDOperand Cond = Op.getOperand(1); |
| 3082 | SDOperand Dest = Op.getOperand(2); |
| 3083 | SDOperand CC; |
| 3084 | if (Cond.getOpcode() == ISD::SETCC) |
| 3085 | Cond = LowerOperation(Cond, DAG); |
| 3086 | |
| 3087 | if (Cond.getOpcode() == X86ISD::SETCC) { |
| 3088 | // If condition flag is set by a X86ISD::CMP, then make a copy of it |
| 3089 | // (since flag operand cannot be shared). If the X86ISD::SETCC does not |
| 3090 | // have another use it will be eliminated. |
| 3091 | // If the X86ISD::SETCC has more than one use, then it's probably better |
| 3092 | // to use a test instead of duplicating the X86ISD::CMP (for register |
| 3093 | // pressure reason). |
| 3094 | unsigned CmpOpc = Cond.getOperand(1).getOpcode(); |
| 3095 | if (CmpOpc == X86ISD::CMP || CmpOpc == X86ISD::COMI || |
| 3096 | CmpOpc == X86ISD::UCOMI) { |
| 3097 | if (!Cond.hasOneUse()) { |
| 3098 | std::vector<MVT::ValueType> Tys; |
| 3099 | for (unsigned i = 0; i < Cond.Val->getNumValues(); ++i) |
| 3100 | Tys.push_back(Cond.Val->getValueType(i)); |
| 3101 | std::vector<SDOperand> Ops; |
| 3102 | for (unsigned i = 0; i < Cond.getNumOperands(); ++i) |
| 3103 | Ops.push_back(Cond.getOperand(i)); |
| 3104 | Cond = DAG.getNode(X86ISD::SETCC, Tys, Ops); |
| 3105 | } |
| 3106 | |
| 3107 | CC = Cond.getOperand(0); |
| 3108 | Cond = Cond.getOperand(1); |
| 3109 | // Make a copy as flag result cannot be used by more than one. |
| 3110 | Cond = DAG.getNode(CmpOpc, MVT::Flag, |
| 3111 | Cond.getOperand(0), Cond.getOperand(1)); |
Evan Cheng | fb22e86 | 2006-01-13 01:03:02 +0000 | [diff] [blame] | 3112 | } else |
| 3113 | addTest = true; |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3114 | } else |
| 3115 | addTest = true; |
Evan Cheng | fb22e86 | 2006-01-13 01:03:02 +0000 | [diff] [blame] | 3116 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3117 | if (addTest) { |
| 3118 | CC = DAG.getConstant(X86ISD::COND_NE, MVT::i8); |
| 3119 | Cond = DAG.getNode(X86ISD::TEST, MVT::Flag, Cond, Cond); |
Evan Cheng | 6fc3104 | 2005-12-19 23:12:38 +0000 | [diff] [blame] | 3120 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3121 | return DAG.getNode(X86ISD::BRCOND, Op.getValueType(), |
| 3122 | Op.getOperand(0), Op.getOperand(2), CC, Cond); |
| 3123 | } |
Evan Cheng | ae986f1 | 2006-01-11 22:15:48 +0000 | [diff] [blame] | 3124 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3125 | SDOperand X86TargetLowering::LowerJumpTable(SDOperand Op, SelectionDAG &DAG) { |
| 3126 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Op); |
| 3127 | SDOperand Result = DAG.getNode(X86ISD::Wrapper, getPointerTy(), |
| 3128 | DAG.getTargetJumpTable(JT->getIndex(), |
| 3129 | getPointerTy())); |
| 3130 | if (Subtarget->isTargetDarwin()) { |
| 3131 | // With PIC, the address is actually $g + Offset. |
| 3132 | if (getTargetMachine().getRelocationModel() == Reloc::PIC) |
| 3133 | Result = DAG.getNode(ISD::ADD, getPointerTy(), |
| 3134 | DAG.getNode(X86ISD::GlobalBaseReg, getPointerTy()), Result); |
Evan Cheng | ae986f1 | 2006-01-11 22:15:48 +0000 | [diff] [blame] | 3135 | } |
Evan Cheng | 9947001 | 2006-02-25 09:55:19 +0000 | [diff] [blame] | 3136 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3137 | return Result; |
| 3138 | } |
Evan Cheng | 5588de9 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 3139 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3140 | SDOperand X86TargetLowering::LowerRET(SDOperand Op, SelectionDAG &DAG) { |
| 3141 | SDOperand Copy; |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3142 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3143 | switch(Op.getNumOperands()) { |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3144 | default: |
| 3145 | assert(0 && "Do not know how to return this many arguments!"); |
| 3146 | abort(); |
Chris Lattner | c070c62 | 2006-04-17 20:32:50 +0000 | [diff] [blame] | 3147 | case 1: // ret void. |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3148 | return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, Op.getOperand(0), |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3149 | DAG.getConstant(getBytesToPopOnReturn(), MVT::i16)); |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3150 | case 2: { |
| 3151 | MVT::ValueType ArgVT = Op.getOperand(1).getValueType(); |
Chris Lattner | c070c62 | 2006-04-17 20:32:50 +0000 | [diff] [blame] | 3152 | |
| 3153 | if (MVT::isVector(ArgVT)) { |
| 3154 | // Integer or FP vector result -> XMM0. |
| 3155 | if (DAG.getMachineFunction().liveout_empty()) |
| 3156 | DAG.getMachineFunction().addLiveOut(X86::XMM0); |
| 3157 | Copy = DAG.getCopyToReg(Op.getOperand(0), X86::XMM0, Op.getOperand(1), |
| 3158 | SDOperand()); |
| 3159 | } else if (MVT::isInteger(ArgVT)) { |
| 3160 | // Integer result -> EAX |
| 3161 | if (DAG.getMachineFunction().liveout_empty()) |
| 3162 | DAG.getMachineFunction().addLiveOut(X86::EAX); |
| 3163 | |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3164 | Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EAX, Op.getOperand(1), |
| 3165 | SDOperand()); |
Chris Lattner | c070c62 | 2006-04-17 20:32:50 +0000 | [diff] [blame] | 3166 | } else if (!X86ScalarSSE) { |
| 3167 | // FP return with fp-stack value. |
| 3168 | if (DAG.getMachineFunction().liveout_empty()) |
| 3169 | DAG.getMachineFunction().addLiveOut(X86::ST0); |
| 3170 | |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3171 | std::vector<MVT::ValueType> Tys; |
| 3172 | Tys.push_back(MVT::Other); |
| 3173 | Tys.push_back(MVT::Flag); |
| 3174 | std::vector<SDOperand> Ops; |
| 3175 | Ops.push_back(Op.getOperand(0)); |
| 3176 | Ops.push_back(Op.getOperand(1)); |
| 3177 | Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops); |
| 3178 | } else { |
Chris Lattner | c070c62 | 2006-04-17 20:32:50 +0000 | [diff] [blame] | 3179 | // FP return with ScalarSSE (return on fp-stack). |
| 3180 | if (DAG.getMachineFunction().liveout_empty()) |
| 3181 | DAG.getMachineFunction().addLiveOut(X86::ST0); |
| 3182 | |
Evan Cheng | e1ce4d7 | 2006-02-01 00:20:21 +0000 | [diff] [blame] | 3183 | SDOperand MemLoc; |
| 3184 | SDOperand Chain = Op.getOperand(0); |
Evan Cheng | 5659ca8 | 2006-01-31 23:19:54 +0000 | [diff] [blame] | 3185 | SDOperand Value = Op.getOperand(1); |
| 3186 | |
Evan Cheng | a24617f | 2006-02-01 01:19:32 +0000 | [diff] [blame] | 3187 | if (Value.getOpcode() == ISD::LOAD && |
| 3188 | (Chain == Value.getValue(1) || Chain == Value.getOperand(0))) { |
Evan Cheng | 5659ca8 | 2006-01-31 23:19:54 +0000 | [diff] [blame] | 3189 | Chain = Value.getOperand(0); |
| 3190 | MemLoc = Value.getOperand(1); |
| 3191 | } else { |
| 3192 | // Spill the value to memory and reload it into top of stack. |
| 3193 | unsigned Size = MVT::getSizeInBits(ArgVT)/8; |
| 3194 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3195 | int SSFI = MF.getFrameInfo()->CreateStackObject(Size, Size); |
| 3196 | MemLoc = DAG.getFrameIndex(SSFI, getPointerTy()); |
| 3197 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), |
| 3198 | Value, MemLoc, DAG.getSrcValue(0)); |
| 3199 | } |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3200 | std::vector<MVT::ValueType> Tys; |
| 3201 | Tys.push_back(MVT::f64); |
| 3202 | Tys.push_back(MVT::Other); |
| 3203 | std::vector<SDOperand> Ops; |
| 3204 | Ops.push_back(Chain); |
Evan Cheng | 5659ca8 | 2006-01-31 23:19:54 +0000 | [diff] [blame] | 3205 | Ops.push_back(MemLoc); |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3206 | Ops.push_back(DAG.getValueType(ArgVT)); |
| 3207 | Copy = DAG.getNode(X86ISD::FLD, Tys, Ops); |
| 3208 | Tys.clear(); |
| 3209 | Tys.push_back(MVT::Other); |
| 3210 | Tys.push_back(MVT::Flag); |
| 3211 | Ops.clear(); |
| 3212 | Ops.push_back(Copy.getValue(1)); |
| 3213 | Ops.push_back(Copy); |
| 3214 | Copy = DAG.getNode(X86ISD::FP_SET_RESULT, Tys, Ops); |
| 3215 | } |
| 3216 | break; |
| 3217 | } |
| 3218 | case 3: |
Chris Lattner | c070c62 | 2006-04-17 20:32:50 +0000 | [diff] [blame] | 3219 | if (DAG.getMachineFunction().liveout_empty()) { |
| 3220 | DAG.getMachineFunction().addLiveOut(X86::EAX); |
| 3221 | DAG.getMachineFunction().addLiveOut(X86::EDX); |
| 3222 | } |
| 3223 | |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3224 | Copy = DAG.getCopyToReg(Op.getOperand(0), X86::EDX, Op.getOperand(2), |
| 3225 | SDOperand()); |
| 3226 | Copy = DAG.getCopyToReg(Copy, X86::EAX,Op.getOperand(1),Copy.getValue(1)); |
| 3227 | break; |
Nate Begeman | 8c47c3a | 2006-01-27 21:09:22 +0000 | [diff] [blame] | 3228 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3229 | return DAG.getNode(X86ISD::RET_FLAG, MVT::Other, |
| 3230 | Copy, DAG.getConstant(getBytesToPopOnReturn(), MVT::i16), |
| 3231 | Copy.getValue(1)); |
| 3232 | } |
| 3233 | |
| 3234 | SDOperand X86TargetLowering::LowerMEMSET(SDOperand Op, SelectionDAG &DAG) { |
| 3235 | SDOperand InFlag(0, 0); |
| 3236 | SDOperand Chain = Op.getOperand(0); |
| 3237 | unsigned Align = |
| 3238 | (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue(); |
| 3239 | if (Align == 0) Align = 1; |
| 3240 | |
| 3241 | ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)); |
| 3242 | // If not DWORD aligned, call memset if size is less than the threshold. |
| 3243 | // It knows how to align to the right boundary first. |
| 3244 | if ((Align & 3) != 0 || |
| 3245 | (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) { |
| 3246 | MVT::ValueType IntPtr = getPointerTy(); |
| 3247 | const Type *IntPtrTy = getTargetData().getIntPtrType(); |
| 3248 | std::vector<std::pair<SDOperand, const Type*> > Args; |
| 3249 | Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy)); |
| 3250 | // Extend the ubyte argument to be an int value for the call. |
| 3251 | SDOperand Val = DAG.getNode(ISD::ZERO_EXTEND, MVT::i32, Op.getOperand(2)); |
| 3252 | Args.push_back(std::make_pair(Val, IntPtrTy)); |
| 3253 | Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy)); |
| 3254 | std::pair<SDOperand,SDOperand> CallResult = |
| 3255 | LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false, |
| 3256 | DAG.getExternalSymbol("memset", IntPtr), Args, DAG); |
| 3257 | return CallResult.second; |
Evan Cheng | d5e905d | 2006-03-21 23:01:21 +0000 | [diff] [blame] | 3258 | } |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 3259 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3260 | MVT::ValueType AVT; |
| 3261 | SDOperand Count; |
| 3262 | ConstantSDNode *ValC = dyn_cast<ConstantSDNode>(Op.getOperand(2)); |
| 3263 | unsigned BytesLeft = 0; |
| 3264 | bool TwoRepStos = false; |
| 3265 | if (ValC) { |
| 3266 | unsigned ValReg; |
| 3267 | unsigned Val = ValC->getValue() & 255; |
Evan Cheng | c995b45 | 2006-04-06 23:23:56 +0000 | [diff] [blame] | 3268 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3269 | // If the value is a constant, then we can potentially use larger sets. |
| 3270 | switch (Align & 3) { |
| 3271 | case 2: // WORD aligned |
| 3272 | AVT = MVT::i16; |
| 3273 | Count = DAG.getConstant(I->getValue() / 2, MVT::i32); |
| 3274 | BytesLeft = I->getValue() % 2; |
| 3275 | Val = (Val << 8) | Val; |
| 3276 | ValReg = X86::AX; |
| 3277 | break; |
| 3278 | case 0: // DWORD aligned |
| 3279 | AVT = MVT::i32; |
| 3280 | if (I) { |
| 3281 | Count = DAG.getConstant(I->getValue() / 4, MVT::i32); |
| 3282 | BytesLeft = I->getValue() % 4; |
Evan Cheng | a3caaee | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 3283 | } else { |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3284 | Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3), |
| 3285 | DAG.getConstant(2, MVT::i8)); |
| 3286 | TwoRepStos = true; |
Evan Cheng | a3caaee | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 3287 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3288 | Val = (Val << 8) | Val; |
| 3289 | Val = (Val << 16) | Val; |
| 3290 | ValReg = X86::EAX; |
| 3291 | break; |
| 3292 | default: // Byte aligned |
| 3293 | AVT = MVT::i8; |
| 3294 | Count = Op.getOperand(3); |
| 3295 | ValReg = X86::AL; |
| 3296 | break; |
Evan Cheng | a3caaee | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 3297 | } |
| 3298 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3299 | Chain = DAG.getCopyToReg(Chain, ValReg, DAG.getConstant(Val, AVT), |
| 3300 | InFlag); |
| 3301 | InFlag = Chain.getValue(1); |
| 3302 | } else { |
| 3303 | AVT = MVT::i8; |
| 3304 | Count = Op.getOperand(3); |
| 3305 | Chain = DAG.getCopyToReg(Chain, X86::AL, Op.getOperand(2), InFlag); |
| 3306 | InFlag = Chain.getValue(1); |
Evan Cheng | d097e67 | 2006-03-22 02:53:00 +0000 | [diff] [blame] | 3307 | } |
Evan Cheng | b046108 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 3308 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3309 | Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag); |
| 3310 | InFlag = Chain.getValue(1); |
| 3311 | Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag); |
| 3312 | InFlag = Chain.getValue(1); |
Evan Cheng | 9b9cc4f | 2006-03-27 07:00:16 +0000 | [diff] [blame] | 3313 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3314 | std::vector<MVT::ValueType> Tys; |
| 3315 | Tys.push_back(MVT::Other); |
| 3316 | Tys.push_back(MVT::Flag); |
| 3317 | std::vector<SDOperand> Ops; |
| 3318 | Ops.push_back(Chain); |
| 3319 | Ops.push_back(DAG.getValueType(AVT)); |
| 3320 | Ops.push_back(InFlag); |
| 3321 | Chain = DAG.getNode(X86ISD::REP_STOS, Tys, Ops); |
Evan Cheng | b046108 | 2006-04-24 18:01:45 +0000 | [diff] [blame] | 3322 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3323 | if (TwoRepStos) { |
| 3324 | InFlag = Chain.getValue(1); |
| 3325 | Count = Op.getOperand(3); |
| 3326 | MVT::ValueType CVT = Count.getValueType(); |
| 3327 | SDOperand Left = DAG.getNode(ISD::AND, CVT, Count, |
| 3328 | DAG.getConstant(3, CVT)); |
| 3329 | Chain = DAG.getCopyToReg(Chain, X86::ECX, Left, InFlag); |
| 3330 | InFlag = Chain.getValue(1); |
| 3331 | Tys.clear(); |
| 3332 | Tys.push_back(MVT::Other); |
| 3333 | Tys.push_back(MVT::Flag); |
| 3334 | Ops.clear(); |
| 3335 | Ops.push_back(Chain); |
| 3336 | Ops.push_back(DAG.getValueType(MVT::i8)); |
| 3337 | Ops.push_back(InFlag); |
| 3338 | Chain = DAG.getNode(X86ISD::REP_STOS, Tys, Ops); |
| 3339 | } else if (BytesLeft) { |
| 3340 | // Issue stores for the last 1 - 3 bytes. |
| 3341 | SDOperand Value; |
| 3342 | unsigned Val = ValC->getValue() & 255; |
| 3343 | unsigned Offset = I->getValue() - BytesLeft; |
| 3344 | SDOperand DstAddr = Op.getOperand(1); |
| 3345 | MVT::ValueType AddrVT = DstAddr.getValueType(); |
| 3346 | if (BytesLeft >= 2) { |
| 3347 | Value = DAG.getConstant((Val << 8) | Val, MVT::i16); |
| 3348 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, |
| 3349 | DAG.getNode(ISD::ADD, AddrVT, DstAddr, |
| 3350 | DAG.getConstant(Offset, AddrVT)), |
| 3351 | DAG.getSrcValue(NULL)); |
| 3352 | BytesLeft -= 2; |
| 3353 | Offset += 2; |
Evan Cheng | 082c878 | 2006-03-24 07:29:27 +0000 | [diff] [blame] | 3354 | } |
| 3355 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3356 | if (BytesLeft == 1) { |
| 3357 | Value = DAG.getConstant(Val, MVT::i8); |
| 3358 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, |
| 3359 | DAG.getNode(ISD::ADD, AddrVT, DstAddr, |
| 3360 | DAG.getConstant(Offset, AddrVT)), |
| 3361 | DAG.getSrcValue(NULL)); |
Evan Cheng | 14215c3 | 2006-04-21 23:03:30 +0000 | [diff] [blame] | 3362 | } |
Evan Cheng | 082c878 | 2006-03-24 07:29:27 +0000 | [diff] [blame] | 3363 | } |
Evan Cheng | ebf1006 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 3364 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3365 | return Chain; |
| 3366 | } |
Evan Cheng | ebf1006 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 3367 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3368 | SDOperand X86TargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) { |
| 3369 | SDOperand Chain = Op.getOperand(0); |
| 3370 | unsigned Align = |
| 3371 | (unsigned)cast<ConstantSDNode>(Op.getOperand(4))->getValue(); |
| 3372 | if (Align == 0) Align = 1; |
Evan Cheng | ebf1006 | 2006-04-03 20:53:28 +0000 | [diff] [blame] | 3373 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3374 | ConstantSDNode *I = dyn_cast<ConstantSDNode>(Op.getOperand(3)); |
| 3375 | // If not DWORD aligned, call memcpy if size is less than the threshold. |
| 3376 | // It knows how to align to the right boundary first. |
| 3377 | if ((Align & 3) != 0 || |
| 3378 | (I && I->getValue() < Subtarget->getMinRepStrSizeThreshold())) { |
| 3379 | MVT::ValueType IntPtr = getPointerTy(); |
| 3380 | const Type *IntPtrTy = getTargetData().getIntPtrType(); |
| 3381 | std::vector<std::pair<SDOperand, const Type*> > Args; |
| 3382 | Args.push_back(std::make_pair(Op.getOperand(1), IntPtrTy)); |
| 3383 | Args.push_back(std::make_pair(Op.getOperand(2), IntPtrTy)); |
| 3384 | Args.push_back(std::make_pair(Op.getOperand(3), IntPtrTy)); |
| 3385 | std::pair<SDOperand,SDOperand> CallResult = |
| 3386 | LowerCallTo(Chain, Type::VoidTy, false, CallingConv::C, false, |
| 3387 | DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG); |
| 3388 | return CallResult.second; |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 3389 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3390 | |
| 3391 | MVT::ValueType AVT; |
| 3392 | SDOperand Count; |
| 3393 | unsigned BytesLeft = 0; |
| 3394 | bool TwoRepMovs = false; |
| 3395 | switch (Align & 3) { |
| 3396 | case 2: // WORD aligned |
| 3397 | AVT = MVT::i16; |
| 3398 | Count = DAG.getConstant(I->getValue() / 2, MVT::i32); |
| 3399 | BytesLeft = I->getValue() % 2; |
| 3400 | break; |
| 3401 | case 0: // DWORD aligned |
| 3402 | AVT = MVT::i32; |
| 3403 | if (I) { |
| 3404 | Count = DAG.getConstant(I->getValue() / 4, MVT::i32); |
| 3405 | BytesLeft = I->getValue() % 4; |
Evan Cheng | 5421206 | 2006-04-17 22:45:49 +0000 | [diff] [blame] | 3406 | } else { |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3407 | Count = DAG.getNode(ISD::SRL, MVT::i32, Op.getOperand(3), |
| 3408 | DAG.getConstant(2, MVT::i8)); |
| 3409 | TwoRepMovs = true; |
Evan Cheng | 6e5e205 | 2006-04-17 22:04:06 +0000 | [diff] [blame] | 3410 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3411 | break; |
| 3412 | default: // Byte aligned |
| 3413 | AVT = MVT::i8; |
| 3414 | Count = Op.getOperand(3); |
| 3415 | break; |
| 3416 | } |
| 3417 | |
| 3418 | SDOperand InFlag(0, 0); |
| 3419 | Chain = DAG.getCopyToReg(Chain, X86::ECX, Count, InFlag); |
| 3420 | InFlag = Chain.getValue(1); |
| 3421 | Chain = DAG.getCopyToReg(Chain, X86::EDI, Op.getOperand(1), InFlag); |
| 3422 | InFlag = Chain.getValue(1); |
| 3423 | Chain = DAG.getCopyToReg(Chain, X86::ESI, Op.getOperand(2), InFlag); |
| 3424 | InFlag = Chain.getValue(1); |
| 3425 | |
| 3426 | std::vector<MVT::ValueType> Tys; |
| 3427 | Tys.push_back(MVT::Other); |
| 3428 | Tys.push_back(MVT::Flag); |
| 3429 | std::vector<SDOperand> Ops; |
| 3430 | Ops.push_back(Chain); |
| 3431 | Ops.push_back(DAG.getValueType(AVT)); |
| 3432 | Ops.push_back(InFlag); |
| 3433 | Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, Ops); |
| 3434 | |
| 3435 | if (TwoRepMovs) { |
| 3436 | InFlag = Chain.getValue(1); |
| 3437 | Count = Op.getOperand(3); |
| 3438 | MVT::ValueType CVT = Count.getValueType(); |
| 3439 | SDOperand Left = DAG.getNode(ISD::AND, CVT, Count, |
| 3440 | DAG.getConstant(3, CVT)); |
| 3441 | Chain = DAG.getCopyToReg(Chain, X86::ECX, Left, InFlag); |
| 3442 | InFlag = Chain.getValue(1); |
| 3443 | Tys.clear(); |
| 3444 | Tys.push_back(MVT::Other); |
| 3445 | Tys.push_back(MVT::Flag); |
| 3446 | Ops.clear(); |
| 3447 | Ops.push_back(Chain); |
| 3448 | Ops.push_back(DAG.getValueType(MVT::i8)); |
| 3449 | Ops.push_back(InFlag); |
| 3450 | Chain = DAG.getNode(X86ISD::REP_MOVS, Tys, Ops); |
| 3451 | } else if (BytesLeft) { |
| 3452 | // Issue loads and stores for the last 1 - 3 bytes. |
| 3453 | unsigned Offset = I->getValue() - BytesLeft; |
| 3454 | SDOperand DstAddr = Op.getOperand(1); |
| 3455 | MVT::ValueType DstVT = DstAddr.getValueType(); |
| 3456 | SDOperand SrcAddr = Op.getOperand(2); |
| 3457 | MVT::ValueType SrcVT = SrcAddr.getValueType(); |
| 3458 | SDOperand Value; |
| 3459 | if (BytesLeft >= 2) { |
| 3460 | Value = DAG.getLoad(MVT::i16, Chain, |
| 3461 | DAG.getNode(ISD::ADD, SrcVT, SrcAddr, |
| 3462 | DAG.getConstant(Offset, SrcVT)), |
| 3463 | DAG.getSrcValue(NULL)); |
| 3464 | Chain = Value.getValue(1); |
| 3465 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, |
| 3466 | DAG.getNode(ISD::ADD, DstVT, DstAddr, |
| 3467 | DAG.getConstant(Offset, DstVT)), |
| 3468 | DAG.getSrcValue(NULL)); |
| 3469 | BytesLeft -= 2; |
| 3470 | Offset += 2; |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 3471 | } |
| 3472 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3473 | if (BytesLeft == 1) { |
| 3474 | Value = DAG.getLoad(MVT::i8, Chain, |
| 3475 | DAG.getNode(ISD::ADD, SrcVT, SrcAddr, |
| 3476 | DAG.getConstant(Offset, SrcVT)), |
| 3477 | DAG.getSrcValue(NULL)); |
| 3478 | Chain = Value.getValue(1); |
| 3479 | Chain = DAG.getNode(ISD::STORE, MVT::Other, Chain, Value, |
| 3480 | DAG.getNode(ISD::ADD, DstVT, DstAddr, |
| 3481 | DAG.getConstant(Offset, DstVT)), |
| 3482 | DAG.getSrcValue(NULL)); |
| 3483 | } |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 3484 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3485 | |
| 3486 | return Chain; |
| 3487 | } |
| 3488 | |
| 3489 | SDOperand |
| 3490 | X86TargetLowering::LowerREADCYCLCECOUNTER(SDOperand Op, SelectionDAG &DAG) { |
| 3491 | std::vector<MVT::ValueType> Tys; |
| 3492 | Tys.push_back(MVT::Other); |
| 3493 | Tys.push_back(MVT::Flag); |
| 3494 | std::vector<SDOperand> Ops; |
| 3495 | Ops.push_back(Op.getOperand(0)); |
| 3496 | SDOperand rd = DAG.getNode(X86ISD::RDTSC_DAG, Tys, Ops); |
| 3497 | Ops.clear(); |
| 3498 | Ops.push_back(DAG.getCopyFromReg(rd, X86::EAX, MVT::i32, rd.getValue(1))); |
| 3499 | Ops.push_back(DAG.getCopyFromReg(Ops[0].getValue(1), X86::EDX, |
| 3500 | MVT::i32, Ops[0].getValue(2))); |
| 3501 | Ops.push_back(Ops[1].getValue(1)); |
| 3502 | Tys[0] = Tys[1] = MVT::i32; |
| 3503 | Tys.push_back(MVT::Other); |
| 3504 | return DAG.getNode(ISD::MERGE_VALUES, Tys, Ops); |
| 3505 | } |
| 3506 | |
| 3507 | SDOperand X86TargetLowering::LowerVASTART(SDOperand Op, SelectionDAG &DAG) { |
| 3508 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 3509 | // memory location argument. |
| 3510 | // FIXME: Replace MVT::i32 with PointerTy |
| 3511 | SDOperand FR = DAG.getFrameIndex(VarArgsFrameIndex, MVT::i32); |
| 3512 | return DAG.getNode(ISD::STORE, MVT::Other, Op.getOperand(0), FR, |
| 3513 | Op.getOperand(1), Op.getOperand(2)); |
| 3514 | } |
| 3515 | |
| 3516 | SDOperand |
| 3517 | X86TargetLowering::LowerINTRINSIC_WO_CHAIN(SDOperand Op, SelectionDAG &DAG) { |
| 3518 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getValue(); |
| 3519 | switch (IntNo) { |
| 3520 | default: return SDOperand(); // Don't custom lower most intrinsics. |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3521 | // Comparison intrinsics. |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3522 | case Intrinsic::x86_sse_comieq_ss: |
| 3523 | case Intrinsic::x86_sse_comilt_ss: |
| 3524 | case Intrinsic::x86_sse_comile_ss: |
| 3525 | case Intrinsic::x86_sse_comigt_ss: |
| 3526 | case Intrinsic::x86_sse_comige_ss: |
| 3527 | case Intrinsic::x86_sse_comineq_ss: |
| 3528 | case Intrinsic::x86_sse_ucomieq_ss: |
| 3529 | case Intrinsic::x86_sse_ucomilt_ss: |
| 3530 | case Intrinsic::x86_sse_ucomile_ss: |
| 3531 | case Intrinsic::x86_sse_ucomigt_ss: |
| 3532 | case Intrinsic::x86_sse_ucomige_ss: |
| 3533 | case Intrinsic::x86_sse_ucomineq_ss: |
| 3534 | case Intrinsic::x86_sse2_comieq_sd: |
| 3535 | case Intrinsic::x86_sse2_comilt_sd: |
| 3536 | case Intrinsic::x86_sse2_comile_sd: |
| 3537 | case Intrinsic::x86_sse2_comigt_sd: |
| 3538 | case Intrinsic::x86_sse2_comige_sd: |
| 3539 | case Intrinsic::x86_sse2_comineq_sd: |
| 3540 | case Intrinsic::x86_sse2_ucomieq_sd: |
| 3541 | case Intrinsic::x86_sse2_ucomilt_sd: |
| 3542 | case Intrinsic::x86_sse2_ucomile_sd: |
| 3543 | case Intrinsic::x86_sse2_ucomigt_sd: |
| 3544 | case Intrinsic::x86_sse2_ucomige_sd: |
| 3545 | case Intrinsic::x86_sse2_ucomineq_sd: { |
| 3546 | unsigned Opc = 0; |
| 3547 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 3548 | switch (IntNo) { |
| 3549 | default: break; |
| 3550 | case Intrinsic::x86_sse_comieq_ss: |
| 3551 | case Intrinsic::x86_sse2_comieq_sd: |
| 3552 | Opc = X86ISD::COMI; |
| 3553 | CC = ISD::SETEQ; |
| 3554 | break; |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3555 | case Intrinsic::x86_sse_comilt_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3556 | case Intrinsic::x86_sse2_comilt_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3557 | Opc = X86ISD::COMI; |
| 3558 | CC = ISD::SETLT; |
| 3559 | break; |
| 3560 | case Intrinsic::x86_sse_comile_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3561 | case Intrinsic::x86_sse2_comile_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3562 | Opc = X86ISD::COMI; |
| 3563 | CC = ISD::SETLE; |
| 3564 | break; |
| 3565 | case Intrinsic::x86_sse_comigt_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3566 | case Intrinsic::x86_sse2_comigt_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3567 | Opc = X86ISD::COMI; |
| 3568 | CC = ISD::SETGT; |
| 3569 | break; |
| 3570 | case Intrinsic::x86_sse_comige_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3571 | case Intrinsic::x86_sse2_comige_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3572 | Opc = X86ISD::COMI; |
| 3573 | CC = ISD::SETGE; |
| 3574 | break; |
| 3575 | case Intrinsic::x86_sse_comineq_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3576 | case Intrinsic::x86_sse2_comineq_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3577 | Opc = X86ISD::COMI; |
| 3578 | CC = ISD::SETNE; |
| 3579 | break; |
| 3580 | case Intrinsic::x86_sse_ucomieq_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3581 | case Intrinsic::x86_sse2_ucomieq_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3582 | Opc = X86ISD::UCOMI; |
| 3583 | CC = ISD::SETEQ; |
| 3584 | break; |
| 3585 | case Intrinsic::x86_sse_ucomilt_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3586 | case Intrinsic::x86_sse2_ucomilt_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3587 | Opc = X86ISD::UCOMI; |
| 3588 | CC = ISD::SETLT; |
| 3589 | break; |
| 3590 | case Intrinsic::x86_sse_ucomile_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3591 | case Intrinsic::x86_sse2_ucomile_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3592 | Opc = X86ISD::UCOMI; |
| 3593 | CC = ISD::SETLE; |
| 3594 | break; |
| 3595 | case Intrinsic::x86_sse_ucomigt_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3596 | case Intrinsic::x86_sse2_ucomigt_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3597 | Opc = X86ISD::UCOMI; |
| 3598 | CC = ISD::SETGT; |
| 3599 | break; |
| 3600 | case Intrinsic::x86_sse_ucomige_ss: |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3601 | case Intrinsic::x86_sse2_ucomige_sd: |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3602 | Opc = X86ISD::UCOMI; |
| 3603 | CC = ISD::SETGE; |
| 3604 | break; |
| 3605 | case Intrinsic::x86_sse_ucomineq_ss: |
| 3606 | case Intrinsic::x86_sse2_ucomineq_sd: |
| 3607 | Opc = X86ISD::UCOMI; |
| 3608 | CC = ISD::SETNE; |
| 3609 | break; |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3610 | } |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3611 | bool Flip; |
| 3612 | unsigned X86CC; |
| 3613 | translateX86CC(CC, true, X86CC, Flip); |
| 3614 | SDOperand Cond = DAG.getNode(Opc, MVT::Flag, Op.getOperand(Flip?2:1), |
| 3615 | Op.getOperand(Flip?1:2)); |
| 3616 | SDOperand SetCC = DAG.getNode(X86ISD::SETCC, MVT::i8, |
| 3617 | DAG.getConstant(X86CC, MVT::i8), Cond); |
| 3618 | return DAG.getNode(ISD::ANY_EXTEND, MVT::i32, SetCC); |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3619 | } |
Evan Cheng | 5c59d49 | 2005-12-23 07:31:11 +0000 | [diff] [blame] | 3620 | } |
Chris Lattner | 76ac068 | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 3621 | } |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3622 | |
Evan Cheng | a9467aa | 2006-04-25 20:13:52 +0000 | [diff] [blame^] | 3623 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 3624 | /// |
| 3625 | SDOperand X86TargetLowering::LowerOperation(SDOperand Op, SelectionDAG &DAG) { |
| 3626 | switch (Op.getOpcode()) { |
| 3627 | default: assert(0 && "Should not custom lower this!"); |
| 3628 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG); |
| 3629 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| 3630 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| 3631 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| 3632 | case ISD::SCALAR_TO_VECTOR: return LowerSCALAR_TO_VECTOR(Op, DAG); |
| 3633 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| 3634 | case ISD::GlobalAddress: return LowerGlobalAddress(Op, DAG); |
| 3635 | case ISD::ExternalSymbol: return LowerExternalSymbol(Op, DAG); |
| 3636 | case ISD::SHL_PARTS: |
| 3637 | case ISD::SRA_PARTS: |
| 3638 | case ISD::SRL_PARTS: return LowerShift(Op, DAG); |
| 3639 | case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG); |
| 3640 | case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG); |
| 3641 | case ISD::FABS: return LowerFABS(Op, DAG); |
| 3642 | case ISD::FNEG: return LowerFNEG(Op, DAG); |
| 3643 | case ISD::SETCC: return LowerSETCC(Op, DAG); |
| 3644 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
| 3645 | case ISD::BRCOND: return LowerBRCOND(Op, DAG); |
| 3646 | case ISD::JumpTable: return LowerJumpTable(Op, DAG); |
| 3647 | case ISD::RET: return LowerRET(Op, DAG); |
| 3648 | case ISD::MEMSET: return LowerMEMSET(Op, DAG); |
| 3649 | case ISD::MEMCPY: return LowerMEMCPY(Op, DAG); |
| 3650 | case ISD::READCYCLECOUNTER: return LowerREADCYCLCECOUNTER(Op, DAG); |
| 3651 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| 3652 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG); |
| 3653 | } |
| 3654 | } |
| 3655 | |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3656 | const char *X86TargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 3657 | switch (Opcode) { |
| 3658 | default: return NULL; |
Evan Cheng | 9c249c3 | 2006-01-09 18:33:28 +0000 | [diff] [blame] | 3659 | case X86ISD::SHLD: return "X86ISD::SHLD"; |
| 3660 | case X86ISD::SHRD: return "X86ISD::SHRD"; |
Evan Cheng | 2dd217b | 2006-01-31 03:14:29 +0000 | [diff] [blame] | 3661 | case X86ISD::FAND: return "X86ISD::FAND"; |
Evan Cheng | 72d5c25 | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 3662 | case X86ISD::FXOR: return "X86ISD::FXOR"; |
Evan Cheng | 6305e50 | 2006-01-12 22:54:21 +0000 | [diff] [blame] | 3663 | case X86ISD::FILD: return "X86ISD::FILD"; |
Evan Cheng | 11613a5 | 2006-02-04 02:20:30 +0000 | [diff] [blame] | 3664 | case X86ISD::FILD_FLAG: return "X86ISD::FILD_FLAG"; |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3665 | case X86ISD::FP_TO_INT16_IN_MEM: return "X86ISD::FP_TO_INT16_IN_MEM"; |
| 3666 | case X86ISD::FP_TO_INT32_IN_MEM: return "X86ISD::FP_TO_INT32_IN_MEM"; |
| 3667 | case X86ISD::FP_TO_INT64_IN_MEM: return "X86ISD::FP_TO_INT64_IN_MEM"; |
Evan Cheng | a74ce62 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 3668 | case X86ISD::FLD: return "X86ISD::FLD"; |
Evan Cheng | 45e19098 | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 3669 | case X86ISD::FST: return "X86ISD::FST"; |
| 3670 | case X86ISD::FP_GET_RESULT: return "X86ISD::FP_GET_RESULT"; |
Evan Cheng | a74ce62 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 3671 | case X86ISD::FP_SET_RESULT: return "X86ISD::FP_SET_RESULT"; |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3672 | case X86ISD::CALL: return "X86ISD::CALL"; |
| 3673 | case X86ISD::TAILCALL: return "X86ISD::TAILCALL"; |
| 3674 | case X86ISD::RDTSC_DAG: return "X86ISD::RDTSC_DAG"; |
| 3675 | case X86ISD::CMP: return "X86ISD::CMP"; |
| 3676 | case X86ISD::TEST: return "X86ISD::TEST"; |
Evan Cheng | 7803829 | 2006-04-05 23:38:46 +0000 | [diff] [blame] | 3677 | case X86ISD::COMI: return "X86ISD::COMI"; |
| 3678 | case X86ISD::UCOMI: return "X86ISD::UCOMI"; |
Evan Cheng | c1583db | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 3679 | case X86ISD::SETCC: return "X86ISD::SETCC"; |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3680 | case X86ISD::CMOV: return "X86ISD::CMOV"; |
| 3681 | case X86ISD::BRCOND: return "X86ISD::BRCOND"; |
Evan Cheng | a74ce62 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 3682 | case X86ISD::RET_FLAG: return "X86ISD::RET_FLAG"; |
Evan Cheng | 084a102 | 2006-03-04 01:12:00 +0000 | [diff] [blame] | 3683 | case X86ISD::REP_STOS: return "X86ISD::REP_STOS"; |
| 3684 | case X86ISD::REP_MOVS: return "X86ISD::REP_MOVS"; |
Evan Cheng | 72d5c25 | 2006-01-31 22:28:30 +0000 | [diff] [blame] | 3685 | case X86ISD::LOAD_PACK: return "X86ISD::LOAD_PACK"; |
Evan Cheng | 5588de9 | 2006-02-18 00:15:05 +0000 | [diff] [blame] | 3686 | case X86ISD::GlobalBaseReg: return "X86ISD::GlobalBaseReg"; |
Evan Cheng | e0ed6ec | 2006-02-23 20:41:18 +0000 | [diff] [blame] | 3687 | case X86ISD::Wrapper: return "X86ISD::Wrapper"; |
Evan Cheng | e7ee6a5 | 2006-03-24 23:15:12 +0000 | [diff] [blame] | 3688 | case X86ISD::S2VEC: return "X86ISD::S2VEC"; |
Evan Cheng | cbffa46 | 2006-03-31 19:22:53 +0000 | [diff] [blame] | 3689 | case X86ISD::PEXTRW: return "X86ISD::PEXTRW"; |
Evan Cheng | 5fd7c69 | 2006-03-31 21:55:24 +0000 | [diff] [blame] | 3690 | case X86ISD::PINSRW: return "X86ISD::PINSRW"; |
Evan Cheng | 6af0263 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 3691 | } |
| 3692 | } |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3693 | |
Nate Begeman | 8a77efe | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 3694 | void X86TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, |
| 3695 | uint64_t Mask, |
| 3696 | uint64_t &KnownZero, |
| 3697 | uint64_t &KnownOne, |
| 3698 | unsigned Depth) const { |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3699 | unsigned Opc = Op.getOpcode(); |
Evan Cheng | 6d196db | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 3700 | assert((Opc >= ISD::BUILTIN_OP_END || |
| 3701 | Opc == ISD::INTRINSIC_WO_CHAIN || |
| 3702 | Opc == ISD::INTRINSIC_W_CHAIN || |
| 3703 | Opc == ISD::INTRINSIC_VOID) && |
| 3704 | "Should use MaskedValueIsZero if you don't know whether Op" |
| 3705 | " is a target node!"); |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3706 | |
Evan Cheng | 6d196db | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 3707 | KnownZero = KnownOne = 0; // Don't know anything. |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3708 | switch (Opc) { |
Evan Cheng | 6d196db | 2006-04-05 06:11:20 +0000 | [diff] [blame] | 3709 | default: break; |
Nate Begeman | 8a77efe | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 3710 | case X86ISD::SETCC: |
| 3711 | KnownZero |= (MVT::getIntVTBitMask(Op.getValueType()) ^ 1ULL); |
| 3712 | break; |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3713 | } |
Evan Cheng | 9cdc16c | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 3714 | } |
Chris Lattner | c642aa5 | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 3715 | |
| 3716 | std::vector<unsigned> X86TargetLowering:: |
Chris Lattner | 7ad77df | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 3717 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
| 3718 | MVT::ValueType VT) const { |
Chris Lattner | c642aa5 | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 3719 | if (Constraint.size() == 1) { |
| 3720 | // FIXME: not handling fp-stack yet! |
| 3721 | // FIXME: not handling MMX registers yet ('y' constraint). |
| 3722 | switch (Constraint[0]) { // GCC X86 Constraint Letters |
| 3723 | default: break; // Unknown constriant letter |
| 3724 | case 'r': // GENERAL_REGS |
| 3725 | case 'R': // LEGACY_REGS |
| 3726 | return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX, |
| 3727 | X86::ESI, X86::EDI, X86::EBP, X86::ESP, 0); |
| 3728 | case 'l': // INDEX_REGS |
| 3729 | return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX, |
| 3730 | X86::ESI, X86::EDI, X86::EBP, 0); |
| 3731 | case 'q': // Q_REGS (GENERAL_REGS in 64-bit mode) |
| 3732 | case 'Q': // Q_REGS |
| 3733 | return make_vector<unsigned>(X86::EAX, X86::EBX, X86::ECX, X86::EDX, 0); |
| 3734 | case 'x': // SSE_REGS if SSE1 allowed |
| 3735 | if (Subtarget->hasSSE1()) |
| 3736 | return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3, |
| 3737 | X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7, |
| 3738 | 0); |
| 3739 | return std::vector<unsigned>(); |
| 3740 | case 'Y': // SSE_REGS if SSE2 allowed |
| 3741 | if (Subtarget->hasSSE2()) |
| 3742 | return make_vector<unsigned>(X86::XMM0, X86::XMM1, X86::XMM2, X86::XMM3, |
| 3743 | X86::XMM4, X86::XMM5, X86::XMM6, X86::XMM7, |
| 3744 | 0); |
| 3745 | return std::vector<unsigned>(); |
| 3746 | } |
| 3747 | } |
| 3748 | |
Chris Lattner | 7ad77df | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 3749 | return std::vector<unsigned>(); |
Chris Lattner | c642aa5 | 2006-01-31 19:43:35 +0000 | [diff] [blame] | 3750 | } |
Evan Cheng | af598d2 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 3751 | |
| 3752 | /// isLegalAddressImmediate - Return true if the integer value or |
| 3753 | /// GlobalValue can be used as the offset of the target addressing mode. |
| 3754 | bool X86TargetLowering::isLegalAddressImmediate(int64_t V) const { |
| 3755 | // X86 allows a sign-extended 32-bit immediate field. |
| 3756 | return (V > -(1LL << 32) && V < (1LL << 32)-1); |
| 3757 | } |
| 3758 | |
| 3759 | bool X86TargetLowering::isLegalAddressImmediate(GlobalValue *GV) const { |
Evan Cheng | bc04722 | 2006-03-22 19:22:18 +0000 | [diff] [blame] | 3760 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | af598d2 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 3761 | Reloc::Model RModel = getTargetMachine().getRelocationModel(); |
| 3762 | if (RModel == Reloc::Static) |
| 3763 | return true; |
| 3764 | else if (RModel == Reloc::DynamicNoPIC) |
Evan Cheng | f75555f | 2006-03-16 22:02:48 +0000 | [diff] [blame] | 3765 | return !DarwinGVRequiresExtraLoad(GV); |
Evan Cheng | af598d2 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 3766 | else |
| 3767 | return false; |
| 3768 | } else |
| 3769 | return true; |
| 3770 | } |
Evan Cheng | 68ad48b | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 3771 | |
| 3772 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 3773 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 3774 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 3775 | /// are assumed to be legal. |
Evan Cheng | 021bb7c | 2006-03-22 22:07:06 +0000 | [diff] [blame] | 3776 | bool |
| 3777 | X86TargetLowering::isShuffleMaskLegal(SDOperand Mask, MVT::ValueType VT) const { |
| 3778 | // Only do shuffles on 128-bit vector types for now. |
| 3779 | if (MVT::getSizeInBits(VT) == 64) return false; |
Evan Cheng | a3caaee | 2006-04-19 22:48:17 +0000 | [diff] [blame] | 3780 | return (Mask.Val->getNumOperands() <= 4 || |
Evan Cheng | 5022b34 | 2006-04-17 20:43:08 +0000 | [diff] [blame] | 3781 | isSplatMask(Mask.Val) || |
Evan Cheng | 59a6355 | 2006-04-05 01:47:37 +0000 | [diff] [blame] | 3782 | isPSHUFHW_PSHUFLWMask(Mask.Val) || |
Evan Cheng | 21e5476 | 2006-03-28 08:27:15 +0000 | [diff] [blame] | 3783 | X86::isUNPCKLMask(Mask.Val) || |
Evan Cheng | f3b52c8 | 2006-04-05 07:20:06 +0000 | [diff] [blame] | 3784 | X86::isUNPCKL_v_undef_Mask(Mask.Val) || |
Jim Laskey | 457e54e | 2006-03-28 10:17:11 +0000 | [diff] [blame] | 3785 | X86::isUNPCKHMask(Mask.Val)); |
Evan Cheng | 68ad48b | 2006-03-22 18:59:22 +0000 | [diff] [blame] | 3786 | } |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 3787 | |
| 3788 | bool X86TargetLowering::isVectorClearMaskLegal(std::vector<SDOperand> &BVOps, |
| 3789 | MVT::ValueType EVT, |
| 3790 | SelectionDAG &DAG) const { |
| 3791 | unsigned NumElts = BVOps.size(); |
| 3792 | // Only do shuffles on 128-bit vector types for now. |
| 3793 | if (MVT::getSizeInBits(EVT) * NumElts == 64) return false; |
| 3794 | if (NumElts == 2) return true; |
| 3795 | if (NumElts == 4) { |
Evan Cheng | e8b5180 | 2006-04-21 01:05:10 +0000 | [diff] [blame] | 3796 | return (isMOVLMask(BVOps) || isCommutedMOVL(BVOps, true) || |
Evan Cheng | 60f0b89 | 2006-04-20 08:58:49 +0000 | [diff] [blame] | 3797 | isSHUFPMask(BVOps) || isCommutedSHUFP(BVOps)); |
| 3798 | } |
| 3799 | return false; |
| 3800 | } |