Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 1 | //===-- TargetLowering.cpp - Implement the TargetLowering class -----------===// |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 4ee451d | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This implements the TargetLowering class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Evan Cheng | 5c80760 | 2008-02-26 02:33:44 +0000 | [diff] [blame] | 14 | #include "llvm/Target/TargetAsmInfo.h" |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 15 | #include "llvm/Target/TargetLowering.h" |
Rafael Espindola | f1ba1ca | 2007-11-05 23:12:20 +0000 | [diff] [blame] | 16 | #include "llvm/Target/TargetSubtarget.h" |
Owen Anderson | 07000c6 | 2006-05-12 06:33:49 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetData.h" |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 18 | #include "llvm/Target/TargetMachine.h" |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetRegisterInfo.h" |
Evan Cheng | 5c80760 | 2008-02-26 02:33:44 +0000 | [diff] [blame] | 20 | #include "llvm/CallingConv.h" |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 21 | #include "llvm/DerivedTypes.h" |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 22 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | 4ccb070 | 2006-01-26 20:37:03 +0000 | [diff] [blame] | 23 | #include "llvm/ADT/StringExtras.h" |
Owen Anderson | 718cb66 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/STLExtras.h" |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 25 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 28 | /// InitLibcallNames - Set default libcall names. |
| 29 | /// |
Evan Cheng | 79cca50 | 2007-01-12 22:51:10 +0000 | [diff] [blame] | 30 | static void InitLibcallNames(const char **Names) { |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 31 | Names[RTLIB::SHL_I32] = "__ashlsi3"; |
| 32 | Names[RTLIB::SHL_I64] = "__ashldi3"; |
| 33 | Names[RTLIB::SRL_I32] = "__lshrsi3"; |
| 34 | Names[RTLIB::SRL_I64] = "__lshrdi3"; |
| 35 | Names[RTLIB::SRA_I32] = "__ashrsi3"; |
| 36 | Names[RTLIB::SRA_I64] = "__ashrdi3"; |
| 37 | Names[RTLIB::MUL_I32] = "__mulsi3"; |
| 38 | Names[RTLIB::MUL_I64] = "__muldi3"; |
| 39 | Names[RTLIB::SDIV_I32] = "__divsi3"; |
| 40 | Names[RTLIB::SDIV_I64] = "__divdi3"; |
| 41 | Names[RTLIB::UDIV_I32] = "__udivsi3"; |
| 42 | Names[RTLIB::UDIV_I64] = "__udivdi3"; |
| 43 | Names[RTLIB::SREM_I32] = "__modsi3"; |
| 44 | Names[RTLIB::SREM_I64] = "__moddi3"; |
| 45 | Names[RTLIB::UREM_I32] = "__umodsi3"; |
| 46 | Names[RTLIB::UREM_I64] = "__umoddi3"; |
| 47 | Names[RTLIB::NEG_I32] = "__negsi2"; |
| 48 | Names[RTLIB::NEG_I64] = "__negdi2"; |
| 49 | Names[RTLIB::ADD_F32] = "__addsf3"; |
| 50 | Names[RTLIB::ADD_F64] = "__adddf3"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 51 | Names[RTLIB::ADD_F80] = "__addxf3"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 52 | Names[RTLIB::ADD_PPCF128] = "__gcc_qadd"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 53 | Names[RTLIB::SUB_F32] = "__subsf3"; |
| 54 | Names[RTLIB::SUB_F64] = "__subdf3"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 55 | Names[RTLIB::SUB_F80] = "__subxf3"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 56 | Names[RTLIB::SUB_PPCF128] = "__gcc_qsub"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 57 | Names[RTLIB::MUL_F32] = "__mulsf3"; |
| 58 | Names[RTLIB::MUL_F64] = "__muldf3"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 59 | Names[RTLIB::MUL_F80] = "__mulxf3"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 60 | Names[RTLIB::MUL_PPCF128] = "__gcc_qmul"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 61 | Names[RTLIB::DIV_F32] = "__divsf3"; |
| 62 | Names[RTLIB::DIV_F64] = "__divdf3"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 63 | Names[RTLIB::DIV_F80] = "__divxf3"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 64 | Names[RTLIB::DIV_PPCF128] = "__gcc_qdiv"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 65 | Names[RTLIB::REM_F32] = "fmodf"; |
| 66 | Names[RTLIB::REM_F64] = "fmod"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 67 | Names[RTLIB::REM_F80] = "fmodl"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 68 | Names[RTLIB::REM_PPCF128] = "fmodl"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 69 | Names[RTLIB::POWI_F32] = "__powisf2"; |
| 70 | Names[RTLIB::POWI_F64] = "__powidf2"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 71 | Names[RTLIB::POWI_F80] = "__powixf2"; |
| 72 | Names[RTLIB::POWI_PPCF128] = "__powitf2"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 73 | Names[RTLIB::SQRT_F32] = "sqrtf"; |
| 74 | Names[RTLIB::SQRT_F64] = "sqrt"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 75 | Names[RTLIB::SQRT_F80] = "sqrtl"; |
| 76 | Names[RTLIB::SQRT_PPCF128] = "sqrtl"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 77 | Names[RTLIB::SIN_F32] = "sinf"; |
| 78 | Names[RTLIB::SIN_F64] = "sin"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 79 | Names[RTLIB::SIN_F80] = "sinl"; |
| 80 | Names[RTLIB::SIN_PPCF128] = "sinl"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 81 | Names[RTLIB::COS_F32] = "cosf"; |
| 82 | Names[RTLIB::COS_F64] = "cos"; |
Duncan Sands | 007f984 | 2008-01-10 10:28:30 +0000 | [diff] [blame] | 83 | Names[RTLIB::COS_F80] = "cosl"; |
| 84 | Names[RTLIB::COS_PPCF128] = "cosl"; |
Dan Gohman | e54be10 | 2007-10-11 23:09:10 +0000 | [diff] [blame] | 85 | Names[RTLIB::POW_F32] = "powf"; |
| 86 | Names[RTLIB::POW_F64] = "pow"; |
| 87 | Names[RTLIB::POW_F80] = "powl"; |
| 88 | Names[RTLIB::POW_PPCF128] = "powl"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 89 | Names[RTLIB::FPEXT_F32_F64] = "__extendsfdf2"; |
| 90 | Names[RTLIB::FPROUND_F64_F32] = "__truncdfsf2"; |
| 91 | Names[RTLIB::FPTOSINT_F32_I32] = "__fixsfsi"; |
| 92 | Names[RTLIB::FPTOSINT_F32_I64] = "__fixsfdi"; |
| 93 | Names[RTLIB::FPTOSINT_F64_I32] = "__fixdfsi"; |
| 94 | Names[RTLIB::FPTOSINT_F64_I64] = "__fixdfdi"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 95 | Names[RTLIB::FPTOSINT_F80_I64] = "__fixxfdi"; |
| 96 | Names[RTLIB::FPTOSINT_PPCF128_I64] = "__fixtfdi"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 97 | Names[RTLIB::FPTOUINT_F32_I32] = "__fixunssfsi"; |
| 98 | Names[RTLIB::FPTOUINT_F32_I64] = "__fixunssfdi"; |
| 99 | Names[RTLIB::FPTOUINT_F64_I32] = "__fixunsdfsi"; |
| 100 | Names[RTLIB::FPTOUINT_F64_I64] = "__fixunsdfdi"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 101 | Names[RTLIB::FPTOUINT_F80_I32] = "__fixunsxfsi"; |
| 102 | Names[RTLIB::FPTOUINT_F80_I64] = "__fixunsxfdi"; |
| 103 | Names[RTLIB::FPTOUINT_PPCF128_I64] = "__fixunstfdi"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 104 | Names[RTLIB::SINTTOFP_I32_F32] = "__floatsisf"; |
| 105 | Names[RTLIB::SINTTOFP_I32_F64] = "__floatsidf"; |
| 106 | Names[RTLIB::SINTTOFP_I64_F32] = "__floatdisf"; |
| 107 | Names[RTLIB::SINTTOFP_I64_F64] = "__floatdidf"; |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 108 | Names[RTLIB::SINTTOFP_I64_F80] = "__floatdixf"; |
| 109 | Names[RTLIB::SINTTOFP_I64_PPCF128] = "__floatditf"; |
Dan Gohman | d91446d | 2008-03-05 01:08:17 +0000 | [diff] [blame] | 110 | Names[RTLIB::SINTTOFP_I128_F32] = "__floattisf"; |
| 111 | Names[RTLIB::SINTTOFP_I128_F64] = "__floattidf"; |
| 112 | Names[RTLIB::SINTTOFP_I128_F80] = "__floattixf"; |
| 113 | Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf"; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 114 | Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf"; |
| 115 | Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf"; |
| 116 | Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf"; |
| 117 | Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf"; |
| 118 | Names[RTLIB::OEQ_F32] = "__eqsf2"; |
| 119 | Names[RTLIB::OEQ_F64] = "__eqdf2"; |
| 120 | Names[RTLIB::UNE_F32] = "__nesf2"; |
| 121 | Names[RTLIB::UNE_F64] = "__nedf2"; |
| 122 | Names[RTLIB::OGE_F32] = "__gesf2"; |
| 123 | Names[RTLIB::OGE_F64] = "__gedf2"; |
| 124 | Names[RTLIB::OLT_F32] = "__ltsf2"; |
| 125 | Names[RTLIB::OLT_F64] = "__ltdf2"; |
| 126 | Names[RTLIB::OLE_F32] = "__lesf2"; |
| 127 | Names[RTLIB::OLE_F64] = "__ledf2"; |
| 128 | Names[RTLIB::OGT_F32] = "__gtsf2"; |
| 129 | Names[RTLIB::OGT_F64] = "__gtdf2"; |
| 130 | Names[RTLIB::UO_F32] = "__unordsf2"; |
| 131 | Names[RTLIB::UO_F64] = "__unorddf2"; |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 132 | Names[RTLIB::O_F32] = "__unordsf2"; |
| 133 | Names[RTLIB::O_F64] = "__unorddf2"; |
| 134 | } |
| 135 | |
| 136 | /// InitCmpLibcallCCs - Set default comparison libcall CC. |
| 137 | /// |
| 138 | static void InitCmpLibcallCCs(ISD::CondCode *CCs) { |
| 139 | memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL); |
| 140 | CCs[RTLIB::OEQ_F32] = ISD::SETEQ; |
| 141 | CCs[RTLIB::OEQ_F64] = ISD::SETEQ; |
| 142 | CCs[RTLIB::UNE_F32] = ISD::SETNE; |
| 143 | CCs[RTLIB::UNE_F64] = ISD::SETNE; |
| 144 | CCs[RTLIB::OGE_F32] = ISD::SETGE; |
| 145 | CCs[RTLIB::OGE_F64] = ISD::SETGE; |
| 146 | CCs[RTLIB::OLT_F32] = ISD::SETLT; |
| 147 | CCs[RTLIB::OLT_F64] = ISD::SETLT; |
| 148 | CCs[RTLIB::OLE_F32] = ISD::SETLE; |
| 149 | CCs[RTLIB::OLE_F64] = ISD::SETLE; |
| 150 | CCs[RTLIB::OGT_F32] = ISD::SETGT; |
| 151 | CCs[RTLIB::OGT_F64] = ISD::SETGT; |
| 152 | CCs[RTLIB::UO_F32] = ISD::SETNE; |
| 153 | CCs[RTLIB::UO_F64] = ISD::SETNE; |
| 154 | CCs[RTLIB::O_F32] = ISD::SETEQ; |
| 155 | CCs[RTLIB::O_F64] = ISD::SETEQ; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 158 | TargetLowering::TargetLowering(TargetMachine &tm) |
Chris Lattner | 3e6e8cc | 2006-01-29 08:41:12 +0000 | [diff] [blame] | 159 | : TM(tm), TD(TM.getTargetData()) { |
Evan Cheng | 33143dc | 2006-03-03 06:58:59 +0000 | [diff] [blame] | 160 | assert(ISD::BUILTIN_OP_END <= 156 && |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 161 | "Fixed size array in TargetLowering is not large enough!"); |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 162 | // All operations default to being supported. |
| 163 | memset(OpActions, 0, sizeof(OpActions)); |
Evan Cheng | c548428 | 2006-10-04 00:56:09 +0000 | [diff] [blame] | 164 | memset(LoadXActions, 0, sizeof(LoadXActions)); |
Chris Lattner | ddf8956 | 2008-01-17 19:59:44 +0000 | [diff] [blame] | 165 | memset(TruncStoreActions, 0, sizeof(TruncStoreActions)); |
Chris Lattner | c9133f9 | 2008-01-18 19:36:20 +0000 | [diff] [blame] | 166 | memset(IndexedModeActions, 0, sizeof(IndexedModeActions)); |
| 167 | memset(ConvertActions, 0, sizeof(ConvertActions)); |
Dan Gohman | 93f81e2 | 2007-07-09 20:49:44 +0000 | [diff] [blame] | 168 | |
Chris Lattner | 1a3048b | 2007-12-22 20:47:56 +0000 | [diff] [blame] | 169 | // Set default actions for various operations. |
Evan Cheng | 5ff839f | 2006-11-09 18:56:43 +0000 | [diff] [blame] | 170 | for (unsigned VT = 0; VT != (unsigned)MVT::LAST_VALUETYPE; ++VT) { |
Chris Lattner | 1a3048b | 2007-12-22 20:47:56 +0000 | [diff] [blame] | 171 | // Default all indexed load / store to expand. |
Evan Cheng | 5ff839f | 2006-11-09 18:56:43 +0000 | [diff] [blame] | 172 | for (unsigned IM = (unsigned)ISD::PRE_INC; |
| 173 | IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) { |
| 174 | setIndexedLoadAction(IM, (MVT::ValueType)VT, Expand); |
| 175 | setIndexedStoreAction(IM, (MVT::ValueType)VT, Expand); |
| 176 | } |
Chris Lattner | 1a3048b | 2007-12-22 20:47:56 +0000 | [diff] [blame] | 177 | |
| 178 | // These operations default to expand. |
| 179 | setOperationAction(ISD::FGETSIGN, (MVT::ValueType)VT, Expand); |
Evan Cheng | 5ff839f | 2006-11-09 18:56:43 +0000 | [diff] [blame] | 180 | } |
Nate Begeman | e179584 | 2008-02-14 08:57:00 +0000 | [diff] [blame] | 181 | |
| 182 | // ConstantFP nodes default to expand. Targets can either change this to |
| 183 | // Legal, in which case all fp constants are legal, or use addLegalFPImmediate |
| 184 | // to optimize expansions for certain constants. |
| 185 | setOperationAction(ISD::ConstantFP, MVT::f32, Expand); |
| 186 | setOperationAction(ISD::ConstantFP, MVT::f64, Expand); |
| 187 | setOperationAction(ISD::ConstantFP, MVT::f80, Expand); |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 188 | |
Chris Lattner | 41bab0b | 2008-01-15 21:58:08 +0000 | [diff] [blame] | 189 | // Default ISD::TRAP to expand (which turns it into abort). |
| 190 | setOperationAction(ISD::TRAP, MVT::Other, Expand); |
| 191 | |
Owen Anderson | a69571c | 2006-05-03 01:29:57 +0000 | [diff] [blame] | 192 | IsLittleEndian = TD->isLittleEndian(); |
Chris Lattner | cf9668f | 2006-10-06 22:52:08 +0000 | [diff] [blame] | 193 | UsesGlobalOffsetTable = false; |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame^] | 194 | ShiftAmountTy = PointerTy = getValueType(TD->getIntPtrType()); |
Chris Lattner | d6e4967 | 2005-01-19 03:36:14 +0000 | [diff] [blame] | 195 | ShiftAmtHandling = Undefined; |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 196 | memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*)); |
Owen Anderson | 718cb66 | 2007-09-07 04:06:50 +0000 | [diff] [blame] | 197 | memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray)); |
Evan Cheng | a03a5dc | 2006-02-14 08:38:30 +0000 | [diff] [blame] | 198 | maxStoresPerMemset = maxStoresPerMemcpy = maxStoresPerMemmove = 8; |
Reid Spencer | 0f9beca | 2005-08-27 19:09:02 +0000 | [diff] [blame] | 199 | allowUnalignedMemoryAccesses = false; |
Anton Korobeynikov | d27a258 | 2006-12-10 23:12:42 +0000 | [diff] [blame] | 200 | UseUnderscoreSetJmp = false; |
| 201 | UseUnderscoreLongJmp = false; |
Chris Lattner | 6618039 | 2007-02-25 01:28:05 +0000 | [diff] [blame] | 202 | SelectIsExpensive = false; |
Nate Begeman | 405e3ec | 2005-10-21 00:02:42 +0000 | [diff] [blame] | 203 | IntDivIsCheap = false; |
| 204 | Pow2DivIsCheap = false; |
Chris Lattner | ee4a765 | 2006-01-25 18:57:15 +0000 | [diff] [blame] | 205 | StackPointerRegisterToSaveRestore = 0; |
Jim Laskey | 9bb3c93 | 2007-02-22 18:04:49 +0000 | [diff] [blame] | 206 | ExceptionPointerRegister = 0; |
| 207 | ExceptionSelectorRegister = 0; |
Chris Lattner | dfe8934 | 2007-09-21 17:06:39 +0000 | [diff] [blame] | 208 | SetCCResultContents = UndefinedSetCCResult; |
Evan Cheng | 0577a22 | 2006-01-25 18:52:42 +0000 | [diff] [blame] | 209 | SchedPreferenceInfo = SchedulingForLatency; |
Chris Lattner | 7acf5f3 | 2006-09-05 17:39:15 +0000 | [diff] [blame] | 210 | JumpBufSize = 0; |
Duraid Madina | 0c9e0ff | 2006-09-04 07:44:11 +0000 | [diff] [blame] | 211 | JumpBufAlignment = 0; |
Evan Cheng | d60483e | 2007-05-16 23:45:53 +0000 | [diff] [blame] | 212 | IfCvtBlockSizeLimit = 2; |
Evan Cheng | fb8075d | 2008-02-28 00:43:03 +0000 | [diff] [blame] | 213 | IfCvtDupBlockSizeLimit = 0; |
| 214 | PrefLoopAlignment = 0; |
Evan Cheng | 5696622 | 2007-01-12 02:11:51 +0000 | [diff] [blame] | 215 | |
| 216 | InitLibcallNames(LibcallRoutineNames); |
Evan Cheng | d385fd6 | 2007-01-31 09:29:11 +0000 | [diff] [blame] | 217 | InitCmpLibcallCCs(CmpLibcallCCs); |
Dan Gohman | c3b0b5c | 2007-09-25 15:10:49 +0000 | [diff] [blame] | 218 | |
| 219 | // Tell Legalize whether the assembler supports DEBUG_LOC. |
| 220 | if (!TM.getTargetAsmInfo()->hasDotLocAndDotFile()) |
| 221 | setOperationAction(ISD::DEBUG_LOC, MVT::Other, Expand); |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 224 | TargetLowering::~TargetLowering() {} |
| 225 | |
Rafael Espindola | f1ba1ca | 2007-11-05 23:12:20 +0000 | [diff] [blame] | 226 | |
| 227 | SDOperand TargetLowering::LowerMEMCPY(SDOperand Op, SelectionDAG &DAG) { |
| 228 | assert(getSubtarget() && "Subtarget not defined"); |
| 229 | SDOperand ChainOp = Op.getOperand(0); |
| 230 | SDOperand DestOp = Op.getOperand(1); |
| 231 | SDOperand SourceOp = Op.getOperand(2); |
| 232 | SDOperand CountOp = Op.getOperand(3); |
| 233 | SDOperand AlignOp = Op.getOperand(4); |
| 234 | SDOperand AlwaysInlineOp = Op.getOperand(5); |
| 235 | |
| 236 | bool AlwaysInline = (bool)cast<ConstantSDNode>(AlwaysInlineOp)->getValue(); |
| 237 | unsigned Align = (unsigned)cast<ConstantSDNode>(AlignOp)->getValue(); |
| 238 | if (Align == 0) Align = 1; |
| 239 | |
| 240 | // If size is unknown, call memcpy. |
| 241 | ConstantSDNode *I = dyn_cast<ConstantSDNode>(CountOp); |
| 242 | if (!I) { |
| 243 | assert(!AlwaysInline && "Cannot inline copy of unknown size"); |
| 244 | return LowerMEMCPYCall(ChainOp, DestOp, SourceOp, CountOp, DAG); |
| 245 | } |
| 246 | |
| 247 | // If not DWORD aligned or if size is more than threshold, then call memcpy. |
| 248 | // The libc version is likely to be faster for the following cases. It can |
| 249 | // use the address value and run time information about the CPU. |
| 250 | // With glibc 2.6.1 on a core 2, coping an array of 100M longs was 30% faster |
| 251 | unsigned Size = I->getValue(); |
| 252 | if (AlwaysInline || |
| 253 | (Size <= getSubtarget()->getMaxInlineSizeThreshold() && |
| 254 | (Align & 3) == 0)) |
| 255 | return LowerMEMCPYInline(ChainOp, DestOp, SourceOp, Size, Align, DAG); |
| 256 | return LowerMEMCPYCall(ChainOp, DestOp, SourceOp, CountOp, DAG); |
| 257 | } |
| 258 | |
| 259 | |
| 260 | SDOperand TargetLowering::LowerMEMCPYCall(SDOperand Chain, |
| 261 | SDOperand Dest, |
| 262 | SDOperand Source, |
| 263 | SDOperand Count, |
| 264 | SelectionDAG &DAG) { |
| 265 | MVT::ValueType IntPtr = getPointerTy(); |
| 266 | TargetLowering::ArgListTy Args; |
| 267 | TargetLowering::ArgListEntry Entry; |
| 268 | Entry.Ty = getTargetData()->getIntPtrType(); |
| 269 | Entry.Node = Dest; Args.push_back(Entry); |
| 270 | Entry.Node = Source; Args.push_back(Entry); |
| 271 | Entry.Node = Count; Args.push_back(Entry); |
| 272 | std::pair<SDOperand,SDOperand> CallResult = |
Duncan Sands | 00fee65 | 2008-02-14 17:28:50 +0000 | [diff] [blame] | 273 | LowerCallTo(Chain, Type::VoidTy, false, false, false, CallingConv::C, |
| 274 | false, DAG.getExternalSymbol("memcpy", IntPtr), Args, DAG); |
Rafael Espindola | f1ba1ca | 2007-11-05 23:12:20 +0000 | [diff] [blame] | 275 | return CallResult.second; |
| 276 | } |
| 277 | |
| 278 | |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 279 | /// computeRegisterProperties - Once all of the register classes are added, |
| 280 | /// this allows us to compute derived properties we expose. |
| 281 | void TargetLowering::computeRegisterProperties() { |
Nate Begeman | 6a64861 | 2005-11-29 05:45:29 +0000 | [diff] [blame] | 282 | assert(MVT::LAST_VALUETYPE <= 32 && |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 283 | "Too many value types for ValueTypeActions to hold!"); |
| 284 | |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 285 | // Everything defaults to needing one register. |
| 286 | for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) { |
Dan Gohman | b9f1019 | 2007-06-21 14:42:22 +0000 | [diff] [blame] | 287 | NumRegistersForVT[i] = 1; |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 288 | RegisterTypeForVT[i] = TransformToType[i] = i; |
| 289 | } |
| 290 | // ...except isVoid, which doesn't need any registers. |
| 291 | NumRegistersForVT[MVT::isVoid] = 0; |
Misha Brukman | f976c85 | 2005-04-21 22:55:34 +0000 | [diff] [blame] | 292 | |
Chris Lattner | 310968c | 2005-01-07 07:44:53 +0000 | [diff] [blame] | 293 | // Find the largest integer register class. |
| 294 | unsigned LargestIntReg = MVT::i128; |
| 295 | for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg) |
| 296 | assert(LargestIntReg != MVT::i1 && "No integer registers defined!"); |
| 297 | |
| 298 | // Every integer value type larger than this largest register takes twice as |
| 299 | // many registers to represent as the previous ValueType. |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 300 | for (MVT::ValueType ExpandedReg = LargestIntReg + 1; |
| 301 | MVT::isInteger(ExpandedReg); ++ExpandedReg) { |
Dan Gohman | b9f1019 | 2007-06-21 14:42:22 +0000 | [diff] [blame] | 302 | NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1]; |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 303 | RegisterTypeForVT[ExpandedReg] = LargestIntReg; |
| 304 | TransformToType[ExpandedReg] = ExpandedReg - 1; |
| 305 | ValueTypeActions.setTypeAction(ExpandedReg, Expand); |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 306 | } |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 307 | |
| 308 | // Inspect all of the ValueType's smaller than the largest integer |
| 309 | // register to see which ones need promotion. |
| 310 | MVT::ValueType LegalIntReg = LargestIntReg; |
| 311 | for (MVT::ValueType IntReg = LargestIntReg - 1; |
| 312 | IntReg >= MVT::i1; --IntReg) { |
| 313 | if (isTypeLegal(IntReg)) { |
| 314 | LegalIntReg = IntReg; |
| 315 | } else { |
| 316 | RegisterTypeForVT[IntReg] = TransformToType[IntReg] = LegalIntReg; |
| 317 | ValueTypeActions.setTypeAction(IntReg, Promote); |
| 318 | } |
| 319 | } |
| 320 | |
Dale Johannesen | 161e897 | 2007-10-05 20:04:43 +0000 | [diff] [blame] | 321 | // ppcf128 type is really two f64's. |
| 322 | if (!isTypeLegal(MVT::ppcf128)) { |
| 323 | NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64]; |
| 324 | RegisterTypeForVT[MVT::ppcf128] = MVT::f64; |
| 325 | TransformToType[MVT::ppcf128] = MVT::f64; |
| 326 | ValueTypeActions.setTypeAction(MVT::ppcf128, Expand); |
| 327 | } |
| 328 | |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 329 | // Decide how to handle f64. If the target does not have native f64 support, |
| 330 | // expand it to i64 and we will be generating soft float library calls. |
| 331 | if (!isTypeLegal(MVT::f64)) { |
| 332 | NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64]; |
| 333 | RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64]; |
| 334 | TransformToType[MVT::f64] = MVT::i64; |
| 335 | ValueTypeActions.setTypeAction(MVT::f64, Expand); |
| 336 | } |
| 337 | |
| 338 | // Decide how to handle f32. If the target does not have native support for |
| 339 | // f32, promote it to f64 if it is legal. Otherwise, expand it to i32. |
| 340 | if (!isTypeLegal(MVT::f32)) { |
| 341 | if (isTypeLegal(MVT::f64)) { |
| 342 | NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::f64]; |
| 343 | RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::f64]; |
| 344 | TransformToType[MVT::f32] = MVT::f64; |
| 345 | ValueTypeActions.setTypeAction(MVT::f32, Promote); |
| 346 | } else { |
| 347 | NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32]; |
| 348 | RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32]; |
| 349 | TransformToType[MVT::f32] = MVT::i32; |
| 350 | ValueTypeActions.setTypeAction(MVT::f32, Expand); |
| 351 | } |
Evan Cheng | 1a8f1fe | 2006-12-09 02:42:38 +0000 | [diff] [blame] | 352 | } |
Nate Begeman | 4ef3b81 | 2005-11-22 01:29:36 +0000 | [diff] [blame] | 353 | |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 354 | // Loop over all of the vector value types to see which need transformations. |
| 355 | for (MVT::ValueType i = MVT::FIRST_VECTOR_VALUETYPE; |
Evan Cheng | 677274b | 2006-03-23 23:24:51 +0000 | [diff] [blame] | 356 | i <= MVT::LAST_VECTOR_VALUETYPE; ++i) { |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 357 | if (!isTypeLegal(i)) { |
| 358 | MVT::ValueType IntermediateVT, RegisterVT; |
| 359 | unsigned NumIntermediates; |
| 360 | NumRegistersForVT[i] = |
| 361 | getVectorTypeBreakdown(i, |
| 362 | IntermediateVT, NumIntermediates, |
| 363 | RegisterVT); |
| 364 | RegisterTypeForVT[i] = RegisterVT; |
| 365 | TransformToType[i] = MVT::Other; // this isn't actually used |
| 366 | ValueTypeActions.setTypeAction(i, Expand); |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 367 | } |
Chris Lattner | 3a593584 | 2006-03-16 19:50:01 +0000 | [diff] [blame] | 368 | } |
Chris Lattner | bb97d81 | 2005-01-16 01:10:58 +0000 | [diff] [blame] | 369 | } |
Chris Lattner | cba82f9 | 2005-01-16 07:28:11 +0000 | [diff] [blame] | 370 | |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 371 | const char *TargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 372 | return NULL; |
| 373 | } |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 374 | |
Scott Michel | 5b8f82e | 2008-03-10 15:42:14 +0000 | [diff] [blame^] | 375 | |
| 376 | MVT::ValueType |
| 377 | TargetLowering::getSetCCResultType(const SDOperand &) const { |
| 378 | return getValueType(TD->getIntPtrType()); |
| 379 | } |
| 380 | |
| 381 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 382 | /// getVectorTypeBreakdown - Vector types are broken down into some number of |
| 383 | /// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32 |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 384 | /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 385 | /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86. |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 386 | /// |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 387 | /// This method returns the number of registers needed, and the VT for each |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 388 | /// register. It also returns the VT and quantity of the intermediate values |
| 389 | /// before they are promoted/expanded. |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 390 | /// |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 391 | unsigned TargetLowering::getVectorTypeBreakdown(MVT::ValueType VT, |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 392 | MVT::ValueType &IntermediateVT, |
| 393 | unsigned &NumIntermediates, |
| 394 | MVT::ValueType &RegisterVT) const { |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 395 | // Figure out the right, legal destination reg to copy into. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 396 | unsigned NumElts = MVT::getVectorNumElements(VT); |
| 397 | MVT::ValueType EltTy = MVT::getVectorElementType(VT); |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 398 | |
| 399 | unsigned NumVectorRegs = 1; |
| 400 | |
Nate Begeman | d73ab88 | 2007-11-27 19:28:48 +0000 | [diff] [blame] | 401 | // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we |
| 402 | // could break down into LHS/RHS like LegalizeDAG does. |
| 403 | if (!isPowerOf2_32(NumElts)) { |
| 404 | NumVectorRegs = NumElts; |
| 405 | NumElts = 1; |
| 406 | } |
| 407 | |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 408 | // Divide the input until we get to a supported size. This will always |
| 409 | // end with a scalar if the target doesn't support vectors. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 410 | while (NumElts > 1 && |
| 411 | !isTypeLegal(MVT::getVectorType(EltTy, NumElts))) { |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 412 | NumElts >>= 1; |
| 413 | NumVectorRegs <<= 1; |
| 414 | } |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 415 | |
| 416 | NumIntermediates = NumVectorRegs; |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 417 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 418 | MVT::ValueType NewVT = MVT::getVectorType(EltTy, NumElts); |
| 419 | if (!isTypeLegal(NewVT)) |
| 420 | NewVT = EltTy; |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 421 | IntermediateVT = NewVT; |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 422 | |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 423 | MVT::ValueType DestVT = getTypeToTransformTo(NewVT); |
Dan Gohman | b6f5b00 | 2007-06-28 23:29:44 +0000 | [diff] [blame] | 424 | RegisterVT = DestVT; |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 425 | if (DestVT < NewVT) { |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 426 | // Value is expanded, e.g. i64 -> i16. |
Dan Gohman | 7f32156 | 2007-06-25 16:23:39 +0000 | [diff] [blame] | 427 | return NumVectorRegs*(MVT::getSizeInBits(NewVT)/MVT::getSizeInBits(DestVT)); |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 428 | } else { |
| 429 | // Otherwise, promotion or legal types use the same number of registers as |
| 430 | // the vector decimated to the appropriate level. |
Chris Lattner | 79227e2 | 2006-03-31 00:46:36 +0000 | [diff] [blame] | 431 | return NumVectorRegs; |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 432 | } |
| 433 | |
Evan Cheng | e9b3da1 | 2006-05-17 18:10:06 +0000 | [diff] [blame] | 434 | return 1; |
Chris Lattner | dc87929 | 2006-03-31 00:28:56 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Evan Cheng | 3ae0543 | 2008-01-24 00:22:01 +0000 | [diff] [blame] | 437 | /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate |
Dale Johannesen | 28d08fd | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 438 | /// function arguments in the caller parameter area. This is the actual |
| 439 | /// alignment, not its logarithm. |
Evan Cheng | 3ae0543 | 2008-01-24 00:22:01 +0000 | [diff] [blame] | 440 | unsigned TargetLowering::getByValTypeAlignment(const Type *Ty) const { |
Dale Johannesen | 28d08fd | 2008-02-28 22:31:51 +0000 | [diff] [blame] | 441 | return TD->getCallFrameTypeAlignment(Ty); |
Evan Cheng | 3ae0543 | 2008-01-24 00:22:01 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Evan Cheng | cc41586 | 2007-11-09 01:32:10 +0000 | [diff] [blame] | 444 | SDOperand TargetLowering::getPICJumpTableRelocBase(SDOperand Table, |
| 445 | SelectionDAG &DAG) const { |
| 446 | if (usesGlobalOffsetTable()) |
| 447 | return DAG.getNode(ISD::GLOBAL_OFFSET_TABLE, getPointerTy()); |
| 448 | return Table; |
| 449 | } |
| 450 | |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 451 | //===----------------------------------------------------------------------===// |
| 452 | // Optimization Methods |
| 453 | //===----------------------------------------------------------------------===// |
| 454 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 455 | /// ShrinkDemandedConstant - Check to see if the specified operand of the |
| 456 | /// specified instruction is a constant integer. If so, check to see if there |
| 457 | /// are any bits set in the constant that are not demanded. If so, shrink the |
| 458 | /// constant and return true. |
| 459 | bool TargetLowering::TargetLoweringOpt::ShrinkDemandedConstant(SDOperand Op, |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 460 | const APInt &Demanded) { |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 461 | // FIXME: ISD::SELECT, ISD::SELECT_CC |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 462 | switch(Op.getOpcode()) { |
| 463 | default: break; |
Nate Begeman | de99629 | 2006-02-03 22:24:05 +0000 | [diff] [blame] | 464 | case ISD::AND: |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 465 | case ISD::OR: |
| 466 | case ISD::XOR: |
| 467 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op.getOperand(1))) |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 468 | if (C->getAPIntValue().intersects(~Demanded)) { |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 469 | MVT::ValueType VT = Op.getValueType(); |
| 470 | SDOperand New = DAG.getNode(Op.getOpcode(), VT, Op.getOperand(0), |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 471 | DAG.getConstant(Demanded & |
| 472 | C->getAPIntValue(), |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 473 | VT)); |
| 474 | return CombineTo(Op, New); |
Nate Begeman | de99629 | 2006-02-03 22:24:05 +0000 | [diff] [blame] | 475 | } |
Nate Begeman | de99629 | 2006-02-03 22:24:05 +0000 | [diff] [blame] | 476 | break; |
| 477 | } |
| 478 | return false; |
| 479 | } |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 480 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 481 | /// SimplifyDemandedBits - Look at Op. At this point, we know that only the |
| 482 | /// DemandedMask bits of the result of Op are ever used downstream. If we can |
| 483 | /// use this information to simplify Op, create a new simplified DAG node and |
| 484 | /// return true, returning the original and new nodes in Old and New. Otherwise, |
| 485 | /// analyze the expression and return a mask of KnownOne and KnownZero bits for |
| 486 | /// the expression (used to simplify the caller). The KnownZero/One bits may |
| 487 | /// only be accurate for those bits in the DemandedMask. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 488 | bool TargetLowering::SimplifyDemandedBits(SDOperand Op, |
| 489 | const APInt &DemandedMask, |
| 490 | APInt &KnownZero, |
| 491 | APInt &KnownOne, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 492 | TargetLoweringOpt &TLO, |
| 493 | unsigned Depth) const { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 494 | unsigned BitWidth = DemandedMask.getBitWidth(); |
| 495 | assert(Op.getValueSizeInBits() == BitWidth && |
| 496 | "Mask size mismatches value type size!"); |
| 497 | APInt NewMask = DemandedMask; |
Chris Lattner | 3fc5b01 | 2007-05-17 18:19:23 +0000 | [diff] [blame] | 498 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 499 | // Don't know anything. |
| 500 | KnownZero = KnownOne = APInt(BitWidth, 0); |
| 501 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 502 | // Other users may use these bits. |
| 503 | if (!Op.Val->hasOneUse()) { |
| 504 | if (Depth != 0) { |
| 505 | // If not at the root, Just compute the KnownZero/KnownOne bits to |
| 506 | // simplify things downstream. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 507 | TLO.DAG.ComputeMaskedBits(Op, DemandedMask, KnownZero, KnownOne, Depth); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 508 | return false; |
| 509 | } |
| 510 | // If this is the root being simplified, allow it to have multiple uses, |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 511 | // just set the NewMask to all bits. |
| 512 | NewMask = APInt::getAllOnesValue(BitWidth); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 513 | } else if (DemandedMask == 0) { |
| 514 | // Not demanding any bits from Op. |
| 515 | if (Op.getOpcode() != ISD::UNDEF) |
| 516 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::UNDEF, Op.getValueType())); |
| 517 | return false; |
| 518 | } else if (Depth == 6) { // Limit search depth. |
| 519 | return false; |
| 520 | } |
| 521 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 522 | APInt KnownZero2, KnownOne2, KnownZeroOut, KnownOneOut; |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 523 | switch (Op.getOpcode()) { |
| 524 | case ISD::Constant: |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 525 | // We know all of the bits for a constant! |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 526 | KnownOne = cast<ConstantSDNode>(Op)->getAPIntValue() & NewMask; |
| 527 | KnownZero = ~KnownOne & NewMask; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 528 | return false; // Don't fall through, will infinitely loop. |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 529 | case ISD::AND: |
Chris Lattner | 81cd355 | 2006-02-27 00:36:27 +0000 | [diff] [blame] | 530 | // If the RHS is a constant, check to see if the LHS would be zero without |
| 531 | // using the bits from the RHS. Below, we use knowledge about the RHS to |
| 532 | // simplify the LHS, here we're using information from the LHS to simplify |
| 533 | // the RHS. |
| 534 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 535 | APInt LHSZero, LHSOne; |
| 536 | TLO.DAG.ComputeMaskedBits(Op.getOperand(0), NewMask, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 537 | LHSZero, LHSOne, Depth+1); |
Chris Lattner | 81cd355 | 2006-02-27 00:36:27 +0000 | [diff] [blame] | 538 | // If the LHS already has zeros where RHSC does, this and is dead. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 539 | if ((LHSZero & NewMask) == (~RHSC->getAPIntValue() & NewMask)) |
Chris Lattner | 81cd355 | 2006-02-27 00:36:27 +0000 | [diff] [blame] | 540 | return TLO.CombineTo(Op, Op.getOperand(0)); |
| 541 | // If any of the set bits in the RHS are known zero on the LHS, shrink |
| 542 | // the constant. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 543 | if (TLO.ShrinkDemandedConstant(Op, ~LHSZero & NewMask)) |
Chris Lattner | 81cd355 | 2006-02-27 00:36:27 +0000 | [diff] [blame] | 544 | return true; |
| 545 | } |
| 546 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 547 | if (SimplifyDemandedBits(Op.getOperand(1), NewMask, KnownZero, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 548 | KnownOne, TLO, Depth+1)) |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 549 | return true; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 550 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 551 | if (SimplifyDemandedBits(Op.getOperand(0), ~KnownZero & NewMask, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 552 | KnownZero2, KnownOne2, TLO, Depth+1)) |
| 553 | return true; |
| 554 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 555 | |
| 556 | // If all of the demanded bits are known one on one side, return the other. |
| 557 | // These bits cannot contribute to the result of the 'and'. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 558 | if ((NewMask & ~KnownZero2 & KnownOne) == (~KnownZero2 & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 559 | return TLO.CombineTo(Op, Op.getOperand(0)); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 560 | if ((NewMask & ~KnownZero & KnownOne2) == (~KnownZero & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 561 | return TLO.CombineTo(Op, Op.getOperand(1)); |
| 562 | // If all of the demanded bits in the inputs are known zeros, return zero. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 563 | if ((NewMask & (KnownZero|KnownZero2)) == NewMask) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 564 | return TLO.CombineTo(Op, TLO.DAG.getConstant(0, Op.getValueType())); |
| 565 | // If the RHS is a constant, see if we can simplify it. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 566 | if (TLO.ShrinkDemandedConstant(Op, ~KnownZero2 & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 567 | return true; |
Chris Lattner | 5f0c658 | 2006-02-27 00:22:28 +0000 | [diff] [blame] | 568 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 569 | // Output known-1 bits are only known if set in both the LHS & RHS. |
| 570 | KnownOne &= KnownOne2; |
| 571 | // Output known-0 are known to be clear if zero in either the LHS | RHS. |
| 572 | KnownZero |= KnownZero2; |
| 573 | break; |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 574 | case ISD::OR: |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 575 | if (SimplifyDemandedBits(Op.getOperand(1), NewMask, KnownZero, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 576 | KnownOne, TLO, Depth+1)) |
| 577 | return true; |
| 578 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 579 | if (SimplifyDemandedBits(Op.getOperand(0), ~KnownOne & NewMask, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 580 | KnownZero2, KnownOne2, TLO, Depth+1)) |
| 581 | return true; |
| 582 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 583 | |
| 584 | // If all of the demanded bits are known zero on one side, return the other. |
| 585 | // These bits cannot contribute to the result of the 'or'. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 586 | if ((NewMask & ~KnownOne2 & KnownZero) == (~KnownOne2 & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 587 | return TLO.CombineTo(Op, Op.getOperand(0)); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 588 | if ((NewMask & ~KnownOne & KnownZero2) == (~KnownOne & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 589 | return TLO.CombineTo(Op, Op.getOperand(1)); |
| 590 | // If all of the potentially set bits on one side are known to be set on |
| 591 | // the other side, just use the 'other' side. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 592 | if ((NewMask & ~KnownZero & KnownOne2) == (~KnownZero & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 593 | return TLO.CombineTo(Op, Op.getOperand(0)); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 594 | if ((NewMask & ~KnownZero2 & KnownOne) == (~KnownZero2 & NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 595 | return TLO.CombineTo(Op, Op.getOperand(1)); |
| 596 | // If the RHS is a constant, see if we can simplify it. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 597 | if (TLO.ShrinkDemandedConstant(Op, NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 598 | return true; |
| 599 | |
| 600 | // Output known-0 bits are only known if clear in both the LHS & RHS. |
| 601 | KnownZero &= KnownZero2; |
| 602 | // Output known-1 are known to be set if set in either the LHS | RHS. |
| 603 | KnownOne |= KnownOne2; |
| 604 | break; |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 605 | case ISD::XOR: |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 606 | if (SimplifyDemandedBits(Op.getOperand(1), NewMask, KnownZero, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 607 | KnownOne, TLO, Depth+1)) |
| 608 | return true; |
| 609 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 610 | if (SimplifyDemandedBits(Op.getOperand(0), NewMask, KnownZero2, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 611 | KnownOne2, TLO, Depth+1)) |
| 612 | return true; |
| 613 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 614 | |
| 615 | // If all of the demanded bits are known zero on one side, return the other. |
| 616 | // These bits cannot contribute to the result of the 'xor'. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 617 | if ((KnownZero & NewMask) == NewMask) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 618 | return TLO.CombineTo(Op, Op.getOperand(0)); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 619 | if ((KnownZero2 & NewMask) == NewMask) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 620 | return TLO.CombineTo(Op, Op.getOperand(1)); |
Chris Lattner | 3687c1a | 2006-11-27 21:50:02 +0000 | [diff] [blame] | 621 | |
| 622 | // If all of the unknown bits are known to be zero on one side or the other |
| 623 | // (but not both) turn this into an *inclusive* or. |
| 624 | // e.g. (A & C1)^(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0 |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 625 | if ((NewMask & ~KnownZero & ~KnownZero2) == 0) |
Chris Lattner | 3687c1a | 2006-11-27 21:50:02 +0000 | [diff] [blame] | 626 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::OR, Op.getValueType(), |
| 627 | Op.getOperand(0), |
| 628 | Op.getOperand(1))); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 629 | |
| 630 | // Output known-0 bits are known if clear or set in both the LHS & RHS. |
| 631 | KnownZeroOut = (KnownZero & KnownZero2) | (KnownOne & KnownOne2); |
| 632 | // Output known-1 are known to be set if set in only one of the LHS, RHS. |
| 633 | KnownOneOut = (KnownZero & KnownOne2) | (KnownOne & KnownZero2); |
| 634 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 635 | // If all of the demanded bits on one side are known, and all of the set |
| 636 | // bits on that side are also known to be set on the other side, turn this |
| 637 | // into an AND, as we know the bits will be cleared. |
| 638 | // e.g. (X | C1) ^ C2 --> (X | C1) & ~C2 iff (C1&C2) == C2 |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 639 | if ((NewMask & (KnownZero|KnownOne)) == NewMask) { // all known |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 640 | if ((KnownOne & KnownOne2) == KnownOne) { |
| 641 | MVT::ValueType VT = Op.getValueType(); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 642 | SDOperand ANDC = TLO.DAG.getConstant(~KnownOne & NewMask, VT); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 643 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::AND, VT, Op.getOperand(0), |
| 644 | ANDC)); |
| 645 | } |
| 646 | } |
| 647 | |
| 648 | // If the RHS is a constant, see if we can simplify it. |
| 649 | // FIXME: for XOR, we prefer to force bits to 1 if they will make a -1. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 650 | if (TLO.ShrinkDemandedConstant(Op, NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 651 | return true; |
| 652 | |
| 653 | KnownZero = KnownZeroOut; |
| 654 | KnownOne = KnownOneOut; |
| 655 | break; |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 656 | case ISD::SELECT: |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 657 | if (SimplifyDemandedBits(Op.getOperand(2), NewMask, KnownZero, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 658 | KnownOne, TLO, Depth+1)) |
| 659 | return true; |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 660 | if (SimplifyDemandedBits(Op.getOperand(1), NewMask, KnownZero2, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 661 | KnownOne2, TLO, Depth+1)) |
| 662 | return true; |
| 663 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 664 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 665 | |
| 666 | // If the operands are constants, see if we can simplify them. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 667 | if (TLO.ShrinkDemandedConstant(Op, NewMask)) |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 668 | return true; |
| 669 | |
| 670 | // Only known if known in both the LHS and RHS. |
| 671 | KnownOne &= KnownOne2; |
| 672 | KnownZero &= KnownZero2; |
| 673 | break; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 674 | case ISD::SELECT_CC: |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 675 | if (SimplifyDemandedBits(Op.getOperand(3), NewMask, KnownZero, |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 676 | KnownOne, TLO, Depth+1)) |
| 677 | return true; |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 678 | if (SimplifyDemandedBits(Op.getOperand(2), NewMask, KnownZero2, |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 679 | KnownOne2, TLO, Depth+1)) |
| 680 | return true; |
| 681 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 682 | assert((KnownZero2 & KnownOne2) == 0 && "Bits known to be one AND zero?"); |
| 683 | |
| 684 | // If the operands are constants, see if we can simplify them. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 685 | if (TLO.ShrinkDemandedConstant(Op, NewMask)) |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 686 | return true; |
| 687 | |
| 688 | // Only known if known in both the LHS and RHS. |
| 689 | KnownOne &= KnownOne2; |
| 690 | KnownZero &= KnownZero2; |
| 691 | break; |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 692 | case ISD::SHL: |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 693 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 694 | unsigned ShAmt = SA->getValue(); |
| 695 | SDOperand InOp = Op.getOperand(0); |
| 696 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 697 | // If the shift count is an invalid immediate, don't do anything. |
| 698 | if (ShAmt >= BitWidth) |
| 699 | break; |
| 700 | |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 701 | // If this is ((X >>u C1) << ShAmt), see if we can simplify this into a |
| 702 | // single shift. We can do this if the bottom bits (which are shifted |
| 703 | // out) are never demanded. |
| 704 | if (InOp.getOpcode() == ISD::SRL && |
| 705 | isa<ConstantSDNode>(InOp.getOperand(1))) { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 706 | if (ShAmt && (NewMask & APInt::getLowBitsSet(BitWidth, ShAmt)) == 0) { |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 707 | unsigned C1 = cast<ConstantSDNode>(InOp.getOperand(1))->getValue(); |
| 708 | unsigned Opc = ISD::SHL; |
| 709 | int Diff = ShAmt-C1; |
| 710 | if (Diff < 0) { |
| 711 | Diff = -Diff; |
| 712 | Opc = ISD::SRL; |
| 713 | } |
| 714 | |
| 715 | SDOperand NewSA = |
Chris Lattner | 4e7e6cd | 2007-05-30 16:30:06 +0000 | [diff] [blame] | 716 | TLO.DAG.getConstant(Diff, Op.getOperand(1).getValueType()); |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 717 | MVT::ValueType VT = Op.getValueType(); |
Chris Lattner | 0a16a1f | 2007-04-18 03:01:40 +0000 | [diff] [blame] | 718 | return TLO.CombineTo(Op, TLO.DAG.getNode(Opc, VT, |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 719 | InOp.getOperand(0), NewSA)); |
| 720 | } |
| 721 | } |
| 722 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 723 | if (SimplifyDemandedBits(Op.getOperand(0), NewMask.lshr(ShAmt), |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 724 | KnownZero, KnownOne, TLO, Depth+1)) |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 725 | return true; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 726 | KnownZero <<= SA->getValue(); |
| 727 | KnownOne <<= SA->getValue(); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 728 | // low bits known zero. |
| 729 | KnownZero |= APInt::getLowBitsSet(BitWidth, SA->getValue()); |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 730 | } |
| 731 | break; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 732 | case ISD::SRL: |
| 733 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
| 734 | MVT::ValueType VT = Op.getValueType(); |
| 735 | unsigned ShAmt = SA->getValue(); |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 736 | unsigned VTSize = MVT::getSizeInBits(VT); |
| 737 | SDOperand InOp = Op.getOperand(0); |
| 738 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 739 | // If the shift count is an invalid immediate, don't do anything. |
| 740 | if (ShAmt >= BitWidth) |
| 741 | break; |
| 742 | |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 743 | // If this is ((X << C1) >>u ShAmt), see if we can simplify this into a |
| 744 | // single shift. We can do this if the top bits (which are shifted out) |
| 745 | // are never demanded. |
| 746 | if (InOp.getOpcode() == ISD::SHL && |
| 747 | isa<ConstantSDNode>(InOp.getOperand(1))) { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 748 | if (ShAmt && (NewMask & APInt::getHighBitsSet(VTSize, ShAmt)) == 0) { |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 749 | unsigned C1 = cast<ConstantSDNode>(InOp.getOperand(1))->getValue(); |
| 750 | unsigned Opc = ISD::SRL; |
| 751 | int Diff = ShAmt-C1; |
| 752 | if (Diff < 0) { |
| 753 | Diff = -Diff; |
| 754 | Opc = ISD::SHL; |
| 755 | } |
| 756 | |
| 757 | SDOperand NewSA = |
Chris Lattner | 8c7d2d5 | 2007-04-17 22:53:02 +0000 | [diff] [blame] | 758 | TLO.DAG.getConstant(Diff, Op.getOperand(1).getValueType()); |
Chris Lattner | 895c4ab | 2007-04-17 21:14:16 +0000 | [diff] [blame] | 759 | return TLO.CombineTo(Op, TLO.DAG.getNode(Opc, VT, |
| 760 | InOp.getOperand(0), NewSA)); |
| 761 | } |
| 762 | } |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 763 | |
| 764 | // Compute the new bits that are at the top now. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 765 | if (SimplifyDemandedBits(InOp, (NewMask << ShAmt), |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 766 | KnownZero, KnownOne, TLO, Depth+1)) |
| 767 | return true; |
| 768 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 769 | KnownZero = KnownZero.lshr(ShAmt); |
| 770 | KnownOne = KnownOne.lshr(ShAmt); |
Chris Lattner | c4fa603 | 2006-06-13 16:52:37 +0000 | [diff] [blame] | 771 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 772 | APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt); |
Chris Lattner | c4fa603 | 2006-06-13 16:52:37 +0000 | [diff] [blame] | 773 | KnownZero |= HighBits; // High bits known zero. |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 774 | } |
| 775 | break; |
| 776 | case ISD::SRA: |
| 777 | if (ConstantSDNode *SA = dyn_cast<ConstantSDNode>(Op.getOperand(1))) { |
| 778 | MVT::ValueType VT = Op.getValueType(); |
| 779 | unsigned ShAmt = SA->getValue(); |
| 780 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 781 | // If the shift count is an invalid immediate, don't do anything. |
| 782 | if (ShAmt >= BitWidth) |
| 783 | break; |
| 784 | |
| 785 | APInt InDemandedMask = (NewMask << ShAmt); |
Chris Lattner | 1b73713 | 2006-05-08 17:22:53 +0000 | [diff] [blame] | 786 | |
| 787 | // If any of the demanded bits are produced by the sign extension, we also |
| 788 | // demand the input sign bit. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 789 | APInt HighBits = APInt::getHighBitsSet(BitWidth, ShAmt); |
| 790 | if (HighBits.intersects(NewMask)) |
| 791 | InDemandedMask |= APInt::getSignBit(MVT::getSizeInBits(VT)); |
Chris Lattner | 1b73713 | 2006-05-08 17:22:53 +0000 | [diff] [blame] | 792 | |
| 793 | if (SimplifyDemandedBits(Op.getOperand(0), InDemandedMask, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 794 | KnownZero, KnownOne, TLO, Depth+1)) |
| 795 | return true; |
| 796 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 797 | KnownZero = KnownZero.lshr(ShAmt); |
| 798 | KnownOne = KnownOne.lshr(ShAmt); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 799 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 800 | // Handle the sign bit, adjusted to where it is now in the mask. |
| 801 | APInt SignBit = APInt::getSignBit(BitWidth).lshr(ShAmt); |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 802 | |
| 803 | // If the input sign bit is known to be zero, or if none of the top bits |
| 804 | // are demanded, turn this into an unsigned shift right. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 805 | if (KnownZero.intersects(SignBit) || (HighBits & ~NewMask) == HighBits) { |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 806 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL, VT, Op.getOperand(0), |
| 807 | Op.getOperand(1))); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 808 | } else if (KnownOne.intersects(SignBit)) { // New bits are known one. |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 809 | KnownOne |= HighBits; |
| 810 | } |
| 811 | } |
| 812 | break; |
| 813 | case ISD::SIGN_EXTEND_INREG: { |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 814 | MVT::ValueType EVT = cast<VTSDNode>(Op.getOperand(1))->getVT(); |
| 815 | |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 816 | // Sign extension. Compute the demanded bits in the result that are not |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 817 | // present in the input. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 818 | APInt NewBits = APInt::getHighBitsSet(BitWidth, |
| 819 | BitWidth - MVT::getSizeInBits(EVT)) & |
| 820 | NewMask; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 821 | |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 822 | // If none of the extended bits are demanded, eliminate the sextinreg. |
| 823 | if (NewBits == 0) |
| 824 | return TLO.CombineTo(Op, Op.getOperand(0)); |
| 825 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 826 | APInt InSignBit = APInt::getSignBit(MVT::getSizeInBits(EVT)); |
| 827 | InSignBit.zext(BitWidth); |
| 828 | APInt InputDemandedBits = APInt::getLowBitsSet(BitWidth, |
| 829 | MVT::getSizeInBits(EVT)) & |
| 830 | NewMask; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 831 | |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 832 | // Since the sign extended bits are demanded, we know that the sign |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 833 | // bit is demanded. |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 834 | InputDemandedBits |= InSignBit; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 835 | |
| 836 | if (SimplifyDemandedBits(Op.getOperand(0), InputDemandedBits, |
| 837 | KnownZero, KnownOne, TLO, Depth+1)) |
| 838 | return true; |
| 839 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
| 840 | |
| 841 | // If the sign bit of the input is known set or clear, then we know the |
| 842 | // top bits of the result. |
| 843 | |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 844 | // If the input sign bit is known zero, convert this into a zero extension. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 845 | if (KnownZero.intersects(InSignBit)) |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 846 | return TLO.CombineTo(Op, |
| 847 | TLO.DAG.getZeroExtendInReg(Op.getOperand(0), EVT)); |
| 848 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 849 | if (KnownOne.intersects(InSignBit)) { // Input sign bit known set |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 850 | KnownOne |= NewBits; |
| 851 | KnownZero &= ~NewBits; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 852 | } else { // Input sign bit unknown |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 853 | KnownZero &= ~NewBits; |
| 854 | KnownOne &= ~NewBits; |
| 855 | } |
| 856 | break; |
| 857 | } |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 858 | case ISD::ZERO_EXTEND: { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 859 | unsigned OperandBitWidth = Op.getOperand(0).getValueSizeInBits(); |
| 860 | APInt InMask = NewMask; |
| 861 | InMask.trunc(OperandBitWidth); |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 862 | |
| 863 | // If none of the top bits are demanded, convert this into an any_extend. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 864 | APInt NewBits = |
| 865 | APInt::getHighBitsSet(BitWidth, BitWidth - OperandBitWidth) & NewMask; |
| 866 | if (!NewBits.intersects(NewMask)) |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 867 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::ANY_EXTEND, |
| 868 | Op.getValueType(), |
| 869 | Op.getOperand(0))); |
| 870 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 871 | if (SimplifyDemandedBits(Op.getOperand(0), InMask, |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 872 | KnownZero, KnownOne, TLO, Depth+1)) |
| 873 | return true; |
| 874 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 875 | KnownZero.zext(BitWidth); |
| 876 | KnownOne.zext(BitWidth); |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 877 | KnownZero |= NewBits; |
| 878 | break; |
| 879 | } |
| 880 | case ISD::SIGN_EXTEND: { |
| 881 | MVT::ValueType InVT = Op.getOperand(0).getValueType(); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 882 | unsigned InBits = MVT::getSizeInBits(InVT); |
| 883 | APInt InMask = APInt::getLowBitsSet(BitWidth, InBits); |
| 884 | APInt InSignBit = APInt::getLowBitsSet(BitWidth, InBits); |
| 885 | APInt NewBits = ~InMask & NewMask; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 886 | |
| 887 | // If none of the top bits are demanded, convert this into an any_extend. |
| 888 | if (NewBits == 0) |
Chris Lattner | fea997a | 2007-02-01 04:55:59 +0000 | [diff] [blame] | 889 | return TLO.CombineTo(Op,TLO.DAG.getNode(ISD::ANY_EXTEND,Op.getValueType(), |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 890 | Op.getOperand(0))); |
| 891 | |
| 892 | // Since some of the sign extended bits are demanded, we know that the sign |
| 893 | // bit is demanded. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 894 | APInt InDemandedBits = InMask & NewMask; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 895 | InDemandedBits |= InSignBit; |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 896 | InDemandedBits.trunc(InBits); |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 897 | |
| 898 | if (SimplifyDemandedBits(Op.getOperand(0), InDemandedBits, KnownZero, |
| 899 | KnownOne, TLO, Depth+1)) |
| 900 | return true; |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 901 | KnownZero.zext(BitWidth); |
| 902 | KnownOne.zext(BitWidth); |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 903 | |
| 904 | // If the sign bit is known zero, convert this to a zero extend. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 905 | if (KnownZero.intersects(InSignBit)) |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 906 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::ZERO_EXTEND, |
| 907 | Op.getValueType(), |
| 908 | Op.getOperand(0))); |
| 909 | |
| 910 | // If the sign bit is known one, the top bits match. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 911 | if (KnownOne.intersects(InSignBit)) { |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 912 | KnownOne |= NewBits; |
| 913 | KnownZero &= ~NewBits; |
| 914 | } else { // Otherwise, top bits aren't known. |
| 915 | KnownOne &= ~NewBits; |
| 916 | KnownZero &= ~NewBits; |
| 917 | } |
| 918 | break; |
| 919 | } |
| 920 | case ISD::ANY_EXTEND: { |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 921 | unsigned OperandBitWidth = Op.getOperand(0).getValueSizeInBits(); |
| 922 | APInt InMask = NewMask; |
| 923 | InMask.trunc(OperandBitWidth); |
| 924 | if (SimplifyDemandedBits(Op.getOperand(0), InMask, |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 925 | KnownZero, KnownOne, TLO, Depth+1)) |
| 926 | return true; |
| 927 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 928 | KnownZero.zext(BitWidth); |
| 929 | KnownOne.zext(BitWidth); |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 930 | break; |
| 931 | } |
Chris Lattner | fe8babf | 2006-05-05 22:32:12 +0000 | [diff] [blame] | 932 | case ISD::TRUNCATE: { |
Chris Lattner | c93dfda | 2006-05-06 00:11:52 +0000 | [diff] [blame] | 933 | // Simplify the input, using demanded bit information, and compute the known |
| 934 | // zero/one bits live out. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 935 | APInt TruncMask = NewMask; |
| 936 | TruncMask.zext(Op.getOperand(0).getValueSizeInBits()); |
| 937 | if (SimplifyDemandedBits(Op.getOperand(0), TruncMask, |
Chris Lattner | fe8babf | 2006-05-05 22:32:12 +0000 | [diff] [blame] | 938 | KnownZero, KnownOne, TLO, Depth+1)) |
| 939 | return true; |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 940 | KnownZero.trunc(BitWidth); |
| 941 | KnownOne.trunc(BitWidth); |
Chris Lattner | c93dfda | 2006-05-06 00:11:52 +0000 | [diff] [blame] | 942 | |
| 943 | // If the input is only used by this truncate, see if we can shrink it based |
| 944 | // on the known demanded bits. |
| 945 | if (Op.getOperand(0).Val->hasOneUse()) { |
| 946 | SDOperand In = Op.getOperand(0); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 947 | unsigned InBitWidth = In.getValueSizeInBits(); |
Chris Lattner | c93dfda | 2006-05-06 00:11:52 +0000 | [diff] [blame] | 948 | switch (In.getOpcode()) { |
| 949 | default: break; |
| 950 | case ISD::SRL: |
| 951 | // Shrink SRL by a constant if none of the high bits shifted in are |
| 952 | // demanded. |
| 953 | if (ConstantSDNode *ShAmt = dyn_cast<ConstantSDNode>(In.getOperand(1))){ |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 954 | APInt HighBits = APInt::getHighBitsSet(InBitWidth, |
| 955 | InBitWidth - BitWidth); |
| 956 | HighBits = HighBits.lshr(ShAmt->getValue()); |
| 957 | HighBits.trunc(BitWidth); |
Chris Lattner | c93dfda | 2006-05-06 00:11:52 +0000 | [diff] [blame] | 958 | |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 959 | if (ShAmt->getValue() < BitWidth && !(HighBits & NewMask)) { |
Chris Lattner | c93dfda | 2006-05-06 00:11:52 +0000 | [diff] [blame] | 960 | // None of the shifted in bits are needed. Add a truncate of the |
| 961 | // shift input, then shift it. |
| 962 | SDOperand NewTrunc = TLO.DAG.getNode(ISD::TRUNCATE, |
| 963 | Op.getValueType(), |
| 964 | In.getOperand(0)); |
| 965 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SRL,Op.getValueType(), |
| 966 | NewTrunc, In.getOperand(1))); |
| 967 | } |
| 968 | } |
| 969 | break; |
| 970 | } |
| 971 | } |
| 972 | |
Chris Lattner | fe8babf | 2006-05-05 22:32:12 +0000 | [diff] [blame] | 973 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Chris Lattner | fe8babf | 2006-05-05 22:32:12 +0000 | [diff] [blame] | 974 | break; |
| 975 | } |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 976 | case ISD::AssertZext: { |
| 977 | MVT::ValueType VT = cast<VTSDNode>(Op.getOperand(1))->getVT(); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 978 | APInt InMask = APInt::getLowBitsSet(BitWidth, |
| 979 | MVT::getSizeInBits(VT)); |
| 980 | if (SimplifyDemandedBits(Op.getOperand(0), InMask & NewMask, |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 981 | KnownZero, KnownOne, TLO, Depth+1)) |
| 982 | return true; |
| 983 | assert((KnownZero & KnownOne) == 0 && "Bits known to be one AND zero?"); |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 984 | KnownZero |= ~InMask & NewMask; |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 985 | break; |
| 986 | } |
Chris Lattner | 2ceb2cf | 2007-12-22 21:35:38 +0000 | [diff] [blame] | 987 | case ISD::BIT_CONVERT: |
| 988 | #if 0 |
| 989 | // If this is an FP->Int bitcast and if the sign bit is the only thing that |
| 990 | // is demanded, turn this into a FGETSIGN. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 991 | if (NewMask == MVT::getIntVTSignBit(Op.getValueType()) && |
Chris Lattner | 2ceb2cf | 2007-12-22 21:35:38 +0000 | [diff] [blame] | 992 | MVT::isFloatingPoint(Op.getOperand(0).getValueType()) && |
| 993 | !MVT::isVector(Op.getOperand(0).getValueType())) { |
| 994 | // Only do this xform if FGETSIGN is valid or if before legalize. |
| 995 | if (!TLO.AfterLegalize || |
| 996 | isOperationLegal(ISD::FGETSIGN, Op.getValueType())) { |
| 997 | // Make a FGETSIGN + SHL to move the sign bit into the appropriate |
| 998 | // place. We expect the SHL to be eliminated by other optimizations. |
| 999 | SDOperand Sign = TLO.DAG.getNode(ISD::FGETSIGN, Op.getValueType(), |
| 1000 | Op.getOperand(0)); |
| 1001 | unsigned ShVal = MVT::getSizeInBits(Op.getValueType())-1; |
| 1002 | SDOperand ShAmt = TLO.DAG.getConstant(ShVal, getShiftAmountTy()); |
| 1003 | return TLO.CombineTo(Op, TLO.DAG.getNode(ISD::SHL, Op.getValueType(), |
| 1004 | Sign, ShAmt)); |
| 1005 | } |
| 1006 | } |
| 1007 | #endif |
| 1008 | break; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 1009 | case ISD::ADD: |
Chris Lattner | a6bc5a4 | 2006-02-27 01:00:42 +0000 | [diff] [blame] | 1010 | case ISD::SUB: |
Chris Lattner | 1482b5f | 2006-04-02 06:15:09 +0000 | [diff] [blame] | 1011 | case ISD::INTRINSIC_WO_CHAIN: |
| 1012 | case ISD::INTRINSIC_W_CHAIN: |
| 1013 | case ISD::INTRINSIC_VOID: |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 1014 | case ISD::CTTZ: |
| 1015 | case ISD::CTLZ: |
| 1016 | case ISD::CTPOP: |
| 1017 | case ISD::LOAD: |
| 1018 | case ISD::SETCC: |
| 1019 | case ISD::FGETSIGN: |
Chris Lattner | 1482b5f | 2006-04-02 06:15:09 +0000 | [diff] [blame] | 1020 | // Just use ComputeMaskedBits to compute output bits. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 1021 | TLO.DAG.ComputeMaskedBits(Op, NewMask, KnownZero, KnownOne, Depth); |
Chris Lattner | a6bc5a4 | 2006-02-27 01:00:42 +0000 | [diff] [blame] | 1022 | break; |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 1023 | } |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 1024 | |
| 1025 | // If we know the value of all of the demanded bits, return this as a |
| 1026 | // constant. |
Dan Gohman | 7b8d4a9 | 2008-02-27 00:25:32 +0000 | [diff] [blame] | 1027 | if ((NewMask & (KnownZero|KnownOne)) == NewMask) |
Chris Lattner | ec66515 | 2006-02-26 23:36:02 +0000 | [diff] [blame] | 1028 | return TLO.CombineTo(Op, TLO.DAG.getConstant(KnownOne, Op.getValueType())); |
| 1029 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 1030 | return false; |
| 1031 | } |
| 1032 | |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 1033 | /// computeMaskedBitsForTargetNode - Determine which of the bits specified |
| 1034 | /// in Mask are known to be either zero or one and return them in the |
| 1035 | /// KnownZero/KnownOne bitsets. |
| 1036 | void TargetLowering::computeMaskedBitsForTargetNode(const SDOperand Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1037 | const APInt &Mask, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 1038 | APInt &KnownZero, |
| 1039 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1040 | const SelectionDAG &DAG, |
Nate Begeman | 368e18d | 2006-02-16 21:11:51 +0000 | [diff] [blame] | 1041 | unsigned Depth) const { |
Chris Lattner | 1b5232a | 2006-04-02 06:19:46 +0000 | [diff] [blame] | 1042 | assert((Op.getOpcode() >= ISD::BUILTIN_OP_END || |
| 1043 | Op.getOpcode() == ISD::INTRINSIC_WO_CHAIN || |
| 1044 | Op.getOpcode() == ISD::INTRINSIC_W_CHAIN || |
| 1045 | Op.getOpcode() == ISD::INTRINSIC_VOID) && |
Chris Lattner | c6fd6cd | 2006-01-30 04:09:27 +0000 | [diff] [blame] | 1046 | "Should use MaskedValueIsZero if you don't know whether Op" |
| 1047 | " is a target node!"); |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 1048 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 1049 | } |
Chris Lattner | 4ccb070 | 2006-01-26 20:37:03 +0000 | [diff] [blame] | 1050 | |
Chris Lattner | 5c3e21d | 2006-05-06 09:27:13 +0000 | [diff] [blame] | 1051 | /// ComputeNumSignBitsForTargetNode - This method can be implemented by |
| 1052 | /// targets that want to expose additional information about sign bits to the |
| 1053 | /// DAG Combiner. |
| 1054 | unsigned TargetLowering::ComputeNumSignBitsForTargetNode(SDOperand Op, |
| 1055 | unsigned Depth) const { |
| 1056 | assert((Op.getOpcode() >= ISD::BUILTIN_OP_END || |
| 1057 | Op.getOpcode() == ISD::INTRINSIC_WO_CHAIN || |
| 1058 | Op.getOpcode() == ISD::INTRINSIC_W_CHAIN || |
| 1059 | Op.getOpcode() == ISD::INTRINSIC_VOID) && |
| 1060 | "Should use ComputeNumSignBits if you don't know whether Op" |
| 1061 | " is a target node!"); |
| 1062 | return 1; |
| 1063 | } |
| 1064 | |
| 1065 | |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1066 | /// SimplifySetCC - Try to simplify a setcc built with the specified operands |
| 1067 | /// and cc. If it is unable to simplify it, return a null SDOperand. |
| 1068 | SDOperand |
| 1069 | TargetLowering::SimplifySetCC(MVT::ValueType VT, SDOperand N0, SDOperand N1, |
| 1070 | ISD::CondCode Cond, bool foldBooleans, |
| 1071 | DAGCombinerInfo &DCI) const { |
| 1072 | SelectionDAG &DAG = DCI.DAG; |
| 1073 | |
| 1074 | // These setcc operations always fold. |
| 1075 | switch (Cond) { |
| 1076 | default: break; |
| 1077 | case ISD::SETFALSE: |
| 1078 | case ISD::SETFALSE2: return DAG.getConstant(0, VT); |
| 1079 | case ISD::SETTRUE: |
| 1080 | case ISD::SETTRUE2: return DAG.getConstant(1, VT); |
| 1081 | } |
| 1082 | |
| 1083 | if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val)) { |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1084 | const APInt &C1 = N1C->getAPIntValue(); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1085 | if (isa<ConstantSDNode>(N0.Val)) { |
| 1086 | return DAG.FoldSetCC(VT, N0, N1, Cond); |
| 1087 | } else { |
| 1088 | // If the LHS is '(srl (ctlz x), 5)', the RHS is 0/1, and this is an |
| 1089 | // equality comparison, then we're just comparing whether X itself is |
| 1090 | // zero. |
| 1091 | if (N0.getOpcode() == ISD::SRL && (C1 == 0 || C1 == 1) && |
| 1092 | N0.getOperand(0).getOpcode() == ISD::CTLZ && |
| 1093 | N0.getOperand(1).getOpcode() == ISD::Constant) { |
| 1094 | unsigned ShAmt = cast<ConstantSDNode>(N0.getOperand(1))->getValue(); |
| 1095 | if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && |
| 1096 | ShAmt == Log2_32(MVT::getSizeInBits(N0.getValueType()))) { |
| 1097 | if ((C1 == 0) == (Cond == ISD::SETEQ)) { |
| 1098 | // (srl (ctlz x), 5) == 0 -> X != 0 |
| 1099 | // (srl (ctlz x), 5) != 1 -> X != 0 |
| 1100 | Cond = ISD::SETNE; |
| 1101 | } else { |
| 1102 | // (srl (ctlz x), 5) != 0 -> X == 0 |
| 1103 | // (srl (ctlz x), 5) == 1 -> X == 0 |
| 1104 | Cond = ISD::SETEQ; |
| 1105 | } |
| 1106 | SDOperand Zero = DAG.getConstant(0, N0.getValueType()); |
| 1107 | return DAG.getSetCC(VT, N0.getOperand(0).getOperand(0), |
| 1108 | Zero, Cond); |
| 1109 | } |
| 1110 | } |
| 1111 | |
| 1112 | // If the LHS is a ZERO_EXTEND, perform the comparison on the input. |
| 1113 | if (N0.getOpcode() == ISD::ZERO_EXTEND) { |
| 1114 | unsigned InSize = MVT::getSizeInBits(N0.getOperand(0).getValueType()); |
| 1115 | |
| 1116 | // If the comparison constant has bits in the upper part, the |
| 1117 | // zero-extended value could never match. |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1118 | if (C1.intersects(APInt::getHighBitsSet(C1.getBitWidth(), |
| 1119 | C1.getBitWidth() - InSize))) { |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1120 | switch (Cond) { |
| 1121 | case ISD::SETUGT: |
| 1122 | case ISD::SETUGE: |
| 1123 | case ISD::SETEQ: return DAG.getConstant(0, VT); |
| 1124 | case ISD::SETULT: |
| 1125 | case ISD::SETULE: |
| 1126 | case ISD::SETNE: return DAG.getConstant(1, VT); |
| 1127 | case ISD::SETGT: |
| 1128 | case ISD::SETGE: |
| 1129 | // True if the sign bit of C1 is set. |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1130 | return DAG.getConstant(C1.isNegative(), VT); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1131 | case ISD::SETLT: |
| 1132 | case ISD::SETLE: |
| 1133 | // True if the sign bit of C1 isn't set. |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1134 | return DAG.getConstant(C1.isNonNegative(), VT); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1135 | default: |
| 1136 | break; |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | // Otherwise, we can perform the comparison with the low bits. |
| 1141 | switch (Cond) { |
| 1142 | case ISD::SETEQ: |
| 1143 | case ISD::SETNE: |
| 1144 | case ISD::SETUGT: |
| 1145 | case ISD::SETUGE: |
| 1146 | case ISD::SETULT: |
| 1147 | case ISD::SETULE: |
| 1148 | return DAG.getSetCC(VT, N0.getOperand(0), |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1149 | DAG.getConstant(APInt(C1).trunc(InSize), |
| 1150 | N0.getOperand(0).getValueType()), |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1151 | Cond); |
| 1152 | default: |
| 1153 | break; // todo, be more careful with signed comparisons |
| 1154 | } |
| 1155 | } else if (N0.getOpcode() == ISD::SIGN_EXTEND_INREG && |
| 1156 | (Cond == ISD::SETEQ || Cond == ISD::SETNE)) { |
| 1157 | MVT::ValueType ExtSrcTy = cast<VTSDNode>(N0.getOperand(1))->getVT(); |
| 1158 | unsigned ExtSrcTyBits = MVT::getSizeInBits(ExtSrcTy); |
| 1159 | MVT::ValueType ExtDstTy = N0.getValueType(); |
| 1160 | unsigned ExtDstTyBits = MVT::getSizeInBits(ExtDstTy); |
| 1161 | |
| 1162 | // If the extended part has any inconsistent bits, it cannot ever |
| 1163 | // compare equal. In other words, they have to be all ones or all |
| 1164 | // zeros. |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1165 | APInt ExtBits = |
| 1166 | APInt::getHighBitsSet(ExtDstTyBits, ExtDstTyBits - ExtSrcTyBits); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1167 | if ((C1 & ExtBits) != 0 && (C1 & ExtBits) != ExtBits) |
| 1168 | return DAG.getConstant(Cond == ISD::SETNE, VT); |
| 1169 | |
| 1170 | SDOperand ZextOp; |
| 1171 | MVT::ValueType Op0Ty = N0.getOperand(0).getValueType(); |
| 1172 | if (Op0Ty == ExtSrcTy) { |
| 1173 | ZextOp = N0.getOperand(0); |
| 1174 | } else { |
Dan Gohman | 3370dd7 | 2008-03-03 22:37:52 +0000 | [diff] [blame] | 1175 | APInt Imm = APInt::getLowBitsSet(ExtDstTyBits, ExtSrcTyBits); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1176 | ZextOp = DAG.getNode(ISD::AND, Op0Ty, N0.getOperand(0), |
| 1177 | DAG.getConstant(Imm, Op0Ty)); |
| 1178 | } |
| 1179 | if (!DCI.isCalledByLegalizer()) |
| 1180 | DCI.AddToWorklist(ZextOp.Val); |
| 1181 | // Otherwise, make this a use of a zext. |
| 1182 | return DAG.getSetCC(VT, ZextOp, |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1183 | DAG.getConstant(C1 & APInt::getLowBitsSet( |
| 1184 | ExtDstTyBits, |
| 1185 | ExtSrcTyBits), |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1186 | ExtDstTy), |
| 1187 | Cond); |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1188 | } else if ((N1C->isNullValue() || N1C->getAPIntValue() == 1) && |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1189 | (Cond == ISD::SETEQ || Cond == ISD::SETNE)) { |
| 1190 | |
| 1191 | // SETCC (SETCC), [0|1], [EQ|NE] -> SETCC |
| 1192 | if (N0.getOpcode() == ISD::SETCC) { |
| 1193 | bool TrueWhenTrue = (Cond == ISD::SETEQ) ^ (N1C->getValue() != 1); |
| 1194 | if (TrueWhenTrue) |
| 1195 | return N0; |
| 1196 | |
| 1197 | // Invert the condition. |
| 1198 | ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get(); |
| 1199 | CC = ISD::getSetCCInverse(CC, |
| 1200 | MVT::isInteger(N0.getOperand(0).getValueType())); |
| 1201 | return DAG.getSetCC(VT, N0.getOperand(0), N0.getOperand(1), CC); |
| 1202 | } |
| 1203 | |
| 1204 | if ((N0.getOpcode() == ISD::XOR || |
| 1205 | (N0.getOpcode() == ISD::AND && |
| 1206 | N0.getOperand(0).getOpcode() == ISD::XOR && |
| 1207 | N0.getOperand(1) == N0.getOperand(0).getOperand(1))) && |
| 1208 | isa<ConstantSDNode>(N0.getOperand(1)) && |
| 1209 | cast<ConstantSDNode>(N0.getOperand(1))->getValue() == 1) { |
| 1210 | // If this is (X^1) == 0/1, swap the RHS and eliminate the xor. We |
| 1211 | // can only do this if the top bits are known zero. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1212 | unsigned BitWidth = N0.getValueSizeInBits(); |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 1213 | if (DAG.MaskedValueIsZero(N0, |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1214 | APInt::getHighBitsSet(BitWidth, |
| 1215 | BitWidth-1))) { |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1216 | // Okay, get the un-inverted input value. |
| 1217 | SDOperand Val; |
| 1218 | if (N0.getOpcode() == ISD::XOR) |
| 1219 | Val = N0.getOperand(0); |
| 1220 | else { |
| 1221 | assert(N0.getOpcode() == ISD::AND && |
| 1222 | N0.getOperand(0).getOpcode() == ISD::XOR); |
| 1223 | // ((X^1)&1)^1 -> X & 1 |
| 1224 | Val = DAG.getNode(ISD::AND, N0.getValueType(), |
| 1225 | N0.getOperand(0).getOperand(0), |
| 1226 | N0.getOperand(1)); |
| 1227 | } |
| 1228 | return DAG.getSetCC(VT, Val, N1, |
| 1229 | Cond == ISD::SETEQ ? ISD::SETNE : ISD::SETEQ); |
| 1230 | } |
| 1231 | } |
| 1232 | } |
| 1233 | |
Dan Gohman | 3370dd7 | 2008-03-03 22:37:52 +0000 | [diff] [blame] | 1234 | APInt MinVal, MaxVal; |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1235 | unsigned OperandBitSize = MVT::getSizeInBits(N1C->getValueType(0)); |
| 1236 | if (ISD::isSignedIntSetCC(Cond)) { |
Dan Gohman | 3370dd7 | 2008-03-03 22:37:52 +0000 | [diff] [blame] | 1237 | MinVal = APInt::getSignedMinValue(OperandBitSize); |
| 1238 | MaxVal = APInt::getSignedMaxValue(OperandBitSize); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1239 | } else { |
Dan Gohman | 3370dd7 | 2008-03-03 22:37:52 +0000 | [diff] [blame] | 1240 | MinVal = APInt::getMinValue(OperandBitSize); |
| 1241 | MaxVal = APInt::getMaxValue(OperandBitSize); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | // Canonicalize GE/LE comparisons to use GT/LT comparisons. |
| 1245 | if (Cond == ISD::SETGE || Cond == ISD::SETUGE) { |
| 1246 | if (C1 == MinVal) return DAG.getConstant(1, VT); // X >= MIN --> true |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1247 | // X >= C0 --> X > (C0-1) |
| 1248 | return DAG.getSetCC(VT, N0, DAG.getConstant(C1-1, N1.getValueType()), |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1249 | (Cond == ISD::SETGE) ? ISD::SETGT : ISD::SETUGT); |
| 1250 | } |
| 1251 | |
| 1252 | if (Cond == ISD::SETLE || Cond == ISD::SETULE) { |
| 1253 | if (C1 == MaxVal) return DAG.getConstant(1, VT); // X <= MAX --> true |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1254 | // X <= C0 --> X < (C0+1) |
| 1255 | return DAG.getSetCC(VT, N0, DAG.getConstant(C1+1, N1.getValueType()), |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1256 | (Cond == ISD::SETLE) ? ISD::SETLT : ISD::SETULT); |
| 1257 | } |
| 1258 | |
| 1259 | if ((Cond == ISD::SETLT || Cond == ISD::SETULT) && C1 == MinVal) |
| 1260 | return DAG.getConstant(0, VT); // X < MIN --> false |
| 1261 | if ((Cond == ISD::SETGE || Cond == ISD::SETUGE) && C1 == MinVal) |
| 1262 | return DAG.getConstant(1, VT); // X >= MIN --> true |
| 1263 | if ((Cond == ISD::SETGT || Cond == ISD::SETUGT) && C1 == MaxVal) |
| 1264 | return DAG.getConstant(0, VT); // X > MAX --> false |
| 1265 | if ((Cond == ISD::SETLE || Cond == ISD::SETULE) && C1 == MaxVal) |
| 1266 | return DAG.getConstant(1, VT); // X <= MAX --> true |
| 1267 | |
| 1268 | // Canonicalize setgt X, Min --> setne X, Min |
| 1269 | if ((Cond == ISD::SETGT || Cond == ISD::SETUGT) && C1 == MinVal) |
| 1270 | return DAG.getSetCC(VT, N0, N1, ISD::SETNE); |
| 1271 | // Canonicalize setlt X, Max --> setne X, Max |
| 1272 | if ((Cond == ISD::SETLT || Cond == ISD::SETULT) && C1 == MaxVal) |
| 1273 | return DAG.getSetCC(VT, N0, N1, ISD::SETNE); |
| 1274 | |
| 1275 | // If we have setult X, 1, turn it into seteq X, 0 |
| 1276 | if ((Cond == ISD::SETLT || Cond == ISD::SETULT) && C1 == MinVal+1) |
| 1277 | return DAG.getSetCC(VT, N0, DAG.getConstant(MinVal, N0.getValueType()), |
| 1278 | ISD::SETEQ); |
| 1279 | // If we have setugt X, Max-1, turn it into seteq X, Max |
| 1280 | else if ((Cond == ISD::SETGT || Cond == ISD::SETUGT) && C1 == MaxVal-1) |
| 1281 | return DAG.getSetCC(VT, N0, DAG.getConstant(MaxVal, N0.getValueType()), |
| 1282 | ISD::SETEQ); |
| 1283 | |
| 1284 | // If we have "setcc X, C0", check to see if we can shrink the immediate |
| 1285 | // by changing cc. |
| 1286 | |
| 1287 | // SETUGT X, SINTMAX -> SETLT X, 0 |
| 1288 | if (Cond == ISD::SETUGT && OperandBitSize != 1 && |
| 1289 | C1 == (~0ULL >> (65-OperandBitSize))) |
| 1290 | return DAG.getSetCC(VT, N0, DAG.getConstant(0, N1.getValueType()), |
| 1291 | ISD::SETLT); |
| 1292 | |
| 1293 | // FIXME: Implement the rest of these. |
| 1294 | |
| 1295 | // Fold bit comparisons when we can. |
| 1296 | if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && |
| 1297 | VT == N0.getValueType() && N0.getOpcode() == ISD::AND) |
| 1298 | if (ConstantSDNode *AndRHS = |
| 1299 | dyn_cast<ConstantSDNode>(N0.getOperand(1))) { |
| 1300 | if (Cond == ISD::SETNE && C1 == 0) {// (X & 8) != 0 --> (X & 8) >> 3 |
| 1301 | // Perform the xform if the AND RHS is a single bit. |
| 1302 | if (isPowerOf2_64(AndRHS->getValue())) { |
| 1303 | return DAG.getNode(ISD::SRL, VT, N0, |
| 1304 | DAG.getConstant(Log2_64(AndRHS->getValue()), |
| 1305 | getShiftAmountTy())); |
| 1306 | } |
| 1307 | } else if (Cond == ISD::SETEQ && C1 == AndRHS->getValue()) { |
| 1308 | // (X & 8) == 8 --> (X & 8) >> 3 |
| 1309 | // Perform the xform if C1 is a single bit. |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1310 | if (C1.isPowerOf2()) { |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1311 | return DAG.getNode(ISD::SRL, VT, N0, |
Dan Gohman | 6c6cd1c | 2008-03-03 22:22:56 +0000 | [diff] [blame] | 1312 | DAG.getConstant(C1.logBase2(), getShiftAmountTy())); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1313 | } |
| 1314 | } |
| 1315 | } |
| 1316 | } |
| 1317 | } else if (isa<ConstantSDNode>(N0.Val)) { |
| 1318 | // Ensure that the constant occurs on the RHS. |
| 1319 | return DAG.getSetCC(VT, N1, N0, ISD::getSetCCSwappedOperands(Cond)); |
| 1320 | } |
| 1321 | |
| 1322 | if (isa<ConstantFPSDNode>(N0.Val)) { |
| 1323 | // Constant fold or commute setcc. |
| 1324 | SDOperand O = DAG.FoldSetCC(VT, N0, N1, Cond); |
| 1325 | if (O.Val) return O; |
Chris Lattner | 63079f0 | 2007-12-29 08:37:08 +0000 | [diff] [blame] | 1326 | } else if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(N1.Val)) { |
| 1327 | // If the RHS of an FP comparison is a constant, simplify it away in |
| 1328 | // some cases. |
| 1329 | if (CFP->getValueAPF().isNaN()) { |
| 1330 | // If an operand is known to be a nan, we can fold it. |
| 1331 | switch (ISD::getUnorderedFlavor(Cond)) { |
| 1332 | default: assert(0 && "Unknown flavor!"); |
| 1333 | case 0: // Known false. |
| 1334 | return DAG.getConstant(0, VT); |
| 1335 | case 1: // Known true. |
| 1336 | return DAG.getConstant(1, VT); |
Chris Lattner | 1c3e1e2 | 2007-12-30 21:21:10 +0000 | [diff] [blame] | 1337 | case 2: // Undefined. |
Chris Lattner | 63079f0 | 2007-12-29 08:37:08 +0000 | [diff] [blame] | 1338 | return DAG.getNode(ISD::UNDEF, VT); |
| 1339 | } |
| 1340 | } |
| 1341 | |
| 1342 | // Otherwise, we know the RHS is not a NaN. Simplify the node to drop the |
| 1343 | // constant if knowing that the operand is non-nan is enough. We prefer to |
| 1344 | // have SETO(x,x) instead of SETO(x, 0.0) because this avoids having to |
| 1345 | // materialize 0.0. |
| 1346 | if (Cond == ISD::SETO || Cond == ISD::SETUO) |
| 1347 | return DAG.getSetCC(VT, N0, N0, Cond); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | if (N0 == N1) { |
| 1351 | // We can always fold X == X for integer setcc's. |
| 1352 | if (MVT::isInteger(N0.getValueType())) |
| 1353 | return DAG.getConstant(ISD::isTrueWhenEqual(Cond), VT); |
| 1354 | unsigned UOF = ISD::getUnorderedFlavor(Cond); |
| 1355 | if (UOF == 2) // FP operators that are undefined on NaNs. |
| 1356 | return DAG.getConstant(ISD::isTrueWhenEqual(Cond), VT); |
| 1357 | if (UOF == unsigned(ISD::isTrueWhenEqual(Cond))) |
| 1358 | return DAG.getConstant(UOF, VT); |
| 1359 | // Otherwise, we can't fold it. However, we can simplify it to SETUO/SETO |
| 1360 | // if it is not already. |
| 1361 | ISD::CondCode NewCond = UOF == 0 ? ISD::SETO : ISD::SETUO; |
| 1362 | if (NewCond != Cond) |
| 1363 | return DAG.getSetCC(VT, N0, N1, NewCond); |
| 1364 | } |
| 1365 | |
| 1366 | if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && |
| 1367 | MVT::isInteger(N0.getValueType())) { |
| 1368 | if (N0.getOpcode() == ISD::ADD || N0.getOpcode() == ISD::SUB || |
| 1369 | N0.getOpcode() == ISD::XOR) { |
| 1370 | // Simplify (X+Y) == (X+Z) --> Y == Z |
| 1371 | if (N0.getOpcode() == N1.getOpcode()) { |
| 1372 | if (N0.getOperand(0) == N1.getOperand(0)) |
| 1373 | return DAG.getSetCC(VT, N0.getOperand(1), N1.getOperand(1), Cond); |
| 1374 | if (N0.getOperand(1) == N1.getOperand(1)) |
| 1375 | return DAG.getSetCC(VT, N0.getOperand(0), N1.getOperand(0), Cond); |
| 1376 | if (DAG.isCommutativeBinOp(N0.getOpcode())) { |
| 1377 | // If X op Y == Y op X, try other combinations. |
| 1378 | if (N0.getOperand(0) == N1.getOperand(1)) |
| 1379 | return DAG.getSetCC(VT, N0.getOperand(1), N1.getOperand(0), Cond); |
| 1380 | if (N0.getOperand(1) == N1.getOperand(0)) |
| 1381 | return DAG.getSetCC(VT, N0.getOperand(0), N1.getOperand(1), Cond); |
| 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(N1)) { |
| 1386 | if (ConstantSDNode *LHSR = dyn_cast<ConstantSDNode>(N0.getOperand(1))) { |
| 1387 | // Turn (X+C1) == C2 --> X == C2-C1 |
| 1388 | if (N0.getOpcode() == ISD::ADD && N0.Val->hasOneUse()) { |
| 1389 | return DAG.getSetCC(VT, N0.getOperand(0), |
| 1390 | DAG.getConstant(RHSC->getValue()-LHSR->getValue(), |
| 1391 | N0.getValueType()), Cond); |
| 1392 | } |
| 1393 | |
| 1394 | // Turn (X^C1) == C2 into X == C1^C2 iff X&~C1 = 0. |
| 1395 | if (N0.getOpcode() == ISD::XOR) |
| 1396 | // If we know that all of the inverted bits are zero, don't bother |
| 1397 | // performing the inversion. |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1398 | if (DAG.MaskedValueIsZero(N0.getOperand(0), ~LHSR->getAPIntValue())) |
| 1399 | return |
| 1400 | DAG.getSetCC(VT, N0.getOperand(0), |
| 1401 | DAG.getConstant(LHSR->getAPIntValue() ^ |
| 1402 | RHSC->getAPIntValue(), |
| 1403 | N0.getValueType()), |
| 1404 | Cond); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | // Turn (C1-X) == C2 --> X == C1-C2 |
| 1408 | if (ConstantSDNode *SUBC = dyn_cast<ConstantSDNode>(N0.getOperand(0))) { |
| 1409 | if (N0.getOpcode() == ISD::SUB && N0.Val->hasOneUse()) { |
Dan Gohman | 2e68b6f | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 1410 | return |
| 1411 | DAG.getSetCC(VT, N0.getOperand(1), |
| 1412 | DAG.getConstant(SUBC->getAPIntValue() - |
| 1413 | RHSC->getAPIntValue(), |
| 1414 | N0.getValueType()), |
| 1415 | Cond); |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1416 | } |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | // Simplify (X+Z) == X --> Z == 0 |
| 1421 | if (N0.getOperand(0) == N1) |
| 1422 | return DAG.getSetCC(VT, N0.getOperand(1), |
| 1423 | DAG.getConstant(0, N0.getValueType()), Cond); |
| 1424 | if (N0.getOperand(1) == N1) { |
| 1425 | if (DAG.isCommutativeBinOp(N0.getOpcode())) |
| 1426 | return DAG.getSetCC(VT, N0.getOperand(0), |
| 1427 | DAG.getConstant(0, N0.getValueType()), Cond); |
Chris Lattner | 2ad913b | 2007-05-19 00:43:44 +0000 | [diff] [blame] | 1428 | else if (N0.Val->hasOneUse()) { |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1429 | assert(N0.getOpcode() == ISD::SUB && "Unexpected operation!"); |
| 1430 | // (Z-X) == X --> Z == X<<1 |
| 1431 | SDOperand SH = DAG.getNode(ISD::SHL, N1.getValueType(), |
| 1432 | N1, |
| 1433 | DAG.getConstant(1, getShiftAmountTy())); |
| 1434 | if (!DCI.isCalledByLegalizer()) |
| 1435 | DCI.AddToWorklist(SH.Val); |
| 1436 | return DAG.getSetCC(VT, N0.getOperand(0), SH, Cond); |
| 1437 | } |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | if (N1.getOpcode() == ISD::ADD || N1.getOpcode() == ISD::SUB || |
| 1442 | N1.getOpcode() == ISD::XOR) { |
| 1443 | // Simplify X == (X+Z) --> Z == 0 |
| 1444 | if (N1.getOperand(0) == N0) { |
| 1445 | return DAG.getSetCC(VT, N1.getOperand(1), |
| 1446 | DAG.getConstant(0, N1.getValueType()), Cond); |
| 1447 | } else if (N1.getOperand(1) == N0) { |
| 1448 | if (DAG.isCommutativeBinOp(N1.getOpcode())) { |
| 1449 | return DAG.getSetCC(VT, N1.getOperand(0), |
| 1450 | DAG.getConstant(0, N1.getValueType()), Cond); |
Chris Lattner | 7667c0b | 2007-05-19 00:46:51 +0000 | [diff] [blame] | 1451 | } else if (N1.Val->hasOneUse()) { |
Evan Cheng | fa1eb27 | 2007-02-08 22:13:59 +0000 | [diff] [blame] | 1452 | assert(N1.getOpcode() == ISD::SUB && "Unexpected operation!"); |
| 1453 | // X == (Z-X) --> X<<1 == Z |
| 1454 | SDOperand SH = DAG.getNode(ISD::SHL, N1.getValueType(), N0, |
| 1455 | DAG.getConstant(1, getShiftAmountTy())); |
| 1456 | if (!DCI.isCalledByLegalizer()) |
| 1457 | DCI.AddToWorklist(SH.Val); |
| 1458 | return DAG.getSetCC(VT, SH, N1.getOperand(0), Cond); |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | } |
| 1463 | |
| 1464 | // Fold away ALL boolean setcc's. |
| 1465 | SDOperand Temp; |
| 1466 | if (N0.getValueType() == MVT::i1 && foldBooleans) { |
| 1467 | switch (Cond) { |
| 1468 | default: assert(0 && "Unknown integer setcc!"); |
| 1469 | case ISD::SETEQ: // X == Y -> (X^Y)^1 |
| 1470 | Temp = DAG.getNode(ISD::XOR, MVT::i1, N0, N1); |
| 1471 | N0 = DAG.getNode(ISD::XOR, MVT::i1, Temp, DAG.getConstant(1, MVT::i1)); |
| 1472 | if (!DCI.isCalledByLegalizer()) |
| 1473 | DCI.AddToWorklist(Temp.Val); |
| 1474 | break; |
| 1475 | case ISD::SETNE: // X != Y --> (X^Y) |
| 1476 | N0 = DAG.getNode(ISD::XOR, MVT::i1, N0, N1); |
| 1477 | break; |
| 1478 | case ISD::SETGT: // X >s Y --> X == 0 & Y == 1 --> X^1 & Y |
| 1479 | case ISD::SETULT: // X <u Y --> X == 0 & Y == 1 --> X^1 & Y |
| 1480 | Temp = DAG.getNode(ISD::XOR, MVT::i1, N0, DAG.getConstant(1, MVT::i1)); |
| 1481 | N0 = DAG.getNode(ISD::AND, MVT::i1, N1, Temp); |
| 1482 | if (!DCI.isCalledByLegalizer()) |
| 1483 | DCI.AddToWorklist(Temp.Val); |
| 1484 | break; |
| 1485 | case ISD::SETLT: // X <s Y --> X == 1 & Y == 0 --> Y^1 & X |
| 1486 | case ISD::SETUGT: // X >u Y --> X == 1 & Y == 0 --> Y^1 & X |
| 1487 | Temp = DAG.getNode(ISD::XOR, MVT::i1, N1, DAG.getConstant(1, MVT::i1)); |
| 1488 | N0 = DAG.getNode(ISD::AND, MVT::i1, N0, Temp); |
| 1489 | if (!DCI.isCalledByLegalizer()) |
| 1490 | DCI.AddToWorklist(Temp.Val); |
| 1491 | break; |
| 1492 | case ISD::SETULE: // X <=u Y --> X == 0 | Y == 1 --> X^1 | Y |
| 1493 | case ISD::SETGE: // X >=s Y --> X == 0 | Y == 1 --> X^1 | Y |
| 1494 | Temp = DAG.getNode(ISD::XOR, MVT::i1, N0, DAG.getConstant(1, MVT::i1)); |
| 1495 | N0 = DAG.getNode(ISD::OR, MVT::i1, N1, Temp); |
| 1496 | if (!DCI.isCalledByLegalizer()) |
| 1497 | DCI.AddToWorklist(Temp.Val); |
| 1498 | break; |
| 1499 | case ISD::SETUGE: // X >=u Y --> X == 1 | Y == 0 --> Y^1 | X |
| 1500 | case ISD::SETLE: // X <=s Y --> X == 1 | Y == 0 --> Y^1 | X |
| 1501 | Temp = DAG.getNode(ISD::XOR, MVT::i1, N1, DAG.getConstant(1, MVT::i1)); |
| 1502 | N0 = DAG.getNode(ISD::OR, MVT::i1, N0, Temp); |
| 1503 | break; |
| 1504 | } |
| 1505 | if (VT != MVT::i1) { |
| 1506 | if (!DCI.isCalledByLegalizer()) |
| 1507 | DCI.AddToWorklist(N0.Val); |
| 1508 | // FIXME: If running after legalize, we probably can't do this. |
| 1509 | N0 = DAG.getNode(ISD::ZERO_EXTEND, VT, N0); |
| 1510 | } |
| 1511 | return N0; |
| 1512 | } |
| 1513 | |
| 1514 | // Could not fold it. |
| 1515 | return SDOperand(); |
| 1516 | } |
| 1517 | |
Chris Lattner | 00ffed0 | 2006-03-01 04:52:55 +0000 | [diff] [blame] | 1518 | SDOperand TargetLowering:: |
| 1519 | PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const { |
| 1520 | // Default implementation: no optimization. |
| 1521 | return SDOperand(); |
| 1522 | } |
| 1523 | |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1524 | //===----------------------------------------------------------------------===// |
| 1525 | // Inline Assembler Implementation Methods |
| 1526 | //===----------------------------------------------------------------------===// |
| 1527 | |
| 1528 | TargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 1529 | TargetLowering::getConstraintType(const std::string &Constraint) const { |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1530 | // FIXME: lots more standard ones to handle. |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 1531 | if (Constraint.size() == 1) { |
| 1532 | switch (Constraint[0]) { |
| 1533 | default: break; |
| 1534 | case 'r': return C_RegisterClass; |
| 1535 | case 'm': // memory |
| 1536 | case 'o': // offsetable |
| 1537 | case 'V': // not offsetable |
| 1538 | return C_Memory; |
| 1539 | case 'i': // Simple Integer or Relocatable Constant |
| 1540 | case 'n': // Simple Integer |
| 1541 | case 's': // Relocatable Constant |
Chris Lattner | c13dd1c | 2007-03-25 04:35:41 +0000 | [diff] [blame] | 1542 | case 'X': // Allow ANY value. |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 1543 | case 'I': // Target registers. |
| 1544 | case 'J': |
| 1545 | case 'K': |
| 1546 | case 'L': |
| 1547 | case 'M': |
| 1548 | case 'N': |
| 1549 | case 'O': |
| 1550 | case 'P': |
| 1551 | return C_Other; |
| 1552 | } |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1553 | } |
Chris Lattner | 065421f | 2007-03-25 02:18:14 +0000 | [diff] [blame] | 1554 | |
| 1555 | if (Constraint.size() > 1 && Constraint[0] == '{' && |
| 1556 | Constraint[Constraint.size()-1] == '}') |
| 1557 | return C_Register; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 1558 | return C_Unknown; |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
Dale Johannesen | ba2a0b9 | 2008-01-29 02:21:21 +0000 | [diff] [blame] | 1561 | /// LowerXConstraint - try to replace an X constraint, which matches anything, |
| 1562 | /// with another that has more specific requirements based on the type of the |
| 1563 | /// corresponding operand. |
| 1564 | void TargetLowering::lowerXConstraint(MVT::ValueType ConstraintVT, |
| 1565 | std::string& s) const { |
| 1566 | if (MVT::isInteger(ConstraintVT)) |
| 1567 | s = "r"; |
| 1568 | else if (MVT::isFloatingPoint(ConstraintVT)) |
| 1569 | s = "f"; // works for many targets |
| 1570 | else |
| 1571 | s = ""; |
| 1572 | } |
| 1573 | |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 1574 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 1575 | /// vector. If it is invalid, don't add anything to Ops. |
| 1576 | void TargetLowering::LowerAsmOperandForConstraint(SDOperand Op, |
| 1577 | char ConstraintLetter, |
| 1578 | std::vector<SDOperand> &Ops, |
| 1579 | SelectionDAG &DAG) { |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1580 | switch (ConstraintLetter) { |
Chris Lattner | 9ff6ee8 | 2007-02-17 06:00:35 +0000 | [diff] [blame] | 1581 | default: break; |
Dale Johannesen | eb57ea7 | 2007-11-05 21:20:28 +0000 | [diff] [blame] | 1582 | case 'X': // Allows any operand; labels (basic block) use this. |
| 1583 | if (Op.getOpcode() == ISD::BasicBlock) { |
| 1584 | Ops.push_back(Op); |
| 1585 | return; |
| 1586 | } |
| 1587 | // fall through |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1588 | case 'i': // Simple Integer or Relocatable Constant |
| 1589 | case 'n': // Simple Integer |
Dale Johannesen | eb57ea7 | 2007-11-05 21:20:28 +0000 | [diff] [blame] | 1590 | case 's': { // Relocatable Constant |
Chris Lattner | 75c7d2b | 2007-05-03 16:54:34 +0000 | [diff] [blame] | 1591 | // These operands are interested in values of the form (GV+C), where C may |
| 1592 | // be folded in as an offset of GV, or it may be explicitly added. Also, it |
| 1593 | // is possible and fine if either GV or C are missing. |
| 1594 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 1595 | GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Op); |
| 1596 | |
| 1597 | // If we have "(add GV, C)", pull out GV/C |
| 1598 | if (Op.getOpcode() == ISD::ADD) { |
| 1599 | C = dyn_cast<ConstantSDNode>(Op.getOperand(1)); |
| 1600 | GA = dyn_cast<GlobalAddressSDNode>(Op.getOperand(0)); |
| 1601 | if (C == 0 || GA == 0) { |
| 1602 | C = dyn_cast<ConstantSDNode>(Op.getOperand(0)); |
| 1603 | GA = dyn_cast<GlobalAddressSDNode>(Op.getOperand(1)); |
| 1604 | } |
| 1605 | if (C == 0 || GA == 0) |
| 1606 | C = 0, GA = 0; |
| 1607 | } |
| 1608 | |
| 1609 | // If we find a valid operand, map to the TargetXXX version so that the |
| 1610 | // value itself doesn't get selected. |
| 1611 | if (GA) { // Either &GV or &GV+C |
| 1612 | if (ConstraintLetter != 'n') { |
| 1613 | int64_t Offs = GA->getOffset(); |
| 1614 | if (C) Offs += C->getValue(); |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 1615 | Ops.push_back(DAG.getTargetGlobalAddress(GA->getGlobal(), |
| 1616 | Op.getValueType(), Offs)); |
| 1617 | return; |
Chris Lattner | 75c7d2b | 2007-05-03 16:54:34 +0000 | [diff] [blame] | 1618 | } |
| 1619 | } |
| 1620 | if (C) { // just C, no GV. |
Chris Lattner | 9ff6ee8 | 2007-02-17 06:00:35 +0000 | [diff] [blame] | 1621 | // Simple constants are not allowed for 's'. |
Chris Lattner | 48884cd | 2007-08-25 00:47:38 +0000 | [diff] [blame] | 1622 | if (ConstraintLetter != 's') { |
| 1623 | Ops.push_back(DAG.getTargetConstant(C->getValue(), Op.getValueType())); |
| 1624 | return; |
| 1625 | } |
Chris Lattner | 9ff6ee8 | 2007-02-17 06:00:35 +0000 | [diff] [blame] | 1626 | } |
Chris Lattner | 9ff6ee8 | 2007-02-17 06:00:35 +0000 | [diff] [blame] | 1627 | break; |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1628 | } |
Chris Lattner | 75c7d2b | 2007-05-03 16:54:34 +0000 | [diff] [blame] | 1629 | } |
Chris Lattner | eb8146b | 2006-02-04 02:13:02 +0000 | [diff] [blame] | 1630 | } |
| 1631 | |
Chris Lattner | 4ccb070 | 2006-01-26 20:37:03 +0000 | [diff] [blame] | 1632 | std::vector<unsigned> TargetLowering:: |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1633 | getRegClassForInlineAsmConstraint(const std::string &Constraint, |
| 1634 | MVT::ValueType VT) const { |
| 1635 | return std::vector<unsigned>(); |
| 1636 | } |
| 1637 | |
| 1638 | |
| 1639 | std::pair<unsigned, const TargetRegisterClass*> TargetLowering:: |
Chris Lattner | 4217ca8dc | 2006-02-21 23:11:00 +0000 | [diff] [blame] | 1640 | getRegForInlineAsmConstraint(const std::string &Constraint, |
| 1641 | MVT::ValueType VT) const { |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1642 | if (Constraint[0] != '{') |
| 1643 | return std::pair<unsigned, const TargetRegisterClass*>(0, 0); |
Chris Lattner | a55079a | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 1644 | assert(*(Constraint.end()-1) == '}' && "Not a brace enclosed constraint?"); |
| 1645 | |
| 1646 | // Remove the braces from around the name. |
| 1647 | std::string RegName(Constraint.begin()+1, Constraint.end()-1); |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1648 | |
| 1649 | // Figure out which register class contains this reg. |
Dan Gohman | 6f0d024 | 2008-02-10 18:45:23 +0000 | [diff] [blame] | 1650 | const TargetRegisterInfo *RI = TM.getRegisterInfo(); |
| 1651 | for (TargetRegisterInfo::regclass_iterator RCI = RI->regclass_begin(), |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1652 | E = RI->regclass_end(); RCI != E; ++RCI) { |
| 1653 | const TargetRegisterClass *RC = *RCI; |
Chris Lattner | b3befd4 | 2006-02-22 23:00:51 +0000 | [diff] [blame] | 1654 | |
| 1655 | // If none of the the value types for this register class are valid, we |
| 1656 | // can't use it. For example, 64-bit reg classes on 32-bit targets. |
| 1657 | bool isLegal = false; |
| 1658 | for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end(); |
| 1659 | I != E; ++I) { |
| 1660 | if (isTypeLegal(*I)) { |
| 1661 | isLegal = true; |
| 1662 | break; |
| 1663 | } |
| 1664 | } |
| 1665 | |
| 1666 | if (!isLegal) continue; |
| 1667 | |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1668 | for (TargetRegisterClass::iterator I = RC->begin(), E = RC->end(); |
| 1669 | I != E; ++I) { |
Bill Wendling | 74ab84c | 2008-02-26 21:11:01 +0000 | [diff] [blame] | 1670 | if (StringsEqualNoCase(RegName, RI->get(*I).AsmName)) |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1671 | return std::make_pair(*I, RC); |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1672 | } |
Chris Lattner | 4ccb070 | 2006-01-26 20:37:03 +0000 | [diff] [blame] | 1673 | } |
Chris Lattner | a55079a | 2006-02-01 01:29:47 +0000 | [diff] [blame] | 1674 | |
Chris Lattner | 1efa40f | 2006-02-22 00:56:39 +0000 | [diff] [blame] | 1675 | return std::pair<unsigned, const TargetRegisterClass*>(0, 0); |
Chris Lattner | 4ccb070 | 2006-01-26 20:37:03 +0000 | [diff] [blame] | 1676 | } |
Evan Cheng | 30b37b5 | 2006-03-13 23:18:16 +0000 | [diff] [blame] | 1677 | |
| 1678 | //===----------------------------------------------------------------------===// |
| 1679 | // Loop Strength Reduction hooks |
| 1680 | //===----------------------------------------------------------------------===// |
| 1681 | |
Chris Lattner | 1436bb6 | 2007-03-30 23:14:50 +0000 | [diff] [blame] | 1682 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 1683 | /// by AM is legal for this target, for a load/store of the specified type. |
| 1684 | bool TargetLowering::isLegalAddressingMode(const AddrMode &AM, |
| 1685 | const Type *Ty) const { |
| 1686 | // The default implementation of this implements a conservative RISCy, r+r and |
| 1687 | // r+i addr mode. |
| 1688 | |
| 1689 | // Allows a sign-extended 16-bit immediate field. |
| 1690 | if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1) |
| 1691 | return false; |
| 1692 | |
| 1693 | // No global is ever allowed as a base. |
| 1694 | if (AM.BaseGV) |
| 1695 | return false; |
| 1696 | |
| 1697 | // Only support r+r, |
| 1698 | switch (AM.Scale) { |
| 1699 | case 0: // "r+i" or just "i", depending on HasBaseReg. |
| 1700 | break; |
| 1701 | case 1: |
| 1702 | if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed. |
| 1703 | return false; |
| 1704 | // Otherwise we have r+r or r+i. |
| 1705 | break; |
| 1706 | case 2: |
| 1707 | if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed. |
| 1708 | return false; |
| 1709 | // Allow 2*r as r+r. |
| 1710 | break; |
| 1711 | } |
| 1712 | |
| 1713 | return true; |
| 1714 | } |
| 1715 | |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1716 | // Magic for divide replacement |
| 1717 | |
| 1718 | struct ms { |
| 1719 | int64_t m; // magic number |
| 1720 | int64_t s; // shift amount |
| 1721 | }; |
| 1722 | |
| 1723 | struct mu { |
| 1724 | uint64_t m; // magic number |
| 1725 | int64_t a; // add indicator |
| 1726 | int64_t s; // shift amount |
| 1727 | }; |
| 1728 | |
| 1729 | /// magic - calculate the magic numbers required to codegen an integer sdiv as |
| 1730 | /// a sequence of multiply and shifts. Requires that the divisor not be 0, 1, |
| 1731 | /// or -1. |
| 1732 | static ms magic32(int32_t d) { |
| 1733 | int32_t p; |
| 1734 | uint32_t ad, anc, delta, q1, r1, q2, r2, t; |
| 1735 | const uint32_t two31 = 0x80000000U; |
| 1736 | struct ms mag; |
| 1737 | |
| 1738 | ad = abs(d); |
| 1739 | t = two31 + ((uint32_t)d >> 31); |
| 1740 | anc = t - 1 - t%ad; // absolute value of nc |
| 1741 | p = 31; // initialize p |
| 1742 | q1 = two31/anc; // initialize q1 = 2p/abs(nc) |
| 1743 | r1 = two31 - q1*anc; // initialize r1 = rem(2p,abs(nc)) |
| 1744 | q2 = two31/ad; // initialize q2 = 2p/abs(d) |
| 1745 | r2 = two31 - q2*ad; // initialize r2 = rem(2p,abs(d)) |
| 1746 | do { |
| 1747 | p = p + 1; |
| 1748 | q1 = 2*q1; // update q1 = 2p/abs(nc) |
| 1749 | r1 = 2*r1; // update r1 = rem(2p/abs(nc)) |
| 1750 | if (r1 >= anc) { // must be unsigned comparison |
| 1751 | q1 = q1 + 1; |
| 1752 | r1 = r1 - anc; |
| 1753 | } |
| 1754 | q2 = 2*q2; // update q2 = 2p/abs(d) |
| 1755 | r2 = 2*r2; // update r2 = rem(2p/abs(d)) |
| 1756 | if (r2 >= ad) { // must be unsigned comparison |
| 1757 | q2 = q2 + 1; |
| 1758 | r2 = r2 - ad; |
| 1759 | } |
| 1760 | delta = ad - r2; |
| 1761 | } while (q1 < delta || (q1 == delta && r1 == 0)); |
| 1762 | |
| 1763 | mag.m = (int32_t)(q2 + 1); // make sure to sign extend |
| 1764 | if (d < 0) mag.m = -mag.m; // resulting magic number |
| 1765 | mag.s = p - 32; // resulting shift |
| 1766 | return mag; |
| 1767 | } |
| 1768 | |
| 1769 | /// magicu - calculate the magic numbers required to codegen an integer udiv as |
| 1770 | /// a sequence of multiply, add and shifts. Requires that the divisor not be 0. |
| 1771 | static mu magicu32(uint32_t d) { |
| 1772 | int32_t p; |
| 1773 | uint32_t nc, delta, q1, r1, q2, r2; |
| 1774 | struct mu magu; |
| 1775 | magu.a = 0; // initialize "add" indicator |
| 1776 | nc = - 1 - (-d)%d; |
| 1777 | p = 31; // initialize p |
| 1778 | q1 = 0x80000000/nc; // initialize q1 = 2p/nc |
| 1779 | r1 = 0x80000000 - q1*nc; // initialize r1 = rem(2p,nc) |
| 1780 | q2 = 0x7FFFFFFF/d; // initialize q2 = (2p-1)/d |
| 1781 | r2 = 0x7FFFFFFF - q2*d; // initialize r2 = rem((2p-1),d) |
| 1782 | do { |
| 1783 | p = p + 1; |
| 1784 | if (r1 >= nc - r1 ) { |
| 1785 | q1 = 2*q1 + 1; // update q1 |
| 1786 | r1 = 2*r1 - nc; // update r1 |
| 1787 | } |
| 1788 | else { |
| 1789 | q1 = 2*q1; // update q1 |
| 1790 | r1 = 2*r1; // update r1 |
| 1791 | } |
| 1792 | if (r2 + 1 >= d - r2) { |
| 1793 | if (q2 >= 0x7FFFFFFF) magu.a = 1; |
| 1794 | q2 = 2*q2 + 1; // update q2 |
| 1795 | r2 = 2*r2 + 1 - d; // update r2 |
| 1796 | } |
| 1797 | else { |
| 1798 | if (q2 >= 0x80000000) magu.a = 1; |
| 1799 | q2 = 2*q2; // update q2 |
| 1800 | r2 = 2*r2 + 1; // update r2 |
| 1801 | } |
| 1802 | delta = d - 1 - r2; |
| 1803 | } while (p < 64 && (q1 < delta || (q1 == delta && r1 == 0))); |
| 1804 | magu.m = q2 + 1; // resulting magic number |
| 1805 | magu.s = p - 32; // resulting shift |
| 1806 | return magu; |
| 1807 | } |
| 1808 | |
| 1809 | /// magic - calculate the magic numbers required to codegen an integer sdiv as |
| 1810 | /// a sequence of multiply and shifts. Requires that the divisor not be 0, 1, |
| 1811 | /// or -1. |
| 1812 | static ms magic64(int64_t d) { |
| 1813 | int64_t p; |
| 1814 | uint64_t ad, anc, delta, q1, r1, q2, r2, t; |
| 1815 | const uint64_t two63 = 9223372036854775808ULL; // 2^63 |
| 1816 | struct ms mag; |
| 1817 | |
| 1818 | ad = d >= 0 ? d : -d; |
| 1819 | t = two63 + ((uint64_t)d >> 63); |
| 1820 | anc = t - 1 - t%ad; // absolute value of nc |
| 1821 | p = 63; // initialize p |
| 1822 | q1 = two63/anc; // initialize q1 = 2p/abs(nc) |
| 1823 | r1 = two63 - q1*anc; // initialize r1 = rem(2p,abs(nc)) |
| 1824 | q2 = two63/ad; // initialize q2 = 2p/abs(d) |
| 1825 | r2 = two63 - q2*ad; // initialize r2 = rem(2p,abs(d)) |
| 1826 | do { |
| 1827 | p = p + 1; |
| 1828 | q1 = 2*q1; // update q1 = 2p/abs(nc) |
| 1829 | r1 = 2*r1; // update r1 = rem(2p/abs(nc)) |
| 1830 | if (r1 >= anc) { // must be unsigned comparison |
| 1831 | q1 = q1 + 1; |
| 1832 | r1 = r1 - anc; |
| 1833 | } |
| 1834 | q2 = 2*q2; // update q2 = 2p/abs(d) |
| 1835 | r2 = 2*r2; // update r2 = rem(2p/abs(d)) |
| 1836 | if (r2 >= ad) { // must be unsigned comparison |
| 1837 | q2 = q2 + 1; |
| 1838 | r2 = r2 - ad; |
| 1839 | } |
| 1840 | delta = ad - r2; |
| 1841 | } while (q1 < delta || (q1 == delta && r1 == 0)); |
| 1842 | |
| 1843 | mag.m = q2 + 1; |
| 1844 | if (d < 0) mag.m = -mag.m; // resulting magic number |
| 1845 | mag.s = p - 64; // resulting shift |
| 1846 | return mag; |
| 1847 | } |
| 1848 | |
| 1849 | /// magicu - calculate the magic numbers required to codegen an integer udiv as |
| 1850 | /// a sequence of multiply, add and shifts. Requires that the divisor not be 0. |
| 1851 | static mu magicu64(uint64_t d) |
| 1852 | { |
| 1853 | int64_t p; |
| 1854 | uint64_t nc, delta, q1, r1, q2, r2; |
| 1855 | struct mu magu; |
| 1856 | magu.a = 0; // initialize "add" indicator |
| 1857 | nc = - 1 - (-d)%d; |
| 1858 | p = 63; // initialize p |
| 1859 | q1 = 0x8000000000000000ull/nc; // initialize q1 = 2p/nc |
| 1860 | r1 = 0x8000000000000000ull - q1*nc; // initialize r1 = rem(2p,nc) |
| 1861 | q2 = 0x7FFFFFFFFFFFFFFFull/d; // initialize q2 = (2p-1)/d |
| 1862 | r2 = 0x7FFFFFFFFFFFFFFFull - q2*d; // initialize r2 = rem((2p-1),d) |
| 1863 | do { |
| 1864 | p = p + 1; |
| 1865 | if (r1 >= nc - r1 ) { |
| 1866 | q1 = 2*q1 + 1; // update q1 |
| 1867 | r1 = 2*r1 - nc; // update r1 |
| 1868 | } |
| 1869 | else { |
| 1870 | q1 = 2*q1; // update q1 |
| 1871 | r1 = 2*r1; // update r1 |
| 1872 | } |
| 1873 | if (r2 + 1 >= d - r2) { |
| 1874 | if (q2 >= 0x7FFFFFFFFFFFFFFFull) magu.a = 1; |
| 1875 | q2 = 2*q2 + 1; // update q2 |
| 1876 | r2 = 2*r2 + 1 - d; // update r2 |
| 1877 | } |
| 1878 | else { |
| 1879 | if (q2 >= 0x8000000000000000ull) magu.a = 1; |
| 1880 | q2 = 2*q2; // update q2 |
| 1881 | r2 = 2*r2 + 1; // update r2 |
| 1882 | } |
| 1883 | delta = d - 1 - r2; |
Andrew Lenharth | 3e34849 | 2006-05-16 17:45:23 +0000 | [diff] [blame] | 1884 | } while (p < 128 && (q1 < delta || (q1 == delta && r1 == 0))); |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1885 | magu.m = q2 + 1; // resulting magic number |
| 1886 | magu.s = p - 64; // resulting shift |
| 1887 | return magu; |
| 1888 | } |
| 1889 | |
| 1890 | /// BuildSDIVSequence - Given an ISD::SDIV node expressing a divide by constant, |
| 1891 | /// return a DAG expression to select that will generate the same value by |
| 1892 | /// multiplying by a magic number. See: |
| 1893 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> |
| 1894 | SDOperand TargetLowering::BuildSDIV(SDNode *N, SelectionDAG &DAG, |
Anton Korobeynikov | bed2946 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 1895 | std::vector<SDNode*>* Created) const { |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1896 | MVT::ValueType VT = N->getValueType(0); |
| 1897 | |
| 1898 | // Check to see if we can do this. |
| 1899 | if (!isTypeLegal(VT) || (VT != MVT::i32 && VT != MVT::i64)) |
| 1900 | return SDOperand(); // BuildSDIV only operates on i32 or i64 |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1901 | |
| 1902 | int64_t d = cast<ConstantSDNode>(N->getOperand(1))->getSignExtended(); |
| 1903 | ms magics = (VT == MVT::i32) ? magic32(d) : magic64(d); |
| 1904 | |
| 1905 | // Multiply the numerator (operand 0) by the magic value |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1906 | SDOperand Q; |
| 1907 | if (isOperationLegal(ISD::MULHS, VT)) |
| 1908 | Q = DAG.getNode(ISD::MULHS, VT, N->getOperand(0), |
| 1909 | DAG.getConstant(magics.m, VT)); |
| 1910 | else if (isOperationLegal(ISD::SMUL_LOHI, VT)) |
| 1911 | Q = SDOperand(DAG.getNode(ISD::SMUL_LOHI, DAG.getVTList(VT, VT), |
| 1912 | N->getOperand(0), |
| 1913 | DAG.getConstant(magics.m, VT)).Val, 1); |
| 1914 | else |
| 1915 | return SDOperand(); // No mulhs or equvialent |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1916 | // If d > 0 and m < 0, add the numerator |
| 1917 | if (d > 0 && magics.m < 0) { |
| 1918 | Q = DAG.getNode(ISD::ADD, VT, Q, N->getOperand(0)); |
| 1919 | if (Created) |
| 1920 | Created->push_back(Q.Val); |
| 1921 | } |
| 1922 | // If d < 0 and m > 0, subtract the numerator. |
| 1923 | if (d < 0 && magics.m > 0) { |
| 1924 | Q = DAG.getNode(ISD::SUB, VT, Q, N->getOperand(0)); |
| 1925 | if (Created) |
| 1926 | Created->push_back(Q.Val); |
| 1927 | } |
| 1928 | // Shift right algebraic if shift value is nonzero |
| 1929 | if (magics.s > 0) { |
| 1930 | Q = DAG.getNode(ISD::SRA, VT, Q, |
| 1931 | DAG.getConstant(magics.s, getShiftAmountTy())); |
| 1932 | if (Created) |
| 1933 | Created->push_back(Q.Val); |
| 1934 | } |
| 1935 | // Extract the sign bit and add it to the quotient |
| 1936 | SDOperand T = |
| 1937 | DAG.getNode(ISD::SRL, VT, Q, DAG.getConstant(MVT::getSizeInBits(VT)-1, |
| 1938 | getShiftAmountTy())); |
| 1939 | if (Created) |
| 1940 | Created->push_back(T.Val); |
| 1941 | return DAG.getNode(ISD::ADD, VT, Q, T); |
| 1942 | } |
| 1943 | |
| 1944 | /// BuildUDIVSequence - Given an ISD::UDIV node expressing a divide by constant, |
| 1945 | /// return a DAG expression to select that will generate the same value by |
| 1946 | /// multiplying by a magic number. See: |
| 1947 | /// <http://the.wall.riscom.net/books/proc/ppc/cwg/code2.html> |
| 1948 | SDOperand TargetLowering::BuildUDIV(SDNode *N, SelectionDAG &DAG, |
Anton Korobeynikov | bed2946 | 2007-04-16 18:10:23 +0000 | [diff] [blame] | 1949 | std::vector<SDNode*>* Created) const { |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1950 | MVT::ValueType VT = N->getValueType(0); |
| 1951 | |
| 1952 | // Check to see if we can do this. |
| 1953 | if (!isTypeLegal(VT) || (VT != MVT::i32 && VT != MVT::i64)) |
| 1954 | return SDOperand(); // BuildUDIV only operates on i32 or i64 |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1955 | |
| 1956 | uint64_t d = cast<ConstantSDNode>(N->getOperand(1))->getValue(); |
| 1957 | mu magics = (VT == MVT::i32) ? magicu32(d) : magicu64(d); |
| 1958 | |
| 1959 | // Multiply the numerator (operand 0) by the magic value |
Dan Gohman | 525178c | 2007-10-08 18:33:35 +0000 | [diff] [blame] | 1960 | SDOperand Q; |
| 1961 | if (isOperationLegal(ISD::MULHU, VT)) |
| 1962 | Q = DAG.getNode(ISD::MULHU, VT, N->getOperand(0), |
| 1963 | DAG.getConstant(magics.m, VT)); |
| 1964 | else if (isOperationLegal(ISD::UMUL_LOHI, VT)) |
| 1965 | Q = SDOperand(DAG.getNode(ISD::UMUL_LOHI, DAG.getVTList(VT, VT), |
| 1966 | N->getOperand(0), |
| 1967 | DAG.getConstant(magics.m, VT)).Val, 1); |
| 1968 | else |
| 1969 | return SDOperand(); // No mulhu or equvialent |
Andrew Lenharth | dae9cbe | 2006-05-16 17:42:15 +0000 | [diff] [blame] | 1970 | if (Created) |
| 1971 | Created->push_back(Q.Val); |
| 1972 | |
| 1973 | if (magics.a == 0) { |
| 1974 | return DAG.getNode(ISD::SRL, VT, Q, |
| 1975 | DAG.getConstant(magics.s, getShiftAmountTy())); |
| 1976 | } else { |
| 1977 | SDOperand NPQ = DAG.getNode(ISD::SUB, VT, N->getOperand(0), Q); |
| 1978 | if (Created) |
| 1979 | Created->push_back(NPQ.Val); |
| 1980 | NPQ = DAG.getNode(ISD::SRL, VT, NPQ, |
| 1981 | DAG.getConstant(1, getShiftAmountTy())); |
| 1982 | if (Created) |
| 1983 | Created->push_back(NPQ.Val); |
| 1984 | NPQ = DAG.getNode(ISD::ADD, VT, NPQ, Q); |
| 1985 | if (Created) |
| 1986 | Created->push_back(NPQ.Val); |
| 1987 | return DAG.getNode(ISD::SRL, VT, NPQ, |
| 1988 | DAG.getConstant(magics.s-1, getShiftAmountTy())); |
| 1989 | } |
| 1990 | } |