Akira Hatanaka | 44ebe00 | 2013-03-14 19:09:52 +0000 | [diff] [blame] | 1 | //===-- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface --*- C++ -*-===// |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Subclass of MipsTargetLowering specialized for mips32/64. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #include "MipsSEISelLowering.h" |
| 14 | #include "MipsRegisterInfo.h" |
| 15 | #include "MipsTargetMachine.h" |
| 16 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| 17 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 18 | #include "llvm/IR/Intrinsics.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 19 | #include "llvm/Support/CommandLine.h" |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 20 | #include "llvm/Support/Debug.h" |
Hans Wennborg | 3e9b1c1 | 2013-10-30 16:10:10 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetInstrInfo.h" |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 26 | #define DEBUG_TYPE "mips-isel" |
| 27 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 28 | static cl::opt<bool> |
| 29 | EnableMipsTailCalls("enable-mips-tail-calls", cl::Hidden, |
| 30 | cl::desc("MIPS: Enable tail calls."), cl::init(false)); |
| 31 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 32 | static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false), |
| 33 | cl::desc("Expand double precision loads and " |
| 34 | "stores to their single precision " |
| 35 | "counterparts")); |
| 36 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 37 | MipsSETargetLowering::MipsSETargetLowering(MipsTargetMachine &TM) |
| 38 | : MipsTargetLowering(TM) { |
| 39 | // Set up the register classes |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 40 | addRegisterClass(MVT::i32, &Mips::GPR32RegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 41 | |
Daniel Sanders | 5e94e68 | 2014-03-27 16:42:17 +0000 | [diff] [blame] | 42 | if (isGP64bit()) |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 43 | addRegisterClass(MVT::i64, &Mips::GPR64RegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 44 | |
Daniel Sanders | 36c671e | 2013-09-27 09:44:59 +0000 | [diff] [blame] | 45 | if (Subtarget->hasDSP() || Subtarget->hasMSA()) { |
| 46 | // Expand all truncating stores and extending loads. |
| 47 | unsigned FirstVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 48 | unsigned LastVT = (unsigned)MVT::LAST_VECTOR_VALUETYPE; |
| 49 | |
| 50 | for (unsigned VT0 = FirstVT; VT0 <= LastVT; ++VT0) { |
| 51 | for (unsigned VT1 = FirstVT; VT1 <= LastVT; ++VT1) |
| 52 | setTruncStoreAction((MVT::SimpleValueType)VT0, |
| 53 | (MVT::SimpleValueType)VT1, Expand); |
| 54 | |
| 55 | setLoadExtAction(ISD::SEXTLOAD, (MVT::SimpleValueType)VT0, Expand); |
| 56 | setLoadExtAction(ISD::ZEXTLOAD, (MVT::SimpleValueType)VT0, Expand); |
| 57 | setLoadExtAction(ISD::EXTLOAD, (MVT::SimpleValueType)VT0, Expand); |
| 58 | } |
| 59 | } |
| 60 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 61 | if (Subtarget->hasDSP()) { |
| 62 | MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8}; |
| 63 | |
| 64 | for (unsigned i = 0; i < array_lengthof(VecTys); ++i) { |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 65 | addRegisterClass(VecTys[i], &Mips::DSPRRegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 66 | |
| 67 | // Expand all builtin opcodes. |
| 68 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 69 | setOperationAction(Opc, VecTys[i], Expand); |
| 70 | |
Akira Hatanaka | 2f08822 | 2013-04-13 00:55:41 +0000 | [diff] [blame] | 71 | setOperationAction(ISD::ADD, VecTys[i], Legal); |
| 72 | setOperationAction(ISD::SUB, VecTys[i], Legal); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 73 | setOperationAction(ISD::LOAD, VecTys[i], Legal); |
| 74 | setOperationAction(ISD::STORE, VecTys[i], Legal); |
| 75 | setOperationAction(ISD::BITCAST, VecTys[i], Legal); |
| 76 | } |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 77 | |
| 78 | setTargetDAGCombine(ISD::SHL); |
| 79 | setTargetDAGCombine(ISD::SRA); |
| 80 | setTargetDAGCombine(ISD::SRL); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 81 | setTargetDAGCombine(ISD::SETCC); |
| 82 | setTargetDAGCombine(ISD::VSELECT); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Akira Hatanaka | 2f08822 | 2013-04-13 00:55:41 +0000 | [diff] [blame] | 85 | if (Subtarget->hasDSPR2()) |
| 86 | setOperationAction(ISD::MUL, MVT::v2i16, Legal); |
| 87 | |
Jack Carter | 3a2c2d4 | 2013-08-13 20:54:07 +0000 | [diff] [blame] | 88 | if (Subtarget->hasMSA()) { |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 89 | addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass); |
| 90 | addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass); |
| 91 | addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass); |
| 92 | addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass); |
| 93 | addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass); |
| 94 | addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass); |
| 95 | addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 96 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 97 | setTargetDAGCombine(ISD::AND); |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 98 | setTargetDAGCombine(ISD::OR); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 99 | setTargetDAGCombine(ISD::SRA); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 100 | setTargetDAGCombine(ISD::VSELECT); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 101 | setTargetDAGCombine(ISD::XOR); |
Jack Carter | 3a2c2d4 | 2013-08-13 20:54:07 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Reed Kotler | c03807a | 2013-08-30 19:40:56 +0000 | [diff] [blame] | 104 | if (!Subtarget->mipsSEUsesSoftFloat()) { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 105 | addRegisterClass(MVT::f32, &Mips::FGR32RegClass); |
| 106 | |
| 107 | // When dealing with single precision only, use libcalls |
| 108 | if (!Subtarget->isSingleFloat()) { |
Akira Hatanaka | bfb6624 | 2013-08-20 23:38:40 +0000 | [diff] [blame] | 109 | if (Subtarget->isFP64bit()) |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 110 | addRegisterClass(MVT::f64, &Mips::FGR64RegClass); |
| 111 | else |
| 112 | addRegisterClass(MVT::f64, &Mips::AFGR64RegClass); |
| 113 | } |
| 114 | } |
| 115 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 116 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom); |
| 117 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom); |
| 118 | setOperationAction(ISD::MULHS, MVT::i32, Custom); |
| 119 | setOperationAction(ISD::MULHU, MVT::i32, Custom); |
| 120 | |
Kai Nacke | 93fe5e8 | 2014-03-20 11:51:58 +0000 | [diff] [blame] | 121 | if (Subtarget->hasCnMips()) |
| 122 | setOperationAction(ISD::MUL, MVT::i64, Legal); |
Daniel Sanders | 3d84935 | 2014-04-14 15:44:42 +0000 | [diff] [blame] | 123 | else if (isGP64bit()) |
Kai Nacke | 93fe5e8 | 2014-03-20 11:51:58 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::MUL, MVT::i64, Custom); |
| 125 | |
Daniel Sanders | 3d84935 | 2014-04-14 15:44:42 +0000 | [diff] [blame] | 126 | if (isGP64bit()) { |
Akira Hatanaka | 4f1130e | 2013-04-11 19:29:26 +0000 | [diff] [blame] | 127 | setOperationAction(ISD::MULHS, MVT::i64, Custom); |
| 128 | setOperationAction(ISD::MULHU, MVT::i64, Custom); |
Akira Hatanaka | 4f1130e | 2013-04-11 19:29:26 +0000 | [diff] [blame] | 129 | } |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 130 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 131 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom); |
| 132 | setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom); |
| 133 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 134 | setOperationAction(ISD::SDIVREM, MVT::i32, Custom); |
| 135 | setOperationAction(ISD::UDIVREM, MVT::i32, Custom); |
| 136 | setOperationAction(ISD::SDIVREM, MVT::i64, Custom); |
| 137 | setOperationAction(ISD::UDIVREM, MVT::i64, Custom); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 138 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| 139 | setOperationAction(ISD::LOAD, MVT::i32, Custom); |
| 140 | setOperationAction(ISD::STORE, MVT::i32, Custom); |
| 141 | |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 142 | setTargetDAGCombine(ISD::ADDE); |
| 143 | setTargetDAGCombine(ISD::SUBE); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 144 | setTargetDAGCombine(ISD::MUL); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 145 | |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 146 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 147 | setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom); |
| 148 | setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); |
| 149 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 150 | if (NoDPLoadStore) { |
| 151 | setOperationAction(ISD::LOAD, MVT::f64, Custom); |
| 152 | setOperationAction(ISD::STORE, MVT::f64, Custom); |
| 153 | } |
| 154 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 155 | computeRegisterProperties(); |
| 156 | } |
| 157 | |
| 158 | const MipsTargetLowering * |
| 159 | llvm::createMipsSETargetLowering(MipsTargetMachine &TM) { |
| 160 | return new MipsSETargetLowering(TM); |
| 161 | } |
| 162 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 163 | // Enable MSA support for the given integer type and Register class. |
Daniel Sanders | 3c9a0ad | 2013-08-23 10:10:13 +0000 | [diff] [blame] | 164 | void MipsSETargetLowering:: |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 165 | addMSAIntType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { |
| 166 | addRegisterClass(Ty, RC); |
| 167 | |
| 168 | // Expand all builtin opcodes. |
| 169 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 170 | setOperationAction(Opc, Ty, Expand); |
| 171 | |
| 172 | setOperationAction(ISD::BITCAST, Ty, Legal); |
| 173 | setOperationAction(ISD::LOAD, Ty, Legal); |
| 174 | setOperationAction(ISD::STORE, Ty, Legal); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 175 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Custom); |
| 176 | setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 177 | setOperationAction(ISD::BUILD_VECTOR, Ty, Custom); |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 178 | |
Daniel Sanders | fa5ab1c | 2013-09-11 10:28:16 +0000 | [diff] [blame] | 179 | setOperationAction(ISD::ADD, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 180 | setOperationAction(ISD::AND, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 181 | setOperationAction(ISD::CTLZ, Ty, Legal); |
Daniel Sanders | 766cb69 | 2013-09-23 13:40:21 +0000 | [diff] [blame] | 182 | setOperationAction(ISD::CTPOP, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 183 | setOperationAction(ISD::MUL, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 184 | setOperationAction(ISD::OR, Ty, Legal); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 185 | setOperationAction(ISD::SDIV, Ty, Legal); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 186 | setOperationAction(ISD::SREM, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 187 | setOperationAction(ISD::SHL, Ty, Legal); |
| 188 | setOperationAction(ISD::SRA, Ty, Legal); |
| 189 | setOperationAction(ISD::SRL, Ty, Legal); |
| 190 | setOperationAction(ISD::SUB, Ty, Legal); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 191 | setOperationAction(ISD::UDIV, Ty, Legal); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 192 | setOperationAction(ISD::UREM, Ty, Legal); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 193 | setOperationAction(ISD::VECTOR_SHUFFLE, Ty, Custom); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 194 | setOperationAction(ISD::VSELECT, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 195 | setOperationAction(ISD::XOR, Ty, Legal); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 196 | |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 197 | if (Ty == MVT::v4i32 || Ty == MVT::v2i64) { |
| 198 | setOperationAction(ISD::FP_TO_SINT, Ty, Legal); |
| 199 | setOperationAction(ISD::FP_TO_UINT, Ty, Legal); |
| 200 | setOperationAction(ISD::SINT_TO_FP, Ty, Legal); |
| 201 | setOperationAction(ISD::UINT_TO_FP, Ty, Legal); |
| 202 | } |
| 203 | |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 204 | setOperationAction(ISD::SETCC, Ty, Legal); |
| 205 | setCondCodeAction(ISD::SETNE, Ty, Expand); |
| 206 | setCondCodeAction(ISD::SETGE, Ty, Expand); |
| 207 | setCondCodeAction(ISD::SETGT, Ty, Expand); |
| 208 | setCondCodeAction(ISD::SETUGE, Ty, Expand); |
| 209 | setCondCodeAction(ISD::SETUGT, Ty, Expand); |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 212 | // Enable MSA support for the given floating-point type and Register class. |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 213 | void MipsSETargetLowering:: |
| 214 | addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { |
Daniel Sanders | 3c9a0ad | 2013-08-23 10:10:13 +0000 | [diff] [blame] | 215 | addRegisterClass(Ty, RC); |
Jack Carter | babdcc8 | 2013-08-15 12:24:57 +0000 | [diff] [blame] | 216 | |
| 217 | // Expand all builtin opcodes. |
| 218 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 219 | setOperationAction(Opc, Ty, Expand); |
| 220 | |
| 221 | setOperationAction(ISD::LOAD, Ty, Legal); |
| 222 | setOperationAction(ISD::STORE, Ty, Legal); |
| 223 | setOperationAction(ISD::BITCAST, Ty, Legal); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 224 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 225 | setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 226 | setOperationAction(ISD::BUILD_VECTOR, Ty, Custom); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 227 | |
| 228 | if (Ty != MVT::v8f16) { |
Daniel Sanders | 4f3ff1b | 2013-09-24 13:02:08 +0000 | [diff] [blame] | 229 | setOperationAction(ISD::FABS, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 230 | setOperationAction(ISD::FADD, Ty, Legal); |
| 231 | setOperationAction(ISD::FDIV, Ty, Legal); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 232 | setOperationAction(ISD::FEXP2, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 233 | setOperationAction(ISD::FLOG2, Ty, Legal); |
Daniel Sanders | d7103f3 | 2013-10-11 10:14:25 +0000 | [diff] [blame] | 234 | setOperationAction(ISD::FMA, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 235 | setOperationAction(ISD::FMUL, Ty, Legal); |
| 236 | setOperationAction(ISD::FRINT, Ty, Legal); |
| 237 | setOperationAction(ISD::FSQRT, Ty, Legal); |
| 238 | setOperationAction(ISD::FSUB, Ty, Legal); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 239 | setOperationAction(ISD::VSELECT, Ty, Legal); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 240 | |
| 241 | setOperationAction(ISD::SETCC, Ty, Legal); |
| 242 | setCondCodeAction(ISD::SETOGE, Ty, Expand); |
| 243 | setCondCodeAction(ISD::SETOGT, Ty, Expand); |
| 244 | setCondCodeAction(ISD::SETUGE, Ty, Expand); |
| 245 | setCondCodeAction(ISD::SETUGT, Ty, Expand); |
| 246 | setCondCodeAction(ISD::SETGE, Ty, Expand); |
| 247 | setCondCodeAction(ISD::SETGT, Ty, Expand); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 248 | } |
Jack Carter | babdcc8 | 2013-08-15 12:24:57 +0000 | [diff] [blame] | 249 | } |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 250 | |
| 251 | bool |
Matt Arsenault | 25793a3 | 2014-02-05 23:15:53 +0000 | [diff] [blame] | 252 | MipsSETargetLowering::allowsUnalignedMemoryAccesses(EVT VT, |
| 253 | unsigned, |
| 254 | bool *Fast) const { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 255 | MVT::SimpleValueType SVT = VT.getSimpleVT().SimpleTy; |
| 256 | |
| 257 | switch (SVT) { |
| 258 | case MVT::i64: |
| 259 | case MVT::i32: |
| 260 | if (Fast) |
| 261 | *Fast = true; |
| 262 | return true; |
| 263 | default: |
| 264 | return false; |
| 265 | } |
| 266 | } |
| 267 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 268 | SDValue MipsSETargetLowering::LowerOperation(SDValue Op, |
| 269 | SelectionDAG &DAG) const { |
| 270 | switch(Op.getOpcode()) { |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 271 | case ISD::LOAD: return lowerLOAD(Op, DAG); |
| 272 | case ISD::STORE: return lowerSTORE(Op, DAG); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 273 | case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG); |
| 274 | case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG); |
| 275 | case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG); |
| 276 | case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG); |
| 277 | case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG); |
| 278 | case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG); |
Akira Hatanaka | d8fb032 | 2013-04-22 20:13:37 +0000 | [diff] [blame] | 279 | case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true, |
| 280 | DAG); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 281 | case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG); |
| 282 | case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 283 | case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 284 | case ISD::EXTRACT_VECTOR_ELT: return lowerEXTRACT_VECTOR_ELT(Op, DAG); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 285 | case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 286 | case ISD::VECTOR_SHUFFLE: return lowerVECTOR_SHUFFLE(Op, DAG); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | return MipsTargetLowering::LowerOperation(Op, DAG); |
| 290 | } |
| 291 | |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 292 | // selectMADD - |
| 293 | // Transforms a subgraph in CurDAG if the following pattern is found: |
| 294 | // (addc multLo, Lo0), (adde multHi, Hi0), |
| 295 | // where, |
| 296 | // multHi/Lo: product of multiplication |
| 297 | // Lo0: initial value of Lo register |
| 298 | // Hi0: initial value of Hi register |
| 299 | // Return true if pattern matching was successful. |
| 300 | static bool selectMADD(SDNode *ADDENode, SelectionDAG *CurDAG) { |
| 301 | // ADDENode's second operand must be a flag output of an ADDC node in order |
| 302 | // for the matching to be successful. |
| 303 | SDNode *ADDCNode = ADDENode->getOperand(2).getNode(); |
| 304 | |
| 305 | if (ADDCNode->getOpcode() != ISD::ADDC) |
| 306 | return false; |
| 307 | |
| 308 | SDValue MultHi = ADDENode->getOperand(0); |
| 309 | SDValue MultLo = ADDCNode->getOperand(0); |
| 310 | SDNode *MultNode = MultHi.getNode(); |
| 311 | unsigned MultOpc = MultHi.getOpcode(); |
| 312 | |
| 313 | // MultHi and MultLo must be generated by the same node, |
| 314 | if (MultLo.getNode() != MultNode) |
| 315 | return false; |
| 316 | |
| 317 | // and it must be a multiplication. |
| 318 | if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) |
| 319 | return false; |
| 320 | |
| 321 | // MultLo amd MultHi must be the first and second output of MultNode |
| 322 | // respectively. |
| 323 | if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) |
| 324 | return false; |
| 325 | |
| 326 | // Transform this to a MADD only if ADDENode and ADDCNode are the only users |
| 327 | // of the values of MultNode, in which case MultNode will be removed in later |
| 328 | // phases. |
| 329 | // If there exist users other than ADDENode or ADDCNode, this function returns |
| 330 | // here, which will result in MultNode being mapped to a single MULT |
| 331 | // instruction node rather than a pair of MULT and MADD instructions being |
| 332 | // produced. |
| 333 | if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) |
| 334 | return false; |
| 335 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 336 | SDLoc DL(ADDENode); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 337 | |
| 338 | // Initialize accumulator. |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 339 | SDValue ACCIn = CurDAG->getNode(MipsISD::MTLOHI, DL, MVT::Untyped, |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 340 | ADDCNode->getOperand(1), |
| 341 | ADDENode->getOperand(1)); |
| 342 | |
| 343 | // create MipsMAdd(u) node |
| 344 | MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MAddu : MipsISD::MAdd; |
| 345 | |
| 346 | SDValue MAdd = CurDAG->getNode(MultOpc, DL, MVT::Untyped, |
| 347 | MultNode->getOperand(0),// Factor 0 |
| 348 | MultNode->getOperand(1),// Factor 1 |
| 349 | ACCIn); |
| 350 | |
| 351 | // replace uses of adde and addc here |
| 352 | if (!SDValue(ADDCNode, 0).use_empty()) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 353 | SDValue LoOut = CurDAG->getNode(MipsISD::MFLO, DL, MVT::i32, MAdd); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 354 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDCNode, 0), LoOut); |
| 355 | } |
| 356 | if (!SDValue(ADDENode, 0).use_empty()) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 357 | SDValue HiOut = CurDAG->getNode(MipsISD::MFHI, DL, MVT::i32, MAdd); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 358 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(ADDENode, 0), HiOut); |
| 359 | } |
| 360 | |
| 361 | return true; |
| 362 | } |
| 363 | |
| 364 | // selectMSUB - |
| 365 | // Transforms a subgraph in CurDAG if the following pattern is found: |
| 366 | // (addc Lo0, multLo), (sube Hi0, multHi), |
| 367 | // where, |
| 368 | // multHi/Lo: product of multiplication |
| 369 | // Lo0: initial value of Lo register |
| 370 | // Hi0: initial value of Hi register |
| 371 | // Return true if pattern matching was successful. |
| 372 | static bool selectMSUB(SDNode *SUBENode, SelectionDAG *CurDAG) { |
| 373 | // SUBENode's second operand must be a flag output of an SUBC node in order |
| 374 | // for the matching to be successful. |
| 375 | SDNode *SUBCNode = SUBENode->getOperand(2).getNode(); |
| 376 | |
| 377 | if (SUBCNode->getOpcode() != ISD::SUBC) |
| 378 | return false; |
| 379 | |
| 380 | SDValue MultHi = SUBENode->getOperand(1); |
| 381 | SDValue MultLo = SUBCNode->getOperand(1); |
| 382 | SDNode *MultNode = MultHi.getNode(); |
| 383 | unsigned MultOpc = MultHi.getOpcode(); |
| 384 | |
| 385 | // MultHi and MultLo must be generated by the same node, |
| 386 | if (MultLo.getNode() != MultNode) |
| 387 | return false; |
| 388 | |
| 389 | // and it must be a multiplication. |
| 390 | if (MultOpc != ISD::SMUL_LOHI && MultOpc != ISD::UMUL_LOHI) |
| 391 | return false; |
| 392 | |
| 393 | // MultLo amd MultHi must be the first and second output of MultNode |
| 394 | // respectively. |
| 395 | if (MultHi.getResNo() != 1 || MultLo.getResNo() != 0) |
| 396 | return false; |
| 397 | |
| 398 | // Transform this to a MSUB only if SUBENode and SUBCNode are the only users |
| 399 | // of the values of MultNode, in which case MultNode will be removed in later |
| 400 | // phases. |
| 401 | // If there exist users other than SUBENode or SUBCNode, this function returns |
| 402 | // here, which will result in MultNode being mapped to a single MULT |
| 403 | // instruction node rather than a pair of MULT and MSUB instructions being |
| 404 | // produced. |
| 405 | if (!MultHi.hasOneUse() || !MultLo.hasOneUse()) |
| 406 | return false; |
| 407 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 408 | SDLoc DL(SUBENode); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 409 | |
| 410 | // Initialize accumulator. |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 411 | SDValue ACCIn = CurDAG->getNode(MipsISD::MTLOHI, DL, MVT::Untyped, |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 412 | SUBCNode->getOperand(0), |
| 413 | SUBENode->getOperand(0)); |
| 414 | |
| 415 | // create MipsSub(u) node |
| 416 | MultOpc = MultOpc == ISD::UMUL_LOHI ? MipsISD::MSubu : MipsISD::MSub; |
| 417 | |
| 418 | SDValue MSub = CurDAG->getNode(MultOpc, DL, MVT::Glue, |
| 419 | MultNode->getOperand(0),// Factor 0 |
| 420 | MultNode->getOperand(1),// Factor 1 |
| 421 | ACCIn); |
| 422 | |
| 423 | // replace uses of sube and subc here |
| 424 | if (!SDValue(SUBCNode, 0).use_empty()) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 425 | SDValue LoOut = CurDAG->getNode(MipsISD::MFLO, DL, MVT::i32, MSub); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 426 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBCNode, 0), LoOut); |
| 427 | } |
| 428 | if (!SDValue(SUBENode, 0).use_empty()) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 429 | SDValue HiOut = CurDAG->getNode(MipsISD::MFHI, DL, MVT::i32, MSub); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 430 | CurDAG->ReplaceAllUsesOfValueWith(SDValue(SUBENode, 0), HiOut); |
| 431 | } |
| 432 | |
| 433 | return true; |
| 434 | } |
| 435 | |
| 436 | static SDValue performADDECombine(SDNode *N, SelectionDAG &DAG, |
| 437 | TargetLowering::DAGCombinerInfo &DCI, |
| 438 | const MipsSubtarget *Subtarget) { |
| 439 | if (DCI.isBeforeLegalize()) |
| 440 | return SDValue(); |
| 441 | |
| 442 | if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 && |
| 443 | selectMADD(N, &DAG)) |
| 444 | return SDValue(N, 0); |
| 445 | |
| 446 | return SDValue(); |
| 447 | } |
| 448 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 449 | // Fold zero extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT |
| 450 | // |
| 451 | // Performs the following transformations: |
| 452 | // - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to zero extension if its |
| 453 | // sign/zero-extension is completely overwritten by the new one performed by |
| 454 | // the ISD::AND. |
| 455 | // - Removes redundant zero extensions performed by an ISD::AND. |
| 456 | static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG, |
| 457 | TargetLowering::DAGCombinerInfo &DCI, |
| 458 | const MipsSubtarget *Subtarget) { |
| 459 | if (!Subtarget->hasMSA()) |
| 460 | return SDValue(); |
| 461 | |
| 462 | SDValue Op0 = N->getOperand(0); |
| 463 | SDValue Op1 = N->getOperand(1); |
| 464 | unsigned Op0Opcode = Op0->getOpcode(); |
| 465 | |
| 466 | // (and (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d) |
| 467 | // where $d + 1 == 2^n and n == 32 |
| 468 | // or $d + 1 == 2^n and n <= 32 and ZExt |
| 469 | // -> (MipsVExtractZExt $a, $b, $c) |
| 470 | if (Op0Opcode == MipsISD::VEXTRACT_SEXT_ELT || |
| 471 | Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT) { |
| 472 | ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(Op1); |
| 473 | |
| 474 | if (!Mask) |
| 475 | return SDValue(); |
| 476 | |
| 477 | int32_t Log2IfPositive = (Mask->getAPIntValue() + 1).exactLogBase2(); |
| 478 | |
| 479 | if (Log2IfPositive <= 0) |
| 480 | return SDValue(); // Mask+1 is not a power of 2 |
| 481 | |
| 482 | SDValue Op0Op2 = Op0->getOperand(2); |
| 483 | EVT ExtendTy = cast<VTSDNode>(Op0Op2)->getVT(); |
| 484 | unsigned ExtendTySize = ExtendTy.getSizeInBits(); |
| 485 | unsigned Log2 = Log2IfPositive; |
| 486 | |
| 487 | if ((Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT && Log2 >= ExtendTySize) || |
| 488 | Log2 == ExtendTySize) { |
| 489 | SDValue Ops[] = { Op0->getOperand(0), Op0->getOperand(1), Op0Op2 }; |
| 490 | DAG.MorphNodeTo(Op0.getNode(), MipsISD::VEXTRACT_ZEXT_ELT, |
| 491 | Op0->getVTList(), Ops, Op0->getNumOperands()); |
| 492 | return Op0; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | return SDValue(); |
| 497 | } |
| 498 | |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 499 | // Determine if the specified node is a constant vector splat. |
| 500 | // |
| 501 | // Returns true and sets Imm if: |
| 502 | // * N is a ISD::BUILD_VECTOR representing a constant splat |
| 503 | // |
| 504 | // This function is quite similar to MipsSEDAGToDAGISel::selectVSplat. The |
| 505 | // differences are that it assumes the MSA has already been checked and the |
| 506 | // arbitrary requirement for a maximum of 32-bit integers isn't applied (and |
| 507 | // must not be in order for binsri.d to be selectable). |
| 508 | static bool isVSplat(SDValue N, APInt &Imm, bool IsLittleEndian) { |
| 509 | BuildVectorSDNode *Node = dyn_cast<BuildVectorSDNode>(N.getNode()); |
| 510 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 511 | if (!Node) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 512 | return false; |
| 513 | |
| 514 | APInt SplatValue, SplatUndef; |
| 515 | unsigned SplatBitSize; |
| 516 | bool HasAnyUndefs; |
| 517 | |
| 518 | if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, |
| 519 | 8, !IsLittleEndian)) |
| 520 | return false; |
| 521 | |
| 522 | Imm = SplatValue; |
| 523 | |
| 524 | return true; |
| 525 | } |
| 526 | |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 527 | // Test whether the given node is an all-ones build_vector. |
| 528 | static bool isVectorAllOnes(SDValue N) { |
| 529 | // Look through bitcasts. Endianness doesn't matter because we are looking |
| 530 | // for an all-ones value. |
| 531 | if (N->getOpcode() == ISD::BITCAST) |
| 532 | N = N->getOperand(0); |
| 533 | |
| 534 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N); |
| 535 | |
| 536 | if (!BVN) |
| 537 | return false; |
| 538 | |
| 539 | APInt SplatValue, SplatUndef; |
| 540 | unsigned SplatBitSize; |
| 541 | bool HasAnyUndefs; |
| 542 | |
| 543 | // Endianness doesn't matter in this context because we are looking for |
| 544 | // an all-ones value. |
| 545 | if (BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs)) |
| 546 | return SplatValue.isAllOnesValue(); |
| 547 | |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | // Test whether N is the bitwise inverse of OfNode. |
| 552 | static bool isBitwiseInverse(SDValue N, SDValue OfNode) { |
| 553 | if (N->getOpcode() != ISD::XOR) |
| 554 | return false; |
| 555 | |
| 556 | if (isVectorAllOnes(N->getOperand(0))) |
| 557 | return N->getOperand(1) == OfNode; |
| 558 | |
| 559 | if (isVectorAllOnes(N->getOperand(1))) |
| 560 | return N->getOperand(0) == OfNode; |
| 561 | |
| 562 | return false; |
| 563 | } |
| 564 | |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 565 | // Perform combines where ISD::OR is the root node. |
| 566 | // |
| 567 | // Performs the following transformations: |
| 568 | // - (or (and $a, $mask), (and $b, $inv_mask)) => (vselect $mask, $a, $b) |
| 569 | // where $inv_mask is the bitwise inverse of $mask and the 'or' has a 128-bit |
| 570 | // vector type. |
| 571 | static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, |
| 572 | TargetLowering::DAGCombinerInfo &DCI, |
| 573 | const MipsSubtarget *Subtarget) { |
| 574 | if (!Subtarget->hasMSA()) |
| 575 | return SDValue(); |
| 576 | |
| 577 | EVT Ty = N->getValueType(0); |
| 578 | |
| 579 | if (!Ty.is128BitVector()) |
| 580 | return SDValue(); |
| 581 | |
| 582 | SDValue Op0 = N->getOperand(0); |
| 583 | SDValue Op1 = N->getOperand(1); |
| 584 | |
| 585 | if (Op0->getOpcode() == ISD::AND && Op1->getOpcode() == ISD::AND) { |
| 586 | SDValue Op0Op0 = Op0->getOperand(0); |
| 587 | SDValue Op0Op1 = Op0->getOperand(1); |
| 588 | SDValue Op1Op0 = Op1->getOperand(0); |
| 589 | SDValue Op1Op1 = Op1->getOperand(1); |
| 590 | bool IsLittleEndian = !Subtarget->isLittle(); |
| 591 | |
| 592 | SDValue IfSet, IfClr, Cond; |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 593 | bool IsConstantMask = false; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 594 | APInt Mask, InvMask; |
| 595 | |
| 596 | // If Op0Op0 is an appropriate mask, try to find it's inverse in either |
| 597 | // Op1Op0, or Op1Op1. Keep track of the Cond, IfSet, and IfClr nodes, while |
| 598 | // looking. |
| 599 | // IfClr will be set if we find a valid match. |
| 600 | if (isVSplat(Op0Op0, Mask, IsLittleEndian)) { |
| 601 | Cond = Op0Op0; |
| 602 | IfSet = Op0Op1; |
| 603 | |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 604 | if (isVSplat(Op1Op0, InvMask, IsLittleEndian) && |
| 605 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 606 | IfClr = Op1Op1; |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 607 | else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) && |
| 608 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 609 | IfClr = Op1Op0; |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 610 | |
| 611 | IsConstantMask = true; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | // If IfClr is not yet set, and Op0Op1 is an appropriate mask, try the same |
| 615 | // thing again using this mask. |
| 616 | // IfClr will be set if we find a valid match. |
| 617 | if (!IfClr.getNode() && isVSplat(Op0Op1, Mask, IsLittleEndian)) { |
| 618 | Cond = Op0Op1; |
| 619 | IfSet = Op0Op0; |
| 620 | |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 621 | if (isVSplat(Op1Op0, InvMask, IsLittleEndian) && |
| 622 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 623 | IfClr = Op1Op1; |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 624 | else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) && |
| 625 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 626 | IfClr = Op1Op0; |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 627 | |
| 628 | IsConstantMask = true; |
| 629 | } |
| 630 | |
| 631 | // If IfClr is not yet set, try looking for a non-constant match. |
| 632 | // IfClr will be set if we find a valid match amongst the eight |
| 633 | // possibilities. |
| 634 | if (!IfClr.getNode()) { |
| 635 | if (isBitwiseInverse(Op0Op0, Op1Op0)) { |
| 636 | Cond = Op1Op0; |
| 637 | IfSet = Op1Op1; |
| 638 | IfClr = Op0Op1; |
| 639 | } else if (isBitwiseInverse(Op0Op1, Op1Op0)) { |
| 640 | Cond = Op1Op0; |
| 641 | IfSet = Op1Op1; |
| 642 | IfClr = Op0Op0; |
| 643 | } else if (isBitwiseInverse(Op0Op0, Op1Op1)) { |
| 644 | Cond = Op1Op1; |
| 645 | IfSet = Op1Op0; |
| 646 | IfClr = Op0Op1; |
| 647 | } else if (isBitwiseInverse(Op0Op1, Op1Op1)) { |
| 648 | Cond = Op1Op1; |
| 649 | IfSet = Op1Op0; |
| 650 | IfClr = Op0Op0; |
| 651 | } else if (isBitwiseInverse(Op1Op0, Op0Op0)) { |
| 652 | Cond = Op0Op0; |
| 653 | IfSet = Op0Op1; |
| 654 | IfClr = Op1Op1; |
| 655 | } else if (isBitwiseInverse(Op1Op1, Op0Op0)) { |
| 656 | Cond = Op0Op0; |
| 657 | IfSet = Op0Op1; |
| 658 | IfClr = Op1Op0; |
| 659 | } else if (isBitwiseInverse(Op1Op0, Op0Op1)) { |
| 660 | Cond = Op0Op1; |
| 661 | IfSet = Op0Op0; |
| 662 | IfClr = Op1Op1; |
| 663 | } else if (isBitwiseInverse(Op1Op1, Op0Op1)) { |
| 664 | Cond = Op0Op1; |
| 665 | IfSet = Op0Op0; |
| 666 | IfClr = Op1Op0; |
| 667 | } |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | // At this point, IfClr will be set if we have a valid match. |
| 671 | if (!IfClr.getNode()) |
| 672 | return SDValue(); |
| 673 | |
| 674 | assert(Cond.getNode() && IfSet.getNode()); |
| 675 | |
| 676 | // Fold degenerate cases. |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 677 | if (IsConstantMask) { |
| 678 | if (Mask.isAllOnesValue()) |
| 679 | return IfSet; |
| 680 | else if (Mask == 0) |
| 681 | return IfClr; |
| 682 | } |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 683 | |
| 684 | // Transform the DAG into an equivalent VSELECT. |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 685 | return DAG.getNode(ISD::VSELECT, SDLoc(N), Ty, Cond, IfSet, IfClr); |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 686 | } |
| 687 | |
| 688 | return SDValue(); |
| 689 | } |
| 690 | |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 691 | static SDValue performSUBECombine(SDNode *N, SelectionDAG &DAG, |
| 692 | TargetLowering::DAGCombinerInfo &DCI, |
| 693 | const MipsSubtarget *Subtarget) { |
| 694 | if (DCI.isBeforeLegalize()) |
| 695 | return SDValue(); |
| 696 | |
| 697 | if (Subtarget->hasMips32() && N->getValueType(0) == MVT::i32 && |
| 698 | selectMSUB(N, &DAG)) |
| 699 | return SDValue(N, 0); |
| 700 | |
| 701 | return SDValue(); |
| 702 | } |
| 703 | |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 704 | static SDValue genConstMult(SDValue X, uint64_t C, SDLoc DL, EVT VT, |
| 705 | EVT ShiftTy, SelectionDAG &DAG) { |
| 706 | // Clear the upper (64 - VT.sizeInBits) bits. |
| 707 | C &= ((uint64_t)-1) >> (64 - VT.getSizeInBits()); |
| 708 | |
| 709 | // Return 0. |
| 710 | if (C == 0) |
| 711 | return DAG.getConstant(0, VT); |
| 712 | |
| 713 | // Return x. |
| 714 | if (C == 1) |
| 715 | return X; |
| 716 | |
| 717 | // If c is power of 2, return (shl x, log2(c)). |
| 718 | if (isPowerOf2_64(C)) |
| 719 | return DAG.getNode(ISD::SHL, DL, VT, X, |
| 720 | DAG.getConstant(Log2_64(C), ShiftTy)); |
| 721 | |
| 722 | unsigned Log2Ceil = Log2_64_Ceil(C); |
| 723 | uint64_t Floor = 1LL << Log2_64(C); |
| 724 | uint64_t Ceil = Log2Ceil == 64 ? 0LL : 1LL << Log2Ceil; |
| 725 | |
| 726 | // If |c - floor_c| <= |c - ceil_c|, |
| 727 | // where floor_c = pow(2, floor(log2(c))) and ceil_c = pow(2, ceil(log2(c))), |
| 728 | // return (add constMult(x, floor_c), constMult(x, c - floor_c)). |
| 729 | if (C - Floor <= Ceil - C) { |
| 730 | SDValue Op0 = genConstMult(X, Floor, DL, VT, ShiftTy, DAG); |
| 731 | SDValue Op1 = genConstMult(X, C - Floor, DL, VT, ShiftTy, DAG); |
| 732 | return DAG.getNode(ISD::ADD, DL, VT, Op0, Op1); |
| 733 | } |
| 734 | |
| 735 | // If |c - floor_c| > |c - ceil_c|, |
| 736 | // return (sub constMult(x, ceil_c), constMult(x, ceil_c - c)). |
| 737 | SDValue Op0 = genConstMult(X, Ceil, DL, VT, ShiftTy, DAG); |
| 738 | SDValue Op1 = genConstMult(X, Ceil - C, DL, VT, ShiftTy, DAG); |
| 739 | return DAG.getNode(ISD::SUB, DL, VT, Op0, Op1); |
| 740 | } |
| 741 | |
| 742 | static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG, |
| 743 | const TargetLowering::DAGCombinerInfo &DCI, |
| 744 | const MipsSETargetLowering *TL) { |
| 745 | EVT VT = N->getValueType(0); |
| 746 | |
| 747 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) |
| 748 | if (!VT.isVector()) |
| 749 | return genConstMult(N->getOperand(0), C->getZExtValue(), SDLoc(N), |
| 750 | VT, TL->getScalarShiftAmountTy(VT), DAG); |
| 751 | |
| 752 | return SDValue(N, 0); |
| 753 | } |
| 754 | |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 755 | static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty, |
| 756 | SelectionDAG &DAG, |
| 757 | const MipsSubtarget *Subtarget) { |
| 758 | // See if this is a vector splat immediate node. |
| 759 | APInt SplatValue, SplatUndef; |
| 760 | unsigned SplatBitSize; |
| 761 | bool HasAnyUndefs; |
| 762 | unsigned EltSize = Ty.getVectorElementType().getSizeInBits(); |
| 763 | BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 764 | |
Daniel Sanders | 6e664bc | 2013-11-21 11:40:14 +0000 | [diff] [blame] | 765 | if (!Subtarget->hasDSP()) |
| 766 | return SDValue(); |
| 767 | |
Akira Hatanaka | 0d6964c | 2013-04-22 19:58:23 +0000 | [diff] [blame] | 768 | if (!BV || |
Akira Hatanaka | d8fb032 | 2013-04-22 20:13:37 +0000 | [diff] [blame] | 769 | !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, |
Akira Hatanaka | e9d0b31 | 2013-04-23 18:09:42 +0000 | [diff] [blame] | 770 | EltSize, !Subtarget->isLittle()) || |
Akira Hatanaka | 0d6964c | 2013-04-22 19:58:23 +0000 | [diff] [blame] | 771 | (SplatBitSize != EltSize) || |
Akira Hatanaka | e9d0b31 | 2013-04-23 18:09:42 +0000 | [diff] [blame] | 772 | (SplatValue.getZExtValue() >= EltSize)) |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 773 | return SDValue(); |
| 774 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 775 | return DAG.getNode(Opc, SDLoc(N), Ty, N->getOperand(0), |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 776 | DAG.getConstant(SplatValue.getZExtValue(), MVT::i32)); |
| 777 | } |
| 778 | |
| 779 | static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG, |
| 780 | TargetLowering::DAGCombinerInfo &DCI, |
| 781 | const MipsSubtarget *Subtarget) { |
| 782 | EVT Ty = N->getValueType(0); |
| 783 | |
| 784 | if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) |
| 785 | return SDValue(); |
| 786 | |
| 787 | return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget); |
| 788 | } |
| 789 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 790 | // Fold sign-extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT for MSA and fold |
| 791 | // constant splats into MipsISD::SHRA_DSP for DSPr2. |
| 792 | // |
| 793 | // Performs the following transformations: |
| 794 | // - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to sign extension if its |
| 795 | // sign/zero-extension is completely overwritten by the new one performed by |
| 796 | // the ISD::SRA and ISD::SHL nodes. |
| 797 | // - Removes redundant sign extensions performed by an ISD::SRA and ISD::SHL |
| 798 | // sequence. |
| 799 | // |
| 800 | // See performDSPShiftCombine for more information about the transformation |
| 801 | // used for DSPr2. |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 802 | static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG, |
| 803 | TargetLowering::DAGCombinerInfo &DCI, |
| 804 | const MipsSubtarget *Subtarget) { |
| 805 | EVT Ty = N->getValueType(0); |
| 806 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 807 | if (Subtarget->hasMSA()) { |
| 808 | SDValue Op0 = N->getOperand(0); |
| 809 | SDValue Op1 = N->getOperand(1); |
| 810 | |
| 811 | // (sra (shl (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d), imm:$d) |
| 812 | // where $d + sizeof($c) == 32 |
| 813 | // or $d + sizeof($c) <= 32 and SExt |
| 814 | // -> (MipsVExtractSExt $a, $b, $c) |
| 815 | if (Op0->getOpcode() == ISD::SHL && Op1 == Op0->getOperand(1)) { |
| 816 | SDValue Op0Op0 = Op0->getOperand(0); |
| 817 | ConstantSDNode *ShAmount = dyn_cast<ConstantSDNode>(Op1); |
| 818 | |
| 819 | if (!ShAmount) |
| 820 | return SDValue(); |
| 821 | |
Daniel Sanders | f4f1a87 | 2013-09-27 09:25:29 +0000 | [diff] [blame] | 822 | if (Op0Op0->getOpcode() != MipsISD::VEXTRACT_SEXT_ELT && |
| 823 | Op0Op0->getOpcode() != MipsISD::VEXTRACT_ZEXT_ELT) |
| 824 | return SDValue(); |
| 825 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 826 | EVT ExtendTy = cast<VTSDNode>(Op0Op0->getOperand(2))->getVT(); |
| 827 | unsigned TotalBits = ShAmount->getZExtValue() + ExtendTy.getSizeInBits(); |
| 828 | |
| 829 | if (TotalBits == 32 || |
| 830 | (Op0Op0->getOpcode() == MipsISD::VEXTRACT_SEXT_ELT && |
| 831 | TotalBits <= 32)) { |
| 832 | SDValue Ops[] = { Op0Op0->getOperand(0), Op0Op0->getOperand(1), |
| 833 | Op0Op0->getOperand(2) }; |
| 834 | DAG.MorphNodeTo(Op0Op0.getNode(), MipsISD::VEXTRACT_SEXT_ELT, |
| 835 | Op0Op0->getVTList(), Ops, Op0Op0->getNumOperands()); |
| 836 | return Op0Op0; |
| 837 | } |
| 838 | } |
| 839 | } |
| 840 | |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 841 | if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget->hasDSPR2())) |
| 842 | return SDValue(); |
| 843 | |
| 844 | return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget); |
| 845 | } |
| 846 | |
| 847 | |
| 848 | static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG, |
| 849 | TargetLowering::DAGCombinerInfo &DCI, |
| 850 | const MipsSubtarget *Subtarget) { |
| 851 | EVT Ty = N->getValueType(0); |
| 852 | |
| 853 | if (((Ty != MVT::v2i16) || !Subtarget->hasDSPR2()) && (Ty != MVT::v4i8)) |
| 854 | return SDValue(); |
| 855 | |
| 856 | return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget); |
| 857 | } |
| 858 | |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 859 | static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC) { |
| 860 | bool IsV216 = (Ty == MVT::v2i16); |
| 861 | |
| 862 | switch (CC) { |
| 863 | case ISD::SETEQ: |
| 864 | case ISD::SETNE: return true; |
| 865 | case ISD::SETLT: |
| 866 | case ISD::SETLE: |
| 867 | case ISD::SETGT: |
| 868 | case ISD::SETGE: return IsV216; |
| 869 | case ISD::SETULT: |
| 870 | case ISD::SETULE: |
| 871 | case ISD::SETUGT: |
| 872 | case ISD::SETUGE: return !IsV216; |
| 873 | default: return false; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG) { |
| 878 | EVT Ty = N->getValueType(0); |
| 879 | |
| 880 | if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) |
| 881 | return SDValue(); |
| 882 | |
| 883 | if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get())) |
| 884 | return SDValue(); |
| 885 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 886 | return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0), |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 887 | N->getOperand(1), N->getOperand(2)); |
| 888 | } |
| 889 | |
| 890 | static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG) { |
| 891 | EVT Ty = N->getValueType(0); |
| 892 | |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 893 | if (Ty.is128BitVector() && Ty.isInteger()) { |
| 894 | // Try the following combines: |
| 895 | // (vselect (setcc $a, $b, SETLT), $b, $a)) -> (vsmax $a, $b) |
| 896 | // (vselect (setcc $a, $b, SETLE), $b, $a)) -> (vsmax $a, $b) |
| 897 | // (vselect (setcc $a, $b, SETLT), $a, $b)) -> (vsmin $a, $b) |
| 898 | // (vselect (setcc $a, $b, SETLE), $a, $b)) -> (vsmin $a, $b) |
| 899 | // (vselect (setcc $a, $b, SETULT), $b, $a)) -> (vumax $a, $b) |
| 900 | // (vselect (setcc $a, $b, SETULE), $b, $a)) -> (vumax $a, $b) |
| 901 | // (vselect (setcc $a, $b, SETULT), $a, $b)) -> (vumin $a, $b) |
| 902 | // (vselect (setcc $a, $b, SETULE), $a, $b)) -> (vumin $a, $b) |
| 903 | // SETGT/SETGE/SETUGT/SETUGE variants of these will show up initially but |
| 904 | // will be expanded to equivalent SETLT/SETLE/SETULT/SETULE versions by the |
| 905 | // legalizer. |
| 906 | SDValue Op0 = N->getOperand(0); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 907 | |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 908 | if (Op0->getOpcode() != ISD::SETCC) |
| 909 | return SDValue(); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 910 | |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 911 | ISD::CondCode CondCode = cast<CondCodeSDNode>(Op0->getOperand(2))->get(); |
| 912 | bool Signed; |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 913 | |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 914 | if (CondCode == ISD::SETLT || CondCode == ISD::SETLE) |
| 915 | Signed = true; |
| 916 | else if (CondCode == ISD::SETULT || CondCode == ISD::SETULE) |
| 917 | Signed = false; |
| 918 | else |
| 919 | return SDValue(); |
| 920 | |
| 921 | SDValue Op1 = N->getOperand(1); |
| 922 | SDValue Op2 = N->getOperand(2); |
| 923 | SDValue Op0Op0 = Op0->getOperand(0); |
| 924 | SDValue Op0Op1 = Op0->getOperand(1); |
| 925 | |
| 926 | if (Op1 == Op0Op0 && Op2 == Op0Op1) |
| 927 | return DAG.getNode(Signed ? MipsISD::VSMIN : MipsISD::VUMIN, SDLoc(N), |
| 928 | Ty, Op1, Op2); |
| 929 | else if (Op1 == Op0Op1 && Op2 == Op0Op0) |
| 930 | return DAG.getNode(Signed ? MipsISD::VSMAX : MipsISD::VUMAX, SDLoc(N), |
| 931 | Ty, Op1, Op2); |
| 932 | } else if ((Ty == MVT::v2i16) || (Ty == MVT::v4i8)) { |
| 933 | SDValue SetCC = N->getOperand(0); |
| 934 | |
| 935 | if (SetCC.getOpcode() != MipsISD::SETCC_DSP) |
| 936 | return SDValue(); |
| 937 | |
| 938 | return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty, |
| 939 | SetCC.getOperand(0), SetCC.getOperand(1), |
| 940 | N->getOperand(1), N->getOperand(2), SetCC.getOperand(2)); |
| 941 | } |
| 942 | |
| 943 | return SDValue(); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 944 | } |
| 945 | |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 946 | static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG, |
| 947 | const MipsSubtarget *Subtarget) { |
| 948 | EVT Ty = N->getValueType(0); |
| 949 | |
| 950 | if (Subtarget->hasMSA() && Ty.is128BitVector() && Ty.isInteger()) { |
| 951 | // Try the following combines: |
| 952 | // (xor (or $a, $b), (build_vector allones)) |
| 953 | // (xor (or $a, $b), (bitcast (build_vector allones))) |
| 954 | SDValue Op0 = N->getOperand(0); |
| 955 | SDValue Op1 = N->getOperand(1); |
| 956 | SDValue NotOp; |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 957 | |
| 958 | if (ISD::isBuildVectorAllOnes(Op0.getNode())) |
| 959 | NotOp = Op1; |
| 960 | else if (ISD::isBuildVectorAllOnes(Op1.getNode())) |
| 961 | NotOp = Op0; |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 962 | else |
| 963 | return SDValue(); |
| 964 | |
| 965 | if (NotOp->getOpcode() == ISD::OR) |
| 966 | return DAG.getNode(MipsISD::VNOR, SDLoc(N), Ty, NotOp->getOperand(0), |
| 967 | NotOp->getOperand(1)); |
| 968 | } |
| 969 | |
| 970 | return SDValue(); |
| 971 | } |
| 972 | |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 973 | SDValue |
| 974 | MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const { |
| 975 | SelectionDAG &DAG = DCI.DAG; |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 976 | SDValue Val; |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 977 | |
| 978 | switch (N->getOpcode()) { |
| 979 | case ISD::ADDE: |
| 980 | return performADDECombine(N, DAG, DCI, Subtarget); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 981 | case ISD::AND: |
| 982 | Val = performANDCombine(N, DAG, DCI, Subtarget); |
| 983 | break; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 984 | case ISD::OR: |
| 985 | Val = performORCombine(N, DAG, DCI, Subtarget); |
| 986 | break; |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 987 | case ISD::SUBE: |
| 988 | return performSUBECombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 989 | case ISD::MUL: |
| 990 | return performMULCombine(N, DAG, DCI, this); |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 991 | case ISD::SHL: |
| 992 | return performSHLCombine(N, DAG, DCI, Subtarget); |
| 993 | case ISD::SRA: |
| 994 | return performSRACombine(N, DAG, DCI, Subtarget); |
| 995 | case ISD::SRL: |
| 996 | return performSRLCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 997 | case ISD::VSELECT: |
| 998 | return performVSELECTCombine(N, DAG); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 999 | case ISD::XOR: |
| 1000 | Val = performXORCombine(N, DAG, Subtarget); |
| 1001 | break; |
| 1002 | case ISD::SETCC: |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1003 | Val = performSETCCCombine(N, DAG); |
| 1004 | break; |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1005 | } |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1006 | |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 1007 | if (Val.getNode()) { |
| 1008 | DEBUG(dbgs() << "\nMipsSE DAG Combine:\n"; |
| 1009 | N->printrWithDepth(dbgs(), &DAG); |
| 1010 | dbgs() << "\n=> \n"; |
| 1011 | Val.getNode()->printrWithDepth(dbgs(), &DAG); |
| 1012 | dbgs() << "\n"); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1013 | return Val; |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 1014 | } |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1015 | |
| 1016 | return MipsTargetLowering::PerformDAGCombine(N, DCI); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1019 | MachineBasicBlock * |
| 1020 | MipsSETargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| 1021 | MachineBasicBlock *BB) const { |
| 1022 | switch (MI->getOpcode()) { |
| 1023 | default: |
| 1024 | return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB); |
| 1025 | case Mips::BPOSGE32_PSEUDO: |
| 1026 | return emitBPOSGE32(MI, BB); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1027 | case Mips::SNZ_B_PSEUDO: |
| 1028 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B); |
| 1029 | case Mips::SNZ_H_PSEUDO: |
| 1030 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H); |
| 1031 | case Mips::SNZ_W_PSEUDO: |
| 1032 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W); |
| 1033 | case Mips::SNZ_D_PSEUDO: |
| 1034 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D); |
| 1035 | case Mips::SNZ_V_PSEUDO: |
| 1036 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V); |
| 1037 | case Mips::SZ_B_PSEUDO: |
| 1038 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_B); |
| 1039 | case Mips::SZ_H_PSEUDO: |
| 1040 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_H); |
| 1041 | case Mips::SZ_W_PSEUDO: |
| 1042 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_W); |
| 1043 | case Mips::SZ_D_PSEUDO: |
| 1044 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_D); |
| 1045 | case Mips::SZ_V_PSEUDO: |
| 1046 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_V); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 1047 | case Mips::COPY_FW_PSEUDO: |
| 1048 | return emitCOPY_FW(MI, BB); |
| 1049 | case Mips::COPY_FD_PSEUDO: |
| 1050 | return emitCOPY_FD(MI, BB); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 1051 | case Mips::INSERT_FW_PSEUDO: |
| 1052 | return emitINSERT_FW(MI, BB); |
| 1053 | case Mips::INSERT_FD_PSEUDO: |
| 1054 | return emitINSERT_FD(MI, BB); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 1055 | case Mips::FILL_FW_PSEUDO: |
| 1056 | return emitFILL_FW(MI, BB); |
| 1057 | case Mips::FILL_FD_PSEUDO: |
| 1058 | return emitFILL_FD(MI, BB); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 1059 | case Mips::FEXP2_W_1_PSEUDO: |
| 1060 | return emitFEXP2_W_1(MI, BB); |
| 1061 | case Mips::FEXP2_D_1_PSEUDO: |
| 1062 | return emitFEXP2_D_1(MI, BB); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | bool MipsSETargetLowering:: |
| 1067 | isEligibleForTailCallOptimization(const MipsCC &MipsCCInfo, |
| 1068 | unsigned NextStackOffset, |
| 1069 | const MipsFunctionInfo& FI) const { |
| 1070 | if (!EnableMipsTailCalls) |
| 1071 | return false; |
| 1072 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1073 | // Return false if either the callee or caller has a byval argument. |
| 1074 | if (MipsCCInfo.hasByValArg() || FI.hasByvalArg()) |
| 1075 | return false; |
| 1076 | |
| 1077 | // Return true if the callee's argument area is no larger than the |
| 1078 | // caller's. |
| 1079 | return NextStackOffset <= FI.getIncomingArgSize(); |
| 1080 | } |
| 1081 | |
| 1082 | void MipsSETargetLowering:: |
| 1083 | getOpndList(SmallVectorImpl<SDValue> &Ops, |
| 1084 | std::deque< std::pair<unsigned, SDValue> > &RegsToPass, |
| 1085 | bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage, |
| 1086 | CallLoweringInfo &CLI, SDValue Callee, SDValue Chain) const { |
Akira Hatanaka | 168d4e5 | 2013-11-27 23:38:42 +0000 | [diff] [blame] | 1087 | Ops.push_back(Callee); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1088 | MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, |
| 1089 | InternalLinkage, CLI, Callee, Chain); |
| 1090 | } |
| 1091 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1092 | SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const { |
| 1093 | LoadSDNode &Nd = *cast<LoadSDNode>(Op); |
| 1094 | |
| 1095 | if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) |
| 1096 | return MipsTargetLowering::lowerLOAD(Op, DAG); |
| 1097 | |
| 1098 | // Replace a double precision load with two i32 loads and a buildpair64. |
| 1099 | SDLoc DL(Op); |
| 1100 | SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); |
| 1101 | EVT PtrVT = Ptr.getValueType(); |
| 1102 | |
| 1103 | // i32 load from lower address. |
| 1104 | SDValue Lo = DAG.getLoad(MVT::i32, DL, Chain, Ptr, |
| 1105 | MachinePointerInfo(), Nd.isVolatile(), |
| 1106 | Nd.isNonTemporal(), Nd.isInvariant(), |
| 1107 | Nd.getAlignment()); |
| 1108 | |
| 1109 | // i32 load from higher address. |
| 1110 | Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT)); |
| 1111 | SDValue Hi = DAG.getLoad(MVT::i32, DL, Lo.getValue(1), Ptr, |
| 1112 | MachinePointerInfo(), Nd.isVolatile(), |
| 1113 | Nd.isNonTemporal(), Nd.isInvariant(), |
Akira Hatanaka | 9cf069f | 2013-09-09 17:59:32 +0000 | [diff] [blame] | 1114 | std::min(Nd.getAlignment(), 4U)); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1115 | |
| 1116 | if (!Subtarget->isLittle()) |
| 1117 | std::swap(Lo, Hi); |
| 1118 | |
| 1119 | SDValue BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi); |
| 1120 | SDValue Ops[2] = {BP, Hi.getValue(1)}; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame^] | 1121 | return DAG.getMergeValues(Ops, DL); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1122 | } |
| 1123 | |
| 1124 | SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const { |
| 1125 | StoreSDNode &Nd = *cast<StoreSDNode>(Op); |
| 1126 | |
| 1127 | if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) |
| 1128 | return MipsTargetLowering::lowerSTORE(Op, DAG); |
| 1129 | |
| 1130 | // Replace a double precision store with two extractelement64s and i32 stores. |
| 1131 | SDLoc DL(Op); |
| 1132 | SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); |
| 1133 | EVT PtrVT = Ptr.getValueType(); |
| 1134 | SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
| 1135 | Val, DAG.getConstant(0, MVT::i32)); |
| 1136 | SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
| 1137 | Val, DAG.getConstant(1, MVT::i32)); |
| 1138 | |
| 1139 | if (!Subtarget->isLittle()) |
| 1140 | std::swap(Lo, Hi); |
| 1141 | |
| 1142 | // i32 store to lower address. |
| 1143 | Chain = DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), |
| 1144 | Nd.isVolatile(), Nd.isNonTemporal(), Nd.getAlignment(), |
| 1145 | Nd.getTBAAInfo()); |
| 1146 | |
| 1147 | // i32 store to higher address. |
| 1148 | Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, PtrVT)); |
| 1149 | return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(), |
Akira Hatanaka | 9cf069f | 2013-09-09 17:59:32 +0000 | [diff] [blame] | 1150 | Nd.isVolatile(), Nd.isNonTemporal(), |
| 1151 | std::min(Nd.getAlignment(), 4U), Nd.getTBAAInfo()); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1154 | SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc, |
| 1155 | bool HasLo, bool HasHi, |
| 1156 | SelectionDAG &DAG) const { |
| 1157 | EVT Ty = Op.getOperand(0).getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1158 | SDLoc DL(Op); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1159 | SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped, |
| 1160 | Op.getOperand(0), Op.getOperand(1)); |
| 1161 | SDValue Lo, Hi; |
| 1162 | |
| 1163 | if (HasLo) |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1164 | Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1165 | if (HasHi) |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1166 | Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1167 | |
| 1168 | if (!HasLo || !HasHi) |
| 1169 | return HasLo ? Lo : Hi; |
| 1170 | |
| 1171 | SDValue Vals[] = { Lo, Hi }; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame^] | 1172 | return DAG.getMergeValues(Vals, DL); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1173 | } |
| 1174 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1175 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1176 | static SDValue initAccumulator(SDValue In, SDLoc DL, SelectionDAG &DAG) { |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1177 | SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, |
| 1178 | DAG.getConstant(0, MVT::i32)); |
| 1179 | SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, |
| 1180 | DAG.getConstant(1, MVT::i32)); |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1181 | return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1184 | static SDValue extractLOHI(SDValue Op, SDLoc DL, SelectionDAG &DAG) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1185 | SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op); |
| 1186 | SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1187 | return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi); |
| 1188 | } |
| 1189 | |
| 1190 | // This function expands mips intrinsic nodes which have 64-bit input operands |
| 1191 | // or output values. |
| 1192 | // |
| 1193 | // out64 = intrinsic-node in64 |
| 1194 | // => |
| 1195 | // lo = copy (extract-element (in64, 0)) |
| 1196 | // hi = copy (extract-element (in64, 1)) |
| 1197 | // mips-specific-node |
| 1198 | // v0 = copy lo |
| 1199 | // v1 = copy hi |
| 1200 | // out64 = merge-values (v0, v1) |
| 1201 | // |
| 1202 | static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1203 | SDLoc DL(Op); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1204 | bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other; |
| 1205 | SmallVector<SDValue, 3> Ops; |
| 1206 | unsigned OpNo = 0; |
| 1207 | |
| 1208 | // See if Op has a chain input. |
| 1209 | if (HasChainIn) |
| 1210 | Ops.push_back(Op->getOperand(OpNo++)); |
| 1211 | |
| 1212 | // The next operand is the intrinsic opcode. |
| 1213 | assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant); |
| 1214 | |
| 1215 | // See if the next operand has type i64. |
| 1216 | SDValue Opnd = Op->getOperand(++OpNo), In64; |
| 1217 | |
| 1218 | if (Opnd.getValueType() == MVT::i64) |
| 1219 | In64 = initAccumulator(Opnd, DL, DAG); |
| 1220 | else |
| 1221 | Ops.push_back(Opnd); |
| 1222 | |
| 1223 | // Push the remaining operands. |
| 1224 | for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo) |
| 1225 | Ops.push_back(Op->getOperand(OpNo)); |
| 1226 | |
| 1227 | // Add In64 to the end of the list. |
| 1228 | if (In64.getNode()) |
| 1229 | Ops.push_back(In64); |
| 1230 | |
| 1231 | // Scan output. |
| 1232 | SmallVector<EVT, 2> ResTys; |
| 1233 | |
| 1234 | for (SDNode::value_iterator I = Op->value_begin(), E = Op->value_end(); |
| 1235 | I != E; ++I) |
| 1236 | ResTys.push_back((*I == MVT::i64) ? MVT::Untyped : *I); |
| 1237 | |
| 1238 | // Create node. |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1239 | SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1240 | SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val; |
| 1241 | |
| 1242 | if (!HasChainIn) |
| 1243 | return Out; |
| 1244 | |
| 1245 | assert(Val->getValueType(1) == MVT::Other); |
| 1246 | SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) }; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame^] | 1247 | return DAG.getMergeValues(Vals, DL); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1250 | // Lower an MSA copy intrinsic into the specified SelectionDAG node |
| 1251 | static SDValue lowerMSACopyIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { |
| 1252 | SDLoc DL(Op); |
| 1253 | SDValue Vec = Op->getOperand(1); |
| 1254 | SDValue Idx = Op->getOperand(2); |
| 1255 | EVT ResTy = Op->getValueType(0); |
| 1256 | EVT EltTy = Vec->getValueType(0).getVectorElementType(); |
| 1257 | |
| 1258 | SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx, |
| 1259 | DAG.getValueType(EltTy)); |
| 1260 | |
| 1261 | return Result; |
| 1262 | } |
| 1263 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1264 | static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) { |
| 1265 | EVT ResVecTy = Op->getValueType(0); |
| 1266 | EVT ViaVecTy = ResVecTy; |
| 1267 | SDLoc DL(Op); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1268 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1269 | // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and |
| 1270 | // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating |
| 1271 | // lanes. |
| 1272 | SDValue LaneA; |
| 1273 | SDValue LaneB = Op->getOperand(2); |
| 1274 | |
| 1275 | if (ResVecTy == MVT::v2i64) { |
| 1276 | LaneA = DAG.getConstant(0, MVT::i32); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1277 | ViaVecTy = MVT::v4i32; |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1278 | } else |
| 1279 | LaneA = LaneB; |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1280 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1281 | SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, |
| 1282 | LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB }; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1283 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1284 | SDValue Result = DAG.getNode(ISD::BUILD_VECTOR, DL, ViaVecTy, |
| 1285 | ArrayRef<SDValue>(Ops, ViaVecTy.getVectorNumElements())); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1286 | |
| 1287 | if (ViaVecTy != ResVecTy) |
| 1288 | Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy, Result); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1289 | |
| 1290 | return Result; |
| 1291 | } |
| 1292 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1293 | static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG) { |
| 1294 | return DAG.getConstant(Op->getConstantOperandVal(ImmOp), Op->getValueType(0)); |
| 1295 | } |
| 1296 | |
| 1297 | static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue, |
| 1298 | bool BigEndian, SelectionDAG &DAG) { |
| 1299 | EVT ViaVecTy = VecTy; |
| 1300 | SDValue SplatValueA = SplatValue; |
| 1301 | SDValue SplatValueB = SplatValue; |
| 1302 | SDLoc DL(SplatValue); |
| 1303 | |
| 1304 | if (VecTy == MVT::v2i64) { |
| 1305 | // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's. |
| 1306 | ViaVecTy = MVT::v4i32; |
| 1307 | |
| 1308 | SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue); |
| 1309 | SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue, |
| 1310 | DAG.getConstant(32, MVT::i32)); |
| 1311 | SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB); |
| 1312 | } |
| 1313 | |
| 1314 | // We currently hold the parts in little endian order. Swap them if |
| 1315 | // necessary. |
| 1316 | if (BigEndian) |
| 1317 | std::swap(SplatValueA, SplatValueB); |
| 1318 | |
| 1319 | SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1320 | SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1321 | SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1322 | SplatValueA, SplatValueB, SplatValueA, SplatValueB }; |
| 1323 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1324 | SDValue Result = DAG.getNode(ISD::BUILD_VECTOR, DL, ViaVecTy, |
| 1325 | ArrayRef<SDValue>(Ops, ViaVecTy.getVectorNumElements())); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1326 | |
| 1327 | if (VecTy != ViaVecTy) |
| 1328 | Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result); |
| 1329 | |
| 1330 | return Result; |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1333 | static SDValue lowerMSABinaryBitImmIntr(SDValue Op, SelectionDAG &DAG, |
| 1334 | unsigned Opc, SDValue Imm, |
| 1335 | bool BigEndian) { |
| 1336 | EVT VecTy = Op->getValueType(0); |
| 1337 | SDValue Exp2Imm; |
| 1338 | SDLoc DL(Op); |
| 1339 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1340 | // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it |
| 1341 | // here for now. |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1342 | if (VecTy == MVT::v2i64) { |
| 1343 | if (ConstantSDNode *CImm = dyn_cast<ConstantSDNode>(Imm)) { |
| 1344 | APInt BitImm = APInt(64, 1) << CImm->getAPIntValue(); |
| 1345 | |
| 1346 | SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), MVT::i32); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1347 | SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), MVT::i32); |
| 1348 | |
| 1349 | if (BigEndian) |
| 1350 | std::swap(BitImmLoOp, BitImmHiOp); |
| 1351 | |
| 1352 | Exp2Imm = |
| 1353 | DAG.getNode(ISD::BITCAST, DL, MVT::v2i64, |
| 1354 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v4i32, BitImmLoOp, |
| 1355 | BitImmHiOp, BitImmLoOp, BitImmHiOp)); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1359 | if (!Exp2Imm.getNode()) { |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1360 | // We couldnt constant fold, do a vector shift instead |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1361 | |
| 1362 | // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since |
| 1363 | // only values 0-63 are valid. |
| 1364 | if (VecTy == MVT::v2i64) |
| 1365 | Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm); |
| 1366 | |
| 1367 | Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG); |
| 1368 | |
| 1369 | Exp2Imm = |
| 1370 | DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, VecTy), Exp2Imm); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1371 | } |
| 1372 | |
| 1373 | return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm); |
| 1374 | } |
| 1375 | |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1376 | static SDValue lowerMSABitClear(SDValue Op, SelectionDAG &DAG) { |
| 1377 | EVT ResTy = Op->getValueType(0); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1378 | SDLoc DL(Op); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1379 | SDValue One = DAG.getConstant(1, ResTy); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1380 | SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, Op->getOperand(2)); |
| 1381 | |
Daniel Sanders | 71ce0ca | 2013-11-15 16:02:04 +0000 | [diff] [blame] | 1382 | return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), |
| 1383 | DAG.getNOT(DL, Bit, ResTy)); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | static SDValue lowerMSABitClearImm(SDValue Op, SelectionDAG &DAG) { |
| 1387 | SDLoc DL(Op); |
| 1388 | EVT ResTy = Op->getValueType(0); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1389 | APInt BitImm = APInt(ResTy.getVectorElementType().getSizeInBits(), 1) |
| 1390 | << cast<ConstantSDNode>(Op->getOperand(2))->getAPIntValue(); |
| 1391 | SDValue BitMask = DAG.getConstant(~BitImm, ResTy); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1392 | |
| 1393 | return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask); |
| 1394 | } |
| 1395 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1396 | SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op, |
| 1397 | SelectionDAG &DAG) const { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1398 | SDLoc DL(Op); |
| 1399 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1400 | switch (cast<ConstantSDNode>(Op->getOperand(0))->getZExtValue()) { |
| 1401 | default: |
| 1402 | return SDValue(); |
| 1403 | case Intrinsic::mips_shilo: |
| 1404 | return lowerDSPIntr(Op, DAG, MipsISD::SHILO); |
| 1405 | case Intrinsic::mips_dpau_h_qbl: |
| 1406 | return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL); |
| 1407 | case Intrinsic::mips_dpau_h_qbr: |
| 1408 | return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR); |
| 1409 | case Intrinsic::mips_dpsu_h_qbl: |
| 1410 | return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL); |
| 1411 | case Intrinsic::mips_dpsu_h_qbr: |
| 1412 | return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR); |
| 1413 | case Intrinsic::mips_dpa_w_ph: |
| 1414 | return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH); |
| 1415 | case Intrinsic::mips_dps_w_ph: |
| 1416 | return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH); |
| 1417 | case Intrinsic::mips_dpax_w_ph: |
| 1418 | return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH); |
| 1419 | case Intrinsic::mips_dpsx_w_ph: |
| 1420 | return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH); |
| 1421 | case Intrinsic::mips_mulsa_w_ph: |
| 1422 | return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH); |
| 1423 | case Intrinsic::mips_mult: |
| 1424 | return lowerDSPIntr(Op, DAG, MipsISD::Mult); |
| 1425 | case Intrinsic::mips_multu: |
| 1426 | return lowerDSPIntr(Op, DAG, MipsISD::Multu); |
| 1427 | case Intrinsic::mips_madd: |
| 1428 | return lowerDSPIntr(Op, DAG, MipsISD::MAdd); |
| 1429 | case Intrinsic::mips_maddu: |
| 1430 | return lowerDSPIntr(Op, DAG, MipsISD::MAddu); |
| 1431 | case Intrinsic::mips_msub: |
| 1432 | return lowerDSPIntr(Op, DAG, MipsISD::MSub); |
| 1433 | case Intrinsic::mips_msubu: |
| 1434 | return lowerDSPIntr(Op, DAG, MipsISD::MSubu); |
Daniel Sanders | fa5ab1c | 2013-09-11 10:28:16 +0000 | [diff] [blame] | 1435 | case Intrinsic::mips_addv_b: |
| 1436 | case Intrinsic::mips_addv_h: |
| 1437 | case Intrinsic::mips_addv_w: |
| 1438 | case Intrinsic::mips_addv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1439 | return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1440 | Op->getOperand(2)); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1441 | case Intrinsic::mips_addvi_b: |
| 1442 | case Intrinsic::mips_addvi_h: |
| 1443 | case Intrinsic::mips_addvi_w: |
| 1444 | case Intrinsic::mips_addvi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1445 | return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1446 | lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 1447 | case Intrinsic::mips_and_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1448 | return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1), |
| 1449 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 1450 | case Intrinsic::mips_andi_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1451 | return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1), |
| 1452 | lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1453 | case Intrinsic::mips_bclr_b: |
| 1454 | case Intrinsic::mips_bclr_h: |
| 1455 | case Intrinsic::mips_bclr_w: |
| 1456 | case Intrinsic::mips_bclr_d: |
| 1457 | return lowerMSABitClear(Op, DAG); |
| 1458 | case Intrinsic::mips_bclri_b: |
| 1459 | case Intrinsic::mips_bclri_h: |
| 1460 | case Intrinsic::mips_bclri_w: |
| 1461 | case Intrinsic::mips_bclri_d: |
| 1462 | return lowerMSABitClearImm(Op, DAG); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1463 | case Intrinsic::mips_binsli_b: |
| 1464 | case Intrinsic::mips_binsli_h: |
| 1465 | case Intrinsic::mips_binsli_w: |
| 1466 | case Intrinsic::mips_binsli_d: { |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1467 | // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear) |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1468 | EVT VecTy = Op->getValueType(0); |
| 1469 | EVT EltTy = VecTy.getVectorElementType(); |
| 1470 | APInt Mask = APInt::getHighBitsSet(EltTy.getSizeInBits(), |
| 1471 | Op->getConstantOperandVal(3)); |
| 1472 | return DAG.getNode(ISD::VSELECT, DL, VecTy, |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1473 | DAG.getConstant(Mask, VecTy, true), Op->getOperand(2), |
| 1474 | Op->getOperand(1)); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1475 | } |
| 1476 | case Intrinsic::mips_binsri_b: |
| 1477 | case Intrinsic::mips_binsri_h: |
| 1478 | case Intrinsic::mips_binsri_w: |
| 1479 | case Intrinsic::mips_binsri_d: { |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1480 | // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear) |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1481 | EVT VecTy = Op->getValueType(0); |
| 1482 | EVT EltTy = VecTy.getVectorElementType(); |
| 1483 | APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(), |
| 1484 | Op->getConstantOperandVal(3)); |
| 1485 | return DAG.getNode(ISD::VSELECT, DL, VecTy, |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1486 | DAG.getConstant(Mask, VecTy, true), Op->getOperand(2), |
| 1487 | Op->getOperand(1)); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1488 | } |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 1489 | case Intrinsic::mips_bmnz_v: |
| 1490 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3), |
| 1491 | Op->getOperand(2), Op->getOperand(1)); |
| 1492 | case Intrinsic::mips_bmnzi_b: |
| 1493 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
| 1494 | lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2), |
| 1495 | Op->getOperand(1)); |
| 1496 | case Intrinsic::mips_bmz_v: |
| 1497 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3), |
| 1498 | Op->getOperand(1), Op->getOperand(2)); |
| 1499 | case Intrinsic::mips_bmzi_b: |
| 1500 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
| 1501 | lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1), |
| 1502 | Op->getOperand(2)); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1503 | case Intrinsic::mips_bneg_b: |
| 1504 | case Intrinsic::mips_bneg_h: |
| 1505 | case Intrinsic::mips_bneg_w: |
| 1506 | case Intrinsic::mips_bneg_d: { |
| 1507 | EVT VecTy = Op->getValueType(0); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1508 | SDValue One = DAG.getConstant(1, VecTy); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1509 | |
| 1510 | return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1), |
| 1511 | DAG.getNode(ISD::SHL, DL, VecTy, One, |
| 1512 | Op->getOperand(2))); |
| 1513 | } |
| 1514 | case Intrinsic::mips_bnegi_b: |
| 1515 | case Intrinsic::mips_bnegi_h: |
| 1516 | case Intrinsic::mips_bnegi_w: |
| 1517 | case Intrinsic::mips_bnegi_d: |
| 1518 | return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2), |
| 1519 | !Subtarget->isLittle()); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1520 | case Intrinsic::mips_bnz_b: |
| 1521 | case Intrinsic::mips_bnz_h: |
| 1522 | case Intrinsic::mips_bnz_w: |
| 1523 | case Intrinsic::mips_bnz_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1524 | return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0), |
| 1525 | Op->getOperand(1)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1526 | case Intrinsic::mips_bnz_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1527 | return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0), |
| 1528 | Op->getOperand(1)); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 1529 | case Intrinsic::mips_bsel_v: |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1530 | // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear) |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1531 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1532 | Op->getOperand(1), Op->getOperand(3), |
| 1533 | Op->getOperand(2)); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 1534 | case Intrinsic::mips_bseli_b: |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1535 | // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear) |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1536 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1537 | Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG), |
| 1538 | Op->getOperand(2)); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1539 | case Intrinsic::mips_bset_b: |
| 1540 | case Intrinsic::mips_bset_h: |
| 1541 | case Intrinsic::mips_bset_w: |
| 1542 | case Intrinsic::mips_bset_d: { |
| 1543 | EVT VecTy = Op->getValueType(0); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1544 | SDValue One = DAG.getConstant(1, VecTy); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1545 | |
| 1546 | return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1), |
| 1547 | DAG.getNode(ISD::SHL, DL, VecTy, One, |
| 1548 | Op->getOperand(2))); |
| 1549 | } |
| 1550 | case Intrinsic::mips_bseti_b: |
| 1551 | case Intrinsic::mips_bseti_h: |
| 1552 | case Intrinsic::mips_bseti_w: |
| 1553 | case Intrinsic::mips_bseti_d: |
| 1554 | return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2), |
| 1555 | !Subtarget->isLittle()); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1556 | case Intrinsic::mips_bz_b: |
| 1557 | case Intrinsic::mips_bz_h: |
| 1558 | case Intrinsic::mips_bz_w: |
| 1559 | case Intrinsic::mips_bz_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1560 | return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0), |
| 1561 | Op->getOperand(1)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1562 | case Intrinsic::mips_bz_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1563 | return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0), |
| 1564 | Op->getOperand(1)); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1565 | case Intrinsic::mips_ceq_b: |
| 1566 | case Intrinsic::mips_ceq_h: |
| 1567 | case Intrinsic::mips_ceq_w: |
| 1568 | case Intrinsic::mips_ceq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1569 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1570 | Op->getOperand(2), ISD::SETEQ); |
| 1571 | case Intrinsic::mips_ceqi_b: |
| 1572 | case Intrinsic::mips_ceqi_h: |
| 1573 | case Intrinsic::mips_ceqi_w: |
| 1574 | case Intrinsic::mips_ceqi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1575 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1576 | lowerMSASplatImm(Op, 2, DAG), ISD::SETEQ); |
| 1577 | case Intrinsic::mips_cle_s_b: |
| 1578 | case Intrinsic::mips_cle_s_h: |
| 1579 | case Intrinsic::mips_cle_s_w: |
| 1580 | case Intrinsic::mips_cle_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1581 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1582 | Op->getOperand(2), ISD::SETLE); |
| 1583 | case Intrinsic::mips_clei_s_b: |
| 1584 | case Intrinsic::mips_clei_s_h: |
| 1585 | case Intrinsic::mips_clei_s_w: |
| 1586 | case Intrinsic::mips_clei_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1587 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1588 | lowerMSASplatImm(Op, 2, DAG), ISD::SETLE); |
| 1589 | case Intrinsic::mips_cle_u_b: |
| 1590 | case Intrinsic::mips_cle_u_h: |
| 1591 | case Intrinsic::mips_cle_u_w: |
| 1592 | case Intrinsic::mips_cle_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1593 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1594 | Op->getOperand(2), ISD::SETULE); |
| 1595 | case Intrinsic::mips_clei_u_b: |
| 1596 | case Intrinsic::mips_clei_u_h: |
| 1597 | case Intrinsic::mips_clei_u_w: |
| 1598 | case Intrinsic::mips_clei_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1599 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1600 | lowerMSASplatImm(Op, 2, DAG), ISD::SETULE); |
| 1601 | case Intrinsic::mips_clt_s_b: |
| 1602 | case Intrinsic::mips_clt_s_h: |
| 1603 | case Intrinsic::mips_clt_s_w: |
| 1604 | case Intrinsic::mips_clt_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1605 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1606 | Op->getOperand(2), ISD::SETLT); |
| 1607 | case Intrinsic::mips_clti_s_b: |
| 1608 | case Intrinsic::mips_clti_s_h: |
| 1609 | case Intrinsic::mips_clti_s_w: |
| 1610 | case Intrinsic::mips_clti_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1611 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1612 | lowerMSASplatImm(Op, 2, DAG), ISD::SETLT); |
| 1613 | case Intrinsic::mips_clt_u_b: |
| 1614 | case Intrinsic::mips_clt_u_h: |
| 1615 | case Intrinsic::mips_clt_u_w: |
| 1616 | case Intrinsic::mips_clt_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1617 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1618 | Op->getOperand(2), ISD::SETULT); |
| 1619 | case Intrinsic::mips_clti_u_b: |
| 1620 | case Intrinsic::mips_clti_u_h: |
| 1621 | case Intrinsic::mips_clti_u_w: |
| 1622 | case Intrinsic::mips_clti_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1623 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1624 | lowerMSASplatImm(Op, 2, DAG), ISD::SETULT); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1625 | case Intrinsic::mips_copy_s_b: |
| 1626 | case Intrinsic::mips_copy_s_h: |
| 1627 | case Intrinsic::mips_copy_s_w: |
| 1628 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT); |
Daniel Sanders | 7f3d946 | 2013-09-27 13:04:21 +0000 | [diff] [blame] | 1629 | case Intrinsic::mips_copy_s_d: |
Daniel Sanders | d897b56 | 2014-03-27 10:46:12 +0000 | [diff] [blame] | 1630 | if (hasMips64()) |
Matheus Almeida | 7407032 | 2014-01-29 14:05:28 +0000 | [diff] [blame] | 1631 | // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64. |
| 1632 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT); |
| 1633 | else { |
| 1634 | // Lower into the generic EXTRACT_VECTOR_ELT node and let the type |
| 1635 | // legalizer and EXTRACT_VECTOR_ELT lowering sort it out. |
| 1636 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op), |
| 1637 | Op->getValueType(0), Op->getOperand(1), |
| 1638 | Op->getOperand(2)); |
| 1639 | } |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1640 | case Intrinsic::mips_copy_u_b: |
| 1641 | case Intrinsic::mips_copy_u_h: |
| 1642 | case Intrinsic::mips_copy_u_w: |
| 1643 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT); |
Daniel Sanders | 7f3d946 | 2013-09-27 13:04:21 +0000 | [diff] [blame] | 1644 | case Intrinsic::mips_copy_u_d: |
Daniel Sanders | d897b56 | 2014-03-27 10:46:12 +0000 | [diff] [blame] | 1645 | if (hasMips64()) |
Matheus Almeida | 7407032 | 2014-01-29 14:05:28 +0000 | [diff] [blame] | 1646 | // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64. |
| 1647 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT); |
| 1648 | else { |
| 1649 | // Lower into the generic EXTRACT_VECTOR_ELT node and let the type |
| 1650 | // legalizer and EXTRACT_VECTOR_ELT lowering sort it out. |
| 1651 | // Note: When i64 is illegal, this results in copy_s.w instructions |
| 1652 | // instead of copy_u.w instructions. This makes no difference to the |
| 1653 | // behaviour since i64 is only illegal when the register file is 32-bit. |
| 1654 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op), |
| 1655 | Op->getValueType(0), Op->getOperand(1), |
| 1656 | Op->getOperand(2)); |
| 1657 | } |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 1658 | case Intrinsic::mips_div_s_b: |
| 1659 | case Intrinsic::mips_div_s_h: |
| 1660 | case Intrinsic::mips_div_s_w: |
| 1661 | case Intrinsic::mips_div_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1662 | return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1663 | Op->getOperand(2)); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 1664 | case Intrinsic::mips_div_u_b: |
| 1665 | case Intrinsic::mips_div_u_h: |
| 1666 | case Intrinsic::mips_div_u_w: |
| 1667 | case Intrinsic::mips_div_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1668 | return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1669 | Op->getOperand(2)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1670 | case Intrinsic::mips_fadd_w: |
| 1671 | case Intrinsic::mips_fadd_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1672 | return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1673 | Op->getOperand(2)); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1674 | // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away |
| 1675 | case Intrinsic::mips_fceq_w: |
| 1676 | case Intrinsic::mips_fceq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1677 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1678 | Op->getOperand(2), ISD::SETOEQ); |
| 1679 | case Intrinsic::mips_fcle_w: |
| 1680 | case Intrinsic::mips_fcle_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1681 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1682 | Op->getOperand(2), ISD::SETOLE); |
| 1683 | case Intrinsic::mips_fclt_w: |
| 1684 | case Intrinsic::mips_fclt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1685 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1686 | Op->getOperand(2), ISD::SETOLT); |
| 1687 | case Intrinsic::mips_fcne_w: |
| 1688 | case Intrinsic::mips_fcne_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1689 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1690 | Op->getOperand(2), ISD::SETONE); |
| 1691 | case Intrinsic::mips_fcor_w: |
| 1692 | case Intrinsic::mips_fcor_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1693 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1694 | Op->getOperand(2), ISD::SETO); |
| 1695 | case Intrinsic::mips_fcueq_w: |
| 1696 | case Intrinsic::mips_fcueq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1697 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1698 | Op->getOperand(2), ISD::SETUEQ); |
| 1699 | case Intrinsic::mips_fcule_w: |
| 1700 | case Intrinsic::mips_fcule_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1701 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1702 | Op->getOperand(2), ISD::SETULE); |
| 1703 | case Intrinsic::mips_fcult_w: |
| 1704 | case Intrinsic::mips_fcult_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1705 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1706 | Op->getOperand(2), ISD::SETULT); |
| 1707 | case Intrinsic::mips_fcun_w: |
| 1708 | case Intrinsic::mips_fcun_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1709 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1710 | Op->getOperand(2), ISD::SETUO); |
| 1711 | case Intrinsic::mips_fcune_w: |
| 1712 | case Intrinsic::mips_fcune_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1713 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1714 | Op->getOperand(2), ISD::SETUNE); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1715 | case Intrinsic::mips_fdiv_w: |
| 1716 | case Intrinsic::mips_fdiv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1717 | return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1718 | Op->getOperand(2)); |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 1719 | case Intrinsic::mips_ffint_u_w: |
| 1720 | case Intrinsic::mips_ffint_u_d: |
| 1721 | return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0), |
| 1722 | Op->getOperand(1)); |
| 1723 | case Intrinsic::mips_ffint_s_w: |
| 1724 | case Intrinsic::mips_ffint_s_d: |
| 1725 | return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0), |
| 1726 | Op->getOperand(1)); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 1727 | case Intrinsic::mips_fill_b: |
| 1728 | case Intrinsic::mips_fill_h: |
Daniel Sanders | c72593e | 2013-09-27 13:20:41 +0000 | [diff] [blame] | 1729 | case Intrinsic::mips_fill_w: |
| 1730 | case Intrinsic::mips_fill_d: { |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1731 | SmallVector<SDValue, 16> Ops; |
| 1732 | EVT ResTy = Op->getValueType(0); |
| 1733 | |
| 1734 | for (unsigned i = 0; i < ResTy.getVectorNumElements(); ++i) |
| 1735 | Ops.push_back(Op->getOperand(1)); |
| 1736 | |
Daniel Sanders | c72593e | 2013-09-27 13:20:41 +0000 | [diff] [blame] | 1737 | // If ResTy is v2i64 then the type legalizer will break this node down into |
| 1738 | // an equivalent v4i32. |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1739 | return DAG.getNode(ISD::BUILD_VECTOR, DL, ResTy, Ops); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1740 | } |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 1741 | case Intrinsic::mips_fexp2_w: |
| 1742 | case Intrinsic::mips_fexp2_d: { |
| 1743 | EVT ResTy = Op->getValueType(0); |
| 1744 | return DAG.getNode( |
| 1745 | ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1746 | DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2))); |
| 1747 | } |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1748 | case Intrinsic::mips_flog2_w: |
| 1749 | case Intrinsic::mips_flog2_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1750 | return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | d7103f3 | 2013-10-11 10:14:25 +0000 | [diff] [blame] | 1751 | case Intrinsic::mips_fmadd_w: |
| 1752 | case Intrinsic::mips_fmadd_d: |
| 1753 | return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0), |
| 1754 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1755 | case Intrinsic::mips_fmul_w: |
| 1756 | case Intrinsic::mips_fmul_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1757 | return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1), |
| 1758 | Op->getOperand(2)); |
Daniel Sanders | e67bd87 | 2013-10-11 10:27:32 +0000 | [diff] [blame] | 1759 | case Intrinsic::mips_fmsub_w: |
| 1760 | case Intrinsic::mips_fmsub_d: { |
| 1761 | EVT ResTy = Op->getValueType(0); |
| 1762 | return DAG.getNode(ISD::FSUB, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1763 | DAG.getNode(ISD::FMUL, SDLoc(Op), ResTy, |
| 1764 | Op->getOperand(2), Op->getOperand(3))); |
| 1765 | } |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1766 | case Intrinsic::mips_frint_w: |
| 1767 | case Intrinsic::mips_frint_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1768 | return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1769 | case Intrinsic::mips_fsqrt_w: |
| 1770 | case Intrinsic::mips_fsqrt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1771 | return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1772 | case Intrinsic::mips_fsub_w: |
| 1773 | case Intrinsic::mips_fsub_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1774 | return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1), |
| 1775 | Op->getOperand(2)); |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 1776 | case Intrinsic::mips_ftrunc_u_w: |
| 1777 | case Intrinsic::mips_ftrunc_u_d: |
| 1778 | return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0), |
| 1779 | Op->getOperand(1)); |
| 1780 | case Intrinsic::mips_ftrunc_s_w: |
| 1781 | case Intrinsic::mips_ftrunc_s_d: |
| 1782 | return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0), |
| 1783 | Op->getOperand(1)); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1784 | case Intrinsic::mips_ilvev_b: |
| 1785 | case Intrinsic::mips_ilvev_h: |
| 1786 | case Intrinsic::mips_ilvev_w: |
| 1787 | case Intrinsic::mips_ilvev_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1788 | return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1789 | Op->getOperand(1), Op->getOperand(2)); |
| 1790 | case Intrinsic::mips_ilvl_b: |
| 1791 | case Intrinsic::mips_ilvl_h: |
| 1792 | case Intrinsic::mips_ilvl_w: |
| 1793 | case Intrinsic::mips_ilvl_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1794 | return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1795 | Op->getOperand(1), Op->getOperand(2)); |
| 1796 | case Intrinsic::mips_ilvod_b: |
| 1797 | case Intrinsic::mips_ilvod_h: |
| 1798 | case Intrinsic::mips_ilvod_w: |
| 1799 | case Intrinsic::mips_ilvod_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1800 | return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1801 | Op->getOperand(1), Op->getOperand(2)); |
| 1802 | case Intrinsic::mips_ilvr_b: |
| 1803 | case Intrinsic::mips_ilvr_h: |
| 1804 | case Intrinsic::mips_ilvr_w: |
| 1805 | case Intrinsic::mips_ilvr_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1806 | return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1807 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1808 | case Intrinsic::mips_insert_b: |
| 1809 | case Intrinsic::mips_insert_h: |
| 1810 | case Intrinsic::mips_insert_w: |
Daniel Sanders | 6098b33 | 2013-09-27 13:36:54 +0000 | [diff] [blame] | 1811 | case Intrinsic::mips_insert_d: |
| 1812 | return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0), |
| 1813 | Op->getOperand(1), Op->getOperand(3), Op->getOperand(2)); |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 1814 | case Intrinsic::mips_insve_b: |
| 1815 | case Intrinsic::mips_insve_h: |
| 1816 | case Intrinsic::mips_insve_w: |
| 1817 | case Intrinsic::mips_insve_d: |
| 1818 | return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0), |
| 1819 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3), |
| 1820 | DAG.getConstant(0, MVT::i32)); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 1821 | case Intrinsic::mips_ldi_b: |
| 1822 | case Intrinsic::mips_ldi_h: |
| 1823 | case Intrinsic::mips_ldi_w: |
| 1824 | case Intrinsic::mips_ldi_d: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1825 | return lowerMSASplatImm(Op, 1, DAG); |
Matheus Almeida | 4b27eb5 | 2014-02-10 12:05:17 +0000 | [diff] [blame] | 1826 | case Intrinsic::mips_lsa: |
| 1827 | case Intrinsic::mips_dlsa: { |
Daniel Sanders | a4eaf59 | 2013-10-17 13:38:20 +0000 | [diff] [blame] | 1828 | EVT ResTy = Op->getValueType(0); |
| 1829 | return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1830 | DAG.getNode(ISD::SHL, SDLoc(Op), ResTy, |
| 1831 | Op->getOperand(2), Op->getOperand(3))); |
| 1832 | } |
Daniel Sanders | 50e5ed3 | 2013-10-11 10:50:42 +0000 | [diff] [blame] | 1833 | case Intrinsic::mips_maddv_b: |
| 1834 | case Intrinsic::mips_maddv_h: |
| 1835 | case Intrinsic::mips_maddv_w: |
| 1836 | case Intrinsic::mips_maddv_d: { |
| 1837 | EVT ResTy = Op->getValueType(0); |
| 1838 | return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1839 | DAG.getNode(ISD::MUL, SDLoc(Op), ResTy, |
| 1840 | Op->getOperand(2), Op->getOperand(3))); |
| 1841 | } |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1842 | case Intrinsic::mips_max_s_b: |
| 1843 | case Intrinsic::mips_max_s_h: |
| 1844 | case Intrinsic::mips_max_s_w: |
| 1845 | case Intrinsic::mips_max_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1846 | return DAG.getNode(MipsISD::VSMAX, DL, Op->getValueType(0), |
| 1847 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1848 | case Intrinsic::mips_max_u_b: |
| 1849 | case Intrinsic::mips_max_u_h: |
| 1850 | case Intrinsic::mips_max_u_w: |
| 1851 | case Intrinsic::mips_max_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1852 | return DAG.getNode(MipsISD::VUMAX, DL, Op->getValueType(0), |
| 1853 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1854 | case Intrinsic::mips_maxi_s_b: |
| 1855 | case Intrinsic::mips_maxi_s_h: |
| 1856 | case Intrinsic::mips_maxi_s_w: |
| 1857 | case Intrinsic::mips_maxi_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1858 | return DAG.getNode(MipsISD::VSMAX, DL, Op->getValueType(0), |
| 1859 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1860 | case Intrinsic::mips_maxi_u_b: |
| 1861 | case Intrinsic::mips_maxi_u_h: |
| 1862 | case Intrinsic::mips_maxi_u_w: |
| 1863 | case Intrinsic::mips_maxi_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1864 | return DAG.getNode(MipsISD::VUMAX, DL, Op->getValueType(0), |
| 1865 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1866 | case Intrinsic::mips_min_s_b: |
| 1867 | case Intrinsic::mips_min_s_h: |
| 1868 | case Intrinsic::mips_min_s_w: |
| 1869 | case Intrinsic::mips_min_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1870 | return DAG.getNode(MipsISD::VSMIN, DL, Op->getValueType(0), |
| 1871 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1872 | case Intrinsic::mips_min_u_b: |
| 1873 | case Intrinsic::mips_min_u_h: |
| 1874 | case Intrinsic::mips_min_u_w: |
| 1875 | case Intrinsic::mips_min_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1876 | return DAG.getNode(MipsISD::VUMIN, DL, Op->getValueType(0), |
| 1877 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1878 | case Intrinsic::mips_mini_s_b: |
| 1879 | case Intrinsic::mips_mini_s_h: |
| 1880 | case Intrinsic::mips_mini_s_w: |
| 1881 | case Intrinsic::mips_mini_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1882 | return DAG.getNode(MipsISD::VSMIN, DL, Op->getValueType(0), |
| 1883 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1884 | case Intrinsic::mips_mini_u_b: |
| 1885 | case Intrinsic::mips_mini_u_h: |
| 1886 | case Intrinsic::mips_mini_u_w: |
| 1887 | case Intrinsic::mips_mini_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1888 | return DAG.getNode(MipsISD::VUMIN, DL, Op->getValueType(0), |
| 1889 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 1890 | case Intrinsic::mips_mod_s_b: |
| 1891 | case Intrinsic::mips_mod_s_h: |
| 1892 | case Intrinsic::mips_mod_s_w: |
| 1893 | case Intrinsic::mips_mod_s_d: |
| 1894 | return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1), |
| 1895 | Op->getOperand(2)); |
| 1896 | case Intrinsic::mips_mod_u_b: |
| 1897 | case Intrinsic::mips_mod_u_h: |
| 1898 | case Intrinsic::mips_mod_u_w: |
| 1899 | case Intrinsic::mips_mod_u_d: |
| 1900 | return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1), |
| 1901 | Op->getOperand(2)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 1902 | case Intrinsic::mips_mulv_b: |
| 1903 | case Intrinsic::mips_mulv_h: |
| 1904 | case Intrinsic::mips_mulv_w: |
| 1905 | case Intrinsic::mips_mulv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1906 | return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1), |
| 1907 | Op->getOperand(2)); |
Daniel Sanders | 50e5ed3 | 2013-10-11 10:50:42 +0000 | [diff] [blame] | 1908 | case Intrinsic::mips_msubv_b: |
| 1909 | case Intrinsic::mips_msubv_h: |
| 1910 | case Intrinsic::mips_msubv_w: |
| 1911 | case Intrinsic::mips_msubv_d: { |
| 1912 | EVT ResTy = Op->getValueType(0); |
| 1913 | return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1914 | DAG.getNode(ISD::MUL, SDLoc(Op), ResTy, |
| 1915 | Op->getOperand(2), Op->getOperand(3))); |
| 1916 | } |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 1917 | case Intrinsic::mips_nlzc_b: |
| 1918 | case Intrinsic::mips_nlzc_h: |
| 1919 | case Intrinsic::mips_nlzc_w: |
| 1920 | case Intrinsic::mips_nlzc_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1921 | return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 1922 | case Intrinsic::mips_nor_v: { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1923 | SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 1924 | Op->getOperand(1), Op->getOperand(2)); |
| 1925 | return DAG.getNOT(DL, Res, Res->getValueType(0)); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 1926 | } |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 1927 | case Intrinsic::mips_nori_b: { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1928 | SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 1929 | Op->getOperand(1), |
| 1930 | lowerMSASplatImm(Op, 2, DAG)); |
| 1931 | return DAG.getNOT(DL, Res, Res->getValueType(0)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 1932 | } |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 1933 | case Intrinsic::mips_or_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1934 | return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1), |
| 1935 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 1936 | case Intrinsic::mips_ori_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1937 | return DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 1938 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 1939 | case Intrinsic::mips_pckev_b: |
| 1940 | case Intrinsic::mips_pckev_h: |
| 1941 | case Intrinsic::mips_pckev_w: |
| 1942 | case Intrinsic::mips_pckev_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1943 | return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0), |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 1944 | Op->getOperand(1), Op->getOperand(2)); |
| 1945 | case Intrinsic::mips_pckod_b: |
| 1946 | case Intrinsic::mips_pckod_h: |
| 1947 | case Intrinsic::mips_pckod_w: |
| 1948 | case Intrinsic::mips_pckod_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1949 | return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0), |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 1950 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 766cb69 | 2013-09-23 13:40:21 +0000 | [diff] [blame] | 1951 | case Intrinsic::mips_pcnt_b: |
| 1952 | case Intrinsic::mips_pcnt_h: |
| 1953 | case Intrinsic::mips_pcnt_w: |
| 1954 | case Intrinsic::mips_pcnt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1955 | return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 1956 | case Intrinsic::mips_shf_b: |
| 1957 | case Intrinsic::mips_shf_h: |
| 1958 | case Intrinsic::mips_shf_w: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1959 | return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0), |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 1960 | Op->getOperand(2), Op->getOperand(1)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 1961 | case Intrinsic::mips_sll_b: |
| 1962 | case Intrinsic::mips_sll_h: |
| 1963 | case Intrinsic::mips_sll_w: |
| 1964 | case Intrinsic::mips_sll_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1965 | return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1), |
| 1966 | Op->getOperand(2)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 1967 | case Intrinsic::mips_slli_b: |
| 1968 | case Intrinsic::mips_slli_h: |
| 1969 | case Intrinsic::mips_slli_w: |
| 1970 | case Intrinsic::mips_slli_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1971 | return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), |
| 1972 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | e7ef0c8 | 2013-10-30 13:07:44 +0000 | [diff] [blame] | 1973 | case Intrinsic::mips_splat_b: |
| 1974 | case Intrinsic::mips_splat_h: |
| 1975 | case Intrinsic::mips_splat_w: |
| 1976 | case Intrinsic::mips_splat_d: |
| 1977 | // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle |
| 1978 | // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because |
| 1979 | // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32. |
| 1980 | // Instead we lower to MipsISD::VSHF and match from there. |
| 1981 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1982 | lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1), |
Daniel Sanders | e7ef0c8 | 2013-10-30 13:07:44 +0000 | [diff] [blame] | 1983 | Op->getOperand(1)); |
Daniel Sanders | 7e51fe1 | 2013-09-27 11:48:57 +0000 | [diff] [blame] | 1984 | case Intrinsic::mips_splati_b: |
| 1985 | case Intrinsic::mips_splati_h: |
| 1986 | case Intrinsic::mips_splati_w: |
| 1987 | case Intrinsic::mips_splati_d: |
| 1988 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
| 1989 | lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1), |
| 1990 | Op->getOperand(1)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 1991 | case Intrinsic::mips_sra_b: |
| 1992 | case Intrinsic::mips_sra_h: |
| 1993 | case Intrinsic::mips_sra_w: |
| 1994 | case Intrinsic::mips_sra_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1995 | return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1), |
| 1996 | Op->getOperand(2)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 1997 | case Intrinsic::mips_srai_b: |
| 1998 | case Intrinsic::mips_srai_h: |
| 1999 | case Intrinsic::mips_srai_w: |
| 2000 | case Intrinsic::mips_srai_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2001 | return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), |
| 2002 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2003 | case Intrinsic::mips_srl_b: |
| 2004 | case Intrinsic::mips_srl_h: |
| 2005 | case Intrinsic::mips_srl_w: |
| 2006 | case Intrinsic::mips_srl_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2007 | return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1), |
| 2008 | Op->getOperand(2)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 2009 | case Intrinsic::mips_srli_b: |
| 2010 | case Intrinsic::mips_srli_h: |
| 2011 | case Intrinsic::mips_srli_w: |
| 2012 | case Intrinsic::mips_srli_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2013 | return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), |
| 2014 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2015 | case Intrinsic::mips_subv_b: |
| 2016 | case Intrinsic::mips_subv_h: |
| 2017 | case Intrinsic::mips_subv_w: |
| 2018 | case Intrinsic::mips_subv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2019 | return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1), |
| 2020 | Op->getOperand(2)); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 2021 | case Intrinsic::mips_subvi_b: |
| 2022 | case Intrinsic::mips_subvi_h: |
| 2023 | case Intrinsic::mips_subvi_w: |
| 2024 | case Intrinsic::mips_subvi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2025 | return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), |
| 2026 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2027 | case Intrinsic::mips_vshf_b: |
| 2028 | case Intrinsic::mips_vshf_h: |
| 2029 | case Intrinsic::mips_vshf_w: |
| 2030 | case Intrinsic::mips_vshf_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2031 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2032 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3)); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 2033 | case Intrinsic::mips_xor_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2034 | return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1), |
| 2035 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 2036 | case Intrinsic::mips_xori_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2037 | return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), |
| 2038 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2039 | } |
| 2040 | } |
| 2041 | |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2042 | static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) { |
| 2043 | SDLoc DL(Op); |
| 2044 | SDValue ChainIn = Op->getOperand(0); |
| 2045 | SDValue Address = Op->getOperand(2); |
| 2046 | SDValue Offset = Op->getOperand(3); |
| 2047 | EVT ResTy = Op->getValueType(0); |
| 2048 | EVT PtrTy = Address->getValueType(0); |
| 2049 | |
| 2050 | Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); |
| 2051 | |
| 2052 | return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(), false, |
| 2053 | false, false, 16); |
| 2054 | } |
| 2055 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2056 | SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op, |
| 2057 | SelectionDAG &DAG) const { |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2058 | unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); |
| 2059 | switch (Intr) { |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2060 | default: |
| 2061 | return SDValue(); |
| 2062 | case Intrinsic::mips_extp: |
| 2063 | return lowerDSPIntr(Op, DAG, MipsISD::EXTP); |
| 2064 | case Intrinsic::mips_extpdp: |
| 2065 | return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP); |
| 2066 | case Intrinsic::mips_extr_w: |
| 2067 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W); |
| 2068 | case Intrinsic::mips_extr_r_w: |
| 2069 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W); |
| 2070 | case Intrinsic::mips_extr_rs_w: |
| 2071 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W); |
| 2072 | case Intrinsic::mips_extr_s_h: |
| 2073 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H); |
| 2074 | case Intrinsic::mips_mthlip: |
| 2075 | return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP); |
| 2076 | case Intrinsic::mips_mulsaq_s_w_ph: |
| 2077 | return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH); |
| 2078 | case Intrinsic::mips_maq_s_w_phl: |
| 2079 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL); |
| 2080 | case Intrinsic::mips_maq_s_w_phr: |
| 2081 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR); |
| 2082 | case Intrinsic::mips_maq_sa_w_phl: |
| 2083 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL); |
| 2084 | case Intrinsic::mips_maq_sa_w_phr: |
| 2085 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR); |
| 2086 | case Intrinsic::mips_dpaq_s_w_ph: |
| 2087 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH); |
| 2088 | case Intrinsic::mips_dpsq_s_w_ph: |
| 2089 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH); |
| 2090 | case Intrinsic::mips_dpaq_sa_l_w: |
| 2091 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W); |
| 2092 | case Intrinsic::mips_dpsq_sa_l_w: |
| 2093 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W); |
| 2094 | case Intrinsic::mips_dpaqx_s_w_ph: |
| 2095 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH); |
| 2096 | case Intrinsic::mips_dpaqx_sa_w_ph: |
| 2097 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH); |
| 2098 | case Intrinsic::mips_dpsqx_s_w_ph: |
| 2099 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH); |
| 2100 | case Intrinsic::mips_dpsqx_sa_w_ph: |
| 2101 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2102 | case Intrinsic::mips_ld_b: |
| 2103 | case Intrinsic::mips_ld_h: |
| 2104 | case Intrinsic::mips_ld_w: |
| 2105 | case Intrinsic::mips_ld_d: |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2106 | return lowerMSALoadIntr(Op, DAG, Intr); |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | static SDValue lowerMSAStoreIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr) { |
| 2111 | SDLoc DL(Op); |
| 2112 | SDValue ChainIn = Op->getOperand(0); |
| 2113 | SDValue Value = Op->getOperand(2); |
| 2114 | SDValue Address = Op->getOperand(3); |
| 2115 | SDValue Offset = Op->getOperand(4); |
| 2116 | EVT PtrTy = Address->getValueType(0); |
| 2117 | |
| 2118 | Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); |
| 2119 | |
| 2120 | return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(), false, |
| 2121 | false, 16); |
| 2122 | } |
| 2123 | |
| 2124 | SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op, |
| 2125 | SelectionDAG &DAG) const { |
| 2126 | unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); |
| 2127 | switch (Intr) { |
| 2128 | default: |
| 2129 | return SDValue(); |
| 2130 | case Intrinsic::mips_st_b: |
| 2131 | case Intrinsic::mips_st_h: |
| 2132 | case Intrinsic::mips_st_w: |
| 2133 | case Intrinsic::mips_st_d: |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 2134 | return lowerMSAStoreIntr(Op, DAG, Intr); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2135 | } |
| 2136 | } |
| 2137 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2138 | /// \brief Check if the given BuildVectorSDNode is a splat. |
| 2139 | /// This method currently relies on DAG nodes being reused when equivalent, |
| 2140 | /// so it's possible for this to return false even when isConstantSplat returns |
| 2141 | /// true. |
| 2142 | static bool isSplatVector(const BuildVectorSDNode *N) { |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2143 | unsigned int nOps = N->getNumOperands(); |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 2144 | assert(nOps > 1 && "isSplatVector has 0 or 1 sized build vector"); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2145 | |
| 2146 | SDValue Operand0 = N->getOperand(0); |
| 2147 | |
| 2148 | for (unsigned int i = 1; i < nOps; ++i) { |
| 2149 | if (N->getOperand(i) != Operand0) |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
| 2153 | return true; |
| 2154 | } |
| 2155 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 2156 | // Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT. |
| 2157 | // |
| 2158 | // The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We |
| 2159 | // choose to sign-extend but we could have equally chosen zero-extend. The |
| 2160 | // DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT |
| 2161 | // result into this node later (possibly changing it to a zero-extend in the |
| 2162 | // process). |
| 2163 | SDValue MipsSETargetLowering:: |
| 2164 | lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const { |
| 2165 | SDLoc DL(Op); |
| 2166 | EVT ResTy = Op->getValueType(0); |
| 2167 | SDValue Op0 = Op->getOperand(0); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 2168 | EVT VecTy = Op0->getValueType(0); |
| 2169 | |
| 2170 | if (!VecTy.is128BitVector()) |
| 2171 | return SDValue(); |
| 2172 | |
| 2173 | if (ResTy.isInteger()) { |
| 2174 | SDValue Op1 = Op->getOperand(1); |
| 2175 | EVT EltTy = VecTy.getVectorElementType(); |
| 2176 | return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1, |
| 2177 | DAG.getValueType(EltTy)); |
| 2178 | } |
| 2179 | |
| 2180 | return Op; |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2183 | static bool isConstantOrUndef(const SDValue Op) { |
| 2184 | if (Op->getOpcode() == ISD::UNDEF) |
| 2185 | return true; |
| 2186 | if (dyn_cast<ConstantSDNode>(Op)) |
| 2187 | return true; |
| 2188 | if (dyn_cast<ConstantFPSDNode>(Op)) |
| 2189 | return true; |
| 2190 | return false; |
| 2191 | } |
| 2192 | |
| 2193 | static bool isConstantOrUndefBUILD_VECTOR(const BuildVectorSDNode *Op) { |
| 2194 | for (unsigned i = 0; i < Op->getNumOperands(); ++i) |
| 2195 | if (isConstantOrUndef(Op->getOperand(i))) |
| 2196 | return true; |
| 2197 | return false; |
| 2198 | } |
| 2199 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2200 | // Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the |
| 2201 | // backend. |
| 2202 | // |
| 2203 | // Lowers according to the following rules: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2204 | // - Constant splats are legal as-is as long as the SplatBitSize is a power of |
| 2205 | // 2 less than or equal to 64 and the value fits into a signed 10-bit |
| 2206 | // immediate |
| 2207 | // - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize |
| 2208 | // is a power of 2 less than or equal to 64 and the value does not fit into a |
| 2209 | // signed 10-bit immediate |
| 2210 | // - Non-constant splats are legal as-is. |
| 2211 | // - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT. |
| 2212 | // - All others are illegal and must be expanded. |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2213 | SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op, |
| 2214 | SelectionDAG &DAG) const { |
| 2215 | BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op); |
| 2216 | EVT ResTy = Op->getValueType(0); |
| 2217 | SDLoc DL(Op); |
| 2218 | APInt SplatValue, SplatUndef; |
| 2219 | unsigned SplatBitSize; |
| 2220 | bool HasAnyUndefs; |
| 2221 | |
| 2222 | if (!Subtarget->hasMSA() || !ResTy.is128BitVector()) |
| 2223 | return SDValue(); |
| 2224 | |
| 2225 | if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, |
| 2226 | HasAnyUndefs, 8, |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2227 | !Subtarget->isLittle()) && SplatBitSize <= 64) { |
| 2228 | // We can only cope with 8, 16, 32, or 64-bit elements |
| 2229 | if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 && |
| 2230 | SplatBitSize != 64) |
| 2231 | return SDValue(); |
| 2232 | |
| 2233 | // If the value fits into a simm10 then we can use ldi.[bhwd] |
Daniel Sanders | fd8e416 | 2013-11-22 11:24:50 +0000 | [diff] [blame] | 2234 | // However, if it isn't an integer type we will have to bitcast from an |
Daniel Sanders | d40aea8 | 2013-11-22 13:22:52 +0000 | [diff] [blame] | 2235 | // integer type first. Also, if there are any undefs, we must lower them |
Daniel Sanders | 630dbe0 | 2013-11-22 13:14:06 +0000 | [diff] [blame] | 2236 | // to defined values first. |
| 2237 | if (ResTy.isInteger() && !HasAnyUndefs && SplatValue.isSignedIntN(10)) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2238 | return Op; |
| 2239 | |
| 2240 | EVT ViaVecTy; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2241 | |
| 2242 | switch (SplatBitSize) { |
| 2243 | default: |
| 2244 | return SDValue(); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2245 | case 8: |
| 2246 | ViaVecTy = MVT::v16i8; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2247 | break; |
| 2248 | case 16: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2249 | ViaVecTy = MVT::v8i16; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2250 | break; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2251 | case 32: |
| 2252 | ViaVecTy = MVT::v4i32; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2253 | break; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2254 | case 64: |
| 2255 | // There's no fill.d to fall back on for 64-bit values |
| 2256 | return SDValue(); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 2259 | // SelectionDAG::getConstant will promote SplatValue appropriately. |
| 2260 | SDValue Result = DAG.getConstant(SplatValue, ViaVecTy); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2261 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 2262 | // Bitcast to the type we originally wanted |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2263 | if (ViaVecTy != ResTy) |
| 2264 | Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2265 | |
| 2266 | return Result; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2267 | } else if (isSplatVector(Node)) |
| 2268 | return Op; |
| 2269 | else if (!isConstantOrUndefBUILD_VECTOR(Node)) { |
Daniel Sanders | f86622b | 2013-09-24 13:16:15 +0000 | [diff] [blame] | 2270 | // Use INSERT_VECTOR_ELT operations rather than expand to stores. |
| 2271 | // The resulting code is the same length as the expansion, but it doesn't |
| 2272 | // use memory operations |
| 2273 | EVT ResTy = Node->getValueType(0); |
| 2274 | |
| 2275 | assert(ResTy.isVector()); |
| 2276 | |
| 2277 | unsigned NumElts = ResTy.getVectorNumElements(); |
| 2278 | SDValue Vector = DAG.getUNDEF(ResTy); |
| 2279 | for (unsigned i = 0; i < NumElts; ++i) { |
| 2280 | Vector = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ResTy, Vector, |
| 2281 | Node->getOperand(i), |
| 2282 | DAG.getConstant(i, MVT::i32)); |
| 2283 | } |
| 2284 | return Vector; |
| 2285 | } |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2286 | |
| 2287 | return SDValue(); |
| 2288 | } |
| 2289 | |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2290 | // Lower VECTOR_SHUFFLE into SHF (if possible). |
| 2291 | // |
| 2292 | // SHF splits the vector into blocks of four elements, then shuffles these |
| 2293 | // elements according to a <4 x i2> constant (encoded as an integer immediate). |
| 2294 | // |
| 2295 | // It is therefore possible to lower into SHF when the mask takes the form: |
| 2296 | // <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...> |
| 2297 | // When undef's appear they are treated as if they were whatever value is |
| 2298 | // necessary in order to fit the above form. |
| 2299 | // |
| 2300 | // For example: |
| 2301 | // %2 = shufflevector <8 x i16> %0, <8 x i16> undef, |
| 2302 | // <8 x i32> <i32 3, i32 2, i32 1, i32 0, |
| 2303 | // i32 7, i32 6, i32 5, i32 4> |
| 2304 | // is lowered to: |
| 2305 | // (SHF_H $w0, $w1, 27) |
| 2306 | // where the 27 comes from: |
| 2307 | // 3 + (2 << 2) + (1 << 4) + (0 << 6) |
| 2308 | static SDValue lowerVECTOR_SHUFFLE_SHF(SDValue Op, EVT ResTy, |
| 2309 | SmallVector<int, 16> Indices, |
| 2310 | SelectionDAG &DAG) { |
| 2311 | int SHFIndices[4] = { -1, -1, -1, -1 }; |
| 2312 | |
| 2313 | if (Indices.size() < 4) |
| 2314 | return SDValue(); |
| 2315 | |
| 2316 | for (unsigned i = 0; i < 4; ++i) { |
| 2317 | for (unsigned j = i; j < Indices.size(); j += 4) { |
| 2318 | int Idx = Indices[j]; |
| 2319 | |
| 2320 | // Convert from vector index to 4-element subvector index |
| 2321 | // If an index refers to an element outside of the subvector then give up |
| 2322 | if (Idx != -1) { |
| 2323 | Idx -= 4 * (j / 4); |
| 2324 | if (Idx < 0 || Idx >= 4) |
| 2325 | return SDValue(); |
| 2326 | } |
| 2327 | |
| 2328 | // If the mask has an undef, replace it with the current index. |
| 2329 | // Note that it might still be undef if the current index is also undef |
| 2330 | if (SHFIndices[i] == -1) |
| 2331 | SHFIndices[i] = Idx; |
| 2332 | |
| 2333 | // Check that non-undef values are the same as in the mask. If they |
| 2334 | // aren't then give up |
| 2335 | if (!(Idx == -1 || Idx == SHFIndices[i])) |
| 2336 | return SDValue(); |
| 2337 | } |
| 2338 | } |
| 2339 | |
| 2340 | // Calculate the immediate. Replace any remaining undefs with zero |
| 2341 | APInt Imm(32, 0); |
| 2342 | for (int i = 3; i >= 0; --i) { |
| 2343 | int Idx = SHFIndices[i]; |
| 2344 | |
| 2345 | if (Idx == -1) |
| 2346 | Idx = 0; |
| 2347 | |
| 2348 | Imm <<= 2; |
| 2349 | Imm |= Idx & 0x3; |
| 2350 | } |
| 2351 | |
| 2352 | return DAG.getNode(MipsISD::SHF, SDLoc(Op), ResTy, |
| 2353 | DAG.getConstant(Imm, MVT::i32), Op->getOperand(0)); |
| 2354 | } |
| 2355 | |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2356 | // Lower VECTOR_SHUFFLE into ILVEV (if possible). |
| 2357 | // |
| 2358 | // ILVEV interleaves the even elements from each vector. |
| 2359 | // |
| 2360 | // It is possible to lower into ILVEV when the mask takes the form: |
| 2361 | // <0, n, 2, n+2, 4, n+4, ...> |
| 2362 | // where n is the number of elements in the vector. |
| 2363 | // |
| 2364 | // When undef's appear in the mask they are treated as if they were whatever |
| 2365 | // value is necessary in order to fit the above form. |
| 2366 | static SDValue lowerVECTOR_SHUFFLE_ILVEV(SDValue Op, EVT ResTy, |
| 2367 | SmallVector<int, 16> Indices, |
| 2368 | SelectionDAG &DAG) { |
| 2369 | assert ((Indices.size() % 2) == 0); |
| 2370 | int WsIdx = 0; |
| 2371 | int WtIdx = ResTy.getVectorNumElements(); |
| 2372 | |
| 2373 | for (unsigned i = 0; i < Indices.size(); i += 2) { |
| 2374 | if (Indices[i] != -1 && Indices[i] != WsIdx) |
| 2375 | return SDValue(); |
| 2376 | if (Indices[i+1] != -1 && Indices[i+1] != WtIdx) |
| 2377 | return SDValue(); |
| 2378 | WsIdx += 2; |
| 2379 | WtIdx += 2; |
| 2380 | } |
| 2381 | |
| 2382 | return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2383 | Op->getOperand(1)); |
| 2384 | } |
| 2385 | |
| 2386 | // Lower VECTOR_SHUFFLE into ILVOD (if possible). |
| 2387 | // |
| 2388 | // ILVOD interleaves the odd elements from each vector. |
| 2389 | // |
| 2390 | // It is possible to lower into ILVOD when the mask takes the form: |
| 2391 | // <1, n+1, 3, n+3, 5, n+5, ...> |
| 2392 | // where n is the number of elements in the vector. |
| 2393 | // |
| 2394 | // When undef's appear in the mask they are treated as if they were whatever |
| 2395 | // value is necessary in order to fit the above form. |
| 2396 | static SDValue lowerVECTOR_SHUFFLE_ILVOD(SDValue Op, EVT ResTy, |
| 2397 | SmallVector<int, 16> Indices, |
| 2398 | SelectionDAG &DAG) { |
| 2399 | assert ((Indices.size() % 2) == 0); |
| 2400 | int WsIdx = 1; |
| 2401 | int WtIdx = ResTy.getVectorNumElements() + 1; |
| 2402 | |
| 2403 | for (unsigned i = 0; i < Indices.size(); i += 2) { |
| 2404 | if (Indices[i] != -1 && Indices[i] != WsIdx) |
| 2405 | return SDValue(); |
| 2406 | if (Indices[i+1] != -1 && Indices[i+1] != WtIdx) |
| 2407 | return SDValue(); |
| 2408 | WsIdx += 2; |
| 2409 | WtIdx += 2; |
| 2410 | } |
| 2411 | |
| 2412 | return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2413 | Op->getOperand(1)); |
| 2414 | } |
| 2415 | |
| 2416 | // Lower VECTOR_SHUFFLE into ILVL (if possible). |
| 2417 | // |
| 2418 | // ILVL interleaves consecutive elements from the left half of each vector. |
| 2419 | // |
| 2420 | // It is possible to lower into ILVL when the mask takes the form: |
| 2421 | // <0, n, 1, n+1, 2, n+2, ...> |
| 2422 | // where n is the number of elements in the vector. |
| 2423 | // |
| 2424 | // When undef's appear in the mask they are treated as if they were whatever |
| 2425 | // value is necessary in order to fit the above form. |
| 2426 | static SDValue lowerVECTOR_SHUFFLE_ILVL(SDValue Op, EVT ResTy, |
| 2427 | SmallVector<int, 16> Indices, |
| 2428 | SelectionDAG &DAG) { |
| 2429 | assert ((Indices.size() % 2) == 0); |
| 2430 | int WsIdx = 0; |
| 2431 | int WtIdx = ResTy.getVectorNumElements(); |
| 2432 | |
| 2433 | for (unsigned i = 0; i < Indices.size(); i += 2) { |
| 2434 | if (Indices[i] != -1 && Indices[i] != WsIdx) |
| 2435 | return SDValue(); |
| 2436 | if (Indices[i+1] != -1 && Indices[i+1] != WtIdx) |
| 2437 | return SDValue(); |
| 2438 | WsIdx ++; |
| 2439 | WtIdx ++; |
| 2440 | } |
| 2441 | |
| 2442 | return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2443 | Op->getOperand(1)); |
| 2444 | } |
| 2445 | |
| 2446 | // Lower VECTOR_SHUFFLE into ILVR (if possible). |
| 2447 | // |
| 2448 | // ILVR interleaves consecutive elements from the right half of each vector. |
| 2449 | // |
| 2450 | // It is possible to lower into ILVR when the mask takes the form: |
| 2451 | // <x, n+x, x+1, n+x+1, x+2, n+x+2, ...> |
| 2452 | // where n is the number of elements in the vector and x is half n. |
| 2453 | // |
| 2454 | // When undef's appear in the mask they are treated as if they were whatever |
| 2455 | // value is necessary in order to fit the above form. |
| 2456 | static SDValue lowerVECTOR_SHUFFLE_ILVR(SDValue Op, EVT ResTy, |
| 2457 | SmallVector<int, 16> Indices, |
| 2458 | SelectionDAG &DAG) { |
| 2459 | assert ((Indices.size() % 2) == 0); |
| 2460 | unsigned NumElts = ResTy.getVectorNumElements(); |
| 2461 | int WsIdx = NumElts / 2; |
| 2462 | int WtIdx = NumElts + NumElts / 2; |
| 2463 | |
| 2464 | for (unsigned i = 0; i < Indices.size(); i += 2) { |
| 2465 | if (Indices[i] != -1 && Indices[i] != WsIdx) |
| 2466 | return SDValue(); |
| 2467 | if (Indices[i+1] != -1 && Indices[i+1] != WtIdx) |
| 2468 | return SDValue(); |
| 2469 | WsIdx ++; |
| 2470 | WtIdx ++; |
| 2471 | } |
| 2472 | |
| 2473 | return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2474 | Op->getOperand(1)); |
| 2475 | } |
| 2476 | |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2477 | // Lower VECTOR_SHUFFLE into PCKEV (if possible). |
| 2478 | // |
| 2479 | // PCKEV copies the even elements of each vector into the result vector. |
| 2480 | // |
| 2481 | // It is possible to lower into PCKEV when the mask takes the form: |
| 2482 | // <0, 2, 4, ..., n, n+2, n+4, ...> |
| 2483 | // where n is the number of elements in the vector. |
| 2484 | // |
| 2485 | // When undef's appear in the mask they are treated as if they were whatever |
| 2486 | // value is necessary in order to fit the above form. |
| 2487 | static SDValue lowerVECTOR_SHUFFLE_PCKEV(SDValue Op, EVT ResTy, |
| 2488 | SmallVector<int, 16> Indices, |
| 2489 | SelectionDAG &DAG) { |
| 2490 | assert ((Indices.size() % 2) == 0); |
| 2491 | int Idx = 0; |
| 2492 | |
| 2493 | for (unsigned i = 0; i < Indices.size(); ++i) { |
| 2494 | if (Indices[i] != -1 && Indices[i] != Idx) |
| 2495 | return SDValue(); |
| 2496 | Idx += 2; |
| 2497 | } |
| 2498 | |
| 2499 | return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2500 | Op->getOperand(1)); |
| 2501 | } |
| 2502 | |
| 2503 | // Lower VECTOR_SHUFFLE into PCKOD (if possible). |
| 2504 | // |
| 2505 | // PCKOD copies the odd elements of each vector into the result vector. |
| 2506 | // |
| 2507 | // It is possible to lower into PCKOD when the mask takes the form: |
| 2508 | // <1, 3, 5, ..., n+1, n+3, n+5, ...> |
| 2509 | // where n is the number of elements in the vector. |
| 2510 | // |
| 2511 | // When undef's appear in the mask they are treated as if they were whatever |
| 2512 | // value is necessary in order to fit the above form. |
| 2513 | static SDValue lowerVECTOR_SHUFFLE_PCKOD(SDValue Op, EVT ResTy, |
| 2514 | SmallVector<int, 16> Indices, |
| 2515 | SelectionDAG &DAG) { |
| 2516 | assert ((Indices.size() % 2) == 0); |
| 2517 | int Idx = 1; |
| 2518 | |
| 2519 | for (unsigned i = 0; i < Indices.size(); ++i) { |
| 2520 | if (Indices[i] != -1 && Indices[i] != Idx) |
| 2521 | return SDValue(); |
| 2522 | Idx += 2; |
| 2523 | } |
| 2524 | |
| 2525 | return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Op->getOperand(0), |
| 2526 | Op->getOperand(1)); |
| 2527 | } |
| 2528 | |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2529 | // Lower VECTOR_SHUFFLE into VSHF. |
| 2530 | // |
| 2531 | // This mostly consists of converting the shuffle indices in Indices into a |
| 2532 | // BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is |
| 2533 | // also code to eliminate unused operands of the VECTOR_SHUFFLE. For example, |
| 2534 | // if the type is v8i16 and all the indices are less than 8 then the second |
| 2535 | // operand is unused and can be replaced with anything. We choose to replace it |
| 2536 | // with the used operand since this reduces the number of instructions overall. |
| 2537 | static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy, |
| 2538 | SmallVector<int, 16> Indices, |
| 2539 | SelectionDAG &DAG) { |
| 2540 | SmallVector<SDValue, 16> Ops; |
| 2541 | SDValue Op0; |
| 2542 | SDValue Op1; |
| 2543 | EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger(); |
| 2544 | EVT MaskEltTy = MaskVecTy.getVectorElementType(); |
| 2545 | bool Using1stVec = false; |
| 2546 | bool Using2ndVec = false; |
| 2547 | SDLoc DL(Op); |
| 2548 | int ResTyNumElts = ResTy.getVectorNumElements(); |
| 2549 | |
| 2550 | for (int i = 0; i < ResTyNumElts; ++i) { |
| 2551 | // Idx == -1 means UNDEF |
| 2552 | int Idx = Indices[i]; |
| 2553 | |
| 2554 | if (0 <= Idx && Idx < ResTyNumElts) |
| 2555 | Using1stVec = true; |
| 2556 | if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2) |
| 2557 | Using2ndVec = true; |
| 2558 | } |
| 2559 | |
| 2560 | for (SmallVector<int, 16>::iterator I = Indices.begin(); I != Indices.end(); |
| 2561 | ++I) |
| 2562 | Ops.push_back(DAG.getTargetConstant(*I, MaskEltTy)); |
| 2563 | |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2564 | SDValue MaskVec = DAG.getNode(ISD::BUILD_VECTOR, DL, MaskVecTy, Ops); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2565 | |
| 2566 | if (Using1stVec && Using2ndVec) { |
| 2567 | Op0 = Op->getOperand(0); |
| 2568 | Op1 = Op->getOperand(1); |
| 2569 | } else if (Using1stVec) |
| 2570 | Op0 = Op1 = Op->getOperand(0); |
| 2571 | else if (Using2ndVec) |
| 2572 | Op0 = Op1 = Op->getOperand(1); |
| 2573 | else |
| 2574 | llvm_unreachable("shuffle vector mask references neither vector operand?"); |
| 2575 | |
Daniel Sanders | f88a29e | 2014-03-21 16:56:51 +0000 | [diff] [blame] | 2576 | // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion. |
| 2577 | // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11> |
| 2578 | // VSHF concatenates the vectors in a bitwise fashion: |
| 2579 | // <0b00, 0b01> + <0b10, 0b11> -> |
| 2580 | // 0b0100 + 0b1110 -> 0b01001110 |
| 2581 | // <0b10, 0b11, 0b00, 0b01> |
| 2582 | // We must therefore swap the operands to get the correct result. |
| 2583 | return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | // Lower VECTOR_SHUFFLE into one of a number of instructions depending on the |
| 2587 | // indices in the shuffle. |
| 2588 | SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op, |
| 2589 | SelectionDAG &DAG) const { |
| 2590 | ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op); |
| 2591 | EVT ResTy = Op->getValueType(0); |
| 2592 | |
| 2593 | if (!ResTy.is128BitVector()) |
| 2594 | return SDValue(); |
| 2595 | |
| 2596 | int ResTyNumElts = ResTy.getVectorNumElements(); |
| 2597 | SmallVector<int, 16> Indices; |
| 2598 | |
| 2599 | for (int i = 0; i < ResTyNumElts; ++i) |
| 2600 | Indices.push_back(Node->getMaskElt(i)); |
| 2601 | |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2602 | SDValue Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG); |
| 2603 | if (Result.getNode()) |
| 2604 | return Result; |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2605 | Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG); |
| 2606 | if (Result.getNode()) |
| 2607 | return Result; |
| 2608 | Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG); |
| 2609 | if (Result.getNode()) |
| 2610 | return Result; |
| 2611 | Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG); |
| 2612 | if (Result.getNode()) |
| 2613 | return Result; |
| 2614 | Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG); |
| 2615 | if (Result.getNode()) |
| 2616 | return Result; |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2617 | Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG); |
| 2618 | if (Result.getNode()) |
| 2619 | return Result; |
| 2620 | Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG); |
| 2621 | if (Result.getNode()) |
| 2622 | return Result; |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2623 | return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, DAG); |
| 2624 | } |
| 2625 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2626 | MachineBasicBlock * MipsSETargetLowering:: |
| 2627 | emitBPOSGE32(MachineInstr *MI, MachineBasicBlock *BB) const{ |
| 2628 | // $bb: |
| 2629 | // bposge32_pseudo $vr0 |
| 2630 | // => |
| 2631 | // $bb: |
| 2632 | // bposge32 $tbb |
| 2633 | // $fbb: |
| 2634 | // li $vr2, 0 |
| 2635 | // b $sink |
| 2636 | // $tbb: |
| 2637 | // li $vr1, 1 |
| 2638 | // $sink: |
| 2639 | // $vr0 = phi($vr2, $fbb, $vr1, $tbb) |
| 2640 | |
| 2641 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2642 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 2643 | const TargetRegisterClass *RC = &Mips::GPR32RegClass; |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2644 | DebugLoc DL = MI->getDebugLoc(); |
| 2645 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 2646 | MachineFunction::iterator It = std::next(MachineFunction::iterator(BB)); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2647 | MachineFunction *F = BB->getParent(); |
| 2648 | MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 2649 | MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 2650 | MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); |
| 2651 | F->insert(It, FBB); |
| 2652 | F->insert(It, TBB); |
| 2653 | F->insert(It, Sink); |
| 2654 | |
| 2655 | // Transfer the remainder of BB and its successor edges to Sink. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 2656 | Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)), |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2657 | BB->end()); |
| 2658 | Sink->transferSuccessorsAndUpdatePHIs(BB); |
| 2659 | |
| 2660 | // Add successors. |
| 2661 | BB->addSuccessor(FBB); |
| 2662 | BB->addSuccessor(TBB); |
| 2663 | FBB->addSuccessor(Sink); |
| 2664 | TBB->addSuccessor(Sink); |
| 2665 | |
| 2666 | // Insert the real bposge32 instruction to $BB. |
| 2667 | BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB); |
| 2668 | |
| 2669 | // Fill $FBB. |
| 2670 | unsigned VR2 = RegInfo.createVirtualRegister(RC); |
| 2671 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2) |
| 2672 | .addReg(Mips::ZERO).addImm(0); |
| 2673 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); |
| 2674 | |
| 2675 | // Fill $TBB. |
| 2676 | unsigned VR1 = RegInfo.createVirtualRegister(RC); |
| 2677 | BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1) |
| 2678 | .addReg(Mips::ZERO).addImm(1); |
| 2679 | |
| 2680 | // Insert phi function to $Sink. |
| 2681 | BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), |
| 2682 | MI->getOperand(0).getReg()) |
| 2683 | .addReg(VR2).addMBB(FBB).addReg(VR1).addMBB(TBB); |
| 2684 | |
| 2685 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2686 | return Sink; |
| 2687 | } |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 2688 | |
| 2689 | MachineBasicBlock * MipsSETargetLowering:: |
| 2690 | emitMSACBranchPseudo(MachineInstr *MI, MachineBasicBlock *BB, |
| 2691 | unsigned BranchOp) const{ |
| 2692 | // $bb: |
| 2693 | // vany_nonzero $rd, $ws |
| 2694 | // => |
| 2695 | // $bb: |
| 2696 | // bnz.b $ws, $tbb |
| 2697 | // b $fbb |
| 2698 | // $fbb: |
| 2699 | // li $rd1, 0 |
| 2700 | // b $sink |
| 2701 | // $tbb: |
| 2702 | // li $rd2, 1 |
| 2703 | // $sink: |
| 2704 | // $rd = phi($rd1, $fbb, $rd2, $tbb) |
| 2705 | |
| 2706 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2707 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2708 | const TargetRegisterClass *RC = &Mips::GPR32RegClass; |
| 2709 | DebugLoc DL = MI->getDebugLoc(); |
| 2710 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 2711 | MachineFunction::iterator It = std::next(MachineFunction::iterator(BB)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 2712 | MachineFunction *F = BB->getParent(); |
| 2713 | MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 2714 | MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 2715 | MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); |
| 2716 | F->insert(It, FBB); |
| 2717 | F->insert(It, TBB); |
| 2718 | F->insert(It, Sink); |
| 2719 | |
| 2720 | // Transfer the remainder of BB and its successor edges to Sink. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 2721 | Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)), |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 2722 | BB->end()); |
| 2723 | Sink->transferSuccessorsAndUpdatePHIs(BB); |
| 2724 | |
| 2725 | // Add successors. |
| 2726 | BB->addSuccessor(FBB); |
| 2727 | BB->addSuccessor(TBB); |
| 2728 | FBB->addSuccessor(Sink); |
| 2729 | TBB->addSuccessor(Sink); |
| 2730 | |
| 2731 | // Insert the real bnz.b instruction to $BB. |
| 2732 | BuildMI(BB, DL, TII->get(BranchOp)) |
| 2733 | .addReg(MI->getOperand(1).getReg()) |
| 2734 | .addMBB(TBB); |
| 2735 | |
| 2736 | // Fill $FBB. |
| 2737 | unsigned RD1 = RegInfo.createVirtualRegister(RC); |
| 2738 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1) |
| 2739 | .addReg(Mips::ZERO).addImm(0); |
| 2740 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); |
| 2741 | |
| 2742 | // Fill $TBB. |
| 2743 | unsigned RD2 = RegInfo.createVirtualRegister(RC); |
| 2744 | BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2) |
| 2745 | .addReg(Mips::ZERO).addImm(1); |
| 2746 | |
| 2747 | // Insert phi function to $Sink. |
| 2748 | BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), |
| 2749 | MI->getOperand(0).getReg()) |
| 2750 | .addReg(RD1).addMBB(FBB).addReg(RD2).addMBB(TBB); |
| 2751 | |
| 2752 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2753 | return Sink; |
| 2754 | } |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 2755 | |
| 2756 | // Emit the COPY_FW pseudo instruction. |
| 2757 | // |
| 2758 | // copy_fw_pseudo $fd, $ws, n |
| 2759 | // => |
| 2760 | // copy_u_w $rt, $ws, $n |
| 2761 | // mtc1 $rt, $fd |
| 2762 | // |
| 2763 | // When n is zero, the equivalent operation can be performed with (potentially) |
| 2764 | // zero instructions due to register overlaps. This optimization is never valid |
| 2765 | // for lane 1 because it would require FR=0 mode which isn't supported by MSA. |
| 2766 | MachineBasicBlock * MipsSETargetLowering:: |
| 2767 | emitCOPY_FW(MachineInstr *MI, MachineBasicBlock *BB) const{ |
| 2768 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2769 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2770 | DebugLoc DL = MI->getDebugLoc(); |
| 2771 | unsigned Fd = MI->getOperand(0).getReg(); |
| 2772 | unsigned Ws = MI->getOperand(1).getReg(); |
| 2773 | unsigned Lane = MI->getOperand(2).getImm(); |
| 2774 | |
| 2775 | if (Lane == 0) |
| 2776 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, 0, Mips::sub_lo); |
| 2777 | else { |
| 2778 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 2779 | |
Daniel Sanders | d920770 | 2014-03-04 13:54:30 +0000 | [diff] [blame] | 2780 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wt).addReg(Ws).addImm(Lane); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 2781 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_lo); |
| 2782 | } |
| 2783 | |
| 2784 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2785 | return BB; |
| 2786 | } |
| 2787 | |
| 2788 | // Emit the COPY_FD pseudo instruction. |
| 2789 | // |
| 2790 | // copy_fd_pseudo $fd, $ws, n |
| 2791 | // => |
| 2792 | // splati.d $wt, $ws, $n |
| 2793 | // copy $fd, $wt:sub_64 |
| 2794 | // |
| 2795 | // When n is zero, the equivalent operation can be performed with (potentially) |
| 2796 | // zero instructions due to register overlaps. This optimization is always |
| 2797 | // valid because FR=1 mode which is the only supported mode in MSA. |
| 2798 | MachineBasicBlock * MipsSETargetLowering:: |
| 2799 | emitCOPY_FD(MachineInstr *MI, MachineBasicBlock *BB) const{ |
| 2800 | assert(Subtarget->isFP64bit()); |
| 2801 | |
| 2802 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2803 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2804 | unsigned Fd = MI->getOperand(0).getReg(); |
| 2805 | unsigned Ws = MI->getOperand(1).getReg(); |
| 2806 | unsigned Lane = MI->getOperand(2).getImm() * 2; |
| 2807 | DebugLoc DL = MI->getDebugLoc(); |
| 2808 | |
| 2809 | if (Lane == 0) |
| 2810 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, 0, Mips::sub_64); |
| 2811 | else { |
| 2812 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 2813 | |
| 2814 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1); |
| 2815 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_64); |
| 2816 | } |
| 2817 | |
| 2818 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2819 | return BB; |
| 2820 | } |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2821 | |
| 2822 | // Emit the INSERT_FW pseudo instruction. |
| 2823 | // |
| 2824 | // insert_fw_pseudo $wd, $wd_in, $n, $fs |
| 2825 | // => |
| 2826 | // subreg_to_reg $wt:sub_lo, $fs |
| 2827 | // insve_w $wd[$n], $wd_in, $wt[0] |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2828 | MachineBasicBlock * |
| 2829 | MipsSETargetLowering::emitINSERT_FW(MachineInstr *MI, |
| 2830 | MachineBasicBlock *BB) const { |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2831 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2832 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2833 | DebugLoc DL = MI->getDebugLoc(); |
| 2834 | unsigned Wd = MI->getOperand(0).getReg(); |
| 2835 | unsigned Wd_in = MI->getOperand(1).getReg(); |
| 2836 | unsigned Lane = MI->getOperand(2).getImm(); |
| 2837 | unsigned Fs = MI->getOperand(3).getReg(); |
| 2838 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 2839 | |
| 2840 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2841 | .addImm(0) |
| 2842 | .addReg(Fs) |
| 2843 | .addImm(Mips::sub_lo); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2844 | BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2845 | .addReg(Wd_in) |
| 2846 | .addImm(Lane) |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 2847 | .addReg(Wt) |
| 2848 | .addImm(0); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2849 | |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2850 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2851 | return BB; |
| 2852 | } |
| 2853 | |
| 2854 | // Emit the INSERT_FD pseudo instruction. |
| 2855 | // |
| 2856 | // insert_fd_pseudo $wd, $fs, n |
| 2857 | // => |
| 2858 | // subreg_to_reg $wt:sub_64, $fs |
| 2859 | // insve_d $wd[$n], $wd_in, $wt[0] |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2860 | MachineBasicBlock * |
| 2861 | MipsSETargetLowering::emitINSERT_FD(MachineInstr *MI, |
| 2862 | MachineBasicBlock *BB) const { |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2863 | assert(Subtarget->isFP64bit()); |
| 2864 | |
| 2865 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2866 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2867 | DebugLoc DL = MI->getDebugLoc(); |
| 2868 | unsigned Wd = MI->getOperand(0).getReg(); |
| 2869 | unsigned Wd_in = MI->getOperand(1).getReg(); |
| 2870 | unsigned Lane = MI->getOperand(2).getImm(); |
| 2871 | unsigned Fs = MI->getOperand(3).getReg(); |
| 2872 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 2873 | |
| 2874 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2875 | .addImm(0) |
| 2876 | .addReg(Fs) |
| 2877 | .addImm(Mips::sub_64); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2878 | BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2879 | .addReg(Wd_in) |
| 2880 | .addImm(Lane) |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 2881 | .addReg(Wt) |
| 2882 | .addImm(0); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 2883 | |
| 2884 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2885 | return BB; |
| 2886 | } |
| 2887 | |
| 2888 | // Emit the FILL_FW pseudo instruction. |
| 2889 | // |
| 2890 | // fill_fw_pseudo $wd, $fs |
| 2891 | // => |
| 2892 | // implicit_def $wt1 |
| 2893 | // insert_subreg $wt2:subreg_lo, $wt1, $fs |
| 2894 | // splati.w $wd, $wt2[0] |
| 2895 | MachineBasicBlock * |
| 2896 | MipsSETargetLowering::emitFILL_FW(MachineInstr *MI, |
| 2897 | MachineBasicBlock *BB) const { |
| 2898 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2899 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2900 | DebugLoc DL = MI->getDebugLoc(); |
| 2901 | unsigned Wd = MI->getOperand(0).getReg(); |
| 2902 | unsigned Fs = MI->getOperand(1).getReg(); |
| 2903 | unsigned Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 2904 | unsigned Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 2905 | |
| 2906 | BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1); |
| 2907 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2) |
| 2908 | .addReg(Wt1) |
| 2909 | .addReg(Fs) |
| 2910 | .addImm(Mips::sub_lo); |
| 2911 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0); |
| 2912 | |
| 2913 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2914 | return BB; |
| 2915 | } |
| 2916 | |
| 2917 | // Emit the FILL_FD pseudo instruction. |
| 2918 | // |
| 2919 | // fill_fd_pseudo $wd, $fs |
| 2920 | // => |
| 2921 | // implicit_def $wt1 |
| 2922 | // insert_subreg $wt2:subreg_64, $wt1, $fs |
| 2923 | // splati.d $wd, $wt2[0] |
| 2924 | MachineBasicBlock * |
| 2925 | MipsSETargetLowering::emitFILL_FD(MachineInstr *MI, |
| 2926 | MachineBasicBlock *BB) const { |
| 2927 | assert(Subtarget->isFP64bit()); |
| 2928 | |
| 2929 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2930 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2931 | DebugLoc DL = MI->getDebugLoc(); |
| 2932 | unsigned Wd = MI->getOperand(0).getReg(); |
| 2933 | unsigned Fs = MI->getOperand(1).getReg(); |
| 2934 | unsigned Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 2935 | unsigned Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 2936 | |
| 2937 | BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1); |
| 2938 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2) |
| 2939 | .addReg(Wt1) |
| 2940 | .addReg(Fs) |
| 2941 | .addImm(Mips::sub_64); |
| 2942 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wd).addReg(Wt2).addImm(0); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 2943 | |
| 2944 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2945 | return BB; |
| 2946 | } |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 2947 | |
| 2948 | // Emit the FEXP2_W_1 pseudo instructions. |
| 2949 | // |
| 2950 | // fexp2_w_1_pseudo $wd, $wt |
| 2951 | // => |
| 2952 | // ldi.w $ws, 1 |
| 2953 | // fexp2.w $wd, $ws, $wt |
| 2954 | MachineBasicBlock * |
| 2955 | MipsSETargetLowering::emitFEXP2_W_1(MachineInstr *MI, |
| 2956 | MachineBasicBlock *BB) const { |
| 2957 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2958 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2959 | const TargetRegisterClass *RC = &Mips::MSA128WRegClass; |
| 2960 | unsigned Ws1 = RegInfo.createVirtualRegister(RC); |
| 2961 | unsigned Ws2 = RegInfo.createVirtualRegister(RC); |
| 2962 | DebugLoc DL = MI->getDebugLoc(); |
| 2963 | |
| 2964 | // Splat 1.0 into a vector |
| 2965 | BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1); |
| 2966 | BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1); |
| 2967 | |
| 2968 | // Emit 1.0 * fexp2(Wt) |
| 2969 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI->getOperand(0).getReg()) |
| 2970 | .addReg(Ws2) |
| 2971 | .addReg(MI->getOperand(1).getReg()); |
| 2972 | |
| 2973 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 2974 | return BB; |
| 2975 | } |
| 2976 | |
| 2977 | // Emit the FEXP2_D_1 pseudo instructions. |
| 2978 | // |
| 2979 | // fexp2_d_1_pseudo $wd, $wt |
| 2980 | // => |
| 2981 | // ldi.d $ws, 1 |
| 2982 | // fexp2.d $wd, $ws, $wt |
| 2983 | MachineBasicBlock * |
| 2984 | MipsSETargetLowering::emitFEXP2_D_1(MachineInstr *MI, |
| 2985 | MachineBasicBlock *BB) const { |
| 2986 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 2987 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 2988 | const TargetRegisterClass *RC = &Mips::MSA128DRegClass; |
| 2989 | unsigned Ws1 = RegInfo.createVirtualRegister(RC); |
| 2990 | unsigned Ws2 = RegInfo.createVirtualRegister(RC); |
| 2991 | DebugLoc DL = MI->getDebugLoc(); |
| 2992 | |
| 2993 | // Splat 1.0 into a vector |
| 2994 | BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1); |
| 2995 | BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1); |
| 2996 | |
| 2997 | // Emit 1.0 * fexp2(Wt) |
| 2998 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI->getOperand(0).getReg()) |
| 2999 | .addReg(Ws2) |
| 3000 | .addReg(MI->getOperand(1).getReg()); |
| 3001 | |
| 3002 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 3003 | return BB; |
| 3004 | } |