Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1 | //===- MipsSEISelLowering.cpp - MipsSE DAG Lowering Interface -------------===// |
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 | //===----------------------------------------------------------------------===// |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 13 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 14 | #include "MipsSEISelLowering.h" |
Eric Christopher | 79cc1e3 | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 15 | #include "MipsMachineFunction.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 16 | #include "MipsRegisterInfo.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 17 | #include "MipsSubtarget.h" |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/APInt.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/ArrayRef.h" |
| 20 | #include "llvm/ADT/STLExtras.h" |
| 21 | #include "llvm/ADT/SmallVector.h" |
| 22 | #include "llvm/ADT/Triple.h" |
| 23 | #include "llvm/CodeGen/CallingConvLower.h" |
| 24 | #include "llvm/CodeGen/ISDOpcodes.h" |
| 25 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 26 | #include "llvm/CodeGen/MachineFunction.h" |
| 27 | #include "llvm/CodeGen/MachineInstr.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineMemOperand.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 30 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 31 | #include "llvm/CodeGen/SelectionDAG.h" |
| 32 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
David Blaikie | 3f833ed | 2017-11-08 01:01:31 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/TargetInstrInfo.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/TargetSubtargetInfo.h" |
Craig Topper | 2fa1436 | 2018-03-29 17:21:10 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/ValueTypes.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 36 | #include "llvm/IR/DebugLoc.h" |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 37 | #include "llvm/IR/Intrinsics.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 38 | #include "llvm/Support/Casting.h" |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 39 | #include "llvm/Support/CommandLine.h" |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 40 | #include "llvm/Support/Debug.h" |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 41 | #include "llvm/Support/ErrorHandling.h" |
David Blaikie | 13e77db | 2018-03-23 23:58:25 +0000 | [diff] [blame] | 42 | #include "llvm/Support/MachineValueType.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 43 | #include "llvm/Support/MathExtras.h" |
Hans Wennborg | 3e9b1c1 | 2013-10-30 16:10:10 +0000 | [diff] [blame] | 44 | #include "llvm/Support/raw_ostream.h" |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 45 | #include <algorithm> |
| 46 | #include <cassert> |
| 47 | #include <cstdint> |
| 48 | #include <iterator> |
| 49 | #include <utility> |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 50 | |
| 51 | using namespace llvm; |
| 52 | |
Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 53 | #define DEBUG_TYPE "mips-isel" |
| 54 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 55 | static cl::opt<bool> |
Simon Dardis | 57f4ae4 | 2016-08-04 09:17:07 +0000 | [diff] [blame] | 56 | UseMipsTailCalls("mips-tail-calls", cl::Hidden, |
Simon Dardis | d2ed8ab | 2016-09-27 13:15:54 +0000 | [diff] [blame] | 57 | cl::desc("MIPS: permit tail calls."), cl::init(false)); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 58 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 59 | static cl::opt<bool> NoDPLoadStore("mno-ldc1-sdc1", cl::init(false), |
| 60 | cl::desc("Expand double precision loads and " |
| 61 | "stores to their single precision " |
| 62 | "counterparts")); |
| 63 | |
Eric Christopher | b152660 | 2014-09-19 23:30:42 +0000 | [diff] [blame] | 64 | MipsSETargetLowering::MipsSETargetLowering(const MipsTargetMachine &TM, |
Eric Christopher | 8924d27 | 2014-07-18 23:25:04 +0000 | [diff] [blame] | 65 | const MipsSubtarget &STI) |
| 66 | : MipsTargetLowering(TM, STI) { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 67 | // Set up the register classes |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 68 | addRegisterClass(MVT::i32, &Mips::GPR32RegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 69 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 70 | if (Subtarget.isGP64bit()) |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 71 | addRegisterClass(MVT::i64, &Mips::GPR64RegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 72 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 73 | if (Subtarget.hasDSP() || Subtarget.hasMSA()) { |
Daniel Sanders | 36c671e | 2013-09-27 09:44:59 +0000 | [diff] [blame] | 74 | // Expand all truncating stores and extending loads. |
Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 75 | for (MVT VT0 : MVT::vector_valuetypes()) { |
Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 76 | for (MVT VT1 : MVT::vector_valuetypes()) { |
Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 77 | setTruncStoreAction(VT0, VT1, Expand); |
Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 78 | setLoadExtAction(ISD::SEXTLOAD, VT0, VT1, Expand); |
| 79 | setLoadExtAction(ISD::ZEXTLOAD, VT0, VT1, Expand); |
| 80 | setLoadExtAction(ISD::EXTLOAD, VT0, VT1, Expand); |
| 81 | } |
Daniel Sanders | 36c671e | 2013-09-27 09:44:59 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 85 | if (Subtarget.hasDSP()) { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 86 | MVT::SimpleValueType VecTys[2] = {MVT::v2i16, MVT::v4i8}; |
| 87 | |
| 88 | for (unsigned i = 0; i < array_lengthof(VecTys); ++i) { |
Akira Hatanaka | 654655f | 2013-08-14 00:53:38 +0000 | [diff] [blame] | 89 | addRegisterClass(VecTys[i], &Mips::DSPRRegClass); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 90 | |
| 91 | // Expand all builtin opcodes. |
| 92 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 93 | setOperationAction(Opc, VecTys[i], Expand); |
| 94 | |
Akira Hatanaka | 2f08822 | 2013-04-13 00:55:41 +0000 | [diff] [blame] | 95 | setOperationAction(ISD::ADD, VecTys[i], Legal); |
| 96 | setOperationAction(ISD::SUB, VecTys[i], Legal); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 97 | setOperationAction(ISD::LOAD, VecTys[i], Legal); |
| 98 | setOperationAction(ISD::STORE, VecTys[i], Legal); |
| 99 | setOperationAction(ISD::BITCAST, VecTys[i], Legal); |
| 100 | } |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 101 | |
| 102 | setTargetDAGCombine(ISD::SHL); |
| 103 | setTargetDAGCombine(ISD::SRA); |
| 104 | setTargetDAGCombine(ISD::SRL); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 105 | setTargetDAGCombine(ISD::SETCC); |
| 106 | setTargetDAGCombine(ISD::VSELECT); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 109 | if (Subtarget.hasDSPR2()) |
Akira Hatanaka | 2f08822 | 2013-04-13 00:55:41 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::MUL, MVT::v2i16, Legal); |
| 111 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 112 | if (Subtarget.hasMSA()) { |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 113 | addMSAIntType(MVT::v16i8, &Mips::MSA128BRegClass); |
| 114 | addMSAIntType(MVT::v8i16, &Mips::MSA128HRegClass); |
| 115 | addMSAIntType(MVT::v4i32, &Mips::MSA128WRegClass); |
| 116 | addMSAIntType(MVT::v2i64, &Mips::MSA128DRegClass); |
| 117 | addMSAFloatType(MVT::v8f16, &Mips::MSA128HRegClass); |
| 118 | addMSAFloatType(MVT::v4f32, &Mips::MSA128WRegClass); |
| 119 | addMSAFloatType(MVT::v2f64, &Mips::MSA128DRegClass); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 120 | |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 121 | // f16 is a storage-only type, always promote it to f32. |
| 122 | addRegisterClass(MVT::f16, &Mips::MSA128HRegClass); |
| 123 | setOperationAction(ISD::SETCC, MVT::f16, Promote); |
| 124 | setOperationAction(ISD::BR_CC, MVT::f16, Promote); |
| 125 | setOperationAction(ISD::SELECT_CC, MVT::f16, Promote); |
| 126 | setOperationAction(ISD::SELECT, MVT::f16, Promote); |
| 127 | setOperationAction(ISD::FADD, MVT::f16, Promote); |
| 128 | setOperationAction(ISD::FSUB, MVT::f16, Promote); |
| 129 | setOperationAction(ISD::FMUL, MVT::f16, Promote); |
| 130 | setOperationAction(ISD::FDIV, MVT::f16, Promote); |
| 131 | setOperationAction(ISD::FREM, MVT::f16, Promote); |
| 132 | setOperationAction(ISD::FMA, MVT::f16, Promote); |
| 133 | setOperationAction(ISD::FNEG, MVT::f16, Promote); |
| 134 | setOperationAction(ISD::FABS, MVT::f16, Promote); |
| 135 | setOperationAction(ISD::FCEIL, MVT::f16, Promote); |
| 136 | setOperationAction(ISD::FCOPYSIGN, MVT::f16, Promote); |
| 137 | setOperationAction(ISD::FCOS, MVT::f16, Promote); |
| 138 | setOperationAction(ISD::FP_EXTEND, MVT::f16, Promote); |
| 139 | setOperationAction(ISD::FFLOOR, MVT::f16, Promote); |
| 140 | setOperationAction(ISD::FNEARBYINT, MVT::f16, Promote); |
| 141 | setOperationAction(ISD::FPOW, MVT::f16, Promote); |
| 142 | setOperationAction(ISD::FPOWI, MVT::f16, Promote); |
| 143 | setOperationAction(ISD::FRINT, MVT::f16, Promote); |
| 144 | setOperationAction(ISD::FSIN, MVT::f16, Promote); |
| 145 | setOperationAction(ISD::FSINCOS, MVT::f16, Promote); |
| 146 | setOperationAction(ISD::FSQRT, MVT::f16, Promote); |
| 147 | setOperationAction(ISD::FEXP, MVT::f16, Promote); |
| 148 | setOperationAction(ISD::FEXP2, MVT::f16, Promote); |
| 149 | setOperationAction(ISD::FLOG, MVT::f16, Promote); |
| 150 | setOperationAction(ISD::FLOG2, MVT::f16, Promote); |
| 151 | setOperationAction(ISD::FLOG10, MVT::f16, Promote); |
| 152 | setOperationAction(ISD::FROUND, MVT::f16, Promote); |
| 153 | setOperationAction(ISD::FTRUNC, MVT::f16, Promote); |
| 154 | setOperationAction(ISD::FMINNUM, MVT::f16, Promote); |
| 155 | setOperationAction(ISD::FMAXNUM, MVT::f16, Promote); |
| 156 | setOperationAction(ISD::FMINNAN, MVT::f16, Promote); |
| 157 | setOperationAction(ISD::FMAXNAN, MVT::f16, Promote); |
| 158 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 159 | setTargetDAGCombine(ISD::AND); |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 160 | setTargetDAGCombine(ISD::OR); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 161 | setTargetDAGCombine(ISD::SRA); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 162 | setTargetDAGCombine(ISD::VSELECT); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 163 | setTargetDAGCombine(ISD::XOR); |
Jack Carter | 3a2c2d4 | 2013-08-13 20:54:07 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Eric Christopher | e8ae3e3 | 2015-05-07 23:10:21 +0000 | [diff] [blame] | 166 | if (!Subtarget.useSoftFloat()) { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 167 | addRegisterClass(MVT::f32, &Mips::FGR32RegClass); |
| 168 | |
| 169 | // When dealing with single precision only, use libcalls |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 170 | if (!Subtarget.isSingleFloat()) { |
| 171 | if (Subtarget.isFP64bit()) |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 172 | addRegisterClass(MVT::f64, &Mips::FGR64RegClass); |
| 173 | else |
| 174 | addRegisterClass(MVT::f64, &Mips::AFGR64RegClass); |
| 175 | } |
| 176 | } |
| 177 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 178 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Custom); |
| 179 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Custom); |
| 180 | setOperationAction(ISD::MULHS, MVT::i32, Custom); |
| 181 | setOperationAction(ISD::MULHU, MVT::i32, Custom); |
| 182 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 183 | if (Subtarget.hasCnMips()) |
Kai Nacke | 93fe5e8 | 2014-03-20 11:51:58 +0000 | [diff] [blame] | 184 | setOperationAction(ISD::MUL, MVT::i64, Legal); |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 185 | else if (Subtarget.isGP64bit()) |
Kai Nacke | 93fe5e8 | 2014-03-20 11:51:58 +0000 | [diff] [blame] | 186 | setOperationAction(ISD::MUL, MVT::i64, Custom); |
| 187 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 188 | if (Subtarget.isGP64bit()) { |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 189 | setOperationAction(ISD::SMUL_LOHI, MVT::i64, Custom); |
| 190 | setOperationAction(ISD::UMUL_LOHI, MVT::i64, Custom); |
Akira Hatanaka | 4f1130e | 2013-04-11 19:29:26 +0000 | [diff] [blame] | 191 | setOperationAction(ISD::MULHS, MVT::i64, Custom); |
| 192 | setOperationAction(ISD::MULHU, MVT::i64, Custom); |
Jan Vesely | 54468a5a | 2014-10-17 14:45:28 +0000 | [diff] [blame] | 193 | setOperationAction(ISD::SDIVREM, MVT::i64, Custom); |
| 194 | setOperationAction(ISD::UDIVREM, MVT::i64, Custom); |
Akira Hatanaka | 4f1130e | 2013-04-11 19:29:26 +0000 | [diff] [blame] | 195 | } |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 196 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 197 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::i64, Custom); |
| 198 | setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::i64, Custom); |
| 199 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 200 | setOperationAction(ISD::SDIVREM, MVT::i32, Custom); |
| 201 | setOperationAction(ISD::UDIVREM, MVT::i32, Custom); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 202 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| 203 | setOperationAction(ISD::LOAD, MVT::i32, Custom); |
| 204 | setOperationAction(ISD::STORE, MVT::i32, Custom); |
| 205 | |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 206 | setTargetDAGCombine(ISD::MUL); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 207 | |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 208 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 209 | setOperationAction(ISD::INTRINSIC_W_CHAIN, MVT::Other, Custom); |
| 210 | setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom); |
| 211 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 212 | if (NoDPLoadStore) { |
| 213 | setOperationAction(ISD::LOAD, MVT::f64, Custom); |
| 214 | setOperationAction(ISD::STORE, MVT::f64, Custom); |
| 215 | } |
| 216 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 217 | if (Subtarget.hasMips32r6()) { |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 218 | // MIPS32r6 replaces the accumulator-based multiplies with a three register |
| 219 | // instruction |
Daniel Sanders | 826f8b3 | 2014-06-12 10:54:16 +0000 | [diff] [blame] | 220 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
| 221 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 222 | setOperationAction(ISD::MUL, MVT::i32, Legal); |
| 223 | setOperationAction(ISD::MULHS, MVT::i32, Legal); |
| 224 | setOperationAction(ISD::MULHU, MVT::i32, Legal); |
| 225 | |
| 226 | // MIPS32r6 replaces the accumulator-based division/remainder with separate |
| 227 | // three register division and remainder instructions. |
| 228 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 229 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
| 230 | setOperationAction(ISD::SDIV, MVT::i32, Legal); |
| 231 | setOperationAction(ISD::UDIV, MVT::i32, Legal); |
| 232 | setOperationAction(ISD::SREM, MVT::i32, Legal); |
| 233 | setOperationAction(ISD::UREM, MVT::i32, Legal); |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 234 | |
| 235 | // MIPS32r6 replaces conditional moves with an equivalent that removes the |
| 236 | // need for three GPR read ports. |
| 237 | setOperationAction(ISD::SETCC, MVT::i32, Legal); |
| 238 | setOperationAction(ISD::SELECT, MVT::i32, Legal); |
| 239 | setOperationAction(ISD::SELECT_CC, MVT::i32, Expand); |
| 240 | |
| 241 | setOperationAction(ISD::SETCC, MVT::f32, Legal); |
| 242 | setOperationAction(ISD::SELECT, MVT::f32, Legal); |
| 243 | setOperationAction(ISD::SELECT_CC, MVT::f32, Expand); |
| 244 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 245 | assert(Subtarget.isFP64bit() && "FR=1 is required for MIPS32r6"); |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 246 | setOperationAction(ISD::SETCC, MVT::f64, Legal); |
Stefan Maksimovic | be0bc71 | 2017-07-20 13:08:18 +0000 | [diff] [blame] | 247 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 248 | setOperationAction(ISD::SELECT_CC, MVT::f64, Expand); |
| 249 | |
Daniel Sanders | 3d3ea53 | 2014-06-12 15:00:17 +0000 | [diff] [blame] | 250 | setOperationAction(ISD::BRCOND, MVT::Other, Legal); |
| 251 | |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 252 | // Floating point > and >= are supported via < and <= |
| 253 | setCondCodeAction(ISD::SETOGE, MVT::f32, Expand); |
| 254 | setCondCodeAction(ISD::SETOGT, MVT::f32, Expand); |
| 255 | setCondCodeAction(ISD::SETUGE, MVT::f32, Expand); |
| 256 | setCondCodeAction(ISD::SETUGT, MVT::f32, Expand); |
| 257 | |
| 258 | setCondCodeAction(ISD::SETOGE, MVT::f64, Expand); |
| 259 | setCondCodeAction(ISD::SETOGT, MVT::f64, Expand); |
| 260 | setCondCodeAction(ISD::SETUGE, MVT::f64, Expand); |
| 261 | setCondCodeAction(ISD::SETUGT, MVT::f64, Expand); |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 264 | if (Subtarget.hasMips64r6()) { |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 265 | // MIPS64r6 replaces the accumulator-based multiplies with a three register |
| 266 | // instruction |
Vasileios Kalintiris | ef96a8e | 2015-01-26 12:33:22 +0000 | [diff] [blame] | 267 | setOperationAction(ISD::SMUL_LOHI, MVT::i64, Expand); |
| 268 | setOperationAction(ISD::UMUL_LOHI, MVT::i64, Expand); |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 269 | setOperationAction(ISD::MUL, MVT::i64, Legal); |
| 270 | setOperationAction(ISD::MULHS, MVT::i64, Legal); |
| 271 | setOperationAction(ISD::MULHU, MVT::i64, Legal); |
| 272 | |
| 273 | // MIPS32r6 replaces the accumulator-based division/remainder with separate |
| 274 | // three register division and remainder instructions. |
| 275 | setOperationAction(ISD::SDIVREM, MVT::i64, Expand); |
| 276 | setOperationAction(ISD::UDIVREM, MVT::i64, Expand); |
| 277 | setOperationAction(ISD::SDIV, MVT::i64, Legal); |
| 278 | setOperationAction(ISD::UDIV, MVT::i64, Legal); |
| 279 | setOperationAction(ISD::SREM, MVT::i64, Legal); |
| 280 | setOperationAction(ISD::UREM, MVT::i64, Legal); |
Daniel Sanders | 0fa6041 | 2014-06-12 13:39:06 +0000 | [diff] [blame] | 281 | |
| 282 | // MIPS64r6 replaces conditional moves with an equivalent that removes the |
| 283 | // need for three GPR read ports. |
| 284 | setOperationAction(ISD::SETCC, MVT::i64, Legal); |
| 285 | setOperationAction(ISD::SELECT, MVT::i64, Legal); |
| 286 | setOperationAction(ISD::SELECT_CC, MVT::i64, Expand); |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 289 | computeRegisterProperties(Subtarget.getRegisterInfo()); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | const MipsTargetLowering * |
Eric Christopher | b152660 | 2014-09-19 23:30:42 +0000 | [diff] [blame] | 293 | llvm::createMipsSETargetLowering(const MipsTargetMachine &TM, |
Eric Christopher | 8924d27 | 2014-07-18 23:25:04 +0000 | [diff] [blame] | 294 | const MipsSubtarget &STI) { |
| 295 | return new MipsSETargetLowering(TM, STI); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Eric Christopher | bf33a3c | 2014-07-02 23:18:40 +0000 | [diff] [blame] | 298 | const TargetRegisterClass * |
| 299 | MipsSETargetLowering::getRepRegClassFor(MVT VT) const { |
| 300 | if (VT == MVT::Untyped) |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 301 | return Subtarget.hasDSP() ? &Mips::ACC64DSPRegClass : &Mips::ACC64RegClass; |
Eric Christopher | bf33a3c | 2014-07-02 23:18:40 +0000 | [diff] [blame] | 302 | |
| 303 | return TargetLowering::getRepRegClassFor(VT); |
| 304 | } |
| 305 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 306 | // Enable MSA support for the given integer type and Register class. |
Daniel Sanders | 3c9a0ad | 2013-08-23 10:10:13 +0000 | [diff] [blame] | 307 | void MipsSETargetLowering:: |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 308 | addMSAIntType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { |
| 309 | addRegisterClass(Ty, RC); |
| 310 | |
| 311 | // Expand all builtin opcodes. |
| 312 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 313 | setOperationAction(Opc, Ty, Expand); |
| 314 | |
| 315 | setOperationAction(ISD::BITCAST, Ty, Legal); |
| 316 | setOperationAction(ISD::LOAD, Ty, Legal); |
| 317 | setOperationAction(ISD::STORE, Ty, Legal); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 318 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Custom); |
| 319 | setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 320 | setOperationAction(ISD::BUILD_VECTOR, Ty, Custom); |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 321 | |
Daniel Sanders | fa5ab1c | 2013-09-11 10:28:16 +0000 | [diff] [blame] | 322 | setOperationAction(ISD::ADD, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 323 | setOperationAction(ISD::AND, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 324 | setOperationAction(ISD::CTLZ, Ty, Legal); |
Daniel Sanders | 766cb69 | 2013-09-23 13:40:21 +0000 | [diff] [blame] | 325 | setOperationAction(ISD::CTPOP, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 326 | setOperationAction(ISD::MUL, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 327 | setOperationAction(ISD::OR, Ty, Legal); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 328 | setOperationAction(ISD::SDIV, Ty, Legal); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 329 | setOperationAction(ISD::SREM, Ty, Legal); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 330 | setOperationAction(ISD::SHL, Ty, Legal); |
| 331 | setOperationAction(ISD::SRA, Ty, Legal); |
| 332 | setOperationAction(ISD::SRL, Ty, Legal); |
| 333 | setOperationAction(ISD::SUB, Ty, Legal); |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 334 | setOperationAction(ISD::SMAX, Ty, Legal); |
| 335 | setOperationAction(ISD::SMIN, Ty, Legal); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 336 | setOperationAction(ISD::UDIV, Ty, Legal); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 337 | setOperationAction(ISD::UREM, Ty, Legal); |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 338 | setOperationAction(ISD::UMAX, Ty, Legal); |
| 339 | setOperationAction(ISD::UMIN, Ty, Legal); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 340 | setOperationAction(ISD::VECTOR_SHUFFLE, Ty, Custom); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 341 | setOperationAction(ISD::VSELECT, Ty, Legal); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 342 | setOperationAction(ISD::XOR, Ty, Legal); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 343 | |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 344 | if (Ty == MVT::v4i32 || Ty == MVT::v2i64) { |
| 345 | setOperationAction(ISD::FP_TO_SINT, Ty, Legal); |
| 346 | setOperationAction(ISD::FP_TO_UINT, Ty, Legal); |
| 347 | setOperationAction(ISD::SINT_TO_FP, Ty, Legal); |
| 348 | setOperationAction(ISD::UINT_TO_FP, Ty, Legal); |
| 349 | } |
| 350 | |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 351 | setOperationAction(ISD::SETCC, Ty, Legal); |
| 352 | setCondCodeAction(ISD::SETNE, Ty, Expand); |
| 353 | setCondCodeAction(ISD::SETGE, Ty, Expand); |
| 354 | setCondCodeAction(ISD::SETGT, Ty, Expand); |
| 355 | setCondCodeAction(ISD::SETUGE, Ty, Expand); |
| 356 | setCondCodeAction(ISD::SETUGT, Ty, Expand); |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 359 | // Enable MSA support for the given floating-point type and Register class. |
Daniel Sanders | c65f58a | 2013-09-11 10:15:48 +0000 | [diff] [blame] | 360 | void MipsSETargetLowering:: |
| 361 | addMSAFloatType(MVT::SimpleValueType Ty, const TargetRegisterClass *RC) { |
Daniel Sanders | 3c9a0ad | 2013-08-23 10:10:13 +0000 | [diff] [blame] | 362 | addRegisterClass(Ty, RC); |
Jack Carter | babdcc8 | 2013-08-15 12:24:57 +0000 | [diff] [blame] | 363 | |
| 364 | // Expand all builtin opcodes. |
| 365 | for (unsigned Opc = 0; Opc < ISD::BUILTIN_OP_END; ++Opc) |
| 366 | setOperationAction(Opc, Ty, Expand); |
| 367 | |
| 368 | setOperationAction(ISD::LOAD, Ty, Legal); |
| 369 | setOperationAction(ISD::STORE, Ty, Legal); |
| 370 | setOperationAction(ISD::BITCAST, Ty, Legal); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 371 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 372 | setOperationAction(ISD::INSERT_VECTOR_ELT, Ty, Legal); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 373 | setOperationAction(ISD::BUILD_VECTOR, Ty, Custom); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 374 | |
| 375 | if (Ty != MVT::v8f16) { |
Daniel Sanders | 4f3ff1b | 2013-09-24 13:02:08 +0000 | [diff] [blame] | 376 | setOperationAction(ISD::FABS, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 377 | setOperationAction(ISD::FADD, Ty, Legal); |
| 378 | setOperationAction(ISD::FDIV, Ty, Legal); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 379 | setOperationAction(ISD::FEXP2, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 380 | setOperationAction(ISD::FLOG2, Ty, Legal); |
Daniel Sanders | d7103f3 | 2013-10-11 10:14:25 +0000 | [diff] [blame] | 381 | setOperationAction(ISD::FMA, Ty, Legal); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 382 | setOperationAction(ISD::FMUL, Ty, Legal); |
| 383 | setOperationAction(ISD::FRINT, Ty, Legal); |
| 384 | setOperationAction(ISD::FSQRT, Ty, Legal); |
| 385 | setOperationAction(ISD::FSUB, Ty, Legal); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 386 | setOperationAction(ISD::VSELECT, Ty, Legal); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 387 | |
| 388 | setOperationAction(ISD::SETCC, Ty, Legal); |
| 389 | setCondCodeAction(ISD::SETOGE, Ty, Expand); |
| 390 | setCondCodeAction(ISD::SETOGT, Ty, Expand); |
| 391 | setCondCodeAction(ISD::SETUGE, Ty, Expand); |
| 392 | setCondCodeAction(ISD::SETUGT, Ty, Expand); |
| 393 | setCondCodeAction(ISD::SETGE, Ty, Expand); |
| 394 | setCondCodeAction(ISD::SETGT, Ty, Expand); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 395 | } |
Jack Carter | babdcc8 | 2013-08-15 12:24:57 +0000 | [diff] [blame] | 396 | } |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 397 | |
Stefan Maksimovic | be0bc71 | 2017-07-20 13:08:18 +0000 | [diff] [blame] | 398 | SDValue MipsSETargetLowering::lowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
Stefan Maksimovic | be0bc71 | 2017-07-20 13:08:18 +0000 | [diff] [blame] | 399 | if(!Subtarget.hasMips32r6()) |
| 400 | return MipsTargetLowering::LowerOperation(Op, DAG); |
| 401 | |
| 402 | EVT ResTy = Op->getValueType(0); |
| 403 | SDLoc DL(Op); |
| 404 | |
| 405 | // Although MTC1_D64 takes an i32 and writes an f64, the upper 32 bits of the |
| 406 | // floating point register are undefined. Not really an issue as sel.d, which |
| 407 | // is produced from an FSELECT node, only looks at bit 0. |
| 408 | SDValue Tmp = DAG.getNode(MipsISD::MTC1_D64, DL, MVT::f64, Op->getOperand(0)); |
| 409 | return DAG.getNode(MipsISD::FSELECT, DL, ResTy, Tmp, Op->getOperand(1), |
| 410 | Op->getOperand(2)); |
| 411 | } |
| 412 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 413 | bool |
Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 414 | MipsSETargetLowering::allowsMisalignedMemoryAccesses(EVT VT, |
| 415 | unsigned, |
| 416 | unsigned, |
| 417 | bool *Fast) const { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 418 | MVT::SimpleValueType SVT = VT.getSimpleVT().SimpleTy; |
| 419 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 420 | if (Subtarget.systemSupportsUnalignedAccess()) { |
Daniel Sanders | ac27263 | 2014-05-23 13:18:02 +0000 | [diff] [blame] | 421 | // MIPS32r6/MIPS64r6 is required to support unaligned access. It's |
| 422 | // implementation defined whether this is handled by hardware, software, or |
| 423 | // a hybrid of the two but it's expected that most implementations will |
| 424 | // handle the majority of cases in hardware. |
| 425 | if (Fast) |
| 426 | *Fast = true; |
| 427 | return true; |
| 428 | } |
| 429 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 430 | switch (SVT) { |
| 431 | case MVT::i64: |
| 432 | case MVT::i32: |
| 433 | if (Fast) |
| 434 | *Fast = true; |
| 435 | return true; |
| 436 | default: |
| 437 | return false; |
| 438 | } |
| 439 | } |
| 440 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 441 | SDValue MipsSETargetLowering::LowerOperation(SDValue Op, |
| 442 | SelectionDAG &DAG) const { |
| 443 | switch(Op.getOpcode()) { |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 444 | case ISD::LOAD: return lowerLOAD(Op, DAG); |
| 445 | case ISD::STORE: return lowerSTORE(Op, DAG); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 446 | case ISD::SMUL_LOHI: return lowerMulDiv(Op, MipsISD::Mult, true, true, DAG); |
| 447 | case ISD::UMUL_LOHI: return lowerMulDiv(Op, MipsISD::Multu, true, true, DAG); |
| 448 | case ISD::MULHS: return lowerMulDiv(Op, MipsISD::Mult, false, true, DAG); |
| 449 | case ISD::MULHU: return lowerMulDiv(Op, MipsISD::Multu, false, true, DAG); |
| 450 | case ISD::MUL: return lowerMulDiv(Op, MipsISD::Mult, true, false, DAG); |
| 451 | case ISD::SDIVREM: return lowerMulDiv(Op, MipsISD::DivRem, true, true, DAG); |
Akira Hatanaka | d8fb032 | 2013-04-22 20:13:37 +0000 | [diff] [blame] | 452 | case ISD::UDIVREM: return lowerMulDiv(Op, MipsISD::DivRemU, true, true, |
| 453 | DAG); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 454 | case ISD::INTRINSIC_WO_CHAIN: return lowerINTRINSIC_WO_CHAIN(Op, DAG); |
| 455 | case ISD::INTRINSIC_W_CHAIN: return lowerINTRINSIC_W_CHAIN(Op, DAG); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 456 | case ISD::INTRINSIC_VOID: return lowerINTRINSIC_VOID(Op, DAG); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 457 | case ISD::EXTRACT_VECTOR_ELT: return lowerEXTRACT_VECTOR_ELT(Op, DAG); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 458 | case ISD::BUILD_VECTOR: return lowerBUILD_VECTOR(Op, DAG); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 459 | case ISD::VECTOR_SHUFFLE: return lowerVECTOR_SHUFFLE(Op, DAG); |
Stefan Maksimovic | be0bc71 | 2017-07-20 13:08:18 +0000 | [diff] [blame] | 460 | case ISD::SELECT: return lowerSELECT(Op, DAG); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | return MipsTargetLowering::LowerOperation(Op, DAG); |
| 464 | } |
| 465 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 466 | // Fold zero extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT |
| 467 | // |
| 468 | // Performs the following transformations: |
| 469 | // - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to zero extension if its |
| 470 | // sign/zero-extension is completely overwritten by the new one performed by |
| 471 | // the ISD::AND. |
| 472 | // - Removes redundant zero extensions performed by an ISD::AND. |
| 473 | static SDValue performANDCombine(SDNode *N, SelectionDAG &DAG, |
| 474 | TargetLowering::DAGCombinerInfo &DCI, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 475 | const MipsSubtarget &Subtarget) { |
| 476 | if (!Subtarget.hasMSA()) |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 477 | return SDValue(); |
| 478 | |
| 479 | SDValue Op0 = N->getOperand(0); |
| 480 | SDValue Op1 = N->getOperand(1); |
| 481 | unsigned Op0Opcode = Op0->getOpcode(); |
| 482 | |
| 483 | // (and (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d) |
| 484 | // where $d + 1 == 2^n and n == 32 |
| 485 | // or $d + 1 == 2^n and n <= 32 and ZExt |
| 486 | // -> (MipsVExtractZExt $a, $b, $c) |
| 487 | if (Op0Opcode == MipsISD::VEXTRACT_SEXT_ELT || |
| 488 | Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT) { |
| 489 | ConstantSDNode *Mask = dyn_cast<ConstantSDNode>(Op1); |
| 490 | |
| 491 | if (!Mask) |
| 492 | return SDValue(); |
| 493 | |
| 494 | int32_t Log2IfPositive = (Mask->getAPIntValue() + 1).exactLogBase2(); |
| 495 | |
| 496 | if (Log2IfPositive <= 0) |
| 497 | return SDValue(); // Mask+1 is not a power of 2 |
| 498 | |
| 499 | SDValue Op0Op2 = Op0->getOperand(2); |
| 500 | EVT ExtendTy = cast<VTSDNode>(Op0Op2)->getVT(); |
| 501 | unsigned ExtendTySize = ExtendTy.getSizeInBits(); |
| 502 | unsigned Log2 = Log2IfPositive; |
| 503 | |
| 504 | if ((Op0Opcode == MipsISD::VEXTRACT_ZEXT_ELT && Log2 >= ExtendTySize) || |
| 505 | Log2 == ExtendTySize) { |
| 506 | SDValue Ops[] = { Op0->getOperand(0), Op0->getOperand(1), Op0Op2 }; |
Chandler Carruth | 356665a | 2014-08-01 22:09:43 +0000 | [diff] [blame] | 507 | return DAG.getNode(MipsISD::VEXTRACT_ZEXT_ELT, SDLoc(Op0), |
| 508 | Op0->getVTList(), |
| 509 | makeArrayRef(Ops, Op0->getNumOperands())); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
| 513 | return SDValue(); |
| 514 | } |
| 515 | |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 516 | // Determine if the specified node is a constant vector splat. |
| 517 | // |
| 518 | // Returns true and sets Imm if: |
| 519 | // * N is a ISD::BUILD_VECTOR representing a constant splat |
| 520 | // |
| 521 | // This function is quite similar to MipsSEDAGToDAGISel::selectVSplat. The |
| 522 | // differences are that it assumes the MSA has already been checked and the |
| 523 | // arbitrary requirement for a maximum of 32-bit integers isn't applied (and |
| 524 | // must not be in order for binsri.d to be selectable). |
| 525 | static bool isVSplat(SDValue N, APInt &Imm, bool IsLittleEndian) { |
| 526 | BuildVectorSDNode *Node = dyn_cast<BuildVectorSDNode>(N.getNode()); |
| 527 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 528 | if (!Node) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 529 | return false; |
| 530 | |
| 531 | APInt SplatValue, SplatUndef; |
| 532 | unsigned SplatBitSize; |
| 533 | bool HasAnyUndefs; |
| 534 | |
| 535 | if (!Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, |
| 536 | 8, !IsLittleEndian)) |
| 537 | return false; |
| 538 | |
| 539 | Imm = SplatValue; |
| 540 | |
| 541 | return true; |
| 542 | } |
| 543 | |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 544 | // Test whether the given node is an all-ones build_vector. |
| 545 | static bool isVectorAllOnes(SDValue N) { |
| 546 | // Look through bitcasts. Endianness doesn't matter because we are looking |
| 547 | // for an all-ones value. |
| 548 | if (N->getOpcode() == ISD::BITCAST) |
| 549 | N = N->getOperand(0); |
| 550 | |
| 551 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N); |
| 552 | |
| 553 | if (!BVN) |
| 554 | return false; |
| 555 | |
| 556 | APInt SplatValue, SplatUndef; |
| 557 | unsigned SplatBitSize; |
| 558 | bool HasAnyUndefs; |
| 559 | |
| 560 | // Endianness doesn't matter in this context because we are looking for |
| 561 | // an all-ones value. |
| 562 | if (BVN->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs)) |
| 563 | return SplatValue.isAllOnesValue(); |
| 564 | |
| 565 | return false; |
| 566 | } |
| 567 | |
| 568 | // Test whether N is the bitwise inverse of OfNode. |
| 569 | static bool isBitwiseInverse(SDValue N, SDValue OfNode) { |
| 570 | if (N->getOpcode() != ISD::XOR) |
| 571 | return false; |
| 572 | |
| 573 | if (isVectorAllOnes(N->getOperand(0))) |
| 574 | return N->getOperand(1) == OfNode; |
| 575 | |
| 576 | if (isVectorAllOnes(N->getOperand(1))) |
| 577 | return N->getOperand(0) == OfNode; |
| 578 | |
| 579 | return false; |
| 580 | } |
| 581 | |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 582 | // Perform combines where ISD::OR is the root node. |
| 583 | // |
| 584 | // Performs the following transformations: |
| 585 | // - (or (and $a, $mask), (and $b, $inv_mask)) => (vselect $mask, $a, $b) |
| 586 | // where $inv_mask is the bitwise inverse of $mask and the 'or' has a 128-bit |
| 587 | // vector type. |
| 588 | static SDValue performORCombine(SDNode *N, SelectionDAG &DAG, |
| 589 | TargetLowering::DAGCombinerInfo &DCI, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 590 | const MipsSubtarget &Subtarget) { |
| 591 | if (!Subtarget.hasMSA()) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 592 | return SDValue(); |
| 593 | |
| 594 | EVT Ty = N->getValueType(0); |
| 595 | |
| 596 | if (!Ty.is128BitVector()) |
| 597 | return SDValue(); |
| 598 | |
| 599 | SDValue Op0 = N->getOperand(0); |
| 600 | SDValue Op1 = N->getOperand(1); |
| 601 | |
| 602 | if (Op0->getOpcode() == ISD::AND && Op1->getOpcode() == ISD::AND) { |
| 603 | SDValue Op0Op0 = Op0->getOperand(0); |
| 604 | SDValue Op0Op1 = Op0->getOperand(1); |
| 605 | SDValue Op1Op0 = Op1->getOperand(0); |
| 606 | SDValue Op1Op1 = Op1->getOperand(1); |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 607 | bool IsLittleEndian = !Subtarget.isLittle(); |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 608 | |
| 609 | SDValue IfSet, IfClr, Cond; |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 610 | bool IsConstantMask = false; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 611 | APInt Mask, InvMask; |
| 612 | |
| 613 | // If Op0Op0 is an appropriate mask, try to find it's inverse in either |
| 614 | // Op1Op0, or Op1Op1. Keep track of the Cond, IfSet, and IfClr nodes, while |
| 615 | // looking. |
| 616 | // IfClr will be set if we find a valid match. |
| 617 | if (isVSplat(Op0Op0, Mask, IsLittleEndian)) { |
| 618 | Cond = Op0Op0; |
| 619 | IfSet = Op0Op1; |
| 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; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | // If IfClr is not yet set, and Op0Op1 is an appropriate mask, try the same |
| 632 | // thing again using this mask. |
| 633 | // IfClr will be set if we find a valid match. |
| 634 | if (!IfClr.getNode() && isVSplat(Op0Op1, Mask, IsLittleEndian)) { |
| 635 | Cond = Op0Op1; |
| 636 | IfSet = Op0Op0; |
| 637 | |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 638 | if (isVSplat(Op1Op0, InvMask, IsLittleEndian) && |
| 639 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 640 | IfClr = Op1Op1; |
Daniel Sanders | c8c50fb | 2013-11-21 16:11:31 +0000 | [diff] [blame] | 641 | else if (isVSplat(Op1Op1, InvMask, IsLittleEndian) && |
| 642 | Mask.getBitWidth() == InvMask.getBitWidth() && Mask == ~InvMask) |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 643 | IfClr = Op1Op0; |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 644 | |
| 645 | IsConstantMask = true; |
| 646 | } |
| 647 | |
| 648 | // If IfClr is not yet set, try looking for a non-constant match. |
| 649 | // IfClr will be set if we find a valid match amongst the eight |
| 650 | // possibilities. |
| 651 | if (!IfClr.getNode()) { |
| 652 | if (isBitwiseInverse(Op0Op0, Op1Op0)) { |
| 653 | Cond = Op1Op0; |
| 654 | IfSet = Op1Op1; |
| 655 | IfClr = Op0Op1; |
| 656 | } else if (isBitwiseInverse(Op0Op1, Op1Op0)) { |
| 657 | Cond = Op1Op0; |
| 658 | IfSet = Op1Op1; |
| 659 | IfClr = Op0Op0; |
| 660 | } else if (isBitwiseInverse(Op0Op0, Op1Op1)) { |
| 661 | Cond = Op1Op1; |
| 662 | IfSet = Op1Op0; |
| 663 | IfClr = Op0Op1; |
| 664 | } else if (isBitwiseInverse(Op0Op1, Op1Op1)) { |
| 665 | Cond = Op1Op1; |
| 666 | IfSet = Op1Op0; |
| 667 | IfClr = Op0Op0; |
| 668 | } else if (isBitwiseInverse(Op1Op0, Op0Op0)) { |
| 669 | Cond = Op0Op0; |
| 670 | IfSet = Op0Op1; |
| 671 | IfClr = Op1Op1; |
| 672 | } else if (isBitwiseInverse(Op1Op1, Op0Op0)) { |
| 673 | Cond = Op0Op0; |
| 674 | IfSet = Op0Op1; |
| 675 | IfClr = Op1Op0; |
| 676 | } else if (isBitwiseInverse(Op1Op0, Op0Op1)) { |
| 677 | Cond = Op0Op1; |
| 678 | IfSet = Op0Op0; |
| 679 | IfClr = Op1Op1; |
| 680 | } else if (isBitwiseInverse(Op1Op1, Op0Op1)) { |
| 681 | Cond = Op0Op1; |
| 682 | IfSet = Op0Op0; |
| 683 | IfClr = Op1Op0; |
| 684 | } |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | // At this point, IfClr will be set if we have a valid match. |
| 688 | if (!IfClr.getNode()) |
| 689 | return SDValue(); |
| 690 | |
| 691 | assert(Cond.getNode() && IfSet.getNode()); |
| 692 | |
| 693 | // Fold degenerate cases. |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 694 | if (IsConstantMask) { |
| 695 | if (Mask.isAllOnesValue()) |
| 696 | return IfSet; |
| 697 | else if (Mask == 0) |
| 698 | return IfClr; |
| 699 | } |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 700 | |
| 701 | // Transform the DAG into an equivalent VSELECT. |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 702 | return DAG.getNode(ISD::VSELECT, SDLoc(N), Ty, Cond, IfSet, IfClr); |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | return SDValue(); |
| 706 | } |
| 707 | |
Simon Dardis | 9ec9f44 | 2018-04-13 16:09:07 +0000 | [diff] [blame] | 708 | static bool shouldTransformMulToShiftsAddsSubs(APInt C, EVT VT, |
| 709 | SelectionDAG &DAG, |
| 710 | const MipsSubtarget &Subtarget) { |
| 711 | // Estimate the number of operations the below transform will turn a |
| 712 | // constant multiply into. The number is approximately how many powers |
| 713 | // of two summed together that the constant can be broken down into. |
| 714 | |
| 715 | SmallVector<APInt, 16> WorkStack(1, C); |
| 716 | unsigned Steps = 0; |
| 717 | unsigned BitWidth = C.getBitWidth(); |
| 718 | |
| 719 | while (!WorkStack.empty()) { |
| 720 | APInt Val = WorkStack.pop_back_val(); |
| 721 | |
| 722 | if (Val == 0 || Val == 1) |
| 723 | continue; |
| 724 | |
| 725 | if (Val.isPowerOf2()) { |
| 726 | ++Steps; |
| 727 | continue; |
| 728 | } |
| 729 | |
| 730 | APInt Floor = APInt(BitWidth, 1) << Val.logBase2(); |
| 731 | APInt Ceil = Val.isNegative() ? APInt(BitWidth, 0) |
| 732 | : APInt(BitWidth, 1) << C.ceilLogBase2(); |
| 733 | |
| 734 | if ((Val - Floor).ule(Ceil - Val)) { |
| 735 | WorkStack.push_back(Floor); |
| 736 | WorkStack.push_back(Val - Floor); |
| 737 | ++Steps; |
| 738 | continue; |
| 739 | } |
| 740 | |
| 741 | WorkStack.push_back(Ceil); |
| 742 | WorkStack.push_back(Ceil - Val); |
| 743 | ++Steps; |
| 744 | |
| 745 | // If we have taken more than 12[1] / 8[2] steps to attempt the |
| 746 | // optimization for a native sized value, it is more than likely that this |
| 747 | // optimization will make things worse. |
| 748 | // |
| 749 | // [1] MIPS64 requires 6 instructions at most to materialize any constant, |
| 750 | // multiplication requires at least 4 cycles, but another cycle (or two) |
| 751 | // to retrieve the result from the HI/LO registers. |
| 752 | // |
| 753 | // [2] For MIPS32, more than 8 steps is expensive as the constant could be |
| 754 | // materialized in 2 instructions, multiplication requires at least 4 |
| 755 | // cycles, but another cycle (or two) to retrieve the result from the |
| 756 | // HI/LO registers. |
| 757 | |
| 758 | if (Steps > 12 && (Subtarget.isABI_N32() || Subtarget.isABI_N64())) |
| 759 | return false; |
| 760 | |
| 761 | if (Steps > 8 && Subtarget.isABI_O32()) |
| 762 | return false; |
| 763 | } |
| 764 | |
| 765 | // If the value being multiplied is not supported natively, we have to pay |
| 766 | // an additional legalization cost, conservatively assume an increase in the |
| 767 | // cost of 3 instructions per step. This values for this heuristic were |
| 768 | // determined experimentally. |
| 769 | unsigned RegisterSize = DAG.getTargetLoweringInfo() |
| 770 | .getRegisterType(*DAG.getContext(), VT) |
| 771 | .getSizeInBits(); |
| 772 | Steps *= (VT.getSizeInBits() != RegisterSize) * 3; |
| 773 | if (Steps > 27) |
| 774 | return false; |
| 775 | |
| 776 | return true; |
| 777 | } |
| 778 | |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 779 | static SDValue genConstMult(SDValue X, APInt C, const SDLoc &DL, EVT VT, |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 780 | EVT ShiftTy, SelectionDAG &DAG) { |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 781 | // Return 0. |
| 782 | if (C == 0) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 783 | return DAG.getConstant(0, DL, VT); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 784 | |
| 785 | // Return x. |
| 786 | if (C == 1) |
| 787 | return X; |
| 788 | |
| 789 | // If c is power of 2, return (shl x, log2(c)). |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 790 | if (C.isPowerOf2()) |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 791 | return DAG.getNode(ISD::SHL, DL, VT, X, |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 792 | DAG.getConstant(C.logBase2(), DL, ShiftTy)); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 793 | |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 794 | unsigned BitWidth = C.getBitWidth(); |
| 795 | APInt Floor = APInt(BitWidth, 1) << C.logBase2(); |
| 796 | APInt Ceil = C.isNegative() ? APInt(BitWidth, 0) : |
| 797 | APInt(BitWidth, 1) << C.ceilLogBase2(); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 798 | |
| 799 | // If |c - floor_c| <= |c - ceil_c|, |
| 800 | // where floor_c = pow(2, floor(log2(c))) and ceil_c = pow(2, ceil(log2(c))), |
| 801 | // return (add constMult(x, floor_c), constMult(x, c - floor_c)). |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 802 | if ((C - Floor).ule(Ceil - C)) { |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 803 | SDValue Op0 = genConstMult(X, Floor, DL, VT, ShiftTy, DAG); |
| 804 | SDValue Op1 = genConstMult(X, C - Floor, DL, VT, ShiftTy, DAG); |
| 805 | return DAG.getNode(ISD::ADD, DL, VT, Op0, Op1); |
| 806 | } |
| 807 | |
| 808 | // If |c - floor_c| > |c - ceil_c|, |
| 809 | // return (sub constMult(x, ceil_c), constMult(x, ceil_c - c)). |
| 810 | SDValue Op0 = genConstMult(X, Ceil, DL, VT, ShiftTy, DAG); |
| 811 | SDValue Op1 = genConstMult(X, Ceil - C, DL, VT, ShiftTy, DAG); |
| 812 | return DAG.getNode(ISD::SUB, DL, VT, Op0, Op1); |
| 813 | } |
| 814 | |
| 815 | static SDValue performMULCombine(SDNode *N, SelectionDAG &DAG, |
| 816 | const TargetLowering::DAGCombinerInfo &DCI, |
Simon Dardis | 9ec9f44 | 2018-04-13 16:09:07 +0000 | [diff] [blame] | 817 | const MipsSETargetLowering *TL, |
| 818 | const MipsSubtarget &Subtarget) { |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 819 | EVT VT = N->getValueType(0); |
| 820 | |
| 821 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1))) |
Simon Dardis | 9ec9f44 | 2018-04-13 16:09:07 +0000 | [diff] [blame] | 822 | if (!VT.isVector() && shouldTransformMulToShiftsAddsSubs( |
| 823 | C->getAPIntValue(), VT, DAG, Subtarget)) |
Petar Jovanovic | cd729ea | 2017-11-15 15:24:04 +0000 | [diff] [blame] | 824 | return genConstMult(N->getOperand(0), C->getAPIntValue(), SDLoc(N), VT, |
Mehdi Amini | eaabc51 | 2015-07-09 15:12:23 +0000 | [diff] [blame] | 825 | TL->getScalarShiftAmountTy(DAG.getDataLayout(), VT), |
| 826 | DAG); |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 827 | |
| 828 | return SDValue(N, 0); |
| 829 | } |
| 830 | |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 831 | static SDValue performDSPShiftCombine(unsigned Opc, SDNode *N, EVT Ty, |
| 832 | SelectionDAG &DAG, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 833 | const MipsSubtarget &Subtarget) { |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 834 | // See if this is a vector splat immediate node. |
| 835 | APInt SplatValue, SplatUndef; |
| 836 | unsigned SplatBitSize; |
| 837 | bool HasAnyUndefs; |
Sanjay Patel | 1ed771f | 2016-09-14 16:37:15 +0000 | [diff] [blame] | 838 | unsigned EltSize = Ty.getScalarSizeInBits(); |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 839 | BuildVectorSDNode *BV = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 840 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 841 | if (!Subtarget.hasDSP()) |
Daniel Sanders | 6e664bc | 2013-11-21 11:40:14 +0000 | [diff] [blame] | 842 | return SDValue(); |
| 843 | |
Akira Hatanaka | 0d6964c | 2013-04-22 19:58:23 +0000 | [diff] [blame] | 844 | if (!BV || |
Akira Hatanaka | d8fb032 | 2013-04-22 20:13:37 +0000 | [diff] [blame] | 845 | !BV->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, HasAnyUndefs, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 846 | EltSize, !Subtarget.isLittle()) || |
Akira Hatanaka | 0d6964c | 2013-04-22 19:58:23 +0000 | [diff] [blame] | 847 | (SplatBitSize != EltSize) || |
Akira Hatanaka | e9d0b31 | 2013-04-23 18:09:42 +0000 | [diff] [blame] | 848 | (SplatValue.getZExtValue() >= EltSize)) |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 849 | return SDValue(); |
| 850 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 851 | SDLoc DL(N); |
| 852 | return DAG.getNode(Opc, DL, Ty, N->getOperand(0), |
| 853 | DAG.getConstant(SplatValue.getZExtValue(), DL, MVT::i32)); |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static SDValue performSHLCombine(SDNode *N, SelectionDAG &DAG, |
| 857 | TargetLowering::DAGCombinerInfo &DCI, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 858 | const MipsSubtarget &Subtarget) { |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 859 | EVT Ty = N->getValueType(0); |
| 860 | |
| 861 | if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) |
| 862 | return SDValue(); |
| 863 | |
| 864 | return performDSPShiftCombine(MipsISD::SHLL_DSP, N, Ty, DAG, Subtarget); |
| 865 | } |
| 866 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 867 | // Fold sign-extensions into MipsISD::VEXTRACT_[SZ]EXT_ELT for MSA and fold |
| 868 | // constant splats into MipsISD::SHRA_DSP for DSPr2. |
| 869 | // |
| 870 | // Performs the following transformations: |
| 871 | // - Changes MipsISD::VEXTRACT_[SZ]EXT_ELT to sign extension if its |
| 872 | // sign/zero-extension is completely overwritten by the new one performed by |
| 873 | // the ISD::SRA and ISD::SHL nodes. |
| 874 | // - Removes redundant sign extensions performed by an ISD::SRA and ISD::SHL |
| 875 | // sequence. |
| 876 | // |
| 877 | // See performDSPShiftCombine for more information about the transformation |
| 878 | // used for DSPr2. |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 879 | static SDValue performSRACombine(SDNode *N, SelectionDAG &DAG, |
| 880 | TargetLowering::DAGCombinerInfo &DCI, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 881 | const MipsSubtarget &Subtarget) { |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 882 | EVT Ty = N->getValueType(0); |
| 883 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 884 | if (Subtarget.hasMSA()) { |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 885 | SDValue Op0 = N->getOperand(0); |
| 886 | SDValue Op1 = N->getOperand(1); |
| 887 | |
| 888 | // (sra (shl (MipsVExtract[SZ]Ext $a, $b, $c), imm:$d), imm:$d) |
| 889 | // where $d + sizeof($c) == 32 |
| 890 | // or $d + sizeof($c) <= 32 and SExt |
| 891 | // -> (MipsVExtractSExt $a, $b, $c) |
| 892 | if (Op0->getOpcode() == ISD::SHL && Op1 == Op0->getOperand(1)) { |
| 893 | SDValue Op0Op0 = Op0->getOperand(0); |
| 894 | ConstantSDNode *ShAmount = dyn_cast<ConstantSDNode>(Op1); |
| 895 | |
| 896 | if (!ShAmount) |
| 897 | return SDValue(); |
| 898 | |
Daniel Sanders | f4f1a87 | 2013-09-27 09:25:29 +0000 | [diff] [blame] | 899 | if (Op0Op0->getOpcode() != MipsISD::VEXTRACT_SEXT_ELT && |
| 900 | Op0Op0->getOpcode() != MipsISD::VEXTRACT_ZEXT_ELT) |
| 901 | return SDValue(); |
| 902 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 903 | EVT ExtendTy = cast<VTSDNode>(Op0Op0->getOperand(2))->getVT(); |
| 904 | unsigned TotalBits = ShAmount->getZExtValue() + ExtendTy.getSizeInBits(); |
| 905 | |
| 906 | if (TotalBits == 32 || |
| 907 | (Op0Op0->getOpcode() == MipsISD::VEXTRACT_SEXT_ELT && |
| 908 | TotalBits <= 32)) { |
| 909 | SDValue Ops[] = { Op0Op0->getOperand(0), Op0Op0->getOperand(1), |
| 910 | Op0Op0->getOperand(2) }; |
Chandler Carruth | 356665a | 2014-08-01 22:09:43 +0000 | [diff] [blame] | 911 | return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, SDLoc(Op0Op0), |
| 912 | Op0Op0->getVTList(), |
| 913 | makeArrayRef(Ops, Op0Op0->getNumOperands())); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | } |
| 917 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 918 | if ((Ty != MVT::v2i16) && ((Ty != MVT::v4i8) || !Subtarget.hasDSPR2())) |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 919 | return SDValue(); |
| 920 | |
| 921 | return performDSPShiftCombine(MipsISD::SHRA_DSP, N, Ty, DAG, Subtarget); |
| 922 | } |
| 923 | |
| 924 | |
| 925 | static SDValue performSRLCombine(SDNode *N, SelectionDAG &DAG, |
| 926 | TargetLowering::DAGCombinerInfo &DCI, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 927 | const MipsSubtarget &Subtarget) { |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 928 | EVT Ty = N->getValueType(0); |
| 929 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 930 | if (((Ty != MVT::v2i16) || !Subtarget.hasDSPR2()) && (Ty != MVT::v4i8)) |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 931 | return SDValue(); |
| 932 | |
| 933 | return performDSPShiftCombine(MipsISD::SHRL_DSP, N, Ty, DAG, Subtarget); |
| 934 | } |
| 935 | |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 936 | static bool isLegalDSPCondCode(EVT Ty, ISD::CondCode CC) { |
| 937 | bool IsV216 = (Ty == MVT::v2i16); |
| 938 | |
| 939 | switch (CC) { |
| 940 | case ISD::SETEQ: |
| 941 | case ISD::SETNE: return true; |
| 942 | case ISD::SETLT: |
| 943 | case ISD::SETLE: |
| 944 | case ISD::SETGT: |
| 945 | case ISD::SETGE: return IsV216; |
| 946 | case ISD::SETULT: |
| 947 | case ISD::SETULE: |
| 948 | case ISD::SETUGT: |
| 949 | case ISD::SETUGE: return !IsV216; |
| 950 | default: return false; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | static SDValue performSETCCCombine(SDNode *N, SelectionDAG &DAG) { |
| 955 | EVT Ty = N->getValueType(0); |
| 956 | |
| 957 | if ((Ty != MVT::v2i16) && (Ty != MVT::v4i8)) |
| 958 | return SDValue(); |
| 959 | |
| 960 | if (!isLegalDSPCondCode(Ty, cast<CondCodeSDNode>(N->getOperand(2))->get())) |
| 961 | return SDValue(); |
| 962 | |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 963 | return DAG.getNode(MipsISD::SETCC_DSP, SDLoc(N), Ty, N->getOperand(0), |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 964 | N->getOperand(1), N->getOperand(2)); |
| 965 | } |
| 966 | |
| 967 | static SDValue performVSELECTCombine(SDNode *N, SelectionDAG &DAG) { |
| 968 | EVT Ty = N->getValueType(0); |
| 969 | |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 970 | if (Ty == MVT::v2i16 || Ty == MVT::v4i8) { |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 971 | SDValue SetCC = N->getOperand(0); |
| 972 | |
| 973 | if (SetCC.getOpcode() != MipsISD::SETCC_DSP) |
| 974 | return SDValue(); |
| 975 | |
| 976 | return DAG.getNode(MipsISD::SELECT_CC_DSP, SDLoc(N), Ty, |
| 977 | SetCC.getOperand(0), SetCC.getOperand(1), |
| 978 | N->getOperand(1), N->getOperand(2), SetCC.getOperand(2)); |
| 979 | } |
| 980 | |
| 981 | return SDValue(); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 982 | } |
| 983 | |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 984 | static SDValue performXORCombine(SDNode *N, SelectionDAG &DAG, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 985 | const MipsSubtarget &Subtarget) { |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 986 | EVT Ty = N->getValueType(0); |
| 987 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 988 | if (Subtarget.hasMSA() && Ty.is128BitVector() && Ty.isInteger()) { |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 989 | // Try the following combines: |
| 990 | // (xor (or $a, $b), (build_vector allones)) |
| 991 | // (xor (or $a, $b), (bitcast (build_vector allones))) |
| 992 | SDValue Op0 = N->getOperand(0); |
| 993 | SDValue Op1 = N->getOperand(1); |
| 994 | SDValue NotOp; |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 995 | |
| 996 | if (ISD::isBuildVectorAllOnes(Op0.getNode())) |
| 997 | NotOp = Op1; |
| 998 | else if (ISD::isBuildVectorAllOnes(Op1.getNode())) |
| 999 | NotOp = Op0; |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 1000 | else |
| 1001 | return SDValue(); |
| 1002 | |
| 1003 | if (NotOp->getOpcode() == ISD::OR) |
| 1004 | return DAG.getNode(MipsISD::VNOR, SDLoc(N), Ty, NotOp->getOperand(0), |
| 1005 | NotOp->getOperand(1)); |
| 1006 | } |
| 1007 | |
| 1008 | return SDValue(); |
| 1009 | } |
| 1010 | |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1011 | SDValue |
| 1012 | MipsSETargetLowering::PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const { |
| 1013 | SelectionDAG &DAG = DCI.DAG; |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1014 | SDValue Val; |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1015 | |
| 1016 | switch (N->getOpcode()) { |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1017 | case ISD::AND: |
| 1018 | Val = performANDCombine(N, DAG, DCI, Subtarget); |
| 1019 | break; |
Daniel Sanders | 53fe6c4 | 2013-10-30 13:51:01 +0000 | [diff] [blame] | 1020 | case ISD::OR: |
| 1021 | Val = performORCombine(N, DAG, DCI, Subtarget); |
| 1022 | break; |
Akira Hatanaka | 5832fc6 | 2013-06-26 18:48:17 +0000 | [diff] [blame] | 1023 | case ISD::MUL: |
Simon Dardis | 9ec9f44 | 2018-04-13 16:09:07 +0000 | [diff] [blame] | 1024 | return performMULCombine(N, DAG, DCI, this, Subtarget); |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 1025 | case ISD::SHL: |
Petar Jovanovic | b71386a | 2017-03-15 13:10:08 +0000 | [diff] [blame] | 1026 | Val = performSHLCombine(N, DAG, DCI, Subtarget); |
| 1027 | break; |
Akira Hatanaka | 1ebb2a1 | 2013-04-19 23:21:32 +0000 | [diff] [blame] | 1028 | case ISD::SRA: |
| 1029 | return performSRACombine(N, DAG, DCI, Subtarget); |
| 1030 | case ISD::SRL: |
| 1031 | return performSRLCombine(N, DAG, DCI, Subtarget); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1032 | case ISD::VSELECT: |
| 1033 | return performVSELECTCombine(N, DAG); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 1034 | case ISD::XOR: |
| 1035 | Val = performXORCombine(N, DAG, Subtarget); |
| 1036 | break; |
| 1037 | case ISD::SETCC: |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1038 | Val = performSETCCCombine(N, DAG); |
| 1039 | break; |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1040 | } |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1041 | |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 1042 | if (Val.getNode()) { |
| 1043 | DEBUG(dbgs() << "\nMipsSE DAG Combine:\n"; |
| 1044 | N->printrWithDepth(dbgs(), &DAG); |
| 1045 | dbgs() << "\n=> \n"; |
| 1046 | Val.getNode()->printrWithDepth(dbgs(), &DAG); |
| 1047 | dbgs() << "\n"); |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1048 | return Val; |
Daniel Sanders | 62aeab8 | 2013-10-30 13:31:27 +0000 | [diff] [blame] | 1049 | } |
Akira Hatanaka | 68741cc | 2013-04-30 22:37:26 +0000 | [diff] [blame] | 1050 | |
| 1051 | return MipsTargetLowering::PerformDAGCombine(N, DCI); |
Akira Hatanaka | 9efcd76 | 2013-03-30 01:42:24 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1054 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 1055 | MipsSETargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI, |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1056 | MachineBasicBlock *BB) const { |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 1057 | switch (MI.getOpcode()) { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1058 | default: |
| 1059 | return MipsTargetLowering::EmitInstrWithCustomInserter(MI, BB); |
| 1060 | case Mips::BPOSGE32_PSEUDO: |
| 1061 | return emitBPOSGE32(MI, BB); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1062 | case Mips::SNZ_B_PSEUDO: |
| 1063 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_B); |
| 1064 | case Mips::SNZ_H_PSEUDO: |
| 1065 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_H); |
| 1066 | case Mips::SNZ_W_PSEUDO: |
| 1067 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_W); |
| 1068 | case Mips::SNZ_D_PSEUDO: |
| 1069 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_D); |
| 1070 | case Mips::SNZ_V_PSEUDO: |
| 1071 | return emitMSACBranchPseudo(MI, BB, Mips::BNZ_V); |
| 1072 | case Mips::SZ_B_PSEUDO: |
| 1073 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_B); |
| 1074 | case Mips::SZ_H_PSEUDO: |
| 1075 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_H); |
| 1076 | case Mips::SZ_W_PSEUDO: |
| 1077 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_W); |
| 1078 | case Mips::SZ_D_PSEUDO: |
| 1079 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_D); |
| 1080 | case Mips::SZ_V_PSEUDO: |
| 1081 | return emitMSACBranchPseudo(MI, BB, Mips::BZ_V); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 1082 | case Mips::COPY_FW_PSEUDO: |
| 1083 | return emitCOPY_FW(MI, BB); |
| 1084 | case Mips::COPY_FD_PSEUDO: |
| 1085 | return emitCOPY_FD(MI, BB); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 1086 | case Mips::INSERT_FW_PSEUDO: |
| 1087 | return emitINSERT_FW(MI, BB); |
| 1088 | case Mips::INSERT_FD_PSEUDO: |
| 1089 | return emitINSERT_FD(MI, BB); |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1090 | case Mips::INSERT_B_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1091 | case Mips::INSERT_B_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1092 | return emitINSERT_DF_VIDX(MI, BB, 1, false); |
| 1093 | case Mips::INSERT_H_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1094 | case Mips::INSERT_H_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1095 | return emitINSERT_DF_VIDX(MI, BB, 2, false); |
| 1096 | case Mips::INSERT_W_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1097 | case Mips::INSERT_W_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1098 | return emitINSERT_DF_VIDX(MI, BB, 4, false); |
| 1099 | case Mips::INSERT_D_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1100 | case Mips::INSERT_D_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1101 | return emitINSERT_DF_VIDX(MI, BB, 8, false); |
| 1102 | case Mips::INSERT_FW_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1103 | case Mips::INSERT_FW_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1104 | return emitINSERT_DF_VIDX(MI, BB, 4, true); |
| 1105 | case Mips::INSERT_FD_VIDX_PSEUDO: |
Daniel Sanders | eda60d2 | 2015-05-05 10:32:24 +0000 | [diff] [blame] | 1106 | case Mips::INSERT_FD_VIDX64_PSEUDO: |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 1107 | return emitINSERT_DF_VIDX(MI, BB, 8, true); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 1108 | case Mips::FILL_FW_PSEUDO: |
| 1109 | return emitFILL_FW(MI, BB); |
| 1110 | case Mips::FILL_FD_PSEUDO: |
| 1111 | return emitFILL_FD(MI, BB); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 1112 | case Mips::FEXP2_W_1_PSEUDO: |
| 1113 | return emitFEXP2_W_1(MI, BB); |
| 1114 | case Mips::FEXP2_D_1_PSEUDO: |
| 1115 | return emitFEXP2_D_1(MI, BB); |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 1116 | case Mips::ST_F16: |
| 1117 | return emitST_F16_PSEUDO(MI, BB); |
| 1118 | case Mips::LD_F16: |
| 1119 | return emitLD_F16_PSEUDO(MI, BB); |
| 1120 | case Mips::MSA_FP_EXTEND_W_PSEUDO: |
| 1121 | return emitFPEXTEND_PSEUDO(MI, BB, false); |
| 1122 | case Mips::MSA_FP_ROUND_W_PSEUDO: |
| 1123 | return emitFPROUND_PSEUDO(MI, BB, false); |
| 1124 | case Mips::MSA_FP_EXTEND_D_PSEUDO: |
| 1125 | return emitFPEXTEND_PSEUDO(MI, BB, true); |
| 1126 | case Mips::MSA_FP_ROUND_D_PSEUDO: |
| 1127 | return emitFPROUND_PSEUDO(MI, BB, true); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
Daniel Sanders | 23e9877 | 2014-11-02 16:09:29 +0000 | [diff] [blame] | 1131 | bool MipsSETargetLowering::isEligibleForTailCallOptimization( |
| 1132 | const CCState &CCInfo, unsigned NextStackOffset, |
| 1133 | const MipsFunctionInfo &FI) const { |
Simon Dardis | 57f4ae4 | 2016-08-04 09:17:07 +0000 | [diff] [blame] | 1134 | if (!UseMipsTailCalls) |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1135 | return false; |
| 1136 | |
Vasileios Kalintiris | 43dff0c | 2015-10-26 12:38:43 +0000 | [diff] [blame] | 1137 | // Exception has to be cleared with eret. |
| 1138 | if (FI.isISR()) |
| 1139 | return false; |
| 1140 | |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1141 | // Return false if either the callee or caller has a byval argument. |
Daniel Sanders | 23e9877 | 2014-11-02 16:09:29 +0000 | [diff] [blame] | 1142 | if (CCInfo.getInRegsParamsCount() > 0 || FI.hasByvalArg()) |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1143 | return false; |
| 1144 | |
| 1145 | // Return true if the callee's argument area is no larger than the |
| 1146 | // caller's. |
| 1147 | return NextStackOffset <= FI.getIncomingArgSize(); |
| 1148 | } |
| 1149 | |
| 1150 | void MipsSETargetLowering:: |
| 1151 | getOpndList(SmallVectorImpl<SDValue> &Ops, |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1152 | std::deque<std::pair<unsigned, SDValue>> &RegsToPass, |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1153 | bool IsPICCall, bool GlobalOrExternal, bool InternalLinkage, |
Sasa Stankovic | 7072a79 | 2014-10-01 08:22:21 +0000 | [diff] [blame] | 1154 | bool IsCallReloc, CallLoweringInfo &CLI, SDValue Callee, |
| 1155 | SDValue Chain) const { |
Akira Hatanaka | 168d4e5 | 2013-11-27 23:38:42 +0000 | [diff] [blame] | 1156 | Ops.push_back(Callee); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1157 | MipsTargetLowering::getOpndList(Ops, RegsToPass, IsPICCall, GlobalOrExternal, |
Sasa Stankovic | 7072a79 | 2014-10-01 08:22:21 +0000 | [diff] [blame] | 1158 | InternalLinkage, IsCallReloc, CLI, Callee, |
| 1159 | Chain); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 1160 | } |
| 1161 | |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1162 | SDValue MipsSETargetLowering::lowerLOAD(SDValue Op, SelectionDAG &DAG) const { |
| 1163 | LoadSDNode &Nd = *cast<LoadSDNode>(Op); |
| 1164 | |
| 1165 | if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) |
| 1166 | return MipsTargetLowering::lowerLOAD(Op, DAG); |
| 1167 | |
| 1168 | // Replace a double precision load with two i32 loads and a buildpair64. |
| 1169 | SDLoc DL(Op); |
| 1170 | SDValue Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); |
| 1171 | EVT PtrVT = Ptr.getValueType(); |
| 1172 | |
| 1173 | // i32 load from lower address. |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1174 | SDValue Lo = DAG.getLoad(MVT::i32, DL, Chain, Ptr, MachinePointerInfo(), |
| 1175 | Nd.getAlignment(), Nd.getMemOperand()->getFlags()); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1176 | |
| 1177 | // i32 load from higher address. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1178 | Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT)); |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1179 | SDValue Hi = DAG.getLoad( |
| 1180 | MVT::i32, DL, Lo.getValue(1), Ptr, MachinePointerInfo(), |
| 1181 | std::min(Nd.getAlignment(), 4U), Nd.getMemOperand()->getFlags()); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1182 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1183 | if (!Subtarget.isLittle()) |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1184 | std::swap(Lo, Hi); |
| 1185 | |
| 1186 | SDValue BP = DAG.getNode(MipsISD::BuildPairF64, DL, MVT::f64, Lo, Hi); |
| 1187 | SDValue Ops[2] = {BP, Hi.getValue(1)}; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 1188 | return DAG.getMergeValues(Ops, DL); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | SDValue MipsSETargetLowering::lowerSTORE(SDValue Op, SelectionDAG &DAG) const { |
| 1192 | StoreSDNode &Nd = *cast<StoreSDNode>(Op); |
| 1193 | |
| 1194 | if (Nd.getMemoryVT() != MVT::f64 || !NoDPLoadStore) |
| 1195 | return MipsTargetLowering::lowerSTORE(Op, DAG); |
| 1196 | |
| 1197 | // Replace a double precision store with two extractelement64s and i32 stores. |
| 1198 | SDLoc DL(Op); |
| 1199 | SDValue Val = Nd.getValue(), Ptr = Nd.getBasePtr(), Chain = Nd.getChain(); |
| 1200 | EVT PtrVT = Ptr.getValueType(); |
| 1201 | SDValue Lo = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1202 | Val, DAG.getConstant(0, DL, MVT::i32)); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1203 | SDValue Hi = DAG.getNode(MipsISD::ExtractElementF64, DL, MVT::i32, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1204 | Val, DAG.getConstant(1, DL, MVT::i32)); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1205 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1206 | if (!Subtarget.isLittle()) |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1207 | std::swap(Lo, Hi); |
| 1208 | |
| 1209 | // i32 store to lower address. |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1210 | Chain = |
| 1211 | DAG.getStore(Chain, DL, Lo, Ptr, MachinePointerInfo(), Nd.getAlignment(), |
| 1212 | Nd.getMemOperand()->getFlags(), Nd.getAAInfo()); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1213 | |
| 1214 | // i32 store to higher address. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1215 | Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, Ptr, DAG.getConstant(4, DL, PtrVT)); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1216 | return DAG.getStore(Chain, DL, Hi, Ptr, MachinePointerInfo(), |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 1217 | std::min(Nd.getAlignment(), 4U), |
| 1218 | Nd.getMemOperand()->getFlags(), Nd.getAAInfo()); |
Akira Hatanaka | 6379121 | 2013-09-07 00:52:30 +0000 | [diff] [blame] | 1219 | } |
| 1220 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1221 | SDValue MipsSETargetLowering::lowerMulDiv(SDValue Op, unsigned NewOpc, |
| 1222 | bool HasLo, bool HasHi, |
| 1223 | SelectionDAG &DAG) const { |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 1224 | // MIPS32r6/MIPS64r6 removed accumulator based multiplies. |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1225 | assert(!Subtarget.hasMips32r6()); |
Daniel Sanders | 308181e | 2014-06-12 10:44:10 +0000 | [diff] [blame] | 1226 | |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1227 | EVT Ty = Op.getOperand(0).getValueType(); |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1228 | SDLoc DL(Op); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1229 | SDValue Mult = DAG.getNode(NewOpc, DL, MVT::Untyped, |
| 1230 | Op.getOperand(0), Op.getOperand(1)); |
| 1231 | SDValue Lo, Hi; |
| 1232 | |
| 1233 | if (HasLo) |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1234 | Lo = DAG.getNode(MipsISD::MFLO, DL, Ty, Mult); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1235 | if (HasHi) |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1236 | Hi = DAG.getNode(MipsISD::MFHI, DL, Ty, Mult); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1237 | |
| 1238 | if (!HasLo || !HasHi) |
| 1239 | return HasLo ? Lo : Hi; |
| 1240 | |
| 1241 | SDValue Vals[] = { Lo, Hi }; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 1242 | return DAG.getMergeValues(Vals, DL); |
Akira Hatanaka | be8612f | 2013-03-30 01:36:35 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1245 | static SDValue initAccumulator(SDValue In, const SDLoc &DL, SelectionDAG &DAG) { |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1246 | SDValue InLo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1247 | DAG.getConstant(0, DL, MVT::i32)); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1248 | SDValue InHi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, In, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1249 | DAG.getConstant(1, DL, MVT::i32)); |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1250 | return DAG.getNode(MipsISD::MTLOHI, DL, MVT::Untyped, InLo, InHi); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Benjamin Kramer | bdc4956 | 2016-06-12 15:39:02 +0000 | [diff] [blame] | 1253 | static SDValue extractLOHI(SDValue Op, const SDLoc &DL, SelectionDAG &DAG) { |
Akira Hatanaka | d98c99f | 2013-10-15 01:12:50 +0000 | [diff] [blame] | 1254 | SDValue Lo = DAG.getNode(MipsISD::MFLO, DL, MVT::i32, Op); |
| 1255 | SDValue Hi = DAG.getNode(MipsISD::MFHI, DL, MVT::i32, Op); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1256 | return DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Lo, Hi); |
| 1257 | } |
| 1258 | |
| 1259 | // This function expands mips intrinsic nodes which have 64-bit input operands |
| 1260 | // or output values. |
| 1261 | // |
| 1262 | // out64 = intrinsic-node in64 |
| 1263 | // => |
| 1264 | // lo = copy (extract-element (in64, 0)) |
| 1265 | // hi = copy (extract-element (in64, 1)) |
| 1266 | // mips-specific-node |
| 1267 | // v0 = copy lo |
| 1268 | // v1 = copy hi |
| 1269 | // out64 = merge-values (v0, v1) |
| 1270 | // |
| 1271 | static SDValue lowerDSPIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { |
Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1272 | SDLoc DL(Op); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1273 | bool HasChainIn = Op->getOperand(0).getValueType() == MVT::Other; |
| 1274 | SmallVector<SDValue, 3> Ops; |
| 1275 | unsigned OpNo = 0; |
| 1276 | |
| 1277 | // See if Op has a chain input. |
| 1278 | if (HasChainIn) |
| 1279 | Ops.push_back(Op->getOperand(OpNo++)); |
| 1280 | |
| 1281 | // The next operand is the intrinsic opcode. |
| 1282 | assert(Op->getOperand(OpNo).getOpcode() == ISD::TargetConstant); |
| 1283 | |
| 1284 | // See if the next operand has type i64. |
| 1285 | SDValue Opnd = Op->getOperand(++OpNo), In64; |
| 1286 | |
| 1287 | if (Opnd.getValueType() == MVT::i64) |
| 1288 | In64 = initAccumulator(Opnd, DL, DAG); |
| 1289 | else |
| 1290 | Ops.push_back(Opnd); |
| 1291 | |
| 1292 | // Push the remaining operands. |
| 1293 | for (++OpNo ; OpNo < Op->getNumOperands(); ++OpNo) |
| 1294 | Ops.push_back(Op->getOperand(OpNo)); |
| 1295 | |
| 1296 | // Add In64 to the end of the list. |
| 1297 | if (In64.getNode()) |
| 1298 | Ops.push_back(In64); |
| 1299 | |
| 1300 | // Scan output. |
| 1301 | SmallVector<EVT, 2> ResTys; |
| 1302 | |
| 1303 | for (SDNode::value_iterator I = Op->value_begin(), E = Op->value_end(); |
| 1304 | I != E; ++I) |
| 1305 | ResTys.push_back((*I == MVT::i64) ? MVT::Untyped : *I); |
| 1306 | |
| 1307 | // Create node. |
Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1308 | SDValue Val = DAG.getNode(Opc, DL, ResTys, Ops); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1309 | SDValue Out = (ResTys[0] == MVT::Untyped) ? extractLOHI(Val, DL, DAG) : Val; |
| 1310 | |
| 1311 | if (!HasChainIn) |
| 1312 | return Out; |
| 1313 | |
| 1314 | assert(Val->getValueType(1) == MVT::Other); |
| 1315 | SDValue Vals[] = { Out, SDValue(Val.getNode(), 1) }; |
Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 1316 | return DAG.getMergeValues(Vals, DL); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1317 | } |
| 1318 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1319 | // Lower an MSA copy intrinsic into the specified SelectionDAG node |
| 1320 | static SDValue lowerMSACopyIntr(SDValue Op, SelectionDAG &DAG, unsigned Opc) { |
| 1321 | SDLoc DL(Op); |
| 1322 | SDValue Vec = Op->getOperand(1); |
| 1323 | SDValue Idx = Op->getOperand(2); |
| 1324 | EVT ResTy = Op->getValueType(0); |
| 1325 | EVT EltTy = Vec->getValueType(0).getVectorElementType(); |
| 1326 | |
| 1327 | SDValue Result = DAG.getNode(Opc, DL, ResTy, Vec, Idx, |
| 1328 | DAG.getValueType(EltTy)); |
| 1329 | |
| 1330 | return Result; |
| 1331 | } |
| 1332 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1333 | static SDValue lowerMSASplatZExt(SDValue Op, unsigned OpNr, SelectionDAG &DAG) { |
| 1334 | EVT ResVecTy = Op->getValueType(0); |
| 1335 | EVT ViaVecTy = ResVecTy; |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1336 | bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian(); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1337 | SDLoc DL(Op); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1338 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1339 | // When ResVecTy == MVT::v2i64, LaneA is the upper 32 bits of the lane and |
| 1340 | // LaneB is the lower 32-bits. Otherwise LaneA and LaneB are alternating |
| 1341 | // lanes. |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1342 | SDValue LaneA = Op->getOperand(OpNr); |
| 1343 | SDValue LaneB; |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1344 | |
| 1345 | if (ResVecTy == MVT::v2i64) { |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1346 | LaneB = DAG.getConstant(0, DL, MVT::i32); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1347 | ViaVecTy = MVT::v4i32; |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1348 | if(BigEndian) |
| 1349 | std::swap(LaneA, LaneB); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1350 | } else |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1351 | LaneB = LaneA; |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1352 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1353 | SDValue Ops[16] = { LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, |
| 1354 | LaneA, LaneB, LaneA, LaneB, LaneA, LaneB, LaneA, LaneB }; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1355 | |
Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 1356 | SDValue Result = DAG.getBuildVector( |
| 1357 | ViaVecTy, DL, makeArrayRef(Ops, ViaVecTy.getVectorNumElements())); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1358 | |
Stefan Maksimovic | b794c0a | 2017-06-23 09:09:31 +0000 | [diff] [blame] | 1359 | if (ViaVecTy != ResVecTy) { |
| 1360 | SDValue One = DAG.getConstant(1, DL, ViaVecTy); |
| 1361 | Result = DAG.getNode(ISD::BITCAST, DL, ResVecTy, |
| 1362 | DAG.getNode(ISD::AND, DL, ViaVecTy, Result, One)); |
| 1363 | } |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1364 | |
| 1365 | return Result; |
| 1366 | } |
| 1367 | |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1368 | static SDValue lowerMSASplatImm(SDValue Op, unsigned ImmOp, SelectionDAG &DAG, |
| 1369 | bool IsSigned = false) { |
| 1370 | return DAG.getConstant( |
| 1371 | APInt(Op->getValueType(0).getScalarType().getSizeInBits(), |
| 1372 | Op->getConstantOperandVal(ImmOp), IsSigned), |
| 1373 | SDLoc(Op), Op->getValueType(0)); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | static SDValue getBuildVectorSplat(EVT VecTy, SDValue SplatValue, |
| 1377 | bool BigEndian, SelectionDAG &DAG) { |
| 1378 | EVT ViaVecTy = VecTy; |
| 1379 | SDValue SplatValueA = SplatValue; |
| 1380 | SDValue SplatValueB = SplatValue; |
| 1381 | SDLoc DL(SplatValue); |
| 1382 | |
| 1383 | if (VecTy == MVT::v2i64) { |
| 1384 | // v2i64 BUILD_VECTOR must be performed via v4i32 so split into i32's. |
| 1385 | ViaVecTy = MVT::v4i32; |
| 1386 | |
| 1387 | SplatValueA = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValue); |
| 1388 | SplatValueB = DAG.getNode(ISD::SRL, DL, MVT::i64, SplatValue, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1389 | DAG.getConstant(32, DL, MVT::i32)); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1390 | SplatValueB = DAG.getNode(ISD::TRUNCATE, DL, MVT::i32, SplatValueB); |
| 1391 | } |
| 1392 | |
| 1393 | // We currently hold the parts in little endian order. Swap them if |
| 1394 | // necessary. |
| 1395 | if (BigEndian) |
| 1396 | std::swap(SplatValueA, SplatValueB); |
| 1397 | |
| 1398 | SDValue Ops[16] = { SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1399 | SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1400 | SplatValueA, SplatValueB, SplatValueA, SplatValueB, |
| 1401 | SplatValueA, SplatValueB, SplatValueA, SplatValueB }; |
| 1402 | |
Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 1403 | SDValue Result = DAG.getBuildVector( |
| 1404 | ViaVecTy, DL, makeArrayRef(Ops, ViaVecTy.getVectorNumElements())); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1405 | |
| 1406 | if (VecTy != ViaVecTy) |
| 1407 | Result = DAG.getNode(ISD::BITCAST, DL, VecTy, Result); |
| 1408 | |
| 1409 | return Result; |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1410 | } |
| 1411 | |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1412 | static SDValue lowerMSABinaryBitImmIntr(SDValue Op, SelectionDAG &DAG, |
| 1413 | unsigned Opc, SDValue Imm, |
| 1414 | bool BigEndian) { |
| 1415 | EVT VecTy = Op->getValueType(0); |
| 1416 | SDValue Exp2Imm; |
| 1417 | SDLoc DL(Op); |
| 1418 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1419 | // The DAG Combiner can't constant fold bitcasted vectors yet so we must do it |
| 1420 | // here for now. |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1421 | if (VecTy == MVT::v2i64) { |
| 1422 | if (ConstantSDNode *CImm = dyn_cast<ConstantSDNode>(Imm)) { |
| 1423 | APInt BitImm = APInt(64, 1) << CImm->getAPIntValue(); |
| 1424 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1425 | SDValue BitImmHiOp = DAG.getConstant(BitImm.lshr(32).trunc(32), DL, |
| 1426 | MVT::i32); |
| 1427 | SDValue BitImmLoOp = DAG.getConstant(BitImm.trunc(32), DL, MVT::i32); |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1428 | |
| 1429 | if (BigEndian) |
| 1430 | std::swap(BitImmLoOp, BitImmHiOp); |
| 1431 | |
Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 1432 | Exp2Imm = DAG.getNode( |
| 1433 | ISD::BITCAST, DL, MVT::v2i64, |
| 1434 | DAG.getBuildVector(MVT::v4i32, DL, |
| 1435 | {BitImmLoOp, BitImmHiOp, BitImmLoOp, BitImmHiOp})); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1436 | } |
| 1437 | } |
| 1438 | |
Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1439 | if (!Exp2Imm.getNode()) { |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1440 | // We couldnt constant fold, do a vector shift instead |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1441 | |
| 1442 | // Extend i32 to i64 if necessary. Sign or zero extend doesn't matter since |
| 1443 | // only values 0-63 are valid. |
| 1444 | if (VecTy == MVT::v2i64) |
| 1445 | Imm = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i64, Imm); |
| 1446 | |
| 1447 | Exp2Imm = getBuildVectorSplat(VecTy, Imm, BigEndian, DAG); |
| 1448 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1449 | Exp2Imm = DAG.getNode(ISD::SHL, DL, VecTy, DAG.getConstant(1, DL, VecTy), |
| 1450 | Exp2Imm); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1451 | } |
| 1452 | |
| 1453 | return DAG.getNode(Opc, DL, VecTy, Op->getOperand(1), Exp2Imm); |
| 1454 | } |
| 1455 | |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 1456 | static SDValue truncateVecElts(SDValue Op, SelectionDAG &DAG) { |
| 1457 | SDLoc DL(Op); |
| 1458 | EVT ResTy = Op->getValueType(0); |
| 1459 | SDValue Vec = Op->getOperand(2); |
| 1460 | bool BigEndian = !DAG.getSubtarget().getTargetTriple().isLittleEndian(); |
| 1461 | MVT ResEltTy = ResTy == MVT::v2i64 ? MVT::i64 : MVT::i32; |
| 1462 | SDValue ConstValue = DAG.getConstant(Vec.getScalarValueSizeInBits() - 1, |
| 1463 | DL, ResEltTy); |
| 1464 | SDValue SplatVec = getBuildVectorSplat(ResTy, ConstValue, BigEndian, DAG); |
| 1465 | |
| 1466 | return DAG.getNode(ISD::AND, DL, ResTy, Vec, SplatVec); |
| 1467 | } |
| 1468 | |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1469 | static SDValue lowerMSABitClear(SDValue Op, SelectionDAG &DAG) { |
| 1470 | EVT ResTy = Op->getValueType(0); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1471 | SDLoc DL(Op); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1472 | SDValue One = DAG.getConstant(1, DL, ResTy); |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 1473 | SDValue Bit = DAG.getNode(ISD::SHL, DL, ResTy, One, truncateVecElts(Op, DAG)); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1474 | |
Daniel Sanders | 71ce0ca | 2013-11-15 16:02:04 +0000 | [diff] [blame] | 1475 | return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), |
| 1476 | DAG.getNOT(DL, Bit, ResTy)); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1477 | } |
| 1478 | |
| 1479 | static SDValue lowerMSABitClearImm(SDValue Op, SelectionDAG &DAG) { |
| 1480 | SDLoc DL(Op); |
| 1481 | EVT ResTy = Op->getValueType(0); |
Sanjay Patel | 1ed771f | 2016-09-14 16:37:15 +0000 | [diff] [blame] | 1482 | APInt BitImm = APInt(ResTy.getScalarSizeInBits(), 1) |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 1483 | << cast<ConstantSDNode>(Op->getOperand(2))->getAPIntValue(); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1484 | SDValue BitMask = DAG.getConstant(~BitImm, DL, ResTy); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1485 | |
| 1486 | return DAG.getNode(ISD::AND, DL, ResTy, Op->getOperand(1), BitMask); |
| 1487 | } |
| 1488 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1489 | SDValue MipsSETargetLowering::lowerINTRINSIC_WO_CHAIN(SDValue Op, |
| 1490 | SelectionDAG &DAG) const { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1491 | SDLoc DL(Op); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1492 | unsigned Intrinsic = cast<ConstantSDNode>(Op->getOperand(0))->getZExtValue(); |
| 1493 | switch (Intrinsic) { |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 1494 | default: |
| 1495 | return SDValue(); |
| 1496 | case Intrinsic::mips_shilo: |
| 1497 | return lowerDSPIntr(Op, DAG, MipsISD::SHILO); |
| 1498 | case Intrinsic::mips_dpau_h_qbl: |
| 1499 | return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBL); |
| 1500 | case Intrinsic::mips_dpau_h_qbr: |
| 1501 | return lowerDSPIntr(Op, DAG, MipsISD::DPAU_H_QBR); |
| 1502 | case Intrinsic::mips_dpsu_h_qbl: |
| 1503 | return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBL); |
| 1504 | case Intrinsic::mips_dpsu_h_qbr: |
| 1505 | return lowerDSPIntr(Op, DAG, MipsISD::DPSU_H_QBR); |
| 1506 | case Intrinsic::mips_dpa_w_ph: |
| 1507 | return lowerDSPIntr(Op, DAG, MipsISD::DPA_W_PH); |
| 1508 | case Intrinsic::mips_dps_w_ph: |
| 1509 | return lowerDSPIntr(Op, DAG, MipsISD::DPS_W_PH); |
| 1510 | case Intrinsic::mips_dpax_w_ph: |
| 1511 | return lowerDSPIntr(Op, DAG, MipsISD::DPAX_W_PH); |
| 1512 | case Intrinsic::mips_dpsx_w_ph: |
| 1513 | return lowerDSPIntr(Op, DAG, MipsISD::DPSX_W_PH); |
| 1514 | case Intrinsic::mips_mulsa_w_ph: |
| 1515 | return lowerDSPIntr(Op, DAG, MipsISD::MULSA_W_PH); |
| 1516 | case Intrinsic::mips_mult: |
| 1517 | return lowerDSPIntr(Op, DAG, MipsISD::Mult); |
| 1518 | case Intrinsic::mips_multu: |
| 1519 | return lowerDSPIntr(Op, DAG, MipsISD::Multu); |
| 1520 | case Intrinsic::mips_madd: |
| 1521 | return lowerDSPIntr(Op, DAG, MipsISD::MAdd); |
| 1522 | case Intrinsic::mips_maddu: |
| 1523 | return lowerDSPIntr(Op, DAG, MipsISD::MAddu); |
| 1524 | case Intrinsic::mips_msub: |
| 1525 | return lowerDSPIntr(Op, DAG, MipsISD::MSub); |
| 1526 | case Intrinsic::mips_msubu: |
| 1527 | return lowerDSPIntr(Op, DAG, MipsISD::MSubu); |
Daniel Sanders | fa5ab1c | 2013-09-11 10:28:16 +0000 | [diff] [blame] | 1528 | case Intrinsic::mips_addv_b: |
| 1529 | case Intrinsic::mips_addv_h: |
| 1530 | case Intrinsic::mips_addv_w: |
| 1531 | case Intrinsic::mips_addv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1532 | return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1533 | Op->getOperand(2)); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 1534 | case Intrinsic::mips_addvi_b: |
| 1535 | case Intrinsic::mips_addvi_h: |
| 1536 | case Intrinsic::mips_addvi_w: |
| 1537 | case Intrinsic::mips_addvi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1538 | return DAG.getNode(ISD::ADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1539 | lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 1540 | case Intrinsic::mips_and_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1541 | return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1), |
| 1542 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 1543 | case Intrinsic::mips_andi_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1544 | return DAG.getNode(ISD::AND, DL, Op->getValueType(0), Op->getOperand(1), |
| 1545 | lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3f6eb54 | 2013-11-12 10:45:18 +0000 | [diff] [blame] | 1546 | case Intrinsic::mips_bclr_b: |
| 1547 | case Intrinsic::mips_bclr_h: |
| 1548 | case Intrinsic::mips_bclr_w: |
| 1549 | case Intrinsic::mips_bclr_d: |
| 1550 | return lowerMSABitClear(Op, DAG); |
| 1551 | case Intrinsic::mips_bclri_b: |
| 1552 | case Intrinsic::mips_bclri_h: |
| 1553 | case Intrinsic::mips_bclri_w: |
| 1554 | case Intrinsic::mips_bclri_d: |
| 1555 | return lowerMSABitClearImm(Op, DAG); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1556 | case Intrinsic::mips_binsli_b: |
| 1557 | case Intrinsic::mips_binsli_h: |
| 1558 | case Intrinsic::mips_binsli_w: |
| 1559 | case Intrinsic::mips_binsli_d: { |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1560 | // binsli_x(IfClear, IfSet, nbits) -> (vselect LBitsMask, IfSet, IfClear) |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1561 | EVT VecTy = Op->getValueType(0); |
| 1562 | EVT EltTy = VecTy.getVectorElementType(); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1563 | if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits()) |
| 1564 | report_fatal_error("Immediate out of range"); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1565 | APInt Mask = APInt::getHighBitsSet(EltTy.getSizeInBits(), |
Petar Jovanovic | bc54eb8 | 2017-04-07 13:31:36 +0000 | [diff] [blame] | 1566 | Op->getConstantOperandVal(3) + 1); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1567 | return DAG.getNode(ISD::VSELECT, DL, VecTy, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1568 | DAG.getConstant(Mask, DL, VecTy, true), |
| 1569 | Op->getOperand(2), Op->getOperand(1)); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1570 | } |
| 1571 | case Intrinsic::mips_binsri_b: |
| 1572 | case Intrinsic::mips_binsri_h: |
| 1573 | case Intrinsic::mips_binsri_w: |
| 1574 | case Intrinsic::mips_binsri_d: { |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1575 | // binsri_x(IfClear, IfSet, nbits) -> (vselect RBitsMask, IfSet, IfClear) |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1576 | EVT VecTy = Op->getValueType(0); |
| 1577 | EVT EltTy = VecTy.getVectorElementType(); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1578 | if (Op->getConstantOperandVal(3) >= EltTy.getSizeInBits()) |
| 1579 | report_fatal_error("Immediate out of range"); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1580 | APInt Mask = APInt::getLowBitsSet(EltTy.getSizeInBits(), |
Petar Jovanovic | bc54eb8 | 2017-04-07 13:31:36 +0000 | [diff] [blame] | 1581 | Op->getConstantOperandVal(3) + 1); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1582 | return DAG.getNode(ISD::VSELECT, DL, VecTy, |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1583 | DAG.getConstant(Mask, DL, VecTy, true), |
| 1584 | Op->getOperand(2), Op->getOperand(1)); |
Daniel Sanders | d74b130 | 2013-10-30 14:45:14 +0000 | [diff] [blame] | 1585 | } |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 1586 | case Intrinsic::mips_bmnz_v: |
| 1587 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3), |
| 1588 | Op->getOperand(2), Op->getOperand(1)); |
| 1589 | case Intrinsic::mips_bmnzi_b: |
| 1590 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
| 1591 | lowerMSASplatImm(Op, 3, DAG), Op->getOperand(2), |
| 1592 | Op->getOperand(1)); |
| 1593 | case Intrinsic::mips_bmz_v: |
| 1594 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), Op->getOperand(3), |
| 1595 | Op->getOperand(1), Op->getOperand(2)); |
| 1596 | case Intrinsic::mips_bmzi_b: |
| 1597 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
| 1598 | lowerMSASplatImm(Op, 3, DAG), Op->getOperand(1), |
| 1599 | Op->getOperand(2)); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1600 | case Intrinsic::mips_bneg_b: |
| 1601 | case Intrinsic::mips_bneg_h: |
| 1602 | case Intrinsic::mips_bneg_w: |
| 1603 | case Intrinsic::mips_bneg_d: { |
| 1604 | EVT VecTy = Op->getValueType(0); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1605 | SDValue One = DAG.getConstant(1, DL, VecTy); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1606 | |
| 1607 | return DAG.getNode(ISD::XOR, DL, VecTy, Op->getOperand(1), |
| 1608 | DAG.getNode(ISD::SHL, DL, VecTy, One, |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 1609 | truncateVecElts(Op, DAG))); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1610 | } |
| 1611 | case Intrinsic::mips_bnegi_b: |
| 1612 | case Intrinsic::mips_bnegi_h: |
| 1613 | case Intrinsic::mips_bnegi_w: |
| 1614 | case Intrinsic::mips_bnegi_d: |
| 1615 | return lowerMSABinaryBitImmIntr(Op, DAG, ISD::XOR, Op->getOperand(2), |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1616 | !Subtarget.isLittle()); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1617 | case Intrinsic::mips_bnz_b: |
| 1618 | case Intrinsic::mips_bnz_h: |
| 1619 | case Intrinsic::mips_bnz_w: |
| 1620 | case Intrinsic::mips_bnz_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1621 | return DAG.getNode(MipsISD::VALL_NONZERO, DL, Op->getValueType(0), |
| 1622 | Op->getOperand(1)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1623 | case Intrinsic::mips_bnz_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1624 | return DAG.getNode(MipsISD::VANY_NONZERO, DL, Op->getValueType(0), |
| 1625 | Op->getOperand(1)); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 1626 | case Intrinsic::mips_bsel_v: |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1627 | // bsel_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear) |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1628 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1629 | Op->getOperand(1), Op->getOperand(3), |
| 1630 | Op->getOperand(2)); |
Daniel Sanders | e1d2435 | 2013-09-24 12:04:44 +0000 | [diff] [blame] | 1631 | case Intrinsic::mips_bseli_b: |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1632 | // bseli_v(Mask, IfClear, IfSet) -> (vselect Mask, IfSet, IfClear) |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1633 | return DAG.getNode(ISD::VSELECT, DL, Op->getValueType(0), |
Daniel Sanders | df221545 | 2014-03-12 11:54:00 +0000 | [diff] [blame] | 1634 | Op->getOperand(1), lowerMSASplatImm(Op, 3, DAG), |
| 1635 | Op->getOperand(2)); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1636 | case Intrinsic::mips_bset_b: |
| 1637 | case Intrinsic::mips_bset_h: |
| 1638 | case Intrinsic::mips_bset_w: |
| 1639 | case Intrinsic::mips_bset_d: { |
| 1640 | EVT VecTy = Op->getValueType(0); |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1641 | SDValue One = DAG.getConstant(1, DL, VecTy); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1642 | |
| 1643 | return DAG.getNode(ISD::OR, DL, VecTy, Op->getOperand(1), |
| 1644 | DAG.getNode(ISD::SHL, DL, VecTy, One, |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 1645 | truncateVecElts(Op, DAG))); |
Daniel Sanders | a5bc99f | 2013-11-12 10:31:49 +0000 | [diff] [blame] | 1646 | } |
| 1647 | case Intrinsic::mips_bseti_b: |
| 1648 | case Intrinsic::mips_bseti_h: |
| 1649 | case Intrinsic::mips_bseti_w: |
| 1650 | case Intrinsic::mips_bseti_d: |
| 1651 | return lowerMSABinaryBitImmIntr(Op, DAG, ISD::OR, Op->getOperand(2), |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1652 | !Subtarget.isLittle()); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1653 | case Intrinsic::mips_bz_b: |
| 1654 | case Intrinsic::mips_bz_h: |
| 1655 | case Intrinsic::mips_bz_w: |
| 1656 | case Intrinsic::mips_bz_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1657 | return DAG.getNode(MipsISD::VALL_ZERO, DL, Op->getValueType(0), |
| 1658 | Op->getOperand(1)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 1659 | case Intrinsic::mips_bz_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1660 | return DAG.getNode(MipsISD::VANY_ZERO, DL, Op->getValueType(0), |
| 1661 | Op->getOperand(1)); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1662 | case Intrinsic::mips_ceq_b: |
| 1663 | case Intrinsic::mips_ceq_h: |
| 1664 | case Intrinsic::mips_ceq_w: |
| 1665 | case Intrinsic::mips_ceq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1666 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1667 | Op->getOperand(2), ISD::SETEQ); |
| 1668 | case Intrinsic::mips_ceqi_b: |
| 1669 | case Intrinsic::mips_ceqi_h: |
| 1670 | case Intrinsic::mips_ceqi_w: |
| 1671 | case Intrinsic::mips_ceqi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1672 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1673 | lowerMSASplatImm(Op, 2, DAG, true), ISD::SETEQ); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1674 | case Intrinsic::mips_cle_s_b: |
| 1675 | case Intrinsic::mips_cle_s_h: |
| 1676 | case Intrinsic::mips_cle_s_w: |
| 1677 | case Intrinsic::mips_cle_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1678 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1679 | Op->getOperand(2), ISD::SETLE); |
| 1680 | case Intrinsic::mips_clei_s_b: |
| 1681 | case Intrinsic::mips_clei_s_h: |
| 1682 | case Intrinsic::mips_clei_s_w: |
| 1683 | case Intrinsic::mips_clei_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1684 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1685 | lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLE); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1686 | case Intrinsic::mips_cle_u_b: |
| 1687 | case Intrinsic::mips_cle_u_h: |
| 1688 | case Intrinsic::mips_cle_u_w: |
| 1689 | case Intrinsic::mips_cle_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1690 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1691 | Op->getOperand(2), ISD::SETULE); |
| 1692 | case Intrinsic::mips_clei_u_b: |
| 1693 | case Intrinsic::mips_clei_u_h: |
| 1694 | case Intrinsic::mips_clei_u_w: |
| 1695 | case Intrinsic::mips_clei_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1696 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1697 | lowerMSASplatImm(Op, 2, DAG), ISD::SETULE); |
| 1698 | case Intrinsic::mips_clt_s_b: |
| 1699 | case Intrinsic::mips_clt_s_h: |
| 1700 | case Intrinsic::mips_clt_s_w: |
| 1701 | case Intrinsic::mips_clt_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1702 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1703 | Op->getOperand(2), ISD::SETLT); |
| 1704 | case Intrinsic::mips_clti_s_b: |
| 1705 | case Intrinsic::mips_clti_s_h: |
| 1706 | case Intrinsic::mips_clti_s_w: |
| 1707 | case Intrinsic::mips_clti_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1708 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1709 | lowerMSASplatImm(Op, 2, DAG, true), ISD::SETLT); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1710 | case Intrinsic::mips_clt_u_b: |
| 1711 | case Intrinsic::mips_clt_u_h: |
| 1712 | case Intrinsic::mips_clt_u_w: |
| 1713 | case Intrinsic::mips_clt_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1714 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1715 | Op->getOperand(2), ISD::SETULT); |
| 1716 | case Intrinsic::mips_clti_u_b: |
| 1717 | case Intrinsic::mips_clti_u_h: |
| 1718 | case Intrinsic::mips_clti_u_w: |
| 1719 | case Intrinsic::mips_clti_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1720 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1721 | lowerMSASplatImm(Op, 2, DAG), ISD::SETULT); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1722 | case Intrinsic::mips_copy_s_b: |
| 1723 | case Intrinsic::mips_copy_s_h: |
| 1724 | case Intrinsic::mips_copy_s_w: |
| 1725 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT); |
Daniel Sanders | 7f3d946 | 2013-09-27 13:04:21 +0000 | [diff] [blame] | 1726 | case Intrinsic::mips_copy_s_d: |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1727 | if (Subtarget.hasMips64()) |
Matheus Almeida | 7407032 | 2014-01-29 14:05:28 +0000 | [diff] [blame] | 1728 | // Lower directly into VEXTRACT_SEXT_ELT since i64 is legal on Mips64. |
| 1729 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_SEXT_ELT); |
| 1730 | else { |
| 1731 | // Lower into the generic EXTRACT_VECTOR_ELT node and let the type |
| 1732 | // legalizer and EXTRACT_VECTOR_ELT lowering sort it out. |
| 1733 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op), |
| 1734 | Op->getValueType(0), Op->getOperand(1), |
| 1735 | Op->getOperand(2)); |
| 1736 | } |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1737 | case Intrinsic::mips_copy_u_b: |
| 1738 | case Intrinsic::mips_copy_u_h: |
| 1739 | case Intrinsic::mips_copy_u_w: |
| 1740 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT); |
Daniel Sanders | 7f3d946 | 2013-09-27 13:04:21 +0000 | [diff] [blame] | 1741 | case Intrinsic::mips_copy_u_d: |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 1742 | if (Subtarget.hasMips64()) |
Matheus Almeida | 7407032 | 2014-01-29 14:05:28 +0000 | [diff] [blame] | 1743 | // Lower directly into VEXTRACT_ZEXT_ELT since i64 is legal on Mips64. |
| 1744 | return lowerMSACopyIntr(Op, DAG, MipsISD::VEXTRACT_ZEXT_ELT); |
| 1745 | else { |
| 1746 | // Lower into the generic EXTRACT_VECTOR_ELT node and let the type |
| 1747 | // legalizer and EXTRACT_VECTOR_ELT lowering sort it out. |
| 1748 | // Note: When i64 is illegal, this results in copy_s.w instructions |
| 1749 | // instead of copy_u.w instructions. This makes no difference to the |
| 1750 | // behaviour since i64 is only illegal when the register file is 32-bit. |
| 1751 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SDLoc(Op), |
| 1752 | Op->getValueType(0), Op->getOperand(1), |
| 1753 | Op->getOperand(2)); |
| 1754 | } |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 1755 | case Intrinsic::mips_div_s_b: |
| 1756 | case Intrinsic::mips_div_s_h: |
| 1757 | case Intrinsic::mips_div_s_w: |
| 1758 | case Intrinsic::mips_div_s_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1759 | return DAG.getNode(ISD::SDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1760 | Op->getOperand(2)); |
Daniel Sanders | 607952b | 2013-09-11 10:38:58 +0000 | [diff] [blame] | 1761 | case Intrinsic::mips_div_u_b: |
| 1762 | case Intrinsic::mips_div_u_h: |
| 1763 | case Intrinsic::mips_div_u_w: |
| 1764 | case Intrinsic::mips_div_u_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1765 | return DAG.getNode(ISD::UDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1766 | Op->getOperand(2)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1767 | case Intrinsic::mips_fadd_w: |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1768 | case Intrinsic::mips_fadd_d: |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1769 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1770 | return DAG.getNode(ISD::FADD, DL, Op->getValueType(0), Op->getOperand(1), |
| 1771 | Op->getOperand(2)); |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1772 | // Don't lower mips_fcaf_[wd] since LLVM folds SETFALSE condcodes away |
| 1773 | case Intrinsic::mips_fceq_w: |
| 1774 | case Intrinsic::mips_fceq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1775 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1776 | Op->getOperand(2), ISD::SETOEQ); |
| 1777 | case Intrinsic::mips_fcle_w: |
| 1778 | case Intrinsic::mips_fcle_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1779 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1780 | Op->getOperand(2), ISD::SETOLE); |
| 1781 | case Intrinsic::mips_fclt_w: |
| 1782 | case Intrinsic::mips_fclt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1783 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1784 | Op->getOperand(2), ISD::SETOLT); |
| 1785 | case Intrinsic::mips_fcne_w: |
| 1786 | case Intrinsic::mips_fcne_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1787 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1788 | Op->getOperand(2), ISD::SETONE); |
| 1789 | case Intrinsic::mips_fcor_w: |
| 1790 | case Intrinsic::mips_fcor_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1791 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1792 | Op->getOperand(2), ISD::SETO); |
| 1793 | case Intrinsic::mips_fcueq_w: |
| 1794 | case Intrinsic::mips_fcueq_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1795 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1796 | Op->getOperand(2), ISD::SETUEQ); |
| 1797 | case Intrinsic::mips_fcule_w: |
| 1798 | case Intrinsic::mips_fcule_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1799 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1800 | Op->getOperand(2), ISD::SETULE); |
| 1801 | case Intrinsic::mips_fcult_w: |
| 1802 | case Intrinsic::mips_fcult_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1803 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1804 | Op->getOperand(2), ISD::SETULT); |
| 1805 | case Intrinsic::mips_fcun_w: |
| 1806 | case Intrinsic::mips_fcun_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1807 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1808 | Op->getOperand(2), ISD::SETUO); |
| 1809 | case Intrinsic::mips_fcune_w: |
| 1810 | case Intrinsic::mips_fcune_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1811 | return DAG.getSetCC(DL, Op->getValueType(0), Op->getOperand(1), |
Daniel Sanders | fd538dc | 2013-09-24 10:46:19 +0000 | [diff] [blame] | 1812 | Op->getOperand(2), ISD::SETUNE); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1813 | case Intrinsic::mips_fdiv_w: |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1814 | case Intrinsic::mips_fdiv_d: |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1815 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1816 | return DAG.getNode(ISD::FDIV, DL, Op->getValueType(0), Op->getOperand(1), |
| 1817 | Op->getOperand(2)); |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 1818 | case Intrinsic::mips_ffint_u_w: |
| 1819 | case Intrinsic::mips_ffint_u_d: |
| 1820 | return DAG.getNode(ISD::UINT_TO_FP, DL, Op->getValueType(0), |
| 1821 | Op->getOperand(1)); |
| 1822 | case Intrinsic::mips_ffint_s_w: |
| 1823 | case Intrinsic::mips_ffint_s_d: |
| 1824 | return DAG.getNode(ISD::SINT_TO_FP, DL, Op->getValueType(0), |
| 1825 | Op->getOperand(1)); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 1826 | case Intrinsic::mips_fill_b: |
| 1827 | case Intrinsic::mips_fill_h: |
Daniel Sanders | c72593e | 2013-09-27 13:20:41 +0000 | [diff] [blame] | 1828 | case Intrinsic::mips_fill_w: |
| 1829 | case Intrinsic::mips_fill_d: { |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1830 | EVT ResTy = Op->getValueType(0); |
Benjamin Kramer | 6cd780f | 2015-02-17 15:29:18 +0000 | [diff] [blame] | 1831 | SmallVector<SDValue, 16> Ops(ResTy.getVectorNumElements(), |
| 1832 | Op->getOperand(1)); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1833 | |
Daniel Sanders | c72593e | 2013-09-27 13:20:41 +0000 | [diff] [blame] | 1834 | // If ResTy is v2i64 then the type legalizer will break this node down into |
| 1835 | // an equivalent v4i32. |
Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 1836 | return DAG.getBuildVector(ResTy, DL, Ops); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 1837 | } |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 1838 | case Intrinsic::mips_fexp2_w: |
| 1839 | case Intrinsic::mips_fexp2_d: { |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1840 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 1841 | EVT ResTy = Op->getValueType(0); |
| 1842 | return DAG.getNode( |
| 1843 | ISD::FMUL, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1844 | DAG.getNode(ISD::FEXP2, SDLoc(Op), ResTy, Op->getOperand(2))); |
| 1845 | } |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1846 | case Intrinsic::mips_flog2_w: |
| 1847 | case Intrinsic::mips_flog2_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1848 | return DAG.getNode(ISD::FLOG2, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | d7103f3 | 2013-10-11 10:14:25 +0000 | [diff] [blame] | 1849 | case Intrinsic::mips_fmadd_w: |
| 1850 | case Intrinsic::mips_fmadd_d: |
| 1851 | return DAG.getNode(ISD::FMA, SDLoc(Op), Op->getValueType(0), |
| 1852 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1853 | case Intrinsic::mips_fmul_w: |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1854 | case Intrinsic::mips_fmul_d: |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1855 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1856 | return DAG.getNode(ISD::FMUL, DL, Op->getValueType(0), Op->getOperand(1), |
| 1857 | Op->getOperand(2)); |
Daniel Sanders | e67bd87 | 2013-10-11 10:27:32 +0000 | [diff] [blame] | 1858 | case Intrinsic::mips_fmsub_w: |
| 1859 | case Intrinsic::mips_fmsub_d: { |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1860 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Aleksandar Beserminji | 3546c16 | 2018-04-27 13:30:27 +0000 | [diff] [blame] | 1861 | return DAG.getNode(MipsISD::FMS, SDLoc(Op), Op->getValueType(0), |
| 1862 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3)); |
Daniel Sanders | e67bd87 | 2013-10-11 10:27:32 +0000 | [diff] [blame] | 1863 | } |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1864 | case Intrinsic::mips_frint_w: |
| 1865 | case Intrinsic::mips_frint_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1866 | return DAG.getNode(ISD::FRINT, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1867 | case Intrinsic::mips_fsqrt_w: |
| 1868 | case Intrinsic::mips_fsqrt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1869 | return DAG.getNode(ISD::FSQRT, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f5bd937 | 2013-09-11 10:51:30 +0000 | [diff] [blame] | 1870 | case Intrinsic::mips_fsub_w: |
Eugene Zelenko | 79220eae | 2017-08-03 22:12:30 +0000 | [diff] [blame] | 1871 | case Intrinsic::mips_fsub_d: |
Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 1872 | // TODO: If intrinsics have fast-math-flags, propagate them. |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1873 | return DAG.getNode(ISD::FSUB, DL, Op->getValueType(0), Op->getOperand(1), |
| 1874 | Op->getOperand(2)); |
Daniel Sanders | 015972b | 2013-10-11 10:00:06 +0000 | [diff] [blame] | 1875 | case Intrinsic::mips_ftrunc_u_w: |
| 1876 | case Intrinsic::mips_ftrunc_u_d: |
| 1877 | return DAG.getNode(ISD::FP_TO_UINT, DL, Op->getValueType(0), |
| 1878 | Op->getOperand(1)); |
| 1879 | case Intrinsic::mips_ftrunc_s_w: |
| 1880 | case Intrinsic::mips_ftrunc_s_d: |
| 1881 | return DAG.getNode(ISD::FP_TO_SINT, DL, Op->getValueType(0), |
| 1882 | Op->getOperand(1)); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1883 | case Intrinsic::mips_ilvev_b: |
| 1884 | case Intrinsic::mips_ilvev_h: |
| 1885 | case Intrinsic::mips_ilvev_w: |
| 1886 | case Intrinsic::mips_ilvev_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1887 | return DAG.getNode(MipsISD::ILVEV, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1888 | Op->getOperand(1), Op->getOperand(2)); |
| 1889 | case Intrinsic::mips_ilvl_b: |
| 1890 | case Intrinsic::mips_ilvl_h: |
| 1891 | case Intrinsic::mips_ilvl_w: |
| 1892 | case Intrinsic::mips_ilvl_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1893 | return DAG.getNode(MipsISD::ILVL, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1894 | Op->getOperand(1), Op->getOperand(2)); |
| 1895 | case Intrinsic::mips_ilvod_b: |
| 1896 | case Intrinsic::mips_ilvod_h: |
| 1897 | case Intrinsic::mips_ilvod_w: |
| 1898 | case Intrinsic::mips_ilvod_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1899 | return DAG.getNode(MipsISD::ILVOD, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1900 | Op->getOperand(1), Op->getOperand(2)); |
| 1901 | case Intrinsic::mips_ilvr_b: |
| 1902 | case Intrinsic::mips_ilvr_h: |
| 1903 | case Intrinsic::mips_ilvr_w: |
| 1904 | case Intrinsic::mips_ilvr_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1905 | return DAG.getNode(MipsISD::ILVR, DL, Op->getValueType(0), |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 1906 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 1907 | case Intrinsic::mips_insert_b: |
| 1908 | case Intrinsic::mips_insert_h: |
| 1909 | case Intrinsic::mips_insert_w: |
Daniel Sanders | 6098b33 | 2013-09-27 13:36:54 +0000 | [diff] [blame] | 1910 | case Intrinsic::mips_insert_d: |
| 1911 | return DAG.getNode(ISD::INSERT_VECTOR_ELT, SDLoc(Op), Op->getValueType(0), |
| 1912 | Op->getOperand(1), Op->getOperand(3), Op->getOperand(2)); |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 1913 | case Intrinsic::mips_insve_b: |
| 1914 | case Intrinsic::mips_insve_h: |
| 1915 | case Intrinsic::mips_insve_w: |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1916 | case Intrinsic::mips_insve_d: { |
| 1917 | // Report an error for out of range values. |
| 1918 | int64_t Max; |
| 1919 | switch (Intrinsic) { |
| 1920 | case Intrinsic::mips_insve_b: Max = 15; break; |
| 1921 | case Intrinsic::mips_insve_h: Max = 7; break; |
| 1922 | case Intrinsic::mips_insve_w: Max = 3; break; |
| 1923 | case Intrinsic::mips_insve_d: Max = 1; break; |
| 1924 | default: llvm_unreachable("Unmatched intrinsic"); |
| 1925 | } |
| 1926 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue(); |
| 1927 | if (Value < 0 || Value > Max) |
| 1928 | report_fatal_error("Immediate out of range"); |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 1929 | return DAG.getNode(MipsISD::INSVE, DL, Op->getValueType(0), |
| 1930 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3), |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1931 | DAG.getConstant(0, DL, MVT::i32)); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1932 | } |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 1933 | case Intrinsic::mips_ldi_b: |
| 1934 | case Intrinsic::mips_ldi_h: |
| 1935 | case Intrinsic::mips_ldi_w: |
| 1936 | case Intrinsic::mips_ldi_d: |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1937 | return lowerMSASplatImm(Op, 1, DAG, true); |
Matheus Almeida | 4b27eb5 | 2014-02-10 12:05:17 +0000 | [diff] [blame] | 1938 | case Intrinsic::mips_lsa: |
| 1939 | case Intrinsic::mips_dlsa: { |
Daniel Sanders | a4eaf59 | 2013-10-17 13:38:20 +0000 | [diff] [blame] | 1940 | EVT ResTy = Op->getValueType(0); |
| 1941 | return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1942 | DAG.getNode(ISD::SHL, SDLoc(Op), ResTy, |
| 1943 | Op->getOperand(2), Op->getOperand(3))); |
| 1944 | } |
Daniel Sanders | 50e5ed3 | 2013-10-11 10:50:42 +0000 | [diff] [blame] | 1945 | case Intrinsic::mips_maddv_b: |
| 1946 | case Intrinsic::mips_maddv_h: |
| 1947 | case Intrinsic::mips_maddv_w: |
| 1948 | case Intrinsic::mips_maddv_d: { |
| 1949 | EVT ResTy = Op->getValueType(0); |
| 1950 | return DAG.getNode(ISD::ADD, SDLoc(Op), ResTy, Op->getOperand(1), |
| 1951 | DAG.getNode(ISD::MUL, SDLoc(Op), ResTy, |
| 1952 | Op->getOperand(2), Op->getOperand(3))); |
| 1953 | } |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1954 | case Intrinsic::mips_max_s_b: |
| 1955 | case Intrinsic::mips_max_s_h: |
| 1956 | case Intrinsic::mips_max_s_w: |
| 1957 | case Intrinsic::mips_max_s_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1958 | return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1959 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1960 | case Intrinsic::mips_max_u_b: |
| 1961 | case Intrinsic::mips_max_u_h: |
| 1962 | case Intrinsic::mips_max_u_w: |
| 1963 | case Intrinsic::mips_max_u_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1964 | return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1965 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1966 | case Intrinsic::mips_maxi_s_b: |
| 1967 | case Intrinsic::mips_maxi_s_h: |
| 1968 | case Intrinsic::mips_maxi_s_w: |
| 1969 | case Intrinsic::mips_maxi_s_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1970 | return DAG.getNode(ISD::SMAX, DL, Op->getValueType(0), |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1971 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1972 | case Intrinsic::mips_maxi_u_b: |
| 1973 | case Intrinsic::mips_maxi_u_h: |
| 1974 | case Intrinsic::mips_maxi_u_w: |
| 1975 | case Intrinsic::mips_maxi_u_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1976 | return DAG.getNode(ISD::UMAX, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1977 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1978 | case Intrinsic::mips_min_s_b: |
| 1979 | case Intrinsic::mips_min_s_h: |
| 1980 | case Intrinsic::mips_min_s_w: |
| 1981 | case Intrinsic::mips_min_s_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1982 | return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1983 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1984 | case Intrinsic::mips_min_u_b: |
| 1985 | case Intrinsic::mips_min_u_h: |
| 1986 | case Intrinsic::mips_min_u_w: |
| 1987 | case Intrinsic::mips_min_u_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1988 | return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 1989 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1990 | case Intrinsic::mips_mini_s_b: |
| 1991 | case Intrinsic::mips_mini_s_h: |
| 1992 | case Intrinsic::mips_mini_s_w: |
| 1993 | case Intrinsic::mips_mini_s_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 1994 | return DAG.getNode(ISD::SMIN, DL, Op->getValueType(0), |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 1995 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG, true)); |
Daniel Sanders | 3ce5662 | 2013-09-24 12:18:31 +0000 | [diff] [blame] | 1996 | case Intrinsic::mips_mini_u_b: |
| 1997 | case Intrinsic::mips_mini_u_h: |
| 1998 | case Intrinsic::mips_mini_u_w: |
| 1999 | case Intrinsic::mips_mini_u_d: |
Simon Pilgrim | 386b8dd | 2018-02-17 21:29:45 +0000 | [diff] [blame] | 2000 | return DAG.getNode(ISD::UMIN, DL, Op->getValueType(0), |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2001 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | 0210dd4 | 2013-10-01 10:22:35 +0000 | [diff] [blame] | 2002 | case Intrinsic::mips_mod_s_b: |
| 2003 | case Intrinsic::mips_mod_s_h: |
| 2004 | case Intrinsic::mips_mod_s_w: |
| 2005 | case Intrinsic::mips_mod_s_d: |
| 2006 | return DAG.getNode(ISD::SREM, DL, Op->getValueType(0), Op->getOperand(1), |
| 2007 | Op->getOperand(2)); |
| 2008 | case Intrinsic::mips_mod_u_b: |
| 2009 | case Intrinsic::mips_mod_u_h: |
| 2010 | case Intrinsic::mips_mod_u_w: |
| 2011 | case Intrinsic::mips_mod_u_d: |
| 2012 | return DAG.getNode(ISD::UREM, DL, Op->getValueType(0), Op->getOperand(1), |
| 2013 | Op->getOperand(2)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2014 | case Intrinsic::mips_mulv_b: |
| 2015 | case Intrinsic::mips_mulv_h: |
| 2016 | case Intrinsic::mips_mulv_w: |
| 2017 | case Intrinsic::mips_mulv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2018 | return DAG.getNode(ISD::MUL, DL, Op->getValueType(0), Op->getOperand(1), |
| 2019 | Op->getOperand(2)); |
Daniel Sanders | 50e5ed3 | 2013-10-11 10:50:42 +0000 | [diff] [blame] | 2020 | case Intrinsic::mips_msubv_b: |
| 2021 | case Intrinsic::mips_msubv_h: |
| 2022 | case Intrinsic::mips_msubv_w: |
| 2023 | case Intrinsic::mips_msubv_d: { |
| 2024 | EVT ResTy = Op->getValueType(0); |
| 2025 | return DAG.getNode(ISD::SUB, SDLoc(Op), ResTy, Op->getOperand(1), |
| 2026 | DAG.getNode(ISD::MUL, SDLoc(Op), ResTy, |
| 2027 | Op->getOperand(2), Op->getOperand(3))); |
| 2028 | } |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2029 | case Intrinsic::mips_nlzc_b: |
| 2030 | case Intrinsic::mips_nlzc_h: |
| 2031 | case Intrinsic::mips_nlzc_w: |
| 2032 | case Intrinsic::mips_nlzc_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2033 | return DAG.getNode(ISD::CTLZ, DL, Op->getValueType(0), Op->getOperand(1)); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 2034 | case Intrinsic::mips_nor_v: { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2035 | SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 2036 | Op->getOperand(1), Op->getOperand(2)); |
| 2037 | return DAG.getNOT(DL, Res, Res->getValueType(0)); |
Daniel Sanders | f7456c7 | 2013-09-23 13:22:24 +0000 | [diff] [blame] | 2038 | } |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 2039 | case Intrinsic::mips_nori_b: { |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2040 | SDValue Res = DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 2041 | Op->getOperand(1), |
| 2042 | lowerMSASplatImm(Op, 2, DAG)); |
| 2043 | return DAG.getNOT(DL, Res, Res->getValueType(0)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 2044 | } |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 2045 | case Intrinsic::mips_or_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2046 | return DAG.getNode(ISD::OR, DL, Op->getValueType(0), Op->getOperand(1), |
| 2047 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 2048 | case Intrinsic::mips_ori_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2049 | return DAG.getNode(ISD::OR, DL, Op->getValueType(0), |
| 2050 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2051 | case Intrinsic::mips_pckev_b: |
| 2052 | case Intrinsic::mips_pckev_h: |
| 2053 | case Intrinsic::mips_pckev_w: |
| 2054 | case Intrinsic::mips_pckev_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2055 | return DAG.getNode(MipsISD::PCKEV, DL, Op->getValueType(0), |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2056 | Op->getOperand(1), Op->getOperand(2)); |
| 2057 | case Intrinsic::mips_pckod_b: |
| 2058 | case Intrinsic::mips_pckod_h: |
| 2059 | case Intrinsic::mips_pckod_w: |
| 2060 | case Intrinsic::mips_pckod_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2061 | return DAG.getNode(MipsISD::PCKOD, DL, Op->getValueType(0), |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2062 | Op->getOperand(1), Op->getOperand(2)); |
Daniel Sanders | 766cb69 | 2013-09-23 13:40:21 +0000 | [diff] [blame] | 2063 | case Intrinsic::mips_pcnt_b: |
| 2064 | case Intrinsic::mips_pcnt_h: |
| 2065 | case Intrinsic::mips_pcnt_w: |
| 2066 | case Intrinsic::mips_pcnt_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2067 | return DAG.getNode(ISD::CTPOP, DL, Op->getValueType(0), Op->getOperand(1)); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2068 | case Intrinsic::mips_sat_s_b: |
| 2069 | case Intrinsic::mips_sat_s_h: |
| 2070 | case Intrinsic::mips_sat_s_w: |
| 2071 | case Intrinsic::mips_sat_s_d: |
| 2072 | case Intrinsic::mips_sat_u_b: |
| 2073 | case Intrinsic::mips_sat_u_h: |
| 2074 | case Intrinsic::mips_sat_u_w: |
| 2075 | case Intrinsic::mips_sat_u_d: { |
| 2076 | // Report an error for out of range values. |
| 2077 | int64_t Max; |
| 2078 | switch (Intrinsic) { |
| 2079 | case Intrinsic::mips_sat_s_b: |
| 2080 | case Intrinsic::mips_sat_u_b: Max = 7; break; |
| 2081 | case Intrinsic::mips_sat_s_h: |
| 2082 | case Intrinsic::mips_sat_u_h: Max = 15; break; |
| 2083 | case Intrinsic::mips_sat_s_w: |
| 2084 | case Intrinsic::mips_sat_u_w: Max = 31; break; |
| 2085 | case Intrinsic::mips_sat_s_d: |
| 2086 | case Intrinsic::mips_sat_u_d: Max = 63; break; |
| 2087 | default: llvm_unreachable("Unmatched intrinsic"); |
| 2088 | } |
| 2089 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue(); |
| 2090 | if (Value < 0 || Value > Max) |
| 2091 | report_fatal_error("Immediate out of range"); |
| 2092 | return SDValue(); |
| 2093 | } |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2094 | case Intrinsic::mips_shf_b: |
| 2095 | case Intrinsic::mips_shf_h: |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2096 | case Intrinsic::mips_shf_w: { |
| 2097 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue(); |
| 2098 | if (Value < 0 || Value > 255) |
| 2099 | report_fatal_error("Immediate out of range"); |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2100 | return DAG.getNode(MipsISD::SHF, DL, Op->getValueType(0), |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2101 | Op->getOperand(2), Op->getOperand(1)); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2102 | } |
| 2103 | case Intrinsic::mips_sldi_b: |
| 2104 | case Intrinsic::mips_sldi_h: |
| 2105 | case Intrinsic::mips_sldi_w: |
| 2106 | case Intrinsic::mips_sldi_d: { |
| 2107 | // Report an error for out of range values. |
| 2108 | int64_t Max; |
| 2109 | switch (Intrinsic) { |
| 2110 | case Intrinsic::mips_sldi_b: Max = 15; break; |
| 2111 | case Intrinsic::mips_sldi_h: Max = 7; break; |
| 2112 | case Intrinsic::mips_sldi_w: Max = 3; break; |
| 2113 | case Intrinsic::mips_sldi_d: Max = 1; break; |
| 2114 | default: llvm_unreachable("Unmatched intrinsic"); |
| 2115 | } |
| 2116 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(3))->getSExtValue(); |
| 2117 | if (Value < 0 || Value > Max) |
| 2118 | report_fatal_error("Immediate out of range"); |
| 2119 | return SDValue(); |
| 2120 | } |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2121 | case Intrinsic::mips_sll_b: |
| 2122 | case Intrinsic::mips_sll_h: |
| 2123 | case Intrinsic::mips_sll_w: |
| 2124 | case Intrinsic::mips_sll_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2125 | return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), Op->getOperand(1), |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 2126 | truncateVecElts(Op, DAG)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 2127 | case Intrinsic::mips_slli_b: |
| 2128 | case Intrinsic::mips_slli_h: |
| 2129 | case Intrinsic::mips_slli_w: |
| 2130 | case Intrinsic::mips_slli_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2131 | return DAG.getNode(ISD::SHL, DL, Op->getValueType(0), |
| 2132 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | e7ef0c8 | 2013-10-30 13:07:44 +0000 | [diff] [blame] | 2133 | case Intrinsic::mips_splat_b: |
| 2134 | case Intrinsic::mips_splat_h: |
| 2135 | case Intrinsic::mips_splat_w: |
| 2136 | case Intrinsic::mips_splat_d: |
| 2137 | // We can't lower via VECTOR_SHUFFLE because it requires constant shuffle |
| 2138 | // masks, nor can we lower via BUILD_VECTOR & EXTRACT_VECTOR_ELT because |
| 2139 | // EXTRACT_VECTOR_ELT can't extract i64's on MIPS32. |
| 2140 | // Instead we lower to MipsISD::VSHF and match from there. |
| 2141 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 2142 | lowerMSASplatZExt(Op, 2, DAG), Op->getOperand(1), |
Daniel Sanders | e7ef0c8 | 2013-10-30 13:07:44 +0000 | [diff] [blame] | 2143 | Op->getOperand(1)); |
Daniel Sanders | 7e51fe1 | 2013-09-27 11:48:57 +0000 | [diff] [blame] | 2144 | case Intrinsic::mips_splati_b: |
| 2145 | case Intrinsic::mips_splati_h: |
| 2146 | case Intrinsic::mips_splati_w: |
| 2147 | case Intrinsic::mips_splati_d: |
| 2148 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
| 2149 | lowerMSASplatImm(Op, 2, DAG), Op->getOperand(1), |
| 2150 | Op->getOperand(1)); |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2151 | case Intrinsic::mips_sra_b: |
| 2152 | case Intrinsic::mips_sra_h: |
| 2153 | case Intrinsic::mips_sra_w: |
| 2154 | case Intrinsic::mips_sra_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2155 | return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), Op->getOperand(1), |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 2156 | truncateVecElts(Op, DAG)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 2157 | case Intrinsic::mips_srai_b: |
| 2158 | case Intrinsic::mips_srai_h: |
| 2159 | case Intrinsic::mips_srai_w: |
| 2160 | case Intrinsic::mips_srai_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2161 | return DAG.getNode(ISD::SRA, DL, Op->getValueType(0), |
| 2162 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2163 | case Intrinsic::mips_srari_b: |
| 2164 | case Intrinsic::mips_srari_h: |
| 2165 | case Intrinsic::mips_srari_w: |
| 2166 | case Intrinsic::mips_srari_d: { |
| 2167 | // Report an error for out of range values. |
| 2168 | int64_t Max; |
| 2169 | switch (Intrinsic) { |
| 2170 | case Intrinsic::mips_srari_b: Max = 7; break; |
| 2171 | case Intrinsic::mips_srari_h: Max = 15; break; |
| 2172 | case Intrinsic::mips_srari_w: Max = 31; break; |
| 2173 | case Intrinsic::mips_srari_d: Max = 63; break; |
| 2174 | default: llvm_unreachable("Unmatched intrinsic"); |
| 2175 | } |
| 2176 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue(); |
| 2177 | if (Value < 0 || Value > Max) |
| 2178 | report_fatal_error("Immediate out of range"); |
| 2179 | return SDValue(); |
| 2180 | } |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2181 | case Intrinsic::mips_srl_b: |
| 2182 | case Intrinsic::mips_srl_h: |
| 2183 | case Intrinsic::mips_srl_w: |
| 2184 | case Intrinsic::mips_srl_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2185 | return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), Op->getOperand(1), |
Petar Jovanovic | 2b6fe3f | 2017-04-20 13:26:46 +0000 | [diff] [blame] | 2186 | truncateVecElts(Op, DAG)); |
Daniel Sanders | cba1922 | 2013-09-24 10:28:18 +0000 | [diff] [blame] | 2187 | case Intrinsic::mips_srli_b: |
| 2188 | case Intrinsic::mips_srli_h: |
| 2189 | case Intrinsic::mips_srli_w: |
| 2190 | case Intrinsic::mips_srli_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2191 | return DAG.getNode(ISD::SRL, DL, Op->getValueType(0), |
| 2192 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2193 | case Intrinsic::mips_srlri_b: |
| 2194 | case Intrinsic::mips_srlri_h: |
| 2195 | case Intrinsic::mips_srlri_w: |
| 2196 | case Intrinsic::mips_srlri_d: { |
| 2197 | // Report an error for out of range values. |
| 2198 | int64_t Max; |
| 2199 | switch (Intrinsic) { |
| 2200 | case Intrinsic::mips_srlri_b: Max = 7; break; |
| 2201 | case Intrinsic::mips_srlri_h: Max = 15; break; |
| 2202 | case Intrinsic::mips_srlri_w: Max = 31; break; |
| 2203 | case Intrinsic::mips_srlri_d: Max = 63; break; |
| 2204 | default: llvm_unreachable("Unmatched intrinsic"); |
| 2205 | } |
| 2206 | int64_t Value = cast<ConstantSDNode>(Op->getOperand(2))->getSExtValue(); |
| 2207 | if (Value < 0 || Value > Max) |
| 2208 | report_fatal_error("Immediate out of range"); |
| 2209 | return SDValue(); |
| 2210 | } |
Daniel Sanders | fbcb582 | 2013-09-11 11:58:30 +0000 | [diff] [blame] | 2211 | case Intrinsic::mips_subv_b: |
| 2212 | case Intrinsic::mips_subv_h: |
| 2213 | case Intrinsic::mips_subv_w: |
| 2214 | case Intrinsic::mips_subv_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2215 | return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), Op->getOperand(1), |
| 2216 | Op->getOperand(2)); |
Daniel Sanders | 86d0c8d | 2013-09-23 14:29:55 +0000 | [diff] [blame] | 2217 | case Intrinsic::mips_subvi_b: |
| 2218 | case Intrinsic::mips_subvi_h: |
| 2219 | case Intrinsic::mips_subvi_w: |
| 2220 | case Intrinsic::mips_subvi_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2221 | return DAG.getNode(ISD::SUB, DL, Op->getValueType(0), |
| 2222 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2223 | case Intrinsic::mips_vshf_b: |
| 2224 | case Intrinsic::mips_vshf_h: |
| 2225 | case Intrinsic::mips_vshf_w: |
| 2226 | case Intrinsic::mips_vshf_d: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2227 | return DAG.getNode(MipsISD::VSHF, DL, Op->getValueType(0), |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2228 | Op->getOperand(1), Op->getOperand(2), Op->getOperand(3)); |
Daniel Sanders | 8ca81e4 | 2013-09-23 12:57:42 +0000 | [diff] [blame] | 2229 | case Intrinsic::mips_xor_v: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2230 | return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), Op->getOperand(1), |
| 2231 | Op->getOperand(2)); |
Daniel Sanders | bfc39ce | 2013-09-24 12:32:47 +0000 | [diff] [blame] | 2232 | case Intrinsic::mips_xori_b: |
Daniel Sanders | 84e7caf | 2013-09-27 10:25:41 +0000 | [diff] [blame] | 2233 | return DAG.getNode(ISD::XOR, DL, Op->getValueType(0), |
| 2234 | Op->getOperand(1), lowerMSASplatImm(Op, 2, DAG)); |
Marcin Koscielnicki | 7efdca5 | 2016-04-27 17:21:49 +0000 | [diff] [blame] | 2235 | case Intrinsic::thread_pointer: { |
| 2236 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 2237 | return DAG.getNode(MipsISD::ThreadPointer, DL, PtrVT); |
| 2238 | } |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2239 | } |
| 2240 | } |
| 2241 | |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2242 | static SDValue lowerMSALoadIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr, |
| 2243 | const MipsSubtarget &Subtarget) { |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2244 | SDLoc DL(Op); |
| 2245 | SDValue ChainIn = Op->getOperand(0); |
| 2246 | SDValue Address = Op->getOperand(2); |
| 2247 | SDValue Offset = Op->getOperand(3); |
| 2248 | EVT ResTy = Op->getValueType(0); |
| 2249 | EVT PtrTy = Address->getValueType(0); |
| 2250 | |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2251 | // For N64 addresses have the underlying type MVT::i64. This intrinsic |
| 2252 | // however takes an i32 signed constant offset. The actual type of the |
| 2253 | // intrinsic is a scaled signed i10. |
| 2254 | if (Subtarget.isABI_N64()) |
| 2255 | Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset); |
| 2256 | |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2257 | Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2258 | return DAG.getLoad(ResTy, DL, ChainIn, Address, MachinePointerInfo(), |
| 2259 | /* Alignment = */ 16); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2260 | } |
| 2261 | |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2262 | SDValue MipsSETargetLowering::lowerINTRINSIC_W_CHAIN(SDValue Op, |
| 2263 | SelectionDAG &DAG) const { |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2264 | unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); |
| 2265 | switch (Intr) { |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2266 | default: |
| 2267 | return SDValue(); |
| 2268 | case Intrinsic::mips_extp: |
| 2269 | return lowerDSPIntr(Op, DAG, MipsISD::EXTP); |
| 2270 | case Intrinsic::mips_extpdp: |
| 2271 | return lowerDSPIntr(Op, DAG, MipsISD::EXTPDP); |
| 2272 | case Intrinsic::mips_extr_w: |
| 2273 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_W); |
| 2274 | case Intrinsic::mips_extr_r_w: |
| 2275 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_R_W); |
| 2276 | case Intrinsic::mips_extr_rs_w: |
| 2277 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_RS_W); |
| 2278 | case Intrinsic::mips_extr_s_h: |
| 2279 | return lowerDSPIntr(Op, DAG, MipsISD::EXTR_S_H); |
| 2280 | case Intrinsic::mips_mthlip: |
| 2281 | return lowerDSPIntr(Op, DAG, MipsISD::MTHLIP); |
| 2282 | case Intrinsic::mips_mulsaq_s_w_ph: |
| 2283 | return lowerDSPIntr(Op, DAG, MipsISD::MULSAQ_S_W_PH); |
| 2284 | case Intrinsic::mips_maq_s_w_phl: |
| 2285 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHL); |
| 2286 | case Intrinsic::mips_maq_s_w_phr: |
| 2287 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_S_W_PHR); |
| 2288 | case Intrinsic::mips_maq_sa_w_phl: |
| 2289 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHL); |
| 2290 | case Intrinsic::mips_maq_sa_w_phr: |
| 2291 | return lowerDSPIntr(Op, DAG, MipsISD::MAQ_SA_W_PHR); |
| 2292 | case Intrinsic::mips_dpaq_s_w_ph: |
| 2293 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_S_W_PH); |
| 2294 | case Intrinsic::mips_dpsq_s_w_ph: |
| 2295 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_S_W_PH); |
| 2296 | case Intrinsic::mips_dpaq_sa_l_w: |
| 2297 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQ_SA_L_W); |
| 2298 | case Intrinsic::mips_dpsq_sa_l_w: |
| 2299 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQ_SA_L_W); |
| 2300 | case Intrinsic::mips_dpaqx_s_w_ph: |
| 2301 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_S_W_PH); |
| 2302 | case Intrinsic::mips_dpaqx_sa_w_ph: |
| 2303 | return lowerDSPIntr(Op, DAG, MipsISD::DPAQX_SA_W_PH); |
| 2304 | case Intrinsic::mips_dpsqx_s_w_ph: |
| 2305 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_S_W_PH); |
| 2306 | case Intrinsic::mips_dpsqx_sa_w_ph: |
| 2307 | return lowerDSPIntr(Op, DAG, MipsISD::DPSQX_SA_W_PH); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2308 | case Intrinsic::mips_ld_b: |
| 2309 | case Intrinsic::mips_ld_h: |
| 2310 | case Intrinsic::mips_ld_w: |
| 2311 | case Intrinsic::mips_ld_d: |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2312 | return lowerMSALoadIntr(Op, DAG, Intr, Subtarget); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2313 | } |
| 2314 | } |
| 2315 | |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2316 | static SDValue lowerMSAStoreIntr(SDValue Op, SelectionDAG &DAG, unsigned Intr, |
| 2317 | const MipsSubtarget &Subtarget) { |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2318 | SDLoc DL(Op); |
| 2319 | SDValue ChainIn = Op->getOperand(0); |
| 2320 | SDValue Value = Op->getOperand(2); |
| 2321 | SDValue Address = Op->getOperand(3); |
| 2322 | SDValue Offset = Op->getOperand(4); |
| 2323 | EVT PtrTy = Address->getValueType(0); |
| 2324 | |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2325 | // For N64 addresses have the underlying type MVT::i64. This intrinsic |
| 2326 | // however takes an i32 signed constant offset. The actual type of the |
| 2327 | // intrinsic is a scaled signed i10. |
| 2328 | if (Subtarget.isABI_N64()) |
| 2329 | Offset = DAG.getNode(ISD::SIGN_EXTEND, DL, PtrTy, Offset); |
| 2330 | |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2331 | Address = DAG.getNode(ISD::ADD, DL, PtrTy, Address, Offset); |
| 2332 | |
Justin Lebar | 9c37581 | 2016-07-15 18:27:10 +0000 | [diff] [blame] | 2333 | return DAG.getStore(ChainIn, DL, Value, Address, MachinePointerInfo(), |
| 2334 | /* Alignment = */ 16); |
Daniel Sanders | e6ed5b7 | 2013-08-28 12:04:29 +0000 | [diff] [blame] | 2335 | } |
| 2336 | |
| 2337 | SDValue MipsSETargetLowering::lowerINTRINSIC_VOID(SDValue Op, |
| 2338 | SelectionDAG &DAG) const { |
| 2339 | unsigned Intr = cast<ConstantSDNode>(Op->getOperand(1))->getZExtValue(); |
| 2340 | switch (Intr) { |
| 2341 | default: |
| 2342 | return SDValue(); |
| 2343 | case Intrinsic::mips_st_b: |
| 2344 | case Intrinsic::mips_st_h: |
| 2345 | case Intrinsic::mips_st_w: |
| 2346 | case Intrinsic::mips_st_d: |
Simon Dardis | 548a53f | 2017-01-10 16:40:57 +0000 | [diff] [blame] | 2347 | return lowerMSAStoreIntr(Op, DAG, Intr, Subtarget); |
Akira Hatanaka | a6bbde5 | 2013-04-13 02:13:30 +0000 | [diff] [blame] | 2348 | } |
| 2349 | } |
| 2350 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame^] | 2351 | /// Check if the given BuildVectorSDNode is a splat. |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2352 | /// This method currently relies on DAG nodes being reused when equivalent, |
| 2353 | /// so it's possible for this to return false even when isConstantSplat returns |
| 2354 | /// true. |
| 2355 | static bool isSplatVector(const BuildVectorSDNode *N) { |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2356 | unsigned int nOps = N->getNumOperands(); |
Daniel Sanders | ab94b53 | 2013-10-30 15:20:38 +0000 | [diff] [blame] | 2357 | assert(nOps > 1 && "isSplatVector has 0 or 1 sized build vector"); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2358 | |
| 2359 | SDValue Operand0 = N->getOperand(0); |
| 2360 | |
| 2361 | for (unsigned int i = 1; i < nOps; ++i) { |
| 2362 | if (N->getOperand(i) != Operand0) |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | return true; |
| 2367 | } |
| 2368 | |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 2369 | // Lower ISD::EXTRACT_VECTOR_ELT into MipsISD::VEXTRACT_SEXT_ELT. |
| 2370 | // |
| 2371 | // The non-value bits resulting from ISD::EXTRACT_VECTOR_ELT are undefined. We |
| 2372 | // choose to sign-extend but we could have equally chosen zero-extend. The |
| 2373 | // DAGCombiner will fold any sign/zero extension of the ISD::EXTRACT_VECTOR_ELT |
| 2374 | // result into this node later (possibly changing it to a zero-extend in the |
| 2375 | // process). |
| 2376 | SDValue MipsSETargetLowering:: |
| 2377 | lowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) const { |
| 2378 | SDLoc DL(Op); |
| 2379 | EVT ResTy = Op->getValueType(0); |
| 2380 | SDValue Op0 = Op->getOperand(0); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 2381 | EVT VecTy = Op0->getValueType(0); |
| 2382 | |
| 2383 | if (!VecTy.is128BitVector()) |
| 2384 | return SDValue(); |
| 2385 | |
| 2386 | if (ResTy.isInteger()) { |
| 2387 | SDValue Op1 = Op->getOperand(1); |
| 2388 | EVT EltTy = VecTy.getVectorElementType(); |
| 2389 | return DAG.getNode(MipsISD::VEXTRACT_SEXT_ELT, DL, ResTy, Op0, Op1, |
| 2390 | DAG.getValueType(EltTy)); |
| 2391 | } |
| 2392 | |
| 2393 | return Op; |
Daniel Sanders | a4c8f3a | 2013-09-23 14:03:12 +0000 | [diff] [blame] | 2394 | } |
| 2395 | |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2396 | static bool isConstantOrUndef(const SDValue Op) { |
Sanjay Patel | 5719584 | 2016-03-14 17:28:46 +0000 | [diff] [blame] | 2397 | if (Op->isUndef()) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2398 | return true; |
Vasileios Kalintiris | 46963f6 | 2015-02-13 19:12:16 +0000 | [diff] [blame] | 2399 | if (isa<ConstantSDNode>(Op)) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2400 | return true; |
Vasileios Kalintiris | 46963f6 | 2015-02-13 19:12:16 +0000 | [diff] [blame] | 2401 | if (isa<ConstantFPSDNode>(Op)) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2402 | return true; |
| 2403 | return false; |
| 2404 | } |
| 2405 | |
| 2406 | static bool isConstantOrUndefBUILD_VECTOR(const BuildVectorSDNode *Op) { |
| 2407 | for (unsigned i = 0; i < Op->getNumOperands(); ++i) |
| 2408 | if (isConstantOrUndef(Op->getOperand(i))) |
| 2409 | return true; |
| 2410 | return false; |
| 2411 | } |
| 2412 | |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2413 | // Lowers ISD::BUILD_VECTOR into appropriate SelectionDAG nodes for the |
| 2414 | // backend. |
| 2415 | // |
| 2416 | // Lowers according to the following rules: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2417 | // - Constant splats are legal as-is as long as the SplatBitSize is a power of |
| 2418 | // 2 less than or equal to 64 and the value fits into a signed 10-bit |
| 2419 | // immediate |
| 2420 | // - Constant splats are lowered to bitconverted BUILD_VECTORs if SplatBitSize |
| 2421 | // is a power of 2 less than or equal to 64 and the value does not fit into a |
| 2422 | // signed 10-bit immediate |
| 2423 | // - Non-constant splats are legal as-is. |
| 2424 | // - Non-constant non-splats are lowered to sequences of INSERT_VECTOR_ELT. |
| 2425 | // - All others are illegal and must be expanded. |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2426 | SDValue MipsSETargetLowering::lowerBUILD_VECTOR(SDValue Op, |
| 2427 | SelectionDAG &DAG) const { |
| 2428 | BuildVectorSDNode *Node = cast<BuildVectorSDNode>(Op); |
| 2429 | EVT ResTy = Op->getValueType(0); |
| 2430 | SDLoc DL(Op); |
| 2431 | APInt SplatValue, SplatUndef; |
| 2432 | unsigned SplatBitSize; |
| 2433 | bool HasAnyUndefs; |
| 2434 | |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 2435 | if (!Subtarget.hasMSA() || !ResTy.is128BitVector()) |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2436 | return SDValue(); |
| 2437 | |
| 2438 | if (Node->isConstantSplat(SplatValue, SplatUndef, SplatBitSize, |
| 2439 | HasAnyUndefs, 8, |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 2440 | !Subtarget.isLittle()) && SplatBitSize <= 64) { |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2441 | // We can only cope with 8, 16, 32, or 64-bit elements |
| 2442 | if (SplatBitSize != 8 && SplatBitSize != 16 && SplatBitSize != 32 && |
| 2443 | SplatBitSize != 64) |
| 2444 | return SDValue(); |
| 2445 | |
Simon Dardis | 7090d14 | 2017-03-10 13:27:14 +0000 | [diff] [blame] | 2446 | // If the value isn't an integer type we will have to bitcast |
| 2447 | // from an integer type first. Also, if there are any undefs, we must |
| 2448 | // lower them to defined values first. |
| 2449 | if (ResTy.isInteger() && !HasAnyUndefs) |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2450 | return Op; |
| 2451 | |
| 2452 | EVT ViaVecTy; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2453 | |
| 2454 | switch (SplatBitSize) { |
| 2455 | default: |
| 2456 | return SDValue(); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2457 | case 8: |
| 2458 | ViaVecTy = MVT::v16i8; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2459 | break; |
| 2460 | case 16: |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2461 | ViaVecTy = MVT::v8i16; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2462 | break; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2463 | case 32: |
| 2464 | ViaVecTy = MVT::v4i32; |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2465 | break; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2466 | case 64: |
| 2467 | // There's no fill.d to fall back on for 64-bit values |
| 2468 | return SDValue(); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2469 | } |
| 2470 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 2471 | // SelectionDAG::getConstant will promote SplatValue appropriately. |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2472 | SDValue Result = DAG.getConstant(SplatValue, DL, ViaVecTy); |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2473 | |
Daniel Sanders | 50b8041 | 2013-11-15 12:56:49 +0000 | [diff] [blame] | 2474 | // Bitcast to the type we originally wanted |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2475 | if (ViaVecTy != ResTy) |
| 2476 | Result = DAG.getNode(ISD::BITCAST, SDLoc(Node), ResTy, Result); |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2477 | |
| 2478 | return Result; |
Daniel Sanders | f49dd82 | 2013-09-24 13:33:07 +0000 | [diff] [blame] | 2479 | } else if (isSplatVector(Node)) |
| 2480 | return Op; |
| 2481 | else if (!isConstantOrUndefBUILD_VECTOR(Node)) { |
Daniel Sanders | f86622b | 2013-09-24 13:16:15 +0000 | [diff] [blame] | 2482 | // Use INSERT_VECTOR_ELT operations rather than expand to stores. |
| 2483 | // The resulting code is the same length as the expansion, but it doesn't |
| 2484 | // use memory operations |
| 2485 | EVT ResTy = Node->getValueType(0); |
| 2486 | |
| 2487 | assert(ResTy.isVector()); |
| 2488 | |
| 2489 | unsigned NumElts = ResTy.getVectorNumElements(); |
| 2490 | SDValue Vector = DAG.getUNDEF(ResTy); |
| 2491 | for (unsigned i = 0; i < NumElts; ++i) { |
| 2492 | Vector = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, ResTy, Vector, |
| 2493 | Node->getOperand(i), |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2494 | DAG.getConstant(i, DL, MVT::i32)); |
Daniel Sanders | f86622b | 2013-09-24 13:16:15 +0000 | [diff] [blame] | 2495 | } |
| 2496 | return Vector; |
| 2497 | } |
Daniel Sanders | 7a289d0 | 2013-09-23 12:02:46 +0000 | [diff] [blame] | 2498 | |
| 2499 | return SDValue(); |
| 2500 | } |
| 2501 | |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2502 | // Lower VECTOR_SHUFFLE into SHF (if possible). |
| 2503 | // |
| 2504 | // SHF splits the vector into blocks of four elements, then shuffles these |
| 2505 | // elements according to a <4 x i2> constant (encoded as an integer immediate). |
| 2506 | // |
| 2507 | // It is therefore possible to lower into SHF when the mask takes the form: |
| 2508 | // <a, b, c, d, a+4, b+4, c+4, d+4, a+8, b+8, c+8, d+8, ...> |
| 2509 | // When undef's appear they are treated as if they were whatever value is |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2510 | // necessary in order to fit the above forms. |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2511 | // |
| 2512 | // For example: |
| 2513 | // %2 = shufflevector <8 x i16> %0, <8 x i16> undef, |
| 2514 | // <8 x i32> <i32 3, i32 2, i32 1, i32 0, |
| 2515 | // i32 7, i32 6, i32 5, i32 4> |
| 2516 | // is lowered to: |
| 2517 | // (SHF_H $w0, $w1, 27) |
| 2518 | // where the 27 comes from: |
| 2519 | // 3 + (2 << 2) + (1 << 4) + (0 << 6) |
| 2520 | static SDValue lowerVECTOR_SHUFFLE_SHF(SDValue Op, EVT ResTy, |
| 2521 | SmallVector<int, 16> Indices, |
| 2522 | SelectionDAG &DAG) { |
| 2523 | int SHFIndices[4] = { -1, -1, -1, -1 }; |
| 2524 | |
| 2525 | if (Indices.size() < 4) |
| 2526 | return SDValue(); |
| 2527 | |
| 2528 | for (unsigned i = 0; i < 4; ++i) { |
| 2529 | for (unsigned j = i; j < Indices.size(); j += 4) { |
| 2530 | int Idx = Indices[j]; |
| 2531 | |
| 2532 | // Convert from vector index to 4-element subvector index |
| 2533 | // If an index refers to an element outside of the subvector then give up |
| 2534 | if (Idx != -1) { |
| 2535 | Idx -= 4 * (j / 4); |
| 2536 | if (Idx < 0 || Idx >= 4) |
| 2537 | return SDValue(); |
| 2538 | } |
| 2539 | |
| 2540 | // If the mask has an undef, replace it with the current index. |
| 2541 | // Note that it might still be undef if the current index is also undef |
| 2542 | if (SHFIndices[i] == -1) |
| 2543 | SHFIndices[i] = Idx; |
| 2544 | |
| 2545 | // Check that non-undef values are the same as in the mask. If they |
| 2546 | // aren't then give up |
| 2547 | if (!(Idx == -1 || Idx == SHFIndices[i])) |
| 2548 | return SDValue(); |
| 2549 | } |
| 2550 | } |
| 2551 | |
| 2552 | // Calculate the immediate. Replace any remaining undefs with zero |
| 2553 | APInt Imm(32, 0); |
| 2554 | for (int i = 3; i >= 0; --i) { |
| 2555 | int Idx = SHFIndices[i]; |
| 2556 | |
| 2557 | if (Idx == -1) |
| 2558 | Idx = 0; |
| 2559 | |
| 2560 | Imm <<= 2; |
| 2561 | Imm |= Idx & 0x3; |
| 2562 | } |
| 2563 | |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2564 | SDLoc DL(Op); |
| 2565 | return DAG.getNode(MipsISD::SHF, DL, ResTy, |
| 2566 | DAG.getConstant(Imm, DL, MVT::i32), Op->getOperand(0)); |
Daniel Sanders | 2630718 | 2013-09-24 14:20:00 +0000 | [diff] [blame] | 2567 | } |
| 2568 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2569 | /// Determine whether a range fits a regular pattern of values. |
| 2570 | /// This function accounts for the possibility of jumping over the End iterator. |
| 2571 | template <typename ValType> |
| 2572 | static bool |
| 2573 | fitsRegularPattern(typename SmallVectorImpl<ValType>::const_iterator Begin, |
| 2574 | unsigned CheckStride, |
| 2575 | typename SmallVectorImpl<ValType>::const_iterator End, |
| 2576 | ValType ExpectedIndex, unsigned ExpectedIndexStride) { |
| 2577 | auto &I = Begin; |
| 2578 | |
| 2579 | while (I != End) { |
| 2580 | if (*I != -1 && *I != ExpectedIndex) |
| 2581 | return false; |
| 2582 | ExpectedIndex += ExpectedIndexStride; |
| 2583 | |
| 2584 | // Incrementing past End is undefined behaviour so we must increment one |
| 2585 | // step at a time and check for End at each step. |
| 2586 | for (unsigned n = 0; n < CheckStride && I != End; ++n, ++I) |
| 2587 | ; // Empty loop body. |
| 2588 | } |
| 2589 | return true; |
| 2590 | } |
| 2591 | |
| 2592 | // Determine whether VECTOR_SHUFFLE is a SPLATI. |
| 2593 | // |
| 2594 | // It is a SPLATI when the mask is: |
| 2595 | // <x, x, x, ...> |
| 2596 | // where x is any valid index. |
| 2597 | // |
| 2598 | // When undef's appear in the mask they are treated as if they were whatever |
| 2599 | // value is necessary in order to fit the above form. |
| 2600 | static bool isVECTOR_SHUFFLE_SPLATI(SDValue Op, EVT ResTy, |
| 2601 | SmallVector<int, 16> Indices, |
| 2602 | SelectionDAG &DAG) { |
| 2603 | assert((Indices.size() % 2) == 0); |
| 2604 | |
| 2605 | int SplatIndex = -1; |
| 2606 | for (const auto &V : Indices) { |
| 2607 | if (V != -1) { |
| 2608 | SplatIndex = V; |
| 2609 | break; |
| 2610 | } |
| 2611 | } |
| 2612 | |
| 2613 | return fitsRegularPattern<int>(Indices.begin(), 1, Indices.end(), SplatIndex, |
| 2614 | 0); |
| 2615 | } |
| 2616 | |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2617 | // Lower VECTOR_SHUFFLE into ILVEV (if possible). |
| 2618 | // |
| 2619 | // ILVEV interleaves the even elements from each vector. |
| 2620 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2621 | // It is possible to lower into ILVEV when the mask consists of two of the |
| 2622 | // following forms interleaved: |
| 2623 | // <0, 2, 4, ...> |
| 2624 | // <n, n+2, n+4, ...> |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2625 | // where n is the number of elements in the vector. |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2626 | // For example: |
| 2627 | // <0, 0, 2, 2, 4, 4, ...> |
| 2628 | // <0, n, 2, n+2, 4, n+4, ...> |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2629 | // |
| 2630 | // When undef's appear in the mask they are treated as if they were whatever |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2631 | // value is necessary in order to fit the above forms. |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2632 | static SDValue lowerVECTOR_SHUFFLE_ILVEV(SDValue Op, EVT ResTy, |
| 2633 | SmallVector<int, 16> Indices, |
| 2634 | SelectionDAG &DAG) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2635 | assert((Indices.size() % 2) == 0); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2636 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2637 | SDValue Wt; |
| 2638 | SDValue Ws; |
| 2639 | const auto &Begin = Indices.begin(); |
| 2640 | const auto &End = Indices.end(); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2641 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2642 | // Check even elements are taken from the even elements of one half or the |
| 2643 | // other and pick an operand accordingly. |
| 2644 | if (fitsRegularPattern<int>(Begin, 2, End, 0, 2)) |
| 2645 | Wt = Op->getOperand(0); |
| 2646 | else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 2)) |
| 2647 | Wt = Op->getOperand(1); |
| 2648 | else |
| 2649 | return SDValue(); |
| 2650 | |
| 2651 | // Check odd elements are taken from the even elements of one half or the |
| 2652 | // other and pick an operand accordingly. |
| 2653 | if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 2)) |
| 2654 | Ws = Op->getOperand(0); |
| 2655 | else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 2)) |
| 2656 | Ws = Op->getOperand(1); |
| 2657 | else |
| 2658 | return SDValue(); |
| 2659 | |
| 2660 | return DAG.getNode(MipsISD::ILVEV, SDLoc(Op), ResTy, Ws, Wt); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2661 | } |
| 2662 | |
| 2663 | // Lower VECTOR_SHUFFLE into ILVOD (if possible). |
| 2664 | // |
| 2665 | // ILVOD interleaves the odd elements from each vector. |
| 2666 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2667 | // It is possible to lower into ILVOD when the mask consists of two of the |
| 2668 | // following forms interleaved: |
| 2669 | // <1, 3, 5, ...> |
| 2670 | // <n+1, n+3, n+5, ...> |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2671 | // where n is the number of elements in the vector. |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2672 | // For example: |
| 2673 | // <1, 1, 3, 3, 5, 5, ...> |
| 2674 | // <1, n+1, 3, n+3, 5, n+5, ...> |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2675 | // |
| 2676 | // When undef's appear in the mask they are treated as if they were whatever |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2677 | // value is necessary in order to fit the above forms. |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2678 | static SDValue lowerVECTOR_SHUFFLE_ILVOD(SDValue Op, EVT ResTy, |
| 2679 | SmallVector<int, 16> Indices, |
| 2680 | SelectionDAG &DAG) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2681 | assert((Indices.size() % 2) == 0); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2682 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2683 | SDValue Wt; |
| 2684 | SDValue Ws; |
| 2685 | const auto &Begin = Indices.begin(); |
| 2686 | const auto &End = Indices.end(); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2687 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2688 | // Check even elements are taken from the odd elements of one half or the |
| 2689 | // other and pick an operand accordingly. |
| 2690 | if (fitsRegularPattern<int>(Begin, 2, End, 1, 2)) |
| 2691 | Wt = Op->getOperand(0); |
| 2692 | else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + 1, 2)) |
| 2693 | Wt = Op->getOperand(1); |
| 2694 | else |
| 2695 | return SDValue(); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2696 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2697 | // Check odd elements are taken from the odd elements of one half or the |
| 2698 | // other and pick an operand accordingly. |
| 2699 | if (fitsRegularPattern<int>(Begin + 1, 2, End, 1, 2)) |
| 2700 | Ws = Op->getOperand(0); |
| 2701 | else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + 1, 2)) |
| 2702 | Ws = Op->getOperand(1); |
| 2703 | else |
| 2704 | return SDValue(); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2705 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2706 | return DAG.getNode(MipsISD::ILVOD, SDLoc(Op), ResTy, Wt, Ws); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2707 | } |
| 2708 | |
| 2709 | // Lower VECTOR_SHUFFLE into ILVR (if possible). |
| 2710 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2711 | // ILVR interleaves consecutive elements from the right (lowest-indexed) half of |
| 2712 | // each vector. |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2713 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2714 | // It is possible to lower into ILVR when the mask consists of two of the |
| 2715 | // following forms interleaved: |
| 2716 | // <0, 1, 2, ...> |
| 2717 | // <n, n+1, n+2, ...> |
| 2718 | // where n is the number of elements in the vector. |
| 2719 | // For example: |
| 2720 | // <0, 0, 1, 1, 2, 2, ...> |
| 2721 | // <0, n, 1, n+1, 2, n+2, ...> |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2722 | // |
| 2723 | // When undef's appear in the mask they are treated as if they were whatever |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2724 | // value is necessary in order to fit the above forms. |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2725 | static SDValue lowerVECTOR_SHUFFLE_ILVR(SDValue Op, EVT ResTy, |
| 2726 | SmallVector<int, 16> Indices, |
| 2727 | SelectionDAG &DAG) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2728 | assert((Indices.size() % 2) == 0); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2729 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2730 | SDValue Wt; |
| 2731 | SDValue Ws; |
| 2732 | const auto &Begin = Indices.begin(); |
| 2733 | const auto &End = Indices.end(); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2734 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2735 | // Check even elements are taken from the right (lowest-indexed) elements of |
| 2736 | // one half or the other and pick an operand accordingly. |
| 2737 | if (fitsRegularPattern<int>(Begin, 2, End, 0, 1)) |
| 2738 | Wt = Op->getOperand(0); |
| 2739 | else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size(), 1)) |
| 2740 | Wt = Op->getOperand(1); |
| 2741 | else |
| 2742 | return SDValue(); |
| 2743 | |
| 2744 | // Check odd elements are taken from the right (lowest-indexed) elements of |
| 2745 | // one half or the other and pick an operand accordingly. |
| 2746 | if (fitsRegularPattern<int>(Begin + 1, 2, End, 0, 1)) |
| 2747 | Ws = Op->getOperand(0); |
| 2748 | else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size(), 1)) |
| 2749 | Ws = Op->getOperand(1); |
| 2750 | else |
| 2751 | return SDValue(); |
| 2752 | |
| 2753 | return DAG.getNode(MipsISD::ILVR, SDLoc(Op), ResTy, Ws, Wt); |
| 2754 | } |
| 2755 | |
| 2756 | // Lower VECTOR_SHUFFLE into ILVL (if possible). |
| 2757 | // |
| 2758 | // ILVL interleaves consecutive elements from the left (highest-indexed) half |
| 2759 | // of each vector. |
| 2760 | // |
| 2761 | // It is possible to lower into ILVL when the mask consists of two of the |
| 2762 | // following forms interleaved: |
| 2763 | // <x, x+1, x+2, ...> |
| 2764 | // <n+x, n+x+1, n+x+2, ...> |
| 2765 | // where n is the number of elements in the vector and x is half n. |
| 2766 | // For example: |
| 2767 | // <x, x, x+1, x+1, x+2, x+2, ...> |
| 2768 | // <x, n+x, x+1, n+x+1, x+2, n+x+2, ...> |
| 2769 | // |
| 2770 | // When undef's appear in the mask they are treated as if they were whatever |
| 2771 | // value is necessary in order to fit the above forms. |
| 2772 | static SDValue lowerVECTOR_SHUFFLE_ILVL(SDValue Op, EVT ResTy, |
| 2773 | SmallVector<int, 16> Indices, |
| 2774 | SelectionDAG &DAG) { |
| 2775 | assert((Indices.size() % 2) == 0); |
| 2776 | |
| 2777 | unsigned HalfSize = Indices.size() / 2; |
| 2778 | SDValue Wt; |
| 2779 | SDValue Ws; |
| 2780 | const auto &Begin = Indices.begin(); |
| 2781 | const auto &End = Indices.end(); |
| 2782 | |
| 2783 | // Check even elements are taken from the left (highest-indexed) elements of |
| 2784 | // one half or the other and pick an operand accordingly. |
| 2785 | if (fitsRegularPattern<int>(Begin, 2, End, HalfSize, 1)) |
| 2786 | Wt = Op->getOperand(0); |
| 2787 | else if (fitsRegularPattern<int>(Begin, 2, End, Indices.size() + HalfSize, 1)) |
| 2788 | Wt = Op->getOperand(1); |
| 2789 | else |
| 2790 | return SDValue(); |
| 2791 | |
| 2792 | // Check odd elements are taken from the left (highest-indexed) elements of |
| 2793 | // one half or the other and pick an operand accordingly. |
| 2794 | if (fitsRegularPattern<int>(Begin + 1, 2, End, HalfSize, 1)) |
| 2795 | Ws = Op->getOperand(0); |
| 2796 | else if (fitsRegularPattern<int>(Begin + 1, 2, End, Indices.size() + HalfSize, |
| 2797 | 1)) |
| 2798 | Ws = Op->getOperand(1); |
| 2799 | else |
| 2800 | return SDValue(); |
| 2801 | |
| 2802 | return DAG.getNode(MipsISD::ILVL, SDLoc(Op), ResTy, Ws, Wt); |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2805 | // Lower VECTOR_SHUFFLE into PCKEV (if possible). |
| 2806 | // |
| 2807 | // PCKEV copies the even elements of each vector into the result vector. |
| 2808 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2809 | // It is possible to lower into PCKEV when the mask consists of two of the |
| 2810 | // following forms concatenated: |
| 2811 | // <0, 2, 4, ...> |
| 2812 | // <n, n+2, n+4, ...> |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2813 | // where n is the number of elements in the vector. |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2814 | // For example: |
| 2815 | // <0, 2, 4, ..., 0, 2, 4, ...> |
| 2816 | // <0, 2, 4, ..., n, n+2, n+4, ...> |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2817 | // |
| 2818 | // When undef's appear in the mask they are treated as if they were whatever |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2819 | // value is necessary in order to fit the above forms. |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2820 | static SDValue lowerVECTOR_SHUFFLE_PCKEV(SDValue Op, EVT ResTy, |
| 2821 | SmallVector<int, 16> Indices, |
| 2822 | SelectionDAG &DAG) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2823 | assert((Indices.size() % 2) == 0); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2824 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2825 | SDValue Wt; |
| 2826 | SDValue Ws; |
| 2827 | const auto &Begin = Indices.begin(); |
| 2828 | const auto &Mid = Indices.begin() + Indices.size() / 2; |
| 2829 | const auto &End = Indices.end(); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2830 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2831 | if (fitsRegularPattern<int>(Begin, 1, Mid, 0, 2)) |
| 2832 | Wt = Op->getOperand(0); |
| 2833 | else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size(), 2)) |
| 2834 | Wt = Op->getOperand(1); |
| 2835 | else |
| 2836 | return SDValue(); |
| 2837 | |
| 2838 | if (fitsRegularPattern<int>(Mid, 1, End, 0, 2)) |
| 2839 | Ws = Op->getOperand(0); |
| 2840 | else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size(), 2)) |
| 2841 | Ws = Op->getOperand(1); |
| 2842 | else |
| 2843 | return SDValue(); |
| 2844 | |
| 2845 | return DAG.getNode(MipsISD::PCKEV, SDLoc(Op), ResTy, Ws, Wt); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | // Lower VECTOR_SHUFFLE into PCKOD (if possible). |
| 2849 | // |
| 2850 | // PCKOD copies the odd elements of each vector into the result vector. |
| 2851 | // |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2852 | // It is possible to lower into PCKOD when the mask consists of two of the |
| 2853 | // following forms concatenated: |
| 2854 | // <1, 3, 5, ...> |
| 2855 | // <n+1, n+3, n+5, ...> |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2856 | // where n is the number of elements in the vector. |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2857 | // For example: |
| 2858 | // <1, 3, 5, ..., 1, 3, 5, ...> |
| 2859 | // <1, 3, 5, ..., n+1, n+3, n+5, ...> |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2860 | // |
| 2861 | // When undef's appear in the mask they are treated as if they were whatever |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2862 | // value is necessary in order to fit the above forms. |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2863 | static SDValue lowerVECTOR_SHUFFLE_PCKOD(SDValue Op, EVT ResTy, |
| 2864 | SmallVector<int, 16> Indices, |
| 2865 | SelectionDAG &DAG) { |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2866 | assert((Indices.size() % 2) == 0); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2867 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2868 | SDValue Wt; |
| 2869 | SDValue Ws; |
| 2870 | const auto &Begin = Indices.begin(); |
| 2871 | const auto &Mid = Indices.begin() + Indices.size() / 2; |
| 2872 | const auto &End = Indices.end(); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2873 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2874 | if (fitsRegularPattern<int>(Begin, 1, Mid, 1, 2)) |
| 2875 | Wt = Op->getOperand(0); |
| 2876 | else if (fitsRegularPattern<int>(Begin, 1, Mid, Indices.size() + 1, 2)) |
| 2877 | Wt = Op->getOperand(1); |
| 2878 | else |
| 2879 | return SDValue(); |
| 2880 | |
| 2881 | if (fitsRegularPattern<int>(Mid, 1, End, 1, 2)) |
| 2882 | Ws = Op->getOperand(0); |
| 2883 | else if (fitsRegularPattern<int>(Mid, 1, End, Indices.size() + 1, 2)) |
| 2884 | Ws = Op->getOperand(1); |
| 2885 | else |
| 2886 | return SDValue(); |
| 2887 | |
| 2888 | return DAG.getNode(MipsISD::PCKOD, SDLoc(Op), ResTy, Ws, Wt); |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2889 | } |
| 2890 | |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2891 | // Lower VECTOR_SHUFFLE into VSHF. |
| 2892 | // |
| 2893 | // This mostly consists of converting the shuffle indices in Indices into a |
| 2894 | // BUILD_VECTOR and adding it as an operand to the resulting VSHF. There is |
| 2895 | // also code to eliminate unused operands of the VECTOR_SHUFFLE. For example, |
| 2896 | // if the type is v8i16 and all the indices are less than 8 then the second |
| 2897 | // operand is unused and can be replaced with anything. We choose to replace it |
| 2898 | // with the used operand since this reduces the number of instructions overall. |
| 2899 | static SDValue lowerVECTOR_SHUFFLE_VSHF(SDValue Op, EVT ResTy, |
| 2900 | SmallVector<int, 16> Indices, |
| 2901 | SelectionDAG &DAG) { |
| 2902 | SmallVector<SDValue, 16> Ops; |
| 2903 | SDValue Op0; |
| 2904 | SDValue Op1; |
| 2905 | EVT MaskVecTy = ResTy.changeVectorElementTypeToInteger(); |
| 2906 | EVT MaskEltTy = MaskVecTy.getVectorElementType(); |
| 2907 | bool Using1stVec = false; |
| 2908 | bool Using2ndVec = false; |
| 2909 | SDLoc DL(Op); |
| 2910 | int ResTyNumElts = ResTy.getVectorNumElements(); |
| 2911 | |
| 2912 | for (int i = 0; i < ResTyNumElts; ++i) { |
| 2913 | // Idx == -1 means UNDEF |
| 2914 | int Idx = Indices[i]; |
| 2915 | |
| 2916 | if (0 <= Idx && Idx < ResTyNumElts) |
| 2917 | Using1stVec = true; |
| 2918 | if (ResTyNumElts <= Idx && Idx < ResTyNumElts * 2) |
| 2919 | Using2ndVec = true; |
| 2920 | } |
| 2921 | |
| 2922 | for (SmallVector<int, 16>::iterator I = Indices.begin(); I != Indices.end(); |
| 2923 | ++I) |
Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2924 | Ops.push_back(DAG.getTargetConstant(*I, DL, MaskEltTy)); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2925 | |
Ahmed Bougacha | 128f873 | 2016-04-26 21:15:30 +0000 | [diff] [blame] | 2926 | SDValue MaskVec = DAG.getBuildVector(MaskVecTy, DL, Ops); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2927 | |
| 2928 | if (Using1stVec && Using2ndVec) { |
| 2929 | Op0 = Op->getOperand(0); |
| 2930 | Op1 = Op->getOperand(1); |
| 2931 | } else if (Using1stVec) |
| 2932 | Op0 = Op1 = Op->getOperand(0); |
| 2933 | else if (Using2ndVec) |
| 2934 | Op0 = Op1 = Op->getOperand(1); |
| 2935 | else |
| 2936 | llvm_unreachable("shuffle vector mask references neither vector operand?"); |
| 2937 | |
Daniel Sanders | f88a29e | 2014-03-21 16:56:51 +0000 | [diff] [blame] | 2938 | // VECTOR_SHUFFLE concatenates the vectors in an vectorwise fashion. |
| 2939 | // <0b00, 0b01> + <0b10, 0b11> -> <0b00, 0b01, 0b10, 0b11> |
| 2940 | // VSHF concatenates the vectors in a bitwise fashion: |
| 2941 | // <0b00, 0b01> + <0b10, 0b11> -> |
| 2942 | // 0b0100 + 0b1110 -> 0b01001110 |
| 2943 | // <0b10, 0b11, 0b00, 0b01> |
| 2944 | // We must therefore swap the operands to get the correct result. |
| 2945 | return DAG.getNode(MipsISD::VSHF, DL, ResTy, MaskVec, Op1, Op0); |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | // Lower VECTOR_SHUFFLE into one of a number of instructions depending on the |
| 2949 | // indices in the shuffle. |
| 2950 | SDValue MipsSETargetLowering::lowerVECTOR_SHUFFLE(SDValue Op, |
| 2951 | SelectionDAG &DAG) const { |
| 2952 | ShuffleVectorSDNode *Node = cast<ShuffleVectorSDNode>(Op); |
| 2953 | EVT ResTy = Op->getValueType(0); |
| 2954 | |
| 2955 | if (!ResTy.is128BitVector()) |
| 2956 | return SDValue(); |
| 2957 | |
| 2958 | int ResTyNumElts = ResTy.getVectorNumElements(); |
| 2959 | SmallVector<int, 16> Indices; |
| 2960 | |
| 2961 | for (int i = 0; i < ResTyNumElts; ++i) |
| 2962 | Indices.push_back(Node->getMaskElt(i)); |
| 2963 | |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2964 | // splati.[bhwd] is preferable to the others but is matched from |
| 2965 | // MipsISD::VSHF. |
| 2966 | if (isVECTOR_SHUFFLE_SPLATI(Op, ResTy, Indices, DAG)) |
| 2967 | return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, DAG); |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2968 | SDValue Result; |
| 2969 | if ((Result = lowerVECTOR_SHUFFLE_ILVEV(Op, ResTy, Indices, DAG))) |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2970 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2971 | if ((Result = lowerVECTOR_SHUFFLE_ILVOD(Op, ResTy, Indices, DAG))) |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2972 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2973 | if ((Result = lowerVECTOR_SHUFFLE_ILVL(Op, ResTy, Indices, DAG))) |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2974 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2975 | if ((Result = lowerVECTOR_SHUFFLE_ILVR(Op, ResTy, Indices, DAG))) |
Daniel Sanders | 2ed228b | 2013-09-24 14:36:12 +0000 | [diff] [blame] | 2976 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2977 | if ((Result = lowerVECTOR_SHUFFLE_PCKEV(Op, ResTy, Indices, DAG))) |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2978 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2979 | if ((Result = lowerVECTOR_SHUFFLE_PCKOD(Op, ResTy, Indices, DAG))) |
Daniel Sanders | fae5f2a | 2013-09-24 14:53:25 +0000 | [diff] [blame] | 2980 | return Result; |
Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 2981 | if ((Result = lowerVECTOR_SHUFFLE_SHF(Op, ResTy, Indices, DAG))) |
Daniel Sanders | c8cd58f | 2015-05-19 12:24:52 +0000 | [diff] [blame] | 2982 | return Result; |
Daniel Sanders | e508704 | 2013-09-24 14:02:15 +0000 | [diff] [blame] | 2983 | return lowerVECTOR_SHUFFLE_VSHF(Op, ResTy, Indices, DAG); |
| 2984 | } |
| 2985 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 2986 | MachineBasicBlock * |
| 2987 | MipsSETargetLowering::emitBPOSGE32(MachineInstr &MI, |
| 2988 | MachineBasicBlock *BB) const { |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 2989 | // $bb: |
| 2990 | // bposge32_pseudo $vr0 |
| 2991 | // => |
| 2992 | // $bb: |
| 2993 | // bposge32 $tbb |
| 2994 | // $fbb: |
| 2995 | // li $vr2, 0 |
| 2996 | // b $sink |
| 2997 | // $tbb: |
| 2998 | // li $vr1, 1 |
| 2999 | // $sink: |
| 3000 | // $vr0 = phi($vr2, $fbb, $vr1, $tbb) |
| 3001 | |
| 3002 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3003 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Akira Hatanaka | 13e6ccf | 2013-08-06 23:08:38 +0000 | [diff] [blame] | 3004 | const TargetRegisterClass *RC = &Mips::GPR32RegClass; |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3005 | DebugLoc DL = MI.getDebugLoc(); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3006 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 3007 | MachineFunction::iterator It = std::next(MachineFunction::iterator(BB)); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3008 | MachineFunction *F = BB->getParent(); |
| 3009 | MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3010 | MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3011 | MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); |
| 3012 | F->insert(It, FBB); |
| 3013 | F->insert(It, TBB); |
| 3014 | F->insert(It, Sink); |
| 3015 | |
| 3016 | // Transfer the remainder of BB and its successor edges to Sink. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 3017 | Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)), |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3018 | BB->end()); |
| 3019 | Sink->transferSuccessorsAndUpdatePHIs(BB); |
| 3020 | |
| 3021 | // Add successors. |
| 3022 | BB->addSuccessor(FBB); |
| 3023 | BB->addSuccessor(TBB); |
| 3024 | FBB->addSuccessor(Sink); |
| 3025 | TBB->addSuccessor(Sink); |
| 3026 | |
| 3027 | // Insert the real bposge32 instruction to $BB. |
| 3028 | BuildMI(BB, DL, TII->get(Mips::BPOSGE32)).addMBB(TBB); |
Hrvoje Varga | 6f09cdf | 2016-05-13 11:32:53 +0000 | [diff] [blame] | 3029 | // Insert the real bposge32c instruction to $BB. |
| 3030 | BuildMI(BB, DL, TII->get(Mips::BPOSGE32C_MMR3)).addMBB(TBB); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3031 | |
| 3032 | // Fill $FBB. |
| 3033 | unsigned VR2 = RegInfo.createVirtualRegister(RC); |
| 3034 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), VR2) |
| 3035 | .addReg(Mips::ZERO).addImm(0); |
| 3036 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); |
| 3037 | |
| 3038 | // Fill $TBB. |
| 3039 | unsigned VR1 = RegInfo.createVirtualRegister(RC); |
| 3040 | BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), VR1) |
| 3041 | .addReg(Mips::ZERO).addImm(1); |
| 3042 | |
| 3043 | // Insert phi function to $Sink. |
| 3044 | BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3045 | MI.getOperand(0).getReg()) |
| 3046 | .addReg(VR2) |
| 3047 | .addMBB(FBB) |
| 3048 | .addReg(VR1) |
| 3049 | .addMBB(TBB); |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3050 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3051 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Akira Hatanaka | 96ca182 | 2013-03-13 00:54:29 +0000 | [diff] [blame] | 3052 | return Sink; |
| 3053 | } |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3054 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3055 | MachineBasicBlock *MipsSETargetLowering::emitMSACBranchPseudo( |
| 3056 | MachineInstr &MI, MachineBasicBlock *BB, unsigned BranchOp) const { |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3057 | // $bb: |
| 3058 | // vany_nonzero $rd, $ws |
| 3059 | // => |
| 3060 | // $bb: |
| 3061 | // bnz.b $ws, $tbb |
| 3062 | // b $fbb |
| 3063 | // $fbb: |
| 3064 | // li $rd1, 0 |
| 3065 | // b $sink |
| 3066 | // $tbb: |
| 3067 | // li $rd2, 1 |
| 3068 | // $sink: |
| 3069 | // $rd = phi($rd1, $fbb, $rd2, $tbb) |
| 3070 | |
| 3071 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3072 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3073 | const TargetRegisterClass *RC = &Mips::GPR32RegClass; |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3074 | DebugLoc DL = MI.getDebugLoc(); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3075 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 3076 | MachineFunction::iterator It = std::next(MachineFunction::iterator(BB)); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3077 | MachineFunction *F = BB->getParent(); |
| 3078 | MachineBasicBlock *FBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3079 | MachineBasicBlock *TBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 3080 | MachineBasicBlock *Sink = F->CreateMachineBasicBlock(LLVM_BB); |
| 3081 | F->insert(It, FBB); |
| 3082 | F->insert(It, TBB); |
| 3083 | F->insert(It, Sink); |
| 3084 | |
| 3085 | // Transfer the remainder of BB and its successor edges to Sink. |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 3086 | Sink->splice(Sink->begin(), BB, std::next(MachineBasicBlock::iterator(MI)), |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3087 | BB->end()); |
| 3088 | Sink->transferSuccessorsAndUpdatePHIs(BB); |
| 3089 | |
| 3090 | // Add successors. |
| 3091 | BB->addSuccessor(FBB); |
| 3092 | BB->addSuccessor(TBB); |
| 3093 | FBB->addSuccessor(Sink); |
| 3094 | TBB->addSuccessor(Sink); |
| 3095 | |
| 3096 | // Insert the real bnz.b instruction to $BB. |
| 3097 | BuildMI(BB, DL, TII->get(BranchOp)) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3098 | .addReg(MI.getOperand(1).getReg()) |
| 3099 | .addMBB(TBB); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3100 | |
| 3101 | // Fill $FBB. |
| 3102 | unsigned RD1 = RegInfo.createVirtualRegister(RC); |
| 3103 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::ADDiu), RD1) |
| 3104 | .addReg(Mips::ZERO).addImm(0); |
| 3105 | BuildMI(*FBB, FBB->end(), DL, TII->get(Mips::B)).addMBB(Sink); |
| 3106 | |
| 3107 | // Fill $TBB. |
| 3108 | unsigned RD2 = RegInfo.createVirtualRegister(RC); |
| 3109 | BuildMI(*TBB, TBB->end(), DL, TII->get(Mips::ADDiu), RD2) |
| 3110 | .addReg(Mips::ZERO).addImm(1); |
| 3111 | |
| 3112 | // Insert phi function to $Sink. |
| 3113 | BuildMI(*Sink, Sink->begin(), DL, TII->get(Mips::PHI), |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3114 | MI.getOperand(0).getReg()) |
| 3115 | .addReg(RD1) |
| 3116 | .addMBB(FBB) |
| 3117 | .addReg(RD2) |
| 3118 | .addMBB(TBB); |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3119 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3120 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | ce09d07 | 2013-08-28 12:14:50 +0000 | [diff] [blame] | 3121 | return Sink; |
| 3122 | } |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3123 | |
| 3124 | // Emit the COPY_FW pseudo instruction. |
| 3125 | // |
| 3126 | // copy_fw_pseudo $fd, $ws, n |
| 3127 | // => |
| 3128 | // copy_u_w $rt, $ws, $n |
| 3129 | // mtc1 $rt, $fd |
| 3130 | // |
| 3131 | // When n is zero, the equivalent operation can be performed with (potentially) |
| 3132 | // zero instructions due to register overlaps. This optimization is never valid |
| 3133 | // for lane 1 because it would require FR=0 mode which isn't supported by MSA. |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3134 | MachineBasicBlock * |
| 3135 | MipsSETargetLowering::emitCOPY_FW(MachineInstr &MI, |
| 3136 | MachineBasicBlock *BB) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3137 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3138 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3139 | DebugLoc DL = MI.getDebugLoc(); |
| 3140 | unsigned Fd = MI.getOperand(0).getReg(); |
| 3141 | unsigned Ws = MI.getOperand(1).getReg(); |
| 3142 | unsigned Lane = MI.getOperand(2).getImm(); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3143 | |
Daniel Sanders | afe27c7 | 2015-02-23 17:22:16 +0000 | [diff] [blame] | 3144 | if (Lane == 0) { |
| 3145 | unsigned Wt = Ws; |
| 3146 | if (!Subtarget.useOddSPReg()) { |
| 3147 | // We must copy to an even-numbered MSA register so that the |
| 3148 | // single-precision sub-register is also guaranteed to be even-numbered. |
| 3149 | Wt = RegInfo.createVirtualRegister(&Mips::MSA128WEvensRegClass); |
| 3150 | |
| 3151 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Wt).addReg(Ws); |
| 3152 | } |
| 3153 | |
| 3154 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_lo); |
| 3155 | } else { |
| 3156 | unsigned Wt = RegInfo.createVirtualRegister( |
| 3157 | Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass : |
| 3158 | &Mips::MSA128WEvensRegClass); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3159 | |
Daniel Sanders | d920770 | 2014-03-04 13:54:30 +0000 | [diff] [blame] | 3160 | 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] | 3161 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_lo); |
| 3162 | } |
| 3163 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3164 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3165 | return BB; |
| 3166 | } |
| 3167 | |
| 3168 | // Emit the COPY_FD pseudo instruction. |
| 3169 | // |
| 3170 | // copy_fd_pseudo $fd, $ws, n |
| 3171 | // => |
| 3172 | // splati.d $wt, $ws, $n |
| 3173 | // copy $fd, $wt:sub_64 |
| 3174 | // |
| 3175 | // When n is zero, the equivalent operation can be performed with (potentially) |
| 3176 | // zero instructions due to register overlaps. This optimization is always |
| 3177 | // valid because FR=1 mode which is the only supported mode in MSA. |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3178 | MachineBasicBlock * |
| 3179 | MipsSETargetLowering::emitCOPY_FD(MachineInstr &MI, |
| 3180 | MachineBasicBlock *BB) const { |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 3181 | assert(Subtarget.isFP64bit()); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3182 | |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3183 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3184 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3185 | unsigned Fd = MI.getOperand(0).getReg(); |
| 3186 | unsigned Ws = MI.getOperand(1).getReg(); |
| 3187 | unsigned Lane = MI.getOperand(2).getImm() * 2; |
| 3188 | DebugLoc DL = MI.getDebugLoc(); |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3189 | |
| 3190 | if (Lane == 0) |
| 3191 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Ws, 0, Mips::sub_64); |
| 3192 | else { |
| 3193 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 3194 | |
| 3195 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_D), Wt).addReg(Ws).addImm(1); |
| 3196 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Fd).addReg(Wt, 0, Mips::sub_64); |
| 3197 | } |
| 3198 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3199 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | 39bb8ba | 2013-09-27 12:17:32 +0000 | [diff] [blame] | 3200 | return BB; |
| 3201 | } |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3202 | |
| 3203 | // Emit the INSERT_FW pseudo instruction. |
| 3204 | // |
| 3205 | // insert_fw_pseudo $wd, $wd_in, $n, $fs |
| 3206 | // => |
| 3207 | // subreg_to_reg $wt:sub_lo, $fs |
| 3208 | // insve_w $wd[$n], $wd_in, $wt[0] |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3209 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3210 | MipsSETargetLowering::emitINSERT_FW(MachineInstr &MI, |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3211 | MachineBasicBlock *BB) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3212 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3213 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3214 | DebugLoc DL = MI.getDebugLoc(); |
| 3215 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3216 | unsigned Wd_in = MI.getOperand(1).getReg(); |
| 3217 | unsigned Lane = MI.getOperand(2).getImm(); |
| 3218 | unsigned Fs = MI.getOperand(3).getReg(); |
Daniel Sanders | afe27c7 | 2015-02-23 17:22:16 +0000 | [diff] [blame] | 3219 | unsigned Wt = RegInfo.createVirtualRegister( |
| 3220 | Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass : |
| 3221 | &Mips::MSA128WEvensRegClass); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3222 | |
| 3223 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3224 | .addImm(0) |
| 3225 | .addReg(Fs) |
| 3226 | .addImm(Mips::sub_lo); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3227 | BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_W), Wd) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3228 | .addReg(Wd_in) |
| 3229 | .addImm(Lane) |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 3230 | .addReg(Wt) |
| 3231 | .addImm(0); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3232 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3233 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3234 | return BB; |
| 3235 | } |
| 3236 | |
| 3237 | // Emit the INSERT_FD pseudo instruction. |
| 3238 | // |
| 3239 | // insert_fd_pseudo $wd, $fs, n |
| 3240 | // => |
| 3241 | // subreg_to_reg $wt:sub_64, $fs |
| 3242 | // insve_d $wd[$n], $wd_in, $wt[0] |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3243 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3244 | MipsSETargetLowering::emitINSERT_FD(MachineInstr &MI, |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3245 | MachineBasicBlock *BB) const { |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 3246 | assert(Subtarget.isFP64bit()); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3247 | |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3248 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3249 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3250 | DebugLoc DL = MI.getDebugLoc(); |
| 3251 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3252 | unsigned Wd_in = MI.getOperand(1).getReg(); |
| 3253 | unsigned Lane = MI.getOperand(2).getImm(); |
| 3254 | unsigned Fs = MI.getOperand(3).getReg(); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3255 | unsigned Wt = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 3256 | |
| 3257 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3258 | .addImm(0) |
| 3259 | .addReg(Fs) |
| 3260 | .addImm(Mips::sub_64); |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3261 | BuildMI(*BB, MI, DL, TII->get(Mips::INSVE_D), Wd) |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3262 | .addReg(Wd_in) |
| 3263 | .addImm(Lane) |
Daniel Sanders | b50ccf8 | 2014-04-01 10:35:28 +0000 | [diff] [blame] | 3264 | .addReg(Wt) |
| 3265 | .addImm(0); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3266 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3267 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3268 | return BB; |
| 3269 | } |
| 3270 | |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3271 | // Emit the INSERT_([BHWD]|F[WD])_VIDX pseudo instruction. |
| 3272 | // |
| 3273 | // For integer: |
| 3274 | // (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $rs) |
| 3275 | // => |
| 3276 | // (SLL $lanetmp1, $lane, <log2size) |
| 3277 | // (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1) |
| 3278 | // (INSERT_[BHWD], $wdtmp2, $wdtmp1, 0, $rs) |
| 3279 | // (NEG $lanetmp2, $lanetmp1) |
| 3280 | // (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2) |
| 3281 | // |
| 3282 | // For floating point: |
| 3283 | // (INSERT_([BHWD]|F[WD])_PSEUDO $wd, $wd_in, $n, $fs) |
| 3284 | // => |
| 3285 | // (SUBREG_TO_REG $wt, $fs, <subreg>) |
| 3286 | // (SLL $lanetmp1, $lane, <log2size) |
| 3287 | // (SLD_B $wdtmp1, $wd_in, $wd_in, $lanetmp1) |
| 3288 | // (INSVE_[WD], $wdtmp2, 0, $wdtmp1, 0) |
| 3289 | // (NEG $lanetmp2, $lanetmp1) |
| 3290 | // (SLD_B $wd, $wdtmp2, $wdtmp2, $lanetmp2) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3291 | MachineBasicBlock *MipsSETargetLowering::emitINSERT_DF_VIDX( |
| 3292 | MachineInstr &MI, MachineBasicBlock *BB, unsigned EltSizeInBytes, |
| 3293 | bool IsFP) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3294 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3295 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3296 | DebugLoc DL = MI.getDebugLoc(); |
| 3297 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3298 | unsigned SrcVecReg = MI.getOperand(1).getReg(); |
| 3299 | unsigned LaneReg = MI.getOperand(2).getReg(); |
| 3300 | unsigned SrcValReg = MI.getOperand(3).getReg(); |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3301 | |
| 3302 | const TargetRegisterClass *VecRC = nullptr; |
Daniel Sanders | d3bb208 | 2016-06-15 08:43:23 +0000 | [diff] [blame] | 3303 | // FIXME: This should be true for N32 too. |
Eric Christopher | bf33a3c | 2014-07-02 23:18:40 +0000 | [diff] [blame] | 3304 | const TargetRegisterClass *GPRRC = |
Daniel Sanders | 4160c80 | 2015-05-05 08:48:35 +0000 | [diff] [blame] | 3305 | Subtarget.isABI_N64() ? &Mips::GPR64RegClass : &Mips::GPR32RegClass; |
Daniel Sanders | d3bb208 | 2016-06-15 08:43:23 +0000 | [diff] [blame] | 3306 | unsigned SubRegIdx = Subtarget.isABI_N64() ? Mips::sub_32 : 0; |
| 3307 | unsigned ShiftOp = Subtarget.isABI_N64() ? Mips::DSLL : Mips::SLL; |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3308 | unsigned EltLog2Size; |
| 3309 | unsigned InsertOp = 0; |
| 3310 | unsigned InsveOp = 0; |
| 3311 | switch (EltSizeInBytes) { |
| 3312 | default: |
| 3313 | llvm_unreachable("Unexpected size"); |
| 3314 | case 1: |
| 3315 | EltLog2Size = 0; |
| 3316 | InsertOp = Mips::INSERT_B; |
| 3317 | InsveOp = Mips::INSVE_B; |
| 3318 | VecRC = &Mips::MSA128BRegClass; |
| 3319 | break; |
| 3320 | case 2: |
| 3321 | EltLog2Size = 1; |
| 3322 | InsertOp = Mips::INSERT_H; |
| 3323 | InsveOp = Mips::INSVE_H; |
| 3324 | VecRC = &Mips::MSA128HRegClass; |
| 3325 | break; |
| 3326 | case 4: |
| 3327 | EltLog2Size = 2; |
| 3328 | InsertOp = Mips::INSERT_W; |
| 3329 | InsveOp = Mips::INSVE_W; |
| 3330 | VecRC = &Mips::MSA128WRegClass; |
| 3331 | break; |
| 3332 | case 8: |
| 3333 | EltLog2Size = 3; |
| 3334 | InsertOp = Mips::INSERT_D; |
| 3335 | InsveOp = Mips::INSVE_D; |
| 3336 | VecRC = &Mips::MSA128DRegClass; |
| 3337 | break; |
| 3338 | } |
| 3339 | |
| 3340 | if (IsFP) { |
| 3341 | unsigned Wt = RegInfo.createVirtualRegister(VecRC); |
| 3342 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Wt) |
| 3343 | .addImm(0) |
| 3344 | .addReg(SrcValReg) |
| 3345 | .addImm(EltSizeInBytes == 8 ? Mips::sub_64 : Mips::sub_lo); |
| 3346 | SrcValReg = Wt; |
| 3347 | } |
| 3348 | |
| 3349 | // Convert the lane index into a byte index |
| 3350 | if (EltSizeInBytes != 1) { |
| 3351 | unsigned LaneTmp1 = RegInfo.createVirtualRegister(GPRRC); |
Daniel Sanders | d3bb208 | 2016-06-15 08:43:23 +0000 | [diff] [blame] | 3352 | BuildMI(*BB, MI, DL, TII->get(ShiftOp), LaneTmp1) |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3353 | .addReg(LaneReg) |
| 3354 | .addImm(EltLog2Size); |
| 3355 | LaneReg = LaneTmp1; |
| 3356 | } |
| 3357 | |
| 3358 | // Rotate bytes around so that the desired lane is element zero |
| 3359 | unsigned WdTmp1 = RegInfo.createVirtualRegister(VecRC); |
| 3360 | BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), WdTmp1) |
| 3361 | .addReg(SrcVecReg) |
| 3362 | .addReg(SrcVecReg) |
Daniel Sanders | d3bb208 | 2016-06-15 08:43:23 +0000 | [diff] [blame] | 3363 | .addReg(LaneReg, 0, SubRegIdx); |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3364 | |
| 3365 | unsigned WdTmp2 = RegInfo.createVirtualRegister(VecRC); |
| 3366 | if (IsFP) { |
| 3367 | // Use insve.df to insert to element zero |
| 3368 | BuildMI(*BB, MI, DL, TII->get(InsveOp), WdTmp2) |
| 3369 | .addReg(WdTmp1) |
| 3370 | .addImm(0) |
| 3371 | .addReg(SrcValReg) |
| 3372 | .addImm(0); |
| 3373 | } else { |
| 3374 | // Use insert.df to insert to element zero |
| 3375 | BuildMI(*BB, MI, DL, TII->get(InsertOp), WdTmp2) |
| 3376 | .addReg(WdTmp1) |
| 3377 | .addReg(SrcValReg) |
| 3378 | .addImm(0); |
| 3379 | } |
| 3380 | |
| 3381 | // Rotate elements the rest of the way for a full rotation. |
| 3382 | // sld.df inteprets $rt modulo the number of columns so we only need to negate |
| 3383 | // the lane index to do this. |
| 3384 | unsigned LaneTmp2 = RegInfo.createVirtualRegister(GPRRC); |
Daniel Sanders | 4160c80 | 2015-05-05 08:48:35 +0000 | [diff] [blame] | 3385 | BuildMI(*BB, MI, DL, TII->get(Subtarget.isABI_N64() ? Mips::DSUB : Mips::SUB), |
| 3386 | LaneTmp2) |
| 3387 | .addReg(Subtarget.isABI_N64() ? Mips::ZERO_64 : Mips::ZERO) |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3388 | .addReg(LaneReg); |
| 3389 | BuildMI(*BB, MI, DL, TII->get(Mips::SLD_B), Wd) |
| 3390 | .addReg(WdTmp2) |
| 3391 | .addReg(WdTmp2) |
Daniel Sanders | d3bb208 | 2016-06-15 08:43:23 +0000 | [diff] [blame] | 3392 | .addReg(LaneTmp2, 0, SubRegIdx); |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3393 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3394 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | e296a0f | 2014-04-30 12:09:32 +0000 | [diff] [blame] | 3395 | return BB; |
| 3396 | } |
| 3397 | |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3398 | // Emit the FILL_FW pseudo instruction. |
| 3399 | // |
| 3400 | // fill_fw_pseudo $wd, $fs |
| 3401 | // => |
| 3402 | // implicit_def $wt1 |
| 3403 | // insert_subreg $wt2:subreg_lo, $wt1, $fs |
| 3404 | // splati.w $wd, $wt2[0] |
| 3405 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3406 | MipsSETargetLowering::emitFILL_FW(MachineInstr &MI, |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3407 | MachineBasicBlock *BB) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3408 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3409 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3410 | DebugLoc DL = MI.getDebugLoc(); |
| 3411 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3412 | unsigned Fs = MI.getOperand(1).getReg(); |
Simon Dardis | 0e9e237 | 2017-01-10 15:53:10 +0000 | [diff] [blame] | 3413 | unsigned Wt1 = RegInfo.createVirtualRegister( |
| 3414 | Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass |
| 3415 | : &Mips::MSA128WEvensRegClass); |
| 3416 | unsigned Wt2 = RegInfo.createVirtualRegister( |
| 3417 | Subtarget.useOddSPReg() ? &Mips::MSA128WRegClass |
| 3418 | : &Mips::MSA128WEvensRegClass); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3419 | |
| 3420 | BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1); |
| 3421 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2) |
| 3422 | .addReg(Wt1) |
| 3423 | .addReg(Fs) |
| 3424 | .addImm(Mips::sub_lo); |
| 3425 | BuildMI(*BB, MI, DL, TII->get(Mips::SPLATI_W), Wd).addReg(Wt2).addImm(0); |
| 3426 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3427 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3428 | return BB; |
| 3429 | } |
| 3430 | |
| 3431 | // Emit the FILL_FD pseudo instruction. |
| 3432 | // |
| 3433 | // fill_fd_pseudo $wd, $fs |
| 3434 | // => |
| 3435 | // implicit_def $wt1 |
| 3436 | // insert_subreg $wt2:subreg_64, $wt1, $fs |
| 3437 | // splati.d $wd, $wt2[0] |
| 3438 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3439 | MipsSETargetLowering::emitFILL_FD(MachineInstr &MI, |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3440 | MachineBasicBlock *BB) const { |
Eric Christopher | 1c29a65 | 2014-07-18 22:55:25 +0000 | [diff] [blame] | 3441 | assert(Subtarget.isFP64bit()); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3442 | |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3443 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3444 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3445 | DebugLoc DL = MI.getDebugLoc(); |
| 3446 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3447 | unsigned Fs = MI.getOperand(1).getReg(); |
Daniel Sanders | 1dfddc7 | 2013-10-15 13:14:41 +0000 | [diff] [blame] | 3448 | unsigned Wt1 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 3449 | unsigned Wt2 = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 3450 | |
| 3451 | BuildMI(*BB, MI, DL, TII->get(Mips::IMPLICIT_DEF), Wt1); |
| 3452 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_SUBREG), Wt2) |
| 3453 | .addReg(Wt1) |
| 3454 | .addReg(Fs) |
| 3455 | .addImm(Mips::sub_64); |
| 3456 | 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] | 3457 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3458 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | a515070 | 2013-09-27 12:31:32 +0000 | [diff] [blame] | 3459 | return BB; |
| 3460 | } |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3461 | |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3462 | // Emit the ST_F16_PSEDUO instruction to store a f16 value from an MSA |
| 3463 | // register. |
| 3464 | // |
| 3465 | // STF16 MSA128F16:$wd, mem_simm10:$addr |
| 3466 | // => |
| 3467 | // copy_u.h $rtemp,$wd[0] |
| 3468 | // sh $rtemp, $addr |
| 3469 | // |
| 3470 | // Safety: We can't use st.h & co as they would over write the memory after |
| 3471 | // the destination. It would require half floats be allocated 16 bytes(!) of |
| 3472 | // space. |
| 3473 | MachineBasicBlock * |
| 3474 | MipsSETargetLowering::emitST_F16_PSEUDO(MachineInstr &MI, |
| 3475 | MachineBasicBlock *BB) const { |
| 3476 | |
| 3477 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
| 3478 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3479 | DebugLoc DL = MI.getDebugLoc(); |
| 3480 | unsigned Ws = MI.getOperand(0).getReg(); |
| 3481 | unsigned Rt = MI.getOperand(1).getReg(); |
| 3482 | const MachineMemOperand &MMO = **MI.memoperands_begin(); |
| 3483 | unsigned Imm = MMO.getOffset(); |
| 3484 | |
| 3485 | // Caution: A load via the GOT can expand to a GPR32 operand, a load via |
| 3486 | // spill and reload can expand as a GPR64 operand. Examine the |
| 3487 | // operand in detail and default to ABI. |
| 3488 | const TargetRegisterClass *RC = |
| 3489 | MI.getOperand(1).isReg() ? RegInfo.getRegClass(MI.getOperand(1).getReg()) |
| 3490 | : (Subtarget.isABI_O32() ? &Mips::GPR32RegClass |
| 3491 | : &Mips::GPR64RegClass); |
| 3492 | const bool UsingMips32 = RC == &Mips::GPR32RegClass; |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3493 | unsigned Rs = RegInfo.createVirtualRegister(&Mips::GPR32RegClass); |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3494 | |
| 3495 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY_U_H), Rs).addReg(Ws).addImm(0); |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3496 | if(!UsingMips32) { |
| 3497 | unsigned Tmp = RegInfo.createVirtualRegister(&Mips::GPR64RegClass); |
| 3498 | BuildMI(*BB, MI, DL, TII->get(Mips::SUBREG_TO_REG), Tmp) |
| 3499 | .addImm(0) |
| 3500 | .addReg(Rs) |
| 3501 | .addImm(Mips::sub_32); |
| 3502 | Rs = Tmp; |
| 3503 | } |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3504 | BuildMI(*BB, MI, DL, TII->get(UsingMips32 ? Mips::SH : Mips::SH64)) |
| 3505 | .addReg(Rs) |
| 3506 | .addReg(Rt) |
| 3507 | .addImm(Imm) |
| 3508 | .addMemOperand(BB->getParent()->getMachineMemOperand( |
| 3509 | &MMO, MMO.getOffset(), MMO.getSize())); |
| 3510 | |
| 3511 | MI.eraseFromParent(); |
| 3512 | return BB; |
| 3513 | } |
| 3514 | |
| 3515 | // Emit the LD_F16_PSEDUO instruction to load a f16 value into an MSA register. |
| 3516 | // |
| 3517 | // LD_F16 MSA128F16:$wd, mem_simm10:$addr |
| 3518 | // => |
| 3519 | // lh $rtemp, $addr |
| 3520 | // fill.h $wd, $rtemp |
| 3521 | // |
| 3522 | // Safety: We can't use ld.h & co as they over-read from the source. |
| 3523 | // Additionally, if the address is not modulo 16, 2 cases can occur: |
| 3524 | // a) Segmentation fault as the load instruction reads from a memory page |
| 3525 | // memory it's not supposed to. |
| 3526 | // b) The load crosses an implementation specific boundary, requiring OS |
| 3527 | // intervention. |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3528 | MachineBasicBlock * |
| 3529 | MipsSETargetLowering::emitLD_F16_PSEUDO(MachineInstr &MI, |
| 3530 | MachineBasicBlock *BB) const { |
| 3531 | |
| 3532 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
| 3533 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3534 | DebugLoc DL = MI.getDebugLoc(); |
| 3535 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3536 | |
| 3537 | // Caution: A load via the GOT can expand to a GPR32 operand, a load via |
| 3538 | // spill and reload can expand as a GPR64 operand. Examine the |
| 3539 | // operand in detail and default to ABI. |
| 3540 | const TargetRegisterClass *RC = |
| 3541 | MI.getOperand(1).isReg() ? RegInfo.getRegClass(MI.getOperand(1).getReg()) |
| 3542 | : (Subtarget.isABI_O32() ? &Mips::GPR32RegClass |
| 3543 | : &Mips::GPR64RegClass); |
| 3544 | |
| 3545 | const bool UsingMips32 = RC == &Mips::GPR32RegClass; |
| 3546 | unsigned Rt = RegInfo.createVirtualRegister(RC); |
| 3547 | |
| 3548 | MachineInstrBuilder MIB = |
| 3549 | BuildMI(*BB, MI, DL, TII->get(UsingMips32 ? Mips::LH : Mips::LH64), Rt); |
| 3550 | for (unsigned i = 1; i < MI.getNumOperands(); i++) |
Diana Picus | 116bbab | 2017-01-13 09:58:52 +0000 | [diff] [blame] | 3551 | MIB.add(MI.getOperand(i)); |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3552 | |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3553 | if(!UsingMips32) { |
| 3554 | unsigned Tmp = RegInfo.createVirtualRegister(&Mips::GPR32RegClass); |
| 3555 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY), Tmp).addReg(Rt, 0, Mips::sub_32); |
| 3556 | Rt = Tmp; |
| 3557 | } |
| 3558 | |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3559 | BuildMI(*BB, MI, DL, TII->get(Mips::FILL_H), Wd).addReg(Rt); |
| 3560 | |
| 3561 | MI.eraseFromParent(); |
| 3562 | return BB; |
| 3563 | } |
| 3564 | |
| 3565 | // Emit the FPROUND_PSEUDO instruction. |
| 3566 | // |
| 3567 | // Round an FGR64Opnd, FGR32Opnd to an f16. |
| 3568 | // |
| 3569 | // Safety: Cycle the operand through the GPRs so the result always ends up |
| 3570 | // the correct MSA register. |
| 3571 | // |
| 3572 | // FIXME: This copying is strictly unnecessary. If we could tie FGR32Opnd:$Fs |
| 3573 | // / FGR64Opnd:$Fs and MSA128F16:$Wd to the same physical register |
| 3574 | // (which they can be, as the MSA registers are defined to alias the |
| 3575 | // FPU's 64 bit and 32 bit registers) the result can be accessed using |
| 3576 | // the correct register class. That requires operands be tie-able across |
| 3577 | // register classes which have a sub/super register class relationship. |
| 3578 | // |
| 3579 | // For FPG32Opnd: |
| 3580 | // |
| 3581 | // FPROUND MSA128F16:$wd, FGR32Opnd:$fs |
| 3582 | // => |
| 3583 | // mfc1 $rtemp, $fs |
| 3584 | // fill.w $rtemp, $wtemp |
| 3585 | // fexdo.w $wd, $wtemp, $wtemp |
| 3586 | // |
| 3587 | // For FPG64Opnd on mips32r2+: |
| 3588 | // |
| 3589 | // FPROUND MSA128F16:$wd, FGR64Opnd:$fs |
| 3590 | // => |
| 3591 | // mfc1 $rtemp, $fs |
| 3592 | // fill.w $rtemp, $wtemp |
| 3593 | // mfhc1 $rtemp2, $fs |
| 3594 | // insert.w $wtemp[1], $rtemp2 |
| 3595 | // insert.w $wtemp[3], $rtemp2 |
| 3596 | // fexdo.w $wtemp2, $wtemp, $wtemp |
| 3597 | // fexdo.h $wd, $temp2, $temp2 |
| 3598 | // |
| 3599 | // For FGR64Opnd on mips64r2+: |
| 3600 | // |
| 3601 | // FPROUND MSA128F16:$wd, FGR64Opnd:$fs |
| 3602 | // => |
| 3603 | // dmfc1 $rtemp, $fs |
| 3604 | // fill.d $rtemp, $wtemp |
| 3605 | // fexdo.w $wtemp2, $wtemp, $wtemp |
| 3606 | // fexdo.h $wd, $wtemp2, $wtemp2 |
| 3607 | // |
| 3608 | // Safety note: As $wtemp is UNDEF, we may provoke a spurious exception if the |
| 3609 | // undef bits are "just right" and the exception enable bits are |
| 3610 | // set. By using fill.w to replicate $fs into all elements over |
| 3611 | // insert.w for one element, we avoid that potiential case. If |
| 3612 | // fexdo.[hw] causes an exception in, the exception is valid and it |
| 3613 | // occurs for all elements. |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3614 | MachineBasicBlock * |
| 3615 | MipsSETargetLowering::emitFPROUND_PSEUDO(MachineInstr &MI, |
| 3616 | MachineBasicBlock *BB, |
| 3617 | bool IsFGR64) const { |
| 3618 | |
| 3619 | // Strictly speaking, we need MIPS32R5 to support MSA. We'll be generous |
| 3620 | // here. It's technically doable to support MIPS32 here, but the ISA forbids |
| 3621 | // it. |
| 3622 | assert(Subtarget.hasMSA() && Subtarget.hasMips32r2()); |
| 3623 | |
| 3624 | bool IsFGR64onMips64 = Subtarget.hasMips64() && IsFGR64; |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3625 | bool IsFGR64onMips32 = !Subtarget.hasMips64() && IsFGR64; |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3626 | |
| 3627 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
| 3628 | DebugLoc DL = MI.getDebugLoc(); |
| 3629 | unsigned Wd = MI.getOperand(0).getReg(); |
| 3630 | unsigned Fs = MI.getOperand(1).getReg(); |
| 3631 | |
| 3632 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3633 | unsigned Wtemp = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 3634 | const TargetRegisterClass *GPRRC = |
| 3635 | IsFGR64onMips64 ? &Mips::GPR64RegClass : &Mips::GPR32RegClass; |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3636 | unsigned MFC1Opc = IsFGR64onMips64 |
| 3637 | ? Mips::DMFC1 |
| 3638 | : (IsFGR64onMips32 ? Mips::MFC1_D64 : Mips::MFC1); |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3639 | unsigned FILLOpc = IsFGR64onMips64 ? Mips::FILL_D : Mips::FILL_W; |
| 3640 | |
| 3641 | // Perform the register class copy as mentioned above. |
| 3642 | unsigned Rtemp = RegInfo.createVirtualRegister(GPRRC); |
| 3643 | BuildMI(*BB, MI, DL, TII->get(MFC1Opc), Rtemp).addReg(Fs); |
| 3644 | BuildMI(*BB, MI, DL, TII->get(FILLOpc), Wtemp).addReg(Rtemp); |
| 3645 | unsigned WPHI = Wtemp; |
| 3646 | |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3647 | if (IsFGR64onMips32) { |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3648 | unsigned Rtemp2 = RegInfo.createVirtualRegister(GPRRC); |
| 3649 | BuildMI(*BB, MI, DL, TII->get(Mips::MFHC1_D64), Rtemp2).addReg(Fs); |
| 3650 | unsigned Wtemp2 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 3651 | unsigned Wtemp3 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 3652 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_W), Wtemp2) |
| 3653 | .addReg(Wtemp) |
| 3654 | .addReg(Rtemp2) |
| 3655 | .addImm(1); |
| 3656 | BuildMI(*BB, MI, DL, TII->get(Mips::INSERT_W), Wtemp3) |
| 3657 | .addReg(Wtemp2) |
| 3658 | .addReg(Rtemp2) |
| 3659 | .addImm(3); |
| 3660 | WPHI = Wtemp3; |
| 3661 | } |
| 3662 | |
| 3663 | if (IsFGR64) { |
| 3664 | unsigned Wtemp2 = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 3665 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXDO_W), Wtemp2) |
| 3666 | .addReg(WPHI) |
| 3667 | .addReg(WPHI); |
| 3668 | WPHI = Wtemp2; |
| 3669 | } |
| 3670 | |
| 3671 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXDO_H), Wd).addReg(WPHI).addReg(WPHI); |
| 3672 | |
| 3673 | MI.eraseFromParent(); |
| 3674 | return BB; |
| 3675 | } |
| 3676 | |
| 3677 | // Emit the FPEXTEND_PSEUDO instruction. |
| 3678 | // |
| 3679 | // Expand an f16 to either a FGR32Opnd or FGR64Opnd. |
| 3680 | // |
| 3681 | // Safety: Cycle the result through the GPRs so the result always ends up |
| 3682 | // the correct floating point register. |
| 3683 | // |
| 3684 | // FIXME: This copying is strictly unnecessary. If we could tie FGR32Opnd:$Fd |
| 3685 | // / FGR64Opnd:$Fd and MSA128F16:$Ws to the same physical register |
| 3686 | // (which they can be, as the MSA registers are defined to alias the |
| 3687 | // FPU's 64 bit and 32 bit registers) the result can be accessed using |
| 3688 | // the correct register class. That requires operands be tie-able across |
| 3689 | // register classes which have a sub/super register class relationship. I |
| 3690 | // haven't checked. |
| 3691 | // |
| 3692 | // For FGR32Opnd: |
| 3693 | // |
| 3694 | // FPEXTEND FGR32Opnd:$fd, MSA128F16:$ws |
| 3695 | // => |
| 3696 | // fexupr.w $wtemp, $ws |
| 3697 | // copy_s.w $rtemp, $ws[0] |
| 3698 | // mtc1 $rtemp, $fd |
| 3699 | // |
| 3700 | // For FGR64Opnd on Mips64: |
| 3701 | // |
| 3702 | // FPEXTEND FGR64Opnd:$fd, MSA128F16:$ws |
| 3703 | // => |
| 3704 | // fexupr.w $wtemp, $ws |
| 3705 | // fexupr.d $wtemp2, $wtemp |
| 3706 | // copy_s.d $rtemp, $wtemp2s[0] |
| 3707 | // dmtc1 $rtemp, $fd |
| 3708 | // |
| 3709 | // For FGR64Opnd on Mips32: |
| 3710 | // |
| 3711 | // FPEXTEND FGR64Opnd:$fd, MSA128F16:$ws |
| 3712 | // => |
| 3713 | // fexupr.w $wtemp, $ws |
| 3714 | // fexupr.d $wtemp2, $wtemp |
| 3715 | // copy_s.w $rtemp, $wtemp2[0] |
| 3716 | // mtc1 $rtemp, $ftemp |
| 3717 | // copy_s.w $rtemp2, $wtemp2[1] |
| 3718 | // $fd = mthc1 $rtemp2, $ftemp |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3719 | MachineBasicBlock * |
| 3720 | MipsSETargetLowering::emitFPEXTEND_PSEUDO(MachineInstr &MI, |
| 3721 | MachineBasicBlock *BB, |
| 3722 | bool IsFGR64) const { |
| 3723 | |
| 3724 | // Strictly speaking, we need MIPS32R5 to support MSA. We'll be generous |
| 3725 | // here. It's technically doable to support MIPS32 here, but the ISA forbids |
| 3726 | // it. |
| 3727 | assert(Subtarget.hasMSA() && Subtarget.hasMips32r2()); |
| 3728 | |
| 3729 | bool IsFGR64onMips64 = Subtarget.hasMips64() && IsFGR64; |
| 3730 | bool IsFGR64onMips32 = !Subtarget.hasMips64() && IsFGR64; |
| 3731 | |
| 3732 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
| 3733 | DebugLoc DL = MI.getDebugLoc(); |
| 3734 | unsigned Fd = MI.getOperand(0).getReg(); |
| 3735 | unsigned Ws = MI.getOperand(1).getReg(); |
| 3736 | |
| 3737 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3738 | const TargetRegisterClass *GPRRC = |
| 3739 | IsFGR64onMips64 ? &Mips::GPR64RegClass : &Mips::GPR32RegClass; |
Stefan Maksimovic | 58f225b | 2017-07-18 12:05:35 +0000 | [diff] [blame] | 3740 | unsigned MTC1Opc = IsFGR64onMips64 |
| 3741 | ? Mips::DMTC1 |
| 3742 | : (IsFGR64onMips32 ? Mips::MTC1_D64 : Mips::MTC1); |
Simon Dardis | 0e2ee3b | 2016-11-18 16:17:44 +0000 | [diff] [blame] | 3743 | unsigned COPYOpc = IsFGR64onMips64 ? Mips::COPY_S_D : Mips::COPY_S_W; |
| 3744 | |
| 3745 | unsigned Wtemp = RegInfo.createVirtualRegister(&Mips::MSA128WRegClass); |
| 3746 | unsigned WPHI = Wtemp; |
| 3747 | |
| 3748 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXUPR_W), Wtemp).addReg(Ws); |
| 3749 | if (IsFGR64) { |
| 3750 | WPHI = RegInfo.createVirtualRegister(&Mips::MSA128DRegClass); |
| 3751 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXUPR_D), WPHI).addReg(Wtemp); |
| 3752 | } |
| 3753 | |
| 3754 | // Perform the safety regclass copy mentioned above. |
| 3755 | unsigned Rtemp = RegInfo.createVirtualRegister(GPRRC); |
| 3756 | unsigned FPRPHI = IsFGR64onMips32 |
| 3757 | ? RegInfo.createVirtualRegister(&Mips::FGR64RegClass) |
| 3758 | : Fd; |
| 3759 | BuildMI(*BB, MI, DL, TII->get(COPYOpc), Rtemp).addReg(WPHI).addImm(0); |
| 3760 | BuildMI(*BB, MI, DL, TII->get(MTC1Opc), FPRPHI).addReg(Rtemp); |
| 3761 | |
| 3762 | if (IsFGR64onMips32) { |
| 3763 | unsigned Rtemp2 = RegInfo.createVirtualRegister(GPRRC); |
| 3764 | BuildMI(*BB, MI, DL, TII->get(Mips::COPY_S_W), Rtemp2) |
| 3765 | .addReg(WPHI) |
| 3766 | .addImm(1); |
| 3767 | BuildMI(*BB, MI, DL, TII->get(Mips::MTHC1_D64), Fd) |
| 3768 | .addReg(FPRPHI) |
| 3769 | .addReg(Rtemp2); |
| 3770 | } |
| 3771 | |
| 3772 | MI.eraseFromParent(); |
| 3773 | return BB; |
| 3774 | } |
| 3775 | |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3776 | // Emit the FEXP2_W_1 pseudo instructions. |
| 3777 | // |
| 3778 | // fexp2_w_1_pseudo $wd, $wt |
| 3779 | // => |
| 3780 | // ldi.w $ws, 1 |
| 3781 | // fexp2.w $wd, $ws, $wt |
| 3782 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3783 | MipsSETargetLowering::emitFEXP2_W_1(MachineInstr &MI, |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3784 | MachineBasicBlock *BB) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3785 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3786 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3787 | const TargetRegisterClass *RC = &Mips::MSA128WRegClass; |
| 3788 | unsigned Ws1 = RegInfo.createVirtualRegister(RC); |
| 3789 | unsigned Ws2 = RegInfo.createVirtualRegister(RC); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3790 | DebugLoc DL = MI.getDebugLoc(); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3791 | |
| 3792 | // Splat 1.0 into a vector |
| 3793 | BuildMI(*BB, MI, DL, TII->get(Mips::LDI_W), Ws1).addImm(1); |
| 3794 | BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_W), Ws2).addReg(Ws1); |
| 3795 | |
| 3796 | // Emit 1.0 * fexp2(Wt) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3797 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_W), MI.getOperand(0).getReg()) |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3798 | .addReg(Ws2) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3799 | .addReg(MI.getOperand(1).getReg()); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3800 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3801 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3802 | return BB; |
| 3803 | } |
| 3804 | |
| 3805 | // Emit the FEXP2_D_1 pseudo instructions. |
| 3806 | // |
| 3807 | // fexp2_d_1_pseudo $wd, $wt |
| 3808 | // => |
| 3809 | // ldi.d $ws, 1 |
| 3810 | // fexp2.d $wd, $ws, $wt |
| 3811 | MachineBasicBlock * |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3812 | MipsSETargetLowering::emitFEXP2_D_1(MachineInstr &MI, |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3813 | MachineBasicBlock *BB) const { |
Eric Christopher | 96e72c6 | 2015-01-29 23:27:36 +0000 | [diff] [blame] | 3814 | const TargetInstrInfo *TII = Subtarget.getInstrInfo(); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3815 | MachineRegisterInfo &RegInfo = BB->getParent()->getRegInfo(); |
| 3816 | const TargetRegisterClass *RC = &Mips::MSA128DRegClass; |
| 3817 | unsigned Ws1 = RegInfo.createVirtualRegister(RC); |
| 3818 | unsigned Ws2 = RegInfo.createVirtualRegister(RC); |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3819 | DebugLoc DL = MI.getDebugLoc(); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3820 | |
| 3821 | // Splat 1.0 into a vector |
| 3822 | BuildMI(*BB, MI, DL, TII->get(Mips::LDI_D), Ws1).addImm(1); |
| 3823 | BuildMI(*BB, MI, DL, TII->get(Mips::FFINT_U_D), Ws2).addReg(Ws1); |
| 3824 | |
| 3825 | // Emit 1.0 * fexp2(Wt) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3826 | BuildMI(*BB, MI, DL, TII->get(Mips::FEXP2_D), MI.getOperand(0).getReg()) |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3827 | .addReg(Ws2) |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3828 | .addReg(MI.getOperand(1).getReg()); |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3829 | |
Duncan P. N. Exon Smith | e4f5e4f | 2016-06-30 22:52:52 +0000 | [diff] [blame] | 3830 | MI.eraseFromParent(); // The pseudo instruction is gone now. |
Daniel Sanders | a952160 | 2013-10-23 10:36:52 +0000 | [diff] [blame] | 3831 | return BB; |
| 3832 | } |