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