| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1 | //===-- ARMISelLowering.cpp - ARM DAG Lowering Implementation -------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines the interfaces that ARM uses to lower LLVM code into a |
| 11 | // selection DAG. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| Craig Topper | 188ed9d | 2012-03-17 07:33:42 +0000 | [diff] [blame] | 15 | #include "ARMISelLowering.h" |
| Eric Christopher | 1c06917 | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 16 | #include "ARMCallingConv.h" |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 17 | #include "ARMConstantPoolValue.h" |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMMachineFunctionInfo.h" |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 19 | #include "ARMPerfectShuffle.h" |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 20 | #include "ARMSubtarget.h" |
| 21 | #include "ARMTargetMachine.h" |
| Chris Lattner | 4e7dfaf | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 22 | #include "ARMTargetObjectFile.h" |
| Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 23 | #include "MCTargetDesc/ARMAddressingModes.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/Statistic.h" |
| 25 | #include "llvm/ADT/StringExtras.h" |
| Pete Cooper | ef21bd4 | 2015-03-04 01:24:11 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringSwitch.h" |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/CallingConvLower.h" |
| Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/IntrinsicLowering.h" |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 30 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 31 | #include "llvm/CodeGen/MachineFunction.h" |
| 32 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
| Eric Christopher | 79cc1e3 | 2014-09-02 22:28:02 +0000 | [diff] [blame] | 33 | #include "llvm/CodeGen/MachineJumpTableInfo.h" |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 34 | #include "llvm/CodeGen/MachineModuleInfo.h" |
| Chris Lattner | a10fff5 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/SelectionDAG.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 37 | #include "llvm/IR/CallingConv.h" |
| 38 | #include "llvm/IR/Constants.h" |
| 39 | #include "llvm/IR/Function.h" |
| 40 | #include "llvm/IR/GlobalValue.h" |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 41 | #include "llvm/IR/IRBuilder.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 42 | #include "llvm/IR/Instruction.h" |
| 43 | #include "llvm/IR/Instructions.h" |
| John Brawn | 0dbcd65 | 2015-03-18 12:01:59 +0000 | [diff] [blame] | 44 | #include "llvm/IR/IntrinsicInst.h" |
| Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 45 | #include "llvm/IR/Intrinsics.h" |
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 46 | #include "llvm/IR/Type.h" |
| Bill Wendling | 46ffefc | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 47 | #include "llvm/MC/MCSectionMachO.h" |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 48 | #include "llvm/Support/CommandLine.h" |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 49 | #include "llvm/Support/Debug.h" |
| Torok Edwin | 6dd2730 | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 50 | #include "llvm/Support/ErrorHandling.h" |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MathExtras.h" |
| Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 52 | #include "llvm/Support/raw_ostream.h" |
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 53 | #include "llvm/Target/TargetOptions.h" |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 54 | #include <utility> |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 55 | using namespace llvm; |
| 56 | |
| Chandler Carruth | 84e68b2 | 2014-04-22 02:41:26 +0000 | [diff] [blame] | 57 | #define DEBUG_TYPE "arm-isel" |
| 58 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 59 | STATISTIC(NumTailCalls, "Number of tail calls"); |
| Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 60 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 61 | STATISTIC(NumLoopByVals, "Number of loops generated for byval arguments"); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 62 | |
| Evan Cheng | f128bdc | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 63 | static cl::opt<bool> |
| 64 | ARMInterworking("arm-interworking", cl::Hidden, |
| 65 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 66 | cl::init(true)); |
| 67 | |
| Benjamin Kramer | 7ba71be | 2011-11-26 23:01:57 +0000 | [diff] [blame] | 68 | namespace { |
| Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 69 | class ARMCCState : public CCState { |
| 70 | public: |
| 71 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 72 | SmallVectorImpl<CCValAssign> &locs, LLVMContext &C, |
| 73 | ParmContext PC) |
| 74 | : CCState(CC, isVarArg, MF, locs, C) { |
| Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 75 | assert(((PC == Call) || (PC == Prologue)) && |
| 76 | "ARMCCState users must specify whether their context is call" |
| 77 | "or prologue generation."); |
| 78 | CallOrPrologue = PC; |
| 79 | } |
| 80 | }; |
| Alexander Kornienko | f00654e | 2015-06-23 09:49:53 +0000 | [diff] [blame] | 81 | } |
| Cameron Zwarich | 8901978 | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 82 | |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 83 | // The APCS parameter registers. |
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 84 | static const MCPhysReg GPRArgRegs[] = { |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 85 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 86 | }; |
| 87 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 88 | void ARMTargetLowering::addTypeForNEON(MVT VT, MVT PromotedLdStVT, |
| 89 | MVT PromotedBitwiseVT) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 90 | if (VT != PromotedLdStVT) { |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 91 | setOperationAction(ISD::LOAD, VT, Promote); |
| 92 | AddPromotedToType (ISD::LOAD, VT, PromotedLdStVT); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 93 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 94 | setOperationAction(ISD::STORE, VT, Promote); |
| 95 | AddPromotedToType (ISD::STORE, VT, PromotedLdStVT); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 98 | MVT ElemTy = VT.getVectorElementType(); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 99 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 100 | setOperationAction(ISD::SETCC, VT, Custom); |
| 101 | setOperationAction(ISD::INSERT_VECTOR_ELT, VT, Custom); |
| 102 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT, Custom); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 103 | if (ElemTy == MVT::i32) { |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 104 | setOperationAction(ISD::SINT_TO_FP, VT, Custom); |
| 105 | setOperationAction(ISD::UINT_TO_FP, VT, Custom); |
| 106 | setOperationAction(ISD::FP_TO_SINT, VT, Custom); |
| 107 | setOperationAction(ISD::FP_TO_UINT, VT, Custom); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 108 | } else { |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::SINT_TO_FP, VT, Expand); |
| 110 | setOperationAction(ISD::UINT_TO_FP, VT, Expand); |
| 111 | setOperationAction(ISD::FP_TO_SINT, VT, Expand); |
| 112 | setOperationAction(ISD::FP_TO_UINT, VT, Expand); |
| Bob Wilson | 5d8cfb2 | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 113 | } |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 114 | setOperationAction(ISD::BUILD_VECTOR, VT, Custom); |
| 115 | setOperationAction(ISD::VECTOR_SHUFFLE, VT, Custom); |
| 116 | setOperationAction(ISD::CONCAT_VECTORS, VT, Legal); |
| 117 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT, Legal); |
| 118 | setOperationAction(ISD::SELECT, VT, Expand); |
| 119 | setOperationAction(ISD::SELECT_CC, VT, Expand); |
| Jim Grosbach | 30af442 | 2012-10-12 22:59:21 +0000 | [diff] [blame] | 120 | setOperationAction(ISD::VSELECT, VT, Expand); |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::SIGN_EXTEND_INREG, VT, Expand); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 122 | if (VT.isInteger()) { |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 123 | setOperationAction(ISD::SHL, VT, Custom); |
| 124 | setOperationAction(ISD::SRA, VT, Custom); |
| 125 | setOperationAction(ISD::SRL, VT, Custom); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | // Promote all bit-wise operations. |
| 129 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 130 | setOperationAction(ISD::AND, VT, Promote); |
| 131 | AddPromotedToType (ISD::AND, VT, PromotedBitwiseVT); |
| 132 | setOperationAction(ISD::OR, VT, Promote); |
| 133 | AddPromotedToType (ISD::OR, VT, PromotedBitwiseVT); |
| 134 | setOperationAction(ISD::XOR, VT, Promote); |
| 135 | AddPromotedToType (ISD::XOR, VT, PromotedBitwiseVT); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 136 | } |
| Bob Wilson | 4ed397c | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 137 | |
| 138 | // Neon does not support vector divide/remainder operations. |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 139 | setOperationAction(ISD::SDIV, VT, Expand); |
| 140 | setOperationAction(ISD::UDIV, VT, Expand); |
| 141 | setOperationAction(ISD::FDIV, VT, Expand); |
| 142 | setOperationAction(ISD::SREM, VT, Expand); |
| 143 | setOperationAction(ISD::UREM, VT, Expand); |
| 144 | setOperationAction(ISD::FREM, VT, Expand); |
| James Molloy | a6702e2 | 2015-07-17 17:10:55 +0000 | [diff] [blame] | 145 | |
| 146 | if (VT.isInteger()) { |
| 147 | setOperationAction(ISD::SABSDIFF, VT, Legal); |
| 148 | setOperationAction(ISD::UABSDIFF, VT, Legal); |
| 149 | } |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 150 | if (!VT.isFloatingPoint() && |
| 151 | VT != MVT::v2i64 && VT != MVT::v1i64) |
| 152 | for (unsigned Opcode : {ISD::SMIN, ISD::SMAX, ISD::UMIN, ISD::UMAX}) |
| 153 | setOperationAction(Opcode, VT, Legal); |
| 154 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 157 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 158 | addRegisterClass(VT, &ARM::DPRRegClass); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 162 | void ARMTargetLowering::addQRTypeForNEON(MVT VT) { |
| Jakob Stoklund Olesen | 2091206 | 2014-01-14 06:18:34 +0000 | [diff] [blame] | 163 | addRegisterClass(VT, &ARM::DPairRegClass); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 164 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 165 | } |
| 166 | |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 167 | ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM, |
| 168 | const ARMSubtarget &STI) |
| 169 | : TargetLowering(TM), Subtarget(&STI) { |
| 170 | RegInfo = Subtarget->getRegisterInfo(); |
| 171 | Itins = Subtarget->getInstrItineraryData(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 172 | |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 173 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 174 | |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 175 | if (Subtarget->isTargetMachO()) { |
| Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 176 | // Uses VFP for Thumb libfuncs if available. |
| Jim Grosbach | 1d1d6d4 | 2013-10-24 23:07:11 +0000 | [diff] [blame] | 177 | if (Subtarget->isThumb() && Subtarget->hasVFP2() && |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 178 | Subtarget->hasARMOps() && !Subtarget->useSoftFloat()) { |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 179 | static const struct { |
| 180 | const RTLIB::Libcall Op; |
| 181 | const char * const Name; |
| 182 | const ISD::CondCode Cond; |
| 183 | } LibraryCalls[] = { |
| 184 | // Single-precision floating-point arithmetic. |
| 185 | { RTLIB::ADD_F32, "__addsf3vfp", ISD::SETCC_INVALID }, |
| 186 | { RTLIB::SUB_F32, "__subsf3vfp", ISD::SETCC_INVALID }, |
| 187 | { RTLIB::MUL_F32, "__mulsf3vfp", ISD::SETCC_INVALID }, |
| 188 | { RTLIB::DIV_F32, "__divsf3vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 189 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 190 | // Double-precision floating-point arithmetic. |
| 191 | { RTLIB::ADD_F64, "__adddf3vfp", ISD::SETCC_INVALID }, |
| 192 | { RTLIB::SUB_F64, "__subdf3vfp", ISD::SETCC_INVALID }, |
| 193 | { RTLIB::MUL_F64, "__muldf3vfp", ISD::SETCC_INVALID }, |
| 194 | { RTLIB::DIV_F64, "__divdf3vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 195 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 196 | // Single-precision comparisons. |
| 197 | { RTLIB::OEQ_F32, "__eqsf2vfp", ISD::SETNE }, |
| 198 | { RTLIB::UNE_F32, "__nesf2vfp", ISD::SETNE }, |
| 199 | { RTLIB::OLT_F32, "__ltsf2vfp", ISD::SETNE }, |
| 200 | { RTLIB::OLE_F32, "__lesf2vfp", ISD::SETNE }, |
| 201 | { RTLIB::OGE_F32, "__gesf2vfp", ISD::SETNE }, |
| 202 | { RTLIB::OGT_F32, "__gtsf2vfp", ISD::SETNE }, |
| 203 | { RTLIB::UO_F32, "__unordsf2vfp", ISD::SETNE }, |
| 204 | { RTLIB::O_F32, "__unordsf2vfp", ISD::SETEQ }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 205 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 206 | // Double-precision comparisons. |
| 207 | { RTLIB::OEQ_F64, "__eqdf2vfp", ISD::SETNE }, |
| 208 | { RTLIB::UNE_F64, "__nedf2vfp", ISD::SETNE }, |
| 209 | { RTLIB::OLT_F64, "__ltdf2vfp", ISD::SETNE }, |
| 210 | { RTLIB::OLE_F64, "__ledf2vfp", ISD::SETNE }, |
| 211 | { RTLIB::OGE_F64, "__gedf2vfp", ISD::SETNE }, |
| 212 | { RTLIB::OGT_F64, "__gtdf2vfp", ISD::SETNE }, |
| 213 | { RTLIB::UO_F64, "__unorddf2vfp", ISD::SETNE }, |
| 214 | { RTLIB::O_F64, "__unorddf2vfp", ISD::SETEQ }, |
| Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 215 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 216 | // Floating-point to integer conversions. |
| 217 | // i64 conversions are done via library routines even when generating VFP |
| 218 | // instructions, so use the same ones. |
| 219 | { RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp", ISD::SETCC_INVALID }, |
| 220 | { RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp", ISD::SETCC_INVALID }, |
| 221 | { RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp", ISD::SETCC_INVALID }, |
| 222 | { RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 223 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 224 | // Conversions between floating types. |
| 225 | { RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp", ISD::SETCC_INVALID }, |
| 226 | { RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 227 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 228 | // Integer to floating-point conversions. |
| 229 | // i64 conversions are done via library routines even when generating VFP |
| 230 | // instructions, so use the same ones. |
| 231 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 232 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
| 233 | { RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp", ISD::SETCC_INVALID }, |
| 234 | { RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp", ISD::SETCC_INVALID }, |
| 235 | { RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp", ISD::SETCC_INVALID }, |
| 236 | { RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp", ISD::SETCC_INVALID }, |
| 237 | }; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 238 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 239 | for (const auto &LC : LibraryCalls) { |
| 240 | setLibcallName(LC.Op, LC.Name); |
| 241 | if (LC.Cond != ISD::SETCC_INVALID) |
| 242 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 243 | } |
| Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 244 | } |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 245 | |
| 246 | // Set the correct calling convention for ARMv7k WatchOS. It's just |
| 247 | // AAPCS_VFP for functions as simple as libcalls. |
| 248 | if (Subtarget->isTargetWatchOS()) { |
| 249 | for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) |
| 250 | setLibcallCallingConv((RTLIB::Libcall)i, CallingConv::ARM_AAPCS_VFP); |
| 251 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 252 | } |
| 253 | |
| Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 254 | // These libcalls are not available in 32-bit. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 255 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 256 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 257 | setLibcallName(RTLIB::SRA_I128, nullptr); |
| Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 258 | |
| Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 259 | // RTLIB |
| 260 | if (Subtarget->isAAPCS_ABI() && |
| 261 | (Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() || |
| 262 | Subtarget->isTargetAndroid())) { |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 263 | static const struct { |
| 264 | const RTLIB::Libcall Op; |
| 265 | const char * const Name; |
| 266 | const CallingConv::ID CC; |
| 267 | const ISD::CondCode Cond; |
| 268 | } LibraryCalls[] = { |
| 269 | // Double-precision floating-point arithmetic helper functions |
| 270 | // RTABI chapter 4.1.2, Table 2 |
| 271 | { RTLIB::ADD_F64, "__aeabi_dadd", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 272 | { RTLIB::DIV_F64, "__aeabi_ddiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 273 | { RTLIB::MUL_F64, "__aeabi_dmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 274 | { RTLIB::SUB_F64, "__aeabi_dsub", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 275 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 276 | // Double-precision floating-point comparison helper functions |
| 277 | // RTABI chapter 4.1.2, Table 3 |
| 278 | { RTLIB::OEQ_F64, "__aeabi_dcmpeq", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 279 | { RTLIB::UNE_F64, "__aeabi_dcmpeq", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| 280 | { RTLIB::OLT_F64, "__aeabi_dcmplt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 281 | { RTLIB::OLE_F64, "__aeabi_dcmple", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 282 | { RTLIB::OGE_F64, "__aeabi_dcmpge", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 283 | { RTLIB::OGT_F64, "__aeabi_dcmpgt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 284 | { RTLIB::UO_F64, "__aeabi_dcmpun", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 285 | { RTLIB::O_F64, "__aeabi_dcmpun", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 286 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 287 | // Single-precision floating-point arithmetic helper functions |
| 288 | // RTABI chapter 4.1.2, Table 4 |
| 289 | { RTLIB::ADD_F32, "__aeabi_fadd", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 290 | { RTLIB::DIV_F32, "__aeabi_fdiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 291 | { RTLIB::MUL_F32, "__aeabi_fmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 292 | { RTLIB::SUB_F32, "__aeabi_fsub", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 293 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 294 | // Single-precision floating-point comparison helper functions |
| 295 | // RTABI chapter 4.1.2, Table 5 |
| 296 | { RTLIB::OEQ_F32, "__aeabi_fcmpeq", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 297 | { RTLIB::UNE_F32, "__aeabi_fcmpeq", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| 298 | { RTLIB::OLT_F32, "__aeabi_fcmplt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 299 | { RTLIB::OLE_F32, "__aeabi_fcmple", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 300 | { RTLIB::OGE_F32, "__aeabi_fcmpge", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 301 | { RTLIB::OGT_F32, "__aeabi_fcmpgt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 302 | { RTLIB::UO_F32, "__aeabi_fcmpun", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 303 | { RTLIB::O_F32, "__aeabi_fcmpun", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 304 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 305 | // Floating-point to integer conversions. |
| 306 | // RTABI chapter 4.1.2, Table 6 |
| 307 | { RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 308 | { RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 309 | { RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 310 | { RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 311 | { RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 312 | { RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 313 | { RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 314 | { RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 315 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 316 | // Conversions between floating types. |
| 317 | // RTABI chapter 4.1.2, Table 7 |
| 318 | { RTLIB::FPROUND_F64_F32, "__aeabi_d2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Saleem Abdulrasool | 017bd57 | 2014-08-17 22:51:02 +0000 | [diff] [blame] | 319 | { RTLIB::FPROUND_F64_F16, "__aeabi_d2h", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 320 | { RTLIB::FPEXT_F32_F64, "__aeabi_f2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 321 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 322 | // Integer to floating-point conversions. |
| 323 | // RTABI chapter 4.1.2, Table 8 |
| 324 | { RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 325 | { RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 326 | { RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 327 | { RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 328 | { RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 329 | { RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 330 | { RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 331 | { RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 332 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 333 | // Long long helper functions |
| 334 | // RTABI chapter 4.2, Table 9 |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 335 | { RTLIB::MUL_I64, "__aeabi_lmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 336 | { RTLIB::SHL_I64, "__aeabi_llsl", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 337 | { RTLIB::SRL_I64, "__aeabi_llsr", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 338 | { RTLIB::SRA_I64, "__aeabi_lasr", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 339 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 340 | // Integer division functions |
| 341 | // RTABI chapter 4.3.1 |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 342 | { RTLIB::SDIV_I8, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 343 | { RTLIB::SDIV_I16, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 344 | { RTLIB::SDIV_I32, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 345 | { RTLIB::SDIV_I64, "__aeabi_ldivmod", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 346 | { RTLIB::UDIV_I8, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 347 | { RTLIB::UDIV_I16, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 348 | { RTLIB::UDIV_I32, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 349 | { RTLIB::UDIV_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | for (const auto &LC : LibraryCalls) { |
| 353 | setLibcallName(LC.Op, LC.Name); |
| 354 | setLibcallCallingConv(LC.Op, LC.CC); |
| 355 | if (LC.Cond != ISD::SETCC_INVALID) |
| 356 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 357 | } |
| Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 358 | |
| 359 | // EABI dependent RTLIB |
| 360 | if (TM.Options.EABIVersion == EABI::EABI4 || |
| 361 | TM.Options.EABIVersion == EABI::EABI5) { |
| 362 | static const struct { |
| 363 | const RTLIB::Libcall Op; |
| 364 | const char *const Name; |
| 365 | const CallingConv::ID CC; |
| 366 | const ISD::CondCode Cond; |
| 367 | } MemOpsLibraryCalls[] = { |
| 368 | // Memory operations |
| 369 | // RTABI chapter 4.3.4 |
| 370 | { RTLIB::MEMCPY, "__aeabi_memcpy", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 371 | { RTLIB::MEMMOVE, "__aeabi_memmove", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 372 | { RTLIB::MEMSET, "__aeabi_memset", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 373 | }; |
| 374 | |
| 375 | for (const auto &LC : MemOpsLibraryCalls) { |
| 376 | setLibcallName(LC.Op, LC.Name); |
| 377 | setLibcallCallingConv(LC.Op, LC.CC); |
| 378 | if (LC.Cond != ISD::SETCC_INVALID) |
| 379 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 380 | } |
| 381 | } |
| Anton Korobeynikov | a6b3ce2 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| Saleem Abdulrasool | 056fc3d | 2014-05-16 05:41:33 +0000 | [diff] [blame] | 384 | if (Subtarget->isTargetWindows()) { |
| 385 | static const struct { |
| 386 | const RTLIB::Libcall Op; |
| 387 | const char * const Name; |
| 388 | const CallingConv::ID CC; |
| 389 | } LibraryCalls[] = { |
| 390 | { RTLIB::FPTOSINT_F32_I64, "__stoi64", CallingConv::ARM_AAPCS_VFP }, |
| 391 | { RTLIB::FPTOSINT_F64_I64, "__dtoi64", CallingConv::ARM_AAPCS_VFP }, |
| 392 | { RTLIB::FPTOUINT_F32_I64, "__stou64", CallingConv::ARM_AAPCS_VFP }, |
| 393 | { RTLIB::FPTOUINT_F64_I64, "__dtou64", CallingConv::ARM_AAPCS_VFP }, |
| 394 | { RTLIB::SINTTOFP_I64_F32, "__i64tos", CallingConv::ARM_AAPCS_VFP }, |
| 395 | { RTLIB::SINTTOFP_I64_F64, "__i64tod", CallingConv::ARM_AAPCS_VFP }, |
| 396 | { RTLIB::UINTTOFP_I64_F32, "__u64tos", CallingConv::ARM_AAPCS_VFP }, |
| 397 | { RTLIB::UINTTOFP_I64_F64, "__u64tod", CallingConv::ARM_AAPCS_VFP }, |
| 398 | }; |
| 399 | |
| 400 | for (const auto &LC : LibraryCalls) { |
| 401 | setLibcallName(LC.Op, LC.Name); |
| 402 | setLibcallCallingConv(LC.Op, LC.CC); |
| 403 | } |
| 404 | } |
| 405 | |
| Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 406 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 407 | if (Subtarget->isTargetWatchOS() || |
| 408 | (Subtarget->isTargetIOS() && |
| 409 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0))) { |
| Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 410 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 411 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 412 | } |
| 413 | |
| Oliver Stannard | 11790b2 | 2014-08-11 09:12:32 +0000 | [diff] [blame] | 414 | // The half <-> float conversion functions are always soft-float, but are |
| 415 | // needed for some targets which use a hard-float calling convention by |
| 416 | // default. |
| 417 | if (Subtarget->isAAPCS_ABI()) { |
| 418 | setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_AAPCS); |
| 419 | setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_AAPCS); |
| 420 | setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_AAPCS); |
| 421 | } else { |
| 422 | setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_APCS); |
| 423 | setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_APCS); |
| 424 | setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_APCS); |
| 425 | } |
| 426 | |
| Oliver Stannard | d3d114b | 2015-10-07 16:58:49 +0000 | [diff] [blame] | 427 | // In EABI, these functions have an __aeabi_ prefix, but in GNUEABI they have |
| 428 | // a __gnu_ prefix (which is the default). |
| 429 | if (Subtarget->isTargetAEABI()) { |
| 430 | setLibcallName(RTLIB::FPROUND_F32_F16, "__aeabi_f2h"); |
| 431 | setLibcallName(RTLIB::FPROUND_F64_F16, "__aeabi_d2h"); |
| 432 | setLibcallName(RTLIB::FPEXT_F16_F32, "__aeabi_h2f"); |
| 433 | } |
| 434 | |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 435 | if (Subtarget->isThumb1Only()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 436 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
| Jim Grosbach | fde2110 | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 437 | else |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 438 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 439 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 440 | !Subtarget->isThumb1Only()) { |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 441 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 442 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 443 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 444 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 445 | for (MVT VT : MVT::vector_valuetypes()) { |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 446 | for (MVT InnerVT : MVT::vector_valuetypes()) { |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 447 | setTruncStoreAction(VT, InnerVT, Expand); |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 448 | setLoadExtAction(ISD::SEXTLOAD, VT, InnerVT, Expand); |
| 449 | setLoadExtAction(ISD::ZEXTLOAD, VT, InnerVT, Expand); |
| 450 | setLoadExtAction(ISD::EXTLOAD, VT, InnerVT, Expand); |
| 451 | } |
| Benjamin Kramer | 4dae598 | 2014-04-26 12:06:28 +0000 | [diff] [blame] | 452 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 453 | setOperationAction(ISD::MULHS, VT, Expand); |
| 454 | setOperationAction(ISD::SMUL_LOHI, VT, Expand); |
| 455 | setOperationAction(ISD::MULHU, VT, Expand); |
| 456 | setOperationAction(ISD::UMUL_LOHI, VT, Expand); |
| Benjamin Kramer | f3ad235 | 2014-05-19 13:12:38 +0000 | [diff] [blame] | 457 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 458 | setOperationAction(ISD::BSWAP, VT, Expand); |
| Eli Friedman | 6f84fed | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 459 | } |
| 460 | |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 461 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 462 | setOperationAction(ISD::ConstantFP, MVT::f64, Custom); |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 463 | |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 464 | setOperationAction(ISD::READ_REGISTER, MVT::i64, Custom); |
| 465 | setOperationAction(ISD::WRITE_REGISTER, MVT::i64, Custom); |
| 466 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 467 | if (Subtarget->hasNEON()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 468 | addDRTypeForNEON(MVT::v2f32); |
| 469 | addDRTypeForNEON(MVT::v8i8); |
| 470 | addDRTypeForNEON(MVT::v4i16); |
| 471 | addDRTypeForNEON(MVT::v2i32); |
| 472 | addDRTypeForNEON(MVT::v1i64); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 473 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 474 | addQRTypeForNEON(MVT::v4f32); |
| 475 | addQRTypeForNEON(MVT::v2f64); |
| 476 | addQRTypeForNEON(MVT::v16i8); |
| 477 | addQRTypeForNEON(MVT::v8i16); |
| 478 | addQRTypeForNEON(MVT::v4i32); |
| 479 | addQRTypeForNEON(MVT::v2i64); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 480 | |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 481 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 482 | // neither Neon nor VFP support any arithmetic operations on it. |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 483 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 484 | // supported for v4f32. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 485 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 486 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 487 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 488 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 489 | // ARMTargetLowering::addTypeForNEON method for details. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 490 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 491 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 492 | // FIXME: Create unittest. |
| 493 | // In another words, find a way when "copysign" appears in DAG with vector |
| 494 | // operands. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 495 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 496 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 497 | // ARMTargetLowering::addTypeForNEON method for details. |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 498 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 499 | // FIXME: Create unittest for FNEG and for FABS. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 500 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 501 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 502 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 505 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 506 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 507 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 508 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 509 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 510 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 511 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 512 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 513 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 514 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 515 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 516 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 517 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 518 | setOperationAction(ISD::FMA, MVT::v2f64, Expand); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 519 | |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 520 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 522 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 523 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 524 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 525 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 526 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 527 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 528 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 529 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
| Craig Topper | 61d0457 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 530 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
| 531 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); |
| 532 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); |
| 533 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); |
| Craig Topper | 3e41a5b | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 534 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 535 | |
| Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 536 | // Mark v2f32 intrinsics. |
| 537 | setOperationAction(ISD::FSQRT, MVT::v2f32, Expand); |
| 538 | setOperationAction(ISD::FSIN, MVT::v2f32, Expand); |
| 539 | setOperationAction(ISD::FCOS, MVT::v2f32, Expand); |
| 540 | setOperationAction(ISD::FPOWI, MVT::v2f32, Expand); |
| 541 | setOperationAction(ISD::FPOW, MVT::v2f32, Expand); |
| 542 | setOperationAction(ISD::FLOG, MVT::v2f32, Expand); |
| 543 | setOperationAction(ISD::FLOG2, MVT::v2f32, Expand); |
| 544 | setOperationAction(ISD::FLOG10, MVT::v2f32, Expand); |
| 545 | setOperationAction(ISD::FEXP, MVT::v2f32, Expand); |
| 546 | setOperationAction(ISD::FEXP2, MVT::v2f32, Expand); |
| 547 | setOperationAction(ISD::FCEIL, MVT::v2f32, Expand); |
| 548 | setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand); |
| 549 | setOperationAction(ISD::FRINT, MVT::v2f32, Expand); |
| 550 | setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand); |
| 551 | setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand); |
| 552 | |
| Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 553 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 554 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 555 | // Custom handling for some quad-vector types to detect VMULL. |
| 556 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 557 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 558 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 559 | // Custom handling for some vector types to avoid expensive expansions |
| 560 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 561 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 562 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 563 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 564 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 565 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 566 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 567 | // a destination type that is wider than the source, and nor does |
| 568 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 569 | // source. |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 570 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 571 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 572 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 573 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
| Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 574 | |
| Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 575 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
| Eli Friedman | 3083494 | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 576 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
| Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 577 | |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 578 | // NEON does not have single instruction CTPOP for vectors with element |
| 579 | // types wider than 8-bits. However, custom lowering can leverage the |
| 580 | // v8i8/v16i8 vcnt instruction. |
| 581 | setOperationAction(ISD::CTPOP, MVT::v2i32, Custom); |
| 582 | setOperationAction(ISD::CTPOP, MVT::v4i32, Custom); |
| 583 | setOperationAction(ISD::CTPOP, MVT::v4i16, Custom); |
| 584 | setOperationAction(ISD::CTPOP, MVT::v8i16, Custom); |
| 585 | |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 586 | // NEON does not have single instruction CTTZ for vectors. |
| 587 | setOperationAction(ISD::CTTZ, MVT::v8i8, Custom); |
| 588 | setOperationAction(ISD::CTTZ, MVT::v4i16, Custom); |
| 589 | setOperationAction(ISD::CTTZ, MVT::v2i32, Custom); |
| 590 | setOperationAction(ISD::CTTZ, MVT::v1i64, Custom); |
| 591 | |
| 592 | setOperationAction(ISD::CTTZ, MVT::v16i8, Custom); |
| 593 | setOperationAction(ISD::CTTZ, MVT::v8i16, Custom); |
| 594 | setOperationAction(ISD::CTTZ, MVT::v4i32, Custom); |
| 595 | setOperationAction(ISD::CTTZ, MVT::v2i64, Custom); |
| 596 | |
| 597 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v8i8, Custom); |
| 598 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v4i16, Custom); |
| 599 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v2i32, Custom); |
| 600 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v1i64, Custom); |
| 601 | |
| 602 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v16i8, Custom); |
| 603 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v8i16, Custom); |
| 604 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v4i32, Custom); |
| 605 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v2i64, Custom); |
| 606 | |
| Jim Grosbach | 5f21587 | 2013-02-27 21:31:12 +0000 | [diff] [blame] | 607 | // NEON only has FMA instructions as of VFP4. |
| 608 | if (!Subtarget->hasVFP4()) { |
| 609 | setOperationAction(ISD::FMA, MVT::v2f32, Expand); |
| 610 | setOperationAction(ISD::FMA, MVT::v4f32, Expand); |
| 611 | } |
| 612 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 613 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 614 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 615 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 616 | setTargetDAGCombine(ISD::SHL); |
| 617 | setTargetDAGCombine(ISD::SRL); |
| 618 | setTargetDAGCombine(ISD::SRA); |
| 619 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 620 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 621 | setTargetDAGCombine(ISD::ANY_EXTEND); |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 622 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 623 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 624 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 625 | setTargetDAGCombine(ISD::STORE); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 626 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 627 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 628 | setTargetDAGCombine(ISD::FDIV); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 629 | setTargetDAGCombine(ISD::LOAD); |
| Nadav Rotem | 097106b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 630 | |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 631 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 632 | for (MVT Ty : {MVT::v8i8, MVT::v4i8, MVT::v2i8, MVT::v4i16, MVT::v2i16, |
| 633 | MVT::v2i32}) { |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 634 | for (MVT VT : MVT::integer_vector_valuetypes()) { |
| Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 635 | setLoadExtAction(ISD::EXTLOAD, VT, Ty, Legal); |
| 636 | setLoadExtAction(ISD::ZEXTLOAD, VT, Ty, Legal); |
| 637 | setLoadExtAction(ISD::SEXTLOAD, VT, Ty, Legal); |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 638 | } |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 639 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 642 | // ARM and Thumb2 support UMLAL/SMLAL. |
| 643 | if (!Subtarget->isThumb1Only()) |
| 644 | setTargetDAGCombine(ISD::ADDC); |
| 645 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 646 | if (Subtarget->isFPOnlySP()) { |
| Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 647 | // When targeting a floating-point unit with only single-precision |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 648 | // operations, f64 is legal for the few double-precision instructions which |
| 649 | // are present However, no double-precision operations other than moves, |
| 650 | // loads and stores are provided by the hardware. |
| 651 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 652 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 653 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| 654 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 655 | setOperationAction(ISD::FDIV, MVT::f64, Expand); |
| 656 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 657 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 658 | setOperationAction(ISD::FGETSIGN, MVT::f64, Expand); |
| 659 | setOperationAction(ISD::FNEG, MVT::f64, Expand); |
| 660 | setOperationAction(ISD::FABS, MVT::f64, Expand); |
| 661 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 662 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 663 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 664 | setOperationAction(ISD::FPOWI, MVT::f64, Expand); |
| 665 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 666 | setOperationAction(ISD::FLOG, MVT::f64, Expand); |
| 667 | setOperationAction(ISD::FLOG2, MVT::f64, Expand); |
| 668 | setOperationAction(ISD::FLOG10, MVT::f64, Expand); |
| 669 | setOperationAction(ISD::FEXP, MVT::f64, Expand); |
| 670 | setOperationAction(ISD::FEXP2, MVT::f64, Expand); |
| 671 | setOperationAction(ISD::FCEIL, MVT::f64, Expand); |
| 672 | setOperationAction(ISD::FTRUNC, MVT::f64, Expand); |
| 673 | setOperationAction(ISD::FRINT, MVT::f64, Expand); |
| 674 | setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand); |
| 675 | setOperationAction(ISD::FFLOOR, MVT::f64, Expand); |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 676 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 677 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 678 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 679 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 680 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Custom); |
| 681 | setOperationAction(ISD::FP_TO_UINT, MVT::f64, Custom); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 682 | setOperationAction(ISD::FP_ROUND, MVT::f32, Custom); |
| 683 | setOperationAction(ISD::FP_EXTEND, MVT::f64, Custom); |
| 684 | } |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 685 | |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 686 | computeRegisterProperties(Subtarget->getRegisterInfo()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 687 | |
| Tim Northover | 4e80b58 | 2014-07-18 13:01:19 +0000 | [diff] [blame] | 688 | // ARM does not have floating-point extending loads. |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 689 | for (MVT VT : MVT::fp_valuetypes()) { |
| 690 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
| 691 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand); |
| 692 | } |
| Tim Northover | 4e80b58 | 2014-07-18 13:01:19 +0000 | [diff] [blame] | 693 | |
| 694 | // ... or truncating stores |
| 695 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| 696 | setTruncStoreAction(MVT::f32, MVT::f16, Expand); |
| 697 | setTruncStoreAction(MVT::f64, MVT::f16, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 698 | |
| Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 699 | // ARM does not have i1 sign extending load. |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 700 | for (MVT VT : MVT::integer_valuetypes()) |
| 701 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); |
| Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 702 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 703 | // ARM supports all 4 flavors of integer indexed load / store. |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 704 | if (!Subtarget->isThumb1Only()) { |
| 705 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 706 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 707 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 708 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 709 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 710 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 711 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 712 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 713 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 714 | setIndexedStoreAction(im, MVT::i32, Legal); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 715 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 716 | } |
| 717 | |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 718 | setOperationAction(ISD::SADDO, MVT::i32, Custom); |
| 719 | setOperationAction(ISD::UADDO, MVT::i32, Custom); |
| 720 | setOperationAction(ISD::SSUBO, MVT::i32, Custom); |
| 721 | setOperationAction(ISD::USUBO, MVT::i32, Custom); |
| 722 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 723 | // i64 operation support. |
| Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 724 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 725 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| Evan Cheng | b24e51e | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 726 | if (Subtarget->isThumb1Only()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 727 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 728 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 729 | } |
| Jim Grosbach | cf1464d | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 730 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| Artyom Skrobov | cf29644 | 2015-09-24 17:31:16 +0000 | [diff] [blame] | 731 | || (Subtarget->isThumb2() && !Subtarget->hasDSP())) |
| Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 732 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 733 | |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 734 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 735 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 736 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 737 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 738 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 739 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 740 | if (!Subtarget->isThumb1Only()) { |
| 741 | // FIXME: We should do this for Thumb1 as well. |
| 742 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 743 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 744 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 745 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 746 | } |
| 747 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 748 | // ARM does not have ROTL. |
| Charlie Turner | 458e79b | 2015-10-27 10:25:20 +0000 | [diff] [blame] | 749 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
| 750 | for (MVT VT : MVT::vector_valuetypes()) { |
| 751 | setOperationAction(ISD::ROTL, VT, Expand); |
| 752 | setOperationAction(ISD::ROTR, VT, Expand); |
| 753 | } |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 754 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 755 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| David Goodwin | aa294c5 | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 756 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 757 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 758 | |
| Chandler Carruth | 637cc6a | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 759 | // These just redirect to CTTZ and CTLZ on ARM. |
| 760 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 761 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 762 | |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 763 | // @llvm.readcyclecounter requires the Performance Monitors extension. |
| 764 | // Default to the 0 expansion on unsupported platforms. |
| 765 | // FIXME: Technically there are older ARM CPUs that have |
| 766 | // implementation-specific ways of obtaining this information. |
| 767 | if (Subtarget->hasPerfMon()) |
| 768 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 769 | |
| Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 770 | // Only ARMv6 has BSWAP. |
| 771 | if (!Subtarget->hasV6Ops()) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 772 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 773 | |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 774 | if (!(Subtarget->hasDivide() && Subtarget->isThumb2()) && |
| 775 | !(Subtarget->hasDivideInARMMode() && !Subtarget->isThumb())) { |
| 776 | // These are expanded into libcalls if the cpu doesn't have HW divider. |
| Artyom Skrobov | 7fd67e2 | 2015-10-20 13:14:52 +0000 | [diff] [blame] | 777 | setOperationAction(ISD::SDIV, MVT::i32, LibCall); |
| 778 | setOperationAction(ISD::UDIV, MVT::i32, LibCall); |
| Jim Grosbach | 92d99900 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 779 | } |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 780 | |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 781 | if (Subtarget->isTargetWindows() && !Subtarget->hasDivide()) { |
| 782 | setOperationAction(ISD::SDIV, MVT::i32, Custom); |
| 783 | setOperationAction(ISD::UDIV, MVT::i32, Custom); |
| 784 | |
| 785 | setOperationAction(ISD::SDIV, MVT::i64, Custom); |
| 786 | setOperationAction(ISD::UDIV, MVT::i64, Custom); |
| 787 | } |
| 788 | |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 789 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 790 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 791 | // Register based DivRem for AEABI (RTABI 4.2) |
| Sumanth Gundapaneni | 532a136 | 2015-07-31 00:45:12 +0000 | [diff] [blame] | 792 | if (Subtarget->isTargetAEABI() || Subtarget->isTargetAndroid()) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 793 | setOperationAction(ISD::SREM, MVT::i64, Custom); |
| 794 | setOperationAction(ISD::UREM, MVT::i64, Custom); |
| 795 | |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 796 | setLibcallName(RTLIB::SDIVREM_I8, "__aeabi_idivmod"); |
| 797 | setLibcallName(RTLIB::SDIVREM_I16, "__aeabi_idivmod"); |
| 798 | setLibcallName(RTLIB::SDIVREM_I32, "__aeabi_idivmod"); |
| 799 | setLibcallName(RTLIB::SDIVREM_I64, "__aeabi_ldivmod"); |
| 800 | setLibcallName(RTLIB::UDIVREM_I8, "__aeabi_uidivmod"); |
| 801 | setLibcallName(RTLIB::UDIVREM_I16, "__aeabi_uidivmod"); |
| 802 | setLibcallName(RTLIB::UDIVREM_I32, "__aeabi_uidivmod"); |
| 803 | setLibcallName(RTLIB::UDIVREM_I64, "__aeabi_uldivmod"); |
| 804 | |
| 805 | setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::ARM_AAPCS); |
| 806 | setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::ARM_AAPCS); |
| 807 | setLibcallCallingConv(RTLIB::SDIVREM_I32, CallingConv::ARM_AAPCS); |
| 808 | setLibcallCallingConv(RTLIB::SDIVREM_I64, CallingConv::ARM_AAPCS); |
| 809 | setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::ARM_AAPCS); |
| 810 | setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::ARM_AAPCS); |
| 811 | setLibcallCallingConv(RTLIB::UDIVREM_I32, CallingConv::ARM_AAPCS); |
| 812 | setLibcallCallingConv(RTLIB::UDIVREM_I64, CallingConv::ARM_AAPCS); |
| 813 | |
| 814 | setOperationAction(ISD::SDIVREM, MVT::i32, Custom); |
| 815 | setOperationAction(ISD::UDIVREM, MVT::i32, Custom); |
| 816 | } else { |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 817 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 818 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
| 819 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 820 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 821 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 822 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 823 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 824 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 825 | |
| Evan Cheng | 74d92c1 | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 826 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| Evan Cheng | 2fa5a7e | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 827 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 828 | // Use the default implementation. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 829 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 830 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 831 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 832 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 833 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 834 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| Bill Wendling | 05d6f2f | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 835 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 836 | if (Subtarget->getTargetTriple().isWindowsItaniumEnvironment()) |
| 837 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 838 | else |
| 839 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
| 840 | |
| Evan Cheng | 6e809de | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 841 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| Jonathan Roelofs | 5e98ff9 | 2014-08-21 14:35:47 +0000 | [diff] [blame] | 842 | // the default expansion. If we are targeting a single threaded system, |
| 843 | // then set them all for expand so we can lower them later into their |
| 844 | // non-atomic form. |
| 845 | if (TM.Options.ThreadModel == ThreadModel::Single) |
| 846 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
| 847 | else if (Subtarget->hasAnyDataBarrier() && !Subtarget->isThumb1Only()) { |
| Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 848 | // ATOMIC_FENCE needs custom lowering; the others should have been expanded |
| 849 | // to ldrex/strex loops already. |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 850 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 851 | |
| Amara Emerson | b4ad2f3 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 852 | // On v8, we have particularly efficient implementations of atomic fences |
| 853 | // if they can be combined with nearby atomic loads and stores. |
| 854 | if (!Subtarget->hasV8Ops()) { |
| Robin Morisset | d18cda6 | 2014-08-15 22:17:28 +0000 | [diff] [blame] | 855 | // Automatically insert fences (dmb ish) around ATOMIC_SWAP etc. |
| Amara Emerson | b4ad2f3 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 856 | setInsertFencesForAtomic(true); |
| 857 | } |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 858 | } else { |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 859 | // If there's anything we can use as a barrier, go through custom lowering |
| 860 | // for ATOMIC_FENCE. |
| 861 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, |
| 862 | Subtarget->hasAnyDataBarrier() ? Custom : Expand); |
| 863 | |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 864 | // Set them all for expansion, which will force libcalls. |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 865 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
| Jim Grosbach | a57c288 | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 866 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 867 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 868 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 869 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 870 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 871 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 872 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 873 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 874 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 875 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 876 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 877 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 878 | // Unordered/Monotonic case. |
| 879 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 880 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 881 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 882 | |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 883 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
| Evan Cheng | 6f36042 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 884 | |
| Eli Friedman | 8cfa771 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 885 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 886 | if (!Subtarget->hasV6Ops()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 887 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 888 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 889 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 890 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 891 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 892 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 893 | !Subtarget->isThumb1Only()) { |
| Bob Wilson | 6a4491b | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 894 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 895 | // iff target supports vfp2. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 896 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 897 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 898 | } |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 899 | |
| 900 | // We want to custom lower some of our intrinsics. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 901 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 902 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 903 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
| 904 | setOperationAction(ISD::EH_SJLJ_SETUP_DISPATCH, MVT::Other, Custom); |
| Tim Northover | f8e47e4 | 2015-10-28 22:56:36 +0000 | [diff] [blame] | 905 | if (Subtarget->useSjLjEH()) |
| John McCall | 7d84ece | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 906 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 907 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 908 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 909 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 910 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 911 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 912 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 913 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 914 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 915 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 916 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 917 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 918 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 919 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 920 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 921 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 922 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 923 | |
| Dan Gohman | 482732a | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 924 | // We don't support sin/cos/fmod/copysign/pow |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 925 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 926 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 927 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 928 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 929 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
| 930 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 931 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 932 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 933 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 934 | !Subtarget->isThumb1Only()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 935 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 936 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 937 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 938 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 939 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 940 | |
| Evan Cheng | d0007f3 | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 941 | if (!Subtarget->hasVFP4()) { |
| 942 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 943 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 944 | } |
| Cameron Zwarich | f03fa18 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 945 | |
| Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 946 | // Various VFP goodness |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 947 | if (!Subtarget->useSoftFloat() && !Subtarget->isThumb1Only()) { |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 948 | // FP-ARMv8 adds f64 <-> f16 conversion. Before that it should be expanded. |
| 949 | if (!Subtarget->hasFPARMv8() || Subtarget->isFPOnlySP()) { |
| Tim Northover | 53f3bcf | 2014-07-17 11:27:04 +0000 | [diff] [blame] | 950 | setOperationAction(ISD::FP16_TO_FP, MVT::f64, Expand); |
| 951 | setOperationAction(ISD::FP_TO_FP16, MVT::f64, Expand); |
| 952 | } |
| 953 | |
| 954 | // fp16 is a special v7 extension that adds f16 <-> f32 conversions. |
| Anton Korobeynikov | 64578d5 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 955 | if (!Subtarget->hasFP16()) { |
| Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 956 | setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand); |
| 957 | setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand); |
| Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 958 | } |
| Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 959 | } |
| Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 960 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 961 | // Combine sin / cos into one node or libcall if possible. |
| 962 | if (Subtarget->hasSinCos()) { |
| 963 | setLibcallName(RTLIB::SINCOS_F32, "sincosf"); |
| 964 | setLibcallName(RTLIB::SINCOS_F64, "sincos"); |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 965 | if (Subtarget->isTargetWatchOS()) { |
| 966 | setLibcallCallingConv(RTLIB::SINCOS_F32, CallingConv::ARM_AAPCS_VFP); |
| 967 | setLibcallCallingConv(RTLIB::SINCOS_F64, CallingConv::ARM_AAPCS_VFP); |
| 968 | } |
| 969 | if (Subtarget->isTargetIOS() || Subtarget->isTargetWatchOS()) { |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 970 | // For iOS, we don't want to the normal expansion of a libcall to |
| 971 | // sincos. We want to issue a libcall to __sincos_stret. |
| 972 | setOperationAction(ISD::FSINCOS, MVT::f64, Custom); |
| 973 | setOperationAction(ISD::FSINCOS, MVT::f32, Custom); |
| 974 | } |
| 975 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 976 | |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 977 | // FP-ARMv8 implements a lot of rounding-like FP operations. |
| 978 | if (Subtarget->hasFPARMv8()) { |
| 979 | setOperationAction(ISD::FFLOOR, MVT::f32, Legal); |
| 980 | setOperationAction(ISD::FCEIL, MVT::f32, Legal); |
| 981 | setOperationAction(ISD::FROUND, MVT::f32, Legal); |
| 982 | setOperationAction(ISD::FTRUNC, MVT::f32, Legal); |
| 983 | setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal); |
| 984 | setOperationAction(ISD::FRINT, MVT::f32, Legal); |
| James Molloy | ea3a687 | 2015-08-11 12:06:22 +0000 | [diff] [blame] | 985 | setOperationAction(ISD::FMINNUM, MVT::f32, Legal); |
| 986 | setOperationAction(ISD::FMAXNUM, MVT::f32, Legal); |
| James Molloy | ee868b2 | 2015-08-11 12:06:25 +0000 | [diff] [blame] | 987 | setOperationAction(ISD::FMINNUM, MVT::v2f32, Legal); |
| 988 | setOperationAction(ISD::FMAXNUM, MVT::v2f32, Legal); |
| 989 | setOperationAction(ISD::FMINNUM, MVT::v4f32, Legal); |
| 990 | setOperationAction(ISD::FMAXNUM, MVT::v4f32, Legal); |
| 991 | |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 992 | if (!Subtarget->isFPOnlySP()) { |
| 993 | setOperationAction(ISD::FFLOOR, MVT::f64, Legal); |
| 994 | setOperationAction(ISD::FCEIL, MVT::f64, Legal); |
| 995 | setOperationAction(ISD::FROUND, MVT::f64, Legal); |
| 996 | setOperationAction(ISD::FTRUNC, MVT::f64, Legal); |
| 997 | setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal); |
| 998 | setOperationAction(ISD::FRINT, MVT::f64, Legal); |
| James Molloy | ea3a687 | 2015-08-11 12:06:22 +0000 | [diff] [blame] | 999 | setOperationAction(ISD::FMINNUM, MVT::f64, Legal); |
| 1000 | setOperationAction(ISD::FMAXNUM, MVT::f64, Legal); |
| Chad Rosier | b1bbf6f | 2014-08-15 21:38:16 +0000 | [diff] [blame] | 1001 | } |
| 1002 | } |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1003 | |
| James Molloy | 974838f | 2015-08-17 19:37:12 +0000 | [diff] [blame] | 1004 | if (Subtarget->hasNEON()) { |
| 1005 | // vmin and vmax aren't available in a scalar form, so we use |
| 1006 | // a NEON instruction with an undef lane instead. |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1007 | setOperationAction(ISD::FMINNAN, MVT::f32, Legal); |
| 1008 | setOperationAction(ISD::FMAXNAN, MVT::f32, Legal); |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 1009 | setOperationAction(ISD::FMINNAN, MVT::v2f32, Legal); |
| 1010 | setOperationAction(ISD::FMAXNAN, MVT::v2f32, Legal); |
| 1011 | setOperationAction(ISD::FMINNAN, MVT::v4f32, Legal); |
| 1012 | setOperationAction(ISD::FMAXNAN, MVT::v4f32, Legal); |
| 1013 | } |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1014 | |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 1015 | // We have target-specific dag combine patterns for the following nodes: |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1016 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 1017 | setTargetDAGCombine(ISD::ADD); |
| 1018 | setTargetDAGCombine(ISD::SUB); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 1019 | setTargetDAGCombine(ISD::MUL); |
| Jakob Stoklund Olesen | e45e22b | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 1020 | setTargetDAGCombine(ISD::AND); |
| 1021 | setTargetDAGCombine(ISD::OR); |
| 1022 | setTargetDAGCombine(ISD::XOR); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 1023 | |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 1024 | if (Subtarget->hasV6Ops()) |
| 1025 | setTargetDAGCombine(ISD::SRL); |
| 1026 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1027 | setStackPointerRegisterToSaveRestore(ARM::SP); |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1028 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 1029 | if (Subtarget->useSoftFloat() || Subtarget->isThumb1Only() || |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1030 | !Subtarget->hasVFP2()) |
| Evan Cheng | 34c2604 | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 1031 | setSchedulingPreference(Sched::RegPressure); |
| 1032 | else |
| 1033 | setSchedulingPreference(Sched::Hybrid); |
| Dale Johannesen | 58698d2 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1034 | |
| Evan Cheng | 3ae2b79 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 1035 | //// temporary - rewrite interface to use type |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1036 | MaxStoresPerMemset = 8; |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1037 | MaxStoresPerMemsetOptSize = 4; |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1038 | MaxStoresPerMemcpy = 4; // For @llvm.memcpy -> sequence of stores |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1039 | MaxStoresPerMemcpyOptSize = 2; |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1040 | MaxStoresPerMemmove = 4; // For @llvm.memmove -> sequence of stores |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1041 | MaxStoresPerMemmoveOptSize = 2; |
| Evan Cheng | b71233f | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 1042 | |
| Rafael Espindola | a76eccf | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 1043 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 1044 | // are at least 4 bytes aligned. |
| 1045 | setMinStackArgumentAlignment(4); |
| 1046 | |
| Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 1047 | // Prefer likely predicted branches to selects on out-of-order cores. |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1048 | PredictableSelectIsExpensive = Subtarget->isLikeA9(); |
| Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 1049 | |
| Eli Friedman | 2518f83 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 1050 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1051 | } |
| 1052 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 1053 | bool ARMTargetLowering::useSoftFloat() const { |
| 1054 | return Subtarget->useSoftFloat(); |
| 1055 | } |
| 1056 | |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1057 | // FIXME: It might make sense to define the representative register class as the |
| 1058 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 1059 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 1060 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 1061 | // pressure tracking were modified such that a register use would increment the |
| 1062 | // pressure of the register class's representative and all of it's super |
| 1063 | // classes' representatives transitively. We have not implemented this because |
| 1064 | // of the difficulty prior to coalescing of modeling operand register classes |
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1065 | // due to the common occurrence of cross class copies and subregister insertions |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1066 | // and extractions. |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 1067 | std::pair<const TargetRegisterClass *, uint8_t> |
| 1068 | ARMTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, |
| 1069 | MVT VT) const { |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1070 | const TargetRegisterClass *RRC = nullptr; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1071 | uint8_t Cost = 1; |
| Patrik Hagglund | f9eb168 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 1072 | switch (VT.SimpleTy) { |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1073 | default: |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 1074 | return TargetLowering::findRepresentativeClass(TRI, VT); |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1075 | // Use DPR as representative register class for all floating point |
| 1076 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 1077 | // the cost is 1 for both f32 and f64. |
| 1078 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1079 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1080 | RRC = &ARM::DPRRegClass; |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1081 | // When NEON is used for SP, only half of the register file is available |
| 1082 | // because operations that define both SP and DP results will be constrained |
| 1083 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 1084 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 1085 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 1086 | Cost = 2; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1087 | break; |
| 1088 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 1089 | case MVT::v4f32: case MVT::v2f64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1090 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1091 | Cost = 2; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1092 | break; |
| 1093 | case MVT::v4i64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1094 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1095 | Cost = 4; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1096 | break; |
| 1097 | case MVT::v8i64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1098 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1099 | Cost = 8; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1100 | break; |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1101 | } |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1102 | return std::make_pair(RRC, Cost); |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1105 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1106 | switch ((ARMISD::NodeType)Opcode) { |
| 1107 | case ARMISD::FIRST_NUMBER: break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1108 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1109 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1110 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| Matthias Braun | f45afee | 2015-05-07 22:16:10 +0000 | [diff] [blame] | 1111 | case ARMISD::COPY_STRUCT_BYVAL: return "ARMISD::COPY_STRUCT_BYVAL"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1112 | case ARMISD::CALL: return "ARMISD::CALL"; |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1113 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1114 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 1115 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 1116 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 1117 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
| Evan Cheng | c6d70ae | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1118 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1119 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1120 | case ARMISD::INTRET_FLAG: return "ARMISD::INTRET_FLAG"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1121 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 1122 | case ARMISD::CMP: return "ARMISD::CMP"; |
| Bill Wendling | 4b79647 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 1123 | case ARMISD::CMN: return "ARMISD::CMN"; |
| David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 1124 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1125 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 1126 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 1127 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1128 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 1129 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1130 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1131 | |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 1132 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 1133 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1134 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 1135 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 1136 | case ARMISD::RRX: return "ARMISD::RRX"; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1137 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 1138 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 1139 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 1140 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 1141 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 1142 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 1143 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 1144 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1145 | |
| Evan Cheng | ec6d7c9 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 1146 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 1147 | case ARMISD::EH_SJLJ_LONGJMP: return "ARMISD::EH_SJLJ_LONGJMP"; |
| 1148 | case ARMISD::EH_SJLJ_SETUP_DISPATCH: return "ARMISD::EH_SJLJ_SETUP_DISPATCH"; |
| Evan Cheng | ec6d7c9 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 1149 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1150 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1151 | |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1152 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1153 | |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1154 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 1155 | |
| Bob Wilson | 7ed5971 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 1156 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
| Jim Grosbach | 53e8854 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1157 | |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 1158 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 1159 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 1160 | case ARMISD::WIN__CHKSTK: return "ARMISD:::WIN__CHKSTK"; |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 1161 | case ARMISD::WIN__DBZCHK: return "ARMISD::WIN__DBZCHK"; |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 1162 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1163 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1164 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1165 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1166 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 1167 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1168 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 1169 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1170 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 1171 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1172 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 1173 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 1174 | |
| 1175 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 1176 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 1177 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1178 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 1179 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 1180 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 1181 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 1182 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 1183 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 1184 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 1185 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 1186 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 1187 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 1188 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 1189 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1190 | case ARMISD::VSLI: return "ARMISD::VSLI"; |
| 1191 | case ARMISD::VSRI: return "ARMISD::VSRI"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1192 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 1193 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 1194 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 1195 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 1196 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
| Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 1197 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
| Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 1198 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 1199 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 1200 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 1201 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 1202 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 1203 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 1204 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 1205 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 1206 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 1207 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 1208 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 1209 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 1210 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
| 1211 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1212 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
| Jim Grosbach | 6e3b5fa | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1213 | case ARMISD::BFI: return "ARMISD::BFI"; |
| Bob Wilson | 62a6f7e | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1214 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 1215 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1216 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 1217 | case ARMISD::MEMCPY: return "ARMISD::MEMCPY"; |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1218 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 1219 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 1220 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1221 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 1222 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 1223 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1224 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1225 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1226 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1227 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1228 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1229 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1230 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1231 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1232 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1233 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1234 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1235 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1236 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1237 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1238 | } |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1239 | return nullptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1242 | EVT ARMTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &, |
| 1243 | EVT VT) const { |
| 1244 | if (!VT.isVector()) |
| 1245 | return getPointerTy(DL); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1246 | return VT.changeVectorElementTypeToInteger(); |
| 1247 | } |
| 1248 | |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1249 | /// getRegClassFor - Return the register class that should be used for the |
| 1250 | /// specified value type. |
| Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1251 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(MVT VT) const { |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1252 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1253 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1254 | // load / store 4 to 8 consecutive D registers. |
| Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1255 | if (Subtarget->hasNEON()) { |
| 1256 | if (VT == MVT::v4i64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1257 | return &ARM::QQPRRegClass; |
| 1258 | if (VT == MVT::v8i64) |
| 1259 | return &ARM::QQQQPRRegClass; |
| Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1260 | } |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1261 | return TargetLowering::getRegClassFor(VT); |
| 1262 | } |
| 1263 | |
| John Brawn | 0dbcd65 | 2015-03-18 12:01:59 +0000 | [diff] [blame] | 1264 | // memcpy, and other memory intrinsics, typically tries to use LDM/STM if the |
| 1265 | // source/dest is aligned and the copy size is large enough. We therefore want |
| 1266 | // to align such objects passed to memory intrinsics. |
| 1267 | bool ARMTargetLowering::shouldAlignPointerArgs(CallInst *CI, unsigned &MinSize, |
| 1268 | unsigned &PrefAlign) const { |
| 1269 | if (!isa<MemIntrinsic>(CI)) |
| 1270 | return false; |
| 1271 | MinSize = 8; |
| 1272 | // On ARM11 onwards (excluding M class) 8-byte aligned LDM is typically 1 |
| 1273 | // cycle faster than 4-byte aligned LDM. |
| 1274 | PrefAlign = (Subtarget->hasV6Ops() && !Subtarget->isMClass() ? 8 : 4); |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1278 | // Create a fast isel object. |
| 1279 | FastISel * |
| Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1280 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
| 1281 | const TargetLibraryInfo *libInfo) const { |
| 1282 | return ARM::createFastISel(funcInfo, libInfo); |
| Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1285 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1286 | unsigned NumVals = N->getNumValues(); |
| 1287 | if (!NumVals) |
| 1288 | return Sched::RegPressure; |
| 1289 | |
| 1290 | for (unsigned i = 0; i != NumVals; ++i) { |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1291 | EVT VT = N->getValueType(i); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1292 | if (VT == MVT::Glue || VT == MVT::Other) |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1293 | continue; |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1294 | if (VT.isFloatingPoint() || VT.isVector()) |
| Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1295 | return Sched::ILP; |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1296 | } |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1297 | |
| 1298 | if (!N->isMachineOpcode()) |
| 1299 | return Sched::RegPressure; |
| 1300 | |
| 1301 | // Load are scheduled for latency even if there instruction itinerary |
| 1302 | // is not available. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 1303 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1304 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1305 | |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1306 | if (MCID.getNumDefs() == 0) |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1307 | return Sched::RegPressure; |
| 1308 | if (!Itins->isEmpty() && |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1309 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
| Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1310 | return Sched::ILP; |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1311 | |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1312 | return Sched::RegPressure; |
| 1313 | } |
| 1314 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1315 | //===----------------------------------------------------------------------===// |
| 1316 | // Lowering Code |
| 1317 | //===----------------------------------------------------------------------===// |
| 1318 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1319 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1320 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1321 | switch (CC) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1322 | default: llvm_unreachable("Unknown condition code!"); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1323 | case ISD::SETNE: return ARMCC::NE; |
| 1324 | case ISD::SETEQ: return ARMCC::EQ; |
| 1325 | case ISD::SETGT: return ARMCC::GT; |
| 1326 | case ISD::SETGE: return ARMCC::GE; |
| 1327 | case ISD::SETLT: return ARMCC::LT; |
| 1328 | case ISD::SETLE: return ARMCC::LE; |
| 1329 | case ISD::SETUGT: return ARMCC::HI; |
| 1330 | case ISD::SETUGE: return ARMCC::HS; |
| 1331 | case ISD::SETULT: return ARMCC::LO; |
| 1332 | case ISD::SETULE: return ARMCC::LS; |
| 1333 | } |
| 1334 | } |
| 1335 | |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1336 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1337 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1338 | ARMCC::CondCodes &CondCode2) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1339 | CondCode2 = ARMCC::AL; |
| 1340 | switch (CC) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1341 | default: llvm_unreachable("Unknown FP condition!"); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1342 | case ISD::SETEQ: |
| 1343 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1344 | case ISD::SETGT: |
| 1345 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1346 | case ISD::SETGE: |
| 1347 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1348 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1349 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1350 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1351 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1352 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1353 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1354 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1355 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1356 | case ISD::SETLT: |
| 1357 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1358 | case ISD::SETLE: |
| 1359 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1360 | case ISD::SETNE: |
| 1361 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1362 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1365 | //===----------------------------------------------------------------------===// |
| 1366 | // Calling Convention Implementation |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1367 | //===----------------------------------------------------------------------===// |
| 1368 | |
| 1369 | #include "ARMGenCallingConv.inc" |
| 1370 | |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1371 | /// getEffectiveCallingConv - Get the effective calling convention, taking into |
| 1372 | /// account presence of floating point hardware and calling convention |
| 1373 | /// limitations, such as support for variadic functions. |
| 1374 | CallingConv::ID |
| 1375 | ARMTargetLowering::getEffectiveCallingConv(CallingConv::ID CC, |
| 1376 | bool isVarArg) const { |
| Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1377 | switch (CC) { |
| 1378 | default: |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1379 | llvm_unreachable("Unsupported calling convention"); |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1380 | case CallingConv::ARM_AAPCS: |
| 1381 | case CallingConv::ARM_APCS: |
| 1382 | case CallingConv::GHC: |
| 1383 | return CC; |
| 1384 | case CallingConv::ARM_AAPCS_VFP: |
| 1385 | return isVarArg ? CallingConv::ARM_AAPCS : CallingConv::ARM_AAPCS_VFP; |
| 1386 | case CallingConv::C: |
| Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1387 | if (!Subtarget->isAAPCS_ABI()) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1388 | return CallingConv::ARM_APCS; |
| Oliver Stannard | b5e596f | 2014-06-13 08:33:03 +0000 | [diff] [blame] | 1389 | else if (Subtarget->hasVFP2() && !Subtarget->isThumb1Only() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1390 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1391 | !isVarArg) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1392 | return CallingConv::ARM_AAPCS_VFP; |
| 1393 | else |
| 1394 | return CallingConv::ARM_AAPCS; |
| 1395 | case CallingConv::Fast: |
| 1396 | if (!Subtarget->isAAPCS_ABI()) { |
| Oliver Stannard | b5e596f | 2014-06-13 08:33:03 +0000 | [diff] [blame] | 1397 | if (Subtarget->hasVFP2() && !Subtarget->isThumb1Only() && !isVarArg) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1398 | return CallingConv::Fast; |
| 1399 | return CallingConv::ARM_APCS; |
| Oliver Stannard | b5e596f | 2014-06-13 08:33:03 +0000 | [diff] [blame] | 1400 | } else if (Subtarget->hasVFP2() && !Subtarget->isThumb1Only() && !isVarArg) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1401 | return CallingConv::ARM_AAPCS_VFP; |
| 1402 | else |
| 1403 | return CallingConv::ARM_AAPCS; |
| Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1404 | } |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
| 1407 | /// CCAssignFnForNode - Selects the correct CCAssignFn for the given |
| 1408 | /// CallingConvention. |
| 1409 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
| 1410 | bool Return, |
| 1411 | bool isVarArg) const { |
| 1412 | switch (getEffectiveCallingConv(CC, isVarArg)) { |
| 1413 | default: |
| 1414 | llvm_unreachable("Unsupported calling convention"); |
| Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1415 | case CallingConv::ARM_APCS: |
| Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1416 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1417 | case CallingConv::ARM_AAPCS: |
| 1418 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1419 | case CallingConv::ARM_AAPCS_VFP: |
| 1420 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1421 | case CallingConv::Fast: |
| 1422 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| Eric Christopher | b332236 | 2012-08-03 00:05:53 +0000 | [diff] [blame] | 1423 | case CallingConv::GHC: |
| 1424 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS_GHC); |
| Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1428 | /// LowerCallResult - Lower the result values of a call into the |
| 1429 | /// appropriate copies out of appropriate physical registers. |
| 1430 | SDValue |
| 1431 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1432 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1433 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1434 | SDLoc dl, SelectionDAG &DAG, |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1435 | SmallVectorImpl<SDValue> &InVals, |
| 1436 | bool isThisReturn, SDValue ThisVal) const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1437 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1438 | // Assign locations to each value returned by this call. |
| 1439 | SmallVector<CCValAssign, 16> RVLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1440 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 1441 | *DAG.getContext(), Call); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1442 | CCInfo.AnalyzeCallResult(Ins, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1443 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1444 | isVarArg)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1445 | |
| 1446 | // Copy all of the result registers out of their specified physreg. |
| 1447 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1448 | CCValAssign VA = RVLocs[i]; |
| 1449 | |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1450 | // Pass 'this' value directly from the argument to return value, to avoid |
| 1451 | // reg unit interference |
| 1452 | if (i == 0 && isThisReturn) { |
| Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1453 | assert(!VA.needsCustom() && VA.getLocVT() == MVT::i32 && |
| 1454 | "unexpected return calling convention register assignment"); |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1455 | InVals.push_back(ThisVal); |
| 1456 | continue; |
| 1457 | } |
| 1458 | |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1459 | SDValue Val; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1460 | if (VA.needsCustom()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1461 | // Handle f64 or half of a v2f64. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1462 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1463 | InFlag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1464 | Chain = Lo.getValue(1); |
| 1465 | InFlag = Lo.getValue(2); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1466 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1467 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1468 | InFlag); |
| 1469 | Chain = Hi.getValue(1); |
| 1470 | InFlag = Hi.getValue(2); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1471 | if (!Subtarget->isLittle()) |
| 1472 | std::swap (Lo, Hi); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1473 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1474 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1475 | if (VA.getLocVT() == MVT::v2f64) { |
| 1476 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1477 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1478 | DAG.getConstant(0, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1479 | |
| 1480 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1481 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1482 | Chain = Lo.getValue(1); |
| 1483 | InFlag = Lo.getValue(2); |
| 1484 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1485 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1486 | Chain = Hi.getValue(1); |
| 1487 | InFlag = Hi.getValue(2); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1488 | if (!Subtarget->isLittle()) |
| 1489 | std::swap (Lo, Hi); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1490 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1491 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1492 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1493 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1494 | } else { |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1495 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1496 | InFlag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1497 | Chain = Val.getValue(1); |
| 1498 | InFlag = Val.getValue(2); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1499 | } |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1500 | |
| 1501 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1502 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1503 | case CCValAssign::Full: break; |
| 1504 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1505 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1506 | break; |
| 1507 | } |
| 1508 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1509 | InVals.push_back(Val); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1512 | return Chain; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1513 | } |
| 1514 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1515 | /// LowerMemOpCallTo - Store the argument to the stack. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1516 | SDValue |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1517 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1518 | SDValue StackPtr, SDValue Arg, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1519 | SDLoc dl, SelectionDAG &DAG, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1520 | const CCValAssign &VA, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1521 | ISD::ArgFlagsTy Flags) const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1522 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1523 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1524 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(DAG.getDataLayout()), |
| 1525 | StackPtr, PtrOff); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1526 | return DAG.getStore( |
| 1527 | Chain, dl, Arg, PtrOff, |
| 1528 | MachinePointerInfo::getStack(DAG.getMachineFunction(), LocMemOffset), |
| 1529 | false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1530 | } |
| 1531 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1532 | void ARMTargetLowering::PassF64ArgInRegs(SDLoc dl, SelectionDAG &DAG, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1533 | SDValue Chain, SDValue &Arg, |
| 1534 | RegsToPassVector &RegsToPass, |
| 1535 | CCValAssign &VA, CCValAssign &NextVA, |
| 1536 | SDValue &StackPtr, |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1537 | SmallVectorImpl<SDValue> &MemOpChains, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1538 | ISD::ArgFlagsTy Flags) const { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1539 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1540 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1541 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1542 | unsigned id = Subtarget->isLittle() ? 0 : 1; |
| 1543 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd.getValue(id))); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1544 | |
| 1545 | if (NextVA.isRegLoc()) |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1546 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1-id))); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1547 | else { |
| 1548 | assert(NextVA.isMemLoc()); |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1549 | if (!StackPtr.getNode()) |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1550 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, |
| 1551 | getPointerTy(DAG.getDataLayout())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1552 | |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1553 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1-id), |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1554 | dl, DAG, NextVA, |
| 1555 | Flags)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1556 | } |
| 1557 | } |
| 1558 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1559 | /// LowerCall - Lowering a call into a callseq_start <- |
| Evan Cheng | 4b6c8f7 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1560 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1561 | /// nodes. |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1562 | SDValue |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1563 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1564 | SmallVectorImpl<SDValue> &InVals) const { |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1565 | SelectionDAG &DAG = CLI.DAG; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1566 | SDLoc &dl = CLI.DL; |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1567 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 1568 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 1569 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1570 | SDValue Chain = CLI.Chain; |
| 1571 | SDValue Callee = CLI.Callee; |
| 1572 | bool &isTailCall = CLI.IsTailCall; |
| 1573 | CallingConv::ID CallConv = CLI.CallConv; |
| 1574 | bool doesNotRet = CLI.DoesNotReturn; |
| 1575 | bool isVarArg = CLI.IsVarArg; |
| 1576 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1577 | MachineFunction &MF = DAG.getMachineFunction(); |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1578 | bool isStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1579 | bool isThisReturn = false; |
| 1580 | bool isSibCall = false; |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 1581 | auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls"); |
| Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1582 | |
| Bob Wilson | 8decdc4 | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1583 | // Disable tail calls if they're not supported. |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 1584 | if (!Subtarget->supportsTailCall() || Attr.getValueAsString() == "true") |
| Bob Wilson | 3c9ed76 | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1585 | isTailCall = false; |
| Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1586 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1587 | if (isTailCall) { |
| 1588 | // Check if it's really possible to do a tail call. |
| 1589 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1590 | isVarArg, isStructRet, MF.getFunction()->hasStructRetAttr(), |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1591 | Outs, OutVals, Ins, DAG); |
| Reid Kleckner | 5772b77 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 1592 | if (!isTailCall && CLI.CS && CLI.CS->isMustTailCall()) |
| 1593 | report_fatal_error("failed to perform tail call elimination on a call " |
| 1594 | "site marked musttail"); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1595 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1596 | // detected sibcalls. |
| 1597 | if (isTailCall) { |
| 1598 | ++NumTailCalls; |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1599 | isSibCall = true; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1600 | } |
| 1601 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1602 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1603 | // Analyze operands of the call, assigning locations to each operand. |
| 1604 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1605 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 1606 | *DAG.getContext(), Call); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1607 | CCInfo.AnalyzeCallOperands(Outs, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1608 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1609 | isVarArg)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1610 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1611 | // Get a count of how many bytes are to be pushed on the stack. |
| 1612 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1613 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1614 | // For tail calls, memory operands are available in our caller's stack. |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1615 | if (isSibCall) |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1616 | NumBytes = 0; |
| 1617 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1618 | // Adjust the stack pointer for the new arguments... |
| 1619 | // These operations are automatically eliminated by the prolog/epilog pass |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1620 | if (!isSibCall) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1621 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1622 | DAG.getIntPtrConstant(NumBytes, dl, true), dl); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1623 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1624 | SDValue StackPtr = |
| 1625 | DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy(DAG.getDataLayout())); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1626 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1627 | RegsToPassVector RegsToPass; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1628 | SmallVector<SDValue, 8> MemOpChains; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1629 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1630 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1631 | // of tail call optimization, arguments are handled later. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1632 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1633 | i != e; |
| 1634 | ++i, ++realArgIdx) { |
| 1635 | CCValAssign &VA = ArgLocs[i]; |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1636 | SDValue Arg = OutVals[realArgIdx]; |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1637 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1638 | bool isByVal = Flags.isByVal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1639 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1640 | // Promote the value if needed. |
| 1641 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1642 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1643 | case CCValAssign::Full: break; |
| 1644 | case CCValAssign::SExt: |
| 1645 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1646 | break; |
| 1647 | case CCValAssign::ZExt: |
| 1648 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1649 | break; |
| 1650 | case CCValAssign::AExt: |
| 1651 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1652 | break; |
| 1653 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1654 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1655 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1656 | } |
| 1657 | |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1658 | // f64 and v2f64 might be passed in i32 pairs and must be split into pieces |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1659 | if (VA.needsCustom()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1660 | if (VA.getLocVT() == MVT::v2f64) { |
| 1661 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1662 | DAG.getConstant(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1663 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1664 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1665 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1666 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1667 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1668 | |
| 1669 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1670 | if (VA.isRegLoc()) { |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1671 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1672 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1673 | } else { |
| 1674 | assert(VA.isMemLoc()); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1675 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1676 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1677 | dl, DAG, VA, Flags)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1678 | } |
| 1679 | } else { |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1680 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1681 | StackPtr, MemOpChains, Flags); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1682 | } |
| 1683 | } else if (VA.isRegLoc()) { |
| Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1684 | if (realArgIdx == 0 && Flags.isReturned() && Outs[0].VT == MVT::i32) { |
| 1685 | assert(VA.getLocVT() == MVT::i32 && |
| 1686 | "unexpected calling convention register assignment"); |
| 1687 | assert(!Ins.empty() && Ins[0].VT == MVT::i32 && |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1688 | "unexpected use of 'returned'"); |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1689 | isThisReturn = true; |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1690 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1691 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1692 | } else if (isByVal) { |
| 1693 | assert(VA.isMemLoc()); |
| 1694 | unsigned offset = 0; |
| 1695 | |
| 1696 | // True if this byval aggregate will be split between registers |
| 1697 | // and memory. |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1698 | unsigned ByValArgsCount = CCInfo.getInRegsParamsCount(); |
| Daniel Sanders | 8104b75 | 2014-11-01 19:32:23 +0000 | [diff] [blame] | 1699 | unsigned CurByValIdx = CCInfo.getInRegsParamsProcessed(); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1700 | |
| 1701 | if (CurByValIdx < ByValArgsCount) { |
| 1702 | |
| 1703 | unsigned RegBegin, RegEnd; |
| 1704 | CCInfo.getInRegsParamInfo(CurByValIdx, RegBegin, RegEnd); |
| 1705 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1706 | EVT PtrVT = |
| 1707 | DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1708 | unsigned int i, j; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1709 | for (i = 0, j = RegBegin; j < RegEnd; i++, j++) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1710 | SDValue Const = DAG.getConstant(4*i, dl, MVT::i32); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1711 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1712 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1713 | MachinePointerInfo(), |
| Manman Ren | 5a78755 | 2013-10-07 19:47:53 +0000 | [diff] [blame] | 1714 | false, false, false, |
| 1715 | DAG.InferPtrAlignment(AddArg)); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1716 | MemOpChains.push_back(Load.getValue(1)); |
| 1717 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1718 | } |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1719 | |
| 1720 | // If parameter size outsides register area, "offset" value |
| 1721 | // helps us to calculate stack slot for remained part properly. |
| 1722 | offset = RegEnd - RegBegin; |
| 1723 | |
| 1724 | CCInfo.nextInRegsParam(); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1725 | } |
| 1726 | |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1727 | if (Flags.getByValSize() > 4*offset) { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1728 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1729 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1730 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1731 | SDValue Dst = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, StkPtrOff); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1732 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1733 | SDValue Src = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, SrcOffset); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1734 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, dl, |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1735 | MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1736 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), dl, |
| 1737 | MVT::i32); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1738 | |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1739 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1740 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1741 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1742 | Ops)); |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1743 | } |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1744 | } else if (!isSibCall) { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1745 | assert(VA.isMemLoc()); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1746 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1747 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1748 | dl, DAG, VA, Flags)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1749 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | if (!MemOpChains.empty()) |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1753 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1754 | |
| 1755 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1756 | // and flag operands which copy the outgoing args into the appropriate regs. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1757 | SDValue InFlag; |
| Dale Johannesen | 44f9dfc | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1758 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1759 | // tail call optimization the copies to registers are lowered later. |
| 1760 | if (!isTailCall) |
| 1761 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1762 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1763 | RegsToPass[i].second, InFlag); |
| 1764 | InFlag = Chain.getValue(1); |
| 1765 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1766 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1767 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1768 | if (isTailCall) { |
| 1769 | // Force all the incoming stack arguments to be loaded from the stack |
| 1770 | // before any new outgoing arguments are stored to the stack, because the |
| 1771 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1772 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1773 | // than necessary, because it means that each store effectively depends |
| 1774 | // on every argument instead of just those arguments it would clobber. |
| 1775 | |
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1776 | // Do not flag preceding copytoreg stuff together with the following stuff. |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1777 | InFlag = SDValue(); |
| 1778 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1779 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1780 | RegsToPass[i].second, InFlag); |
| 1781 | InFlag = Chain.getValue(1); |
| 1782 | } |
| Stephen Lin | d36fd2c | 2013-04-20 00:47:48 +0000 | [diff] [blame] | 1783 | InFlag = SDValue(); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1784 | } |
| 1785 | |
| Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1786 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1787 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1788 | // node so that legalize doesn't hack it. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1789 | bool isDirect = false; |
| 1790 | bool isARMFunc = false; |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1791 | bool isLocalARMFunc = false; |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1792 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1793 | auto PtrVt = getPointerTy(DAG.getDataLayout()); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1794 | |
| Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame] | 1795 | if (Subtarget->genLongCalls()) { |
| Saleem Abdulrasool | 90386ad | 2014-06-07 20:29:27 +0000 | [diff] [blame] | 1796 | assert((Subtarget->isTargetWindows() || |
| 1797 | getTargetMachine().getRelocationModel() == Reloc::Static) && |
| 1798 | "long-calls with non-static relocation model!"); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1799 | // Handle a global address or an external symbol. If it's not one of |
| 1800 | // those, the target's already in a register, so we don't need to do |
| 1801 | // anything extra. |
| 1802 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Anders Carlsson | 47bccf7 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1803 | const GlobalValue *GV = G->getGlobal(); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1804 | // Create a constant pool entry for the callee address |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1805 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1806 | ARMConstantPoolValue *CPV = |
| 1807 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1808 | |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1809 | // Get the address of the callee into a register |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1810 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1811 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1812 | Callee = DAG.getLoad( |
| 1813 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1814 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1815 | false, false, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1816 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1817 | const char *Sym = S->getSymbol(); |
| 1818 | |
| 1819 | // Create a constant pool entry for the callee address |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1820 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1821 | ARMConstantPoolValue *CPV = |
| 1822 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1823 | ARMPCLabelIndex, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1824 | // Get the address of the callee into a register |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1825 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1826 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1827 | Callee = DAG.getLoad( |
| 1828 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1829 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1830 | false, false, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1831 | } |
| 1832 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1833 | const GlobalValue *GV = G->getGlobal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1834 | isDirect = true; |
| Peter Collingbourne | 6a9d177 | 2015-07-05 20:52:35 +0000 | [diff] [blame] | 1835 | bool isDef = GV->isStrongDefinitionForLinker(); |
| 1836 | bool isStub = (!isDef && Subtarget->isTargetMachO()) && |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1837 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| Tim Northover | 2a417b9 | 2014-08-06 11:13:14 +0000 | [diff] [blame] | 1838 | isARMFunc = !Subtarget->isThumb() || (isStub && !Subtarget->isMClass()); |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1839 | // ARM call to a local ARM function is predicable. |
| Peter Collingbourne | 6a9d177 | 2015-07-05 20:52:35 +0000 | [diff] [blame] | 1840 | isLocalARMFunc = !Subtarget->isThumb() && (isDef || !ARMInterworking); |
| Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1841 | // tBX takes a register source operand. |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 1842 | if (isStub && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1843 | assert(Subtarget->isTargetMachO() && "WrapperPIC use on non-MachO?"); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1844 | Callee = DAG.getNode( |
| 1845 | ARMISD::WrapperPIC, dl, PtrVt, |
| 1846 | DAG.getTargetGlobalAddress(GV, dl, PtrVt, 0, ARMII::MO_NONLAZY)); |
| 1847 | Callee = DAG.getLoad(PtrVt, dl, DAG.getEntryNode(), Callee, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1848 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 1849 | false, false, true, 0); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 1850 | } else if (Subtarget->isTargetCOFF()) { |
| 1851 | assert(Subtarget->isTargetWindows() && |
| 1852 | "Windows is the only supported COFF target"); |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 1853 | unsigned TargetFlags = GV->hasDLLImportStorageClass() |
| 1854 | ? ARMII::MO_DLLIMPORT |
| 1855 | : ARMII::MO_NO_FLAG; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1856 | Callee = |
| 1857 | DAG.getTargetGlobalAddress(GV, dl, PtrVt, /*Offset=*/0, TargetFlags); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 1858 | if (GV->hasDLLImportStorageClass()) |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1859 | Callee = |
| 1860 | DAG.getLoad(PtrVt, dl, DAG.getEntryNode(), |
| 1861 | DAG.getNode(ARMISD::Wrapper, dl, PtrVt, Callee), |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1862 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 1863 | false, false, false, 0); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1864 | } else { |
| 1865 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1866 | unsigned OpFlags = 0; |
| 1867 | if (Subtarget->isTargetELF() && |
| Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 1868 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1869 | OpFlags = ARMII::MO_PLT; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1870 | Callee = DAG.getTargetGlobalAddress(GV, dl, PtrVt, 0, OpFlags); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1871 | } |
| Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1872 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1873 | isDirect = true; |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1874 | bool isStub = Subtarget->isTargetMachO() && |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1875 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| Tim Northover | 2a417b9 | 2014-08-06 11:13:14 +0000 | [diff] [blame] | 1876 | isARMFunc = !Subtarget->isThumb() || (isStub && !Subtarget->isMClass()); |
| Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1877 | // tBX takes a register source operand. |
| 1878 | const char *Sym = S->getSymbol(); |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1879 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1880 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1881 | ARMConstantPoolValue *CPV = |
| 1882 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1883 | ARMPCLabelIndex, 4); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1884 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1885 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1886 | Callee = DAG.getLoad( |
| 1887 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1888 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1889 | false, false, 0); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1890 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1891 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVt, Callee, PICLabel); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1892 | } else { |
| 1893 | unsigned OpFlags = 0; |
| 1894 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1895 | if (Subtarget->isTargetELF() && |
| 1896 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1897 | OpFlags = ARMII::MO_PLT; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1898 | Callee = DAG.getTargetExternalSymbol(Sym, PtrVt, OpFlags); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1899 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1900 | } |
| 1901 | |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1902 | // FIXME: handle tail calls differently. |
| 1903 | unsigned CallOpc; |
| Evan Cheng | 6ab54fd | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1904 | if (Subtarget->isThumb()) { |
| 1905 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1906 | CallOpc = ARMISD::CALL_NOLINK; |
| 1907 | else |
| 1908 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1909 | } else { |
| Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1910 | if (!isDirect && !Subtarget->hasV5TOps()) |
| Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1911 | CallOpc = ARMISD::CALL_NOLINK; |
| Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1912 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
| Sanjay Patel | 924879a | 2015-08-04 15:49:57 +0000 | [diff] [blame] | 1913 | // Emit regular call when code size is the priority |
| 1914 | !MF.getFunction()->optForMinSize()) |
| Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1915 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1916 | CallOpc = ARMISD::CALL_NOLINK; |
| 1917 | else |
| 1918 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1919 | } |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1920 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1921 | std::vector<SDValue> Ops; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1922 | Ops.push_back(Chain); |
| 1923 | Ops.push_back(Callee); |
| 1924 | |
| 1925 | // Add argument registers to the end of the list so that they are known live |
| 1926 | // into the call. |
| 1927 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1928 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1929 | RegsToPass[i].second.getValueType())); |
| 1930 | |
| Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1931 | // Add a register mask operand representing the call-preserved registers. |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1932 | if (!isTailCall) { |
| 1933 | const uint32_t *Mask; |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 1934 | const ARMBaseRegisterInfo *ARI = Subtarget->getRegisterInfo(); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1935 | if (isThisReturn) { |
| 1936 | // For 'this' returns, use the R0-preserving mask if applicable |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1937 | Mask = ARI->getThisReturnPreservedMask(MF, CallConv); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1938 | if (!Mask) { |
| 1939 | // Set isThisReturn to false if the calling convention is not one that |
| 1940 | // allows 'returned' to be modeled in this way, so LowerCallResult does |
| 1941 | // not try to pass 'this' straight through |
| 1942 | isThisReturn = false; |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1943 | Mask = ARI->getCallPreservedMask(MF, CallConv); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1944 | } |
| 1945 | } else |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1946 | Mask = ARI->getCallPreservedMask(MF, CallConv); |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1947 | |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1948 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1949 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1950 | } |
| Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1951 | |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1952 | if (InFlag.getNode()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1953 | Ops.push_back(InFlag); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1954 | |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1955 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 1956 | if (isTailCall) { |
| 1957 | MF.getFrameInfo()->setHasTailCall(); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1958 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, Ops); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 1959 | } |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1960 | |
| Duncan Sands | 739a054 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1961 | // Returns a chain and a flag for retval copy to use. |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1962 | Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1963 | InFlag = Chain.getValue(1); |
| 1964 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1965 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
| 1966 | DAG.getIntPtrConstant(0, dl, true), InFlag, dl); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1967 | if (!Ins.empty()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1968 | InFlag = Chain.getValue(1); |
| 1969 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1970 | // Handle result values, copying them out of physregs into vregs that we |
| 1971 | // return. |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1972 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1973 | InVals, isThisReturn, |
| 1974 | isThisReturn ? OutVals[0] : SDValue()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1977 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1978 | /// on the stack. Remember the next parameter register to allocate, |
| 1979 | /// and then confiscate the rest of the parameter registers to insure |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1980 | /// this. |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1981 | void ARMTargetLowering::HandleByVal(CCState *State, unsigned &Size, |
| 1982 | unsigned Align) const { |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1983 | assert((State->getCallOrPrologue() == Prologue || |
| 1984 | State->getCallOrPrologue() == Call) && |
| 1985 | "unhandled ParmContext"); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1986 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1987 | // Byval (as with any stack) slots are always at least 4 byte aligned. |
| 1988 | Align = std::max(Align, 4U); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1989 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1990 | unsigned Reg = State->AllocateReg(GPRArgRegs); |
| 1991 | if (!Reg) |
| 1992 | return; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1993 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1994 | unsigned AlignInRegs = Align / 4; |
| 1995 | unsigned Waste = (ARM::R4 - Reg) % AlignInRegs; |
| 1996 | for (unsigned i = 0; i < Waste; ++i) |
| 1997 | Reg = State->AllocateReg(GPRArgRegs); |
| 1998 | |
| 1999 | if (!Reg) |
| 2000 | return; |
| 2001 | |
| 2002 | unsigned Excess = 4 * (ARM::R4 - Reg); |
| 2003 | |
| 2004 | // Special case when NSAA != SP and parameter size greater than size of |
| 2005 | // all remained GPR regs. In that case we can't split parameter, we must |
| 2006 | // send it to stack. We also must set NCRN to R4, so waste all |
| 2007 | // remained registers. |
| 2008 | const unsigned NSAAOffset = State->getNextStackOffset(); |
| 2009 | if (NSAAOffset != 0 && Size > Excess) { |
| 2010 | while (State->AllocateReg(GPRArgRegs)) |
| 2011 | ; |
| 2012 | return; |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2013 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 2014 | |
| 2015 | // First register for byval parameter is the first register that wasn't |
| 2016 | // allocated before this method call, so it would be "reg". |
| 2017 | // If parameter is small enough to be saved in range [reg, r4), then |
| 2018 | // the end (first after last) register would be reg + param-size-in-regs, |
| 2019 | // else parameter would be splitted between registers and stack, |
| 2020 | // end register would be r4 in this case. |
| 2021 | unsigned ByValRegBegin = Reg; |
| 2022 | unsigned ByValRegEnd = std::min<unsigned>(Reg + Size / 4, ARM::R4); |
| 2023 | State->addInRegsParamInfo(ByValRegBegin, ByValRegEnd); |
| 2024 | // Note, first register is allocated in the beginning of function already, |
| 2025 | // allocate remained amount of registers we need. |
| 2026 | for (unsigned i = Reg + 1; i != ByValRegEnd; ++i) |
| 2027 | State->AllocateReg(GPRArgRegs); |
| 2028 | // A byval parameter that is split between registers and memory needs its |
| 2029 | // size truncated here. |
| 2030 | // In the case where the entire structure fits in registers, we set the |
| 2031 | // size in memory to zero. |
| 2032 | Size = std::max<int>(Size - Excess, 0); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2035 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 2036 | /// already available in the same position (relatively) of the caller's |
| 2037 | /// incoming argument stack. |
| 2038 | static |
| 2039 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 2040 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| Craig Topper | 07720d8 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 2041 | const TargetInstrInfo *TII) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2042 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 2043 | int FI = INT_MAX; |
| 2044 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 2045 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
| Jakob Stoklund Olesen | 2fb5b31 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 2046 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2047 | return false; |
| 2048 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 2049 | if (!Def) |
| 2050 | return false; |
| 2051 | if (!Flags.isByVal()) { |
| 2052 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 2053 | return false; |
| 2054 | } else { |
| Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 2055 | return false; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2056 | } |
| 2057 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 2058 | if (Flags.isByVal()) |
| 2059 | // ByVal argument is passed in as a pointer but it's now being |
| 2060 | // dereferenced. e.g. |
| 2061 | // define @foo(%struct.X* %A) { |
| 2062 | // tail call @bar(%struct.X* byval %A) |
| 2063 | // } |
| 2064 | return false; |
| 2065 | SDValue Ptr = Ld->getBasePtr(); |
| 2066 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 2067 | if (!FINode) |
| 2068 | return false; |
| 2069 | FI = FINode->getIndex(); |
| 2070 | } else |
| 2071 | return false; |
| 2072 | |
| 2073 | assert(FI != INT_MAX); |
| 2074 | if (!MFI->isFixedObjectIndex(FI)) |
| 2075 | return false; |
| 2076 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 2077 | } |
| 2078 | |
| 2079 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 2080 | /// for tail call optimization. Targets which want to do tail call |
| 2081 | /// optimization should implement this function. |
| 2082 | bool |
| 2083 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 2084 | CallingConv::ID CalleeCC, |
| 2085 | bool isVarArg, |
| 2086 | bool isCalleeStructRet, |
| 2087 | bool isCallerStructRet, |
| 2088 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2089 | const SmallVectorImpl<SDValue> &OutVals, |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2090 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 2091 | SelectionDAG& DAG) const { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2092 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 2093 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 2094 | bool CCMatch = CallerCC == CalleeCC; |
| 2095 | |
| Artyom Skrobov | ad8a063 | 2015-09-28 09:44:11 +0000 | [diff] [blame] | 2096 | assert(Subtarget->supportsTailCall()); |
| 2097 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2098 | // Look for obvious safe cases to perform tail call optimization that do not |
| 2099 | // require ABI changes. This is what gcc calls sibcall. |
| 2100 | |
| Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2101 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 2102 | // any arguments. |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2103 | if (isVarArg && !Outs.empty()) |
| 2104 | return false; |
| 2105 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2106 | // Exception-handling functions need a special set of instructions to indicate |
| 2107 | // a return to the hardware. Tail-calling another function would probably |
| 2108 | // break this. |
| 2109 | if (CallerF->hasFnAttribute("interrupt")) |
| 2110 | return false; |
| 2111 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2112 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 2113 | // return semantics. |
| 2114 | if (isCalleeStructRet || isCallerStructRet) |
| 2115 | return false; |
| 2116 | |
| Oliver Stannard | 12993dd | 2014-08-18 12:42:15 +0000 | [diff] [blame] | 2117 | // Externally-defined functions with weak linkage should not be |
| 2118 | // tail-called on ARM when the OS does not support dynamic |
| 2119 | // pre-emption of symbols, as the AAELF spec requires normal calls |
| 2120 | // to undefined weak functions to be replaced with a NOP or jump to the |
| 2121 | // next instruction. The behaviour of branch instructions in this |
| 2122 | // situation (as used for tail calls) is implementation-defined, so we |
| 2123 | // cannot rely on the linker replacing the tail call with a return. |
| 2124 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 2125 | const GlobalValue *GV = G->getGlobal(); |
| Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 2126 | const Triple &TT = getTargetMachine().getTargetTriple(); |
| Saleem Abdulrasool | 67f7299 | 2015-01-03 21:35:00 +0000 | [diff] [blame] | 2127 | if (GV->hasExternalWeakLinkage() && |
| 2128 | (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO())) |
| Oliver Stannard | 12993dd | 2014-08-18 12:42:15 +0000 | [diff] [blame] | 2129 | return false; |
| 2130 | } |
| 2131 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2132 | // If the calling conventions do not match, then we'd better make sure the |
| 2133 | // results are returned in the same way as what the caller expects. |
| 2134 | if (!CCMatch) { |
| 2135 | SmallVector<CCValAssign, 16> RVLocs1; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2136 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), RVLocs1, |
| 2137 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2138 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 2139 | |
| 2140 | SmallVector<CCValAssign, 16> RVLocs2; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2141 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), RVLocs2, |
| 2142 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2143 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 2144 | |
| 2145 | if (RVLocs1.size() != RVLocs2.size()) |
| 2146 | return false; |
| 2147 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 2148 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 2149 | return false; |
| 2150 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 2151 | return false; |
| 2152 | if (RVLocs1[i].isRegLoc()) { |
| 2153 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 2154 | return false; |
| 2155 | } else { |
| 2156 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 2157 | return false; |
| 2158 | } |
| 2159 | } |
| 2160 | } |
| 2161 | |
| Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 2162 | // If Caller's vararg or byval argument has been split between registers and |
| 2163 | // stack, do not perform tail call, since part of the argument is in caller's |
| 2164 | // local frame. |
| 2165 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). |
| 2166 | getInfo<ARMFunctionInfo>(); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2167 | if (AFI_Caller->getArgRegsSaveSize()) |
| Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 2168 | return false; |
| 2169 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2170 | // If the callee takes no arguments then go on to check the results of the |
| 2171 | // call. |
| 2172 | if (!Outs.empty()) { |
| 2173 | // Check if stack adjustment is needed. For now, do not do this if any |
| 2174 | // argument is passed on the stack. |
| 2175 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2176 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 2177 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2178 | CCInfo.AnalyzeCallOperands(Outs, |
| 2179 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 2180 | if (CCInfo.getNextStackOffset()) { |
| 2181 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2182 | |
| 2183 | // Check if the arguments are already laid out in the right way as |
| 2184 | // the caller's fixed stack objects. |
| 2185 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2186 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 2187 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2188 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 2189 | i != e; |
| 2190 | ++i, ++realArgIdx) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2191 | CCValAssign &VA = ArgLocs[i]; |
| 2192 | EVT RegVT = VA.getLocVT(); |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2193 | SDValue Arg = OutVals[realArgIdx]; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2194 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2195 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 2196 | return false; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2197 | if (VA.needsCustom()) { |
| 2198 | // f64 and vector types are split into multiple registers or |
| 2199 | // register/stack-slot combinations. The types will not match |
| 2200 | // the registers; give up on memory f64 refs until we figure |
| 2201 | // out what to do about this. |
| 2202 | if (!VA.isRegLoc()) |
| 2203 | return false; |
| 2204 | if (!ArgLocs[++i].isRegLoc()) |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 2205 | return false; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2206 | if (RegVT == MVT::v2f64) { |
| 2207 | if (!ArgLocs[++i].isRegLoc()) |
| 2208 | return false; |
| 2209 | if (!ArgLocs[++i].isRegLoc()) |
| 2210 | return false; |
| 2211 | } |
| 2212 | } else if (!VA.isRegLoc()) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2213 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 2214 | MFI, MRI, TII)) |
| 2215 | return false; |
| 2216 | } |
| 2217 | } |
| 2218 | } |
| 2219 | } |
| 2220 | |
| 2221 | return true; |
| 2222 | } |
| 2223 | |
| Benjamin Kramer | b1996da | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2224 | bool |
| 2225 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
| 2226 | MachineFunction &MF, bool isVarArg, |
| 2227 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2228 | LLVMContext &Context) const { |
| 2229 | SmallVector<CCValAssign, 16> RVLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2230 | CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context); |
| Benjamin Kramer | b1996da | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2231 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, |
| 2232 | isVarArg)); |
| 2233 | } |
| 2234 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2235 | static SDValue LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps, |
| 2236 | SDLoc DL, SelectionDAG &DAG) { |
| 2237 | const MachineFunction &MF = DAG.getMachineFunction(); |
| 2238 | const Function *F = MF.getFunction(); |
| 2239 | |
| 2240 | StringRef IntKind = F->getFnAttribute("interrupt").getValueAsString(); |
| 2241 | |
| 2242 | // See ARM ARM v7 B1.8.3. On exception entry LR is set to a possibly offset |
| 2243 | // version of the "preferred return address". These offsets affect the return |
| 2244 | // instruction if this is a return from PL1 without hypervisor extensions. |
| 2245 | // IRQ/FIQ: +4 "subs pc, lr, #4" |
| 2246 | // SWI: 0 "subs pc, lr, #0" |
| 2247 | // ABORT: +4 "subs pc, lr, #4" |
| 2248 | // UNDEF: +4/+2 "subs pc, lr, #0" |
| 2249 | // UNDEF varies depending on where the exception came from ARM or Thumb |
| 2250 | // mode. Alongside GCC, we throw our hands up in disgust and pretend it's 0. |
| 2251 | |
| 2252 | int64_t LROffset; |
| 2253 | if (IntKind == "" || IntKind == "IRQ" || IntKind == "FIQ" || |
| 2254 | IntKind == "ABORT") |
| 2255 | LROffset = 4; |
| 2256 | else if (IntKind == "SWI" || IntKind == "UNDEF") |
| 2257 | LROffset = 0; |
| 2258 | else |
| 2259 | report_fatal_error("Unsupported interrupt attribute. If present, value " |
| 2260 | "must be one of: IRQ, FIQ, SWI, ABORT or UNDEF"); |
| 2261 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2262 | RetOps.insert(RetOps.begin() + 1, |
| 2263 | DAG.getConstant(LROffset, DL, MVT::i32, false)); |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2264 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2265 | return DAG.getNode(ARMISD::INTRET_FLAG, DL, MVT::Other, RetOps); |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2266 | } |
| 2267 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2268 | SDValue |
| 2269 | ARMTargetLowering::LowerReturn(SDValue Chain, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2270 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2271 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2272 | const SmallVectorImpl<SDValue> &OutVals, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2273 | SDLoc dl, SelectionDAG &DAG) const { |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2274 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2275 | // CCValAssign - represent the assignment of the return value to a location. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2276 | SmallVector<CCValAssign, 16> RVLocs; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2277 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2278 | // CCState - Info about the registers and stack slots. |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2279 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 2280 | *DAG.getContext(), Call); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2281 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2282 | // Analyze outgoing return values. |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2283 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 2284 | isVarArg)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2285 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2286 | SDValue Flag; |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2287 | SmallVector<SDValue, 4> RetOps; |
| 2288 | RetOps.push_back(Chain); // Operand #0 = Chain (updated below) |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2289 | bool isLittleEndian = Subtarget->isLittle(); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2290 | |
| Jonathan Roelofs | ef84bda | 2014-08-05 21:32:21 +0000 | [diff] [blame] | 2291 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2292 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2293 | AFI->setReturnRegsCount(RVLocs.size()); |
| 2294 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2295 | // Copy the result values into the output registers. |
| 2296 | for (unsigned i = 0, realRVLocIdx = 0; |
| 2297 | i != RVLocs.size(); |
| 2298 | ++i, ++realRVLocIdx) { |
| 2299 | CCValAssign &VA = RVLocs[i]; |
| 2300 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 2301 | |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2302 | SDValue Arg = OutVals[realRVLocIdx]; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2303 | |
| 2304 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2305 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2306 | case CCValAssign::Full: break; |
| 2307 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2308 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2309 | break; |
| 2310 | } |
| 2311 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2312 | if (VA.needsCustom()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2313 | if (VA.getLocVT() == MVT::v2f64) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2314 | // Extract the first half and return it in two registers. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2315 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2316 | DAG.getConstant(0, dl, MVT::i32)); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2317 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2318 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2319 | |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2320 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2321 | HalfGPRs.getValue(isLittleEndian ? 0 : 1), |
| 2322 | Flag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2323 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2324 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2325 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2326 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2327 | HalfGPRs.getValue(isLittleEndian ? 1 : 0), |
| 2328 | Flag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2329 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2330 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2331 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2332 | |
| 2333 | // Extract the 2nd half and fall through to handle it as an f64 value. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2334 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2335 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2336 | } |
| 2337 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 2338 | // available. |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2339 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2340 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2341 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2342 | fmrrd.getValue(isLittleEndian ? 0 : 1), |
| 2343 | Flag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 2344 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2345 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2346 | VA = RVLocs[++i]; // skip ahead to next loc |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2347 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2348 | fmrrd.getValue(isLittleEndian ? 1 : 0), |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2349 | Flag); |
| 2350 | } else |
| 2351 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 2352 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2353 | // Guarantee that all emitted copies are |
| 2354 | // stuck together, avoiding something bad. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2355 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2356 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2357 | } |
| 2358 | |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2359 | // Update chain and glue. |
| 2360 | RetOps[0] = Chain; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2361 | if (Flag.getNode()) |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2362 | RetOps.push_back(Flag); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2363 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2364 | // CPUs which aren't M-class use a special sequence to return from |
| 2365 | // exceptions (roughly, any instruction setting pc and cpsr simultaneously, |
| 2366 | // though we use "subs pc, lr, #N"). |
| 2367 | // |
| 2368 | // M-class CPUs actually use a normal return sequence with a special |
| 2369 | // (hardware-provided) value in LR, so the normal code path works. |
| 2370 | if (DAG.getMachineFunction().getFunction()->hasFnAttribute("interrupt") && |
| 2371 | !Subtarget->isMClass()) { |
| 2372 | if (Subtarget->isThumb1Only()) |
| 2373 | report_fatal_error("interrupt attribute is not supported in Thumb1"); |
| 2374 | return LowerInterruptReturn(RetOps, dl, DAG); |
| 2375 | } |
| 2376 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2377 | return DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, RetOps); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2380 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2381 | if (N->getNumValues() != 1) |
| 2382 | return false; |
| 2383 | if (!N->hasNUsesOfValue(1, 0)) |
| 2384 | return false; |
| 2385 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2386 | SDValue TCChain = Chain; |
| 2387 | SDNode *Copy = *N->use_begin(); |
| 2388 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 2389 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2390 | // perform a tail call. |
| 2391 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2392 | return false; |
| 2393 | TCChain = Copy->getOperand(0); |
| 2394 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 2395 | SDNode *VMov = Copy; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2396 | // f64 returned in a pair of GPRs. |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2397 | SmallPtrSet<SDNode*, 2> Copies; |
| 2398 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2399 | UI != UE; ++UI) { |
| 2400 | if (UI->getOpcode() != ISD::CopyToReg) |
| 2401 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2402 | Copies.insert(*UI); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2403 | } |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2404 | if (Copies.size() > 2) |
| 2405 | return false; |
| 2406 | |
| 2407 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 2408 | UI != UE; ++UI) { |
| 2409 | SDValue UseChain = UI->getOperand(0); |
| 2410 | if (Copies.count(UseChain.getNode())) |
| 2411 | // Second CopyToReg |
| 2412 | Copy = *UI; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2413 | else { |
| 2414 | // We are at the top of this chain. |
| 2415 | // If the copy has a glue operand, we conservatively assume it |
| 2416 | // isn't safe to perform a tail call. |
| 2417 | if (UI->getOperand(UI->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2418 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2419 | // First CopyToReg |
| 2420 | TCChain = UseChain; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2421 | } |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2422 | } |
| 2423 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2424 | // f32 returned in a single GPR. |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2425 | if (!Copy->hasOneUse()) |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2426 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2427 | Copy = *Copy->use_begin(); |
| 2428 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2429 | return false; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2430 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2431 | // perform a tail call. |
| 2432 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2433 | return false; |
| Lang Hames | 67c09b3 | 2013-05-13 10:21:19 +0000 | [diff] [blame] | 2434 | TCChain = Copy->getOperand(0); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2435 | } else { |
| 2436 | return false; |
| 2437 | } |
| 2438 | |
| Evan Cheng | 419ea28 | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2439 | bool HasRet = false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2440 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 2441 | UI != UE; ++UI) { |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2442 | if (UI->getOpcode() != ARMISD::RET_FLAG && |
| 2443 | UI->getOpcode() != ARMISD::INTRET_FLAG) |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2444 | return false; |
| 2445 | HasRet = true; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2448 | if (!HasRet) |
| 2449 | return false; |
| 2450 | |
| 2451 | Chain = TCChain; |
| 2452 | return true; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2453 | } |
| 2454 | |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2455 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| Saleem Abdulrasool | b720a6b | 2014-03-11 15:09:49 +0000 | [diff] [blame] | 2456 | if (!Subtarget->supportsTailCall()) |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2457 | return false; |
| 2458 | |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 2459 | auto Attr = |
| 2460 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 2461 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2462 | return false; |
| 2463 | |
| Artyom Skrobov | ad8a063 | 2015-09-28 09:44:11 +0000 | [diff] [blame] | 2464 | return true; |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 2467 | // Trying to write a 64 bit value so need to split into two 32 bit values first, |
| 2468 | // and pass the lower and high parts through. |
| 2469 | static SDValue LowerWRITE_REGISTER(SDValue Op, SelectionDAG &DAG) { |
| 2470 | SDLoc DL(Op); |
| 2471 | SDValue WriteValue = Op->getOperand(2); |
| 2472 | |
| 2473 | // This function is only supposed to be called for i64 type argument. |
| 2474 | assert(WriteValue.getValueType() == MVT::i64 |
| 2475 | && "LowerWRITE_REGISTER called for non-i64 type argument."); |
| 2476 | |
| 2477 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, WriteValue, |
| 2478 | DAG.getConstant(0, DL, MVT::i32)); |
| 2479 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, WriteValue, |
| 2480 | DAG.getConstant(1, DL, MVT::i32)); |
| 2481 | SDValue Ops[] = { Op->getOperand(0), Op->getOperand(1), Lo, Hi }; |
| 2482 | return DAG.getNode(ISD::WRITE_REGISTER, DL, MVT::Other, Ops); |
| 2483 | } |
| 2484 | |
| Bob Wilson | b389f2a | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2485 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2486 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2487 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2488 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2489 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2490 | // into MOVi. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2491 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2492 | EVT PtrVT = Op.getValueType(); |
| Dale Johannesen | 62fd95d | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2493 | // FIXME there is no actual debug info here |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2494 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2495 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2496 | SDValue Res; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2497 | if (CP->isMachineConstantPoolEntry()) |
| 2498 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2499 | CP->getAlignment()); |
| 2500 | else |
| 2501 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2502 | CP->getAlignment()); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2503 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| Jim Grosbach | 8d3ba73 | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2506 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2507 | return MachineJumpTableInfo::EK_Inline; |
| 2508 | } |
| 2509 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2510 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2511 | SelectionDAG &DAG) const { |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2512 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2513 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2514 | unsigned ARMPCLabelIndex = 0; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2515 | SDLoc DL(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2516 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2517 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2518 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2519 | SDValue CPAddr; |
| 2520 | if (RelocM == Reloc::Static) { |
| 2521 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2522 | } else { |
| 2523 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2524 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2525 | ARMConstantPoolValue *CPV = |
| 2526 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2527 | ARMCP::CPBlockAddress, PCAdj); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2528 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2529 | } |
| 2530 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2531 | SDValue Result = |
| 2532 | DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
| 2533 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), |
| 2534 | false, false, false, 0); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2535 | if (RelocM == Reloc::Static) |
| 2536 | return Result; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2537 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, DL, MVT::i32); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2538 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2539 | } |
| 2540 | |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2541 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2542 | SDValue |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2543 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2544 | SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2545 | SDLoc dl(GA); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2546 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2547 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2548 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2549 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2550 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2551 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2552 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2553 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2554 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2555 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2556 | Argument = |
| 2557 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
| 2558 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), |
| 2559 | false, false, false, 0); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2560 | SDValue Chain = Argument.getValue(1); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2561 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2562 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2563 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2564 | |
| 2565 | // call __tls_get_addr. |
| 2566 | ArgListTy Args; |
| 2567 | ArgListEntry Entry; |
| 2568 | Entry.Node = Argument; |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2569 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2570 | Args.push_back(Entry); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2571 | |
| Dale Johannesen | 555a375 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2572 | // FIXME: is there useful debug info available here? |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2573 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 2574 | CLI.setDebugLoc(dl).setChain(Chain) |
| 2575 | .setCallee(CallingConv::C, Type::getInt32Ty(*DAG.getContext()), |
| Juergen Ributzka | 3bd03c7 | 2014-07-01 22:01:54 +0000 | [diff] [blame] | 2576 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), std::move(Args), |
| 2577 | 0); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2578 | |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2579 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2580 | return CallResult.first; |
| 2581 | } |
| 2582 | |
| 2583 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2584 | // "local exec" model. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2585 | SDValue |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2586 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2587 | SelectionDAG &DAG, |
| 2588 | TLSModel::Model model) const { |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2589 | const GlobalValue *GV = GA->getGlobal(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2590 | SDLoc dl(GA); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2591 | SDValue Offset; |
| 2592 | SDValue Chain = DAG.getEntryNode(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2593 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2594 | // Get the Thread Pointer |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2595 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2596 | |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2597 | if (model == TLSModel::InitialExec) { |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2598 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2599 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2600 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2601 | // Initial exec model. |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2602 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2603 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2604 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2605 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2606 | true); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2607 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2608 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2609 | Offset = DAG.getLoad( |
| 2610 | PtrVT, dl, Chain, Offset, |
| 2611 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2612 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2613 | Chain = Offset.getValue(1); |
| 2614 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2615 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2616 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2617 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2618 | Offset = DAG.getLoad( |
| 2619 | PtrVT, dl, Chain, Offset, |
| 2620 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2621 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2622 | } else { |
| 2623 | // local exec model |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2624 | assert(model == TLSModel::LocalExec); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2625 | ARMConstantPoolValue *CPV = |
| 2626 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2627 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2628 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2629 | Offset = DAG.getLoad( |
| 2630 | PtrVT, dl, Chain, Offset, |
| 2631 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2632 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | // The address of the thread local variable is the add of the thread |
| 2636 | // pointer with the offset of the variable. |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2637 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2640 | SDValue |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2641 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2642 | // TODO: implement the "local dynamic" model |
| 2643 | assert(Subtarget->isTargetELF() && |
| 2644 | "TLS not implemented for non-ELF targets"); |
| 2645 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| Chih-Hung Hsieh | 1e85958 | 2015-07-28 16:24:05 +0000 | [diff] [blame] | 2646 | if (DAG.getTarget().Options.EmulatedTLS) |
| 2647 | return LowerToTLSEmulatedModel(GA, DAG); |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2648 | |
| 2649 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2650 | |
| 2651 | switch (model) { |
| 2652 | case TLSModel::GeneralDynamic: |
| 2653 | case TLSModel::LocalDynamic: |
| 2654 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2655 | case TLSModel::InitialExec: |
| 2656 | case TLSModel::LocalExec: |
| 2657 | return LowerToTLSExecModels(GA, DAG, model); |
| 2658 | } |
| Matt Beaumont-Gay | e82ab6b | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2659 | llvm_unreachable("bogus TLS model"); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2660 | } |
| 2661 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2662 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2663 | SelectionDAG &DAG) const { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2664 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2665 | SDLoc dl(Op); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2666 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2667 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2668 | bool UseGOT_PREL = |
| Peter Collingbourne | 99fac80 | 2015-10-26 20:46:44 +0000 | [diff] [blame] | 2669 | !(GV->hasHiddenVisibility() || GV->hasLocalLinkage()); |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2670 | |
| 2671 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2672 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2673 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| 2674 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 2675 | SDLoc dl(Op); |
| 2676 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2677 | ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create( |
| 2678 | GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj, |
| 2679 | UseGOT_PREL ? ARMCP::GOT_PREL : ARMCP::no_modifier, |
| 2680 | /*AddCurrentAddress=*/UseGOT_PREL); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2681 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2682 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2683 | SDValue Result = DAG.getLoad( |
| 2684 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2685 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2686 | false, false, 0); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2687 | SDValue Chain = Result.getValue(1); |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2688 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| 2689 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2690 | if (UseGOT_PREL) |
| Anton Korobeynikov | 75b59fb | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2691 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2692 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2693 | false, false, false, 0); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2694 | return Result; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| James Molloy | dd9137a | 2011-10-26 08:53:19 +0000 | [diff] [blame] | 2698 | // pair. This is always cheaper. |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2699 | if (Subtarget->useMovt(DAG.getMachineFunction())) { |
| Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2700 | ++NumMovwMovt; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2701 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2702 | // operands, expand this into two nodes. |
| 2703 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2704 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2705 | } else { |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2706 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2707 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2708 | return DAG.getLoad( |
| 2709 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2710 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2711 | false, false, 0); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2712 | } |
| 2713 | } |
| 2714 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2715 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2716 | SelectionDAG &DAG) const { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2717 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2718 | SDLoc dl(Op); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2719 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2720 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2721 | |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2722 | if (Subtarget->useMovt(DAG.getMachineFunction())) |
| Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2723 | ++NumMovwMovt; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2724 | |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2725 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2726 | // operands, expand this into multiple nodes |
| 2727 | unsigned Wrapper = |
| 2728 | RelocM == Reloc::PIC_ ? ARMISD::WrapperPIC : ARMISD::Wrapper; |
| Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 2729 | |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2730 | SDValue G = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, ARMII::MO_NONLAZY); |
| 2731 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, G); |
| Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2732 | |
| Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2733 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2734 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2735 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 2736 | false, false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2737 | return Result; |
| 2738 | } |
| 2739 | |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2740 | SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op, |
| 2741 | SelectionDAG &DAG) const { |
| 2742 | assert(Subtarget->isTargetWindows() && "non-Windows COFF is not supported"); |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2743 | assert(Subtarget->useMovt(DAG.getMachineFunction()) && |
| 2744 | "Windows on ARM expects to use movw/movt"); |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2745 | |
| 2746 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 2747 | const ARMII::TOF TargetFlags = |
| 2748 | (GV->hasDLLImportStorageClass() ? ARMII::MO_DLLIMPORT : ARMII::MO_NO_FLAG); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2749 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2750 | SDValue Result; |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2751 | SDLoc DL(Op); |
| 2752 | |
| 2753 | ++NumMovwMovt; |
| 2754 | |
| 2755 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2756 | // operands, expand this into two nodes. |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2757 | Result = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, |
| 2758 | DAG.getTargetGlobalAddress(GV, DL, PtrVT, /*Offset=*/0, |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 2759 | TargetFlags)); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2760 | if (GV->hasDLLImportStorageClass()) |
| 2761 | Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2762 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 2763 | false, false, false, 0); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2764 | return Result; |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2765 | } |
| 2766 | |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2767 | SDValue |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2768 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2769 | SDLoc dl(Op); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2770 | SDValue Val = DAG.getConstant(0, dl, MVT::i32); |
| Bill Wendling | 7ecfbd9 | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2771 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2772 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2773 | Op.getOperand(1), Val); |
| 2774 | } |
| 2775 | |
| 2776 | SDValue |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2777 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2778 | SDLoc dl(Op); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2779 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2780 | Op.getOperand(1), DAG.getConstant(0, dl, MVT::i32)); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2781 | } |
| 2782 | |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 2783 | SDValue ARMTargetLowering::LowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, |
| 2784 | SelectionDAG &DAG) const { |
| 2785 | SDLoc dl(Op); |
| 2786 | return DAG.getNode(ARMISD::EH_SJLJ_SETUP_DISPATCH, dl, MVT::Other, |
| 2787 | Op.getOperand(0)); |
| 2788 | } |
| 2789 | |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2790 | SDValue |
| Jim Grosbach | a570d05 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2791 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
| Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2792 | const ARMSubtarget *Subtarget) const { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2793 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2794 | SDLoc dl(Op); |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2795 | switch (IntNo) { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2796 | default: return SDValue(); // Don't custom lower most intrinsics. |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2797 | case Intrinsic::arm_rbit: { |
| Yi Kong | c655f0c | 2014-08-20 10:40:20 +0000 | [diff] [blame] | 2798 | assert(Op.getOperand(1).getValueType() == MVT::i32 && |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2799 | "RBIT intrinsic must have i32 type!"); |
| Yi Kong | c655f0c | 2014-08-20 10:40:20 +0000 | [diff] [blame] | 2800 | return DAG.getNode(ARMISD::RBIT, dl, MVT::i32, Op.getOperand(1)); |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2801 | } |
| Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2802 | case Intrinsic::arm_thread_pointer: { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2803 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2804 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2805 | } |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2806 | case Intrinsic::eh_sjlj_lsda: { |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2807 | MachineFunction &MF = DAG.getMachineFunction(); |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2808 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2809 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2810 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2811 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2812 | SDValue CPAddr; |
| 2813 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2814 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2815 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2816 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2817 | ARMCP::CPLSDA, PCAdj); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2818 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2819 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2820 | SDValue Result = DAG.getLoad( |
| 2821 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2822 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2823 | false, false, 0); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2824 | |
| 2825 | if (RelocM == Reloc::PIC_) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2826 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2827 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2828 | } |
| 2829 | return Result; |
| 2830 | } |
| Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2831 | case Intrinsic::arm_neon_vmulls: |
| 2832 | case Intrinsic::arm_neon_vmullu: { |
| 2833 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2834 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2835 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2836 | Op.getOperand(1), Op.getOperand(2)); |
| 2837 | } |
| James Molloy | ee868b2 | 2015-08-11 12:06:25 +0000 | [diff] [blame] | 2838 | case Intrinsic::arm_neon_vminnm: |
| 2839 | case Intrinsic::arm_neon_vmaxnm: { |
| 2840 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vminnm) |
| 2841 | ? ISD::FMINNUM : ISD::FMAXNUM; |
| 2842 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2843 | Op.getOperand(1), Op.getOperand(2)); |
| 2844 | } |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 2845 | case Intrinsic::arm_neon_vminu: |
| 2846 | case Intrinsic::arm_neon_vmaxu: { |
| 2847 | if (Op.getValueType().isFloatingPoint()) |
| 2848 | return SDValue(); |
| 2849 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vminu) |
| 2850 | ? ISD::UMIN : ISD::UMAX; |
| 2851 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2852 | Op.getOperand(1), Op.getOperand(2)); |
| 2853 | } |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 2854 | case Intrinsic::arm_neon_vmins: |
| 2855 | case Intrinsic::arm_neon_vmaxs: { |
| 2856 | // v{min,max}s is overloaded between signed integers and floats. |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 2857 | if (!Op.getValueType().isFloatingPoint()) { |
| 2858 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmins) |
| 2859 | ? ISD::SMIN : ISD::SMAX; |
| 2860 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2861 | Op.getOperand(1), Op.getOperand(2)); |
| 2862 | } |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 2863 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmins) |
| 2864 | ? ISD::FMINNAN : ISD::FMAXNAN; |
| 2865 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2866 | Op.getOperand(1), Op.getOperand(2)); |
| 2867 | } |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2868 | } |
| 2869 | } |
| 2870 | |
| Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2871 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2872 | const ARMSubtarget *Subtarget) { |
| 2873 | // FIXME: handle "fence singlethread" more efficiently. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2874 | SDLoc dl(Op); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2875 | if (!Subtarget->hasDataBarrier()) { |
| 2876 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2877 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2878 | // here. |
| 2879 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 2880 | "Unexpected ISD::ATOMIC_FENCE encountered. Should be libcall!"); |
| Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2881 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2882 | DAG.getConstant(0, dl, MVT::i32)); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2883 | } |
| 2884 | |
| Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 2885 | ConstantSDNode *OrdN = cast<ConstantSDNode>(Op.getOperand(1)); |
| 2886 | AtomicOrdering Ord = static_cast<AtomicOrdering>(OrdN->getZExtValue()); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 2887 | ARM_MB::MemBOpt Domain = ARM_MB::ISH; |
| Tim Northover | f576988 | 2013-08-28 14:39:19 +0000 | [diff] [blame] | 2888 | if (Subtarget->isMClass()) { |
| 2889 | // Only a full system barrier exists in the M-class architectures. |
| 2890 | Domain = ARM_MB::SY; |
| 2891 | } else if (Subtarget->isSwift() && Ord == Release) { |
| Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 2892 | // Swift happens to implement ISHST barriers in a way that's compatible with |
| 2893 | // Release semantics but weaker than ISH so we'd be fools not to use |
| 2894 | // it. Beware: other processors probably don't! |
| 2895 | Domain = ARM_MB::ISHST; |
| 2896 | } |
| 2897 | |
| Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 2898 | return DAG.getNode(ISD::INTRINSIC_VOID, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2899 | DAG.getConstant(Intrinsic::arm_dmb, dl, MVT::i32), |
| 2900 | DAG.getConstant(Domain, dl, MVT::i32)); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2901 | } |
| 2902 | |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2903 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2904 | const ARMSubtarget *Subtarget) { |
| 2905 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2906 | if (!(Subtarget->isThumb2() || |
| 2907 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2908 | // Just preserve the chain. |
| 2909 | return Op.getOperand(0); |
| 2910 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2911 | SDLoc dl(Op); |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2912 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2913 | if (!isRead && |
| 2914 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2915 | // ARMv7 with MP extension has PLDW. |
| 2916 | return Op.getOperand(0); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2917 | |
| Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2918 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2919 | if (Subtarget->isThumb()) { |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2920 | // Invert the bits. |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2921 | isRead = ~isRead & 1; |
| Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2922 | isData = ~isData & 1; |
| 2923 | } |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2924 | |
| 2925 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2926 | Op.getOperand(1), DAG.getConstant(isRead, dl, MVT::i32), |
| 2927 | DAG.getConstant(isData, dl, MVT::i32)); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2928 | } |
| 2929 | |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2930 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2931 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2932 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2933 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2934 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2935 | // memory location argument. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2936 | SDLoc dl(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2937 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2938 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2939 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
| Chris Lattner | 886250c | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2940 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2941 | MachinePointerInfo(SV), false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2944 | SDValue |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2945 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2946 | SDValue &Root, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2947 | SDLoc dl) const { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2948 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2949 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2950 | |
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 2951 | const TargetRegisterClass *RC; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2952 | if (AFI->isThumb1OnlyFunction()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2953 | RC = &ARM::tGPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2954 | else |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 2955 | RC = &ARM::GPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2956 | |
| 2957 | // Transform the arguments stored in physical registers into virtual ones. |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2958 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2959 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2960 | |
| 2961 | SDValue ArgValue2; |
| 2962 | if (NextVA.isMemLoc()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2963 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2964 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2965 | |
| 2966 | // Create load node to retrieve arguments from the stack. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2967 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2968 | ArgValue2 = DAG.getLoad( |
| 2969 | MVT::i32, dl, Root, FIN, |
| 2970 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), false, |
| 2971 | false, false, 0); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2972 | } else { |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2973 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2974 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2975 | } |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2976 | if (!Subtarget->isLittle()) |
| 2977 | std::swap (ArgValue, ArgValue2); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2978 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2981 | // The remaining GPRs hold either the beginning of variable-argument |
| David Peixotto | 4299cf8 | 2013-02-13 00:36:35 +0000 | [diff] [blame] | 2982 | // data, or the beginning of an aggregate passed by value (usually |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2983 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2984 | // provided by our caller, and store the unallocated registers there. |
| 2985 | // If this is a variadic function, the va_list pointer will begin with |
| 2986 | // these values; otherwise, this reassembles a (byval) structure that |
| 2987 | // was split between registers and memory. |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2988 | // Return: The frame index registers were stored into. |
| 2989 | int |
| 2990 | ARMTargetLowering::StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2991 | SDLoc dl, SDValue &Chain, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2992 | const Value *OrigArg, |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 2993 | unsigned InRegsParamRecordIdx, |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 2994 | int ArgOffset, |
| 2995 | unsigned ArgSize) const { |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2996 | // Currently, two use-cases possible: |
| Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 2997 | // Case #1. Non-var-args function, and we meet first byval parameter. |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2998 | // Setup first unallocated register as first byval register; |
| 2999 | // eat all remained registers |
| 3000 | // (these two actions are performed by HandleByVal method). |
| 3001 | // Then, here, we initialize stack frame with |
| 3002 | // "store-reg" instructions. |
| 3003 | // Case #2. Var-args function, that doesn't contain byval parameters. |
| 3004 | // The same: eat all remained unallocated registers, |
| 3005 | // initialize stack frame. |
| 3006 | |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3007 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3008 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3009 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3010 | unsigned RBegin, REnd; |
| 3011 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { |
| 3012 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3013 | } else { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3014 | unsigned RBeginIdx = CCInfo.getFirstUnallocated(GPRArgRegs); |
| Aaron Ballman | c579d66 | 2015-03-12 13:24:06 +0000 | [diff] [blame] | 3015 | RBegin = RBeginIdx == 4 ? (unsigned)ARM::R4 : GPRArgRegs[RBeginIdx]; |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3016 | REnd = ARM::R4; |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3019 | if (REnd != RBegin) |
| 3020 | ArgOffset = -4 * (ARM::R4 - RBegin); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3021 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3022 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3023 | int FrameIndex = MFI->CreateFixedObject(ArgSize, ArgOffset, false); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3024 | SDValue FIN = DAG.getFrameIndex(FrameIndex, PtrVT); |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3025 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3026 | SmallVector<SDValue, 4> MemOps; |
| 3027 | const TargetRegisterClass *RC = |
| 3028 | AFI->isThumb1OnlyFunction() ? &ARM::tGPRRegClass : &ARM::GPRRegClass; |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3029 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3030 | for (unsigned Reg = RBegin, i = 0; Reg < REnd; ++Reg, ++i) { |
| 3031 | unsigned VReg = MF.addLiveIn(Reg, RC); |
| 3032 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 3033 | SDValue Store = |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3034 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3035 | MachinePointerInfo(OrigArg, 4 * i), false, false, 0); |
| 3036 | MemOps.push_back(Store); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3037 | FIN = DAG.getNode(ISD::ADD, dl, PtrVT, FIN, DAG.getConstant(4, dl, PtrVT)); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3038 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3039 | |
| 3040 | if (!MemOps.empty()) |
| 3041 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
| 3042 | return FrameIndex; |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3043 | } |
| 3044 | |
| 3045 | // Setup stack frame, the va_list pointer will start from. |
| 3046 | void |
| 3047 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3048 | SDLoc dl, SDValue &Chain, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3049 | unsigned ArgOffset, |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3050 | unsigned TotalArgRegsSaveSize, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3051 | bool ForceMutable) const { |
| 3052 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3053 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 3054 | |
| 3055 | // Try to store any remaining integer argument regs |
| 3056 | // to their spots on the stack so that they may be loaded by deferencing |
| 3057 | // the result of va_next. |
| 3058 | // If there is no regs to be stored, just point address after last |
| 3059 | // argument passed via stack. |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3060 | int FrameIndex = StoreByValRegs(CCInfo, DAG, dl, Chain, nullptr, |
| 3061 | CCInfo.getInRegsParamsCount(), |
| 3062 | CCInfo.getNextStackOffset(), 4); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3063 | AFI->setVarArgsFrameIndex(FrameIndex); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3064 | } |
| 3065 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3066 | SDValue |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3067 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 3068 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3069 | const SmallVectorImpl<ISD::InputArg> |
| 3070 | &Ins, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3071 | SDLoc dl, SelectionDAG &DAG, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3072 | SmallVectorImpl<SDValue> &InVals) |
| 3073 | const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3074 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3075 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3076 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3077 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 3078 | |
| 3079 | // Assign locations to all of the incoming arguments. |
| 3080 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 3081 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 3082 | *DAG.getContext(), Prologue); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3083 | CCInfo.AnalyzeFormalArguments(Ins, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 3084 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 3085 | isVarArg)); |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 3086 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3087 | SmallVector<SDValue, 16> ArgValues; |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3088 | SDValue ArgValue; |
| Stepan Dyatkovskiy | f13dbb8 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 3089 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
| 3090 | unsigned CurArgIdx = 0; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3091 | |
| 3092 | // Initially ArgRegsSaveSize is zero. |
| 3093 | // Then we increase this value each time we meet byval parameter. |
| 3094 | // We also increase this value in case of varargs function. |
| 3095 | AFI->setArgRegsSaveSize(0); |
| 3096 | |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3097 | // Calculate the amount of stack space that we need to allocate to store |
| 3098 | // byval and variadic arguments that are passed in registers. |
| 3099 | // We need to know this before we allocate the first byval or variadic |
| 3100 | // argument, as they will be allocated a stack slot below the CFA (Canonical |
| 3101 | // Frame Address, the stack pointer at entry to the function). |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3102 | unsigned ArgRegBegin = ARM::R4; |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3103 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3104 | if (CCInfo.getInRegsParamsProcessed() >= CCInfo.getInRegsParamsCount()) |
| 3105 | break; |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3106 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3107 | CCValAssign &VA = ArgLocs[i]; |
| 3108 | unsigned Index = VA.getValNo(); |
| 3109 | ISD::ArgFlagsTy Flags = Ins[Index].Flags; |
| 3110 | if (!Flags.isByVal()) |
| 3111 | continue; |
| 3112 | |
| 3113 | assert(VA.isMemLoc() && "unexpected byval pointer in reg"); |
| 3114 | unsigned RBegin, REnd; |
| 3115 | CCInfo.getInRegsParamInfo(CCInfo.getInRegsParamsProcessed(), RBegin, REnd); |
| 3116 | ArgRegBegin = std::min(ArgRegBegin, RBegin); |
| 3117 | |
| 3118 | CCInfo.nextInRegsParam(); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3119 | } |
| 3120 | CCInfo.rewindByValRegsInfo(); |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3121 | |
| 3122 | int lastInsIndex = -1; |
| Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 3123 | if (isVarArg && MFI->hasVAStart()) { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3124 | unsigned RegIdx = CCInfo.getFirstUnallocated(GPRArgRegs); |
| 3125 | if (RegIdx != array_lengthof(GPRArgRegs)) |
| 3126 | ArgRegBegin = std::min(ArgRegBegin, (unsigned)GPRArgRegs[RegIdx]); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3127 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3128 | |
| 3129 | unsigned TotalArgRegsSaveSize = 4 * (ARM::R4 - ArgRegBegin); |
| 3130 | AFI->setArgRegsSaveSize(TotalArgRegsSaveSize); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3131 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3132 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3133 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 3134 | CCValAssign &VA = ArgLocs[i]; |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3135 | if (Ins[VA.getValNo()].isOrigArg()) { |
| 3136 | std::advance(CurOrigArg, |
| 3137 | Ins[VA.getValNo()].getOrigArgIndex() - CurArgIdx); |
| 3138 | CurArgIdx = Ins[VA.getValNo()].getOrigArgIndex(); |
| 3139 | } |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 3140 | // Arguments stored in registers. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3141 | if (VA.isRegLoc()) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3142 | EVT RegVT = VA.getLocVT(); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3143 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3144 | if (VA.needsCustom()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3145 | // f64 and vector types are split up into multiple registers or |
| 3146 | // combinations of registers and stack slots. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3147 | if (VA.getLocVT() == MVT::v2f64) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3148 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3149 | Chain, DAG, dl); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3150 | VA = ArgLocs[++i]; // skip ahead to next loc |
| Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 3151 | SDValue ArgValue2; |
| 3152 | if (VA.isMemLoc()) { |
| Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 3153 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3154 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3155 | ArgValue2 = DAG.getLoad( |
| 3156 | MVT::f64, dl, Chain, FIN, |
| 3157 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), |
| 3158 | false, false, false, 0); |
| Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 3159 | } else { |
| 3160 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 3161 | Chain, DAG, dl); |
| 3162 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3163 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 3164 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3165 | ArgValue, ArgValue1, |
| 3166 | DAG.getIntPtrConstant(0, dl)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3167 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3168 | ArgValue, ArgValue2, |
| 3169 | DAG.getIntPtrConstant(1, dl)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3170 | } else |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3171 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3172 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3173 | } else { |
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 3174 | const TargetRegisterClass *RC; |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 3175 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3176 | if (RegVT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3177 | RC = &ARM::SPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3178 | else if (RegVT == MVT::f64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3179 | RC = &ARM::DPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3180 | else if (RegVT == MVT::v2f64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3181 | RC = &ARM::QPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3182 | else if (RegVT == MVT::i32) |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 3183 | RC = AFI->isThumb1OnlyFunction() ? &ARM::tGPRRegClass |
| 3184 | : &ARM::GPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3185 | else |
| Anton Korobeynikov | ef98dbe | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 3186 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3187 | |
| 3188 | // Transform the arguments in physical registers into virtual ones. |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3189 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3190 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3191 | } |
| 3192 | |
| 3193 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 3194 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 3195 | // truncate to the right size. |
| 3196 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3197 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3198 | case CCValAssign::Full: break; |
| 3199 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3200 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3201 | break; |
| 3202 | case CCValAssign::SExt: |
| 3203 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 3204 | DAG.getValueType(VA.getValVT())); |
| 3205 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 3206 | break; |
| 3207 | case CCValAssign::ZExt: |
| 3208 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 3209 | DAG.getValueType(VA.getValVT())); |
| 3210 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 3211 | break; |
| 3212 | } |
| 3213 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3214 | InVals.push_back(ArgValue); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3215 | |
| 3216 | } else { // VA.isRegLoc() |
| 3217 | |
| 3218 | // sanity check |
| 3219 | assert(VA.isMemLoc()); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3220 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3221 | |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3222 | int index = VA.getValNo(); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3223 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3224 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 3225 | // Process them only once. |
| 3226 | if (index != lastInsIndex) |
| 3227 | { |
| 3228 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 3229 | // FIXME: For now, all byval parameter objects are marked mutable. |
| Eric Christopher | e02e07c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 3230 | // This can be changed with more analysis. |
| 3231 | // In case of tail call optimization mark all arguments mutable. |
| 3232 | // Since they could be overwritten by lowering of arguments in case of |
| 3233 | // a tail call. |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3234 | if (Flags.isByVal()) { |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3235 | assert(Ins[index].isOrigArg() && |
| 3236 | "Byval arguments cannot be implicit"); |
| Daniel Sanders | 8104b75 | 2014-11-01 19:32:23 +0000 | [diff] [blame] | 3237 | unsigned CurByValIndex = CCInfo.getInRegsParamsProcessed(); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3238 | |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 3239 | int FrameIndex = StoreByValRegs( |
| 3240 | CCInfo, DAG, dl, Chain, &*CurOrigArg, CurByValIndex, |
| 3241 | VA.getLocMemOffset(), Flags.getByValSize()); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3242 | InVals.push_back(DAG.getFrameIndex(FrameIndex, PtrVT)); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3243 | CCInfo.nextInRegsParam(); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3244 | } else { |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3245 | unsigned FIOffset = VA.getLocMemOffset(); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3246 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3247 | FIOffset, true); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3248 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3249 | // Create load nodes to retrieve arguments from the stack. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3250 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3251 | InVals.push_back(DAG.getLoad( |
| 3252 | VA.getValVT(), dl, Chain, FIN, |
| 3253 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), |
| 3254 | false, false, false, 0)); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3255 | } |
| 3256 | lastInsIndex = index; |
| 3257 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3258 | } |
| 3259 | } |
| 3260 | |
| 3261 | // varargs |
| Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 3262 | if (isVarArg && MFI->hasVAStart()) |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3263 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3264 | CCInfo.getNextStackOffset(), |
| 3265 | TotalArgRegsSaveSize); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3266 | |
| Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 3267 | AFI->setArgumentStackSize(CCInfo.getNextStackOffset()); |
| 3268 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3269 | return Chain; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3270 | } |
| 3271 | |
| 3272 | /// isFloatingPointZero - Return true if this is +0.0. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3273 | static bool isFloatingPointZero(SDValue Op) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3274 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3275 | return CFP->getValueAPF().isPosZero(); |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3276 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3277 | // Maybe this has already been legalized into the constant pool? |
| 3278 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3279 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3280 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 3281 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3282 | return CFP->getValueAPF().isPosZero(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3283 | } |
| Renato Golin | 6fb9c2e | 2014-10-23 15:31:50 +0000 | [diff] [blame] | 3284 | } else if (Op->getOpcode() == ISD::BITCAST && |
| 3285 | Op->getValueType(0) == MVT::f64) { |
| 3286 | // Handle (ISD::BITCAST (ARMISD::VMOVIMM (ISD::TargetConstant 0)) MVT::f64) |
| 3287 | // created by LowerConstantFP(). |
| 3288 | SDValue BitcastOp = Op->getOperand(0); |
| 3289 | if (BitcastOp->getOpcode() == ARMISD::VMOVIMM) { |
| 3290 | SDValue MoveOp = BitcastOp->getOperand(0); |
| 3291 | if (MoveOp->getOpcode() == ISD::TargetConstant && |
| 3292 | cast<ConstantSDNode>(MoveOp)->getZExtValue() == 0) { |
| 3293 | return true; |
| 3294 | } |
| 3295 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3296 | } |
| 3297 | return false; |
| 3298 | } |
| 3299 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3300 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 3301 | /// the given operands. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3302 | SDValue |
| 3303 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3304 | SDValue &ARMcc, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3305 | SDLoc dl) const { |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3306 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3307 | unsigned C = RHSC->getZExtValue(); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3308 | if (!isLegalICmpImmediate(C)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3309 | // Constant does not fit, try adjusting it by one? |
| 3310 | switch (CC) { |
| 3311 | default: break; |
| 3312 | case ISD::SETLT: |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3313 | case ISD::SETGE: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3314 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3315 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3316 | RHS = DAG.getConstant(C - 1, dl, MVT::i32); |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3317 | } |
| 3318 | break; |
| 3319 | case ISD::SETULT: |
| 3320 | case ISD::SETUGE: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3321 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3322 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3323 | RHS = DAG.getConstant(C - 1, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3324 | } |
| 3325 | break; |
| 3326 | case ISD::SETLE: |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3327 | case ISD::SETGT: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3328 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3329 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3330 | RHS = DAG.getConstant(C + 1, dl, MVT::i32); |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3331 | } |
| 3332 | break; |
| 3333 | case ISD::SETULE: |
| 3334 | case ISD::SETUGT: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3335 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3336 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3337 | RHS = DAG.getConstant(C + 1, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3338 | } |
| 3339 | break; |
| 3340 | } |
| 3341 | } |
| 3342 | } |
| 3343 | |
| 3344 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3345 | ARMISD::NodeType CompareType; |
| 3346 | switch (CondCode) { |
| 3347 | default: |
| 3348 | CompareType = ARMISD::CMP; |
| 3349 | break; |
| 3350 | case ARMCC::EQ: |
| 3351 | case ARMCC::NE: |
| David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 3352 | // Uses only Z Flag |
| 3353 | CompareType = ARMISD::CMPZ; |
| Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3354 | break; |
| 3355 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3356 | ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3357 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. |
| Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3361 | SDValue |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3362 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3363 | SDLoc dl) const { |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3364 | assert(!Subtarget->isFPOnlySP() || RHS.getValueType() != MVT::f64); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3365 | SDValue Cmp; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3366 | if (!isFloatingPointZero(RHS)) |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3367 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3368 | else |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3369 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 3370 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3371 | } |
| 3372 | |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3373 | /// duplicateCmp - Glue values can have only one use, so this function |
| 3374 | /// duplicates a comparison node. |
| 3375 | SDValue |
| 3376 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 3377 | unsigned Opc = Cmp.getOpcode(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3378 | SDLoc DL(Cmp); |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3379 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 3380 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3381 | |
| 3382 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 3383 | Cmp = Cmp.getOperand(0); |
| 3384 | Opc = Cmp.getOpcode(); |
| 3385 | if (Opc == ARMISD::CMPFP) |
| 3386 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3387 | else { |
| 3388 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 3389 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 3390 | } |
| 3391 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 3392 | } |
| 3393 | |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3394 | std::pair<SDValue, SDValue> |
| 3395 | ARMTargetLowering::getARMXALUOOp(SDValue Op, SelectionDAG &DAG, |
| 3396 | SDValue &ARMcc) const { |
| 3397 | assert(Op.getValueType() == MVT::i32 && "Unsupported value type"); |
| 3398 | |
| 3399 | SDValue Value, OverflowCmp; |
| 3400 | SDValue LHS = Op.getOperand(0); |
| 3401 | SDValue RHS = Op.getOperand(1); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3402 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3403 | |
| 3404 | // FIXME: We are currently always generating CMPs because we don't support |
| 3405 | // generating CMN through the backend. This is not as good as the natural |
| 3406 | // CMP case because it causes a register dependency and cannot be folded |
| 3407 | // later. |
| 3408 | |
| 3409 | switch (Op.getOpcode()) { |
| 3410 | default: |
| 3411 | llvm_unreachable("Unknown overflow instruction!"); |
| 3412 | case ISD::SADDO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3413 | ARMcc = DAG.getConstant(ARMCC::VC, dl, MVT::i32); |
| 3414 | Value = DAG.getNode(ISD::ADD, dl, Op.getValueType(), LHS, RHS); |
| 3415 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, Value, LHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3416 | break; |
| 3417 | case ISD::UADDO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3418 | ARMcc = DAG.getConstant(ARMCC::HS, dl, MVT::i32); |
| 3419 | Value = DAG.getNode(ISD::ADD, dl, Op.getValueType(), LHS, RHS); |
| 3420 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, Value, LHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3421 | break; |
| 3422 | case ISD::SSUBO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3423 | ARMcc = DAG.getConstant(ARMCC::VC, dl, MVT::i32); |
| 3424 | Value = DAG.getNode(ISD::SUB, dl, Op.getValueType(), LHS, RHS); |
| 3425 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, LHS, RHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3426 | break; |
| 3427 | case ISD::USUBO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3428 | ARMcc = DAG.getConstant(ARMCC::HS, dl, MVT::i32); |
| 3429 | Value = DAG.getNode(ISD::SUB, dl, Op.getValueType(), LHS, RHS); |
| 3430 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, LHS, RHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3431 | break; |
| 3432 | } // switch (...) |
| 3433 | |
| 3434 | return std::make_pair(Value, OverflowCmp); |
| 3435 | } |
| 3436 | |
| 3437 | |
| 3438 | SDValue |
| 3439 | ARMTargetLowering::LowerXALUO(SDValue Op, SelectionDAG &DAG) const { |
| 3440 | // Let legalize expand this if it isn't a legal type yet. |
| 3441 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Op.getValueType())) |
| 3442 | return SDValue(); |
| 3443 | |
| 3444 | SDValue Value, OverflowCmp; |
| 3445 | SDValue ARMcc; |
| 3446 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Op, DAG, ARMcc); |
| 3447 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3448 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3449 | // We use 0 and 1 as false and true values. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3450 | SDValue TVal = DAG.getConstant(1, dl, MVT::i32); |
| 3451 | SDValue FVal = DAG.getConstant(0, dl, MVT::i32); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3452 | EVT VT = Op.getValueType(); |
| 3453 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3454 | SDValue Overflow = DAG.getNode(ARMISD::CMOV, dl, VT, TVal, FVal, |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3455 | ARMcc, CCR, OverflowCmp); |
| 3456 | |
| 3457 | SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3458 | return DAG.getNode(ISD::MERGE_VALUES, dl, VTs, Value, Overflow); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3462 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 3463 | SDValue Cond = Op.getOperand(0); |
| 3464 | SDValue SelectTrue = Op.getOperand(1); |
| 3465 | SDValue SelectFalse = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3466 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3467 | unsigned Opc = Cond.getOpcode(); |
| 3468 | |
| 3469 | if (Cond.getResNo() == 1 && |
| 3470 | (Opc == ISD::SADDO || Opc == ISD::UADDO || Opc == ISD::SSUBO || |
| 3471 | Opc == ISD::USUBO)) { |
| 3472 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Cond->getValueType(0))) |
| 3473 | return SDValue(); |
| 3474 | |
| 3475 | SDValue Value, OverflowCmp; |
| 3476 | SDValue ARMcc; |
| 3477 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Cond, DAG, ARMcc); |
| 3478 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3479 | EVT VT = Op.getValueType(); |
| 3480 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3481 | return getCMOV(dl, VT, SelectTrue, SelectFalse, ARMcc, CCR, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3482 | OverflowCmp, DAG); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3483 | } |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3484 | |
| 3485 | // Convert: |
| 3486 | // |
| 3487 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 3488 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 3489 | // |
| 3490 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 3491 | const ConstantSDNode *CMOVTrue = |
| 3492 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 3493 | const ConstantSDNode *CMOVFalse = |
| 3494 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 3495 | |
| 3496 | if (CMOVTrue && CMOVFalse) { |
| 3497 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 3498 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 3499 | |
| 3500 | SDValue True; |
| 3501 | SDValue False; |
| 3502 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 3503 | True = SelectTrue; |
| 3504 | False = SelectFalse; |
| 3505 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 3506 | True = SelectFalse; |
| 3507 | False = SelectTrue; |
| 3508 | } |
| 3509 | |
| 3510 | if (True.getNode() && False.getNode()) { |
| Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3511 | EVT VT = Op.getValueType(); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3512 | SDValue ARMcc = Cond.getOperand(2); |
| 3513 | SDValue CCR = Cond.getOperand(3); |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3514 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
| Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3515 | assert(True.getValueType() == VT); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3516 | return getCMOV(dl, VT, True, False, ARMcc, CCR, Cmp, DAG); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3517 | } |
| 3518 | } |
| 3519 | } |
| 3520 | |
| Dan Gohman | d4a77c4 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3521 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 3522 | // undefined bits before doing a full-word comparison with zero. |
| 3523 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3524 | DAG.getConstant(1, dl, Cond.getValueType())); |
| Dan Gohman | d4a77c4 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3525 | |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3526 | return DAG.getSelectCC(dl, Cond, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3527 | DAG.getConstant(0, dl, Cond.getValueType()), |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3528 | SelectTrue, SelectFalse, ISD::SETNE); |
| 3529 | } |
| 3530 | |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3531 | static void checkVSELConstraints(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
| 3532 | bool &swpCmpOps, bool &swpVselOps) { |
| 3533 | // Start by selecting the GE condition code for opcodes that return true for |
| 3534 | // 'equality' |
| 3535 | if (CC == ISD::SETUGE || CC == ISD::SETOGE || CC == ISD::SETOLE || |
| 3536 | CC == ISD::SETULE) |
| 3537 | CondCode = ARMCC::GE; |
| 3538 | |
| 3539 | // and GT for opcodes that return false for 'equality'. |
| 3540 | else if (CC == ISD::SETUGT || CC == ISD::SETOGT || CC == ISD::SETOLT || |
| 3541 | CC == ISD::SETULT) |
| 3542 | CondCode = ARMCC::GT; |
| 3543 | |
| 3544 | // Since we are constrained to GE/GT, if the opcode contains 'less', we need |
| 3545 | // to swap the compare operands. |
| 3546 | if (CC == ISD::SETOLE || CC == ISD::SETULE || CC == ISD::SETOLT || |
| 3547 | CC == ISD::SETULT) |
| 3548 | swpCmpOps = true; |
| 3549 | |
| 3550 | // Both GT and GE are ordered comparisons, and return false for 'unordered'. |
| 3551 | // If we have an unordered opcode, we need to swap the operands to the VSEL |
| 3552 | // instruction (effectively negating the condition). |
| 3553 | // |
| 3554 | // This also has the effect of swapping which one of 'less' or 'greater' |
| 3555 | // returns true, so we also swap the compare operands. It also switches |
| 3556 | // whether we return true for 'equality', so we compensate by picking the |
| 3557 | // opposite condition code to our original choice. |
| 3558 | if (CC == ISD::SETULE || CC == ISD::SETULT || CC == ISD::SETUGE || |
| 3559 | CC == ISD::SETUGT) { |
| 3560 | swpCmpOps = !swpCmpOps; |
| 3561 | swpVselOps = !swpVselOps; |
| 3562 | CondCode = CondCode == ARMCC::GT ? ARMCC::GE : ARMCC::GT; |
| 3563 | } |
| 3564 | |
| 3565 | // 'ordered' is 'anything but unordered', so use the VS condition code and |
| 3566 | // swap the VSEL operands. |
| 3567 | if (CC == ISD::SETO) { |
| 3568 | CondCode = ARMCC::VS; |
| 3569 | swpVselOps = true; |
| 3570 | } |
| 3571 | |
| 3572 | // 'unordered or not equal' is 'anything but equal', so use the EQ condition |
| 3573 | // code and swap the VSEL operands. |
| 3574 | if (CC == ISD::SETUNE) { |
| 3575 | CondCode = ARMCC::EQ; |
| 3576 | swpVselOps = true; |
| 3577 | } |
| 3578 | } |
| 3579 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3580 | SDValue ARMTargetLowering::getCMOV(SDLoc dl, EVT VT, SDValue FalseVal, |
| 3581 | SDValue TrueVal, SDValue ARMcc, SDValue CCR, |
| 3582 | SDValue Cmp, SelectionDAG &DAG) const { |
| 3583 | if (Subtarget->isFPOnlySP() && VT == MVT::f64) { |
| 3584 | FalseVal = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3585 | DAG.getVTList(MVT::i32, MVT::i32), FalseVal); |
| 3586 | TrueVal = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3587 | DAG.getVTList(MVT::i32, MVT::i32), TrueVal); |
| 3588 | |
| 3589 | SDValue TrueLow = TrueVal.getValue(0); |
| 3590 | SDValue TrueHigh = TrueVal.getValue(1); |
| 3591 | SDValue FalseLow = FalseVal.getValue(0); |
| 3592 | SDValue FalseHigh = FalseVal.getValue(1); |
| 3593 | |
| 3594 | SDValue Low = DAG.getNode(ARMISD::CMOV, dl, MVT::i32, FalseLow, TrueLow, |
| 3595 | ARMcc, CCR, Cmp); |
| 3596 | SDValue High = DAG.getNode(ARMISD::CMOV, dl, MVT::i32, FalseHigh, TrueHigh, |
| 3597 | ARMcc, CCR, duplicateCmp(Cmp, DAG)); |
| 3598 | |
| 3599 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Low, High); |
| 3600 | } else { |
| 3601 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR, |
| 3602 | Cmp); |
| 3603 | } |
| 3604 | } |
| 3605 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3606 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3607 | EVT VT = Op.getValueType(); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3608 | SDValue LHS = Op.getOperand(0); |
| 3609 | SDValue RHS = Op.getOperand(1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3610 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3611 | SDValue TrueVal = Op.getOperand(2); |
| 3612 | SDValue FalseVal = Op.getOperand(3); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3613 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3614 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3615 | if (Subtarget->isFPOnlySP() && LHS.getValueType() == MVT::f64) { |
| 3616 | DAG.getTargetLoweringInfo().softenSetCCOperands(DAG, MVT::f64, LHS, RHS, CC, |
| 3617 | dl); |
| 3618 | |
| 3619 | // If softenSetCCOperands only returned one value, we should compare it to |
| 3620 | // zero. |
| 3621 | if (!RHS.getNode()) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3622 | RHS = DAG.getConstant(0, dl, LHS.getValueType()); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3623 | CC = ISD::SETNE; |
| 3624 | } |
| 3625 | } |
| 3626 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3627 | if (LHS.getValueType() == MVT::i32) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3628 | // Try to generate VSEL on ARMv8. |
| 3629 | // The VSEL instruction can't use all the usual ARM condition |
| 3630 | // codes: it only has two bits to select the condition code, so it's |
| 3631 | // constrained to use only GE, GT, VS and EQ. |
| 3632 | // |
| 3633 | // To implement all the various ISD::SETXXX opcodes, we sometimes need to |
| 3634 | // swap the operands of the previous compare instruction (effectively |
| 3635 | // inverting the compare condition, swapping 'less' and 'greater') and |
| 3636 | // sometimes need to swap the operands to the VSEL (which inverts the |
| 3637 | // condition in the sense of firing whenever the previous condition didn't) |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 3638 | if (Subtarget->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
| 3639 | TrueVal.getValueType() == MVT::f64)) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3640 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3641 | if (CondCode == ARMCC::LT || CondCode == ARMCC::LE || |
| 3642 | CondCode == ARMCC::VC || CondCode == ARMCC::NE) { |
| Artyom Skrobov | 3f8eae9 | 2015-05-06 11:44:10 +0000 | [diff] [blame] | 3643 | CC = ISD::getSetCCInverse(CC, true); |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3644 | std::swap(TrueVal, FalseVal); |
| 3645 | } |
| 3646 | } |
| 3647 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3648 | SDValue ARMcc; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3649 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3650 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3651 | return getCMOV(dl, VT, FalseVal, TrueVal, ARMcc, CCR, Cmp, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3652 | } |
| 3653 | |
| 3654 | ARMCC::CondCodes CondCode, CondCode2; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3655 | FPCCToARMCC(CC, CondCode, CondCode2); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3656 | |
| Scott Douglass | 7ad7792 | 2015-04-08 17:18:28 +0000 | [diff] [blame] | 3657 | // Try to generate VMAXNM/VMINNM on ARMv8. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 3658 | if (Subtarget->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
| 3659 | TrueVal.getValueType() == MVT::f64)) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3660 | bool swpCmpOps = false; |
| 3661 | bool swpVselOps = false; |
| 3662 | checkVSELConstraints(CC, CondCode, swpCmpOps, swpVselOps); |
| 3663 | |
| 3664 | if (CondCode == ARMCC::GT || CondCode == ARMCC::GE || |
| 3665 | CondCode == ARMCC::VS || CondCode == ARMCC::EQ) { |
| 3666 | if (swpCmpOps) |
| 3667 | std::swap(LHS, RHS); |
| 3668 | if (swpVselOps) |
| 3669 | std::swap(TrueVal, FalseVal); |
| 3670 | } |
| 3671 | } |
| 3672 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3673 | SDValue ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3674 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3675 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3676 | SDValue Result = getCMOV(dl, VT, FalseVal, TrueVal, ARMcc, CCR, Cmp, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3677 | if (CondCode2 != ARMCC::AL) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3678 | SDValue ARMcc2 = DAG.getConstant(CondCode2, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3679 | // FIXME: Needs another CMP because flag can have but one use. |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3680 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3681 | Result = getCMOV(dl, VT, Result, TrueVal, ARMcc2, CCR, Cmp2, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3682 | } |
| 3683 | return Result; |
| 3684 | } |
| 3685 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3686 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 3687 | /// to morph to an integer compare sequence. |
| 3688 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 3689 | const ARMSubtarget *Subtarget) { |
| 3690 | SDNode *N = Op.getNode(); |
| 3691 | if (!N->hasOneUse()) |
| 3692 | // Otherwise it requires moving the value from fp to integer registers. |
| 3693 | return false; |
| 3694 | if (!N->getNumValues()) |
| 3695 | return false; |
| 3696 | EVT VT = Op.getValueType(); |
| 3697 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 3698 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 3699 | // vmrs are very slow, e.g. cortex-a8. |
| 3700 | return false; |
| 3701 | |
| 3702 | if (isFloatingPointZero(Op)) { |
| 3703 | SeenZero = true; |
| 3704 | return true; |
| 3705 | } |
| 3706 | return ISD::isNormalLoad(N); |
| 3707 | } |
| 3708 | |
| 3709 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 3710 | if (isFloatingPointZero(Op)) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3711 | return DAG.getConstant(0, SDLoc(Op), MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3712 | |
| 3713 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3714 | return DAG.getLoad(MVT::i32, SDLoc(Op), |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3715 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3716 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3717 | Ld->isInvariant(), Ld->getAlignment()); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3718 | |
| 3719 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3720 | } |
| 3721 | |
| 3722 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 3723 | SDValue &RetVal1, SDValue &RetVal2) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3724 | SDLoc dl(Op); |
| 3725 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3726 | if (isFloatingPointZero(Op)) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3727 | RetVal1 = DAG.getConstant(0, dl, MVT::i32); |
| 3728 | RetVal2 = DAG.getConstant(0, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3729 | return; |
| 3730 | } |
| 3731 | |
| 3732 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 3733 | SDValue Ptr = Ld->getBasePtr(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3734 | RetVal1 = DAG.getLoad(MVT::i32, dl, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3735 | Ld->getChain(), Ptr, |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3736 | Ld->getPointerInfo(), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3737 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3738 | Ld->isInvariant(), Ld->getAlignment()); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3739 | |
| 3740 | EVT PtrType = Ptr.getValueType(); |
| 3741 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3742 | SDValue NewPtr = DAG.getNode(ISD::ADD, dl, |
| 3743 | PtrType, Ptr, DAG.getConstant(4, dl, PtrType)); |
| 3744 | RetVal2 = DAG.getLoad(MVT::i32, dl, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3745 | Ld->getChain(), NewPtr, |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3746 | Ld->getPointerInfo().getWithOffset(4), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3747 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3748 | Ld->isInvariant(), NewAlign); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3749 | return; |
| 3750 | } |
| 3751 | |
| 3752 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3753 | } |
| 3754 | |
| 3755 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 3756 | /// f32 and even f64 comparisons to integer ones. |
| 3757 | SDValue |
| 3758 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 3759 | SDValue Chain = Op.getOperand(0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3760 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3761 | SDValue LHS = Op.getOperand(2); |
| 3762 | SDValue RHS = Op.getOperand(3); |
| 3763 | SDValue Dest = Op.getOperand(4); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3764 | SDLoc dl(Op); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3765 | |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3766 | bool LHSSeenZero = false; |
| 3767 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3768 | bool RHSSeenZero = false; |
| 3769 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3770 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
| Bob Wilson | 70bd363 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3771 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3772 | // the CMP operands, and the condition code is EQ or NE, we can optimize it |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3773 | // to an integer comparison. |
| 3774 | if (CC == ISD::SETOEQ) |
| 3775 | CC = ISD::SETEQ; |
| 3776 | else if (CC == ISD::SETUNE) |
| 3777 | CC = ISD::SETNE; |
| 3778 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3779 | SDValue Mask = DAG.getConstant(0x7fffffff, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3780 | SDValue ARMcc; |
| 3781 | if (LHS.getValueType() == MVT::f32) { |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3782 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3783 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3784 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3785 | bitcastf32Toi32(RHS, DAG), Mask); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3786 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3787 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3788 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3789 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3790 | } |
| 3791 | |
| 3792 | SDValue LHS1, LHS2; |
| 3793 | SDValue RHS1, RHS2; |
| 3794 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3795 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3796 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3797 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3798 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3799 | ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3800 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3801 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3802 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | return SDValue(); |
| 3806 | } |
| 3807 | |
| 3808 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3809 | SDValue Chain = Op.getOperand(0); |
| 3810 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3811 | SDValue LHS = Op.getOperand(2); |
| 3812 | SDValue RHS = Op.getOperand(3); |
| 3813 | SDValue Dest = Op.getOperand(4); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3814 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3815 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3816 | if (Subtarget->isFPOnlySP() && LHS.getValueType() == MVT::f64) { |
| 3817 | DAG.getTargetLoweringInfo().softenSetCCOperands(DAG, MVT::f64, LHS, RHS, CC, |
| 3818 | dl); |
| 3819 | |
| 3820 | // If softenSetCCOperands only returned one value, we should compare it to |
| 3821 | // zero. |
| 3822 | if (!RHS.getNode()) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3823 | RHS = DAG.getConstant(0, dl, LHS.getValueType()); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3824 | CC = ISD::SETNE; |
| 3825 | } |
| 3826 | } |
| 3827 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3828 | if (LHS.getValueType() == MVT::i32) { |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3829 | SDValue ARMcc; |
| 3830 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3831 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3832 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3833 | Chain, Dest, ARMcc, CCR, Cmp); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3834 | } |
| 3835 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3836 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3837 | |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3838 | if (getTargetMachine().Options.UnsafeFPMath && |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3839 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3840 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 3841 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 3842 | if (Result.getNode()) |
| 3843 | return Result; |
| 3844 | } |
| 3845 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3846 | ARMCC::CondCodes CondCode, CondCode2; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3847 | FPCCToARMCC(CC, CondCode, CondCode2); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3848 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3849 | SDValue ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3850 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3851 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3852 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3853 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3854 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3855 | if (CondCode2 != ARMCC::AL) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3856 | ARMcc = DAG.getConstant(CondCode2, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3857 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3858 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3859 | } |
| 3860 | return Res; |
| 3861 | } |
| 3862 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3863 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3864 | SDValue Chain = Op.getOperand(0); |
| 3865 | SDValue Table = Op.getOperand(1); |
| 3866 | SDValue Index = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3867 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3868 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3869 | EVT PTy = getPointerTy(DAG.getDataLayout()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3870 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3871 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 3872 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3873 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, dl, PTy)); |
| Evan Cheng | c8bed03 | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 3874 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3875 | if (Subtarget->isThumb2()) { |
| 3876 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 3877 | // which does another jump to the destination. This also makes it easier |
| 3878 | // to translate it to TBB / TBH later. |
| 3879 | // FIXME: This might not work if the function is extremely large. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3880 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 3881 | Addr, Op.getOperand(2), JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3882 | } |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3883 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3884 | Addr = |
| 3885 | DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
| 3886 | MachinePointerInfo::getJumpTable(DAG.getMachineFunction()), |
| 3887 | false, false, false, 0); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3888 | Chain = Addr.getValue(1); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 3889 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 3890 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3891 | } else { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3892 | Addr = |
| 3893 | DAG.getLoad(PTy, dl, Chain, Addr, |
| 3894 | MachinePointerInfo::getJumpTable(DAG.getMachineFunction()), |
| 3895 | false, false, false, 0); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3896 | Chain = Addr.getValue(1); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 3897 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 3898 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3899 | } |
| 3900 | |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3901 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3902 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3903 | SDLoc dl(Op); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3904 | |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 3905 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 3906 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 3907 | return Op; |
| 3908 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3909 | } |
| 3910 | |
| 3911 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 3912 | "Invalid type for custom lowering!"); |
| 3913 | if (VT != MVT::v4i16) |
| 3914 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3915 | |
| 3916 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 3917 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3918 | } |
| 3919 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3920 | SDValue ARMTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const { |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3921 | EVT VT = Op.getValueType(); |
| 3922 | if (VT.isVector()) |
| 3923 | return LowerVectorFP_TO_INT(Op, DAG); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3924 | if (Subtarget->isFPOnlySP() && Op.getOperand(0).getValueType() == MVT::f64) { |
| 3925 | RTLIB::Libcall LC; |
| 3926 | if (Op.getOpcode() == ISD::FP_TO_SINT) |
| 3927 | LC = RTLIB::getFPTOSINT(Op.getOperand(0).getValueType(), |
| 3928 | Op.getValueType()); |
| 3929 | else |
| 3930 | LC = RTLIB::getFPTOUINT(Op.getOperand(0).getValueType(), |
| 3931 | Op.getValueType()); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 3932 | return makeLibCall(DAG, LC, Op.getValueType(), Op.getOperand(0), |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3933 | /*isSigned*/ false, SDLoc(Op)).first; |
| 3934 | } |
| 3935 | |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 3936 | return Op; |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3937 | } |
| 3938 | |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3939 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3940 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3941 | SDLoc dl(Op); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3942 | |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 3943 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 3944 | if (VT.getVectorElementType() == MVT::f32) |
| 3945 | return Op; |
| 3946 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3947 | } |
| 3948 | |
| Duncan Sands | a41634e | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 3949 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 3950 | "Invalid type for custom lowering!"); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3951 | if (VT != MVT::v4f32) |
| 3952 | return DAG.UnrollVectorOp(Op.getNode()); |
| 3953 | |
| 3954 | unsigned CastOpc; |
| 3955 | unsigned Opc; |
| 3956 | switch (Op.getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 3957 | default: llvm_unreachable("Invalid opcode!"); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3958 | case ISD::SINT_TO_FP: |
| 3959 | CastOpc = ISD::SIGN_EXTEND; |
| 3960 | Opc = ISD::SINT_TO_FP; |
| 3961 | break; |
| 3962 | case ISD::UINT_TO_FP: |
| 3963 | CastOpc = ISD::ZERO_EXTEND; |
| 3964 | Opc = ISD::UINT_TO_FP; |
| 3965 | break; |
| 3966 | } |
| 3967 | |
| 3968 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3969 | return DAG.getNode(Opc, dl, VT, Op); |
| 3970 | } |
| 3971 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3972 | SDValue ARMTargetLowering::LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const { |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3973 | EVT VT = Op.getValueType(); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3974 | if (VT.isVector()) |
| 3975 | return LowerVectorINT_TO_FP(Op, DAG); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3976 | if (Subtarget->isFPOnlySP() && Op.getValueType() == MVT::f64) { |
| 3977 | RTLIB::Libcall LC; |
| 3978 | if (Op.getOpcode() == ISD::SINT_TO_FP) |
| 3979 | LC = RTLIB::getSINTTOFP(Op.getOperand(0).getValueType(), |
| 3980 | Op.getValueType()); |
| 3981 | else |
| 3982 | LC = RTLIB::getUINTTOFP(Op.getOperand(0).getValueType(), |
| 3983 | Op.getValueType()); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 3984 | return makeLibCall(DAG, LC, Op.getValueType(), Op.getOperand(0), |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3985 | /*isSigned*/ false, SDLoc(Op)).first; |
| 3986 | } |
| 3987 | |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 3988 | return Op; |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3989 | } |
| 3990 | |
| Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3991 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3992 | // Implement fcopysign with a fabs and a conditional fneg. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3993 | SDValue Tmp0 = Op.getOperand(0); |
| 3994 | SDValue Tmp1 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3995 | SDLoc dl(Op); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3996 | EVT VT = Op.getValueType(); |
| 3997 | EVT SrcVT = Tmp1.getValueType(); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3998 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3999 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 4000 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 4001 | |
| 4002 | if (UseNEON) { |
| 4003 | // Use VBSL to copy the sign bit. |
| 4004 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 4005 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4006 | DAG.getTargetConstant(EncodedVal, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4007 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 4008 | if (VT == MVT::f64) |
| 4009 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 4010 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4011 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4012 | else /*if (VT == MVT::f32)*/ |
| 4013 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 4014 | if (SrcVT == MVT::f32) { |
| 4015 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 4016 | if (VT == MVT::f64) |
| 4017 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 4018 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4019 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | 12bb05b | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 4020 | } else if (VT == MVT::f32) |
| 4021 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 4022 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4023 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4024 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 4025 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 4026 | |
| 4027 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4028 | dl, MVT::i32); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4029 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 4030 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 4031 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4032 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4033 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 4034 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 4035 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
| Evan Cheng | 6e3d443 | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 4036 | if (VT == MVT::f32) { |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4037 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 4038 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4039 | DAG.getConstant(0, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4040 | } else { |
| 4041 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 4042 | } |
| 4043 | |
| 4044 | return Res; |
| 4045 | } |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4046 | |
| 4047 | // Bitcast operand 1 to i32. |
| 4048 | if (SrcVT == MVT::f64) |
| 4049 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4050 | Tmp1).getValue(1); |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4051 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 4052 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4053 | // Or in the signbit with integer operations. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4054 | SDValue Mask1 = DAG.getConstant(0x80000000, dl, MVT::i32); |
| 4055 | SDValue Mask2 = DAG.getConstant(0x7fffffff, dl, MVT::i32); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4056 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 4057 | if (VT == MVT::f32) { |
| 4058 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 4059 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 4060 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 4061 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4062 | } |
| 4063 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4064 | // f64: Or the high part with signbit and then combine two parts. |
| 4065 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4066 | Tmp0); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4067 | SDValue Lo = Tmp0.getValue(0); |
| 4068 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 4069 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 4070 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4071 | } |
| 4072 | |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4073 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 4074 | MachineFunction &MF = DAG.getMachineFunction(); |
| 4075 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 4076 | MFI->setReturnAddressIsTaken(true); |
| 4077 | |
| Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 4078 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 4079 | return SDValue(); |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 4080 | |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4081 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4082 | SDLoc dl(Op); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4083 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 4084 | if (Depth) { |
| 4085 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4086 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4087 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 4088 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4089 | MachinePointerInfo(), false, false, false, 0); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4090 | } |
| 4091 | |
| 4092 | // Return LR, which contains the return address. Mark it an implicit live-in. |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 4093 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4094 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 4095 | } |
| 4096 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4097 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
| Saleem Abdulrasool | f11f4b4 | 2014-05-18 03:18:09 +0000 | [diff] [blame] | 4098 | const ARMBaseRegisterInfo &ARI = |
| 4099 | *static_cast<const ARMBaseRegisterInfo*>(RegInfo); |
| 4100 | MachineFunction &MF = DAG.getMachineFunction(); |
| 4101 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4102 | MFI->setFrameAddressIsTaken(true); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4103 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4104 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4105 | SDLoc dl(Op); // FIXME probably not meaningful |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4106 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| Saleem Abdulrasool | f11f4b4 | 2014-05-18 03:18:09 +0000 | [diff] [blame] | 4107 | unsigned FrameReg = ARI.getFrameRegister(MF); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4108 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 4109 | while (Depth--) |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 4110 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 4111 | MachinePointerInfo(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4112 | false, false, false, 0); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4113 | return FrameAddr; |
| 4114 | } |
| 4115 | |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4116 | // FIXME? Maybe this could be a TableGen attribute on some registers and |
| 4117 | // this table could be generated automatically from RegInfo. |
| Pat Gavlin | a717f25 | 2015-07-09 17:40:29 +0000 | [diff] [blame] | 4118 | unsigned ARMTargetLowering::getRegisterByName(const char* RegName, EVT VT, |
| 4119 | SelectionDAG &DAG) const { |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4120 | unsigned Reg = StringSwitch<unsigned>(RegName) |
| 4121 | .Case("sp", ARM::SP) |
| 4122 | .Default(0); |
| 4123 | if (Reg) |
| 4124 | return Reg; |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 4125 | report_fatal_error(Twine("Invalid register name \"" |
| 4126 | + StringRef(RegName) + "\".")); |
| 4127 | } |
| 4128 | |
| 4129 | // Result is 64 bit value so split into two 32 bit values and return as a |
| 4130 | // pair of values. |
| 4131 | static void ExpandREAD_REGISTER(SDNode *N, SmallVectorImpl<SDValue> &Results, |
| 4132 | SelectionDAG &DAG) { |
| 4133 | SDLoc DL(N); |
| 4134 | |
| 4135 | // This function is only supposed to be called for i64 type destination. |
| 4136 | assert(N->getValueType(0) == MVT::i64 |
| 4137 | && "ExpandREAD_REGISTER called for non-i64 type result."); |
| 4138 | |
| 4139 | SDValue Read = DAG.getNode(ISD::READ_REGISTER, DL, |
| 4140 | DAG.getVTList(MVT::i32, MVT::i32, MVT::Other), |
| 4141 | N->getOperand(0), |
| 4142 | N->getOperand(1)); |
| 4143 | |
| 4144 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Read.getValue(0), |
| 4145 | Read.getValue(1))); |
| 4146 | Results.push_back(Read.getOperand(0)); |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4147 | } |
| 4148 | |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4149 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4150 | /// expand a bit convert where either the source or destination type is i64 to |
| 4151 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 4152 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 4153 | /// vectors), since the legalizer won't know what to do with that. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4154 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4155 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4156 | SDLoc dl(N); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4157 | SDValue Op = N->getOperand(0); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4158 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4159 | // This function is only supposed to be called for i64 types, either as the |
| 4160 | // source or destination of the bit convert. |
| 4161 | EVT SrcVT = Op.getValueType(); |
| 4162 | EVT DstVT = N->getValueType(0); |
| 4163 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4164 | "ExpandBITCAST called for non-i64 type"); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4165 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4166 | // Turn i64->f64 into VMOVDRR. |
| 4167 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4168 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4169 | DAG.getConstant(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4170 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4171 | DAG.getConstant(1, dl, MVT::i32)); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4172 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
| Bob Wilson | f07d33d | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 4173 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
| Evan Cheng | 297b32a | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 4174 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4175 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4176 | // Turn f64->i64 into VMOVRRD. |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4177 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame] | 4178 | SDValue Cvt; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 4179 | if (DAG.getDataLayout().isBigEndian() && SrcVT.isVector() && |
| Christian Pirker | 6692e7c | 2014-05-14 16:59:44 +0000 | [diff] [blame] | 4180 | SrcVT.getVectorNumElements() > 1) |
| Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame] | 4181 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 4182 | DAG.getVTList(MVT::i32, MVT::i32), |
| 4183 | DAG.getNode(ARMISD::VREV64, dl, SrcVT, Op)); |
| 4184 | else |
| 4185 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 4186 | DAG.getVTList(MVT::i32, MVT::i32), Op); |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4187 | // Merge the pieces into a single i64 value. |
| 4188 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 4189 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4190 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4191 | return SDValue(); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4194 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4195 | /// Zero vectors are used to represent vector negation and in those cases |
| 4196 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 4197 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 4198 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 4199 | /// zero vector. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4200 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, SDLoc dl) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4201 | assert(VT.isVector() && "Expected a vector type"); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4202 | // The canonical modified immediate encoding of a zero vector is....0! |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4203 | SDValue EncodedVal = DAG.getTargetConstant(0, dl, MVT::i32); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4204 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 4205 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4206 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4207 | } |
| 4208 | |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4209 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 4210 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4211 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 4212 | SelectionDAG &DAG) const { |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4213 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 4214 | EVT VT = Op.getValueType(); |
| 4215 | unsigned VTBits = VT.getSizeInBits(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4216 | SDLoc dl(Op); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4217 | SDValue ShOpLo = Op.getOperand(0); |
| 4218 | SDValue ShOpHi = Op.getOperand(1); |
| 4219 | SDValue ShAmt = Op.getOperand(2); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4220 | SDValue ARMcc; |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4221 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4222 | |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4223 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 4224 | |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4225 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4226 | DAG.getConstant(VTBits, dl, MVT::i32), ShAmt); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4227 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 4228 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4229 | DAG.getConstant(VTBits, dl, MVT::i32)); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4230 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 4231 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4232 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4233 | |
| 4234 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4235 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, dl, MVT::i32), |
| 4236 | ISD::SETGE, ARMcc, DAG, dl); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4237 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4238 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4239 | CCR, Cmp); |
| 4240 | |
| 4241 | SDValue Ops[2] = { Lo, Hi }; |
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4242 | return DAG.getMergeValues(Ops, dl); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4243 | } |
| 4244 | |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4245 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 4246 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4247 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 4248 | SelectionDAG &DAG) const { |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4249 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 4250 | EVT VT = Op.getValueType(); |
| 4251 | unsigned VTBits = VT.getSizeInBits(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4252 | SDLoc dl(Op); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4253 | SDValue ShOpLo = Op.getOperand(0); |
| 4254 | SDValue ShOpHi = Op.getOperand(1); |
| 4255 | SDValue ShAmt = Op.getOperand(2); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4256 | SDValue ARMcc; |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4257 | |
| 4258 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 4259 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4260 | DAG.getConstant(VTBits, dl, MVT::i32), ShAmt); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4261 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 4262 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4263 | DAG.getConstant(VTBits, dl, MVT::i32)); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4264 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 4265 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 4266 | |
| 4267 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 4268 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4269 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, dl, MVT::i32), |
| 4270 | ISD::SETGE, ARMcc, DAG, dl); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4271 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4272 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4273 | CCR, Cmp); |
| 4274 | |
| 4275 | SDValue Ops[2] = { Lo, Hi }; |
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4276 | return DAG.getMergeValues(Ops, dl); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4279 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4280 | SelectionDAG &DAG) const { |
| 4281 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 4282 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 4283 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 4284 | // so that the shift + and get folded into a bitfield extract. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4285 | SDLoc dl(Op); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4286 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4287 | DAG.getConstant(Intrinsic::arm_get_fpscr, dl, |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4288 | MVT::i32)); |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4289 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4290 | DAG.getConstant(1U << 22, dl, MVT::i32)); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4291 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4292 | DAG.getConstant(22, dl, MVT::i32)); |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4293 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4294 | DAG.getConstant(3, dl, MVT::i32)); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4295 | } |
| 4296 | |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4297 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 4298 | const ARMSubtarget *ST) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4299 | SDLoc dl(N); |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 4300 | EVT VT = N->getValueType(0); |
| 4301 | if (VT.isVector()) { |
| 4302 | assert(ST->hasNEON()); |
| 4303 | |
| 4304 | // Compute the least significant set bit: LSB = X & -X |
| 4305 | SDValue X = N->getOperand(0); |
| 4306 | SDValue NX = DAG.getNode(ISD::SUB, dl, VT, getZeroVector(VT, DAG, dl), X); |
| 4307 | SDValue LSB = DAG.getNode(ISD::AND, dl, VT, X, NX); |
| 4308 | |
| 4309 | EVT ElemTy = VT.getVectorElementType(); |
| 4310 | |
| 4311 | if (ElemTy == MVT::i8) { |
| 4312 | // Compute with: cttz(x) = ctpop(lsb - 1) |
| 4313 | SDValue One = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4314 | DAG.getTargetConstant(1, dl, ElemTy)); |
| 4315 | SDValue Bits = DAG.getNode(ISD::SUB, dl, VT, LSB, One); |
| 4316 | return DAG.getNode(ISD::CTPOP, dl, VT, Bits); |
| 4317 | } |
| 4318 | |
| 4319 | if ((ElemTy == MVT::i16 || ElemTy == MVT::i32) && |
| 4320 | (N->getOpcode() == ISD::CTTZ_ZERO_UNDEF)) { |
| 4321 | // Compute with: cttz(x) = (width - 1) - ctlz(lsb), if x != 0 |
| 4322 | unsigned NumBits = ElemTy.getSizeInBits(); |
| 4323 | SDValue WidthMinus1 = |
| 4324 | DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4325 | DAG.getTargetConstant(NumBits - 1, dl, ElemTy)); |
| 4326 | SDValue CTLZ = DAG.getNode(ISD::CTLZ, dl, VT, LSB); |
| 4327 | return DAG.getNode(ISD::SUB, dl, VT, WidthMinus1, CTLZ); |
| 4328 | } |
| 4329 | |
| 4330 | // Compute with: cttz(x) = ctpop(lsb - 1) |
| 4331 | |
| 4332 | // Since we can only compute the number of bits in a byte with vcnt.8, we |
| 4333 | // have to gather the result with pairwise addition (vpaddl) for i16, i32, |
| 4334 | // and i64. |
| 4335 | |
| 4336 | // Compute LSB - 1. |
| 4337 | SDValue Bits; |
| 4338 | if (ElemTy == MVT::i64) { |
| 4339 | // Load constant 0xffff'ffff'ffff'ffff to register. |
| 4340 | SDValue FF = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4341 | DAG.getTargetConstant(0x1eff, dl, MVT::i32)); |
| 4342 | Bits = DAG.getNode(ISD::ADD, dl, VT, LSB, FF); |
| 4343 | } else { |
| 4344 | SDValue One = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4345 | DAG.getTargetConstant(1, dl, ElemTy)); |
| 4346 | Bits = DAG.getNode(ISD::SUB, dl, VT, LSB, One); |
| 4347 | } |
| 4348 | |
| 4349 | // Count #bits with vcnt.8. |
| 4350 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 4351 | SDValue BitsVT8 = DAG.getNode(ISD::BITCAST, dl, VT8Bit, Bits); |
| 4352 | SDValue Cnt8 = DAG.getNode(ISD::CTPOP, dl, VT8Bit, BitsVT8); |
| 4353 | |
| 4354 | // Gather the #bits with vpaddl (pairwise add.) |
| 4355 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 4356 | SDValue Cnt16 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT16Bit, |
| 4357 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4358 | Cnt8); |
| 4359 | if (ElemTy == MVT::i16) |
| 4360 | return Cnt16; |
| 4361 | |
| 4362 | EVT VT32Bit = VT.is64BitVector() ? MVT::v2i32 : MVT::v4i32; |
| 4363 | SDValue Cnt32 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT32Bit, |
| 4364 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4365 | Cnt16); |
| 4366 | if (ElemTy == MVT::i32) |
| 4367 | return Cnt32; |
| 4368 | |
| 4369 | assert(ElemTy == MVT::i64); |
| 4370 | SDValue Cnt64 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 4371 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4372 | Cnt32); |
| 4373 | return Cnt64; |
| 4374 | } |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4375 | |
| 4376 | if (!ST->hasV6T2Ops()) |
| 4377 | return SDValue(); |
| 4378 | |
| 4379 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 4380 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 4381 | } |
| 4382 | |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4383 | /// getCTPOP16BitCounts - Returns a v8i8/v16i8 vector containing the bit-count |
| 4384 | /// for each 16-bit element from operand, repeated. The basic idea is to |
| 4385 | /// leverage vcnt to get the 8-bit counts, gather and add the results. |
| 4386 | /// |
| 4387 | /// Trace for v4i16: |
| 4388 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 4389 | /// cast: N0 = [w0 w1 w2 w3 w4 w5 w6 w7] (v0 = [w0 w1], wi 8-bit element) |
| 4390 | /// vcnt: N1 = [b0 b1 b2 b3 b4 b5 b6 b7] (bi = bit-count of 8-bit element wi) |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4391 | /// vrev: N2 = [b1 b0 b3 b2 b5 b4 b7 b6] |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4392 | /// [b0 b1 b2 b3 b4 b5 b6 b7] |
| 4393 | /// +[b1 b0 b3 b2 b5 b4 b7 b6] |
| 4394 | /// N3=N1+N2 = [k0 k0 k1 k1 k2 k2 k3 k3] (k0 = b0+b1 = bit-count of 16-bit v0, |
| 4395 | /// vuzp: = [k0 k1 k2 k3 k0 k1 k2 k3] each ki is 8-bits) |
| 4396 | static SDValue getCTPOP16BitCounts(SDNode *N, SelectionDAG &DAG) { |
| 4397 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4398 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4399 | |
| 4400 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 4401 | SDValue N0 = DAG.getNode(ISD::BITCAST, DL, VT8Bit, N->getOperand(0)); |
| 4402 | SDValue N1 = DAG.getNode(ISD::CTPOP, DL, VT8Bit, N0); |
| 4403 | SDValue N2 = DAG.getNode(ARMISD::VREV16, DL, VT8Bit, N1); |
| 4404 | SDValue N3 = DAG.getNode(ISD::ADD, DL, VT8Bit, N1, N2); |
| 4405 | return DAG.getNode(ARMISD::VUZP, DL, VT8Bit, N3, N3); |
| 4406 | } |
| 4407 | |
| 4408 | /// lowerCTPOP16BitElements - Returns a v4i16/v8i16 vector containing the |
| 4409 | /// bit-count for each 16-bit element from the operand. We need slightly |
| 4410 | /// different sequencing for v4i16 and v8i16 to stay within NEON's available |
| 4411 | /// 64/128-bit registers. |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4412 | /// |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4413 | /// Trace for v4i16: |
| 4414 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 4415 | /// v8i8: BitCounts = [k0 k1 k2 k3 k0 k1 k2 k3 ] (ki is the bit-count of vi) |
| 4416 | /// v8i16:Extended = [k0 k1 k2 k3 k0 k1 k2 k3 ] |
| 4417 | /// v4i16:Extracted = [k0 k1 k2 k3 ] |
| 4418 | static SDValue lowerCTPOP16BitElements(SDNode *N, SelectionDAG &DAG) { |
| 4419 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4420 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4421 | |
| 4422 | SDValue BitCounts = getCTPOP16BitCounts(N, DAG); |
| 4423 | if (VT.is64BitVector()) { |
| 4424 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, BitCounts); |
| 4425 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, Extended, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4426 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4427 | } else { |
| 4428 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4429 | BitCounts, DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4430 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, Extracted); |
| 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | /// lowerCTPOP32BitElements - Returns a v2i32/v4i32 vector containing the |
| 4435 | /// bit-count for each 32-bit element from the operand. The idea here is |
| 4436 | /// to split the vector into 16-bit elements, leverage the 16-bit count |
| 4437 | /// routine, and then combine the results. |
| 4438 | /// |
| 4439 | /// Trace for v2i32 (v4i32 similar with Extracted/Extended exchanged): |
| 4440 | /// input = [v0 v1 ] (vi: 32-bit elements) |
| 4441 | /// Bitcast = [w0 w1 w2 w3 ] (wi: 16-bit elements, v0 = [w0 w1]) |
| 4442 | /// Counts16 = [k0 k1 k2 k3 ] (ki: 16-bit elements, bit-count of wi) |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4443 | /// vrev: N0 = [k1 k0 k3 k2 ] |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4444 | /// [k0 k1 k2 k3 ] |
| 4445 | /// N1 =+[k1 k0 k3 k2 ] |
| 4446 | /// [k0 k2 k1 k3 ] |
| 4447 | /// N2 =+[k1 k3 k0 k2 ] |
| 4448 | /// [k0 k2 k1 k3 ] |
| 4449 | /// Extended =+[k1 k3 k0 k2 ] |
| 4450 | /// [k0 k2 ] |
| 4451 | /// Extracted=+[k1 k3 ] |
| 4452 | /// |
| 4453 | static SDValue lowerCTPOP32BitElements(SDNode *N, SelectionDAG &DAG) { |
| 4454 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4455 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4456 | |
| 4457 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 4458 | |
| 4459 | SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT16Bit, N->getOperand(0)); |
| 4460 | SDValue Counts16 = lowerCTPOP16BitElements(Bitcast.getNode(), DAG); |
| 4461 | SDValue N0 = DAG.getNode(ARMISD::VREV32, DL, VT16Bit, Counts16); |
| 4462 | SDValue N1 = DAG.getNode(ISD::ADD, DL, VT16Bit, Counts16, N0); |
| 4463 | SDValue N2 = DAG.getNode(ARMISD::VUZP, DL, VT16Bit, N1, N1); |
| 4464 | |
| 4465 | if (VT.is64BitVector()) { |
| 4466 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, N2); |
| 4467 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v2i32, Extended, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4468 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4469 | } else { |
| 4470 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, N2, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4471 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4472 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, Extracted); |
| 4473 | } |
| 4474 | } |
| 4475 | |
| 4476 | static SDValue LowerCTPOP(SDNode *N, SelectionDAG &DAG, |
| 4477 | const ARMSubtarget *ST) { |
| 4478 | EVT VT = N->getValueType(0); |
| 4479 | |
| 4480 | assert(ST->hasNEON() && "Custom ctpop lowering requires NEON."); |
| Matt Beaumont-Gay | 50f61b6 | 2012-12-04 23:54:02 +0000 | [diff] [blame] | 4481 | assert((VT == MVT::v2i32 || VT == MVT::v4i32 || |
| 4482 | VT == MVT::v4i16 || VT == MVT::v8i16) && |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4483 | "Unexpected type for custom ctpop lowering"); |
| 4484 | |
| 4485 | if (VT.getVectorElementType() == MVT::i32) |
| 4486 | return lowerCTPOP32BitElements(N, DAG); |
| 4487 | else |
| 4488 | return lowerCTPOP16BitElements(N, DAG); |
| 4489 | } |
| 4490 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4491 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 4492 | const ARMSubtarget *ST) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4493 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4494 | SDLoc dl(N); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4495 | |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4496 | if (!VT.isVector()) |
| 4497 | return SDValue(); |
| 4498 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4499 | // Lower vector shifts on NEON to use VSHL. |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4500 | assert(ST->hasNEON() && "unexpected vector shift"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4501 | |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4502 | // Left shifts translate directly to the vshiftu intrinsic. |
| 4503 | if (N->getOpcode() == ISD::SHL) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4504 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4505 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, dl, |
| 4506 | MVT::i32), |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4507 | N->getOperand(0), N->getOperand(1)); |
| 4508 | |
| 4509 | assert((N->getOpcode() == ISD::SRA || |
| 4510 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 4511 | |
| 4512 | // NEON uses the same intrinsics for both left and right shifts. For |
| 4513 | // right shifts, the shift amounts are negative, so negate the vector of |
| 4514 | // shift amounts. |
| 4515 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 4516 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 4517 | getZeroVector(ShiftVT, DAG, dl), |
| 4518 | N->getOperand(1)); |
| 4519 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 4520 | Intrinsic::arm_neon_vshifts : |
| 4521 | Intrinsic::arm_neon_vshiftu); |
| 4522 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4523 | DAG.getConstant(vshiftInt, dl, MVT::i32), |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4524 | N->getOperand(0), NegatedCount); |
| 4525 | } |
| 4526 | |
| 4527 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 4528 | const ARMSubtarget *ST) { |
| 4529 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4530 | SDLoc dl(N); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4531 | |
| Eli Friedman | 682d8c1 | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 4532 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 4533 | if (VT != MVT::i64) |
| 4534 | return SDValue(); |
| 4535 | |
| 4536 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4537 | "Unknown shift to lower!"); |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4538 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4539 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 4540 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 4541 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4542 | return SDValue(); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4543 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4544 | // If we are in thumb mode, we don't have RRX. |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4545 | if (ST->isThumb1Only()) return SDValue(); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4546 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4547 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4548 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4549 | DAG.getConstant(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4550 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4551 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4552 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4553 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 4554 | // captures the result into a carry flag. |
| 4555 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4556 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), Hi); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4557 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4558 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4559 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4560 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4561 | // Merge the pieces into a single i64 value. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4562 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4563 | } |
| 4564 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4565 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 4566 | SDValue TmpOp0, TmpOp1; |
| 4567 | bool Invert = false; |
| 4568 | bool Swap = false; |
| 4569 | unsigned Opc = 0; |
| 4570 | |
| 4571 | SDValue Op0 = Op.getOperand(0); |
| 4572 | SDValue Op1 = Op.getOperand(1); |
| 4573 | SDValue CC = Op.getOperand(2); |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4574 | EVT CmpVT = Op0.getValueType().changeVectorElementTypeToInteger(); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4575 | EVT VT = Op.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4576 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4577 | SDLoc dl(Op); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4578 | |
| James Molloy | bf17009 | 2015-08-20 16:33:44 +0000 | [diff] [blame] | 4579 | if (CmpVT.getVectorElementType() == MVT::i64) |
| 4580 | // 64-bit comparisons are not legal. We've marked SETCC as non-Custom, |
| 4581 | // but it's possible that our operands are 64-bit but our result is 32-bit. |
| 4582 | // Bail in this case. |
| 4583 | return SDValue(); |
| 4584 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4585 | if (Op1.getValueType().isFloatingPoint()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4586 | switch (SetCCOpcode) { |
| David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4587 | default: llvm_unreachable("Illegal FP comparison"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4588 | case ISD::SETUNE: |
| 4589 | case ISD::SETNE: Invert = true; // Fallthrough |
| 4590 | case ISD::SETOEQ: |
| 4591 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 4592 | case ISD::SETOLT: |
| 4593 | case ISD::SETLT: Swap = true; // Fallthrough |
| 4594 | case ISD::SETOGT: |
| 4595 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 4596 | case ISD::SETOLE: |
| 4597 | case ISD::SETLE: Swap = true; // Fallthrough |
| 4598 | case ISD::SETOGE: |
| 4599 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 4600 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 4601 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 4602 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 4603 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 4604 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 4605 | case ISD::SETONE: |
| 4606 | // Expand this to (OLT | OGT). |
| 4607 | TmpOp0 = Op0; |
| 4608 | TmpOp1 = Op1; |
| 4609 | Opc = ISD::OR; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4610 | Op0 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp1, TmpOp0); |
| 4611 | Op1 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp0, TmpOp1); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4612 | break; |
| 4613 | case ISD::SETUO: Invert = true; // Fallthrough |
| 4614 | case ISD::SETO: |
| 4615 | // Expand this to (OLT | OGE). |
| 4616 | TmpOp0 = Op0; |
| 4617 | TmpOp1 = Op1; |
| 4618 | Opc = ISD::OR; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4619 | Op0 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp1, TmpOp0); |
| 4620 | Op1 = DAG.getNode(ARMISD::VCGE, dl, CmpVT, TmpOp0, TmpOp1); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4621 | break; |
| 4622 | } |
| 4623 | } else { |
| 4624 | // Integer comparisons. |
| 4625 | switch (SetCCOpcode) { |
| David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4626 | default: llvm_unreachable("Illegal integer comparison"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4627 | case ISD::SETNE: Invert = true; |
| 4628 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 4629 | case ISD::SETLT: Swap = true; |
| 4630 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 4631 | case ISD::SETLE: Swap = true; |
| 4632 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 4633 | case ISD::SETULT: Swap = true; |
| 4634 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 4635 | case ISD::SETULE: Swap = true; |
| 4636 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 4637 | } |
| 4638 | |
| Nick Lewycky | a21d3da | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 4639 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4640 | if (Opc == ARMISD::VCEQ) { |
| 4641 | |
| 4642 | SDValue AndOp; |
| 4643 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4644 | AndOp = Op0; |
| 4645 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 4646 | AndOp = Op1; |
| 4647 | |
| 4648 | // Ignore bitconvert. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4649 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4650 | AndOp = AndOp.getOperand(0); |
| 4651 | |
| 4652 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 4653 | Opc = ARMISD::VTST; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4654 | Op0 = DAG.getNode(ISD::BITCAST, dl, CmpVT, AndOp.getOperand(0)); |
| 4655 | Op1 = DAG.getNode(ISD::BITCAST, dl, CmpVT, AndOp.getOperand(1)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4656 | Invert = !Invert; |
| 4657 | } |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | if (Swap) |
| 4662 | std::swap(Op0, Op1); |
| 4663 | |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4664 | // If one of the operands is a constant vector zero, attempt to fold the |
| 4665 | // comparison to a specialized compare-against-zero form. |
| 4666 | SDValue SingleOp; |
| 4667 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4668 | SingleOp = Op0; |
| 4669 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 4670 | if (Opc == ARMISD::VCGE) |
| 4671 | Opc = ARMISD::VCLEZ; |
| 4672 | else if (Opc == ARMISD::VCGT) |
| 4673 | Opc = ARMISD::VCLTZ; |
| 4674 | SingleOp = Op1; |
| 4675 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4676 | |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4677 | SDValue Result; |
| 4678 | if (SingleOp.getNode()) { |
| 4679 | switch (Opc) { |
| 4680 | case ARMISD::VCEQ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4681 | Result = DAG.getNode(ARMISD::VCEQZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4682 | case ARMISD::VCGE: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4683 | Result = DAG.getNode(ARMISD::VCGEZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4684 | case ARMISD::VCLEZ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4685 | Result = DAG.getNode(ARMISD::VCLEZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4686 | case ARMISD::VCGT: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4687 | Result = DAG.getNode(ARMISD::VCGTZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4688 | case ARMISD::VCLTZ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4689 | Result = DAG.getNode(ARMISD::VCLTZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4690 | default: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4691 | Result = DAG.getNode(Opc, dl, CmpVT, Op0, Op1); |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4692 | } |
| 4693 | } else { |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4694 | Result = DAG.getNode(Opc, dl, CmpVT, Op0, Op1); |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4695 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4696 | |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4697 | Result = DAG.getSExtOrTrunc(Result, dl, VT); |
| 4698 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4699 | if (Invert) |
| 4700 | Result = DAG.getNOT(dl, Result, VT); |
| 4701 | |
| 4702 | return Result; |
| 4703 | } |
| 4704 | |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4705 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 4706 | /// valid vector constant for a NEON instruction with a "modified immediate" |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4707 | /// operand (e.g., VMOV). If so, return the encoded value. |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4708 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 4709 | unsigned SplatBitSize, SelectionDAG &DAG, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4710 | SDLoc dl, EVT &VT, bool is128Bits, |
| 4711 | NEONModImmType type) { |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4712 | unsigned OpCmode, Imm; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4713 | |
| Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4714 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 4715 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 4716 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 4717 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 4718 | // 32-bit version. |
| 4719 | if (SplatBits == 0) |
| 4720 | SplatBitSize = 32; |
| 4721 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4722 | switch (SplatBitSize) { |
| 4723 | case 8: |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4724 | if (type != VMOVModImm) |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4725 | return SDValue(); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4726 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4727 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4728 | OpCmode = 0xe; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4729 | Imm = SplatBits; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4730 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4731 | break; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4732 | |
| 4733 | case 16: |
| 4734 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4735 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4736 | if ((SplatBits & ~0xff) == 0) { |
| 4737 | // Value = 0x00nn: Op=x, Cmode=100x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4738 | OpCmode = 0x8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4739 | Imm = SplatBits; |
| 4740 | break; |
| 4741 | } |
| 4742 | if ((SplatBits & ~0xff00) == 0) { |
| 4743 | // Value = 0xnn00: Op=x, Cmode=101x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4744 | OpCmode = 0xa; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4745 | Imm = SplatBits >> 8; |
| 4746 | break; |
| 4747 | } |
| 4748 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4749 | |
| 4750 | case 32: |
| 4751 | // NEON's 32-bit VMOV supports splat values where: |
| 4752 | // * only one byte is nonzero, or |
| 4753 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 4754 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4755 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4756 | if ((SplatBits & ~0xff) == 0) { |
| 4757 | // Value = 0x000000nn: Op=x, Cmode=000x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4758 | OpCmode = 0; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4759 | Imm = SplatBits; |
| 4760 | break; |
| 4761 | } |
| 4762 | if ((SplatBits & ~0xff00) == 0) { |
| 4763 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4764 | OpCmode = 0x2; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4765 | Imm = SplatBits >> 8; |
| 4766 | break; |
| 4767 | } |
| 4768 | if ((SplatBits & ~0xff0000) == 0) { |
| 4769 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4770 | OpCmode = 0x4; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4771 | Imm = SplatBits >> 16; |
| 4772 | break; |
| 4773 | } |
| 4774 | if ((SplatBits & ~0xff000000) == 0) { |
| 4775 | // Value = 0xnn000000: Op=x, Cmode=011x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4776 | OpCmode = 0x6; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4777 | Imm = SplatBits >> 24; |
| 4778 | break; |
| 4779 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4780 | |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4781 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 4782 | if (type == OtherModImm) return SDValue(); |
| 4783 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4784 | if ((SplatBits & ~0xffff) == 0 && |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4785 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 4786 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4787 | OpCmode = 0xc; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4788 | Imm = SplatBits >> 8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4789 | break; |
| 4790 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4791 | |
| 4792 | if ((SplatBits & ~0xffffff) == 0 && |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4793 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 4794 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4795 | OpCmode = 0xd; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4796 | Imm = SplatBits >> 16; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4797 | break; |
| 4798 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4799 | |
| 4800 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 4801 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 4802 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 4803 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 4804 | // caller would also need to check and handle the change in size. |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4805 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4806 | |
| 4807 | case 64: { |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4808 | if (type != VMOVModImm) |
| Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4809 | return SDValue(); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4810 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4811 | uint64_t BitMask = 0xff; |
| 4812 | uint64_t Val = 0; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4813 | unsigned ImmMask = 1; |
| 4814 | Imm = 0; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4815 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4816 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4817 | Val |= BitMask; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4818 | Imm |= ImmMask; |
| 4819 | } else if ((SplatBits & BitMask) != 0) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4820 | return SDValue(); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4821 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4822 | BitMask <<= 8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4823 | ImmMask <<= 1; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4824 | } |
| Christian Pirker | 6f81e75 | 2014-06-23 18:05:53 +0000 | [diff] [blame] | 4825 | |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 4826 | if (DAG.getDataLayout().isBigEndian()) |
| Christian Pirker | 6f81e75 | 2014-06-23 18:05:53 +0000 | [diff] [blame] | 4827 | // swap higher and lower 32 bit word |
| 4828 | Imm = ((Imm & 0xf) << 4) | ((Imm & 0xf0) >> 4); |
| 4829 | |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4830 | // Op=1, Cmode=1110. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4831 | OpCmode = 0x1e; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4832 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4833 | break; |
| 4834 | } |
| 4835 | |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4836 | default: |
| Bob Wilson | 0ae0893 | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 4837 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4838 | } |
| 4839 | |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4840 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4841 | return DAG.getTargetConstant(EncodedVal, dl, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4842 | } |
| 4843 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4844 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 4845 | const ARMSubtarget *ST) const { |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4846 | if (!ST->hasVFP3()) |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4847 | return SDValue(); |
| 4848 | |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4849 | bool IsDouble = Op.getValueType() == MVT::f64; |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4850 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4851 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4852 | // Use the default (constant pool) lowering for double constants when we have |
| 4853 | // an SP-only FPU |
| 4854 | if (IsDouble && Subtarget->isFPOnlySP()) |
| 4855 | return SDValue(); |
| 4856 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4857 | // Try splatting with a VMOV.f32... |
| 4858 | APFloat FPVal = CFP->getValueAPF(); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4859 | int ImmVal = IsDouble ? ARM_AM::getFP64Imm(FPVal) : ARM_AM::getFP32Imm(FPVal); |
| 4860 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4861 | if (ImmVal != -1) { |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4862 | if (IsDouble || !ST->useNEONForSinglePrecisionFP()) { |
| 4863 | // We have code in place to select a valid ConstantFP already, no need to |
| 4864 | // do any mangling. |
| 4865 | return Op; |
| 4866 | } |
| 4867 | |
| 4868 | // It's a float and we are trying to use NEON operations where |
| 4869 | // possible. Lower it to a splat followed by an extract. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4870 | SDLoc DL(Op); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4871 | SDValue NewVal = DAG.getTargetConstant(ImmVal, DL, MVT::i32); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4872 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 4873 | NewVal); |
| 4874 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4875 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4876 | } |
| 4877 | |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4878 | // The rest of our options are NEON only, make sure that's allowed before |
| 4879 | // proceeding.. |
| 4880 | if (!ST->hasNEON() || (!IsDouble && !ST->useNEONForSinglePrecisionFP())) |
| 4881 | return SDValue(); |
| 4882 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4883 | EVT VMovVT; |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4884 | uint64_t iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 4885 | |
| 4886 | // It wouldn't really be worth bothering for doubles except for one very |
| 4887 | // important value, which does happen to match: 0.0. So make sure we don't do |
| 4888 | // anything stupid. |
| 4889 | if (IsDouble && (iVal & 0xffffffff) != (iVal >> 32)) |
| 4890 | return SDValue(); |
| 4891 | |
| 4892 | // Try a VMOV.i32 (FIXME: i8, i16, or i64 could work too). |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4893 | SDValue NewVal = isNEONModifiedImm(iVal & 0xffffffffU, 0, 32, DAG, SDLoc(Op), |
| 4894 | VMovVT, false, VMOVModImm); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4895 | if (NewVal != SDValue()) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4896 | SDLoc DL(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4897 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 4898 | NewVal); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4899 | if (IsDouble) |
| 4900 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); |
| 4901 | |
| 4902 | // It's a float: cast and extract a vector element. |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4903 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4904 | VecConstant); |
| 4905 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4906 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4907 | } |
| 4908 | |
| 4909 | // Finally, try a VMVN.i32 |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4910 | NewVal = isNEONModifiedImm(~iVal & 0xffffffffU, 0, 32, DAG, SDLoc(Op), VMovVT, |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4911 | false, VMVNModImm); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4912 | if (NewVal != SDValue()) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4913 | SDLoc DL(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4914 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 4915 | |
| 4916 | if (IsDouble) |
| 4917 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); |
| 4918 | |
| 4919 | // It's a float: cast and extract a vector element. |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4920 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 4921 | VecConstant); |
| 4922 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4923 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | return SDValue(); |
| 4927 | } |
| 4928 | |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 4929 | // check if an VEXT instruction can handle the shuffle mask when the |
| 4930 | // vector sources of the shuffle are the same. |
| 4931 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { |
| 4932 | unsigned NumElts = VT.getVectorNumElements(); |
| 4933 | |
| 4934 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4935 | if (M[0] < 0) |
| 4936 | return false; |
| 4937 | |
| 4938 | Imm = M[0]; |
| 4939 | |
| 4940 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4941 | // element. The other shuffle indices must be the successive elements after |
| 4942 | // the first one. |
| 4943 | unsigned ExpectedElt = Imm; |
| 4944 | for (unsigned i = 1; i < NumElts; ++i) { |
| 4945 | // Increment the expected index. If it wraps around, just follow it |
| 4946 | // back to index zero and keep going. |
| 4947 | ++ExpectedElt; |
| 4948 | if (ExpectedElt == NumElts) |
| 4949 | ExpectedElt = 0; |
| 4950 | |
| 4951 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 4952 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| 4953 | return false; |
| 4954 | } |
| 4955 | |
| 4956 | return true; |
| 4957 | } |
| 4958 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 4959 | |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4960 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4961 | bool &ReverseVEXT, unsigned &Imm) { |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4962 | unsigned NumElts = VT.getVectorNumElements(); |
| 4963 | ReverseVEXT = false; |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4964 | |
| 4965 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 4966 | if (M[0] < 0) |
| 4967 | return false; |
| 4968 | |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4969 | Imm = M[0]; |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4970 | |
| 4971 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 4972 | // element. The other shuffle indices must be the successive elements after |
| 4973 | // the first one. |
| 4974 | unsigned ExpectedElt = Imm; |
| 4975 | for (unsigned i = 1; i < NumElts; ++i) { |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4976 | // Increment the expected index. If it wraps around, it may still be |
| 4977 | // a VEXT but the source vectors must be swapped. |
| 4978 | ExpectedElt += 1; |
| 4979 | if (ExpectedElt == NumElts * 2) { |
| 4980 | ExpectedElt = 0; |
| 4981 | ReverseVEXT = true; |
| 4982 | } |
| 4983 | |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 4984 | if (M[i] < 0) continue; // ignore UNDEF indices |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4985 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4986 | return false; |
| 4987 | } |
| 4988 | |
| 4989 | // Adjust the index value if the source operands will be swapped. |
| 4990 | if (ReverseVEXT) |
| 4991 | Imm -= NumElts; |
| 4992 | |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4993 | return true; |
| 4994 | } |
| 4995 | |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 4996 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 4997 | /// instruction with the specified blocksize. (The order of the elements |
| 4998 | /// within each block of the vector is reversed.) |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 4999 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5000 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 5001 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 5002 | |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5003 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5004 | if (EltSz == 64) |
| 5005 | return false; |
| 5006 | |
| 5007 | unsigned NumElts = VT.getVectorNumElements(); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5008 | unsigned BlockElts = M[0] + 1; |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5009 | // If the first shuffle index is UNDEF, be optimistic. |
| 5010 | if (M[0] < 0) |
| 5011 | BlockElts = BlockSize / EltSz; |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5012 | |
| 5013 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 5014 | return false; |
| 5015 | |
| 5016 | for (unsigned i = 0; i < NumElts; ++i) { |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5017 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 5018 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5019 | return false; |
| 5020 | } |
| 5021 | |
| 5022 | return true; |
| 5023 | } |
| 5024 | |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5025 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
| Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 5026 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 5027 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 5028 | // of 8 elements can work here. |
| 5029 | return VT == MVT::v8i8 && M.size() == 8; |
| 5030 | } |
| 5031 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5032 | // Checks whether the shuffle mask represents a vector transpose (VTRN) by |
| 5033 | // checking that pairs of elements in the shuffle mask represent the same index |
| 5034 | // in each vector, incrementing the expected index by 2 at each step. |
| 5035 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 4, 2, 6] |
| 5036 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,e,c,g} |
| 5037 | // v2={e,f,g,h} |
| 5038 | // WhichResult gives the offset for each element in the mask based on which |
| 5039 | // of the two results it belongs to. |
| 5040 | // |
| 5041 | // The transpose can be represented either as: |
| 5042 | // result1 = shufflevector v1, v2, result1_shuffle_mask |
| 5043 | // result2 = shufflevector v1, v2, result2_shuffle_mask |
| 5044 | // where v1/v2 and the shuffle masks have the same number of elements |
| 5045 | // (here WhichResult (see below) indicates which result is being checked) |
| 5046 | // |
| 5047 | // or as: |
| 5048 | // results = shufflevector v1, v2, shuffle_mask |
| 5049 | // where both results are returned in one vector and the shuffle mask has twice |
| 5050 | // as many elements as v1/v2 (here WhichResult will always be 0 if true) here we |
| 5051 | // want to check the low half and high half of the shuffle mask as if it were |
| 5052 | // the other case |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5053 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5054 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5055 | if (EltSz == 64) |
| 5056 | return false; |
| 5057 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5058 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5059 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5060 | return false; |
| 5061 | |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5062 | // If the mask is twice as long as the input vector then we need to check the |
| 5063 | // upper and lower parts of the mask with a matching value for WhichResult |
| 5064 | // FIXME: A mask with only even values will be rejected in case the first |
| 5065 | // element is undefined, e.g. [-1, 4, 2, 6] will be rejected, because only |
| 5066 | // M[0] is used to determine WhichResult |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5067 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5068 | if (M.size() == NumElts * 2) |
| 5069 | WhichResult = i / NumElts; |
| 5070 | else |
| 5071 | WhichResult = M[i] == 0 ? 0 : 1; |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5072 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5073 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != j + WhichResult) || |
| 5074 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != j + NumElts + WhichResult)) |
| 5075 | return false; |
| 5076 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5077 | } |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5078 | |
| 5079 | if (M.size() == NumElts*2) |
| 5080 | WhichResult = 0; |
| 5081 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5082 | return true; |
| 5083 | } |
| 5084 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5085 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 5086 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5087 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5088 | static bool isVTRN_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5089 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5090 | if (EltSz == 64) |
| 5091 | return false; |
| 5092 | |
| 5093 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5094 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5095 | return false; |
| 5096 | |
| 5097 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5098 | if (M.size() == NumElts * 2) |
| 5099 | WhichResult = i / NumElts; |
| 5100 | else |
| 5101 | WhichResult = M[i] == 0 ? 0 : 1; |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5102 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5103 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != j + WhichResult) || |
| 5104 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != j + WhichResult)) |
| 5105 | return false; |
| 5106 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5107 | } |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5108 | |
| 5109 | if (M.size() == NumElts*2) |
| 5110 | WhichResult = 0; |
| 5111 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5112 | return true; |
| 5113 | } |
| 5114 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5115 | // Checks whether the shuffle mask represents a vector unzip (VUZP) by checking |
| 5116 | // that the mask elements are either all even and in steps of size 2 or all odd |
| 5117 | // and in steps of size 2. |
| 5118 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 2, 4, 6] |
| 5119 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,c,e,g} |
| 5120 | // v2={e,f,g,h} |
| 5121 | // Requires similar checks to that of isVTRNMask with |
| 5122 | // respect the how results are returned. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5123 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5124 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5125 | if (EltSz == 64) |
| 5126 | return false; |
| 5127 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5128 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5129 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5130 | return false; |
| 5131 | |
| 5132 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5133 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5134 | for (unsigned j = 0; j < NumElts; ++j) { |
| 5135 | if (M[i+j] >= 0 && (unsigned) M[i+j] != 2 * j + WhichResult) |
| 5136 | return false; |
| 5137 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5140 | if (M.size() == NumElts*2) |
| 5141 | WhichResult = 0; |
| 5142 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5143 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5144 | if (VT.is64BitVector() && EltSz == 32) |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5145 | return false; |
| 5146 | |
| 5147 | return true; |
| 5148 | } |
| 5149 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5150 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 5151 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5152 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5153 | static bool isVUZP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5154 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5155 | if (EltSz == 64) |
| 5156 | return false; |
| 5157 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5158 | unsigned NumElts = VT.getVectorNumElements(); |
| 5159 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5160 | return false; |
| 5161 | |
| 5162 | unsigned Half = NumElts / 2; |
| 5163 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5164 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5165 | for (unsigned j = 0; j < NumElts; j += Half) { |
| 5166 | unsigned Idx = WhichResult; |
| 5167 | for (unsigned k = 0; k < Half; ++k) { |
| 5168 | int MIdx = M[i + j + k]; |
| 5169 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
| 5170 | return false; |
| 5171 | Idx += 2; |
| 5172 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5173 | } |
| 5174 | } |
| 5175 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5176 | if (M.size() == NumElts*2) |
| 5177 | WhichResult = 0; |
| 5178 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5179 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 5180 | if (VT.is64BitVector() && EltSz == 32) |
| 5181 | return false; |
| 5182 | |
| 5183 | return true; |
| 5184 | } |
| 5185 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5186 | // Checks whether the shuffle mask represents a vector zip (VZIP) by checking |
| 5187 | // that pairs of elements of the shufflemask represent the same index in each |
| 5188 | // vector incrementing sequentially through the vectors. |
| 5189 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 4, 1, 5] |
| 5190 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,e,b,f} |
| 5191 | // v2={e,f,g,h} |
| 5192 | // Requires similar checks to that of isVTRNMask with respect the how results |
| 5193 | // are returned. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5194 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5195 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5196 | if (EltSz == 64) |
| 5197 | return false; |
| 5198 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5199 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5200 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5201 | return false; |
| 5202 | |
| 5203 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5204 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5205 | unsigned Idx = WhichResult * NumElts / 2; |
| 5206 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5207 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != Idx) || |
| 5208 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != Idx + NumElts)) |
| 5209 | return false; |
| 5210 | Idx += 1; |
| 5211 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5212 | } |
| 5213 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5214 | if (M.size() == NumElts*2) |
| 5215 | WhichResult = 0; |
| 5216 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5217 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5218 | if (VT.is64BitVector() && EltSz == 32) |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5219 | return false; |
| 5220 | |
| 5221 | return true; |
| 5222 | } |
| 5223 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5224 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 5225 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5226 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5227 | static bool isVZIP_v_undef_Mask(ArrayRef<int> M, EVT VT, unsigned &WhichResult){ |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5228 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5229 | if (EltSz == 64) |
| 5230 | return false; |
| 5231 | |
| 5232 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5233 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5234 | return false; |
| 5235 | |
| 5236 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5237 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5238 | unsigned Idx = WhichResult * NumElts / 2; |
| 5239 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5240 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != Idx) || |
| 5241 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != Idx)) |
| 5242 | return false; |
| 5243 | Idx += 1; |
| 5244 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5245 | } |
| 5246 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5247 | if (M.size() == NumElts*2) |
| 5248 | WhichResult = 0; |
| 5249 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5250 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 5251 | if (VT.is64BitVector() && EltSz == 32) |
| 5252 | return false; |
| 5253 | |
| 5254 | return true; |
| 5255 | } |
| 5256 | |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5257 | /// Check if \p ShuffleMask is a NEON two-result shuffle (VZIP, VUZP, VTRN), |
| 5258 | /// and return the corresponding ARMISD opcode if it is, or 0 if it isn't. |
| 5259 | static unsigned isNEONTwoResultShuffleMask(ArrayRef<int> ShuffleMask, EVT VT, |
| 5260 | unsigned &WhichResult, |
| 5261 | bool &isV_UNDEF) { |
| 5262 | isV_UNDEF = false; |
| 5263 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 5264 | return ARMISD::VTRN; |
| 5265 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 5266 | return ARMISD::VUZP; |
| 5267 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 5268 | return ARMISD::VZIP; |
| 5269 | |
| 5270 | isV_UNDEF = true; |
| 5271 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5272 | return ARMISD::VTRN; |
| 5273 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5274 | return ARMISD::VUZP; |
| 5275 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5276 | return ARMISD::VZIP; |
| 5277 | |
| 5278 | return 0; |
| 5279 | } |
| 5280 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5281 | /// \return true if this is a reverse operation on an vector. |
| 5282 | static bool isReverseMask(ArrayRef<int> M, EVT VT) { |
| 5283 | unsigned NumElts = VT.getVectorNumElements(); |
| 5284 | // Make sure the mask has the right size. |
| 5285 | if (NumElts != M.size()) |
| 5286 | return false; |
| 5287 | |
| 5288 | // Look for <15, ..., 3, -1, 1, 0>. |
| 5289 | for (unsigned i = 0; i != NumElts; ++i) |
| 5290 | if (M[i] >= 0 && M[i] != (int) (NumElts - 1 - i)) |
| 5291 | return false; |
| 5292 | |
| 5293 | return true; |
| 5294 | } |
| 5295 | |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5296 | // If N is an integer constant that can be moved into a register in one |
| 5297 | // instruction, return an SDValue of such a constant (will become a MOV |
| 5298 | // instruction). Otherwise return null. |
| 5299 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5300 | const ARMSubtarget *ST, SDLoc dl) { |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5301 | uint64_t Val; |
| 5302 | if (!isa<ConstantSDNode>(N)) |
| 5303 | return SDValue(); |
| 5304 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 5305 | |
| 5306 | if (ST->isThumb1Only()) { |
| 5307 | if (Val <= 255 || ~Val <= 255) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5308 | return DAG.getConstant(Val, dl, MVT::i32); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5309 | } else { |
| 5310 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5311 | return DAG.getConstant(Val, dl, MVT::i32); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5312 | } |
| 5313 | return SDValue(); |
| 5314 | } |
| 5315 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5316 | // If this is a case we can't handle, return null and let the default |
| 5317 | // expansion code take care of it. |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5318 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 5319 | const ARMSubtarget *ST) const { |
| Bob Wilson | fcd6361 | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 5320 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5321 | SDLoc dl(Op); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5322 | EVT VT = Op.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5323 | |
| 5324 | APInt SplatBits, SplatUndef; |
| 5325 | unsigned SplatBitSize; |
| 5326 | bool HasAnyUndefs; |
| 5327 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 5328 | if (SplatBitSize <= 64) { |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 5329 | // Check if an immediate VMOV works. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5330 | EVT VmovVT; |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 5331 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5332 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5333 | DAG, dl, VmovVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5334 | VMOVModImm); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5335 | if (Val.getNode()) { |
| 5336 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5337 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5338 | } |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5339 | |
| 5340 | // Try an immediate VMVN. |
| Eli Friedman | aa6ec39 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 5341 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5342 | Val = isNEONModifiedImm(NegatedImm, |
| 5343 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5344 | DAG, dl, VmovVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5345 | VMVNModImm); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5346 | if (Val.getNode()) { |
| 5347 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5348 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5349 | } |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5350 | |
| 5351 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
| Eli Friedman | c9bf1b1 | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 5352 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
| Eli Friedman | 4e36a93 | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 5353 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5354 | if (ImmVal != -1) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5355 | SDValue Val = DAG.getTargetConstant(ImmVal, dl, MVT::i32); |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5356 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 5357 | } |
| 5358 | } |
| Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 5359 | } |
| Bob Wilson | 0dbdec8 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 5360 | } |
| 5361 | |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5362 | // Scan through the operands to see if only one value is used. |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5363 | // |
| 5364 | // As an optimisation, even if more than one value is used it may be more |
| 5365 | // profitable to splat with one value then change some lanes. |
| 5366 | // |
| 5367 | // Heuristically we decide to do this if the vector has a "dominant" value, |
| 5368 | // defined as splatted to more than half of the lanes. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5369 | unsigned NumElts = VT.getVectorNumElements(); |
| 5370 | bool isOnlyLowElement = true; |
| 5371 | bool usesOnlyOneValue = true; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5372 | bool hasDominantValue = false; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5373 | bool isConstant = true; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5374 | |
| 5375 | // Map of the number of times a particular SDValue appears in the |
| 5376 | // element list. |
| James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 5377 | DenseMap<SDValue, unsigned> ValueCounts; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5378 | SDValue Value; |
| 5379 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5380 | SDValue V = Op.getOperand(i); |
| 5381 | if (V.getOpcode() == ISD::UNDEF) |
| 5382 | continue; |
| 5383 | if (i > 0) |
| 5384 | isOnlyLowElement = false; |
| 5385 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 5386 | isConstant = false; |
| 5387 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5388 | ValueCounts.insert(std::make_pair(V, 0)); |
| James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 5389 | unsigned &Count = ValueCounts[V]; |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 5390 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5391 | // Is this value dominant? (takes up more than half of the lanes) |
| 5392 | if (++Count > (NumElts / 2)) { |
| 5393 | hasDominantValue = true; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5394 | Value = V; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5395 | } |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5396 | } |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5397 | if (ValueCounts.size() != 1) |
| 5398 | usesOnlyOneValue = false; |
| 5399 | if (!Value.getNode() && ValueCounts.size() > 0) |
| 5400 | Value = ValueCounts.begin()->first; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5401 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5402 | if (ValueCounts.size() == 0) |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5403 | return DAG.getUNDEF(VT); |
| 5404 | |
| Quentin Colombet | 0f2fe74 | 2013-07-23 22:34:47 +0000 | [diff] [blame] | 5405 | // Loads are better lowered with insert_vector_elt/ARMISD::BUILD_VECTOR. |
| 5406 | // Keep going if we are hitting this case. |
| 5407 | if (isOnlyLowElement && !ISD::isNormalLoad(Value.getNode())) |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5408 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 5409 | |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5410 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5411 | |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5412 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 5413 | // i32 and try again. |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5414 | if (hasDominantValue && EltSize <= 32) { |
| 5415 | if (!isConstant) { |
| 5416 | SDValue N; |
| 5417 | |
| 5418 | // If we are VDUPing a value that comes directly from a vector, that will |
| 5419 | // cause an unnecessary move to and from a GPR, where instead we could |
| Jim Grosbach | a3c5c76 | 2013-03-02 20:16:24 +0000 | [diff] [blame] | 5420 | // just use VDUPLANE. We can only do this if the lane being extracted |
| 5421 | // is at a constant index, as the VDUP from lane instructions only have |
| 5422 | // constant-index forms. |
| 5423 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT && |
| 5424 | isa<ConstantSDNode>(Value->getOperand(1))) { |
| Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5425 | // We need to create a new undef vector to use for the VDUPLANE if the |
| 5426 | // size of the vector from which we get the value is different than the |
| 5427 | // size of the vector that we need to create. We will insert the element |
| 5428 | // such that the register coalescer will remove unnecessary copies. |
| 5429 | if (VT != Value->getOperand(0).getValueType()) { |
| 5430 | ConstantSDNode *constIndex; |
| 5431 | constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)); |
| 5432 | assert(constIndex && "The index is not a constant!"); |
| 5433 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % |
| 5434 | VT.getVectorNumElements(); |
| 5435 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| 5436 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5437 | Value, DAG.getConstant(index, dl, MVT::i32)), |
| 5438 | DAG.getConstant(index, dl, MVT::i32)); |
| Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5439 | } else |
| Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5440 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5441 | Value->getOperand(0), Value->getOperand(1)); |
| Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5442 | } else |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5443 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 5444 | |
| 5445 | if (!usesOnlyOneValue) { |
| 5446 | // The dominant value was splatted as 'N', but we now have to insert |
| 5447 | // all differing elements. |
| 5448 | for (unsigned I = 0; I < NumElts; ++I) { |
| 5449 | if (Op.getOperand(I) == Value) |
| 5450 | continue; |
| 5451 | SmallVector<SDValue, 3> Ops; |
| 5452 | Ops.push_back(N); |
| 5453 | Ops.push_back(Op.getOperand(I)); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5454 | Ops.push_back(DAG.getConstant(I, dl, MVT::i32)); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5455 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Ops); |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5456 | } |
| 5457 | } |
| 5458 | return N; |
| 5459 | } |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5460 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 5461 | SmallVector<SDValue, 8> Ops; |
| 5462 | for (unsigned i = 0; i < NumElts; ++i) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5463 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5464 | Op.getOperand(i))); |
| Nate Begeman | ca52411 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 5465 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5466 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Dale Johannesen | ff37675 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 5467 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 5468 | if (Val.getNode()) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5469 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5470 | } |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5471 | if (usesOnlyOneValue) { |
| 5472 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 5473 | if (isConstant && Val.getNode()) |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 5474 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5475 | } |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5476 | } |
| 5477 | |
| 5478 | // If all elements are constants and the case above didn't get hit, fall back |
| 5479 | // to the default expansion, which will generate a load from the constant |
| 5480 | // pool. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5481 | if (isConstant) |
| 5482 | return SDValue(); |
| 5483 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5484 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 5485 | if (NumElts >= 4) { |
| 5486 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 5487 | if (shuffle != SDValue()) |
| 5488 | return shuffle; |
| 5489 | } |
| 5490 | |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5491 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5492 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 5493 | // will be legalized. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5494 | if (EltSize >= 32) { |
| 5495 | // Do the expansion with floating-point types, since that is what the VFP |
| 5496 | // registers are defined to use, and since i64 is not legal. |
| 5497 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 5498 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5499 | SmallVector<SDValue, 8> Ops; |
| 5500 | for (unsigned i = 0; i < NumElts; ++i) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5501 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5502 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5503 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5504 | } |
| 5505 | |
| Jim Grosbach | 24e102a | 2013-07-08 18:18:52 +0000 | [diff] [blame] | 5506 | // If all else fails, just use a sequence of INSERT_VECTOR_ELT when we |
| 5507 | // know the default expansion would otherwise fall back on something even |
| 5508 | // worse. For a vector with one or two non-undef values, that's |
| 5509 | // scalar_to_vector for the elements followed by a shuffle (provided the |
| 5510 | // shuffle is valid for the target) and materialization element by element |
| 5511 | // on the stack followed by a load for everything else. |
| 5512 | if (!isConstant && !usesOnlyOneValue) { |
| 5513 | SDValue Vec = DAG.getUNDEF(VT); |
| 5514 | for (unsigned i = 0 ; i < NumElts; ++i) { |
| 5515 | SDValue V = Op.getOperand(i); |
| 5516 | if (V.getOpcode() == ISD::UNDEF) |
| 5517 | continue; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5518 | SDValue LaneIdx = DAG.getConstant(i, dl, MVT::i32); |
| Jim Grosbach | 24e102a | 2013-07-08 18:18:52 +0000 | [diff] [blame] | 5519 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Vec, V, LaneIdx); |
| 5520 | } |
| 5521 | return Vec; |
| 5522 | } |
| 5523 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5524 | return SDValue(); |
| 5525 | } |
| 5526 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5527 | // Gather data to see if the operation can be modelled as a |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5528 | // shuffle in combination with VEXTs. |
| Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5529 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 5530 | SelectionDAG &DAG) const { |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5531 | assert(Op.getOpcode() == ISD::BUILD_VECTOR && "Unknown opcode!"); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5532 | SDLoc dl(Op); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5533 | EVT VT = Op.getValueType(); |
| 5534 | unsigned NumElts = VT.getVectorNumElements(); |
| 5535 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5536 | struct ShuffleSourceInfo { |
| 5537 | SDValue Vec; |
| 5538 | unsigned MinElt; |
| 5539 | unsigned MaxElt; |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5540 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5541 | // We may insert some combination of BITCASTs and VEXT nodes to force Vec to |
| 5542 | // be compatible with the shuffle we intend to construct. As a result |
| 5543 | // ShuffleVec will be some sliding window into the original Vec. |
| 5544 | SDValue ShuffleVec; |
| 5545 | |
| 5546 | // Code should guarantee that element i in Vec starts at element "WindowBase |
| 5547 | // + i * WindowScale in ShuffleVec". |
| 5548 | int WindowBase; |
| 5549 | int WindowScale; |
| 5550 | |
| 5551 | bool operator ==(SDValue OtherVec) { return Vec == OtherVec; } |
| 5552 | ShuffleSourceInfo(SDValue Vec) |
| 5553 | : Vec(Vec), MinElt(UINT_MAX), MaxElt(0), ShuffleVec(Vec), WindowBase(0), |
| 5554 | WindowScale(1) {} |
| 5555 | }; |
| 5556 | |
| 5557 | // First gather all vectors used as an immediate source for this BUILD_VECTOR |
| 5558 | // node. |
| 5559 | SmallVector<ShuffleSourceInfo, 2> Sources; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5560 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5561 | SDValue V = Op.getOperand(i); |
| 5562 | if (V.getOpcode() == ISD::UNDEF) |
| 5563 | continue; |
| 5564 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 5565 | // A shuffle can only come from building a vector from various |
| 5566 | // elements of other vectors. |
| 5567 | return SDValue(); |
| Ahmed Bougacha | 699a9dd | 2015-09-01 21:56:00 +0000 | [diff] [blame] | 5568 | } else if (!isa<ConstantSDNode>(V.getOperand(1))) { |
| 5569 | // Furthermore, shuffles require a constant mask, whereas extractelts |
| 5570 | // accept variable indices. |
| 5571 | return SDValue(); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5572 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5573 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5574 | // Add this element source to the list if it's not already there. |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5575 | SDValue SourceVec = V.getOperand(0); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5576 | auto Source = std::find(Sources.begin(), Sources.end(), SourceVec); |
| 5577 | if (Source == Sources.end()) |
| 5578 | Source = Sources.insert(Sources.end(), ShuffleSourceInfo(SourceVec)); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5579 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5580 | // Update the minimum and maximum lane number seen. |
| 5581 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 5582 | Source->MinElt = std::min(Source->MinElt, EltNo); |
| 5583 | Source->MaxElt = std::max(Source->MaxElt, EltNo); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5584 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5585 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5586 | // Currently only do something sane when at most two source vectors |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5587 | // are involved. |
| 5588 | if (Sources.size() > 2) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5589 | return SDValue(); |
| 5590 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5591 | // Find out the smallest element size among result and two sources, and use |
| 5592 | // it as element size to build the shuffle_vector. |
| 5593 | EVT SmallestEltTy = VT.getVectorElementType(); |
| 5594 | for (auto &Source : Sources) { |
| 5595 | EVT SrcEltTy = Source.Vec.getValueType().getVectorElementType(); |
| 5596 | if (SrcEltTy.bitsLT(SmallestEltTy)) |
| 5597 | SmallestEltTy = SrcEltTy; |
| 5598 | } |
| 5599 | unsigned ResMultiplier = |
| 5600 | VT.getVectorElementType().getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5601 | NumElts = VT.getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5602 | EVT ShuffleVT = EVT::getVectorVT(*DAG.getContext(), SmallestEltTy, NumElts); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5603 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5604 | // If the source vector is too wide or too narrow, we may nevertheless be able |
| 5605 | // to construct a compatible shuffle either by concatenating it with UNDEF or |
| 5606 | // extracting a suitable range of elements. |
| 5607 | for (auto &Src : Sources) { |
| 5608 | EVT SrcVT = Src.ShuffleVec.getValueType(); |
| 5609 | |
| 5610 | if (SrcVT.getSizeInBits() == VT.getSizeInBits()) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5611 | continue; |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5612 | |
| 5613 | // This stage of the search produces a source with the same element type as |
| 5614 | // the original, but with a total width matching the BUILD_VECTOR output. |
| 5615 | EVT EltVT = SrcVT.getVectorElementType(); |
| 5616 | unsigned NumSrcElts = VT.getSizeInBits() / EltVT.getSizeInBits(); |
| 5617 | EVT DestVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumSrcElts); |
| 5618 | |
| 5619 | if (SrcVT.getSizeInBits() < VT.getSizeInBits()) { |
| 5620 | if (2 * SrcVT.getSizeInBits() != VT.getSizeInBits()) |
| 5621 | return SDValue(); |
| 5622 | // We can pad out the smaller vector for free, so if it's part of a |
| 5623 | // shuffle... |
| 5624 | Src.ShuffleVec = |
| 5625 | DAG.getNode(ISD::CONCAT_VECTORS, dl, DestVT, Src.ShuffleVec, |
| 5626 | DAG.getUNDEF(Src.ShuffleVec.getValueType())); |
| 5627 | continue; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5628 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5629 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5630 | if (SrcVT.getSizeInBits() != 2 * VT.getSizeInBits()) |
| 5631 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5632 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5633 | if (Src.MaxElt - Src.MinElt >= NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5634 | // Span too large for a VEXT to cope |
| 5635 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5638 | if (Src.MinElt >= NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5639 | // The extraction can just take the second half |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5640 | Src.ShuffleVec = |
| 5641 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5642 | DAG.getConstant(NumSrcElts, dl, MVT::i32)); |
| 5643 | Src.WindowBase = -NumSrcElts; |
| 5644 | } else if (Src.MaxElt < NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5645 | // The extraction can just take the first half |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5646 | Src.ShuffleVec = |
| 5647 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5648 | DAG.getConstant(0, dl, MVT::i32)); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5649 | } else { |
| 5650 | // An actual VEXT is needed |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5651 | SDValue VEXTSrc1 = |
| 5652 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5653 | DAG.getConstant(0, dl, MVT::i32)); |
| 5654 | SDValue VEXTSrc2 = |
| 5655 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5656 | DAG.getConstant(NumSrcElts, dl, MVT::i32)); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5657 | |
| 5658 | Src.ShuffleVec = DAG.getNode(ARMISD::VEXT, dl, DestVT, VEXTSrc1, |
| 5659 | VEXTSrc2, |
| Jeroen Ketema | 41681a5 | 2015-09-21 20:28:04 +0000 | [diff] [blame] | 5660 | DAG.getConstant(Src.MinElt, dl, MVT::i32)); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5661 | Src.WindowBase = -Src.MinElt; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5662 | } |
| 5663 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5664 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5665 | // Another possible incompatibility occurs from the vector element types. We |
| 5666 | // can fix this by bitcasting the source vectors to the same type we intend |
| 5667 | // for the shuffle. |
| 5668 | for (auto &Src : Sources) { |
| 5669 | EVT SrcEltTy = Src.ShuffleVec.getValueType().getVectorElementType(); |
| 5670 | if (SrcEltTy == SmallestEltTy) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5671 | continue; |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5672 | assert(ShuffleVT.getVectorElementType() == SmallestEltTy); |
| 5673 | Src.ShuffleVec = DAG.getNode(ISD::BITCAST, dl, ShuffleVT, Src.ShuffleVec); |
| 5674 | Src.WindowScale = SrcEltTy.getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5675 | Src.WindowBase *= Src.WindowScale; |
| 5676 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5677 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5678 | // Final sanity check before we try to actually produce a shuffle. |
| Silviu Baranga | a07090f | 2015-08-07 12:05:46 +0000 | [diff] [blame] | 5679 | DEBUG( |
| 5680 | for (auto Src : Sources) |
| 5681 | assert(Src.ShuffleVec.getValueType() == ShuffleVT); |
| 5682 | ); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5683 | |
| 5684 | // The stars all align, our next step is to produce the mask for the shuffle. |
| 5685 | SmallVector<int, 8> Mask(ShuffleVT.getVectorNumElements(), -1); |
| 5686 | int BitsPerShuffleLane = ShuffleVT.getVectorElementType().getSizeInBits(); |
| 5687 | for (unsigned i = 0; i < VT.getVectorNumElements(); ++i) { |
| 5688 | SDValue Entry = Op.getOperand(i); |
| 5689 | if (Entry.getOpcode() == ISD::UNDEF) |
| 5690 | continue; |
| 5691 | |
| 5692 | auto Src = std::find(Sources.begin(), Sources.end(), Entry.getOperand(0)); |
| 5693 | int EltNo = cast<ConstantSDNode>(Entry.getOperand(1))->getSExtValue(); |
| 5694 | |
| 5695 | // EXTRACT_VECTOR_ELT performs an implicit any_ext; BUILD_VECTOR an implicit |
| 5696 | // trunc. So only std::min(SrcBits, DestBits) actually get defined in this |
| 5697 | // segment. |
| 5698 | EVT OrigEltTy = Entry.getOperand(0).getValueType().getVectorElementType(); |
| 5699 | int BitsDefined = std::min(OrigEltTy.getSizeInBits(), |
| 5700 | VT.getVectorElementType().getSizeInBits()); |
| 5701 | int LanesDefined = BitsDefined / BitsPerShuffleLane; |
| 5702 | |
| 5703 | // This source is expected to fill ResMultiplier lanes of the final shuffle, |
| 5704 | // starting at the appropriate offset. |
| 5705 | int *LaneMask = &Mask[i * ResMultiplier]; |
| 5706 | |
| 5707 | int ExtractBase = EltNo * Src->WindowScale + Src->WindowBase; |
| 5708 | ExtractBase += NumElts * (Src - Sources.begin()); |
| 5709 | for (int j = 0; j < LanesDefined; ++j) |
| 5710 | LaneMask[j] = ExtractBase + j; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5711 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5712 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5713 | // Final check before we try to produce nonsense... |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5714 | if (!isShuffleMaskLegal(Mask, ShuffleVT)) |
| 5715 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5716 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5717 | // We can't handle more than two sources. This should have already |
| 5718 | // been checked before this point. |
| 5719 | assert(Sources.size() <= 2 && "Too many sources!"); |
| 5720 | |
| 5721 | SDValue ShuffleOps[] = { DAG.getUNDEF(ShuffleVT), DAG.getUNDEF(ShuffleVT) }; |
| 5722 | for (unsigned i = 0; i < Sources.size(); ++i) |
| 5723 | ShuffleOps[i] = Sources[i].ShuffleVec; |
| 5724 | |
| 5725 | SDValue Shuffle = DAG.getVectorShuffle(ShuffleVT, dl, ShuffleOps[0], |
| 5726 | ShuffleOps[1], &Mask[0]); |
| 5727 | return DAG.getNode(ISD::BITCAST, dl, VT, Shuffle); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5728 | } |
| 5729 | |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5730 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 5731 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 5732 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 5733 | /// are assumed to be legal. |
| 5734 | bool |
| 5735 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 5736 | EVT VT) const { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5737 | if (VT.getVectorNumElements() == 4 && |
| 5738 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 5739 | unsigned PFIndexes[4]; |
| 5740 | for (unsigned i = 0; i != 4; ++i) { |
| 5741 | if (M[i] < 0) |
| 5742 | PFIndexes[i] = 8; |
| 5743 | else |
| 5744 | PFIndexes[i] = M[i]; |
| 5745 | } |
| 5746 | |
| 5747 | // Compute the index in the perfect shuffle table. |
| 5748 | unsigned PFTableIndex = |
| 5749 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 5750 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 5751 | unsigned Cost = (PFEntry >> 30); |
| 5752 | |
| 5753 | if (Cost <= 4) |
| 5754 | return true; |
| 5755 | } |
| 5756 | |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5757 | bool ReverseVEXT, isV_UNDEF; |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5758 | unsigned Imm, WhichResult; |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5759 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5760 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5761 | return (EltSize >= 32 || |
| 5762 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5763 | isVREVMask(M, VT, 64) || |
| 5764 | isVREVMask(M, VT, 32) || |
| 5765 | isVREVMask(M, VT, 16) || |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5766 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
| Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 5767 | isVTBLMask(M, VT) || |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5768 | isNEONTwoResultShuffleMask(M, VT, WhichResult, isV_UNDEF) || |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5769 | ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(M, VT))); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5770 | } |
| 5771 | |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5772 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 5773 | /// the specified operations to build the shuffle. |
| 5774 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 5775 | SDValue RHS, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5776 | SDLoc dl) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5777 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 5778 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 5779 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 5780 | |
| 5781 | enum { |
| 5782 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 5783 | OP_VREV, |
| 5784 | OP_VDUP0, |
| 5785 | OP_VDUP1, |
| 5786 | OP_VDUP2, |
| 5787 | OP_VDUP3, |
| 5788 | OP_VEXT1, |
| 5789 | OP_VEXT2, |
| 5790 | OP_VEXT3, |
| 5791 | OP_VUZPL, // VUZP, left result |
| 5792 | OP_VUZPR, // VUZP, right result |
| 5793 | OP_VZIPL, // VZIP, left result |
| 5794 | OP_VZIPR, // VZIP, right result |
| 5795 | OP_VTRNL, // VTRN, left result |
| 5796 | OP_VTRNR // VTRN, right result |
| 5797 | }; |
| 5798 | |
| 5799 | if (OpNum == OP_COPY) { |
| 5800 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 5801 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 5802 | return RHS; |
| 5803 | } |
| 5804 | |
| 5805 | SDValue OpLHS, OpRHS; |
| 5806 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 5807 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 5808 | EVT VT = OpLHS.getValueType(); |
| 5809 | |
| 5810 | switch (OpNum) { |
| 5811 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 5812 | case OP_VREV: |
| Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5813 | // VREV divides the vector in half and swaps within the half. |
| Tanya Lattner | 1d11720 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 5814 | if (VT.getVectorElementType() == MVT::i32 || |
| 5815 | VT.getVectorElementType() == MVT::f32) |
| Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5816 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 5817 | // vrev <4 x i16> -> VREV32 |
| 5818 | if (VT.getVectorElementType() == MVT::i16) |
| 5819 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 5820 | // vrev <4 x i8> -> VREV16 |
| 5821 | assert(VT.getVectorElementType() == MVT::i8); |
| 5822 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5823 | case OP_VDUP0: |
| 5824 | case OP_VDUP1: |
| 5825 | case OP_VDUP2: |
| 5826 | case OP_VDUP3: |
| 5827 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5828 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, dl, MVT::i32)); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5829 | case OP_VEXT1: |
| 5830 | case OP_VEXT2: |
| 5831 | case OP_VEXT3: |
| 5832 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 5833 | OpLHS, OpRHS, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5834 | DAG.getConstant(OpNum - OP_VEXT1 + 1, dl, MVT::i32)); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5835 | case OP_VUZPL: |
| 5836 | case OP_VUZPR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5837 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5838 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 5839 | case OP_VZIPL: |
| 5840 | case OP_VZIPR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5841 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5842 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 5843 | case OP_VTRNL: |
| 5844 | case OP_VTRNR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 5845 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 5846 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5847 | } |
| 5848 | } |
| 5849 | |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5850 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5851 | ArrayRef<int> ShuffleMask, |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5852 | SelectionDAG &DAG) { |
| 5853 | // Check to see if we can use the VTBL instruction. |
| 5854 | SDValue V1 = Op.getOperand(0); |
| 5855 | SDValue V2 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5856 | SDLoc DL(Op); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5857 | |
| 5858 | SmallVector<SDValue, 8> VTBLMask; |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5859 | for (ArrayRef<int>::iterator |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5860 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5861 | VTBLMask.push_back(DAG.getConstant(*I, DL, MVT::i32)); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5862 | |
| 5863 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 5864 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5865 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
| Bill Wendling | ebecb33 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 5866 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5867 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5868 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 5869 | } |
| 5870 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5871 | static SDValue LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(SDValue Op, |
| 5872 | SelectionDAG &DAG) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5873 | SDLoc DL(Op); |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5874 | SDValue OpLHS = Op.getOperand(0); |
| 5875 | EVT VT = OpLHS.getValueType(); |
| 5876 | |
| 5877 | assert((VT == MVT::v8i16 || VT == MVT::v16i8) && |
| 5878 | "Expect an v8i16/v16i8 type"); |
| 5879 | OpLHS = DAG.getNode(ARMISD::VREV64, DL, VT, OpLHS); |
| 5880 | // For a v16i8 type: After the VREV, we have got <8, ...15, 8, ..., 0>. Now, |
| 5881 | // extract the first 8 bytes into the top double word and the last 8 bytes |
| 5882 | // into the bottom double word. The v8i16 case is similar. |
| 5883 | unsigned ExtractNum = (VT == MVT::v16i8) ? 8 : 4; |
| 5884 | return DAG.getNode(ARMISD::VEXT, DL, VT, OpLHS, OpLHS, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5885 | DAG.getConstant(ExtractNum, DL, MVT::i32)); |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5886 | } |
| 5887 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5888 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5889 | SDValue V1 = Op.getOperand(0); |
| 5890 | SDValue V2 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5891 | SDLoc dl(Op); |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5892 | EVT VT = Op.getValueType(); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5893 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 5894 | |
| Bob Wilson | c6800b5 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 5895 | // Convert shuffles that are directly supported on NEON to target-specific |
| 5896 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 5897 | // during code selection. This is more efficient and avoids the possibility |
| 5898 | // of inconsistencies between legalization and selection. |
| Bob Wilson | 3e4c012 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 5899 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 5900 | // of the same time so that they get CSEd properly. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5901 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5902 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5903 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5904 | if (EltSize <= 32) { |
| 5905 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 5906 | int Lane = SVN->getSplatIndex(); |
| 5907 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 5908 | if (Lane == -1) Lane = 0; |
| Anton Korobeynikov | 4d23754 | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 5909 | |
| Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5910 | // Test if V1 is a SCALAR_TO_VECTOR. |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5911 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 5912 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 5913 | } |
| Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 5914 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 5915 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 5916 | // reaches it). |
| 5917 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 5918 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 5919 | bool IsScalarToVector = true; |
| 5920 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 5921 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 5922 | IsScalarToVector = false; |
| 5923 | break; |
| 5924 | } |
| 5925 | if (IsScalarToVector) |
| 5926 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 5927 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5928 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5929 | DAG.getConstant(Lane, dl, MVT::i32)); |
| Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 5930 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5931 | |
| 5932 | bool ReverseVEXT; |
| 5933 | unsigned Imm; |
| 5934 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 5935 | if (ReverseVEXT) |
| 5936 | std::swap(V1, V2); |
| 5937 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5938 | DAG.getConstant(Imm, dl, MVT::i32)); |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 5942 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 5943 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 5944 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 5945 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 5946 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 5947 | |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 5948 | if (V2->getOpcode() == ISD::UNDEF && |
| 5949 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { |
| 5950 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5951 | DAG.getConstant(Imm, dl, MVT::i32)); |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 5952 | } |
| 5953 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5954 | // Check for Neon shuffles that modify both input vectors in place. |
| 5955 | // If both results are used, i.e., if there are two shuffles with the same |
| 5956 | // source operands and with masks corresponding to both results of one of |
| 5957 | // these operations, DAG memoization will ensure that a single node is |
| 5958 | // used for both shuffles. |
| 5959 | unsigned WhichResult; |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5960 | bool isV_UNDEF; |
| 5961 | if (unsigned ShuffleOpc = isNEONTwoResultShuffleMask( |
| 5962 | ShuffleMask, VT, WhichResult, isV_UNDEF)) { |
| 5963 | if (isV_UNDEF) |
| 5964 | V2 = V1; |
| 5965 | return DAG.getNode(ShuffleOpc, dl, DAG.getVTList(VT, VT), V1, V2) |
| 5966 | .getValue(WhichResult); |
| 5967 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5968 | |
| Ahmed Bougacha | 9a90942 | 2015-06-19 02:32:35 +0000 | [diff] [blame] | 5969 | // Also check for these shuffles through CONCAT_VECTORS: we canonicalize |
| 5970 | // shuffles that produce a result larger than their operands with: |
| 5971 | // shuffle(concat(v1, undef), concat(v2, undef)) |
| 5972 | // -> |
| 5973 | // shuffle(concat(v1, v2), undef) |
| 5974 | // because we can access quad vectors (see PerformVECTOR_SHUFFLECombine). |
| 5975 | // |
| 5976 | // This is useful in the general case, but there are special cases where |
| 5977 | // native shuffles produce larger results: the two-result ops. |
| 5978 | // |
| 5979 | // Look through the concat when lowering them: |
| 5980 | // shuffle(concat(v1, v2), undef) |
| 5981 | // -> |
| 5982 | // concat(VZIP(v1, v2):0, :1) |
| 5983 | // |
| 5984 | if (V1->getOpcode() == ISD::CONCAT_VECTORS && |
| 5985 | V2->getOpcode() == ISD::UNDEF) { |
| 5986 | SDValue SubV1 = V1->getOperand(0); |
| 5987 | SDValue SubV2 = V1->getOperand(1); |
| 5988 | EVT SubVT = SubV1.getValueType(); |
| 5989 | |
| 5990 | // We expect these to have been canonicalized to -1. |
| 5991 | assert(std::all_of(ShuffleMask.begin(), ShuffleMask.end(), [&](int i) { |
| 5992 | return i < (int)VT.getVectorNumElements(); |
| 5993 | }) && "Unexpected shuffle index into UNDEF operand!"); |
| 5994 | |
| 5995 | if (unsigned ShuffleOpc = isNEONTwoResultShuffleMask( |
| 5996 | ShuffleMask, SubVT, WhichResult, isV_UNDEF)) { |
| 5997 | if (isV_UNDEF) |
| 5998 | SubV2 = SubV1; |
| 5999 | assert((WhichResult == 0) && |
| 6000 | "In-place shuffle of concat can only have one result!"); |
| 6001 | SDValue Res = DAG.getNode(ShuffleOpc, dl, DAG.getVTList(SubVT, SubVT), |
| 6002 | SubV1, SubV2); |
| 6003 | return DAG.getNode(ISD::CONCAT_VECTORS, dl, VT, Res.getValue(0), |
| 6004 | Res.getValue(1)); |
| 6005 | } |
| 6006 | } |
| Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 6007 | } |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 6008 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 6009 | // If the shuffle is not directly supported and it has 4 elements, use |
| 6010 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6011 | unsigned NumElts = VT.getVectorNumElements(); |
| 6012 | if (NumElts == 4) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6013 | unsigned PFIndexes[4]; |
| 6014 | for (unsigned i = 0; i != 4; ++i) { |
| 6015 | if (ShuffleMask[i] < 0) |
| 6016 | PFIndexes[i] = 8; |
| 6017 | else |
| 6018 | PFIndexes[i] = ShuffleMask[i]; |
| 6019 | } |
| 6020 | |
| 6021 | // Compute the index in the perfect shuffle table. |
| 6022 | unsigned PFTableIndex = |
| 6023 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6024 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 6025 | unsigned Cost = (PFEntry >> 30); |
| 6026 | |
| 6027 | if (Cost <= 4) |
| 6028 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 6029 | } |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 6030 | |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6031 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6032 | if (EltSize >= 32) { |
| 6033 | // Do the expansion with floating-point types, since that is what the VFP |
| 6034 | // registers are defined to use, and since i64 is not legal. |
| 6035 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 6036 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6037 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 6038 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6039 | SmallVector<SDValue, 8> Ops; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6040 | for (unsigned i = 0; i < NumElts; ++i) { |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6041 | if (ShuffleMask[i] < 0) |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6042 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 6043 | else |
| 6044 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 6045 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 6046 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6047 | dl, MVT::i32))); |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6048 | } |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6049 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6050 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 6053 | if ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(ShuffleMask, VT)) |
| 6054 | return LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(Op, DAG); |
| 6055 | |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6056 | if (VT == MVT::v8i8) { |
| 6057 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 6058 | if (NewOp.getNode()) |
| 6059 | return NewOp; |
| 6060 | } |
| 6061 | |
| Bob Wilson | 6f34e27 | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 6062 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6063 | } |
| 6064 | |
| Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 6065 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 6066 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 6067 | SDValue Lane = Op.getOperand(2); |
| 6068 | if (!isa<ConstantSDNode>(Lane)) |
| 6069 | return SDValue(); |
| 6070 | |
| 6071 | return Op; |
| 6072 | } |
| 6073 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6074 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6075 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6076 | SDValue Lane = Op.getOperand(1); |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6077 | if (!isa<ConstantSDNode>(Lane)) |
| 6078 | return SDValue(); |
| 6079 | |
| 6080 | SDValue Vec = Op.getOperand(0); |
| 6081 | if (Op.getValueType() == MVT::i32 && |
| 6082 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6083 | SDLoc dl(Op); |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6084 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 6085 | } |
| 6086 | |
| 6087 | return Op; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6088 | } |
| 6089 | |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6090 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 6091 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 6092 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 6093 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 6094 | "unexpected CONCAT_VECTORS"); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6095 | SDLoc dl(Op); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6096 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6097 | SDValue Op0 = Op.getOperand(0); |
| 6098 | SDValue Op1 = Op.getOperand(1); |
| 6099 | if (Op0.getOpcode() != ISD::UNDEF) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6100 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6101 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6102 | DAG.getIntPtrConstant(0, dl)); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6103 | if (Op1.getOpcode() != ISD::UNDEF) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6104 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6105 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6106 | DAG.getIntPtrConstant(1, dl)); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6107 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6108 | } |
| 6109 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6110 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 6111 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 6112 | /// from an integer type half its size. |
| 6113 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 6114 | bool isSigned) { |
| 6115 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 6116 | EVT VT = N->getValueType(0); |
| 6117 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 6118 | SDNode *BVN = N->getOperand(0).getNode(); |
| 6119 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 6120 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 6121 | return false; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 6122 | unsigned LoElt = DAG.getDataLayout().isBigEndian() ? 1 : 0; |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6123 | unsigned HiElt = 1 - LoElt; |
| 6124 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 6125 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 6126 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 6127 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 6128 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 6129 | return false; |
| 6130 | if (isSigned) { |
| 6131 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 6132 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 6133 | return true; |
| 6134 | } else { |
| 6135 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 6136 | return true; |
| 6137 | } |
| 6138 | return false; |
| 6139 | } |
| 6140 | |
| 6141 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 6142 | return false; |
| 6143 | |
| 6144 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 6145 | SDNode *Elt = N->getOperand(i).getNode(); |
| 6146 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 6147 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 6148 | unsigned HalfSize = EltSize / 2; |
| 6149 | if (isSigned) { |
| Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 6150 | if (!isIntN(HalfSize, C->getSExtValue())) |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6151 | return false; |
| 6152 | } else { |
| Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 6153 | if (!isUIntN(HalfSize, C->getZExtValue())) |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6154 | return false; |
| 6155 | } |
| 6156 | continue; |
| 6157 | } |
| 6158 | return false; |
| 6159 | } |
| 6160 | |
| 6161 | return true; |
| 6162 | } |
| 6163 | |
| 6164 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 6165 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 6166 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 6167 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 6168 | return true; |
| 6169 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 6170 | return true; |
| 6171 | return false; |
| 6172 | } |
| 6173 | |
| 6174 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 6175 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 6176 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 6177 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 6178 | return true; |
| 6179 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 6180 | return true; |
| 6181 | return false; |
| 6182 | } |
| 6183 | |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6184 | static EVT getExtensionTo64Bits(const EVT &OrigVT) { |
| 6185 | if (OrigVT.getSizeInBits() >= 64) |
| 6186 | return OrigVT; |
| 6187 | |
| 6188 | assert(OrigVT.isSimple() && "Expecting a simple value type"); |
| 6189 | |
| 6190 | MVT::SimpleValueType OrigSimpleTy = OrigVT.getSimpleVT().SimpleTy; |
| 6191 | switch (OrigSimpleTy) { |
| 6192 | default: llvm_unreachable("Unexpected Vector Type"); |
| 6193 | case MVT::v2i8: |
| 6194 | case MVT::v2i16: |
| 6195 | return MVT::v2i32; |
| 6196 | case MVT::v4i8: |
| 6197 | return MVT::v4i16; |
| 6198 | } |
| 6199 | } |
| 6200 | |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6201 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
| 6202 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. |
| 6203 | /// We insert the required extension here to get the vector to fill a D register. |
| 6204 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, |
| 6205 | const EVT &OrigTy, |
| 6206 | const EVT &ExtTy, |
| 6207 | unsigned ExtOpcode) { |
| 6208 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. |
| 6209 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than |
| 6210 | // 64-bits we need to insert a new extension so that it will be 64-bits. |
| 6211 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); |
| 6212 | if (OrigTy.getSizeInBits() >= 64) |
| 6213 | return N; |
| 6214 | |
| 6215 | // Must extend size to at least 64 bits to be used as an operand for VMULL. |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6216 | EVT NewVT = getExtensionTo64Bits(OrigTy); |
| 6217 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6218 | return DAG.getNode(ExtOpcode, SDLoc(N), NewVT, N); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6219 | } |
| 6220 | |
| 6221 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that |
| 6222 | /// does not do any sign/zero extension. If the original vector is less |
| 6223 | /// than 64 bits, an appropriate extension will be added after the load to |
| 6224 | /// reach a total size of 64 bits. We have to add the extension separately |
| 6225 | /// because ARM does not have a sign/zero extending load for vectors. |
| 6226 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6227 | EVT ExtendedTy = getExtensionTo64Bits(LD->getMemoryVT()); |
| 6228 | |
| 6229 | // The load already has the right type. |
| 6230 | if (ExtendedTy == LD->getMemoryVT()) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6231 | return DAG.getLoad(LD->getMemoryVT(), SDLoc(LD), LD->getChain(), |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6232 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 6233 | LD->isNonTemporal(), LD->isInvariant(), |
| 6234 | LD->getAlignment()); |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6235 | |
| 6236 | // We need to create a zextload/sextload. We cannot just create a load |
| 6237 | // followed by a zext/zext node because LowerMUL is also run during normal |
| 6238 | // operation legalization where we can't create illegal types. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6239 | return DAG.getExtLoad(LD->getExtensionType(), SDLoc(LD), ExtendedTy, |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6240 | LD->getChain(), LD->getBasePtr(), LD->getPointerInfo(), |
| Louis Gerbarg | 67474e3 | 2014-07-31 21:45:05 +0000 | [diff] [blame] | 6241 | LD->getMemoryVT(), LD->isVolatile(), LD->isInvariant(), |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6242 | LD->isNonTemporal(), LD->getAlignment()); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
| 6245 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, |
| 6246 | /// extending load, or BUILD_VECTOR with extended elements, return the |
| 6247 | /// unextended value. The unextended vector should be 64 bits so that it can |
| 6248 | /// be used as an operand to a VMULL instruction. If the original vector size |
| 6249 | /// before extension is less than 64 bits we add a an extension to resize |
| 6250 | /// the vector to 64 bits. |
| 6251 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6252 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6253 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
| 6254 | N->getOperand(0)->getValueType(0), |
| 6255 | N->getValueType(0), |
| 6256 | N->getOpcode()); |
| 6257 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6258 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6259 | return SkipLoadExtensionForVMULL(LD, DAG); |
| 6260 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6261 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 6262 | // have been legalized as a BITCAST from v4i32. |
| 6263 | if (N->getOpcode() == ISD::BITCAST) { |
| 6264 | SDNode *BVN = N->getOperand(0).getNode(); |
| 6265 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 6266 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 6267 | unsigned LowElt = DAG.getDataLayout().isBigEndian() ? 1 : 0; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6268 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), MVT::v2i32, |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6269 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 6270 | } |
| 6271 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 6272 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 6273 | EVT VT = N->getValueType(0); |
| 6274 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 6275 | unsigned NumElts = VT.getVectorNumElements(); |
| 6276 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 6277 | SmallVector<SDValue, 8> Ops; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6278 | SDLoc dl(N); |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6279 | for (unsigned i = 0; i != NumElts; ++i) { |
| 6280 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 6281 | const APInt &CInt = C->getAPIntValue(); |
| Bob Wilson | 9245c93 | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 6282 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 6283 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6284 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), dl, MVT::i32)); |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6285 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6286 | return DAG.getNode(ISD::BUILD_VECTOR, dl, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6287 | MVT::getVectorVT(TruncVT, NumElts), Ops); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6288 | } |
| 6289 | |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6290 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 6291 | unsigned Opcode = N->getOpcode(); |
| 6292 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 6293 | SDNode *N0 = N->getOperand(0).getNode(); |
| 6294 | SDNode *N1 = N->getOperand(1).getNode(); |
| 6295 | return N0->hasOneUse() && N1->hasOneUse() && |
| 6296 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 6297 | } |
| 6298 | return false; |
| 6299 | } |
| 6300 | |
| 6301 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 6302 | unsigned Opcode = N->getOpcode(); |
| 6303 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 6304 | SDNode *N0 = N->getOperand(0).getNode(); |
| 6305 | SDNode *N1 = N->getOperand(1).getNode(); |
| 6306 | return N0->hasOneUse() && N1->hasOneUse() && |
| 6307 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 6308 | } |
| 6309 | return false; |
| 6310 | } |
| 6311 | |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6312 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 6313 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 6314 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 6315 | EVT VT = Op.getValueType(); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6316 | assert(VT.is128BitVector() && VT.isInteger() && |
| 6317 | "unexpected type for custom-lowering ISD::MUL"); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6318 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 6319 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 6320 | unsigned NewOpc = 0; |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6321 | bool isMLA = false; |
| 6322 | bool isN0SExt = isSignExtended(N0, DAG); |
| 6323 | bool isN1SExt = isSignExtended(N1, DAG); |
| 6324 | if (isN0SExt && isN1SExt) |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6325 | NewOpc = ARMISD::VMULLs; |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6326 | else { |
| 6327 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 6328 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 6329 | if (isN0ZExt && isN1ZExt) |
| 6330 | NewOpc = ARMISD::VMULLu; |
| 6331 | else if (isN1SExt || isN1ZExt) { |
| 6332 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 6333 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 6334 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 6335 | NewOpc = ARMISD::VMULLs; |
| 6336 | isMLA = true; |
| 6337 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 6338 | NewOpc = ARMISD::VMULLu; |
| 6339 | isMLA = true; |
| 6340 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 6341 | std::swap(N0, N1); |
| 6342 | NewOpc = ARMISD::VMULLu; |
| 6343 | isMLA = true; |
| 6344 | } |
| 6345 | } |
| 6346 | |
| 6347 | if (!NewOpc) { |
| 6348 | if (VT == MVT::v2i64) |
| 6349 | // Fall through to expand this. It is not legal. |
| 6350 | return SDValue(); |
| 6351 | else |
| 6352 | // Other vector multiplications are legal. |
| 6353 | return Op; |
| 6354 | } |
| 6355 | } |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6356 | |
| 6357 | // Legalize to a VMULL instruction. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6358 | SDLoc DL(Op); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6359 | SDValue Op0; |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6360 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6361 | if (!isMLA) { |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6362 | Op0 = SkipExtensionForVMULL(N0, DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6363 | assert(Op0.getValueType().is64BitVector() && |
| 6364 | Op1.getValueType().is64BitVector() && |
| 6365 | "unexpected types for extended operands to VMULL"); |
| 6366 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 6367 | } |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6368 | |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6369 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 6370 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 6371 | // vmull q0, d4, d6 |
| 6372 | // vmlal q0, d5, d6 |
| 6373 | // is faster than |
| 6374 | // vaddl q0, d4, d5 |
| 6375 | // vmovl q1, d6 |
| 6376 | // vmul q0, q0, q1 |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6377 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
| 6378 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6379 | EVT Op1VT = Op1.getValueType(); |
| 6380 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 6381 | DAG.getNode(NewOpc, DL, VT, |
| 6382 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 6383 | DAG.getNode(NewOpc, DL, VT, |
| 6384 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6385 | } |
| 6386 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6387 | static SDValue |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6388 | LowerSDIV_v4i8(SDValue X, SDValue Y, SDLoc dl, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6389 | // TODO: Should this propagate fast-math-flags? |
| 6390 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6391 | // Convert to float |
| 6392 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 6393 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 6394 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 6395 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 6396 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 6397 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 6398 | // Get reciprocal estimate. |
| 6399 | // float4 recip = vrecpeq_f32(yf); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6400 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6401 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6402 | Y); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6403 | // Because char has a smaller range than uchar, we can actually get away |
| 6404 | // without any newton steps. This requires that we use a weird bias |
| 6405 | // of 0xb000, however (again, this has been exhaustively tested). |
| 6406 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 6407 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 6408 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6409 | Y = DAG.getConstant(0xb000, dl, MVT::i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6410 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 6411 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 6412 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 6413 | // Convert back to short. |
| 6414 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 6415 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 6416 | return X; |
| 6417 | } |
| 6418 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6419 | static SDValue |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6420 | LowerSDIV_v4i16(SDValue N0, SDValue N1, SDLoc dl, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6421 | // TODO: Should this propagate fast-math-flags? |
| 6422 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6423 | SDValue N2; |
| 6424 | // Convert to float. |
| 6425 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 6426 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 6427 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 6428 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 6429 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 6430 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6431 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6432 | // Use reciprocal estimate and one refinement step. |
| 6433 | // float4 recip = vrecpeq_f32(yf); |
| 6434 | // recip *= vrecpsq_f32(yf, recip); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6435 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6436 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6437 | N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6438 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6439 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6440 | N1, N2); |
| 6441 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 6442 | // Because short has a smaller range than ushort, we can actually get away |
| 6443 | // with only a single newton step. This requires that we use a weird bias |
| 6444 | // of 89, however (again, this has been exhaustively tested). |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6445 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6446 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 6447 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6448 | N1 = DAG.getConstant(0x89, dl, MVT::i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6449 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 6450 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 6451 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 6452 | // Convert back to integer and return. |
| 6453 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 6454 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 6455 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 6456 | return N0; |
| 6457 | } |
| 6458 | |
| 6459 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 6460 | EVT VT = Op.getValueType(); |
| 6461 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 6462 | "unexpected type for custom-lowering ISD::SDIV"); |
| 6463 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6464 | SDLoc dl(Op); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6465 | SDValue N0 = Op.getOperand(0); |
| 6466 | SDValue N1 = Op.getOperand(1); |
| 6467 | SDValue N2, N3; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6468 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6469 | if (VT == MVT::v8i8) { |
| 6470 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 6471 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6472 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6473 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6474 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6475 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6476 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6477 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6478 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6479 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6480 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6481 | |
| 6482 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 6483 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 6484 | |
| 6485 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 6486 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6487 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6488 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 6489 | return N0; |
| 6490 | } |
| 6491 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 6492 | } |
| 6493 | |
| 6494 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6495 | // TODO: Should this propagate fast-math-flags? |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6496 | EVT VT = Op.getValueType(); |
| 6497 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 6498 | "unexpected type for custom-lowering ISD::UDIV"); |
| 6499 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6500 | SDLoc dl(Op); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6501 | SDValue N0 = Op.getOperand(0); |
| 6502 | SDValue N1 = Op.getOperand(1); |
| 6503 | SDValue N2, N3; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6504 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6505 | if (VT == MVT::v8i8) { |
| 6506 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 6507 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6508 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6509 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6510 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6511 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6512 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6513 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6514 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6515 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6516 | DAG.getIntPtrConstant(0, dl)); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6517 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6518 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 6519 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6520 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6521 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 6522 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6523 | |
| 6524 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6525 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, dl, |
| 6526 | MVT::i32), |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6527 | N0); |
| 6528 | return N0; |
| 6529 | } |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6530 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6531 | // v4i16 sdiv ... Convert to float. |
| 6532 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 6533 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 6534 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 6535 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 6536 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6537 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6538 | |
| 6539 | // Use reciprocal estimate and two refinement steps. |
| 6540 | // float4 recip = vrecpeq_f32(yf); |
| 6541 | // recip *= vrecpsq_f32(yf, recip); |
| 6542 | // recip *= vrecpsq_f32(yf, recip); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6543 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6544 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6545 | BN1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6546 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6547 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6548 | BN1, N2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6549 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6550 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6551 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6552 | BN1, N2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6553 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 6554 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 6555 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 6556 | // and that it will never cause us to return an answer too large). |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6557 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6558 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 6559 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6560 | N1 = DAG.getConstant(2, dl, MVT::i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6561 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 6562 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 6563 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 6564 | // Convert back to integer and return. |
| 6565 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 6566 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 6567 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 6568 | return N0; |
| 6569 | } |
| 6570 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6571 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 6572 | EVT VT = Op.getNode()->getValueType(0); |
| 6573 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 6574 | |
| 6575 | unsigned Opc; |
| 6576 | bool ExtraOp = false; |
| 6577 | switch (Op.getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6578 | default: llvm_unreachable("Invalid code"); |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6579 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 6580 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 6581 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 6582 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 6583 | } |
| 6584 | |
| 6585 | if (!ExtraOp) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6586 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6587 | Op.getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6588 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6589 | Op.getOperand(1), Op.getOperand(2)); |
| 6590 | } |
| 6591 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6592 | SDValue ARMTargetLowering::LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const { |
| 6593 | assert(Subtarget->isTargetDarwin()); |
| 6594 | |
| 6595 | // For iOS, we want to call an alternative entry point: __sincos_stret, |
| 6596 | // return values are passed via sret. |
| 6597 | SDLoc dl(Op); |
| 6598 | SDValue Arg = Op.getOperand(0); |
| 6599 | EVT ArgVT = Arg.getValueType(); |
| 6600 | Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6601 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6602 | |
| 6603 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6604 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6605 | |
| 6606 | // Pair of floats / doubles used to pass the result. |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6607 | Type *RetTy = StructType::get(ArgTy, ArgTy, nullptr); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6608 | auto &DL = DAG.getDataLayout(); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6609 | |
| 6610 | ArgListTy Args; |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6611 | bool ShouldUseSRet = Subtarget->isAPCS_ABI(); |
| 6612 | SDValue SRet; |
| 6613 | if (ShouldUseSRet) { |
| 6614 | // Create stack object for sret. |
| 6615 | const uint64_t ByteSize = DL.getTypeAllocSize(RetTy); |
| 6616 | const unsigned StackAlign = DL.getPrefTypeAlignment(RetTy); |
| 6617 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign, false); |
| 6618 | SRet = DAG.getFrameIndex(FrameIdx, TLI.getPointerTy(DL)); |
| 6619 | |
| 6620 | ArgListEntry Entry; |
| 6621 | Entry.Node = SRet; |
| 6622 | Entry.Ty = RetTy->getPointerTo(); |
| 6623 | Entry.isSExt = false; |
| 6624 | Entry.isZExt = false; |
| 6625 | Entry.isSRet = true; |
| 6626 | Args.push_back(Entry); |
| 6627 | RetTy = Type::getVoidTy(*DAG.getContext()); |
| 6628 | } |
| 6629 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6630 | ArgListEntry Entry; |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6631 | Entry.Node = Arg; |
| 6632 | Entry.Ty = ArgTy; |
| 6633 | Entry.isSExt = false; |
| 6634 | Entry.isZExt = false; |
| 6635 | Args.push_back(Entry); |
| 6636 | |
| Saleem Abdulrasool | 4966f58 | 2015-09-20 03:19:09 +0000 | [diff] [blame] | 6637 | const char *LibcallName = |
| 6638 | (ArgVT == MVT::f64) ? "__sincos_stret" : "__sincosf_stret"; |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6639 | RTLIB::Libcall LC = |
| 6640 | (ArgVT == MVT::f64) ? RTLIB::SINCOS_F64 : RTLIB::SINCOS_F32; |
| 6641 | CallingConv::ID CC = getLibcallCallingConv(LC); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6642 | SDValue Callee = DAG.getExternalSymbol(LibcallName, getPointerTy(DL)); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6643 | |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 6644 | TargetLowering::CallLoweringInfo CLI(DAG); |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6645 | CLI.setDebugLoc(dl) |
| 6646 | .setChain(DAG.getEntryNode()) |
| 6647 | .setCallee(CC, RetTy, Callee, std::move(Args), 0) |
| 6648 | .setDiscardResult(ShouldUseSRet); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6649 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| 6650 | |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6651 | if (!ShouldUseSRet) |
| 6652 | return CallResult.first; |
| 6653 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6654 | SDValue LoadSin = DAG.getLoad(ArgVT, dl, CallResult.second, SRet, |
| 6655 | MachinePointerInfo(), false, false, false, 0); |
| 6656 | |
| 6657 | // Address of cos field. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6658 | SDValue Add = DAG.getNode(ISD::ADD, dl, PtrVT, SRet, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6659 | DAG.getIntPtrConstant(ArgVT.getStoreSize(), dl)); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6660 | SDValue LoadCos = DAG.getLoad(ArgVT, dl, LoadSin.getValue(1), Add, |
| 6661 | MachinePointerInfo(), false, false, false, 0); |
| 6662 | |
| 6663 | SDVTList Tys = DAG.getVTList(ArgVT, ArgVT); |
| 6664 | return DAG.getNode(ISD::MERGE_VALUES, dl, Tys, |
| 6665 | LoadSin.getValue(0), LoadCos.getValue(0)); |
| 6666 | } |
| 6667 | |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6668 | SDValue ARMTargetLowering::LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG, |
| 6669 | bool Signed, |
| 6670 | SDValue &Chain) const { |
| 6671 | EVT VT = Op.getValueType(); |
| 6672 | assert((VT == MVT::i32 || VT == MVT::i64) && |
| 6673 | "unexpected type for custom lowering DIV"); |
| 6674 | SDLoc dl(Op); |
| 6675 | |
| 6676 | const auto &DL = DAG.getDataLayout(); |
| 6677 | const auto &TLI = DAG.getTargetLoweringInfo(); |
| 6678 | |
| 6679 | const char *Name = nullptr; |
| 6680 | if (Signed) |
| 6681 | Name = (VT == MVT::i32) ? "__rt_sdiv" : "__rt_sdiv64"; |
| 6682 | else |
| 6683 | Name = (VT == MVT::i32) ? "__rt_udiv" : "__rt_udiv64"; |
| 6684 | |
| 6685 | SDValue ES = DAG.getExternalSymbol(Name, TLI.getPointerTy(DL)); |
| 6686 | |
| 6687 | ARMTargetLowering::ArgListTy Args; |
| 6688 | |
| 6689 | for (auto AI : {1, 0}) { |
| 6690 | ArgListEntry Arg; |
| 6691 | Arg.Node = Op.getOperand(AI); |
| 6692 | Arg.Ty = Arg.Node.getValueType().getTypeForEVT(*DAG.getContext()); |
| 6693 | Args.push_back(Arg); |
| 6694 | } |
| 6695 | |
| 6696 | CallLoweringInfo CLI(DAG); |
| 6697 | CLI.setDebugLoc(dl) |
| 6698 | .setChain(Chain) |
| 6699 | .setCallee(CallingConv::ARM_AAPCS_VFP, VT.getTypeForEVT(*DAG.getContext()), |
| 6700 | ES, std::move(Args), 0); |
| 6701 | |
| 6702 | return LowerCallTo(CLI).first; |
| 6703 | } |
| 6704 | |
| 6705 | SDValue ARMTargetLowering::LowerDIV_Windows(SDValue Op, SelectionDAG &DAG, |
| 6706 | bool Signed) const { |
| Saleem Abdulrasool | 8e99f50 | 2015-09-25 05:41:02 +0000 | [diff] [blame] | 6707 | assert(Op.getValueType() == MVT::i32 && |
| 6708 | "unexpected type for custom lowering DIV"); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6709 | SDLoc dl(Op); |
| 6710 | |
| 6711 | SDValue DBZCHK = DAG.getNode(ARMISD::WIN__DBZCHK, dl, MVT::Other, |
| 6712 | DAG.getEntryNode(), Op.getOperand(1)); |
| 6713 | |
| 6714 | return LowerWindowsDIVLibCall(Op, DAG, Signed, DBZCHK); |
| 6715 | } |
| 6716 | |
| 6717 | void ARMTargetLowering::ExpandDIV_Windows( |
| 6718 | SDValue Op, SelectionDAG &DAG, bool Signed, |
| 6719 | SmallVectorImpl<SDValue> &Results) const { |
| 6720 | const auto &DL = DAG.getDataLayout(); |
| 6721 | const auto &TLI = DAG.getTargetLoweringInfo(); |
| 6722 | |
| Saleem Abdulrasool | 8e99f50 | 2015-09-25 05:41:02 +0000 | [diff] [blame] | 6723 | assert(Op.getValueType() == MVT::i64 && |
| 6724 | "unexpected type for custom lowering DIV"); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6725 | SDLoc dl(Op); |
| 6726 | |
| 6727 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op.getOperand(1), |
| 6728 | DAG.getConstant(0, dl, MVT::i32)); |
| 6729 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op.getOperand(1), |
| 6730 | DAG.getConstant(1, dl, MVT::i32)); |
| 6731 | SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i32, Lo, Hi); |
| 6732 | |
| 6733 | SDValue DBZCHK = |
| 6734 | DAG.getNode(ARMISD::WIN__DBZCHK, dl, MVT::Other, DAG.getEntryNode(), Or); |
| 6735 | |
| 6736 | SDValue Result = LowerWindowsDIVLibCall(Op, DAG, Signed, DBZCHK); |
| 6737 | |
| 6738 | SDValue Lower = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Result); |
| 6739 | SDValue Upper = DAG.getNode(ISD::SRL, dl, MVT::i64, Result, |
| 6740 | DAG.getConstant(32, dl, TLI.getPointerTy(DL))); |
| 6741 | Upper = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Upper); |
| 6742 | |
| 6743 | Results.push_back(Lower); |
| 6744 | Results.push_back(Upper); |
| 6745 | } |
| 6746 | |
| Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 6747 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6748 | // Monotonic load/store is legal for all targets |
| 6749 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 6750 | return Op; |
| 6751 | |
| Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 6752 | // Acquire/Release load/store is not legal for targets without a |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6753 | // dmb or equivalent available. |
| 6754 | return SDValue(); |
| 6755 | } |
| 6756 | |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6757 | static void ReplaceREADCYCLECOUNTER(SDNode *N, |
| 6758 | SmallVectorImpl<SDValue> &Results, |
| 6759 | SelectionDAG &DAG, |
| 6760 | const ARMSubtarget *Subtarget) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6761 | SDLoc DL(N); |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 6762 | // Under Power Management extensions, the cycle-count is: |
| 6763 | // mrc p15, #0, <Rt>, c9, c13, #0 |
| 6764 | SDValue Ops[] = { N->getOperand(0), // Chain |
| 6765 | DAG.getConstant(Intrinsic::arm_mrc, DL, MVT::i32), |
| 6766 | DAG.getConstant(15, DL, MVT::i32), |
| 6767 | DAG.getConstant(0, DL, MVT::i32), |
| 6768 | DAG.getConstant(9, DL, MVT::i32), |
| 6769 | DAG.getConstant(13, DL, MVT::i32), |
| 6770 | DAG.getConstant(0, DL, MVT::i32) |
| 6771 | }; |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6772 | |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 6773 | SDValue Cycles32 = DAG.getNode(ISD::INTRINSIC_W_CHAIN, DL, |
| 6774 | DAG.getVTList(MVT::i32, MVT::Other), Ops); |
| 6775 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Cycles32, |
| 6776 | DAG.getConstant(0, DL, MVT::i32))); |
| 6777 | Results.push_back(Cycles32.getValue(1)); |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6778 | } |
| 6779 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6780 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6781 | switch (Op.getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6782 | default: llvm_unreachable("Don't know how to custom lower this!"); |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 6783 | case ISD::WRITE_REGISTER: return LowerWRITE_REGISTER(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6784 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 6785 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 6786 | case ISD::GlobalAddress: |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 6787 | switch (Subtarget->getTargetTriple().getObjectFormat()) { |
| 6788 | default: llvm_unreachable("unknown object format"); |
| 6789 | case Triple::COFF: |
| 6790 | return LowerGlobalAddressWindows(Op, DAG); |
| 6791 | case Triple::ELF: |
| 6792 | return LowerGlobalAddressELF(Op, DAG); |
| 6793 | case Triple::MachO: |
| 6794 | return LowerGlobalAddressDarwin(Op, DAG); |
| 6795 | } |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6796 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 6797 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6798 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 6799 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6800 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 6801 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 6802 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 6803 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 6804 | case ISD::SINT_TO_FP: |
| 6805 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 6806 | case ISD::FP_TO_SINT: |
| 6807 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6808 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 6809 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 6810 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 6811 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 6812 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 6813 | case ISD::EH_SJLJ_SETUP_DISPATCH: return LowerEH_SJLJ_SETUP_DISPATCH(Op, DAG); |
| Jim Grosbach | a570d05 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 6814 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 6815 | Subtarget); |
| Evan Cheng | 383ecd8 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 6816 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6817 | case ISD::SHL: |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6818 | case ISD::SRL: |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6819 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 6820 | case ISD::SREM: return LowerREM(Op.getNode(), DAG); |
| 6821 | case ISD::UREM: return LowerREM(Op.getNode(), DAG); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6822 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 6823 | case ISD::SRL_PARTS: |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6824 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 6825 | case ISD::CTTZ: |
| 6826 | case ISD::CTTZ_ZERO_UNDEF: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 6827 | case ISD::CTPOP: return LowerCTPOP(Op.getNode(), DAG, Subtarget); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 6828 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 6829 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 6830 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6831 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 6832 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6833 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6834 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 6835 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6836 | case ISD::MUL: return LowerMUL(Op, DAG); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6837 | case ISD::SDIV: |
| 6838 | if (Subtarget->isTargetWindows()) |
| 6839 | return LowerDIV_Windows(Op, DAG, /* Signed */ true); |
| 6840 | return LowerSDIV(Op, DAG); |
| 6841 | case ISD::UDIV: |
| 6842 | if (Subtarget->isTargetWindows()) |
| 6843 | return LowerDIV_Windows(Op, DAG, /* Signed */ false); |
| 6844 | return LowerUDIV(Op, DAG); |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6845 | case ISD::ADDC: |
| 6846 | case ISD::ADDE: |
| 6847 | case ISD::SUBC: |
| 6848 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 6849 | case ISD::SADDO: |
| 6850 | case ISD::UADDO: |
| 6851 | case ISD::SSUBO: |
| 6852 | case ISD::USUBO: |
| 6853 | return LowerXALUO(Op, DAG); |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6854 | case ISD::ATOMIC_LOAD: |
| Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 6855 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6856 | case ISD::FSINCOS: return LowerFSINCOS(Op, DAG); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 6857 | case ISD::SDIVREM: |
| 6858 | case ISD::UDIVREM: return LowerDivRem(Op, DAG); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 6859 | case ISD::DYNAMIC_STACKALLOC: |
| 6860 | if (Subtarget->getTargetTriple().isWindowsItaniumEnvironment()) |
| 6861 | return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 6862 | llvm_unreachable("Don't know how to custom lower this!"); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 6863 | case ISD::FP_ROUND: return LowerFP_ROUND(Op, DAG); |
| 6864 | case ISD::FP_EXTEND: return LowerFP_EXTEND(Op, DAG); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6865 | case ARMISD::WIN__DBZCHK: return SDValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6866 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6867 | } |
| 6868 | |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6869 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 6870 | /// type with new values built out of custom code. |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6871 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6872 | SmallVectorImpl<SDValue> &Results, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6873 | SelectionDAG &DAG) const { |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6874 | SDValue Res; |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6875 | switch (N->getOpcode()) { |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6876 | default: |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6877 | llvm_unreachable("Don't know how to custom expand this!"); |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 6878 | case ISD::READ_REGISTER: |
| 6879 | ExpandREAD_REGISTER(N, Results, DAG); |
| 6880 | break; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6881 | case ISD::BITCAST: |
| 6882 | Res = ExpandBITCAST(N, DAG); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6883 | break; |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6884 | case ISD::SRL: |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6885 | case ISD::SRA: |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 6886 | Res = Expand64BitShift(N, DAG, Subtarget); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6887 | break; |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 6888 | case ISD::SREM: |
| 6889 | case ISD::UREM: |
| 6890 | Res = LowerREM(N, DAG); |
| 6891 | break; |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6892 | case ISD::READCYCLECOUNTER: |
| 6893 | ReplaceREADCYCLECOUNTER(N, Results, DAG, Subtarget); |
| 6894 | return; |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6895 | case ISD::UDIV: |
| 6896 | case ISD::SDIV: |
| 6897 | assert(Subtarget->isTargetWindows() && "can only expand DIV on Windows"); |
| 6898 | return ExpandDIV_Windows(SDValue(N, 0), DAG, N->getOpcode() == ISD::SDIV, |
| 6899 | Results); |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 6900 | } |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 6901 | if (Res.getNode()) |
| 6902 | Results.push_back(Res); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6903 | } |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6904 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6905 | //===----------------------------------------------------------------------===// |
| 6906 | // ARM Scheduler Hooks |
| 6907 | //===----------------------------------------------------------------------===// |
| 6908 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6909 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 6910 | /// registers the function context. |
| 6911 | void ARMTargetLowering:: |
| 6912 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 6913 | MachineBasicBlock *DispatchBB, int FI) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 6914 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6915 | DebugLoc dl = MI->getDebugLoc(); |
| 6916 | MachineFunction *MF = MBB->getParent(); |
| 6917 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 6918 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 6919 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 6920 | const Function *F = MF->getFunction(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6921 | |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6922 | bool isThumb = Subtarget->isThumb(); |
| Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6923 | bool isThumb2 = Subtarget->isThumb2(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6924 | |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6925 | unsigned PCLabelId = AFI->createPICLabelUId(); |
| Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 6926 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6927 | ARMConstantPoolValue *CPV = |
| 6928 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 6929 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 6930 | |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 6931 | const TargetRegisterClass *TRC = isThumb ? &ARM::tGPRRegClass |
| 6932 | : &ARM::GPRRegClass; |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 6933 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6934 | // Grab constant pool and fixed stack memory operands. |
| 6935 | MachineMemOperand *CPMMO = |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6936 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(*MF), |
| 6937 | MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6938 | |
| 6939 | MachineMemOperand *FIMMOSt = |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 6940 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(*MF, FI), |
| 6941 | MachineMemOperand::MOStore, 4, 4); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6942 | |
| 6943 | // Load the address of the dispatch MBB into the jump buffer. |
| 6944 | if (isThumb2) { |
| 6945 | // Incoming value: jbuf |
| 6946 | // ldr.n r5, LCPI1_1 |
| 6947 | // orr r5, r5, #1 |
| 6948 | // add r5, pc |
| 6949 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 6950 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6951 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 6952 | .addConstantPoolIndex(CPI) |
| 6953 | .addMemOperand(CPMMO)); |
| 6954 | // Set the low bit because of thumb mode. |
| 6955 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6956 | AddDefaultCC( |
| 6957 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 6958 | .addReg(NewVReg1, RegState::Kill) |
| 6959 | .addImm(0x01))); |
| 6960 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6961 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 6962 | .addReg(NewVReg2, RegState::Kill) |
| 6963 | .addImm(PCLabelId); |
| 6964 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 6965 | .addReg(NewVReg3, RegState::Kill) |
| 6966 | .addFrameIndex(FI) |
| 6967 | .addImm(36) // &jbuf[1] :: pc |
| 6968 | .addMemOperand(FIMMOSt)); |
| 6969 | } else if (isThumb) { |
| 6970 | // Incoming value: jbuf |
| 6971 | // ldr.n r1, LCPI1_4 |
| 6972 | // add r1, pc |
| 6973 | // mov r2, #1 |
| 6974 | // orrs r1, r2 |
| 6975 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 6976 | // str r1, [r2] |
| 6977 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 6978 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 6979 | .addConstantPoolIndex(CPI) |
| 6980 | .addMemOperand(CPMMO)); |
| 6981 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 6982 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 6983 | .addReg(NewVReg1, RegState::Kill) |
| 6984 | .addImm(PCLabelId); |
| 6985 | // Set the low bit because of thumb mode. |
| 6986 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 6987 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 6988 | .addReg(ARM::CPSR, RegState::Define) |
| 6989 | .addImm(1)); |
| 6990 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 6991 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 6992 | .addReg(ARM::CPSR, RegState::Define) |
| 6993 | .addReg(NewVReg2, RegState::Kill) |
| 6994 | .addReg(NewVReg3, RegState::Kill)); |
| 6995 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| Tim Northover | 23075cc | 2014-10-20 21:28:41 +0000 | [diff] [blame] | 6996 | BuildMI(*MBB, MI, dl, TII->get(ARM::tADDframe), NewVReg5) |
| 6997 | .addFrameIndex(FI) |
| 6998 | .addImm(36); // &jbuf[1] :: pc |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 6999 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 7000 | .addReg(NewVReg4, RegState::Kill) |
| 7001 | .addReg(NewVReg5, RegState::Kill) |
| 7002 | .addImm(0) |
| 7003 | .addMemOperand(FIMMOSt)); |
| 7004 | } else { |
| 7005 | // Incoming value: jbuf |
| 7006 | // ldr r1, LCPI1_1 |
| 7007 | // add r1, pc, r1 |
| 7008 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 7009 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7010 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 7011 | .addConstantPoolIndex(CPI) |
| 7012 | .addImm(0) |
| 7013 | .addMemOperand(CPMMO)); |
| 7014 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7015 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 7016 | .addReg(NewVReg1, RegState::Kill) |
| 7017 | .addImm(PCLabelId)); |
| 7018 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 7019 | .addReg(NewVReg2, RegState::Kill) |
| 7020 | .addFrameIndex(FI) |
| 7021 | .addImm(36) // &jbuf[1] :: pc |
| 7022 | .addMemOperand(FIMMOSt)); |
| 7023 | } |
| 7024 | } |
| 7025 | |
| Matthias Braun | eec4efc | 2015-04-28 00:37:05 +0000 | [diff] [blame] | 7026 | void ARMTargetLowering::EmitSjLjDispatchBlock(MachineInstr *MI, |
| 7027 | MachineBasicBlock *MBB) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7028 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7029 | DebugLoc dl = MI->getDebugLoc(); |
| 7030 | MachineFunction *MF = MBB->getParent(); |
| 7031 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7032 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 7033 | int FI = MFI->getFunctionContextIndex(); |
| 7034 | |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7035 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? &ARM::tGPRRegClass |
| 7036 | : &ARM::GPRnopcRegClass; |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7037 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7038 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 7039 | // associated with. |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7040 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 7041 | unsigned MaxCSNum = 0; |
| 7042 | MachineModuleInfo &MMI = MF->getMMI(); |
| Jim Grosbach | 0c509fa | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 7043 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 7044 | ++BB) { |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7045 | if (!BB->isEHPad()) continue; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7046 | |
| 7047 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 7048 | // pad. |
| 7049 | for (MachineBasicBlock::iterator |
| 7050 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 7051 | if (!II->isEHLabel()) continue; |
| 7052 | |
| 7053 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7054 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7055 | |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7056 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 7057 | for (SmallVectorImpl<unsigned>::iterator |
| 7058 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 7059 | CSI != CSE; ++CSI) { |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 7060 | CallSiteNumToLPad[*CSI].push_back(&*BB); |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7061 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 7062 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7063 | break; |
| 7064 | } |
| 7065 | } |
| 7066 | |
| 7067 | // Get an ordered list of the machine basic blocks for the jump table. |
| 7068 | std::vector<MachineBasicBlock*> LPadList; |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7069 | SmallPtrSet<MachineBasicBlock*, 64> InvokeBBs; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7070 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 7071 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 7072 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 7073 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7074 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7075 | LPadList.push_back(*II); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7076 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 7077 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7078 | } |
| 7079 | |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7080 | assert(!LPadList.empty() && |
| 7081 | "No landing pad destinations for the dispatch jump table!"); |
| 7082 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7083 | // Create the jump table and associated information. |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7084 | MachineJumpTableInfo *JTI = |
| 7085 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 7086 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7087 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7088 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7089 | // Create the MBBs for the dispatch code. |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7090 | |
| 7091 | // Shove the dispatch's address into the return slot in the function context. |
| 7092 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7093 | DispatchBB->setIsEHPad(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7094 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7095 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7096 | unsigned trap_opcode; |
| Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 7097 | if (Subtarget->isThumb()) |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7098 | trap_opcode = ARM::tTRAP; |
| Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 7099 | else |
| 7100 | trap_opcode = Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP; |
| 7101 | |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7102 | BuildMI(TrapBB, dl, TII->get(trap_opcode)); |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7103 | DispatchBB->addSuccessor(TrapBB); |
| 7104 | |
| 7105 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 7106 | DispatchBB->addSuccessor(DispContBB); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7107 | |
| Bill Wendling | 510fbcd | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 7108 | // Insert and MBBs. |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7109 | MF->insert(MF->end(), DispatchBB); |
| 7110 | MF->insert(MF->end(), DispContBB); |
| 7111 | MF->insert(MF->end(), TrapBB); |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7112 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7113 | // Insert code into the entry block that creates and registers the function |
| 7114 | // context. |
| 7115 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 7116 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7117 | MachineMemOperand *FIMMOLd = MF->getMachineMemOperand( |
| 7118 | MachinePointerInfo::getFixedStack(*MF, FI), |
| 7119 | MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile, 4, 4); |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7120 | |
| Chad Rosier | 1ec8e40 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 7121 | MachineInstrBuilder MIB; |
| 7122 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
| 7123 | |
| 7124 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 7125 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 7126 | |
| 7127 | // Add a register mask with no preserved registers. This results in all |
| 7128 | // registers being marked as clobbered. |
| 7129 | MIB.addRegMask(RI.getNoPreservedMask()); |
| Bob Wilson | f6d1728 | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 7130 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7131 | unsigned NumLPads = LPadList.size(); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7132 | if (Subtarget->isThumb2()) { |
| 7133 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7134 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 7135 | .addFrameIndex(FI) |
| 7136 | .addImm(4) |
| 7137 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7138 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7139 | if (NumLPads < 256) { |
| 7140 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 7141 | .addReg(NewVReg1) |
| 7142 | .addImm(LPadList.size())); |
| 7143 | } else { |
| 7144 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7145 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
| Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 7146 | .addImm(NumLPads & 0xFFFF)); |
| 7147 | |
| 7148 | unsigned VReg2 = VReg1; |
| 7149 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 7150 | VReg2 = MRI->createVirtualRegister(TRC); |
| 7151 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 7152 | .addReg(VReg1) |
| 7153 | .addImm(NumLPads >> 16)); |
| 7154 | } |
| 7155 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7156 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 7157 | .addReg(NewVReg1) |
| 7158 | .addReg(VReg2)); |
| 7159 | } |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7160 | |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7161 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 7162 | .addMBB(TrapBB) |
| 7163 | .addImm(ARMCC::HI) |
| 7164 | .addReg(ARM::CPSR); |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7165 | |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7166 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 7167 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7168 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7169 | |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7170 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7171 | AddDefaultCC( |
| 7172 | AddDefaultPred( |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7173 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 7174 | .addReg(NewVReg3, RegState::Kill) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7175 | .addReg(NewVReg1) |
| 7176 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 7177 | |
| 7178 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7179 | .addReg(NewVReg4, RegState::Kill) |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7180 | .addReg(NewVReg1) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7181 | .addJumpTableIndex(MJTI); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7182 | } else if (Subtarget->isThumb()) { |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7183 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7184 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 7185 | .addFrameIndex(FI) |
| 7186 | .addImm(1) |
| 7187 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | f9f5e45 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 7188 | |
| Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 7189 | if (NumLPads < 256) { |
| 7190 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 7191 | .addReg(NewVReg1) |
| 7192 | .addImm(NumLPads)); |
| 7193 | } else { |
| 7194 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7195 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7196 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 7197 | |
| 7198 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7199 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7200 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7201 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7202 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 7203 | |
| 7204 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7205 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 7206 | .addReg(VReg1, RegState::Define) |
| 7207 | .addConstantPoolIndex(Idx)); |
| 7208 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 7209 | .addReg(NewVReg1) |
| 7210 | .addReg(VReg1)); |
| 7211 | } |
| 7212 | |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7213 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 7214 | .addMBB(TrapBB) |
| 7215 | .addImm(ARMCC::HI) |
| 7216 | .addReg(ARM::CPSR); |
| 7217 | |
| 7218 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7219 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 7220 | .addReg(ARM::CPSR, RegState::Define) |
| 7221 | .addReg(NewVReg1) |
| 7222 | .addImm(2)); |
| 7223 | |
| 7224 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 8d50ea0 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 7225 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7226 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7227 | |
| 7228 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 7229 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 7230 | .addReg(ARM::CPSR, RegState::Define) |
| 7231 | .addReg(NewVReg2, RegState::Kill) |
| 7232 | .addReg(NewVReg3)); |
| 7233 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7234 | MachineMemOperand *JTMMOLd = MF->getMachineMemOperand( |
| 7235 | MachinePointerInfo::getJumpTable(*MF), MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7236 | |
| 7237 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 7238 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 7239 | .addReg(NewVReg4, RegState::Kill) |
| 7240 | .addImm(0) |
| 7241 | .addMemOperand(JTMMOLd)); |
| 7242 | |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7243 | unsigned NewVReg6 = NewVReg5; |
| 7244 | if (RelocM == Reloc::PIC_) { |
| 7245 | NewVReg6 = MRI->createVirtualRegister(TRC); |
| 7246 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 7247 | .addReg(ARM::CPSR, RegState::Define) |
| 7248 | .addReg(NewVReg5, RegState::Kill) |
| 7249 | .addReg(NewVReg3)); |
| 7250 | } |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7251 | |
| 7252 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 7253 | .addReg(NewVReg6, RegState::Kill) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7254 | .addJumpTableIndex(MJTI); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7255 | } else { |
| 7256 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7257 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 7258 | .addFrameIndex(FI) |
| 7259 | .addImm(4) |
| 7260 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7261 | |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7262 | if (NumLPads < 256) { |
| 7263 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 7264 | .addReg(NewVReg1) |
| 7265 | .addImm(NumLPads)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7266 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7267 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7268 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
| Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 7269 | .addImm(NumLPads & 0xFFFF)); |
| 7270 | |
| 7271 | unsigned VReg2 = VReg1; |
| 7272 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 7273 | VReg2 = MRI->createVirtualRegister(TRC); |
| 7274 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 7275 | .addReg(VReg1) |
| 7276 | .addImm(NumLPads >> 16)); |
| 7277 | } |
| 7278 | |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7279 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 7280 | .addReg(NewVReg1) |
| 7281 | .addReg(VReg2)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7282 | } else { |
| 7283 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 7284 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7285 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 7286 | |
| 7287 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7288 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7289 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7290 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7291 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 7292 | |
| 7293 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7294 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 7295 | .addReg(VReg1, RegState::Define) |
| Bill Wendling | cf7bdf4 | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 7296 | .addConstantPoolIndex(Idx) |
| 7297 | .addImm(0)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7298 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 7299 | .addReg(NewVReg1) |
| 7300 | .addReg(VReg1, RegState::Kill)); |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7301 | } |
| 7302 | |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7303 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 7304 | .addMBB(TrapBB) |
| 7305 | .addImm(ARMCC::HI) |
| 7306 | .addReg(ARM::CPSR); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7307 | |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7308 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7309 | AddDefaultCC( |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7310 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7311 | .addReg(NewVReg1) |
| 7312 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7313 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 7314 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7315 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7316 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7317 | MachineMemOperand *JTMMOLd = MF->getMachineMemOperand( |
| 7318 | MachinePointerInfo::getJumpTable(*MF), MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7319 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7320 | AddDefaultPred( |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7321 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 7322 | .addReg(NewVReg3, RegState::Kill) |
| 7323 | .addReg(NewVReg4) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7324 | .addImm(0) |
| 7325 | .addMemOperand(JTMMOLd)); |
| 7326 | |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7327 | if (RelocM == Reloc::PIC_) { |
| 7328 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
| 7329 | .addReg(NewVReg5, RegState::Kill) |
| 7330 | .addReg(NewVReg4) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7331 | .addJumpTableIndex(MJTI); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7332 | } else { |
| 7333 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTr)) |
| 7334 | .addReg(NewVReg5, RegState::Kill) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7335 | .addJumpTableIndex(MJTI); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7336 | } |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7337 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7338 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7339 | // Add the jump table entries as successors to the MBB. |
| Jakob Stoklund Olesen | 710093e | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 7340 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7341 | for (std::vector<MachineBasicBlock*>::iterator |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7342 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 7343 | MachineBasicBlock *CurMBB = *I; |
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 7344 | if (SeenMBBs.insert(CurMBB).second) |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7345 | DispContBB->addSuccessor(CurMBB); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7346 | } |
| 7347 | |
| Bill Wendling | 26d2780 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 7348 | // N.B. the order the invoke BBs are processed in doesn't matter here. |
| Craig Topper | 840beec | 2014-04-04 05:16:06 +0000 | [diff] [blame] | 7349 | const MCPhysReg *SavedRegs = RI.getCalleeSavedRegs(MF); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7350 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
| Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 7351 | for (MachineBasicBlock *BB : InvokeBBs) { |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7352 | |
| 7353 | // Remove the landing pad successor from the invoke block and replace it |
| 7354 | // with the new dispatch block. |
| Bill Wendling | 1414bc5 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 7355 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 7356 | BB->succ_end()); |
| 7357 | while (!Successors.empty()) { |
| 7358 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7359 | if (SMBB->isEHPad()) { |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7360 | BB->removeSuccessor(SMBB); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7361 | MBBLPads.push_back(SMBB); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | BB->addSuccessor(DispatchBB); |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7366 | |
| 7367 | // Find the invoke call and mark all of the callee-saved registers as |
| 7368 | // 'implicit defined' so that they're spilled. This prevents code from |
| 7369 | // moving instructions to before the EH block, where they will never be |
| 7370 | // executed. |
| 7371 | for (MachineBasicBlock::reverse_iterator |
| 7372 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7373 | if (!II->isCall()) continue; |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7374 | |
| 7375 | DenseMap<unsigned, bool> DefRegs; |
| 7376 | for (MachineInstr::mop_iterator |
| 7377 | OI = II->operands_begin(), OE = II->operands_end(); |
| 7378 | OI != OE; ++OI) { |
| 7379 | if (!OI->isReg()) continue; |
| 7380 | DefRegs[OI->getReg()] = true; |
| 7381 | } |
| 7382 | |
| Jakob Stoklund Olesen | b159b5f | 2012-12-19 21:31:56 +0000 | [diff] [blame] | 7383 | MachineInstrBuilder MIB(*MF, &*II); |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7384 | |
| Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 7385 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7386 | unsigned Reg = SavedRegs[i]; |
| 7387 | if (Subtarget->isThumb2() && |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7388 | !ARM::tGPRRegClass.contains(Reg) && |
| 7389 | !ARM::hGPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7390 | continue; |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7391 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7392 | continue; |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7393 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7394 | continue; |
| 7395 | if (!DefRegs[Reg]) |
| 7396 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
| Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 7397 | } |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7398 | |
| 7399 | break; |
| 7400 | } |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7401 | } |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7402 | |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7403 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 7404 | // landing pad now. |
| 7405 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 7406 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7407 | (*I)->setIsEHPad(false); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7408 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7409 | // The instruction is gone now. |
| 7410 | MI->eraseFromParent(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7411 | } |
| 7412 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7413 | static |
| 7414 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 7415 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 7416 | E = MBB->succ_end(); I != E; ++I) |
| 7417 | if (*I != Succ) |
| 7418 | return *I; |
| 7419 | llvm_unreachable("Expecting a BB with two successors!"); |
| 7420 | } |
| 7421 | |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7422 | /// Return the load opcode for a given load size. If load size >= 8, |
| 7423 | /// neon opcode will be returned. |
| 7424 | static unsigned getLdOpcode(unsigned LdSize, bool IsThumb1, bool IsThumb2) { |
| 7425 | if (LdSize >= 8) |
| 7426 | return LdSize == 16 ? ARM::VLD1q32wb_fixed |
| 7427 | : LdSize == 8 ? ARM::VLD1d32wb_fixed : 0; |
| 7428 | if (IsThumb1) |
| 7429 | return LdSize == 4 ? ARM::tLDRi |
| 7430 | : LdSize == 2 ? ARM::tLDRHi |
| 7431 | : LdSize == 1 ? ARM::tLDRBi : 0; |
| 7432 | if (IsThumb2) |
| 7433 | return LdSize == 4 ? ARM::t2LDR_POST |
| 7434 | : LdSize == 2 ? ARM::t2LDRH_POST |
| 7435 | : LdSize == 1 ? ARM::t2LDRB_POST : 0; |
| 7436 | return LdSize == 4 ? ARM::LDR_POST_IMM |
| 7437 | : LdSize == 2 ? ARM::LDRH_POST |
| 7438 | : LdSize == 1 ? ARM::LDRB_POST_IMM : 0; |
| 7439 | } |
| 7440 | |
| 7441 | /// Return the store opcode for a given store size. If store size >= 8, |
| 7442 | /// neon opcode will be returned. |
| 7443 | static unsigned getStOpcode(unsigned StSize, bool IsThumb1, bool IsThumb2) { |
| 7444 | if (StSize >= 8) |
| 7445 | return StSize == 16 ? ARM::VST1q32wb_fixed |
| 7446 | : StSize == 8 ? ARM::VST1d32wb_fixed : 0; |
| 7447 | if (IsThumb1) |
| 7448 | return StSize == 4 ? ARM::tSTRi |
| 7449 | : StSize == 2 ? ARM::tSTRHi |
| 7450 | : StSize == 1 ? ARM::tSTRBi : 0; |
| 7451 | if (IsThumb2) |
| 7452 | return StSize == 4 ? ARM::t2STR_POST |
| 7453 | : StSize == 2 ? ARM::t2STRH_POST |
| 7454 | : StSize == 1 ? ARM::t2STRB_POST : 0; |
| 7455 | return StSize == 4 ? ARM::STR_POST_IMM |
| 7456 | : StSize == 2 ? ARM::STRH_POST |
| 7457 | : StSize == 1 ? ARM::STRB_POST_IMM : 0; |
| 7458 | } |
| 7459 | |
| 7460 | /// Emit a post-increment load operation with given size. The instructions |
| 7461 | /// will be added to BB at Pos. |
| 7462 | static void emitPostLd(MachineBasicBlock *BB, MachineInstr *Pos, |
| 7463 | const TargetInstrInfo *TII, DebugLoc dl, |
| 7464 | unsigned LdSize, unsigned Data, unsigned AddrIn, |
| 7465 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { |
| 7466 | unsigned LdOpc = getLdOpcode(LdSize, IsThumb1, IsThumb2); |
| 7467 | assert(LdOpc != 0 && "Should have a load opcode"); |
| 7468 | if (LdSize >= 8) { |
| 7469 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7470 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7471 | .addImm(0)); |
| 7472 | } else if (IsThumb1) { |
| 7473 | // load + update AddrIn |
| 7474 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7475 | .addReg(AddrIn).addImm(0)); |
| 7476 | MachineInstrBuilder MIB = |
| 7477 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); |
| 7478 | MIB = AddDefaultT1CC(MIB); |
| 7479 | MIB.addReg(AddrIn).addImm(LdSize); |
| 7480 | AddDefaultPred(MIB); |
| 7481 | } else if (IsThumb2) { |
| 7482 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7483 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7484 | .addImm(LdSize)); |
| 7485 | } else { // arm |
| 7486 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7487 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7488 | .addReg(0).addImm(LdSize)); |
| 7489 | } |
| 7490 | } |
| 7491 | |
| 7492 | /// Emit a post-increment store operation with given size. The instructions |
| 7493 | /// will be added to BB at Pos. |
| 7494 | static void emitPostSt(MachineBasicBlock *BB, MachineInstr *Pos, |
| 7495 | const TargetInstrInfo *TII, DebugLoc dl, |
| 7496 | unsigned StSize, unsigned Data, unsigned AddrIn, |
| 7497 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { |
| 7498 | unsigned StOpc = getStOpcode(StSize, IsThumb1, IsThumb2); |
| 7499 | assert(StOpc != 0 && "Should have a store opcode"); |
| 7500 | if (StSize >= 8) { |
| 7501 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7502 | .addReg(AddrIn).addImm(0).addReg(Data)); |
| 7503 | } else if (IsThumb1) { |
| 7504 | // store + update AddrIn |
| 7505 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc)).addReg(Data) |
| 7506 | .addReg(AddrIn).addImm(0)); |
| 7507 | MachineInstrBuilder MIB = |
| 7508 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); |
| 7509 | MIB = AddDefaultT1CC(MIB); |
| 7510 | MIB.addReg(AddrIn).addImm(StSize); |
| 7511 | AddDefaultPred(MIB); |
| 7512 | } else if (IsThumb2) { |
| 7513 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7514 | .addReg(Data).addReg(AddrIn).addImm(StSize)); |
| 7515 | } else { // arm |
| 7516 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7517 | .addReg(Data).addReg(AddrIn).addReg(0) |
| 7518 | .addImm(StSize)); |
| 7519 | } |
| 7520 | } |
| 7521 | |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7522 | MachineBasicBlock * |
| 7523 | ARMTargetLowering::EmitStructByval(MachineInstr *MI, |
| 7524 | MachineBasicBlock *BB) const { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7525 | // This pseudo instruction has 3 operands: dst, src, size |
| 7526 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). |
| 7527 | // Otherwise, we will generate unrolled scalar copies. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7528 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7529 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 7530 | MachineFunction::iterator It = ++BB->getIterator(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7531 | |
| 7532 | unsigned dest = MI->getOperand(0).getReg(); |
| 7533 | unsigned src = MI->getOperand(1).getReg(); |
| 7534 | unsigned SizeVal = MI->getOperand(2).getImm(); |
| 7535 | unsigned Align = MI->getOperand(3).getImm(); |
| 7536 | DebugLoc dl = MI->getDebugLoc(); |
| 7537 | |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7538 | MachineFunction *MF = BB->getParent(); |
| 7539 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7540 | unsigned UnitSize = 0; |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 7541 | const TargetRegisterClass *TRC = nullptr; |
| 7542 | const TargetRegisterClass *VecTRC = nullptr; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7543 | |
| 7544 | bool IsThumb1 = Subtarget->isThumb1Only(); |
| 7545 | bool IsThumb2 = Subtarget->isThumb2(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7546 | |
| 7547 | if (Align & 1) { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7548 | UnitSize = 1; |
| 7549 | } else if (Align & 2) { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7550 | UnitSize = 2; |
| 7551 | } else { |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7552 | // Check whether we can use NEON instructions. |
| Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 7553 | if (!MF->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) && |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7554 | Subtarget->hasNEON()) { |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7555 | if ((Align % 16 == 0) && SizeVal >= 16) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7556 | UnitSize = 16; |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7557 | else if ((Align % 8 == 0) && SizeVal >= 8) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7558 | UnitSize = 8; |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7559 | } |
| 7560 | // Can't use NEON instructions. |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7561 | if (UnitSize == 0) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7562 | UnitSize = 4; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7563 | } |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7564 | |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7565 | // Select the correct opcode and register class for unit size load/store |
| 7566 | bool IsNeon = UnitSize >= 8; |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7567 | TRC = (IsThumb1 || IsThumb2) ? &ARM::tGPRRegClass : &ARM::GPRRegClass; |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7568 | if (IsNeon) |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7569 | VecTRC = UnitSize == 16 ? &ARM::DPairRegClass |
| 7570 | : UnitSize == 8 ? &ARM::DPRRegClass |
| 7571 | : nullptr; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7572 | |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7573 | unsigned BytesLeft = SizeVal % UnitSize; |
| 7574 | unsigned LoopSize = SizeVal - BytesLeft; |
| 7575 | |
| 7576 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { |
| 7577 | // Use LDR and STR to copy. |
| 7578 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) |
| 7579 | // [destOut] = STR_POST(scratch, destIn, UnitSize) |
| 7580 | unsigned srcIn = src; |
| 7581 | unsigned destIn = dest; |
| 7582 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7583 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7584 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7585 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7586 | emitPostLd(BB, MI, TII, dl, UnitSize, scratch, srcIn, srcOut, |
| 7587 | IsThumb1, IsThumb2); |
| 7588 | emitPostSt(BB, MI, TII, dl, UnitSize, scratch, destIn, destOut, |
| 7589 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7590 | srcIn = srcOut; |
| 7591 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7592 | } |
| 7593 | |
| 7594 | // Handle the leftover bytes with LDRB and STRB. |
| 7595 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) |
| 7596 | // [destOut] = STRB_POST(scratch, destIn, 1) |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7597 | for (unsigned i = 0; i < BytesLeft; i++) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7598 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7599 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7600 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7601 | emitPostLd(BB, MI, TII, dl, 1, scratch, srcIn, srcOut, |
| 7602 | IsThumb1, IsThumb2); |
| 7603 | emitPostSt(BB, MI, TII, dl, 1, scratch, destIn, destOut, |
| 7604 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7605 | srcIn = srcOut; |
| 7606 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7607 | } |
| 7608 | MI->eraseFromParent(); // The instruction is gone now. |
| 7609 | return BB; |
| 7610 | } |
| 7611 | |
| 7612 | // Expand the pseudo op to a loop. |
| 7613 | // thisMBB: |
| 7614 | // ... |
| 7615 | // movw varEnd, # --> with thumb2 |
| 7616 | // movt varEnd, # |
| 7617 | // ldrcp varEnd, idx --> without thumb2 |
| 7618 | // fallthrough --> loopMBB |
| 7619 | // loopMBB: |
| 7620 | // PHI varPhi, varEnd, varLoop |
| 7621 | // PHI srcPhi, src, srcLoop |
| 7622 | // PHI destPhi, dst, destLoop |
| 7623 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7624 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) |
| 7625 | // subs varLoop, varPhi, #UnitSize |
| 7626 | // bne loopMBB |
| 7627 | // fallthrough --> exitMBB |
| 7628 | // exitMBB: |
| 7629 | // epilogue to handle left-over bytes |
| 7630 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7631 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7632 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7633 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7634 | MF->insert(It, loopMBB); |
| 7635 | MF->insert(It, exitMBB); |
| 7636 | |
| 7637 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 7638 | exitMBB->splice(exitMBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7639 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7640 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7641 | |
| 7642 | // Load an immediate to varEnd. |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7643 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7644 | if (Subtarget->useMovt(*MF)) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7645 | unsigned Vtmp = varEnd; |
| 7646 | if ((LoopSize & 0xFFFF0000) != 0) |
| 7647 | Vtmp = MRI.createVirtualRegister(TRC); |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7648 | AddDefaultPred(BuildMI(BB, dl, |
| 7649 | TII->get(IsThumb2 ? ARM::t2MOVi16 : ARM::MOVi16), |
| 7650 | Vtmp).addImm(LoopSize & 0xFFFF)); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7651 | |
| 7652 | if ((LoopSize & 0xFFFF0000) != 0) |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7653 | AddDefaultPred(BuildMI(BB, dl, |
| 7654 | TII->get(IsThumb2 ? ARM::t2MOVTi16 : ARM::MOVTi16), |
| 7655 | varEnd) |
| 7656 | .addReg(Vtmp) |
| 7657 | .addImm(LoopSize >> 16)); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7658 | } else { |
| 7659 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 7660 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7661 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); |
| 7662 | |
| 7663 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7664 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7665 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7666 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7667 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 7668 | |
| 7669 | if (IsThumb1) |
| 7670 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::tLDRpci)).addReg( |
| 7671 | varEnd, RegState::Define).addConstantPoolIndex(Idx)); |
| 7672 | else |
| 7673 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::LDRcp)).addReg( |
| 7674 | varEnd, RegState::Define).addConstantPoolIndex(Idx).addImm(0)); |
| 7675 | } |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7676 | BB->addSuccessor(loopMBB); |
| 7677 | |
| 7678 | // Generate the loop body: |
| 7679 | // varPhi = PHI(varLoop, varEnd) |
| 7680 | // srcPhi = PHI(srcLoop, src) |
| 7681 | // destPhi = PHI(destLoop, dst) |
| 7682 | MachineBasicBlock *entryBB = BB; |
| 7683 | BB = loopMBB; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7684 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
| 7685 | unsigned varPhi = MRI.createVirtualRegister(TRC); |
| 7686 | unsigned srcLoop = MRI.createVirtualRegister(TRC); |
| 7687 | unsigned srcPhi = MRI.createVirtualRegister(TRC); |
| 7688 | unsigned destLoop = MRI.createVirtualRegister(TRC); |
| 7689 | unsigned destPhi = MRI.createVirtualRegister(TRC); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7690 | |
| 7691 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) |
| 7692 | .addReg(varLoop).addMBB(loopMBB) |
| 7693 | .addReg(varEnd).addMBB(entryBB); |
| 7694 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) |
| 7695 | .addReg(srcLoop).addMBB(loopMBB) |
| 7696 | .addReg(src).addMBB(entryBB); |
| 7697 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) |
| 7698 | .addReg(destLoop).addMBB(loopMBB) |
| 7699 | .addReg(dest).addMBB(entryBB); |
| 7700 | |
| 7701 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7702 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7703 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7704 | emitPostLd(BB, BB->end(), TII, dl, UnitSize, scratch, srcPhi, srcLoop, |
| 7705 | IsThumb1, IsThumb2); |
| 7706 | emitPostSt(BB, BB->end(), TII, dl, UnitSize, scratch, destPhi, destLoop, |
| 7707 | IsThumb1, IsThumb2); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7708 | |
| 7709 | // Decrement loop variable by UnitSize. |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7710 | if (IsThumb1) { |
| 7711 | MachineInstrBuilder MIB = |
| 7712 | BuildMI(*BB, BB->end(), dl, TII->get(ARM::tSUBi8), varLoop); |
| 7713 | MIB = AddDefaultT1CC(MIB); |
| 7714 | MIB.addReg(varPhi).addImm(UnitSize); |
| 7715 | AddDefaultPred(MIB); |
| 7716 | } else { |
| 7717 | MachineInstrBuilder MIB = |
| 7718 | BuildMI(*BB, BB->end(), dl, |
| 7719 | TII->get(IsThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); |
| 7720 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); |
| 7721 | MIB->getOperand(5).setReg(ARM::CPSR); |
| 7722 | MIB->getOperand(5).setIsDef(true); |
| 7723 | } |
| 7724 | BuildMI(*BB, BB->end(), dl, |
| 7725 | TII->get(IsThumb1 ? ARM::tBcc : IsThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7726 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7727 | |
| 7728 | // loopMBB can loop back to loopMBB or fall through to exitMBB. |
| 7729 | BB->addSuccessor(loopMBB); |
| 7730 | BB->addSuccessor(exitMBB); |
| 7731 | |
| 7732 | // Add epilogue to handle BytesLeft. |
| 7733 | BB = exitMBB; |
| 7734 | MachineInstr *StartOfExit = exitMBB->begin(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7735 | |
| 7736 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7737 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7738 | unsigned srcIn = srcLoop; |
| 7739 | unsigned destIn = destLoop; |
| 7740 | for (unsigned i = 0; i < BytesLeft; i++) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7741 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7742 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7743 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7744 | emitPostLd(BB, StartOfExit, TII, dl, 1, scratch, srcIn, srcOut, |
| 7745 | IsThumb1, IsThumb2); |
| 7746 | emitPostSt(BB, StartOfExit, TII, dl, 1, scratch, destIn, destOut, |
| 7747 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7748 | srcIn = srcOut; |
| 7749 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7750 | } |
| 7751 | |
| 7752 | MI->eraseFromParent(); // The instruction is gone now. |
| 7753 | return BB; |
| 7754 | } |
| 7755 | |
| Jim Grosbach | 8f9a3ac | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7756 | MachineBasicBlock * |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7757 | ARMTargetLowering::EmitLowered__chkstk(MachineInstr *MI, |
| 7758 | MachineBasicBlock *MBB) const { |
| 7759 | const TargetMachine &TM = getTargetMachine(); |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7760 | const TargetInstrInfo &TII = *Subtarget->getInstrInfo(); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7761 | DebugLoc DL = MI->getDebugLoc(); |
| 7762 | |
| 7763 | assert(Subtarget->isTargetWindows() && |
| 7764 | "__chkstk is only supported on Windows"); |
| 7765 | assert(Subtarget->isThumb2() && "Windows on ARM requires Thumb-2 mode"); |
| 7766 | |
| 7767 | // __chkstk takes the number of words to allocate on the stack in R4, and |
| 7768 | // returns the stack adjustment in number of bytes in R4. This will not |
| 7769 | // clober any other registers (other than the obvious lr). |
| 7770 | // |
| 7771 | // Although, technically, IP should be considered a register which may be |
| 7772 | // clobbered, the call itself will not touch it. Windows on ARM is a pure |
| 7773 | // thumb-2 environment, so there is no interworking required. As a result, we |
| 7774 | // do not expect a veneer to be emitted by the linker, clobbering IP. |
| 7775 | // |
| Alp Toker | 1d099d9 | 2014-06-19 19:41:26 +0000 | [diff] [blame] | 7776 | // Each module receives its own copy of __chkstk, so no import thunk is |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7777 | // required, again, ensuring that IP is not clobbered. |
| 7778 | // |
| 7779 | // Finally, although some linkers may theoretically provide a trampoline for |
| 7780 | // out of range calls (which is quite common due to a 32M range limitation of |
| 7781 | // branches for Thumb), we can generate the long-call version via |
| 7782 | // -mcmodel=large, alleviating the need for the trampoline which may clobber |
| 7783 | // IP. |
| 7784 | |
| 7785 | switch (TM.getCodeModel()) { |
| 7786 | case CodeModel::Small: |
| 7787 | case CodeModel::Medium: |
| 7788 | case CodeModel::Default: |
| 7789 | case CodeModel::Kernel: |
| 7790 | BuildMI(*MBB, MI, DL, TII.get(ARM::tBL)) |
| 7791 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 7792 | .addExternalSymbol("__chkstk") |
| 7793 | .addReg(ARM::R4, RegState::Implicit | RegState::Kill) |
| 7794 | .addReg(ARM::R4, RegState::Implicit | RegState::Define) |
| 7795 | .addReg(ARM::R12, RegState::Implicit | RegState::Define | RegState::Dead); |
| 7796 | break; |
| 7797 | case CodeModel::Large: |
| 7798 | case CodeModel::JITDefault: { |
| 7799 | MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); |
| 7800 | unsigned Reg = MRI.createVirtualRegister(&ARM::rGPRRegClass); |
| 7801 | |
| 7802 | BuildMI(*MBB, MI, DL, TII.get(ARM::t2MOVi32imm), Reg) |
| 7803 | .addExternalSymbol("__chkstk"); |
| 7804 | BuildMI(*MBB, MI, DL, TII.get(ARM::tBLXr)) |
| 7805 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 7806 | .addReg(Reg, RegState::Kill) |
| 7807 | .addReg(ARM::R4, RegState::Implicit | RegState::Kill) |
| 7808 | .addReg(ARM::R4, RegState::Implicit | RegState::Define) |
| 7809 | .addReg(ARM::R12, RegState::Implicit | RegState::Define | RegState::Dead); |
| 7810 | break; |
| 7811 | } |
| 7812 | } |
| 7813 | |
| 7814 | AddDefaultCC(AddDefaultPred(BuildMI(*MBB, MI, DL, TII.get(ARM::t2SUBrr), |
| 7815 | ARM::SP) |
| Saleem Abdulrasool | c4e0028 | 2014-07-19 01:29:51 +0000 | [diff] [blame] | 7816 | .addReg(ARM::SP).addReg(ARM::R4))); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7817 | |
| 7818 | MI->eraseFromParent(); |
| 7819 | return MBB; |
| 7820 | } |
| 7821 | |
| 7822 | MachineBasicBlock * |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 7823 | ARMTargetLowering::EmitLowered__dbzchk(MachineInstr *MI, |
| 7824 | MachineBasicBlock *MBB) const { |
| 7825 | DebugLoc DL = MI->getDebugLoc(); |
| 7826 | MachineFunction *MF = MBB->getParent(); |
| 7827 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| 7828 | |
| 7829 | MachineBasicBlock *ContBB = MF->CreateMachineBasicBlock(); |
| 7830 | MF->push_back(ContBB); |
| 7831 | ContBB->splice(ContBB->begin(), MBB, |
| 7832 | std::next(MachineBasicBlock::iterator(MI)), MBB->end()); |
| 7833 | MBB->addSuccessor(ContBB); |
| 7834 | |
| 7835 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
| 7836 | MF->push_back(TrapBB); |
| 7837 | BuildMI(TrapBB, DL, TII->get(ARM::t2UDF)).addImm(249); |
| 7838 | MBB->addSuccessor(TrapBB); |
| 7839 | |
| 7840 | BuildMI(*MBB, MI, DL, TII->get(ARM::tCBZ)) |
| 7841 | .addReg(MI->getOperand(0).getReg()) |
| 7842 | .addMBB(TrapBB); |
| 7843 | |
| 7844 | MI->eraseFromParent(); |
| 7845 | return ContBB; |
| 7846 | } |
| 7847 | |
| 7848 | MachineBasicBlock * |
| Evan Cheng | 29cfb67 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 7849 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 7850 | MachineBasicBlock *BB) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7851 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Dale Johannesen | 7647da6 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 7852 | DebugLoc dl = MI->getDebugLoc(); |
| Jim Grosbach | 57ccc19 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 7853 | bool isThumb2 = Subtarget->isThumb2(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7854 | switch (MI->getOpcode()) { |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7855 | default: { |
| Jim Grosbach | 5c4e99f | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 7856 | MI->dump(); |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7857 | llvm_unreachable("Unexpected instr type to insert"); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 7858 | } |
| Jim Grosbach | 9c0b86a | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 7859 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 7860 | // define them differently in the .td files from the isel patterns, so |
| 7861 | // they need pseudos. |
| 7862 | case ARM::t2STR_preidx: |
| 7863 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 7864 | return BB; |
| 7865 | case ARM::t2STRB_preidx: |
| 7866 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 7867 | return BB; |
| 7868 | case ARM::t2STRH_preidx: |
| 7869 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 7870 | return BB; |
| 7871 | |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7872 | case ARM::STRi_preidx: |
| 7873 | case ARM::STRBi_preidx: { |
| Jim Grosbach | 5e80abb | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 7874 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7875 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 7876 | // Decode the offset. |
| 7877 | unsigned Offset = MI->getOperand(4).getImm(); |
| 7878 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 7879 | Offset = ARM_AM::getAM2Offset(Offset); |
| 7880 | if (isSub) |
| 7881 | Offset = -Offset; |
| 7882 | |
| Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7883 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
| Benjamin Kramer | 61a1ff5 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 7884 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7885 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 7886 | .addOperand(MI->getOperand(1)) // Rt |
| 7887 | .addOperand(MI->getOperand(2)) // Rn |
| 7888 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 7889 | .addOperand(MI->getOperand(5)) // pred |
| Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 7890 | .addOperand(MI->getOperand(6)) |
| 7891 | .addMemOperand(MMO); |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7892 | MI->eraseFromParent(); |
| 7893 | return BB; |
| 7894 | } |
| 7895 | case ARM::STRr_preidx: |
| Jim Grosbach | d886f8c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 7896 | case ARM::STRBr_preidx: |
| 7897 | case ARM::STRH_preidx: { |
| 7898 | unsigned NewOpc; |
| 7899 | switch (MI->getOpcode()) { |
| 7900 | default: llvm_unreachable("unexpected opcode!"); |
| 7901 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 7902 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 7903 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 7904 | } |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 7905 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 7906 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 7907 | MIB.addOperand(MI->getOperand(i)); |
| 7908 | MI->eraseFromParent(); |
| 7909 | return BB; |
| 7910 | } |
| Eli Friedman | c3f9c4a | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 7911 | |
| Evan Cheng | bb2af35 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 7912 | case ARM::tMOVCCr_pseudo: { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7913 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 7914 | // diamond control-flow pattern. The incoming instruction knows the |
| 7915 | // destination vreg to set, the condition code register to branch on, the |
| 7916 | // true/false values to select between, and a branch opcode to use. |
| 7917 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 7918 | MachineFunction::iterator It = ++BB->getIterator(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7919 | |
| 7920 | // thisMBB: |
| 7921 | // ... |
| 7922 | // TrueVal = ... |
| 7923 | // cmpTY ccX, r1, r2 |
| 7924 | // bCC copy1MBB |
| 7925 | // fallthrough --> copy0MBB |
| 7926 | MachineBasicBlock *thisMBB = BB; |
| Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 7927 | MachineFunction *F = BB->getParent(); |
| 7928 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 7929 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
| Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7930 | F->insert(It, copy0MBB); |
| 7931 | F->insert(It, sinkMBB); |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7932 | |
| 7933 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 7934 | sinkMBB->splice(sinkMBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7935 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7936 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7937 | |
| Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 7938 | BB->addSuccessor(copy0MBB); |
| 7939 | BB->addSuccessor(sinkMBB); |
| Dan Gohman | 1220564 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 7940 | |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7941 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 7942 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 7943 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7944 | // copy0MBB: |
| 7945 | // %FalseValue = ... |
| 7946 | // # fallthrough to sinkMBB |
| 7947 | BB = copy0MBB; |
| 7948 | |
| 7949 | // Update machine-CFG edges |
| 7950 | BB->addSuccessor(sinkMBB); |
| 7951 | |
| 7952 | // sinkMBB: |
| 7953 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 7954 | // ... |
| 7955 | BB = sinkMBB; |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7956 | BuildMI(*BB, BB->begin(), dl, |
| 7957 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7958 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 7959 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 7960 | |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 7961 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7962 | return BB; |
| 7963 | } |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 7964 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7965 | case ARM::BCCi64: |
| 7966 | case ARM::BCCZi64: { |
| Bob Wilson | 36be00c | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 7967 | // If there is an unconditional branch to the other successor, remove it. |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7968 | BB->erase(std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 7969 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7970 | // Compare both parts that make up the double comparison separately for |
| 7971 | // equality. |
| 7972 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 7973 | |
| 7974 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 7975 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 7976 | if (RHSisZero) { |
| 7977 | AddDefaultPred(BuildMI(BB, dl, |
| 7978 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7979 | .addReg(LHS1).addImm(0)); |
| 7980 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 7981 | .addReg(LHS2).addImm(0) |
| 7982 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7983 | } else { |
| 7984 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 7985 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 7986 | AddDefaultPred(BuildMI(BB, dl, |
| 7987 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7988 | .addReg(LHS1).addReg(RHS1)); |
| 7989 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 7990 | .addReg(LHS2).addReg(RHS2) |
| 7991 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 7992 | } |
| 7993 | |
| 7994 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 7995 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 7996 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 7997 | std::swap(destMBB, exitMBB); |
| 7998 | |
| 7999 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 8000 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8001 | if (isThumb2) |
| 8002 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 8003 | else |
| 8004 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 8005 | |
| 8006 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 8007 | return BB; |
| 8008 | } |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8009 | |
| Bill Wendling | f7f223f | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 8010 | case ARM::Int_eh_sjlj_setjmp: |
| 8011 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 8012 | case ARM::tInt_eh_sjlj_setjmp: |
| 8013 | case ARM::t2Int_eh_sjlj_setjmp: |
| 8014 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 8015 | return BB; |
| 8016 | |
| 8017 | case ARM::Int_eh_sjlj_setup_dispatch: |
| Bill Wendling | f7f223f | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 8018 | EmitSjLjDispatchBlock(MI, BB); |
| 8019 | return BB; |
| 8020 | |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8021 | case ARM::ABS: |
| 8022 | case ARM::t2ABS: { |
| 8023 | // To insert an ABS instruction, we have to insert the |
| 8024 | // diamond control-flow pattern. The incoming instruction knows the |
| 8025 | // source vreg to test against 0, the destination vreg to set, |
| 8026 | // the condition code register to branch on, the |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8027 | // true/false values to select between, and a branch opcode to use. |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8028 | // It transforms |
| 8029 | // V1 = ABS V0 |
| 8030 | // into |
| 8031 | // V2 = MOVS V0 |
| 8032 | // BCC (branch to SinkBB if V0 >= 0) |
| 8033 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8034 | // SinkBB: V1 = PHI(V2, V3) |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8035 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 8036 | MachineFunction::iterator BBI = ++BB->getIterator(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8037 | MachineFunction *Fn = BB->getParent(); |
| 8038 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 8039 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 8040 | Fn->insert(BBI, RSBBB); |
| 8041 | Fn->insert(BBI, SinkBB); |
| 8042 | |
| 8043 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 8044 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| Pete Cooper | 5111881 | 2015-04-30 22:15:59 +0000 | [diff] [blame] | 8045 | bool ABSSrcKIll = MI->getOperand(1).isKill(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8046 | bool isThumb2 = Subtarget->isThumb2(); |
| 8047 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 8048 | // In Thumb mode S must not be specified if source register is the SP or |
| 8049 | // PC and if destination register is the SP, so restrict register class |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 8050 | unsigned NewRsbDstReg = |
| 8051 | MRI.createVirtualRegister(isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRRegClass); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8052 | |
| 8053 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 8054 | SinkBB->splice(SinkBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8055 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8056 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 8057 | |
| 8058 | BB->addSuccessor(RSBBB); |
| 8059 | BB->addSuccessor(SinkBB); |
| 8060 | |
| 8061 | // fall through to SinkMBB |
| 8062 | RSBBB->addSuccessor(SinkBB); |
| 8063 | |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8064 | // insert a cmp at the end of BB |
| Andrew Trick | bc32516 | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8065 | AddDefaultPred(BuildMI(BB, dl, |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8066 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 8067 | .addReg(ABSSrcReg).addImm(0)); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8068 | |
| 8069 | // insert a bcc with opposite CC to ARMCC::MI at the end of BB |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8070 | BuildMI(BB, dl, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8071 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 8072 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 8073 | |
| 8074 | // insert rsbri in RSBBB |
| 8075 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 8076 | // by if-conversion pass |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8077 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8078 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| Pete Cooper | 5111881 | 2015-04-30 22:15:59 +0000 | [diff] [blame] | 8079 | .addReg(ABSSrcReg, ABSSrcKIll ? RegState::Kill : 0) |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8080 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 8081 | |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8082 | // insert PHI in SinkBB, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8083 | // reuse ABSDstReg to not change uses of ABS instruction |
| 8084 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 8085 | TII->get(ARM::PHI), ABSDstReg) |
| 8086 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8087 | .addReg(ABSSrcReg).addMBB(BB); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8088 | |
| 8089 | // remove ABS instruction |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8090 | MI->eraseFromParent(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8091 | |
| 8092 | // return last added BB |
| 8093 | return SinkBB; |
| 8094 | } |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 8095 | case ARM::COPY_STRUCT_BYVAL_I32: |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 8096 | ++NumLoopByVals; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 8097 | return EmitStructByval(MI, BB); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 8098 | case ARM::WIN__CHKSTK: |
| 8099 | return EmitLowered__chkstk(MI, BB); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 8100 | case ARM::WIN__DBZCHK: |
| 8101 | return EmitLowered__dbzchk(MI, BB); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8102 | } |
| 8103 | } |
| 8104 | |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 8105 | /// \brief Attaches vregs to MEMCPY that it will use as scratch registers |
| 8106 | /// when it is expanded into LDM/STM. This is done as a post-isel lowering |
| 8107 | /// instead of as a custom inserter because we need the use list from the SDNode. |
| 8108 | static void attachMEMCPYScratchRegs(const ARMSubtarget *Subtarget, |
| 8109 | MachineInstr *MI, const SDNode *Node) { |
| 8110 | bool isThumb1 = Subtarget->isThumb1Only(); |
| 8111 | |
| 8112 | DebugLoc DL = MI->getDebugLoc(); |
| 8113 | MachineFunction *MF = MI->getParent()->getParent(); |
| 8114 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 8115 | MachineInstrBuilder MIB(*MF, MI); |
| 8116 | |
| 8117 | // If the new dst/src is unused mark it as dead. |
| 8118 | if (!Node->hasAnyUseOfValue(0)) { |
| 8119 | MI->getOperand(0).setIsDead(true); |
| 8120 | } |
| 8121 | if (!Node->hasAnyUseOfValue(1)) { |
| 8122 | MI->getOperand(1).setIsDead(true); |
| 8123 | } |
| 8124 | |
| 8125 | // The MEMCPY both defines and kills the scratch registers. |
| 8126 | for (unsigned I = 0; I != MI->getOperand(4).getImm(); ++I) { |
| 8127 | unsigned TmpReg = MRI.createVirtualRegister(isThumb1 ? &ARM::tGPRRegClass |
| 8128 | : &ARM::GPRRegClass); |
| 8129 | MIB.addReg(TmpReg, RegState::Define|RegState::Dead); |
| 8130 | } |
| 8131 | } |
| 8132 | |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8133 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 8134 | SDNode *Node) const { |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 8135 | if (MI->getOpcode() == ARM::MEMCPY) { |
| 8136 | attachMEMCPYScratchRegs(Subtarget, MI, Node); |
| 8137 | return; |
| 8138 | } |
| 8139 | |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 8140 | const MCInstrDesc *MCID = &MI->getDesc(); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8141 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 8142 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 8143 | // operand is still set to noreg. If needed, set the optional operand's |
| 8144 | // register to CPSR, and remove the redundant implicit def. |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8145 | // |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8146 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8147 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8148 | // Rename pseudo opcodes. |
| 8149 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 8150 | if (NewOpc) { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 8151 | const ARMBaseInstrInfo *TII = Subtarget->getInstrInfo(); |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8152 | MCID = &TII->get(NewOpc); |
| 8153 | |
| 8154 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 8155 | "converted opcode should be the same except for cc_out"); |
| 8156 | |
| 8157 | MI->setDesc(*MCID); |
| 8158 | |
| 8159 | // Add the optional cc_out operand |
| 8160 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8161 | } |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8162 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8163 | |
| 8164 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 8165 | // "cc_out" operand in the last operand position. |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 8166 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8167 | assert(!NewOpc && "Optional cc_out operand required"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8168 | return; |
| 8169 | } |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8170 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 8171 | // since we already have an optional CPSR def. |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8172 | bool definesCPSR = false; |
| 8173 | bool deadCPSR = false; |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8174 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8175 | i != e; ++i) { |
| 8176 | const MachineOperand &MO = MI->getOperand(i); |
| 8177 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 8178 | definesCPSR = true; |
| 8179 | if (MO.isDead()) |
| 8180 | deadCPSR = true; |
| 8181 | MI->RemoveOperand(i); |
| 8182 | break; |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8183 | } |
| 8184 | } |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8185 | if (!definesCPSR) { |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8186 | assert(!NewOpc && "Optional cc_out operand required"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8187 | return; |
| 8188 | } |
| 8189 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8190 | if (deadCPSR) { |
| 8191 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 8192 | "expect uninitialized optional cc_out operand"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8193 | return; |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8194 | } |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8195 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8196 | // If this instruction was defined with an optional CPSR def and its dag node |
| 8197 | // had a live implicit CPSR def, then activate the optional CPSR def. |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8198 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 8199 | MO.setReg(ARM::CPSR); |
| 8200 | MO.setIsDef(true); |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8201 | } |
| 8202 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8203 | //===----------------------------------------------------------------------===// |
| 8204 | // ARM Optimization Hooks |
| 8205 | //===----------------------------------------------------------------------===// |
| 8206 | |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8207 | // Helper function that checks if N is a null or all ones constant. |
| 8208 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { |
| 8209 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N); |
| 8210 | if (!C) |
| 8211 | return false; |
| 8212 | return AllOnes ? C->isAllOnesValue() : C->isNullValue(); |
| 8213 | } |
| 8214 | |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8215 | // Return true if N is conditionally 0 or all ones. |
| 8216 | // Detects these expressions where cc is an i1 value: |
| 8217 | // |
| 8218 | // (select cc 0, y) [AllOnes=0] |
| 8219 | // (select cc y, 0) [AllOnes=0] |
| 8220 | // (zext cc) [AllOnes=0] |
| 8221 | // (sext cc) [AllOnes=0/1] |
| 8222 | // (select cc -1, y) [AllOnes=1] |
| 8223 | // (select cc y, -1) [AllOnes=1] |
| 8224 | // |
| 8225 | // Invert is set when N is the null/all ones constant when CC is false. |
| 8226 | // OtherOp is set to the alternative value of N. |
| 8227 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, |
| 8228 | SDValue &CC, bool &Invert, |
| 8229 | SDValue &OtherOp, |
| 8230 | SelectionDAG &DAG) { |
| 8231 | switch (N->getOpcode()) { |
| 8232 | default: return false; |
| 8233 | case ISD::SELECT: { |
| 8234 | CC = N->getOperand(0); |
| 8235 | SDValue N1 = N->getOperand(1); |
| 8236 | SDValue N2 = N->getOperand(2); |
| 8237 | if (isZeroOrAllOnes(N1, AllOnes)) { |
| 8238 | Invert = false; |
| 8239 | OtherOp = N2; |
| 8240 | return true; |
| 8241 | } |
| 8242 | if (isZeroOrAllOnes(N2, AllOnes)) { |
| 8243 | Invert = true; |
| 8244 | OtherOp = N1; |
| 8245 | return true; |
| 8246 | } |
| 8247 | return false; |
| 8248 | } |
| 8249 | case ISD::ZERO_EXTEND: |
| 8250 | // (zext cc) can never be the all ones value. |
| 8251 | if (AllOnes) |
| 8252 | return false; |
| 8253 | // Fall through. |
| 8254 | case ISD::SIGN_EXTEND: { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8255 | SDLoc dl(N); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8256 | EVT VT = N->getValueType(0); |
| 8257 | CC = N->getOperand(0); |
| 8258 | if (CC.getValueType() != MVT::i1) |
| 8259 | return false; |
| 8260 | Invert = !AllOnes; |
| 8261 | if (AllOnes) |
| 8262 | // When looking for an AllOnes constant, N is an sext, and the 'other' |
| 8263 | // value is 0. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8264 | OtherOp = DAG.getConstant(0, dl, VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8265 | else if (N->getOpcode() == ISD::ZERO_EXTEND) |
| 8266 | // When looking for a 0 constant, N can be zext or sext. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8267 | OtherOp = DAG.getConstant(1, dl, VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8268 | else |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8269 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), dl, |
| 8270 | VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8271 | return true; |
| 8272 | } |
| 8273 | } |
| 8274 | } |
| 8275 | |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8276 | // Combine a constant select operand into its use: |
| 8277 | // |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8278 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 8279 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 8280 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] |
| 8281 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 8282 | // (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8283 | // |
| 8284 | // The transform is rejected if the select doesn't have a constant operand that |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8285 | // is null, or all ones when AllOnes is set. |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8286 | // |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8287 | // Also recognize sext/zext from i1: |
| 8288 | // |
| 8289 | // (add (zext cc), x) -> (select cc (add x, 1), x) |
| 8290 | // (add (sext cc), x) -> (select cc (add x, -1), x) |
| 8291 | // |
| 8292 | // These transformations eventually create predicated instructions. |
| 8293 | // |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8294 | // @param N The node to transform. |
| 8295 | // @param Slct The N operand that is a select. |
| 8296 | // @param OtherOp The other N operand (x above). |
| 8297 | // @param DCI Context. |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8298 | // @param AllOnes Require the select constant to be all ones instead of null. |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8299 | // @returns The new node, or SDValue() on failure. |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8300 | static |
| 8301 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8302 | TargetLowering::DAGCombinerInfo &DCI, |
| 8303 | bool AllOnes = false) { |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8304 | SelectionDAG &DAG = DCI.DAG; |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8305 | EVT VT = N->getValueType(0); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8306 | SDValue NonConstantVal; |
| 8307 | SDValue CCOp; |
| 8308 | bool SwapSelectOps; |
| 8309 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, |
| 8310 | NonConstantVal, DAG)) |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8311 | return SDValue(); |
| 8312 | |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8313 | // Slct is now know to be the desired identity constant when CC is true. |
| 8314 | SDValue TrueVal = OtherOp; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8315 | SDValue FalseVal = DAG.getNode(N->getOpcode(), SDLoc(N), VT, |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8316 | OtherOp, NonConstantVal); |
| 8317 | // Unless SwapSelectOps says CC should be false. |
| 8318 | if (SwapSelectOps) |
| 8319 | std::swap(TrueVal, FalseVal); |
| 8320 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8321 | return DAG.getNode(ISD::SELECT, SDLoc(N), VT, |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8322 | CCOp, TrueVal, FalseVal); |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8323 | } |
| 8324 | |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8325 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
| 8326 | static |
| 8327 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, |
| 8328 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8329 | SDValue N0 = N->getOperand(0); |
| 8330 | SDValue N1 = N->getOperand(1); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8331 | if (N0.getNode()->hasOneUse()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8332 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes); |
| 8333 | if (Result.getNode()) |
| 8334 | return Result; |
| 8335 | } |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8336 | if (N1.getNode()->hasOneUse()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8337 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes); |
| 8338 | if (Result.getNode()) |
| 8339 | return Result; |
| 8340 | } |
| 8341 | return SDValue(); |
| 8342 | } |
| 8343 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8344 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8345 | // (only after legalization). |
| 8346 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 8347 | TargetLowering::DAGCombinerInfo &DCI, |
| 8348 | const ARMSubtarget *Subtarget) { |
| 8349 | |
| 8350 | // Only perform optimization if after legalize, and if NEON is available. We |
| 8351 | // also expected both operands to be BUILD_VECTORs. |
| 8352 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 8353 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 8354 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 8355 | return SDValue(); |
| 8356 | |
| 8357 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 8358 | EVT VT = N->getValueType(0); |
| 8359 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 8360 | return SDValue(); |
| 8361 | |
| 8362 | // Check that the vector operands are of the right form. |
| 8363 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 8364 | // operands, where N is the size of the formed vector. |
| 8365 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 8366 | // index such that we have a pair wise add pattern. |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8367 | |
| 8368 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
| Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 8369 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8370 | return SDValue(); |
| Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 8371 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 8372 | SDNode *V = Vec.getNode(); |
| 8373 | unsigned nextIndex = 0; |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8374 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8375 | // For each operands to the ADD which are BUILD_VECTORs, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8376 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 8377 | // the same vector and appropriate index. |
| 8378 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 8379 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 8380 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8381 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8382 | SDValue ExtVec0 = N0->getOperand(i); |
| 8383 | SDValue ExtVec1 = N1->getOperand(i); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8384 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8385 | // First operand is the vector, verify its the same. |
| 8386 | if (V != ExtVec0->getOperand(0).getNode() || |
| 8387 | V != ExtVec1->getOperand(0).getNode()) |
| 8388 | return SDValue(); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8389 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8390 | // Second is the constant, verify its correct. |
| 8391 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 8392 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8393 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8394 | // For the constant, we want to see all the even or all the odd. |
| 8395 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 8396 | || C1->getZExtValue() != nextIndex+1) |
| 8397 | return SDValue(); |
| 8398 | |
| 8399 | // Increment index. |
| 8400 | nextIndex+=2; |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8401 | } else |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8402 | return SDValue(); |
| 8403 | } |
| 8404 | |
| 8405 | // Create VPADDL node. |
| 8406 | SelectionDAG &DAG = DCI.DAG; |
| 8407 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8408 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8409 | SDLoc dl(N); |
| 8410 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8411 | // Build operand list. |
| 8412 | SmallVector<SDValue, 8> Ops; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8413 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, dl, |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8414 | TLI.getPointerTy(DAG.getDataLayout()))); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8415 | |
| 8416 | // Input is the vector. |
| 8417 | Ops.push_back(Vec); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8418 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8419 | // Get widened type and narrowed type. |
| 8420 | MVT widenType; |
| 8421 | unsigned numElem = VT.getVectorNumElements(); |
| Oliver Stannard | 6cb2346 | 2015-05-18 16:39:16 +0000 | [diff] [blame] | 8422 | |
| Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 8423 | EVT inputLaneType = Vec.getValueType().getVectorElementType(); |
| 8424 | switch (inputLaneType.getSimpleVT().SimpleTy) { |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8425 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 8426 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 8427 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 8428 | default: |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8429 | llvm_unreachable("Invalid vector element type for padd optimization."); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8430 | } |
| 8431 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8432 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, widenType, Ops); |
| Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 8433 | unsigned ExtOp = VT.bitsGT(tmp.getValueType()) ? ISD::ANY_EXTEND : ISD::TRUNCATE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8434 | return DAG.getNode(ExtOp, dl, VT, tmp); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8435 | } |
| 8436 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8437 | static SDValue findMUL_LOHI(SDValue V) { |
| 8438 | if (V->getOpcode() == ISD::UMUL_LOHI || |
| 8439 | V->getOpcode() == ISD::SMUL_LOHI) |
| 8440 | return V; |
| 8441 | return SDValue(); |
| 8442 | } |
| 8443 | |
| 8444 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, |
| 8445 | TargetLowering::DAGCombinerInfo &DCI, |
| 8446 | const ARMSubtarget *Subtarget) { |
| 8447 | |
| 8448 | if (Subtarget->isThumb1Only()) return SDValue(); |
| 8449 | |
| 8450 | // Only perform the checks after legalize when the pattern is available. |
| 8451 | if (DCI.isBeforeLegalize()) return SDValue(); |
| 8452 | |
| 8453 | // Look for multiply add opportunities. |
| 8454 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where |
| 8455 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is |
| 8456 | // a glue link from the first add to the second add. |
| 8457 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by |
| 8458 | // a S/UMLAL instruction. |
| Matthias Braun | 6091208 | 2015-05-20 18:40:06 +0000 | [diff] [blame] | 8459 | // UMUL_LOHI |
| 8460 | // / :lo \ :hi |
| 8461 | // / \ [no multiline comment] |
| 8462 | // loAdd -> ADDE | |
| 8463 | // \ :glue / |
| 8464 | // \ / |
| 8465 | // ADDC <- hiAdd |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8466 | // |
| 8467 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); |
| 8468 | SDValue AddcOp0 = AddcNode->getOperand(0); |
| 8469 | SDValue AddcOp1 = AddcNode->getOperand(1); |
| 8470 | |
| 8471 | // Check if the two operands are from the same mul_lohi node. |
| 8472 | if (AddcOp0.getNode() == AddcOp1.getNode()) |
| 8473 | return SDValue(); |
| 8474 | |
| 8475 | assert(AddcNode->getNumValues() == 2 && |
| 8476 | AddcNode->getValueType(0) == MVT::i32 && |
| Michael Gottesman | b2a7056 | 2013-06-18 20:49:40 +0000 | [diff] [blame] | 8477 | "Expect ADDC with two result values. First: i32"); |
| 8478 | |
| 8479 | // Check that we have a glued ADDC node. |
| 8480 | if (AddcNode->getValueType(1) != MVT::Glue) |
| 8481 | return SDValue(); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8482 | |
| 8483 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. |
| 8484 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && |
| 8485 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && |
| 8486 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && |
| 8487 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) |
| 8488 | return SDValue(); |
| 8489 | |
| 8490 | // Look for the glued ADDE. |
| 8491 | SDNode* AddeNode = AddcNode->getGluedUser(); |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8492 | if (!AddeNode) |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8493 | return SDValue(); |
| 8494 | |
| 8495 | // Make sure it is really an ADDE. |
| 8496 | if (AddeNode->getOpcode() != ISD::ADDE) |
| 8497 | return SDValue(); |
| 8498 | |
| 8499 | assert(AddeNode->getNumOperands() == 3 && |
| 8500 | AddeNode->getOperand(2).getValueType() == MVT::Glue && |
| 8501 | "ADDE node has the wrong inputs"); |
| 8502 | |
| 8503 | // Check for the triangle shape. |
| 8504 | SDValue AddeOp0 = AddeNode->getOperand(0); |
| 8505 | SDValue AddeOp1 = AddeNode->getOperand(1); |
| 8506 | |
| 8507 | // Make sure that the ADDE operands are not coming from the same node. |
| 8508 | if (AddeOp0.getNode() == AddeOp1.getNode()) |
| 8509 | return SDValue(); |
| 8510 | |
| 8511 | // Find the MUL_LOHI node walking up ADDE's operands. |
| 8512 | bool IsLeftOperandMUL = false; |
| 8513 | SDValue MULOp = findMUL_LOHI(AddeOp0); |
| 8514 | if (MULOp == SDValue()) |
| 8515 | MULOp = findMUL_LOHI(AddeOp1); |
| 8516 | else |
| 8517 | IsLeftOperandMUL = true; |
| 8518 | if (MULOp == SDValue()) |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8519 | return SDValue(); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8520 | |
| 8521 | // Figure out the right opcode. |
| 8522 | unsigned Opc = MULOp->getOpcode(); |
| 8523 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; |
| 8524 | |
| 8525 | // Figure out the high and low input values to the MLAL node. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8526 | SDValue* HiAdd = nullptr; |
| 8527 | SDValue* LoMul = nullptr; |
| 8528 | SDValue* LowAdd = nullptr; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8529 | |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8530 | // Ensure that ADDE is from high result of ISD::SMUL_LOHI. |
| 8531 | if ((AddeOp0 != MULOp.getValue(1)) && (AddeOp1 != MULOp.getValue(1))) |
| 8532 | return SDValue(); |
| 8533 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8534 | if (IsLeftOperandMUL) |
| 8535 | HiAdd = &AddeOp1; |
| 8536 | else |
| 8537 | HiAdd = &AddeOp0; |
| 8538 | |
| 8539 | |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8540 | // Ensure that LoMul and LowAdd are taken from correct ISD::SMUL_LOHI node |
| 8541 | // whose low result is fed to the ADDC we are checking. |
| 8542 | |
| 8543 | if (AddcOp0 == MULOp.getValue(0)) { |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8544 | LoMul = &AddcOp0; |
| 8545 | LowAdd = &AddcOp1; |
| 8546 | } |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8547 | if (AddcOp1 == MULOp.getValue(0)) { |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8548 | LoMul = &AddcOp1; |
| 8549 | LowAdd = &AddcOp0; |
| 8550 | } |
| 8551 | |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8552 | if (!LoMul) |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8553 | return SDValue(); |
| 8554 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8555 | // Create the merged node. |
| 8556 | SelectionDAG &DAG = DCI.DAG; |
| 8557 | |
| 8558 | // Build operand list. |
| 8559 | SmallVector<SDValue, 8> Ops; |
| 8560 | Ops.push_back(LoMul->getOperand(0)); |
| 8561 | Ops.push_back(LoMul->getOperand(1)); |
| 8562 | Ops.push_back(*LowAdd); |
| 8563 | Ops.push_back(*HiAdd); |
| 8564 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8565 | SDValue MLALNode = DAG.getNode(FinalOpc, SDLoc(AddcNode), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 8566 | DAG.getVTList(MVT::i32, MVT::i32), Ops); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8567 | |
| 8568 | // Replace the ADDs' nodes uses by the MLA node's values. |
| 8569 | SDValue HiMLALResult(MLALNode.getNode(), 1); |
| 8570 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); |
| 8571 | |
| 8572 | SDValue LoMLALResult(MLALNode.getNode(), 0); |
| 8573 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); |
| 8574 | |
| 8575 | // Return original node to notify the driver to stop replacing. |
| 8576 | SDValue resNode(AddcNode, 0); |
| 8577 | return resNode; |
| 8578 | } |
| 8579 | |
| 8580 | /// PerformADDCCombine - Target-specific dag combine transform from |
| 8581 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. |
| 8582 | static SDValue PerformADDCCombine(SDNode *N, |
| 8583 | TargetLowering::DAGCombinerInfo &DCI, |
| 8584 | const ARMSubtarget *Subtarget) { |
| 8585 | |
| 8586 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); |
| 8587 | |
| 8588 | } |
| 8589 | |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8590 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 8591 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 8592 | /// called with the default operands, and if that fails, with commuted |
| 8593 | /// operands. |
| 8594 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8595 | TargetLowering::DAGCombinerInfo &DCI, |
| 8596 | const ARMSubtarget *Subtarget){ |
| 8597 | |
| 8598 | // Attempt to create vpaddl for this add. |
| 8599 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 8600 | if (Result.getNode()) |
| 8601 | return Result; |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8602 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8603 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8604 | if (N0.getNode()->hasOneUse()) { |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8605 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 8606 | if (Result.getNode()) return Result; |
| 8607 | } |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8608 | return SDValue(); |
| 8609 | } |
| 8610 | |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8611 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 8612 | /// |
| 8613 | static SDValue PerformADDCombine(SDNode *N, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8614 | TargetLowering::DAGCombinerInfo &DCI, |
| 8615 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8616 | SDValue N0 = N->getOperand(0); |
| 8617 | SDValue N1 = N->getOperand(1); |
| 8618 | |
| 8619 | // First try with the default operand order. |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8620 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8621 | if (Result.getNode()) |
| 8622 | return Result; |
| 8623 | |
| 8624 | // If that didn't work, try again with the operands commuted. |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8625 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8626 | } |
| 8627 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8628 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8629 | /// |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8630 | static SDValue PerformSUBCombine(SDNode *N, |
| 8631 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8632 | SDValue N0 = N->getOperand(0); |
| 8633 | SDValue N1 = N->getOperand(1); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8634 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8635 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8636 | if (N1.getNode()->hasOneUse()) { |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8637 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 8638 | if (Result.getNode()) return Result; |
| 8639 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8640 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8641 | return SDValue(); |
| 8642 | } |
| 8643 | |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8644 | /// PerformVMULCombine |
| 8645 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 8646 | /// special multiplier accumulator forwarding. |
| 8647 | /// vmul d3, d0, d2 |
| 8648 | /// vmla d3, d1, d2 |
| 8649 | /// is faster than |
| 8650 | /// vadd d3, d0, d1 |
| 8651 | /// vmul d3, d3, d2 |
| Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 8652 | // However, for (A + B) * (A + B), |
| 8653 | // vadd d2, d0, d1 |
| 8654 | // vmul d3, d0, d2 |
| 8655 | // vmla d3, d1, d2 |
| 8656 | // is slower than |
| 8657 | // vadd d2, d0, d1 |
| 8658 | // vmul d3, d2, d2 |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8659 | static SDValue PerformVMULCombine(SDNode *N, |
| 8660 | TargetLowering::DAGCombinerInfo &DCI, |
| 8661 | const ARMSubtarget *Subtarget) { |
| 8662 | if (!Subtarget->hasVMLxForwarding()) |
| 8663 | return SDValue(); |
| 8664 | |
| 8665 | SelectionDAG &DAG = DCI.DAG; |
| 8666 | SDValue N0 = N->getOperand(0); |
| 8667 | SDValue N1 = N->getOperand(1); |
| 8668 | unsigned Opcode = N0.getOpcode(); |
| 8669 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8670 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
| Chad Rosier | 2730162 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 8671 | Opcode = N1.getOpcode(); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8672 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8673 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 8674 | return SDValue(); |
| 8675 | std::swap(N0, N1); |
| 8676 | } |
| 8677 | |
| Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 8678 | if (N0 == N1) |
| 8679 | return SDValue(); |
| 8680 | |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8681 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8682 | SDLoc DL(N); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8683 | SDValue N00 = N0->getOperand(0); |
| 8684 | SDValue N01 = N0->getOperand(1); |
| 8685 | return DAG.getNode(Opcode, DL, VT, |
| 8686 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 8687 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 8688 | } |
| 8689 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8690 | static SDValue PerformMULCombine(SDNode *N, |
| 8691 | TargetLowering::DAGCombinerInfo &DCI, |
| 8692 | const ARMSubtarget *Subtarget) { |
| 8693 | SelectionDAG &DAG = DCI.DAG; |
| 8694 | |
| 8695 | if (Subtarget->isThumb1Only()) |
| 8696 | return SDValue(); |
| 8697 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8698 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8699 | return SDValue(); |
| 8700 | |
| 8701 | EVT VT = N->getValueType(0); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8702 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 8703 | return PerformVMULCombine(N, DCI, Subtarget); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8704 | if (VT != MVT::i32) |
| 8705 | return SDValue(); |
| 8706 | |
| 8707 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 8708 | if (!C) |
| 8709 | return SDValue(); |
| 8710 | |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8711 | int64_t MulAmt = C->getSExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8712 | unsigned ShiftAmt = countTrailingZeros<uint64_t>(MulAmt); |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8713 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8714 | ShiftAmt = ShiftAmt & (32 - 1); |
| 8715 | SDValue V = N->getOperand(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8716 | SDLoc DL(N); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8717 | |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8718 | SDValue Res; |
| 8719 | MulAmt >>= ShiftAmt; |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8720 | |
| 8721 | if (MulAmt >= 0) { |
| 8722 | if (isPowerOf2_32(MulAmt - 1)) { |
| 8723 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 8724 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8725 | V, |
| 8726 | DAG.getNode(ISD::SHL, DL, VT, |
| 8727 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8728 | DAG.getConstant(Log2_32(MulAmt - 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8729 | MVT::i32))); |
| 8730 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 8731 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 8732 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8733 | DAG.getNode(ISD::SHL, DL, VT, |
| 8734 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8735 | DAG.getConstant(Log2_32(MulAmt + 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8736 | MVT::i32)), |
| 8737 | V); |
| 8738 | } else |
| 8739 | return SDValue(); |
| 8740 | } else { |
| 8741 | uint64_t MulAmtAbs = -MulAmt; |
| 8742 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 8743 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 8744 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8745 | V, |
| 8746 | DAG.getNode(ISD::SHL, DL, VT, |
| 8747 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8748 | DAG.getConstant(Log2_32(MulAmtAbs + 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8749 | MVT::i32))); |
| 8750 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 8751 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 8752 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8753 | V, |
| 8754 | DAG.getNode(ISD::SHL, DL, VT, |
| 8755 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8756 | DAG.getConstant(Log2_32(MulAmtAbs - 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8757 | MVT::i32))); |
| 8758 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8759 | DAG.getConstant(0, DL, MVT::i32), Res); |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8760 | |
| 8761 | } else |
| 8762 | return SDValue(); |
| 8763 | } |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8764 | |
| 8765 | if (ShiftAmt != 0) |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8766 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8767 | Res, DAG.getConstant(ShiftAmt, DL, MVT::i32)); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8768 | |
| 8769 | // Do not add new nodes to DAG combiner worklist. |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8770 | DCI.CombineTo(N, Res, false); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8771 | return SDValue(); |
| 8772 | } |
| 8773 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8774 | static SDValue PerformANDCombine(SDNode *N, |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8775 | TargetLowering::DAGCombinerInfo &DCI, |
| 8776 | const ARMSubtarget *Subtarget) { |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8777 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8778 | // Attempt to use immediate-form VBIC |
| 8779 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8780 | SDLoc dl(N); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8781 | EVT VT = N->getValueType(0); |
| 8782 | SelectionDAG &DAG = DCI.DAG; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8783 | |
| Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8784 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8785 | return SDValue(); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8786 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8787 | APInt SplatBits, SplatUndef; |
| 8788 | unsigned SplatBitSize; |
| 8789 | bool HasAnyUndefs; |
| 8790 | if (BVN && |
| 8791 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8792 | if (SplatBitSize <= 64) { |
| 8793 | EVT VbicVT; |
| 8794 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 8795 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8796 | DAG, dl, VbicVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8797 | OtherModImm); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8798 | if (Val.getNode()) { |
| 8799 | SDValue Input = |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8800 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8801 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8802 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8803 | } |
| 8804 | } |
| 8805 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8806 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8807 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8808 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
| 8809 | SDValue Result = combineSelectAndUseCommutative(N, true, DCI); |
| 8810 | if (Result.getNode()) |
| 8811 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8812 | } |
| 8813 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8814 | return SDValue(); |
| 8815 | } |
| 8816 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8817 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 8818 | static SDValue PerformORCombine(SDNode *N, |
| 8819 | TargetLowering::DAGCombinerInfo &DCI, |
| 8820 | const ARMSubtarget *Subtarget) { |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8821 | // Attempt to use immediate-form VORR |
| 8822 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8823 | SDLoc dl(N); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8824 | EVT VT = N->getValueType(0); |
| 8825 | SelectionDAG &DAG = DCI.DAG; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8826 | |
| Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8827 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8828 | return SDValue(); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8829 | |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8830 | APInt SplatBits, SplatUndef; |
| 8831 | unsigned SplatBitSize; |
| 8832 | bool HasAnyUndefs; |
| 8833 | if (BVN && Subtarget->hasNEON() && |
| 8834 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8835 | if (SplatBitSize <= 64) { |
| 8836 | EVT VorrVT; |
| 8837 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 8838 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8839 | DAG, dl, VorrVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8840 | OtherModImm); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8841 | if (Val.getNode()) { |
| 8842 | SDValue Input = |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8843 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8844 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8845 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8846 | } |
| 8847 | } |
| 8848 | } |
| 8849 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8850 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8851 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 8852 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 8853 | if (Result.getNode()) |
| 8854 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8855 | } |
| 8856 | |
| Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8857 | // The code below optimizes (or (and X, Y), Z). |
| 8858 | // The AND operand needs to have a single user to make these optimizations |
| 8859 | // profitable. |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8860 | SDValue N0 = N->getOperand(0); |
| Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 8861 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8862 | return SDValue(); |
| 8863 | SDValue N1 = N->getOperand(1); |
| 8864 | |
| 8865 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 8866 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 8867 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 8868 | APInt SplatUndef; |
| 8869 | unsigned SplatBitSize; |
| 8870 | bool HasAnyUndefs; |
| 8871 | |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8872 | APInt SplatBits0, SplatBits1; |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8873 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8874 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 8875 | // Ensure that the second operand of both ands are constants |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8876 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 8877 | HasAnyUndefs) && !HasAnyUndefs) { |
| 8878 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 8879 | HasAnyUndefs) && !HasAnyUndefs) { |
| 8880 | // Ensure that the bit width of the constants are the same and that |
| 8881 | // the splat arguments are logical inverses as per the pattern we |
| 8882 | // are trying to simplify. |
| 8883 | if (SplatBits0.getBitWidth() == SplatBits1.getBitWidth() && |
| 8884 | SplatBits0 == ~SplatBits1) { |
| 8885 | // Canonicalize the vector type to make instruction selection |
| 8886 | // simpler. |
| 8887 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 8888 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 8889 | N0->getOperand(1), |
| 8890 | N0->getOperand(0), |
| 8891 | N1->getOperand(0)); |
| 8892 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 8893 | } |
| 8894 | } |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 8895 | } |
| 8896 | } |
| 8897 | |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8898 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 8899 | // reasonable. |
| 8900 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8901 | // BFI is only available on V6T2+ |
| 8902 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 8903 | return SDValue(); |
| 8904 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8905 | SDLoc DL(N); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8906 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8907 | // iff (val & mask) == val |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8908 | // |
| 8909 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8910 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8911 | // && mask == ~mask2 |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 8912 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8913 | // && ~mask == mask2 |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8914 | // (i.e., copy a bitfield value into another bitfield of the same width) |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8915 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8916 | if (VT != MVT::i32) |
| 8917 | return SDValue(); |
| 8918 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8919 | SDValue N00 = N0.getOperand(0); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8920 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8921 | // The value and the mask need to be constants so we can verify this is |
| 8922 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 8923 | // via a movt instruction, so don't use BFI in that case. |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8924 | SDValue MaskOp = N0.getOperand(1); |
| 8925 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 8926 | if (!MaskC) |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8927 | return SDValue(); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8928 | unsigned Mask = MaskC->getZExtValue(); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8929 | if (Mask == 0xffff) |
| 8930 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8931 | SDValue Res; |
| 8932 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8933 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 8934 | if (N1C) { |
| 8935 | unsigned Val = N1C->getZExtValue(); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8936 | if ((Val & ~Mask) != Val) |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8937 | return SDValue(); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8938 | |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8939 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8940 | Val >>= countTrailingZeros(~Mask); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8941 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8942 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8943 | DAG.getConstant(Val, DL, MVT::i32), |
| 8944 | DAG.getConstant(Mask, DL, MVT::i32)); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8945 | |
| 8946 | // Do not add new nodes to DAG combiner worklist. |
| 8947 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8948 | return SDValue(); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 8949 | } |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8950 | } else if (N1.getOpcode() == ISD::AND) { |
| 8951 | // case (2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8952 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 8953 | if (!N11C) |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8954 | return SDValue(); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8955 | unsigned Mask2 = N11C->getZExtValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8956 | |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8957 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 8958 | // as is to match. |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8959 | if (ARM::isBitFieldInvertedMask(Mask) && |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8960 | (Mask == ~Mask2)) { |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8961 | // The pack halfword instruction works better for masks that fit it, |
| 8962 | // so use that when it's available. |
| 8963 | if (Subtarget->hasT2ExtractPack() && |
| 8964 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 8965 | return SDValue(); |
| 8966 | // 2a |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8967 | unsigned amt = countTrailingZeros(Mask2); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8968 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8969 | DAG.getConstant(amt, DL, MVT::i32)); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8970 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8971 | DAG.getConstant(Mask, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8972 | // Do not add new nodes to DAG combiner worklist. |
| 8973 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8974 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8975 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 8976 | (~Mask == Mask2)) { |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8977 | // The pack halfword instruction works better for masks that fit it, |
| 8978 | // so use that when it's available. |
| 8979 | if (Subtarget->hasT2ExtractPack() && |
| 8980 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 8981 | return SDValue(); |
| 8982 | // 2b |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8983 | unsigned lsb = countTrailingZeros(Mask); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8984 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8985 | DAG.getConstant(lsb, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8986 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8987 | DAG.getConstant(Mask2, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8988 | // Do not add new nodes to DAG combiner worklist. |
| 8989 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8990 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 8991 | } |
| 8992 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8993 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 8994 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 8995 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 8996 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 8997 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 8998 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 8999 | SDValue ShAmt = N00.getOperand(1); |
| 9000 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9001 | unsigned LSB = countTrailingZeros(Mask); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9002 | if (ShAmtC != LSB) |
| 9003 | return SDValue(); |
| 9004 | |
| 9005 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9006 | DAG.getConstant(~Mask, DL, MVT::i32)); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9007 | |
| 9008 | // Do not add new nodes to DAG combiner worklist. |
| 9009 | DCI.CombineTo(N, Res, false); |
| 9010 | } |
| 9011 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9012 | return SDValue(); |
| 9013 | } |
| 9014 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9015 | static SDValue PerformXORCombine(SDNode *N, |
| 9016 | TargetLowering::DAGCombinerInfo &DCI, |
| 9017 | const ARMSubtarget *Subtarget) { |
| 9018 | EVT VT = N->getValueType(0); |
| 9019 | SelectionDAG &DAG = DCI.DAG; |
| 9020 | |
| 9021 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 9022 | return SDValue(); |
| 9023 | |
| 9024 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 9025 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| 9026 | SDValue Result = combineSelectAndUseCommutative(N, false, DCI); |
| 9027 | if (Result.getNode()) |
| 9028 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9029 | } |
| 9030 | |
| 9031 | return SDValue(); |
| 9032 | } |
| 9033 | |
| Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 9034 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 9035 | /// the bits being cleared by the AND are not demanded by the BFI. |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9036 | static SDValue PerformBFICombine(SDNode *N, |
| 9037 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9038 | SDValue N1 = N->getOperand(1); |
| 9039 | if (N1.getOpcode() == ISD::AND) { |
| 9040 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 9041 | if (!N11C) |
| 9042 | return SDValue(); |
| Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 9043 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9044 | unsigned LSB = countTrailingZeros(~InvMask); |
| 9045 | unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB; |
| Aaron Ballman | 0d6a010 | 2014-12-16 14:04:11 +0000 | [diff] [blame] | 9046 | assert(Width < |
| 9047 | static_cast<unsigned>(std::numeric_limits<unsigned>::digits) && |
| Michael Ilseman | addddc4 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 9048 | "undefined behavior"); |
| 9049 | unsigned Mask = (1u << Width) - 1; |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9050 | unsigned Mask2 = N11C->getZExtValue(); |
| Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 9051 | if ((Mask & (~Mask2)) == 0) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9052 | return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0), |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9053 | N->getOperand(0), N1.getOperand(0), |
| 9054 | N->getOperand(2)); |
| 9055 | } |
| 9056 | return SDValue(); |
| 9057 | } |
| 9058 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9059 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 9060 | /// ARMISD::VMOVRRD. |
| 9061 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9062 | TargetLowering::DAGCombinerInfo &DCI, |
| 9063 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9064 | // vmovrrd(vmovdrr x, y) -> x,y |
| 9065 | SDValue InDouble = N->getOperand(0); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9066 | if (InDouble.getOpcode() == ARMISD::VMOVDRR && !Subtarget->isFPOnlySP()) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9067 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9068 | |
| 9069 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 9070 | SDNode *InNode = InDouble.getNode(); |
| 9071 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 9072 | InNode->getValueType(0) == MVT::f64 && |
| 9073 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 9074 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 9075 | // TODO: Should this be done for non-FrameIndex operands? |
| 9076 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 9077 | |
| 9078 | SelectionDAG &DAG = DCI.DAG; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9079 | SDLoc DL(LD); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9080 | SDValue BasePtr = LD->getBasePtr(); |
| 9081 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 9082 | LD->getPointerInfo(), LD->isVolatile(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 9083 | LD->isNonTemporal(), LD->isInvariant(), |
| 9084 | LD->getAlignment()); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9085 | |
| 9086 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9087 | DAG.getConstant(4, DL, MVT::i32)); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9088 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 9089 | LD->getPointerInfo(), LD->isVolatile(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 9090 | LD->isNonTemporal(), LD->isInvariant(), |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9091 | std::min(4U, LD->getAlignment() / 2)); |
| 9092 | |
| 9093 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 9094 | if (DCI.DAG.getDataLayout().isBigEndian()) |
| Christian Pirker | 762b2c6 | 2014-06-01 09:30:52 +0000 | [diff] [blame] | 9095 | std::swap (NewLD1, NewLD2); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9096 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9097 | return Result; |
| 9098 | } |
| 9099 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9100 | return SDValue(); |
| 9101 | } |
| 9102 | |
| 9103 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 9104 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 9105 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 9106 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 9107 | SDValue Op0 = N->getOperand(0); |
| 9108 | SDValue Op1 = N->getOperand(1); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9109 | if (Op0.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9110 | Op0 = Op0.getOperand(0); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9111 | if (Op1.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9112 | Op1 = Op1.getOperand(0); |
| 9113 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 9114 | Op0.getNode() == Op1.getNode() && |
| 9115 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9116 | return DAG.getNode(ISD::BITCAST, SDLoc(N), |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9117 | N->getValueType(0), Op0.getOperand(0)); |
| 9118 | return SDValue(); |
| 9119 | } |
| 9120 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9121 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 9122 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 9123 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 9124 | /// directly into a VFP register. |
| 9125 | static bool hasNormalLoadOperand(SDNode *N) { |
| 9126 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 9127 | for (unsigned i = 0; i < NumElts; ++i) { |
| 9128 | SDNode *Elt = N->getOperand(i).getNode(); |
| 9129 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 9130 | return true; |
| 9131 | } |
| 9132 | return false; |
| 9133 | } |
| 9134 | |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9135 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 9136 | /// ISD::BUILD_VECTOR. |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9137 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9138 | TargetLowering::DAGCombinerInfo &DCI, |
| 9139 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9140 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 9141 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 9142 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 9143 | // but if the i64 value is converted to a vector, we need to undo the VMOVRRD. |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9144 | SelectionDAG &DAG = DCI.DAG; |
| 9145 | if (N->getNumOperands() == 2) { |
| 9146 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 9147 | if (RV.getNode()) |
| 9148 | return RV; |
| 9149 | } |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9150 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9151 | // Load i64 elements as f64 values so that type legalization does not split |
| 9152 | // them up into i32 values. |
| 9153 | EVT VT = N->getValueType(0); |
| 9154 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 9155 | return SDValue(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9156 | SDLoc dl(N); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9157 | SmallVector<SDValue, 8> Ops; |
| 9158 | unsigned NumElts = VT.getVectorNumElements(); |
| 9159 | for (unsigned i = 0; i < NumElts; ++i) { |
| 9160 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 9161 | Ops.push_back(V); |
| 9162 | // Make the DAGCombiner fold the bitcast. |
| 9163 | DCI.AddToWorklist(V.getNode()); |
| 9164 | } |
| 9165 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 9166 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9167 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 9168 | } |
| 9169 | |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9170 | /// \brief Target-specific dag combine xforms for ARMISD::BUILD_VECTOR. |
| 9171 | static SDValue |
| 9172 | PerformARMBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 9173 | // ARMISD::BUILD_VECTOR is introduced when legalizing ISD::BUILD_VECTOR. |
| 9174 | // At that time, we may have inserted bitcasts from integer to float. |
| 9175 | // If these bitcasts have survived DAGCombine, change the lowering of this |
| 9176 | // BUILD_VECTOR in something more vector friendly, i.e., that does not |
| 9177 | // force to use floating point types. |
| 9178 | |
| 9179 | // Make sure we can change the type of the vector. |
| 9180 | // This is possible iff: |
| 9181 | // 1. The vector is only used in a bitcast to a integer type. I.e., |
| 9182 | // 1.1. Vector is used only once. |
| 9183 | // 1.2. Use is a bit convert to an integer type. |
| 9184 | // 2. The size of its operands are 32-bits (64-bits are not legal). |
| 9185 | EVT VT = N->getValueType(0); |
| 9186 | EVT EltVT = VT.getVectorElementType(); |
| 9187 | |
| 9188 | // Check 1.1. and 2. |
| 9189 | if (EltVT.getSizeInBits() != 32 || !N->hasOneUse()) |
| 9190 | return SDValue(); |
| 9191 | |
| 9192 | // By construction, the input type must be float. |
| 9193 | assert(EltVT == MVT::f32 && "Unexpected type!"); |
| 9194 | |
| 9195 | // Check 1.2. |
| 9196 | SDNode *Use = *N->use_begin(); |
| 9197 | if (Use->getOpcode() != ISD::BITCAST || |
| 9198 | Use->getValueType(0).isFloatingPoint()) |
| 9199 | return SDValue(); |
| 9200 | |
| 9201 | // Check profitability. |
| 9202 | // Model is, if more than half of the relevant operands are bitcast from |
| 9203 | // i32, turn the build_vector into a sequence of insert_vector_elt. |
| 9204 | // Relevant operands are everything that is not statically |
| 9205 | // (i.e., at compile time) bitcasted. |
| 9206 | unsigned NumOfBitCastedElts = 0; |
| 9207 | unsigned NumElts = VT.getVectorNumElements(); |
| 9208 | unsigned NumOfRelevantElts = NumElts; |
| 9209 | for (unsigned Idx = 0; Idx < NumElts; ++Idx) { |
| 9210 | SDValue Elt = N->getOperand(Idx); |
| 9211 | if (Elt->getOpcode() == ISD::BITCAST) { |
| 9212 | // Assume only bit cast to i32 will go away. |
| 9213 | if (Elt->getOperand(0).getValueType() == MVT::i32) |
| 9214 | ++NumOfBitCastedElts; |
| 9215 | } else if (Elt.getOpcode() == ISD::UNDEF || isa<ConstantSDNode>(Elt)) |
| 9216 | // Constants are statically casted, thus do not count them as |
| 9217 | // relevant operands. |
| 9218 | --NumOfRelevantElts; |
| 9219 | } |
| 9220 | |
| 9221 | // Check if more than half of the elements require a non-free bitcast. |
| 9222 | if (NumOfBitCastedElts <= NumOfRelevantElts / 2) |
| 9223 | return SDValue(); |
| 9224 | |
| 9225 | SelectionDAG &DAG = DCI.DAG; |
| 9226 | // Create the new vector type. |
| 9227 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 9228 | // Check if the type is legal. |
| 9229 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9230 | if (!TLI.isTypeLegal(VecVT)) |
| 9231 | return SDValue(); |
| 9232 | |
| 9233 | // Combine: |
| 9234 | // ARMISD::BUILD_VECTOR E1, E2, ..., EN. |
| 9235 | // => BITCAST INSERT_VECTOR_ELT |
| 9236 | // (INSERT_VECTOR_ELT (...), (BITCAST EN-1), N-1), |
| 9237 | // (BITCAST EN), N. |
| 9238 | SDValue Vec = DAG.getUNDEF(VecVT); |
| 9239 | SDLoc dl(N); |
| 9240 | for (unsigned Idx = 0 ; Idx < NumElts; ++Idx) { |
| 9241 | SDValue V = N->getOperand(Idx); |
| 9242 | if (V.getOpcode() == ISD::UNDEF) |
| 9243 | continue; |
| 9244 | if (V.getOpcode() == ISD::BITCAST && |
| 9245 | V->getOperand(0).getValueType() == MVT::i32) |
| 9246 | // Fold obvious case. |
| 9247 | V = V.getOperand(0); |
| 9248 | else { |
| Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 9249 | V = DAG.getNode(ISD::BITCAST, SDLoc(V), MVT::i32, V); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9250 | // Make the DAGCombiner fold the bitcasts. |
| 9251 | DCI.AddToWorklist(V.getNode()); |
| 9252 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9253 | SDValue LaneIdx = DAG.getConstant(Idx, dl, MVT::i32); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9254 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecVT, Vec, V, LaneIdx); |
| 9255 | } |
| 9256 | Vec = DAG.getNode(ISD::BITCAST, dl, VT, Vec); |
| 9257 | // Make the DAGCombiner fold the bitcasts. |
| 9258 | DCI.AddToWorklist(Vec.getNode()); |
| 9259 | return Vec; |
| 9260 | } |
| 9261 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9262 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 9263 | /// ISD::INSERT_VECTOR_ELT. |
| 9264 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 9265 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9266 | // Bitcast an i64 load inserted into a vector to f64. |
| 9267 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 9268 | EVT VT = N->getValueType(0); |
| 9269 | SDNode *Elt = N->getOperand(1).getNode(); |
| 9270 | if (VT.getVectorElementType() != MVT::i64 || |
| 9271 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 9272 | return SDValue(); |
| 9273 | |
| 9274 | SelectionDAG &DAG = DCI.DAG; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9275 | SDLoc dl(N); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9276 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 9277 | VT.getVectorNumElements()); |
| 9278 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 9279 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 9280 | // Make the DAGCombiner fold the bitcasts. |
| 9281 | DCI.AddToWorklist(Vec.getNode()); |
| 9282 | DCI.AddToWorklist(V.getNode()); |
| 9283 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 9284 | Vec, V, N->getOperand(2)); |
| 9285 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9286 | } |
| 9287 | |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9288 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 9289 | /// ISD::VECTOR_SHUFFLE. |
| 9290 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 9291 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 9292 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 9293 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 9294 | // operands do not match the mask length, they are extended by concatenating |
| 9295 | // them with undef vectors. That is probably the right thing for other |
| 9296 | // targets, but for NEON it is better to concatenate two double-register |
| 9297 | // size vector operands into a single quad-register size vector. Do that |
| 9298 | // transformation here: |
| 9299 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 9300 | // shuffle(concat(v1, v2), undef) |
| 9301 | SDValue Op0 = N->getOperand(0); |
| 9302 | SDValue Op1 = N->getOperand(1); |
| 9303 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 9304 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 9305 | Op0.getNumOperands() != 2 || |
| 9306 | Op1.getNumOperands() != 2) |
| 9307 | return SDValue(); |
| 9308 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 9309 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 9310 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 9311 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 9312 | return SDValue(); |
| 9313 | // Skip the transformation if any of the types are illegal. |
| 9314 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9315 | EVT VT = N->getValueType(0); |
| 9316 | if (!TLI.isTypeLegal(VT) || |
| 9317 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 9318 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 9319 | return SDValue(); |
| 9320 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9321 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9322 | Op0.getOperand(0), Op1.getOperand(0)); |
| 9323 | // Translate the shuffle mask. |
| 9324 | SmallVector<int, 16> NewMask; |
| 9325 | unsigned NumElts = VT.getVectorNumElements(); |
| 9326 | unsigned HalfElts = NumElts/2; |
| 9327 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 9328 | for (unsigned n = 0; n < NumElts; ++n) { |
| 9329 | int MaskElt = SVN->getMaskElt(n); |
| 9330 | int NewElt = -1; |
| Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 9331 | if (MaskElt < (int)HalfElts) |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9332 | NewElt = MaskElt; |
| Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 9333 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9334 | NewElt = HalfElts + MaskElt - NumElts; |
| 9335 | NewMask.push_back(NewElt); |
| 9336 | } |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9337 | return DAG.getVectorShuffle(VT, SDLoc(N), NewConcat, |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9338 | DAG.getUNDEF(VT), NewMask.data()); |
| 9339 | } |
| 9340 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9341 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP, |
| 9342 | /// NEON load/store intrinsics, and generic vector load/stores, to merge |
| 9343 | /// base address updates. |
| 9344 | /// For generic load/stores, the memory type is assumed to be a vector. |
| 9345 | /// The caller is assumed to have checked legality. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9346 | static SDValue CombineBaseUpdate(SDNode *N, |
| 9347 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9348 | SelectionDAG &DAG = DCI.DAG; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9349 | const bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 9350 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9351 | const bool isStore = N->getOpcode() == ISD::STORE; |
| 9352 | const unsigned AddrOpIdx = ((isIntrinsic || isStore) ? 2 : 1); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9353 | SDValue Addr = N->getOperand(AddrOpIdx); |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9354 | MemSDNode *MemN = cast<MemSDNode>(N); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9355 | SDLoc dl(N); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9356 | |
| 9357 | // Search for a use of the address operand that is an increment. |
| 9358 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 9359 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 9360 | SDNode *User = *UI; |
| 9361 | if (User->getOpcode() != ISD::ADD || |
| 9362 | UI.getUse().getResNo() != Addr.getResNo()) |
| 9363 | continue; |
| 9364 | |
| 9365 | // Check that the add is independent of the load/store. Otherwise, folding |
| 9366 | // it would create a cycle. |
| 9367 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 9368 | continue; |
| 9369 | |
| 9370 | // Find the new opcode for the updating load/store. |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9371 | bool isLoadOp = true; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9372 | bool isLaneOp = false; |
| 9373 | unsigned NewOpc = 0; |
| 9374 | unsigned NumVecs = 0; |
| 9375 | if (isIntrinsic) { |
| 9376 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 9377 | switch (IntNo) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 9378 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9379 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 9380 | NumVecs = 1; break; |
| 9381 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 9382 | NumVecs = 2; break; |
| 9383 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 9384 | NumVecs = 3; break; |
| 9385 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 9386 | NumVecs = 4; break; |
| 9387 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 9388 | NumVecs = 2; isLaneOp = true; break; |
| 9389 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 9390 | NumVecs = 3; isLaneOp = true; break; |
| 9391 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 9392 | NumVecs = 4; isLaneOp = true; break; |
| 9393 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9394 | NumVecs = 1; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9395 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9396 | NumVecs = 2; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9397 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9398 | NumVecs = 3; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9399 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9400 | NumVecs = 4; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9401 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9402 | NumVecs = 2; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9403 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9404 | NumVecs = 3; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9405 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9406 | NumVecs = 4; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9407 | } |
| 9408 | } else { |
| 9409 | isLaneOp = true; |
| 9410 | switch (N->getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 9411 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9412 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 9413 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 9414 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9415 | case ISD::LOAD: NewOpc = ARMISD::VLD1_UPD; |
| 9416 | NumVecs = 1; isLaneOp = false; break; |
| 9417 | case ISD::STORE: NewOpc = ARMISD::VST1_UPD; |
| 9418 | NumVecs = 1; isLaneOp = false; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9419 | } |
| 9420 | } |
| 9421 | |
| 9422 | // Find the size of memory referenced by the load/store. |
| 9423 | EVT VecTy; |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9424 | if (isLoadOp) { |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9425 | VecTy = N->getValueType(0); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9426 | } else if (isIntrinsic) { |
| Renato Golin | 2a5c0a5 | 2015-02-04 10:11:59 +0000 | [diff] [blame] | 9427 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9428 | } else { |
| 9429 | assert(isStore && "Node has to be a load, a store, or an intrinsic!"); |
| 9430 | VecTy = N->getOperand(1).getValueType(); |
| 9431 | } |
| 9432 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9433 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 9434 | if (isLaneOp) |
| 9435 | NumBytes /= VecTy.getVectorNumElements(); |
| 9436 | |
| 9437 | // If the increment is a constant, it must match the memory ref size. |
| 9438 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 9439 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 9440 | uint64_t IncVal = CInc->getZExtValue(); |
| 9441 | if (IncVal != NumBytes) |
| 9442 | continue; |
| 9443 | } else if (NumBytes >= 3 * 16) { |
| 9444 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 9445 | // separate instructions that make it harder to use a non-constant update. |
| 9446 | continue; |
| 9447 | } |
| 9448 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9449 | // OK, we found an ADD we can fold into the base update. |
| 9450 | // Now, create a _UPD node, taking care of not breaking alignment. |
| 9451 | |
| 9452 | EVT AlignedVecTy = VecTy; |
| 9453 | unsigned Alignment = MemN->getAlignment(); |
| 9454 | |
| 9455 | // If this is a less-than-standard-aligned load/store, change the type to |
| 9456 | // match the standard alignment. |
| 9457 | // The alignment is overlooked when selecting _UPD variants; and it's |
| 9458 | // easier to introduce bitcasts here than fix that. |
| 9459 | // There are 3 ways to get to this base-update combine: |
| 9460 | // - intrinsics: they are assumed to be properly aligned (to the standard |
| 9461 | // alignment of the memory type), so we don't need to do anything. |
| 9462 | // - ARMISD::VLDx nodes: they are only generated from the aforementioned |
| 9463 | // intrinsics, so, likewise, there's nothing to do. |
| 9464 | // - generic load/store instructions: the alignment is specified as an |
| 9465 | // explicit operand, rather than implicitly as the standard alignment |
| 9466 | // of the memory type (like the intrisics). We need to change the |
| 9467 | // memory type to match the explicit alignment. That way, we don't |
| 9468 | // generate non-standard-aligned ARMISD::VLDx nodes. |
| 9469 | if (isa<LSBaseSDNode>(N)) { |
| 9470 | if (Alignment == 0) |
| 9471 | Alignment = 1; |
| 9472 | if (Alignment < VecTy.getScalarSizeInBits() / 8) { |
| 9473 | MVT EltTy = MVT::getIntegerVT(Alignment * 8); |
| 9474 | assert(NumVecs == 1 && "Unexpected multi-element generic load/store."); |
| 9475 | assert(!isLaneOp && "Unexpected generic load/store lane."); |
| 9476 | unsigned NumElts = NumBytes / (EltTy.getSizeInBits() / 8); |
| 9477 | AlignedVecTy = MVT::getVectorVT(EltTy, NumElts); |
| 9478 | } |
| 9479 | // Don't set an explicit alignment on regular load/stores that we want |
| 9480 | // to transform to VLD/VST 1_UPD nodes. |
| 9481 | // This matches the behavior of regular load/stores, which only get an |
| 9482 | // explicit alignment if the MMO alignment is larger than the standard |
| 9483 | // alignment of the memory type. |
| 9484 | // Intrinsics, however, always get an explicit alignment, set to the |
| 9485 | // alignment of the MMO. |
| 9486 | Alignment = 1; |
| 9487 | } |
| 9488 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9489 | // Create the new updating load/store node. |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9490 | // First, create an SDVTList for the new updating node's results. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9491 | EVT Tys[6]; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9492 | unsigned NumResultVecs = (isLoadOp ? NumVecs : 0); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9493 | unsigned n; |
| 9494 | for (n = 0; n < NumResultVecs; ++n) |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9495 | Tys[n] = AlignedVecTy; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9496 | Tys[n++] = MVT::i32; |
| 9497 | Tys[n] = MVT::Other; |
| Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 9498 | SDVTList SDTys = DAG.getVTList(makeArrayRef(Tys, NumResultVecs+2)); |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9499 | |
| 9500 | // Then, gather the new node's operands. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9501 | SmallVector<SDValue, 8> Ops; |
| 9502 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 9503 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 9504 | Ops.push_back(Inc); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9505 | |
| 9506 | if (StoreSDNode *StN = dyn_cast<StoreSDNode>(N)) { |
| 9507 | // Try to match the intrinsic's signature |
| 9508 | Ops.push_back(StN->getValue()); |
| 9509 | } else { |
| 9510 | // Loads (and of course intrinsics) match the intrinsics' signature, |
| 9511 | // so just add all but the alignment operand. |
| 9512 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands() - 1; ++i) |
| 9513 | Ops.push_back(N->getOperand(i)); |
| 9514 | } |
| 9515 | |
| 9516 | // For all node types, the alignment operand is always the last one. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9517 | Ops.push_back(DAG.getConstant(Alignment, dl, MVT::i32)); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9518 | |
| 9519 | // If this is a non-standard-aligned STORE, the penultimate operand is the |
| 9520 | // stored value. Bitcast it to the aligned type. |
| 9521 | if (AlignedVecTy != VecTy && N->getOpcode() == ISD::STORE) { |
| 9522 | SDValue &StVal = Ops[Ops.size()-2]; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9523 | StVal = DAG.getNode(ISD::BITCAST, dl, AlignedVecTy, StVal); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9524 | } |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9525 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9526 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, dl, SDTys, |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9527 | Ops, AlignedVecTy, |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9528 | MemN->getMemOperand()); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9529 | |
| 9530 | // Update the uses. |
| Ahmed Bougacha | 4c2b078 | 2015-02-19 23:13:10 +0000 | [diff] [blame] | 9531 | SmallVector<SDValue, 5> NewResults; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9532 | for (unsigned i = 0; i < NumResultVecs; ++i) |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9533 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9534 | |
| 9535 | // If this is an non-standard-aligned LOAD, the first result is the loaded |
| 9536 | // value. Bitcast it to the expected result type. |
| 9537 | if (AlignedVecTy != VecTy && N->getOpcode() == ISD::LOAD) { |
| 9538 | SDValue &LdVal = NewResults[0]; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9539 | LdVal = DAG.getNode(ISD::BITCAST, dl, VecTy, LdVal); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9540 | } |
| 9541 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9542 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 9543 | DCI.CombineTo(N, NewResults); |
| 9544 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 9545 | |
| 9546 | break; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 9547 | } |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9548 | return SDValue(); |
| 9549 | } |
| 9550 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9551 | static SDValue PerformVLDCombine(SDNode *N, |
| 9552 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9553 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 9554 | return SDValue(); |
| 9555 | |
| 9556 | return CombineBaseUpdate(N, DCI); |
| 9557 | } |
| 9558 | |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9559 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 9560 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 9561 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 9562 | /// return true. |
| 9563 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 9564 | SelectionDAG &DAG = DCI.DAG; |
| 9565 | EVT VT = N->getValueType(0); |
| 9566 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 9567 | if (!VT.is64BitVector()) |
| 9568 | return false; |
| 9569 | |
| 9570 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 9571 | SDNode *VLD = N->getOperand(0).getNode(); |
| 9572 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 9573 | return false; |
| 9574 | unsigned NumVecs = 0; |
| 9575 | unsigned NewOpc = 0; |
| 9576 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 9577 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 9578 | NumVecs = 2; |
| 9579 | NewOpc = ARMISD::VLD2DUP; |
| 9580 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 9581 | NumVecs = 3; |
| 9582 | NewOpc = ARMISD::VLD3DUP; |
| 9583 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 9584 | NumVecs = 4; |
| 9585 | NewOpc = ARMISD::VLD4DUP; |
| 9586 | } else { |
| 9587 | return false; |
| 9588 | } |
| 9589 | |
| 9590 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 9591 | // numbers match the load. |
| 9592 | unsigned VLDLaneNo = |
| 9593 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 9594 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9595 | UI != UE; ++UI) { |
| 9596 | // Ignore uses of the chain result. |
| 9597 | if (UI.getUse().getResNo() == NumVecs) |
| 9598 | continue; |
| 9599 | SDNode *User = *UI; |
| 9600 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 9601 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 9602 | return false; |
| 9603 | } |
| 9604 | |
| 9605 | // Create the vldN-dup node. |
| 9606 | EVT Tys[5]; |
| 9607 | unsigned n; |
| 9608 | for (n = 0; n < NumVecs; ++n) |
| 9609 | Tys[n] = VT; |
| 9610 | Tys[n] = MVT::Other; |
| Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 9611 | SDVTList SDTys = DAG.getVTList(makeArrayRef(Tys, NumVecs+1)); |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9612 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 9613 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9614 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, SDLoc(VLD), SDTys, |
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 9615 | Ops, VLDMemInt->getMemoryVT(), |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9616 | VLDMemInt->getMemOperand()); |
| 9617 | |
| 9618 | // Update the uses. |
| 9619 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9620 | UI != UE; ++UI) { |
| 9621 | unsigned ResNo = UI.getUse().getResNo(); |
| 9622 | // Ignore uses of the chain result. |
| 9623 | if (ResNo == NumVecs) |
| 9624 | continue; |
| 9625 | SDNode *User = *UI; |
| 9626 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 9627 | } |
| 9628 | |
| 9629 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 9630 | // Update uses of the chain. |
| 9631 | std::vector<SDValue> VLDDupResults; |
| 9632 | for (unsigned n = 0; n < NumVecs; ++n) |
| 9633 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 9634 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 9635 | DCI.CombineTo(VLD, VLDDupResults); |
| 9636 | |
| 9637 | return true; |
| 9638 | } |
| 9639 | |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9640 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 9641 | /// ARMISD::VDUPLANE. |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9642 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 9643 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9644 | SDValue Op = N->getOperand(0); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9645 | |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9646 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 9647 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 9648 | if (CombineVLDDUP(N, DCI)) |
| 9649 | return SDValue(N, 0); |
| 9650 | |
| 9651 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 9652 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9653 | while (Op.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9654 | Op = Op.getOperand(0); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 9655 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9656 | return SDValue(); |
| 9657 | |
| 9658 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 9659 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 9660 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 9661 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 9662 | unsigned EltBits; |
| 9663 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 9664 | EltSize = 8; |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9665 | EVT VT = N->getValueType(0); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9666 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 9667 | return SDValue(); |
| 9668 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9669 | return DCI.DAG.getNode(ISD::BITCAST, SDLoc(N), VT, Op); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9670 | } |
| 9671 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9672 | static SDValue PerformLOADCombine(SDNode *N, |
| 9673 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9674 | EVT VT = N->getValueType(0); |
| 9675 | |
| 9676 | // If this is a legal vector load, try to combine it into a VLD1_UPD. |
| 9677 | if (ISD::isNormalLoad(N) && VT.isVector() && |
| 9678 | DCI.DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 9679 | return CombineBaseUpdate(N, DCI); |
| 9680 | |
| 9681 | return SDValue(); |
| 9682 | } |
| 9683 | |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9684 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 9685 | /// ISD::STORE. |
| 9686 | static SDValue PerformSTORECombine(SDNode *N, |
| 9687 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9688 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 9689 | if (St->isVolatile()) |
| 9690 | return SDValue(); |
| 9691 | |
| 9692 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
| 9693 | // pack all of the elements in one place. Next, store to memory in fewer |
| 9694 | // chunks. |
| 9695 | SDValue StVal = St->getValue(); |
| 9696 | EVT VT = StVal.getValueType(); |
| 9697 | if (St->isTruncatingStore() && VT.isVector()) { |
| 9698 | SelectionDAG &DAG = DCI.DAG; |
| 9699 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9700 | EVT StVT = St->getMemoryVT(); |
| 9701 | unsigned NumElems = VT.getVectorNumElements(); |
| 9702 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 9703 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 9704 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 9705 | |
| 9706 | // From, To sizes and ElemCount must be pow of two |
| 9707 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 9708 | |
| 9709 | // We are going to use the original vector elt for storing. |
| 9710 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 9711 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 9712 | |
| 9713 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 9714 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 9715 | |
| 9716 | // Create a type on which we perform the shuffle. |
| 9717 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 9718 | NumElems*SizeRatio); |
| 9719 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 9720 | |
| 9721 | SDLoc DL(St); |
| 9722 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 9723 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 9724 | for (unsigned i = 0; i < NumElems; ++i) |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 9725 | ShuffleVec[i] = DAG.getDataLayout().isBigEndian() |
| 9726 | ? (i + 1) * SizeRatio - 1 |
| 9727 | : i * SizeRatio; |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9728 | |
| 9729 | // Can't shuffle using an illegal type. |
| 9730 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 9731 | |
| 9732 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 9733 | DAG.getUNDEF(WideVec.getValueType()), |
| 9734 | ShuffleVec.data()); |
| 9735 | // At this point all of the data is stored at the bottom of the |
| 9736 | // register. We now need to save it to mem. |
| 9737 | |
| 9738 | // Find the largest store unit |
| 9739 | MVT StoreType = MVT::i8; |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 9740 | for (MVT Tp : MVT::integer_valuetypes()) { |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9741 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 9742 | StoreType = Tp; |
| 9743 | } |
| 9744 | // Didn't find a legal store type. |
| 9745 | if (!TLI.isTypeLegal(StoreType)) |
| 9746 | return SDValue(); |
| 9747 | |
| 9748 | // Bitcast the original vector into a vector of store-size units |
| 9749 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 9750 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 9751 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 9752 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 9753 | SmallVector<SDValue, 8> Chains; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 9754 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits() / 8, DL, |
| 9755 | TLI.getPointerTy(DAG.getDataLayout())); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9756 | SDValue BasePtr = St->getBasePtr(); |
| 9757 | |
| 9758 | // Perform one or more big stores into memory. |
| 9759 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 9760 | for (unsigned I = 0; I < E; I++) { |
| 9761 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 9762 | StoreType, ShuffWide, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9763 | DAG.getIntPtrConstant(I, DL)); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9764 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 9765 | St->getPointerInfo(), St->isVolatile(), |
| 9766 | St->isNonTemporal(), St->getAlignment()); |
| 9767 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 9768 | Increment); |
| 9769 | Chains.push_back(Ch); |
| 9770 | } |
| 9771 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains); |
| 9772 | } |
| 9773 | |
| 9774 | if (!ISD::isNormalStore(St)) |
| 9775 | return SDValue(); |
| 9776 | |
| 9777 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 9778 | // ARM stores of arguments in the same cache line. |
| 9779 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 9780 | StVal.getNode()->hasOneUse()) { |
| 9781 | SelectionDAG &DAG = DCI.DAG; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 9782 | bool isBigEndian = DAG.getDataLayout().isBigEndian(); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9783 | SDLoc DL(St); |
| 9784 | SDValue BasePtr = St->getBasePtr(); |
| 9785 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 9786 | StVal.getNode()->getOperand(isBigEndian ? 1 : 0 ), |
| 9787 | BasePtr, St->getPointerInfo(), St->isVolatile(), |
| 9788 | St->isNonTemporal(), St->getAlignment()); |
| 9789 | |
| 9790 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9791 | DAG.getConstant(4, DL, MVT::i32)); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9792 | return DAG.getStore(NewST1.getValue(0), DL, |
| 9793 | StVal.getNode()->getOperand(isBigEndian ? 0 : 1), |
| 9794 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 9795 | St->isNonTemporal(), |
| 9796 | std::min(4U, St->getAlignment() / 2)); |
| 9797 | } |
| 9798 | |
| 9799 | if (StVal.getValueType() == MVT::i64 && |
| 9800 | StVal.getNode()->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 9801 | |
| 9802 | // Bitcast an i64 store extracted from a vector to f64. |
| 9803 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 9804 | SelectionDAG &DAG = DCI.DAG; |
| 9805 | SDLoc dl(StVal); |
| 9806 | SDValue IntVec = StVal.getOperand(0); |
| 9807 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 9808 | IntVec.getValueType().getVectorNumElements()); |
| 9809 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 9810 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 9811 | Vec, StVal.getOperand(1)); |
| 9812 | dl = SDLoc(N); |
| 9813 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 9814 | // Make the DAGCombiner fold the bitcasts. |
| 9815 | DCI.AddToWorklist(Vec.getNode()); |
| 9816 | DCI.AddToWorklist(ExtElt.getNode()); |
| 9817 | DCI.AddToWorklist(V.getNode()); |
| 9818 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 9819 | St->getPointerInfo(), St->isVolatile(), |
| 9820 | St->isNonTemporal(), St->getAlignment(), |
| 9821 | St->getAAInfo()); |
| 9822 | } |
| 9823 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9824 | // If this is a legal vector store, try to combine it into a VST1_UPD. |
| 9825 | if (ISD::isNormalStore(N) && VT.isVector() && |
| 9826 | DCI.DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 9827 | return CombineBaseUpdate(N, DCI); |
| 9828 | |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9829 | return SDValue(); |
| 9830 | } |
| 9831 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9832 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 9833 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 9834 | /// when the VMUL has a constant operand that is a power of 2. |
| 9835 | /// |
| 9836 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 9837 | /// vmul.f32 d16, d17, d16 |
| 9838 | /// vcvt.s32.f32 d16, d16 |
| 9839 | /// becomes: |
| 9840 | /// vcvt.s32.f32 d16, d16, #3 |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9841 | static SDValue PerformVCVTCombine(SDNode *N, SelectionDAG &DAG, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9842 | const ARMSubtarget *Subtarget) { |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9843 | if (!Subtarget->hasNEON()) |
| 9844 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9845 | |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9846 | SDValue Op = N->getOperand(0); |
| 9847 | if (!Op.getValueType().isVector() || Op.getOpcode() != ISD::FMUL) |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9848 | return SDValue(); |
| 9849 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9850 | SDValue ConstVec = Op->getOperand(1); |
| Chad Rosier | aed910b | 2015-10-06 20:51:26 +0000 | [diff] [blame] | 9851 | if (!isa<BuildVectorSDNode>(ConstVec)) |
| 9852 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9853 | |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9854 | MVT FloatTy = Op.getSimpleValueType().getVectorElementType(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 9855 | uint32_t FloatBits = FloatTy.getSizeInBits(); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9856 | MVT IntTy = N->getSimpleValueType(0).getVectorElementType(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 9857 | uint32_t IntBits = IntTy.getSizeInBits(); |
| Bradley Smith | ececb7f | 2014-12-16 10:59:27 +0000 | [diff] [blame] | 9858 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 9859 | if (FloatBits != 32 || IntBits > 32 || NumLanes > 4) { |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9860 | // These instructions only exist converting from f32 to i32. We can handle |
| 9861 | // smaller integers by generating an extra truncate, but larger ones would |
| Bradley Smith | ececb7f | 2014-12-16 10:59:27 +0000 | [diff] [blame] | 9862 | // be lossy. We also can't handle more then 4 lanes, since these intructions |
| 9863 | // only support v2i32/v4i32 types. |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9864 | return SDValue(); |
| 9865 | } |
| 9866 | |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9867 | BitVector UndefElements; |
| 9868 | BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec); |
| 9869 | int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, 33); |
| 9870 | if (C == -1 || C == 0 || C > 32) |
| Chad Rosier | db71abf | 2015-10-07 13:40:44 +0000 | [diff] [blame] | 9871 | return SDValue(); |
| 9872 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9873 | SDLoc dl(N); |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9874 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9875 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 9876 | Intrinsic::arm_neon_vcvtfp2fxu; |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 9877 | SDValue FixConv = DAG.getNode( |
| 9878 | ISD::INTRINSIC_WO_CHAIN, dl, NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, |
| 9879 | DAG.getConstant(IntrinsicOpcode, dl, MVT::i32), Op->getOperand(0), |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9880 | DAG.getConstant(C, dl, MVT::i32)); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9881 | |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 9882 | if (IntBits < FloatBits) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9883 | FixConv = DAG.getNode(ISD::TRUNCATE, dl, N->getValueType(0), FixConv); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9884 | |
| 9885 | return FixConv; |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9886 | } |
| 9887 | |
| 9888 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 9889 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 9890 | /// when the VDIV has a constant operand that is a power of 2. |
| 9891 | /// |
| 9892 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 9893 | /// vcvt.f32.s32 d16, d16 |
| 9894 | /// vdiv.f32 d16, d17, d16 |
| 9895 | /// becomes: |
| 9896 | /// vcvt.f32.s32 d16, d16, #3 |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9897 | static SDValue PerformVDIVCombine(SDNode *N, SelectionDAG &DAG, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9898 | const ARMSubtarget *Subtarget) { |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9899 | if (!Subtarget->hasNEON()) |
| 9900 | return SDValue(); |
| 9901 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9902 | SDValue Op = N->getOperand(0); |
| 9903 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 9904 | if (!N->getValueType(0).isVector() || |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9905 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 9906 | return SDValue(); |
| 9907 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9908 | SDValue ConstVec = N->getOperand(1); |
| Chad Rosier | aed910b | 2015-10-06 20:51:26 +0000 | [diff] [blame] | 9909 | if (!isa<BuildVectorSDNode>(ConstVec)) |
| 9910 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9911 | |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9912 | MVT FloatTy = N->getSimpleValueType(0).getVectorElementType(); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 9913 | uint32_t FloatBits = FloatTy.getSizeInBits(); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9914 | MVT IntTy = Op.getOperand(0).getSimpleValueType().getVectorElementType(); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 9915 | uint32_t IntBits = IntTy.getSizeInBits(); |
| Chad Rosier | 17436bf | 2015-10-07 16:15:40 +0000 | [diff] [blame] | 9916 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); |
| 9917 | if (FloatBits != 32 || IntBits > 32 || NumLanes > 4) { |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9918 | // These instructions only exist converting from i32 to f32. We can handle |
| 9919 | // smaller integers by generating an extra extend, but larger ones would |
| Chad Rosier | 17436bf | 2015-10-07 16:15:40 +0000 | [diff] [blame] | 9920 | // be lossy. We also can't handle more then 4 lanes, since these intructions |
| 9921 | // only support v2i32/v4i32 types. |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9922 | return SDValue(); |
| 9923 | } |
| 9924 | |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9925 | BitVector UndefElements; |
| 9926 | BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec); |
| 9927 | int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, 33); |
| 9928 | if (C == -1 || C == 0 || C > 32) |
| Chad Rosier | db71abf | 2015-10-07 13:40:44 +0000 | [diff] [blame] | 9929 | return SDValue(); |
| 9930 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9931 | SDLoc dl(N); |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9932 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9933 | SDValue ConvInput = Op.getOperand(0); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 9934 | if (IntBits < FloatBits) |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9935 | ConvInput = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9936 | dl, NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 9937 | ConvInput); |
| 9938 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 9939 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9940 | Intrinsic::arm_neon_vcvtfxu2fp; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9941 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9942 | Op.getValueType(), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9943 | DAG.getConstant(IntrinsicOpcode, dl, MVT::i32), |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 9944 | ConvInput, DAG.getConstant(C, dl, MVT::i32)); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 9945 | } |
| 9946 | |
| 9947 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9948 | /// operand of a vector shift operation, where all the elements of the |
| 9949 | /// build_vector must have the same constant integer value. |
| 9950 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 9951 | // Ignore bit_converts. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9952 | while (Op.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9953 | Op = Op.getOperand(0); |
| 9954 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 9955 | APInt SplatBits, SplatUndef; |
| 9956 | unsigned SplatBitSize; |
| 9957 | bool HasAnyUndefs; |
| 9958 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 9959 | HasAnyUndefs, ElementBits) || |
| 9960 | SplatBitSize > ElementBits) |
| 9961 | return false; |
| 9962 | Cnt = SplatBits.getSExtValue(); |
| 9963 | return true; |
| 9964 | } |
| 9965 | |
| 9966 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 9967 | /// operand of a vector shift left operation. That value must be in the range: |
| 9968 | /// 0 <= Value < ElementBits for a left shift; or |
| 9969 | /// 0 <= Value <= ElementBits for a long left shift. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9970 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9971 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 9972 | int64_t ElementBits = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9973 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 9974 | return false; |
| 9975 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 9976 | } |
| 9977 | |
| 9978 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 9979 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 9980 | /// is positive, but for an intrinsic the value count must be negative. The |
| 9981 | /// absolute value must be in the range: |
| 9982 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 9983 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 9984 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9985 | int64_t &Cnt) { |
| 9986 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 9987 | int64_t ElementBits = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9988 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 9989 | return false; |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 9990 | if (!isIntrinsic) |
| 9991 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 9992 | if (Cnt >= -(isNarrow ? ElementBits/2 : ElementBits) && Cnt <= -1) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9993 | Cnt = -Cnt; |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 9994 | return true; |
| 9995 | } |
| 9996 | return false; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 9997 | } |
| 9998 | |
| 9999 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 10000 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 10001 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 10002 | switch (IntNo) { |
| 10003 | default: |
| 10004 | // Don't do anything for most intrinsics. |
| 10005 | break; |
| 10006 | |
| James Molloy | a6702e2 | 2015-07-17 17:10:55 +0000 | [diff] [blame] | 10007 | case Intrinsic::arm_neon_vabds: |
| 10008 | if (!N->getValueType(0).isInteger()) |
| 10009 | return SDValue(); |
| 10010 | return DAG.getNode(ISD::SABSDIFF, SDLoc(N), N->getValueType(0), |
| 10011 | N->getOperand(1), N->getOperand(2)); |
| 10012 | case Intrinsic::arm_neon_vabdu: |
| 10013 | return DAG.getNode(ISD::UABSDIFF, SDLoc(N), N->getValueType(0), |
| 10014 | N->getOperand(1), N->getOperand(2)); |
| 10015 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10016 | // Vector shifts: check for immediate versions and lower them. |
| 10017 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 10018 | // the build_vectors for 64-bit vector element shift counts are generally |
| 10019 | // not legal, and it is hard to see their values after they get legalized to |
| 10020 | // loads from a constant pool. |
| 10021 | case Intrinsic::arm_neon_vshifts: |
| 10022 | case Intrinsic::arm_neon_vshiftu: |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10023 | case Intrinsic::arm_neon_vrshifts: |
| 10024 | case Intrinsic::arm_neon_vrshiftu: |
| 10025 | case Intrinsic::arm_neon_vrshiftn: |
| 10026 | case Intrinsic::arm_neon_vqshifts: |
| 10027 | case Intrinsic::arm_neon_vqshiftu: |
| 10028 | case Intrinsic::arm_neon_vqshiftsu: |
| 10029 | case Intrinsic::arm_neon_vqshiftns: |
| 10030 | case Intrinsic::arm_neon_vqshiftnu: |
| 10031 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10032 | case Intrinsic::arm_neon_vqrshiftns: |
| 10033 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10034 | case Intrinsic::arm_neon_vqrshiftnsu: { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10035 | EVT VT = N->getOperand(1).getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10036 | int64_t Cnt; |
| 10037 | unsigned VShiftOpc = 0; |
| 10038 | |
| 10039 | switch (IntNo) { |
| 10040 | case Intrinsic::arm_neon_vshifts: |
| 10041 | case Intrinsic::arm_neon_vshiftu: |
| 10042 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 10043 | VShiftOpc = ARMISD::VSHL; |
| 10044 | break; |
| 10045 | } |
| 10046 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 10047 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 10048 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 10049 | break; |
| 10050 | } |
| 10051 | return SDValue(); |
| 10052 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10053 | case Intrinsic::arm_neon_vrshifts: |
| 10054 | case Intrinsic::arm_neon_vrshiftu: |
| 10055 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 10056 | break; |
| 10057 | return SDValue(); |
| 10058 | |
| 10059 | case Intrinsic::arm_neon_vqshifts: |
| 10060 | case Intrinsic::arm_neon_vqshiftu: |
| 10061 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 10062 | break; |
| 10063 | return SDValue(); |
| 10064 | |
| 10065 | case Intrinsic::arm_neon_vqshiftsu: |
| 10066 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 10067 | break; |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10068 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10069 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10070 | case Intrinsic::arm_neon_vrshiftn: |
| 10071 | case Intrinsic::arm_neon_vqshiftns: |
| 10072 | case Intrinsic::arm_neon_vqshiftnu: |
| 10073 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10074 | case Intrinsic::arm_neon_vqrshiftns: |
| 10075 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10076 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 10077 | // Narrowing shifts require an immediate right shift. |
| 10078 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 10079 | break; |
| Jim Grosbach | 84511e1 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 10080 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 10081 | "intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10082 | |
| 10083 | default: |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10084 | llvm_unreachable("unhandled vector shift"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10085 | } |
| 10086 | |
| 10087 | switch (IntNo) { |
| 10088 | case Intrinsic::arm_neon_vshifts: |
| 10089 | case Intrinsic::arm_neon_vshiftu: |
| 10090 | // Opcode already set above. |
| 10091 | break; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10092 | case Intrinsic::arm_neon_vrshifts: |
| 10093 | VShiftOpc = ARMISD::VRSHRs; break; |
| 10094 | case Intrinsic::arm_neon_vrshiftu: |
| 10095 | VShiftOpc = ARMISD::VRSHRu; break; |
| 10096 | case Intrinsic::arm_neon_vrshiftn: |
| 10097 | VShiftOpc = ARMISD::VRSHRN; break; |
| 10098 | case Intrinsic::arm_neon_vqshifts: |
| 10099 | VShiftOpc = ARMISD::VQSHLs; break; |
| 10100 | case Intrinsic::arm_neon_vqshiftu: |
| 10101 | VShiftOpc = ARMISD::VQSHLu; break; |
| 10102 | case Intrinsic::arm_neon_vqshiftsu: |
| 10103 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 10104 | case Intrinsic::arm_neon_vqshiftns: |
| 10105 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 10106 | case Intrinsic::arm_neon_vqshiftnu: |
| 10107 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 10108 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10109 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 10110 | case Intrinsic::arm_neon_vqrshiftns: |
| 10111 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 10112 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10113 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 10114 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 10115 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 10116 | } |
| 10117 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10118 | SDLoc dl(N); |
| 10119 | return DAG.getNode(VShiftOpc, dl, N->getValueType(0), |
| 10120 | N->getOperand(1), DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10121 | } |
| 10122 | |
| 10123 | case Intrinsic::arm_neon_vshiftins: { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10124 | EVT VT = N->getOperand(1).getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10125 | int64_t Cnt; |
| 10126 | unsigned VShiftOpc = 0; |
| 10127 | |
| 10128 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 10129 | VShiftOpc = ARMISD::VSLI; |
| 10130 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 10131 | VShiftOpc = ARMISD::VSRI; |
| 10132 | else { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10133 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10134 | } |
| 10135 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10136 | SDLoc dl(N); |
| 10137 | return DAG.getNode(VShiftOpc, dl, N->getValueType(0), |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10138 | N->getOperand(1), N->getOperand(2), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10139 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10140 | } |
| 10141 | |
| 10142 | case Intrinsic::arm_neon_vqrshifts: |
| 10143 | case Intrinsic::arm_neon_vqrshiftu: |
| 10144 | // No immediate versions of these to check for. |
| 10145 | break; |
| 10146 | } |
| 10147 | |
| 10148 | return SDValue(); |
| 10149 | } |
| 10150 | |
| 10151 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 10152 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 10153 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 10154 | /// vector element shift counts are generally not legal, and it is hard to see |
| 10155 | /// their values after they get legalized to loads from a constant pool. |
| 10156 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 10157 | const ARMSubtarget *ST) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10158 | EVT VT = N->getValueType(0); |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 10159 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 10160 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 10161 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 10162 | SDValue N1 = N->getOperand(1); |
| 10163 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 10164 | SDValue N0 = N->getOperand(0); |
| 10165 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 10166 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 10167 | APInt::getHighBitsSet(32, 16))) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10168 | return DAG.getNode(ISD::ROTR, SDLoc(N), VT, N0, N1); |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 10169 | } |
| 10170 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10171 | |
| 10172 | // Nothing to be done for scalar shifts. |
| Tanya Lattner | cd68095 | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 10173 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 10174 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10175 | return SDValue(); |
| 10176 | |
| 10177 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 10178 | int64_t Cnt; |
| 10179 | |
| 10180 | switch (N->getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10181 | default: llvm_unreachable("unexpected shift opcode"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10182 | |
| 10183 | case ISD::SHL: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10184 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) { |
| 10185 | SDLoc dl(N); |
| 10186 | return DAG.getNode(ARMISD::VSHL, dl, VT, N->getOperand(0), |
| 10187 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| 10188 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10189 | break; |
| 10190 | |
| 10191 | case ISD::SRA: |
| 10192 | case ISD::SRL: |
| 10193 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 10194 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 10195 | ARMISD::VSHRs : ARMISD::VSHRu); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10196 | SDLoc dl(N); |
| 10197 | return DAG.getNode(VShiftOpc, dl, VT, N->getOperand(0), |
| 10198 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10199 | } |
| 10200 | } |
| 10201 | return SDValue(); |
| 10202 | } |
| 10203 | |
| 10204 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 10205 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 10206 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 10207 | const ARMSubtarget *ST) { |
| 10208 | SDValue N0 = N->getOperand(0); |
| 10209 | |
| 10210 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 10211 | // and 16-bit vector elements. NEON supports these directly. They are |
| 10212 | // handled during DAG combining because type legalization will promote them |
| 10213 | // to 32-bit types and it is messy to recognize the operations after that. |
| 10214 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 10215 | SDValue Vec = N0.getOperand(0); |
| 10216 | SDValue Lane = N0.getOperand(1); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10217 | EVT VT = N->getValueType(0); |
| 10218 | EVT EltVT = N0.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10219 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 10220 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10221 | if (VT == MVT::i32 && |
| 10222 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 10223 | TLI.isTypeLegal(Vec.getValueType()) && |
| 10224 | isa<ConstantSDNode>(Lane)) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10225 | |
| 10226 | unsigned Opc = 0; |
| 10227 | switch (N->getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10228 | default: llvm_unreachable("unexpected opcode"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10229 | case ISD::SIGN_EXTEND: |
| 10230 | Opc = ARMISD::VGETLANEs; |
| 10231 | break; |
| 10232 | case ISD::ZERO_EXTEND: |
| 10233 | case ISD::ANY_EXTEND: |
| 10234 | Opc = ARMISD::VGETLANEu; |
| 10235 | break; |
| 10236 | } |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10237 | return DAG.getNode(Opc, SDLoc(N), VT, Vec, Lane); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10238 | } |
| 10239 | } |
| 10240 | |
| 10241 | return SDValue(); |
| 10242 | } |
| 10243 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10244 | static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero, |
| 10245 | APInt &KnownOne) { |
| 10246 | if (Op.getOpcode() == ARMISD::BFI) { |
| 10247 | // Conservatively, we can recurse down the first operand |
| 10248 | // and just mask out all affected bits. |
| 10249 | computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne); |
| 10250 | |
| 10251 | // The operand to BFI is already a mask suitable for removing the bits it |
| 10252 | // sets. |
| 10253 | ConstantSDNode *CI = cast<ConstantSDNode>(Op.getOperand(2)); |
| 10254 | APInt Mask = CI->getAPIntValue(); |
| 10255 | KnownZero &= Mask; |
| 10256 | KnownOne &= Mask; |
| 10257 | return; |
| 10258 | } |
| 10259 | if (Op.getOpcode() == ARMISD::CMOV) { |
| 10260 | APInt KZ2(KnownZero.getBitWidth(), 0); |
| 10261 | APInt KO2(KnownOne.getBitWidth(), 0); |
| 10262 | computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne); |
| 10263 | computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2); |
| 10264 | |
| 10265 | KnownZero &= KZ2; |
| 10266 | KnownOne &= KO2; |
| 10267 | return; |
| 10268 | } |
| 10269 | return DAG.computeKnownBits(Op, KnownZero, KnownOne); |
| 10270 | } |
| 10271 | |
| 10272 | SDValue ARMTargetLowering::PerformCMOVToBFICombine(SDNode *CMOV, SelectionDAG &DAG) const { |
| 10273 | // If we have a CMOV, OR and AND combination such as: |
| 10274 | // if (x & CN) |
| 10275 | // y |= CM; |
| 10276 | // |
| 10277 | // And: |
| 10278 | // * CN is a single bit; |
| 10279 | // * All bits covered by CM are known zero in y |
| 10280 | // |
| 10281 | // Then we can convert this into a sequence of BFI instructions. This will |
| 10282 | // always be a win if CM is a single bit, will always be no worse than the |
| 10283 | // TST&OR sequence if CM is two bits, and for thumb will be no worse if CM is |
| 10284 | // three bits (due to the extra IT instruction). |
| 10285 | |
| 10286 | SDValue Op0 = CMOV->getOperand(0); |
| 10287 | SDValue Op1 = CMOV->getOperand(1); |
| 10288 | SDValue CmpZ = CMOV->getOperand(4); |
| 10289 | |
| 10290 | assert(CmpZ->getOpcode() == ARMISD::CMPZ); |
| 10291 | SDValue And = CmpZ->getOperand(0); |
| 10292 | if (And->getOpcode() != ISD::AND) |
| 10293 | return SDValue(); |
| 10294 | ConstantSDNode *AndC = dyn_cast<ConstantSDNode>(And->getOperand(1)); |
| 10295 | if (!AndC || !AndC->getAPIntValue().isPowerOf2()) |
| 10296 | return SDValue(); |
| 10297 | SDValue X = And->getOperand(0); |
| 10298 | |
| 10299 | if (Op1->getOpcode() != ISD::OR) |
| 10300 | return SDValue(); |
| 10301 | |
| 10302 | ConstantSDNode *OrC = dyn_cast<ConstantSDNode>(Op1->getOperand(1)); |
| 10303 | if (!OrC) |
| 10304 | return SDValue(); |
| 10305 | SDValue Y = Op1->getOperand(0); |
| 10306 | |
| 10307 | if (Op0 != Y) |
| 10308 | return SDValue(); |
| 10309 | |
| 10310 | // Now, is it profitable to continue? |
| 10311 | APInt OrCI = OrC->getAPIntValue(); |
| 10312 | unsigned Heuristic = Subtarget->isThumb() ? 3 : 2; |
| 10313 | if (OrCI.countPopulation() > Heuristic) |
| 10314 | return SDValue(); |
| 10315 | |
| 10316 | // Lastly, can we determine that the bits defined by OrCI |
| 10317 | // are zero in Y? |
| 10318 | APInt KnownZero, KnownOne; |
| 10319 | computeKnownBits(DAG, Y, KnownZero, KnownOne); |
| 10320 | if ((OrCI & KnownZero) != OrCI) |
| 10321 | return SDValue(); |
| 10322 | |
| 10323 | // OK, we can do the combine. |
| 10324 | SDValue V = Y; |
| 10325 | SDLoc dl(X); |
| 10326 | EVT VT = X.getValueType(); |
| 10327 | unsigned BitInX = AndC->getAPIntValue().logBase2(); |
| 10328 | |
| 10329 | if (BitInX != 0) { |
| 10330 | // We must shift X first. |
| 10331 | X = DAG.getNode(ISD::SRL, dl, VT, X, |
| 10332 | DAG.getConstant(BitInX, dl, VT)); |
| 10333 | } |
| 10334 | |
| 10335 | for (unsigned BitInY = 0, NumActiveBits = OrCI.getActiveBits(); |
| 10336 | BitInY < NumActiveBits; ++BitInY) { |
| 10337 | if (OrCI[BitInY] == 0) |
| 10338 | continue; |
| 10339 | APInt Mask(VT.getSizeInBits(), 0); |
| 10340 | Mask.setBit(BitInY); |
| 10341 | V = DAG.getNode(ARMISD::BFI, dl, VT, V, X, |
| 10342 | // Confusingly, the operand is an *inverted* mask. |
| 10343 | DAG.getConstant(~Mask, dl, VT)); |
| 10344 | } |
| 10345 | |
| 10346 | return V; |
| 10347 | } |
| 10348 | |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10349 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 10350 | SDValue |
| 10351 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 10352 | SDValue Cmp = N->getOperand(4); |
| 10353 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 10354 | // Only looking at EQ and NE cases. |
| 10355 | return SDValue(); |
| 10356 | |
| 10357 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10358 | SDLoc dl(N); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10359 | SDValue LHS = Cmp.getOperand(0); |
| 10360 | SDValue RHS = Cmp.getOperand(1); |
| 10361 | SDValue FalseVal = N->getOperand(0); |
| 10362 | SDValue TrueVal = N->getOperand(1); |
| 10363 | SDValue ARMcc = N->getOperand(2); |
| Jim Grosbach | e7e2aca | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 10364 | ARMCC::CondCodes CC = |
| 10365 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10366 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10367 | // BFI is only available on V6T2+. |
| 10368 | if (!Subtarget->isThumb1Only() && Subtarget->hasV6T2Ops()) { |
| 10369 | SDValue R = PerformCMOVToBFICombine(N, DAG); |
| 10370 | if (R) |
| 10371 | return R; |
| 10372 | } |
| 10373 | |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10374 | // Simplify |
| 10375 | // mov r1, r0 |
| 10376 | // cmp r1, x |
| 10377 | // mov r0, y |
| 10378 | // moveq r0, x |
| 10379 | // to |
| 10380 | // cmp r0, x |
| 10381 | // movne r0, y |
| 10382 | // |
| 10383 | // mov r1, r0 |
| 10384 | // cmp r1, x |
| 10385 | // mov r0, x |
| 10386 | // movne r0, y |
| 10387 | // to |
| 10388 | // cmp r0, x |
| 10389 | // movne r0, y |
| 10390 | /// FIXME: Turn this into a target neutral optimization? |
| 10391 | SDValue Res; |
| Evan Cheng | 8156376 | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 10392 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10393 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 10394 | N->getOperand(3), Cmp); |
| 10395 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 10396 | SDValue ARMcc; |
| 10397 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 10398 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 10399 | N->getOperand(3), NewCmp); |
| 10400 | } |
| 10401 | |
| 10402 | if (Res.getNode()) { |
| 10403 | APInt KnownZero, KnownOne; |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 10404 | DAG.computeKnownBits(SDValue(N,0), KnownZero, KnownOne); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10405 | // Capture demanded bits information that would be otherwise lost. |
| 10406 | if (KnownZero == 0xfffffffe) |
| 10407 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10408 | DAG.getValueType(MVT::i1)); |
| 10409 | else if (KnownZero == 0xffffff00) |
| 10410 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10411 | DAG.getValueType(MVT::i8)); |
| 10412 | else if (KnownZero == 0xffff0000) |
| 10413 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10414 | DAG.getValueType(MVT::i16)); |
| 10415 | } |
| 10416 | |
| 10417 | return Res; |
| 10418 | } |
| 10419 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10420 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10421 | DAGCombinerInfo &DCI) const { |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10422 | switch (N->getOpcode()) { |
| 10423 | default: break; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 10424 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 10425 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10426 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 10427 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10428 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 10429 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 10430 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 10431 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 10432 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI, Subtarget); |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 10433 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 10434 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 10435 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI, Subtarget); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 10436 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 10437 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 10438 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10439 | case ISD::FP_TO_SINT: |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10440 | case ISD::FP_TO_UINT: |
| 10441 | return PerformVCVTCombine(N, DCI.DAG, Subtarget); |
| 10442 | case ISD::FDIV: |
| 10443 | return PerformVDIVCombine(N, DCI.DAG, Subtarget); |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10444 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10445 | case ISD::SHL: |
| 10446 | case ISD::SRA: |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10447 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10448 | case ISD::SIGN_EXTEND: |
| 10449 | case ISD::ZERO_EXTEND: |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10450 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10451 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10452 | case ISD::LOAD: return PerformLOADCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10453 | case ARMISD::VLD2DUP: |
| 10454 | case ARMISD::VLD3DUP: |
| 10455 | case ARMISD::VLD4DUP: |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10456 | return PerformVLDCombine(N, DCI); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 10457 | case ARMISD::BUILD_VECTOR: |
| 10458 | return PerformARMBUILD_VECTORCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10459 | case ISD::INTRINSIC_VOID: |
| 10460 | case ISD::INTRINSIC_W_CHAIN: |
| 10461 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 10462 | case Intrinsic::arm_neon_vld1: |
| 10463 | case Intrinsic::arm_neon_vld2: |
| 10464 | case Intrinsic::arm_neon_vld3: |
| 10465 | case Intrinsic::arm_neon_vld4: |
| 10466 | case Intrinsic::arm_neon_vld2lane: |
| 10467 | case Intrinsic::arm_neon_vld3lane: |
| 10468 | case Intrinsic::arm_neon_vld4lane: |
| 10469 | case Intrinsic::arm_neon_vst1: |
| 10470 | case Intrinsic::arm_neon_vst2: |
| 10471 | case Intrinsic::arm_neon_vst3: |
| 10472 | case Intrinsic::arm_neon_vst4: |
| 10473 | case Intrinsic::arm_neon_vst2lane: |
| 10474 | case Intrinsic::arm_neon_vst3lane: |
| 10475 | case Intrinsic::arm_neon_vst4lane: |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10476 | return PerformVLDCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10477 | default: break; |
| 10478 | } |
| 10479 | break; |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10480 | } |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10481 | return SDValue(); |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10482 | } |
| 10483 | |
| Evan Cheng | d42641c | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 10484 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 10485 | EVT VT) const { |
| 10486 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 10487 | } |
| 10488 | |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10489 | bool ARMTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, |
| 10490 | unsigned, |
| 10491 | unsigned, |
| 10492 | bool *Fast) const { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10493 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
| Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 10494 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
| Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 10495 | |
| 10496 | switch (VT.getSimpleVT().SimpleTy) { |
| 10497 | default: |
| 10498 | return false; |
| 10499 | case MVT::i8: |
| 10500 | case MVT::i16: |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10501 | case MVT::i32: { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10502 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10503 | if (AllowsUnaligned) { |
| 10504 | if (Fast) |
| 10505 | *Fast = Subtarget->hasV7Ops(); |
| 10506 | return true; |
| 10507 | } |
| 10508 | return false; |
| 10509 | } |
| Evan Cheng | eec6bc6 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 10510 | case MVT::f64: |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10511 | case MVT::v2f64: { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10512 | // For any little-endian targets with neon, we can support unaligned ld/st |
| 10513 | // of D and Q (e.g. {D0,D1}) registers by using vld1.i8/vst1.i8. |
| Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 10514 | // A big-endian target may also explicitly support unaligned accesses |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 10515 | if (Subtarget->hasNEON() && (AllowsUnaligned || Subtarget->isLittle())) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10516 | if (Fast) |
| 10517 | *Fast = true; |
| 10518 | return true; |
| 10519 | } |
| 10520 | return false; |
| 10521 | } |
| Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 10522 | } |
| 10523 | } |
| 10524 | |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10525 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 10526 | unsigned AlignCheck) { |
| 10527 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 10528 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 10529 | } |
| 10530 | |
| 10531 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 10532 | unsigned DstAlign, unsigned SrcAlign, |
| Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 10533 | bool IsMemset, bool ZeroMemset, |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10534 | bool MemcpyStrSrc, |
| 10535 | MachineFunction &MF) const { |
| 10536 | const Function *F = MF.getFunction(); |
| 10537 | |
| 10538 | // See if we can use NEON instructions for this... |
| Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 10539 | if ((!IsMemset || ZeroMemset) && Subtarget->hasNEON() && |
| 10540 | !F->hasFnAttribute(Attribute::NoImplicitFloat)) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10541 | bool Fast; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10542 | if (Size >= 16 && |
| 10543 | (memOpAlign(SrcAlign, DstAlign, 16) || |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10544 | (allowsMisalignedMemoryAccesses(MVT::v2f64, 0, 1, &Fast) && Fast))) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10545 | return MVT::v2f64; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10546 | } else if (Size >= 8 && |
| 10547 | (memOpAlign(SrcAlign, DstAlign, 8) || |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10548 | (allowsMisalignedMemoryAccesses(MVT::f64, 0, 1, &Fast) && |
| 10549 | Fast))) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10550 | return MVT::f64; |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10551 | } |
| 10552 | } |
| 10553 | |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10554 | // Lowering to i32/i16 if the size permits. |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10555 | if (Size >= 4) |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10556 | return MVT::i32; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10557 | else if (Size >= 2) |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10558 | return MVT::i16; |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10559 | |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10560 | // Let the target-independent logic figure it out. |
| 10561 | return MVT::Other; |
| 10562 | } |
| 10563 | |
| Evan Cheng | 9ec512d | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 10564 | bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { |
| 10565 | if (Val.getOpcode() != ISD::LOAD) |
| 10566 | return false; |
| 10567 | |
| 10568 | EVT VT1 = Val.getValueType(); |
| 10569 | if (!VT1.isSimple() || !VT1.isInteger() || |
| 10570 | !VT2.isSimple() || !VT2.isInteger()) |
| 10571 | return false; |
| 10572 | |
| 10573 | switch (VT1.getSimpleVT().SimpleTy) { |
| 10574 | default: break; |
| 10575 | case MVT::i1: |
| 10576 | case MVT::i8: |
| 10577 | case MVT::i16: |
| 10578 | // 8-bit and 16-bit loads implicitly zero-extend to 32-bits. |
| 10579 | return true; |
| 10580 | } |
| 10581 | |
| 10582 | return false; |
| 10583 | } |
| 10584 | |
| Ahmed Bougacha | 4200cc9 | 2015-03-05 19:37:53 +0000 | [diff] [blame] | 10585 | bool ARMTargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const { |
| 10586 | EVT VT = ExtVal.getValueType(); |
| 10587 | |
| 10588 | if (!isTypeLegal(VT)) |
| 10589 | return false; |
| 10590 | |
| 10591 | // Don't create a loadext if we can fold the extension into a wide/long |
| 10592 | // instruction. |
| 10593 | // If there's more than one user instruction, the loadext is desirable no |
| 10594 | // matter what. There can be two uses by the same instruction. |
| 10595 | if (ExtVal->use_empty() || |
| 10596 | !ExtVal->use_begin()->isOnlyUserOf(ExtVal.getNode())) |
| 10597 | return true; |
| 10598 | |
| 10599 | SDNode *U = *ExtVal->use_begin(); |
| 10600 | if ((U->getOpcode() == ISD::ADD || U->getOpcode() == ISD::SUB || |
| 10601 | U->getOpcode() == ISD::SHL || U->getOpcode() == ARMISD::VSHL)) |
| 10602 | return false; |
| 10603 | |
| 10604 | return true; |
| 10605 | } |
| 10606 | |
| Tim Northover | cc2e903 | 2013-08-06 13:58:03 +0000 | [diff] [blame] | 10607 | bool ARMTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 10608 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 10609 | return false; |
| 10610 | |
| 10611 | if (!isTypeLegal(EVT::getEVT(Ty1))) |
| 10612 | return false; |
| 10613 | |
| 10614 | assert(Ty1->getPrimitiveSizeInBits() <= 64 && "i128 is probably not a noop"); |
| 10615 | |
| 10616 | // Assuming the caller doesn't have a zeroext or signext return parameter, |
| 10617 | // truncation all the way down to i1 is valid. |
| 10618 | return true; |
| 10619 | } |
| 10620 | |
| 10621 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10622 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 10623 | if (V < 0) |
| 10624 | return false; |
| 10625 | |
| 10626 | unsigned Scale = 1; |
| 10627 | switch (VT.getSimpleVT().SimpleTy) { |
| 10628 | default: return false; |
| 10629 | case MVT::i1: |
| 10630 | case MVT::i8: |
| 10631 | // Scale == 1; |
| 10632 | break; |
| 10633 | case MVT::i16: |
| 10634 | // Scale == 2; |
| 10635 | Scale = 2; |
| 10636 | break; |
| 10637 | case MVT::i32: |
| 10638 | // Scale == 4; |
| 10639 | Scale = 4; |
| 10640 | break; |
| 10641 | } |
| 10642 | |
| 10643 | if ((V & (Scale - 1)) != 0) |
| 10644 | return false; |
| 10645 | V /= Scale; |
| 10646 | return V == (V & ((1LL << 5) - 1)); |
| 10647 | } |
| 10648 | |
| 10649 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 10650 | const ARMSubtarget *Subtarget) { |
| 10651 | bool isNeg = false; |
| 10652 | if (V < 0) { |
| 10653 | isNeg = true; |
| 10654 | V = - V; |
| 10655 | } |
| 10656 | |
| 10657 | switch (VT.getSimpleVT().SimpleTy) { |
| 10658 | default: return false; |
| 10659 | case MVT::i1: |
| 10660 | case MVT::i8: |
| 10661 | case MVT::i16: |
| 10662 | case MVT::i32: |
| 10663 | // + imm12 or - imm8 |
| 10664 | if (isNeg) |
| 10665 | return V == (V & ((1LL << 8) - 1)); |
| 10666 | return V == (V & ((1LL << 12) - 1)); |
| 10667 | case MVT::f32: |
| 10668 | case MVT::f64: |
| 10669 | // Same as ARM mode. FIXME: NEON? |
| 10670 | if (!Subtarget->hasVFP2()) |
| 10671 | return false; |
| 10672 | if ((V & 3) != 0) |
| 10673 | return false; |
| 10674 | V >>= 2; |
| 10675 | return V == (V & ((1LL << 8) - 1)); |
| 10676 | } |
| 10677 | } |
| 10678 | |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10679 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 10680 | /// as the offset of the target addressing mode for load / store of the |
| 10681 | /// given type. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10682 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10683 | const ARMSubtarget *Subtarget) { |
| Evan Cheng | 507eefa | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 10684 | if (V == 0) |
| 10685 | return true; |
| 10686 | |
| Evan Cheng | ce5dfb6 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 10687 | if (!VT.isSimple()) |
| 10688 | return false; |
| 10689 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10690 | if (Subtarget->isThumb1Only()) |
| 10691 | return isLegalT1AddressImmediate(V, VT); |
| 10692 | else if (Subtarget->isThumb2()) |
| 10693 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10694 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10695 | // ARM mode. |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10696 | if (V < 0) |
| 10697 | V = - V; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10698 | switch (VT.getSimpleVT().SimpleTy) { |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10699 | default: return false; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10700 | case MVT::i1: |
| 10701 | case MVT::i8: |
| 10702 | case MVT::i32: |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10703 | // +- imm12 |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10704 | return V == (V & ((1LL << 12) - 1)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10705 | case MVT::i16: |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10706 | // +- imm8 |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10707 | return V == (V & ((1LL << 8) - 1)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10708 | case MVT::f32: |
| 10709 | case MVT::f64: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10710 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10711 | return false; |
| Evan Cheng | bef131de | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 10712 | if ((V & 3) != 0) |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10713 | return false; |
| 10714 | V >>= 2; |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10715 | return V == (V & ((1LL << 8) - 1)); |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10716 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10717 | } |
| 10718 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10719 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 10720 | EVT VT) const { |
| 10721 | int Scale = AM.Scale; |
| 10722 | if (Scale < 0) |
| 10723 | return false; |
| 10724 | |
| 10725 | switch (VT.getSimpleVT().SimpleTy) { |
| 10726 | default: return false; |
| 10727 | case MVT::i1: |
| 10728 | case MVT::i8: |
| 10729 | case MVT::i16: |
| 10730 | case MVT::i32: |
| 10731 | if (Scale == 1) |
| 10732 | return true; |
| 10733 | // r + r << imm |
| 10734 | Scale = Scale & ~1; |
| 10735 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 10736 | case MVT::i64: |
| 10737 | // r + r |
| 10738 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 10739 | return true; |
| 10740 | return false; |
| 10741 | case MVT::isVoid: |
| 10742 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 10743 | // stores), because arm allows folding a scale into many arithmetic |
| 10744 | // operations. This should be made more precise and revisited later. |
| 10745 | |
| 10746 | // Allow r << imm, but the imm has to be a multiple of two. |
| 10747 | if (Scale & 1) return false; |
| 10748 | return isPowerOf2_32(Scale); |
| 10749 | } |
| 10750 | } |
| 10751 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10752 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 10753 | /// by AM is legal for this target, for a load/store of the specified type. |
| Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 10754 | bool ARMTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 10755 | const AddrMode &AM, Type *Ty, |
| Matt Arsenault | bd7d80a | 2015-06-01 05:31:59 +0000 | [diff] [blame] | 10756 | unsigned AS) const { |
| Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 10757 | EVT VT = getValueType(DL, Ty, true); |
| Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 10758 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10759 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10760 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10761 | // Can never fold addr of global into load/store. |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10762 | if (AM.BaseGV) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10763 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10764 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10765 | switch (AM.Scale) { |
| 10766 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 10767 | break; |
| 10768 | case 1: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10769 | if (Subtarget->isThumb1Only()) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10770 | return false; |
| Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 10771 | // FALL THROUGH. |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10772 | default: |
| Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 10773 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 10774 | if (AM.BaseOffs) |
| 10775 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10776 | |
| Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 10777 | if (!VT.isSimple()) |
| 10778 | return false; |
| 10779 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10780 | if (Subtarget->isThumb2()) |
| 10781 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 10782 | |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 10783 | int Scale = AM.Scale; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10784 | switch (VT.getSimpleVT().SimpleTy) { |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10785 | default: return false; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10786 | case MVT::i1: |
| 10787 | case MVT::i8: |
| 10788 | case MVT::i32: |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 10789 | if (Scale < 0) Scale = -Scale; |
| 10790 | if (Scale == 1) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10791 | return true; |
| 10792 | // r + r << imm |
| Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 10793 | return isPowerOf2_32(Scale & ~1); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10794 | case MVT::i16: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10795 | case MVT::i64: |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10796 | // r + r |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 10797 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10798 | return true; |
| Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 10799 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10800 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10801 | case MVT::isVoid: |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10802 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 10803 | // stores), because arm allows folding a scale into many arithmetic |
| 10804 | // operations. This should be made more precise and revisited later. |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10805 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10806 | // Allow r << imm, but the imm has to be a multiple of two. |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10807 | if (Scale & 1) return false; |
| 10808 | return isPowerOf2_32(Scale); |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10809 | } |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10810 | } |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10811 | return true; |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10812 | } |
| 10813 | |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 10814 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 10815 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 10816 | /// a register against the immediate without having to materialize the |
| 10817 | /// immediate into a register. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 10818 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 10819 | // Thumb2 and ARM modes can use cmn for negative immediates. |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 10820 | if (!Subtarget->isThumb()) |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 10821 | return ARM_AM::getSOImmVal(std::abs(Imm)) != -1; |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 10822 | if (Subtarget->isThumb2()) |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 10823 | return ARM_AM::getT2SOImmVal(std::abs(Imm)) != -1; |
| Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 10824 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 10825 | return Imm >= 0 && Imm <= 255; |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 10826 | } |
| 10827 | |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 10828 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
| 10829 | /// *or sub* immediate, that is the target has add or sub instructions which can |
| 10830 | /// add a register with the immediate without having to materialize the |
| Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 10831 | /// immediate into a register. |
| 10832 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 10833 | // Same encoding for add/sub, just flip the sign. |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 10834 | int64_t AbsImm = std::abs(Imm); |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 10835 | if (!Subtarget->isThumb()) |
| 10836 | return ARM_AM::getSOImmVal(AbsImm) != -1; |
| 10837 | if (Subtarget->isThumb2()) |
| 10838 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; |
| 10839 | // Thumb1 only has 8-bit unsigned immediate. |
| 10840 | return AbsImm >= 0 && AbsImm <= 255; |
| Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 10841 | } |
| 10842 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10843 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10844 | bool isSEXTLoad, SDValue &Base, |
| 10845 | SDValue &Offset, bool &isInc, |
| 10846 | SelectionDAG &DAG) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10847 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 10848 | return false; |
| 10849 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10850 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10851 | // AddressingMode 3 |
| 10852 | Base = Ptr->getOperand(0); |
| 10853 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 10854 | int RHSC = (int)RHS->getZExtValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10855 | if (RHSC < 0 && RHSC > -256) { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10856 | assert(Ptr->getOpcode() == ISD::ADD); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10857 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10858 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10859 | return true; |
| 10860 | } |
| 10861 | } |
| 10862 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 10863 | Offset = Ptr->getOperand(1); |
| 10864 | return true; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10865 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10866 | // AddressingMode 2 |
| 10867 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 10868 | int RHSC = (int)RHS->getZExtValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10869 | if (RHSC < 0 && RHSC > -0x1000) { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10870 | assert(Ptr->getOpcode() == ISD::ADD); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10871 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10872 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10873 | Base = Ptr->getOperand(0); |
| 10874 | return true; |
| 10875 | } |
| 10876 | } |
| 10877 | |
| 10878 | if (Ptr->getOpcode() == ISD::ADD) { |
| 10879 | isInc = true; |
| Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 10880 | ARM_AM::ShiftOpc ShOpcVal= |
| 10881 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10882 | if (ShOpcVal != ARM_AM::no_shift) { |
| 10883 | Base = Ptr->getOperand(1); |
| 10884 | Offset = Ptr->getOperand(0); |
| 10885 | } else { |
| 10886 | Base = Ptr->getOperand(0); |
| 10887 | Offset = Ptr->getOperand(1); |
| 10888 | } |
| 10889 | return true; |
| 10890 | } |
| 10891 | |
| 10892 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 10893 | Base = Ptr->getOperand(0); |
| 10894 | Offset = Ptr->getOperand(1); |
| 10895 | return true; |
| 10896 | } |
| 10897 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 10898 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10899 | return false; |
| 10900 | } |
| 10901 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10902 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10903 | bool isSEXTLoad, SDValue &Base, |
| 10904 | SDValue &Offset, bool &isInc, |
| 10905 | SelectionDAG &DAG) { |
| 10906 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 10907 | return false; |
| 10908 | |
| 10909 | Base = Ptr->getOperand(0); |
| 10910 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 10911 | int RHSC = (int)RHS->getZExtValue(); |
| 10912 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 10913 | assert(Ptr->getOpcode() == ISD::ADD); |
| 10914 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10915 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10916 | return true; |
| 10917 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 10918 | isInc = Ptr->getOpcode() == ISD::ADD; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10919 | Offset = DAG.getConstant(RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10920 | return true; |
| 10921 | } |
| 10922 | } |
| 10923 | |
| 10924 | return false; |
| 10925 | } |
| 10926 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10927 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 10928 | /// offset pointer and addressing mode by reference if the node's address |
| 10929 | /// can be legally represented as pre-indexed load / store address. |
| 10930 | bool |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10931 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 10932 | SDValue &Offset, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10933 | ISD::MemIndexedMode &AM, |
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10934 | SelectionDAG &DAG) const { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10935 | if (Subtarget->isThumb1Only()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10936 | return false; |
| 10937 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10938 | EVT VT; |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10939 | SDValue Ptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10940 | bool isSEXTLoad = false; |
| 10941 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 10942 | Ptr = LD->getBasePtr(); |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10943 | VT = LD->getMemoryVT(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10944 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 10945 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 10946 | Ptr = ST->getBasePtr(); |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10947 | VT = ST->getMemoryVT(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10948 | } else |
| 10949 | return false; |
| 10950 | |
| 10951 | bool isInc; |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10952 | bool isLegal = false; |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10953 | if (Subtarget->isThumb2()) |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10954 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 10955 | Offset, isInc, DAG); |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10956 | else |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10957 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| Evan Cheng | 844f0b4 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 10958 | Offset, isInc, DAG); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10959 | if (!isLegal) |
| 10960 | return false; |
| 10961 | |
| 10962 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 10963 | return true; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10964 | } |
| 10965 | |
| 10966 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 10967 | /// offset pointer and addressing mode by reference if this node can be |
| 10968 | /// combined with a load / store to form a post-indexed load / store. |
| 10969 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10970 | SDValue &Base, |
| 10971 | SDValue &Offset, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10972 | ISD::MemIndexedMode &AM, |
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 10973 | SelectionDAG &DAG) const { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10974 | if (Subtarget->isThumb1Only()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10975 | return false; |
| 10976 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10977 | EVT VT; |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10978 | SDValue Ptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10979 | bool isSEXTLoad = false; |
| 10980 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10981 | VT = LD->getMemoryVT(); |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10982 | Ptr = LD->getBasePtr(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10983 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 10984 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 10985 | VT = ST->getMemoryVT(); |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10986 | Ptr = ST->getBasePtr(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10987 | } else |
| 10988 | return false; |
| 10989 | |
| 10990 | bool isInc; |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10991 | bool isLegal = false; |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10992 | if (Subtarget->isThumb2()) |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10993 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 10994 | isInc, DAG); |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 10995 | else |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 10996 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 10997 | isInc, DAG); |
| 10998 | if (!isLegal) |
| 10999 | return false; |
| 11000 | |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 11001 | if (Ptr != Base) { |
| 11002 | // Swap base ptr and offset to catch more post-index load / store when |
| 11003 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 11004 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 11005 | !Subtarget->isThumb2()) |
| 11006 | std::swap(Base, Offset); |
| 11007 | |
| 11008 | // Post-indexed load / store update the base pointer. |
| 11009 | if (Ptr != Base) |
| 11010 | return false; |
| 11011 | } |
| 11012 | |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11013 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 11014 | return true; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11015 | } |
| 11016 | |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11017 | void ARMTargetLowering::computeKnownBitsForTargetNode(const SDValue Op, |
| 11018 | APInt &KnownZero, |
| 11019 | APInt &KnownOne, |
| 11020 | const SelectionDAG &DAG, |
| 11021 | unsigned Depth) const { |
| Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 11022 | unsigned BitWidth = KnownOne.getBitWidth(); |
| 11023 | KnownZero = KnownOne = APInt(BitWidth, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11024 | switch (Op.getOpcode()) { |
| 11025 | default: break; |
| Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 11026 | case ARMISD::ADDC: |
| 11027 | case ARMISD::ADDE: |
| 11028 | case ARMISD::SUBC: |
| 11029 | case ARMISD::SUBE: |
| 11030 | // These nodes' second result is a boolean |
| 11031 | if (Op.getResNo() == 0) |
| 11032 | break; |
| 11033 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1); |
| 11034 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11035 | case ARMISD::CMOV: { |
| 11036 | // Bits are known zero/one if known on the LHS and RHS. |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11037 | DAG.computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11038 | if (KnownZero == 0 && KnownOne == 0) return; |
| 11039 | |
| Dan Gohman | f990faf | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 11040 | APInt KnownZeroRHS, KnownOneRHS; |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11041 | DAG.computeKnownBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11042 | KnownZero &= KnownZeroRHS; |
| 11043 | KnownOne &= KnownOneRHS; |
| 11044 | return; |
| 11045 | } |
| Tim Northover | 01b4aa9 | 2014-04-03 15:10:35 +0000 | [diff] [blame] | 11046 | case ISD::INTRINSIC_W_CHAIN: { |
| 11047 | ConstantSDNode *CN = cast<ConstantSDNode>(Op->getOperand(1)); |
| 11048 | Intrinsic::ID IntID = static_cast<Intrinsic::ID>(CN->getZExtValue()); |
| 11049 | switch (IntID) { |
| 11050 | default: return; |
| 11051 | case Intrinsic::arm_ldaex: |
| 11052 | case Intrinsic::arm_ldrex: { |
| 11053 | EVT VT = cast<MemIntrinsicSDNode>(Op)->getMemoryVT(); |
| 11054 | unsigned MemBits = VT.getScalarType().getSizeInBits(); |
| 11055 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits); |
| 11056 | return; |
| 11057 | } |
| 11058 | } |
| 11059 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11060 | } |
| 11061 | } |
| 11062 | |
| 11063 | //===----------------------------------------------------------------------===// |
| 11064 | // ARM Inline Assembly Support |
| 11065 | //===----------------------------------------------------------------------===// |
| 11066 | |
| Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 11067 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 11068 | // Looking for "rev" which is V6+. |
| 11069 | if (!Subtarget->hasV6Ops()) |
| 11070 | return false; |
| 11071 | |
| 11072 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 11073 | std::string AsmStr = IA->getAsmString(); |
| 11074 | SmallVector<StringRef, 4> AsmPieces; |
| 11075 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 11076 | |
| 11077 | switch (AsmPieces.size()) { |
| 11078 | default: return false; |
| 11079 | case 1: |
| 11080 | AsmStr = AsmPieces[0]; |
| 11081 | AsmPieces.clear(); |
| 11082 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 11083 | |
| 11084 | // rev $0, $1 |
| 11085 | if (AsmPieces.size() == 3 && |
| 11086 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 11087 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11088 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 11089 | if (Ty && Ty->getBitWidth() == 32) |
| 11090 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 11091 | } |
| 11092 | break; |
| 11093 | } |
| 11094 | |
| 11095 | return false; |
| 11096 | } |
| 11097 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11098 | /// getConstraintType - Given a constraint letter, return the type of |
| 11099 | /// constraint it is for this target. |
| 11100 | ARMTargetLowering::ConstraintType |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11101 | ARMTargetLowering::getConstraintType(StringRef Constraint) const { |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11102 | if (Constraint.size() == 1) { |
| 11103 | switch (Constraint[0]) { |
| 11104 | default: break; |
| 11105 | case 'l': return C_RegisterClass; |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11106 | case 'w': return C_RegisterClass; |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11107 | case 'h': return C_RegisterClass; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11108 | case 'x': return C_RegisterClass; |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11109 | case 't': return C_RegisterClass; |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11110 | case 'j': return C_Other; // Constant for movw. |
| Eric Christopher | aa50300 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 11111 | // An address with a single base register. Due to the way we |
| 11112 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 11113 | case 'Q': return C_Memory; |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11114 | } |
| Eric Christopher | e256cd0 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 11115 | } else if (Constraint.size() == 2) { |
| 11116 | switch (Constraint[0]) { |
| 11117 | default: break; |
| 11118 | // All 'U+' constraints are addresses. |
| 11119 | case 'U': return C_Memory; |
| 11120 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11121 | } |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11122 | return TargetLowering::getConstraintType(Constraint); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11123 | } |
| 11124 | |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11125 | /// Examine constraint type and operand type and determine a weight value. |
| 11126 | /// This object must already have been set up with the operand type |
| 11127 | /// and the current alternative constraint selected. |
| 11128 | TargetLowering::ConstraintWeight |
| 11129 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 11130 | AsmOperandInfo &info, const char *constraint) const { |
| 11131 | ConstraintWeight weight = CW_Invalid; |
| 11132 | Value *CallOperandVal = info.CallOperandVal; |
| 11133 | // If we don't have a value, we can't do a match, |
| 11134 | // but allow it at the lowest weight. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11135 | if (!CallOperandVal) |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11136 | return CW_Default; |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11137 | Type *type = CallOperandVal->getType(); |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11138 | // Look at the constraint type. |
| 11139 | switch (*constraint) { |
| 11140 | default: |
| 11141 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 11142 | break; |
| 11143 | case 'l': |
| 11144 | if (type->isIntegerTy()) { |
| 11145 | if (Subtarget->isThumb()) |
| 11146 | weight = CW_SpecificReg; |
| 11147 | else |
| 11148 | weight = CW_Register; |
| 11149 | } |
| 11150 | break; |
| 11151 | case 'w': |
| 11152 | if (type->isFloatingPointTy()) |
| 11153 | weight = CW_Register; |
| 11154 | break; |
| 11155 | } |
| 11156 | return weight; |
| 11157 | } |
| 11158 | |
| Eric Christopher | cf2007c | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 11159 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11160 | RCPair ARMTargetLowering::getRegForInlineAsmConstraint( |
| 11161 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11162 | if (Constraint.size() == 1) { |
| Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 11163 | // GCC ARM Constraint Letters |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11164 | switch (Constraint[0]) { |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11165 | case 'l': // Low regs or general regs. |
| Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 11166 | if (Subtarget->isThumb()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11167 | return RCPair(0U, &ARM::tGPRRegClass); |
| 11168 | return RCPair(0U, &ARM::GPRRegClass); |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11169 | case 'h': // High regs or no regs. |
| 11170 | if (Subtarget->isThumb()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11171 | return RCPair(0U, &ARM::hGPRRegClass); |
| Eric Christopher | f09b0f1 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 11172 | break; |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11173 | case 'r': |
| Akira Hatanaka | b961534 | 2014-11-03 20:37:04 +0000 | [diff] [blame] | 11174 | if (Subtarget->isThumb1Only()) |
| 11175 | return RCPair(0U, &ARM::tGPRRegClass); |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11176 | return RCPair(0U, &ARM::GPRRegClass); |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11177 | case 'w': |
| Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 11178 | if (VT == MVT::Other) |
| 11179 | break; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11180 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11181 | return RCPair(0U, &ARM::SPRRegClass); |
| Bob Wilson | 3152b047 | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 11182 | if (VT.getSizeInBits() == 64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11183 | return RCPair(0U, &ARM::DPRRegClass); |
| Evan Cheng | 0c2544f | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 11184 | if (VT.getSizeInBits() == 128) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11185 | return RCPair(0U, &ARM::QPRRegClass); |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11186 | break; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11187 | case 'x': |
| Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 11188 | if (VT == MVT::Other) |
| 11189 | break; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11190 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11191 | return RCPair(0U, &ARM::SPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11192 | if (VT.getSizeInBits() == 64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11193 | return RCPair(0U, &ARM::DPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11194 | if (VT.getSizeInBits() == 128) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11195 | return RCPair(0U, &ARM::QPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11196 | break; |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11197 | case 't': |
| 11198 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11199 | return RCPair(0U, &ARM::SPRRegClass); |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11200 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11201 | } |
| 11202 | } |
| Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 11203 | if (StringRef("{cc}").equals_lower(Constraint)) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11204 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
| Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 11205 | |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 11206 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11207 | } |
| 11208 | |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11209 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 11210 | /// vector. If it is invalid, don't add anything to Ops. |
| 11211 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11212 | std::string &Constraint, |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11213 | std::vector<SDValue>&Ops, |
| 11214 | SelectionDAG &DAG) const { |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11215 | SDValue Result; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11216 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11217 | // Currently only support length 1 constraints. |
| 11218 | if (Constraint.length() != 1) return; |
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 11219 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11220 | char ConstraintLetter = Constraint[0]; |
| 11221 | switch (ConstraintLetter) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11222 | default: break; |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11223 | case 'j': |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11224 | case 'I': case 'J': case 'K': case 'L': |
| 11225 | case 'M': case 'N': case 'O': |
| 11226 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 11227 | if (!C) |
| 11228 | return; |
| 11229 | |
| 11230 | int64_t CVal64 = C->getSExtValue(); |
| 11231 | int CVal = (int) CVal64; |
| 11232 | // None of these constraints allow values larger than 32 bits. Check |
| 11233 | // that the value fits in an int. |
| 11234 | if (CVal != CVal64) |
| 11235 | return; |
| 11236 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11237 | switch (ConstraintLetter) { |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11238 | case 'j': |
| Andrew Trick | 53df4b6 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 11239 | // Constant suitable for movw, must be between 0 and |
| 11240 | // 65535. |
| 11241 | if (Subtarget->hasV6T2Ops()) |
| 11242 | if (CVal >= 0 && CVal <= 65535) |
| 11243 | break; |
| 11244 | return; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11245 | case 'I': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11246 | if (Subtarget->isThumb1Only()) { |
| 11247 | // This must be a constant between 0 and 255, for ADD |
| 11248 | // immediates. |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11249 | if (CVal >= 0 && CVal <= 255) |
| 11250 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11251 | } else if (Subtarget->isThumb2()) { |
| 11252 | // A constant that can be used as an immediate value in a |
| 11253 | // data-processing instruction. |
| 11254 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 11255 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11256 | } else { |
| 11257 | // A constant that can be used as an immediate value in a |
| 11258 | // data-processing instruction. |
| 11259 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 11260 | break; |
| 11261 | } |
| 11262 | return; |
| 11263 | |
| 11264 | case 'J': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11265 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11266 | // This must be a constant between -255 and -1, for negated ADD |
| 11267 | // immediates. This can be used in GCC with an "n" modifier that |
| 11268 | // prints the negated value, for use with SUB instructions. It is |
| 11269 | // not useful otherwise but is implemented for compatibility. |
| 11270 | if (CVal >= -255 && CVal <= -1) |
| 11271 | break; |
| 11272 | } else { |
| 11273 | // This must be a constant between -4095 and 4095. It is not clear |
| 11274 | // what this constraint is intended for. Implemented for |
| 11275 | // compatibility with GCC. |
| 11276 | if (CVal >= -4095 && CVal <= 4095) |
| 11277 | break; |
| 11278 | } |
| 11279 | return; |
| 11280 | |
| 11281 | case 'K': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11282 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11283 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 11284 | // zero to match GCC. This constraint is used by GCC internally for |
| 11285 | // constants that can be loaded with a move/shift combination. |
| 11286 | // It is not useful otherwise but is implemented for compatibility. |
| 11287 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 11288 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11289 | } else if (Subtarget->isThumb2()) { |
| 11290 | // A constant whose bitwise inverse can be used as an immediate |
| 11291 | // value in a data-processing instruction. This can be used in GCC |
| 11292 | // with a "B" modifier that prints the inverted value, for use with |
| 11293 | // BIC and MVN instructions. It is not useful otherwise but is |
| 11294 | // implemented for compatibility. |
| 11295 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 11296 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11297 | } else { |
| 11298 | // A constant whose bitwise inverse can be used as an immediate |
| 11299 | // value in a data-processing instruction. This can be used in GCC |
| 11300 | // with a "B" modifier that prints the inverted value, for use with |
| 11301 | // BIC and MVN instructions. It is not useful otherwise but is |
| 11302 | // implemented for compatibility. |
| 11303 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 11304 | break; |
| 11305 | } |
| 11306 | return; |
| 11307 | |
| 11308 | case 'L': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11309 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11310 | // This must be a constant between -7 and 7, |
| 11311 | // for 3-operand ADD/SUB immediate instructions. |
| 11312 | if (CVal >= -7 && CVal < 7) |
| 11313 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11314 | } else if (Subtarget->isThumb2()) { |
| 11315 | // A constant whose negation can be used as an immediate value in a |
| 11316 | // data-processing instruction. This can be used in GCC with an "n" |
| 11317 | // modifier that prints the negated value, for use with SUB |
| 11318 | // instructions. It is not useful otherwise but is implemented for |
| 11319 | // compatibility. |
| 11320 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 11321 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11322 | } else { |
| 11323 | // A constant whose negation can be used as an immediate value in a |
| 11324 | // data-processing instruction. This can be used in GCC with an "n" |
| 11325 | // modifier that prints the negated value, for use with SUB |
| 11326 | // instructions. It is not useful otherwise but is implemented for |
| 11327 | // compatibility. |
| 11328 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 11329 | break; |
| 11330 | } |
| 11331 | return; |
| 11332 | |
| 11333 | case 'M': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11334 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11335 | // This must be a multiple of 4 between 0 and 1020, for |
| 11336 | // ADD sp + immediate. |
| 11337 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 11338 | break; |
| 11339 | } else { |
| 11340 | // A power of two or a constant between 0 and 32. This is used in |
| 11341 | // GCC for the shift amount on shifted register operands, but it is |
| 11342 | // useful in general for any shift amounts. |
| 11343 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 11344 | break; |
| 11345 | } |
| 11346 | return; |
| 11347 | |
| 11348 | case 'N': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11349 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11350 | // This must be a constant between 0 and 31, for shift amounts. |
| 11351 | if (CVal >= 0 && CVal <= 31) |
| 11352 | break; |
| 11353 | } |
| 11354 | return; |
| 11355 | |
| 11356 | case 'O': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11357 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11358 | // This must be a multiple of 4 between -508 and 508, for |
| 11359 | // ADD/SUB sp = sp + immediate. |
| 11360 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 11361 | break; |
| 11362 | } |
| 11363 | return; |
| 11364 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11365 | Result = DAG.getTargetConstant(CVal, SDLoc(Op), Op.getValueType()); |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11366 | break; |
| 11367 | } |
| 11368 | |
| 11369 | if (Result.getNode()) { |
| 11370 | Ops.push_back(Result); |
| 11371 | return; |
| 11372 | } |
| Dale Johannesen | ce97d55 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 11373 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11374 | } |
| Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 11375 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11376 | static RTLIB::Libcall getDivRemLibcall( |
| 11377 | const SDNode *N, MVT::SimpleValueType SVT) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11378 | assert((N->getOpcode() == ISD::SDIVREM || N->getOpcode() == ISD::UDIVREM || |
| 11379 | N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM) && |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11380 | "Unhandled Opcode in getDivRemLibcall"); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11381 | bool isSigned = N->getOpcode() == ISD::SDIVREM || |
| 11382 | N->getOpcode() == ISD::SREM; |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11383 | RTLIB::Libcall LC; |
| 11384 | switch (SVT) { |
| 11385 | default: llvm_unreachable("Unexpected request for libcall!"); |
| 11386 | case MVT::i8: LC = isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8; break; |
| 11387 | case MVT::i16: LC = isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16; break; |
| 11388 | case MVT::i32: LC = isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32; break; |
| 11389 | case MVT::i64: LC = isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64; break; |
| 11390 | } |
| 11391 | return LC; |
| 11392 | } |
| 11393 | |
| 11394 | static TargetLowering::ArgListTy getDivRemArgList( |
| 11395 | const SDNode *N, LLVMContext *Context) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11396 | assert((N->getOpcode() == ISD::SDIVREM || N->getOpcode() == ISD::UDIVREM || |
| 11397 | N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM) && |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11398 | "Unhandled Opcode in getDivRemArgList"); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11399 | bool isSigned = N->getOpcode() == ISD::SDIVREM || |
| 11400 | N->getOpcode() == ISD::SREM; |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11401 | TargetLowering::ArgListTy Args; |
| 11402 | TargetLowering::ArgListEntry Entry; |
| 11403 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 11404 | EVT ArgVT = N->getOperand(i).getValueType(); |
| 11405 | Type *ArgTy = ArgVT.getTypeForEVT(*Context); |
| 11406 | Entry.Node = N->getOperand(i); |
| 11407 | Entry.Ty = ArgTy; |
| 11408 | Entry.isSExt = isSigned; |
| 11409 | Entry.isZExt = !isSigned; |
| 11410 | Args.push_back(Entry); |
| 11411 | } |
| 11412 | return Args; |
| 11413 | } |
| 11414 | |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11415 | SDValue ARMTargetLowering::LowerDivRem(SDValue Op, SelectionDAG &DAG) const { |
| Sumanth Gundapaneni | 532a136 | 2015-07-31 00:45:12 +0000 | [diff] [blame] | 11416 | assert((Subtarget->isTargetAEABI() || Subtarget->isTargetAndroid()) && |
| 11417 | "Register-based DivRem lowering only"); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11418 | unsigned Opcode = Op->getOpcode(); |
| 11419 | assert((Opcode == ISD::SDIVREM || Opcode == ISD::UDIVREM) && |
| Saleem Abdulrasool | 740be89 | 2014-08-17 22:50:59 +0000 | [diff] [blame] | 11420 | "Invalid opcode for Div/Rem lowering"); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11421 | bool isSigned = (Opcode == ISD::SDIVREM); |
| 11422 | EVT VT = Op->getValueType(0); |
| 11423 | Type *Ty = VT.getTypeForEVT(*DAG.getContext()); |
| 11424 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11425 | RTLIB::Libcall LC = getDivRemLibcall(Op.getNode(), |
| 11426 | VT.getSimpleVT().SimpleTy); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11427 | SDValue InChain = DAG.getEntryNode(); |
| 11428 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11429 | TargetLowering::ArgListTy Args = getDivRemArgList(Op.getNode(), |
| 11430 | DAG.getContext()); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11431 | |
| 11432 | SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11433 | getPointerTy(DAG.getDataLayout())); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11434 | |
| Reid Kleckner | 343c395 | 2014-11-20 23:51:47 +0000 | [diff] [blame] | 11435 | Type *RetTy = (Type*)StructType::get(Ty, Ty, nullptr); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11436 | |
| 11437 | SDLoc dl(Op); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11438 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 11439 | CLI.setDebugLoc(dl).setChain(InChain) |
| Juergen Ributzka | 3bd03c7 | 2014-07-01 22:01:54 +0000 | [diff] [blame] | 11440 | .setCallee(getLibcallCallingConv(LC), RetTy, Callee, std::move(Args), 0) |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11441 | .setInRegister().setSExtResult(isSigned).setZExtResult(!isSigned); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11442 | |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11443 | std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11444 | return CallInfo.first; |
| 11445 | } |
| 11446 | |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11447 | // Lowers REM using divmod helpers |
| 11448 | // see RTABI section 4.2/4.3 |
| 11449 | SDValue ARMTargetLowering::LowerREM(SDNode *N, SelectionDAG &DAG) const { |
| 11450 | // Build return types (div and rem) |
| 11451 | std::vector<Type*> RetTyParams; |
| 11452 | Type *RetTyElement; |
| 11453 | |
| 11454 | switch (N->getValueType(0).getSimpleVT().SimpleTy) { |
| 11455 | default: llvm_unreachable("Unexpected request for libcall!"); |
| 11456 | case MVT::i8: RetTyElement = Type::getInt8Ty(*DAG.getContext()); break; |
| 11457 | case MVT::i16: RetTyElement = Type::getInt16Ty(*DAG.getContext()); break; |
| 11458 | case MVT::i32: RetTyElement = Type::getInt32Ty(*DAG.getContext()); break; |
| 11459 | case MVT::i64: RetTyElement = Type::getInt64Ty(*DAG.getContext()); break; |
| 11460 | } |
| 11461 | |
| 11462 | RetTyParams.push_back(RetTyElement); |
| 11463 | RetTyParams.push_back(RetTyElement); |
| 11464 | ArrayRef<Type*> ret = ArrayRef<Type*>(RetTyParams); |
| 11465 | Type *RetTy = StructType::get(*DAG.getContext(), ret); |
| 11466 | |
| 11467 | RTLIB::Libcall LC = getDivRemLibcall(N, N->getValueType(0).getSimpleVT(). |
| 11468 | SimpleTy); |
| 11469 | SDValue InChain = DAG.getEntryNode(); |
| 11470 | TargetLowering::ArgListTy Args = getDivRemArgList(N, DAG.getContext()); |
| 11471 | bool isSigned = N->getOpcode() == ISD::SREM; |
| 11472 | SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), |
| 11473 | getPointerTy(DAG.getDataLayout())); |
| 11474 | |
| 11475 | // Lower call |
| 11476 | CallLoweringInfo CLI(DAG); |
| 11477 | CLI.setChain(InChain) |
| 11478 | .setCallee(CallingConv::ARM_AAPCS, RetTy, Callee, std::move(Args), 0) |
| 11479 | .setSExtResult(isSigned).setZExtResult(!isSigned).setDebugLoc(SDLoc(N)); |
| 11480 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| 11481 | |
| 11482 | // Return second (rem) result operand (first contains div) |
| 11483 | SDNode *ResNode = CallResult.first.getNode(); |
| 11484 | assert(ResNode->getNumOperands() == 2 && "divmod should return two operands"); |
| 11485 | return ResNode->getOperand(1); |
| 11486 | } |
| 11487 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11488 | SDValue |
| 11489 | ARMTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const { |
| 11490 | assert(Subtarget->isTargetWindows() && "unsupported target platform"); |
| 11491 | SDLoc DL(Op); |
| 11492 | |
| 11493 | // Get the inputs. |
| 11494 | SDValue Chain = Op.getOperand(0); |
| 11495 | SDValue Size = Op.getOperand(1); |
| 11496 | |
| 11497 | SDValue Words = DAG.getNode(ISD::SRL, DL, MVT::i32, Size, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11498 | DAG.getConstant(2, DL, MVT::i32)); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11499 | |
| 11500 | SDValue Flag; |
| 11501 | Chain = DAG.getCopyToReg(Chain, DL, ARM::R4, Words, Flag); |
| 11502 | Flag = Chain.getValue(1); |
| 11503 | |
| Saleem Abdulrasool | c4e0028 | 2014-07-19 01:29:51 +0000 | [diff] [blame] | 11504 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11505 | Chain = DAG.getNode(ARMISD::WIN__CHKSTK, DL, NodeTys, Chain, Flag); |
| 11506 | |
| 11507 | SDValue NewSP = DAG.getCopyFromReg(Chain, DL, ARM::SP, MVT::i32); |
| 11508 | Chain = NewSP.getValue(1); |
| 11509 | |
| 11510 | SDValue Ops[2] = { NewSP, Chain }; |
| 11511 | return DAG.getMergeValues(Ops, DL); |
| 11512 | } |
| 11513 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11514 | SDValue ARMTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const { |
| 11515 | assert(Op.getValueType() == MVT::f64 && Subtarget->isFPOnlySP() && |
| 11516 | "Unexpected type for custom-lowering FP_EXTEND"); |
| 11517 | |
| 11518 | RTLIB::Libcall LC; |
| 11519 | LC = RTLIB::getFPEXT(Op.getOperand(0).getValueType(), Op.getValueType()); |
| 11520 | |
| 11521 | SDValue SrcVal = Op.getOperand(0); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 11522 | return makeLibCall(DAG, LC, Op.getValueType(), SrcVal, /*isSigned*/ false, |
| 11523 | SDLoc(Op)).first; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11524 | } |
| 11525 | |
| 11526 | SDValue ARMTargetLowering::LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const { |
| 11527 | assert(Op.getOperand(0).getValueType() == MVT::f64 && |
| 11528 | Subtarget->isFPOnlySP() && |
| 11529 | "Unexpected type for custom-lowering FP_ROUND"); |
| 11530 | |
| 11531 | RTLIB::Libcall LC; |
| 11532 | LC = RTLIB::getFPROUND(Op.getOperand(0).getValueType(), Op.getValueType()); |
| 11533 | |
| 11534 | SDValue SrcVal = Op.getOperand(0); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 11535 | return makeLibCall(DAG, LC, Op.getValueType(), SrcVal, /*isSigned*/ false, |
| 11536 | SDLoc(Op)).first; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11537 | } |
| 11538 | |
| Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 11539 | bool |
| 11540 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 11541 | // The ARM target isn't yet aware of offsets. |
| 11542 | return false; |
| 11543 | } |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11544 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11545 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 11546 | if (v == 0xffffffff) |
| Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 11547 | return false; |
| 11548 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11549 | // there can be 1's on either or both "outsides", all the "inside" |
| 11550 | // bits must be 0's |
| Benjamin Kramer | 5f6a907 | 2015-02-12 15:35:40 +0000 | [diff] [blame] | 11551 | return isShiftedMask_32(~v); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11552 | } |
| 11553 | |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11554 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 11555 | /// specified FP immediate natively. If false, the legalizer will |
| 11556 | /// materialize the FP immediate as a load from a constant pool. |
| 11557 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 11558 | if (!Subtarget->hasVFP3()) |
| 11559 | return false; |
| 11560 | if (VT == MVT::f32) |
| Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 11561 | return ARM_AM::getFP32Imm(Imm) != -1; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11562 | if (VT == MVT::f64 && !Subtarget->isFPOnlySP()) |
| Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 11563 | return ARM_AM::getFP64Imm(Imm) != -1; |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11564 | return false; |
| 11565 | } |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11566 | |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 11567 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11568 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 11569 | /// specified in the intrinsic calls. |
| 11570 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 11571 | const CallInst &I, |
| 11572 | unsigned Intrinsic) const { |
| 11573 | switch (Intrinsic) { |
| 11574 | case Intrinsic::arm_neon_vld1: |
| 11575 | case Intrinsic::arm_neon_vld2: |
| 11576 | case Intrinsic::arm_neon_vld3: |
| 11577 | case Intrinsic::arm_neon_vld4: |
| 11578 | case Intrinsic::arm_neon_vld2lane: |
| 11579 | case Intrinsic::arm_neon_vld3lane: |
| 11580 | case Intrinsic::arm_neon_vld4lane: { |
| 11581 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11582 | // Conservatively set memVT to the entire set of vectors loaded. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11583 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| 11584 | uint64_t NumElts = DL.getTypeAllocSize(I.getType()) / 8; |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11585 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 11586 | Info.ptrVal = I.getArgOperand(0); |
| 11587 | Info.offset = 0; |
| 11588 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 11589 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 11590 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 11591 | Info.readMem = true; |
| 11592 | Info.writeMem = false; |
| 11593 | return true; |
| 11594 | } |
| 11595 | case Intrinsic::arm_neon_vst1: |
| 11596 | case Intrinsic::arm_neon_vst2: |
| 11597 | case Intrinsic::arm_neon_vst3: |
| 11598 | case Intrinsic::arm_neon_vst4: |
| 11599 | case Intrinsic::arm_neon_vst2lane: |
| 11600 | case Intrinsic::arm_neon_vst3lane: |
| 11601 | case Intrinsic::arm_neon_vst4lane: { |
| 11602 | Info.opc = ISD::INTRINSIC_VOID; |
| 11603 | // Conservatively set memVT to the entire set of vectors stored. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11604 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11605 | unsigned NumElts = 0; |
| 11606 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11607 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11608 | if (!ArgTy->isVectorTy()) |
| 11609 | break; |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11610 | NumElts += DL.getTypeAllocSize(ArgTy) / 8; |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11611 | } |
| 11612 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 11613 | Info.ptrVal = I.getArgOperand(0); |
| 11614 | Info.offset = 0; |
| 11615 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 11616 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 11617 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 11618 | Info.readMem = false; |
| 11619 | Info.writeMem = true; |
| 11620 | return true; |
| 11621 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11622 | case Intrinsic::arm_ldaex: |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11623 | case Intrinsic::arm_ldrex: { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11624 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11625 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(0)->getType()); |
| 11626 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11627 | Info.memVT = MVT::getVT(PtrTy->getElementType()); |
| 11628 | Info.ptrVal = I.getArgOperand(0); |
| 11629 | Info.offset = 0; |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11630 | Info.align = DL.getABITypeAlignment(PtrTy->getElementType()); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11631 | Info.vol = true; |
| 11632 | Info.readMem = true; |
| 11633 | Info.writeMem = false; |
| 11634 | return true; |
| 11635 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11636 | case Intrinsic::arm_stlex: |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11637 | case Intrinsic::arm_strex: { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11638 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11639 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(1)->getType()); |
| 11640 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11641 | Info.memVT = MVT::getVT(PtrTy->getElementType()); |
| 11642 | Info.ptrVal = I.getArgOperand(1); |
| 11643 | Info.offset = 0; |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11644 | Info.align = DL.getABITypeAlignment(PtrTy->getElementType()); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11645 | Info.vol = true; |
| 11646 | Info.readMem = false; |
| 11647 | Info.writeMem = true; |
| 11648 | return true; |
| 11649 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11650 | case Intrinsic::arm_stlexd: |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11651 | case Intrinsic::arm_strexd: { |
| 11652 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11653 | Info.memVT = MVT::i64; |
| 11654 | Info.ptrVal = I.getArgOperand(2); |
| 11655 | Info.offset = 0; |
| 11656 | Info.align = 8; |
| Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 11657 | Info.vol = true; |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11658 | Info.readMem = false; |
| 11659 | Info.writeMem = true; |
| 11660 | return true; |
| 11661 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11662 | case Intrinsic::arm_ldaexd: |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11663 | case Intrinsic::arm_ldrexd: { |
| 11664 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11665 | Info.memVT = MVT::i64; |
| 11666 | Info.ptrVal = I.getArgOperand(0); |
| 11667 | Info.offset = 0; |
| 11668 | Info.align = 8; |
| Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 11669 | Info.vol = true; |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11670 | Info.readMem = true; |
| 11671 | Info.writeMem = false; |
| 11672 | return true; |
| 11673 | } |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11674 | default: |
| 11675 | break; |
| 11676 | } |
| 11677 | |
| 11678 | return false; |
| 11679 | } |
| Juergen Ributzka | 659ce00 | 2014-01-28 01:20:14 +0000 | [diff] [blame] | 11680 | |
| 11681 | /// \brief Returns true if it is beneficial to convert a load of a constant |
| 11682 | /// to just the constant itself. |
| 11683 | bool ARMTargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm, |
| 11684 | Type *Ty) const { |
| 11685 | assert(Ty->isIntegerTy()); |
| 11686 | |
| 11687 | unsigned Bits = Ty->getPrimitiveSizeInBits(); |
| 11688 | if (Bits == 0 || Bits > 32) |
| 11689 | return false; |
| 11690 | return true; |
| 11691 | } |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11692 | |
| Robin Morisset | 5349e8e | 2014-09-18 18:56:04 +0000 | [diff] [blame] | 11693 | Instruction* ARMTargetLowering::makeDMB(IRBuilder<> &Builder, |
| 11694 | ARM_MB::MemBOpt Domain) const { |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11695 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| Robin Morisset | 5349e8e | 2014-09-18 18:56:04 +0000 | [diff] [blame] | 11696 | |
| 11697 | // First, if the target has no DMB, see what fallback we can use. |
| 11698 | if (!Subtarget->hasDataBarrier()) { |
| 11699 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 11700 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 11701 | // here. |
| 11702 | if (Subtarget->hasV6Ops() && !Subtarget->isThumb()) { |
| 11703 | Function *MCR = llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_mcr); |
| 11704 | Value* args[6] = {Builder.getInt32(15), Builder.getInt32(0), |
| 11705 | Builder.getInt32(0), Builder.getInt32(7), |
| 11706 | Builder.getInt32(10), Builder.getInt32(5)}; |
| 11707 | return Builder.CreateCall(MCR, args); |
| 11708 | } else { |
| 11709 | // Instead of using barriers, atomic accesses on these subtargets use |
| 11710 | // libcalls. |
| 11711 | llvm_unreachable("makeDMB on a target so old that it has no barriers"); |
| 11712 | } |
| 11713 | } else { |
| 11714 | Function *DMB = llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_dmb); |
| 11715 | // Only a full system barrier exists in the M-class architectures. |
| 11716 | Domain = Subtarget->isMClass() ? ARM_MB::SY : Domain; |
| 11717 | Constant *CDomain = Builder.getInt32(Domain); |
| 11718 | return Builder.CreateCall(DMB, CDomain); |
| 11719 | } |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11720 | } |
| 11721 | |
| 11722 | // Based on http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11723 | Instruction* ARMTargetLowering::emitLeadingFence(IRBuilder<> &Builder, |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11724 | AtomicOrdering Ord, bool IsStore, |
| 11725 | bool IsLoad) const { |
| 11726 | if (!getInsertFencesForAtomic()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11727 | return nullptr; |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11728 | |
| 11729 | switch (Ord) { |
| 11730 | case NotAtomic: |
| 11731 | case Unordered: |
| 11732 | llvm_unreachable("Invalid fence: unordered/non-atomic"); |
| 11733 | case Monotonic: |
| 11734 | case Acquire: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11735 | return nullptr; // Nothing to do |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11736 | case SequentiallyConsistent: |
| 11737 | if (!IsStore) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11738 | return nullptr; // Nothing to do |
| 11739 | /*FALLTHROUGH*/ |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11740 | case Release: |
| 11741 | case AcquireRelease: |
| 11742 | if (Subtarget->isSwift()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11743 | return makeDMB(Builder, ARM_MB::ISHST); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11744 | // FIXME: add a comment with a link to documentation justifying this. |
| 11745 | else |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11746 | return makeDMB(Builder, ARM_MB::ISH); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11747 | } |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11748 | llvm_unreachable("Unknown fence ordering in emitLeadingFence"); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11749 | } |
| 11750 | |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11751 | Instruction* ARMTargetLowering::emitTrailingFence(IRBuilder<> &Builder, |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11752 | AtomicOrdering Ord, bool IsStore, |
| 11753 | bool IsLoad) const { |
| 11754 | if (!getInsertFencesForAtomic()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11755 | return nullptr; |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11756 | |
| 11757 | switch (Ord) { |
| 11758 | case NotAtomic: |
| 11759 | case Unordered: |
| 11760 | llvm_unreachable("Invalid fence: unordered/not-atomic"); |
| 11761 | case Monotonic: |
| 11762 | case Release: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11763 | return nullptr; // Nothing to do |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11764 | case Acquire: |
| 11765 | case AcquireRelease: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11766 | case SequentiallyConsistent: |
| 11767 | return makeDMB(Builder, ARM_MB::ISH); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11768 | } |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 11769 | llvm_unreachable("Unknown fence ordering in emitTrailingFence"); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11770 | } |
| 11771 | |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 11772 | // Loads and stores less than 64-bits are already atomic; ones above that |
| 11773 | // are doomed anyway, so defer to the default libcall and blame the OS when |
| 11774 | // things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit |
| 11775 | // anything for those. |
| 11776 | bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 11777 | unsigned Size = SI->getValueOperand()->getType()->getPrimitiveSizeInBits(); |
| 11778 | return (Size == 64) && !Subtarget->isMClass(); |
| 11779 | } |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11780 | |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 11781 | // Loads and stores less than 64-bits are already atomic; ones above that |
| 11782 | // are doomed anyway, so defer to the default libcall and blame the OS when |
| 11783 | // things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit |
| 11784 | // anything for those. |
| Robin Morisset | a7b357f | 2014-09-23 18:33:21 +0000 | [diff] [blame] | 11785 | // FIXME: ldrd and strd are atomic if the CPU has LPAE (e.g. A15 has that |
| 11786 | // guarantee, see DDI0406C ARM architecture reference manual, |
| 11787 | // sections A8.8.72-74 LDRD) |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 11788 | TargetLowering::AtomicExpansionKind |
| 11789 | ARMTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 11790 | unsigned Size = LI->getType()->getPrimitiveSizeInBits(); |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 11791 | return ((Size == 64) && !Subtarget->isMClass()) ? AtomicExpansionKind::LLSC |
| 11792 | : AtomicExpansionKind::None; |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 11793 | } |
| 11794 | |
| 11795 | // For the real atomic operations, we have ldrex/strex up to 32 bits, |
| 11796 | // and up to 64 bits on the non-M profiles |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 11797 | TargetLowering::AtomicExpansionKind |
| JF Bastien | f14889e | 2015-03-04 15:47:57 +0000 | [diff] [blame] | 11798 | ARMTargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const { |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 11799 | unsigned Size = AI->getType()->getPrimitiveSizeInBits(); |
| JF Bastien | f14889e | 2015-03-04 15:47:57 +0000 | [diff] [blame] | 11800 | return (Size <= (Subtarget->isMClass() ? 32U : 64U)) |
| Ahmed Bougacha | 9d67713 | 2015-09-11 17:08:17 +0000 | [diff] [blame] | 11801 | ? AtomicExpansionKind::LLSC |
| 11802 | : AtomicExpansionKind::None; |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11803 | } |
| 11804 | |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 11805 | bool ARMTargetLowering::shouldExpandAtomicCmpXchgInIR( |
| 11806 | AtomicCmpXchgInst *AI) const { |
| 11807 | return true; |
| 11808 | } |
| 11809 | |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 11810 | // This has so far only been implemented for MachO. |
| 11811 | bool ARMTargetLowering::useLoadStackGuardNode() const { |
| Eric Christopher | 66322e8 | 2014-12-05 00:22:35 +0000 | [diff] [blame] | 11812 | return Subtarget->isTargetMachO(); |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 11813 | } |
| 11814 | |
| Quentin Colombet | c32615d | 2014-10-31 17:52:53 +0000 | [diff] [blame] | 11815 | bool ARMTargetLowering::canCombineStoreAndExtract(Type *VectorTy, Value *Idx, |
| 11816 | unsigned &Cost) const { |
| 11817 | // If we do not have NEON, vector types are not natively supported. |
| 11818 | if (!Subtarget->hasNEON()) |
| 11819 | return false; |
| 11820 | |
| 11821 | // Floating point values and vector values map to the same register file. |
| Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 11822 | // Therefore, although we could do a store extract of a vector type, this is |
| Quentin Colombet | c32615d | 2014-10-31 17:52:53 +0000 | [diff] [blame] | 11823 | // better to leave at float as we have more freedom in the addressing mode for |
| 11824 | // those. |
| 11825 | if (VectorTy->isFPOrFPVectorTy()) |
| 11826 | return false; |
| 11827 | |
| 11828 | // If the index is unknown at compile time, this is very expensive to lower |
| 11829 | // and it is not possible to combine the store with the extract. |
| 11830 | if (!isa<ConstantInt>(Idx)) |
| 11831 | return false; |
| 11832 | |
| 11833 | assert(VectorTy->isVectorTy() && "VectorTy is not a vector type"); |
| 11834 | unsigned BitWidth = cast<VectorType>(VectorTy)->getBitWidth(); |
| 11835 | // We can do a store + vector extract on any vector that fits perfectly in a D |
| 11836 | // or Q register. |
| 11837 | if (BitWidth == 64 || BitWidth == 128) { |
| 11838 | Cost = 0; |
| 11839 | return true; |
| 11840 | } |
| 11841 | return false; |
| 11842 | } |
| 11843 | |
| Sanjay Patel | af1b48b | 2015-11-10 19:24:31 +0000 | [diff] [blame] | 11844 | bool ARMTargetLowering::isCheapToSpeculateCttz() const { |
| 11845 | return Subtarget->hasV6T2Ops(); |
| 11846 | } |
| 11847 | |
| 11848 | bool ARMTargetLowering::isCheapToSpeculateCtlz() const { |
| 11849 | return Subtarget->hasV6T2Ops(); |
| 11850 | } |
| 11851 | |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11852 | Value *ARMTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 11853 | AtomicOrdering Ord) const { |
| 11854 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| 11855 | Type *ValTy = cast<PointerType>(Addr->getType())->getElementType(); |
| Robin Morisset | b155f52 | 2014-08-18 16:48:58 +0000 | [diff] [blame] | 11856 | bool IsAcquire = isAtLeastAcquire(Ord); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11857 | |
| 11858 | // Since i64 isn't legal and intrinsics don't get type-lowered, the ldrexd |
| 11859 | // intrinsic must return {i32, i32} and we have to recombine them into a |
| 11860 | // single i64 here. |
| 11861 | if (ValTy->getPrimitiveSizeInBits() == 64) { |
| 11862 | Intrinsic::ID Int = |
| 11863 | IsAcquire ? Intrinsic::arm_ldaexd : Intrinsic::arm_ldrexd; |
| 11864 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int); |
| 11865 | |
| 11866 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); |
| 11867 | Value *LoHi = Builder.CreateCall(Ldrex, Addr, "lohi"); |
| 11868 | |
| 11869 | Value *Lo = Builder.CreateExtractValue(LoHi, 0, "lo"); |
| 11870 | Value *Hi = Builder.CreateExtractValue(LoHi, 1, "hi"); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 11871 | if (!Subtarget->isLittle()) |
| 11872 | std::swap (Lo, Hi); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11873 | Lo = Builder.CreateZExt(Lo, ValTy, "lo64"); |
| 11874 | Hi = Builder.CreateZExt(Hi, ValTy, "hi64"); |
| 11875 | return Builder.CreateOr( |
| 11876 | Lo, Builder.CreateShl(Hi, ConstantInt::get(ValTy, 32)), "val64"); |
| 11877 | } |
| 11878 | |
| 11879 | Type *Tys[] = { Addr->getType() }; |
| 11880 | Intrinsic::ID Int = IsAcquire ? Intrinsic::arm_ldaex : Intrinsic::arm_ldrex; |
| 11881 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int, Tys); |
| 11882 | |
| 11883 | return Builder.CreateTruncOrBitCast( |
| 11884 | Builder.CreateCall(Ldrex, Addr), |
| 11885 | cast<PointerType>(Addr->getType())->getElementType()); |
| 11886 | } |
| 11887 | |
| Ahmed Bougacha | 81616a7 | 2015-09-22 17:22:58 +0000 | [diff] [blame] | 11888 | void ARMTargetLowering::emitAtomicCmpXchgNoStoreLLBalance( |
| 11889 | IRBuilder<> &Builder) const { |
| Ahmed Bougacha | e81610f | 2015-09-26 00:14:02 +0000 | [diff] [blame] | 11890 | if (!Subtarget->hasV7Ops()) |
| 11891 | return; |
| Ahmed Bougacha | 81616a7 | 2015-09-22 17:22:58 +0000 | [diff] [blame] | 11892 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| 11893 | Builder.CreateCall(llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_clrex)); |
| 11894 | } |
| 11895 | |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11896 | Value *ARMTargetLowering::emitStoreConditional(IRBuilder<> &Builder, Value *Val, |
| 11897 | Value *Addr, |
| 11898 | AtomicOrdering Ord) const { |
| 11899 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| Robin Morisset | b155f52 | 2014-08-18 16:48:58 +0000 | [diff] [blame] | 11900 | bool IsRelease = isAtLeastRelease(Ord); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11901 | |
| 11902 | // Since the intrinsics must have legal type, the i64 intrinsics take two |
| 11903 | // parameters: "i32, i32". We must marshal Val into the appropriate form |
| 11904 | // before the call. |
| 11905 | if (Val->getType()->getPrimitiveSizeInBits() == 64) { |
| 11906 | Intrinsic::ID Int = |
| 11907 | IsRelease ? Intrinsic::arm_stlexd : Intrinsic::arm_strexd; |
| 11908 | Function *Strex = Intrinsic::getDeclaration(M, Int); |
| 11909 | Type *Int32Ty = Type::getInt32Ty(M->getContext()); |
| 11910 | |
| 11911 | Value *Lo = Builder.CreateTrunc(Val, Int32Ty, "lo"); |
| 11912 | Value *Hi = Builder.CreateTrunc(Builder.CreateLShr(Val, 32), Int32Ty, "hi"); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 11913 | if (!Subtarget->isLittle()) |
| 11914 | std::swap (Lo, Hi); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11915 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); |
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 11916 | return Builder.CreateCall(Strex, {Lo, Hi, Addr}); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11917 | } |
| 11918 | |
| 11919 | Intrinsic::ID Int = IsRelease ? Intrinsic::arm_stlex : Intrinsic::arm_strex; |
| 11920 | Type *Tys[] = { Addr->getType() }; |
| 11921 | Function *Strex = Intrinsic::getDeclaration(M, Int, Tys); |
| 11922 | |
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 11923 | return Builder.CreateCall( |
| 11924 | Strex, {Builder.CreateZExtOrBitCast( |
| 11925 | Val, Strex->getFunctionType()->getParamType(0)), |
| 11926 | Addr}); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11927 | } |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 11928 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11929 | /// \brief Lower an interleaved load into a vldN intrinsic. |
| 11930 | /// |
| 11931 | /// E.g. Lower an interleaved load (Factor = 2): |
| 11932 | /// %wide.vec = load <8 x i32>, <8 x i32>* %ptr, align 4 |
| 11933 | /// %v0 = shuffle %wide.vec, undef, <0, 2, 4, 6> ; Extract even elements |
| 11934 | /// %v1 = shuffle %wide.vec, undef, <1, 3, 5, 7> ; Extract odd elements |
| 11935 | /// |
| 11936 | /// Into: |
| 11937 | /// %vld2 = { <4 x i32>, <4 x i32> } call llvm.arm.neon.vld2(%ptr, 4) |
| 11938 | /// %vec0 = extractelement { <4 x i32>, <4 x i32> } %vld2, i32 0 |
| 11939 | /// %vec1 = extractelement { <4 x i32>, <4 x i32> } %vld2, i32 1 |
| 11940 | bool ARMTargetLowering::lowerInterleavedLoad( |
| 11941 | LoadInst *LI, ArrayRef<ShuffleVectorInst *> Shuffles, |
| 11942 | ArrayRef<unsigned> Indices, unsigned Factor) const { |
| 11943 | assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() && |
| 11944 | "Invalid interleave factor"); |
| 11945 | assert(!Shuffles.empty() && "Empty shufflevector input"); |
| 11946 | assert(Shuffles.size() == Indices.size() && |
| 11947 | "Unmatched number of shufflevectors and indices"); |
| 11948 | |
| 11949 | VectorType *VecTy = Shuffles[0]->getType(); |
| 11950 | Type *EltTy = VecTy->getVectorElementType(); |
| 11951 | |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11952 | const DataLayout &DL = LI->getModule()->getDataLayout(); |
| 11953 | unsigned VecSize = DL.getTypeAllocSizeInBits(VecTy); |
| 11954 | bool EltIs64Bits = DL.getTypeAllocSizeInBits(EltTy) == 64; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11955 | |
| Jeroen Ketema | aebca09 | 2015-10-07 14:53:29 +0000 | [diff] [blame] | 11956 | // Skip if we do not have NEON and skip illegal vector types and vector types |
| 11957 | // with i64/f64 elements (vldN doesn't support i64/f64 elements). |
| 11958 | if (!Subtarget->hasNEON() || (VecSize != 64 && VecSize != 128) || EltIs64Bits) |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11959 | return false; |
| 11960 | |
| 11961 | // A pointer vector can not be the return type of the ldN intrinsics. Need to |
| 11962 | // load integer vectors first and then convert to pointer vectors. |
| 11963 | if (EltTy->isPointerTy()) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11964 | VecTy = |
| 11965 | VectorType::get(DL.getIntPtrType(EltTy), VecTy->getVectorNumElements()); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11966 | |
| 11967 | static const Intrinsic::ID LoadInts[3] = {Intrinsic::arm_neon_vld2, |
| 11968 | Intrinsic::arm_neon_vld3, |
| 11969 | Intrinsic::arm_neon_vld4}; |
| 11970 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11971 | IRBuilder<> Builder(LI); |
| 11972 | SmallVector<Value *, 2> Ops; |
| 11973 | |
| 11974 | Type *Int8Ptr = Builder.getInt8PtrTy(LI->getPointerAddressSpace()); |
| 11975 | Ops.push_back(Builder.CreateBitCast(LI->getPointerOperand(), Int8Ptr)); |
| 11976 | Ops.push_back(Builder.getInt32(LI->getAlignment())); |
| 11977 | |
| Jeroen Ketema | ab99b59 | 2015-09-30 10:56:37 +0000 | [diff] [blame] | 11978 | Type *Tys[] = { VecTy, Int8Ptr }; |
| 11979 | Function *VldnFunc = |
| 11980 | Intrinsic::getDeclaration(LI->getModule(), LoadInts[Factor - 2], Tys); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 11981 | CallInst *VldN = Builder.CreateCall(VldnFunc, Ops, "vldN"); |
| 11982 | |
| 11983 | // Replace uses of each shufflevector with the corresponding vector loaded |
| 11984 | // by ldN. |
| 11985 | for (unsigned i = 0; i < Shuffles.size(); i++) { |
| 11986 | ShuffleVectorInst *SV = Shuffles[i]; |
| 11987 | unsigned Index = Indices[i]; |
| 11988 | |
| 11989 | Value *SubVec = Builder.CreateExtractValue(VldN, Index); |
| 11990 | |
| 11991 | // Convert the integer vector to pointer vector if the element is pointer. |
| 11992 | if (EltTy->isPointerTy()) |
| 11993 | SubVec = Builder.CreateIntToPtr(SubVec, SV->getType()); |
| 11994 | |
| 11995 | SV->replaceAllUsesWith(SubVec); |
| 11996 | } |
| 11997 | |
| 11998 | return true; |
| 11999 | } |
| 12000 | |
| 12001 | /// \brief Get a mask consisting of sequential integers starting from \p Start. |
| 12002 | /// |
| 12003 | /// I.e. <Start, Start + 1, ..., Start + NumElts - 1> |
| 12004 | static Constant *getSequentialMask(IRBuilder<> &Builder, unsigned Start, |
| 12005 | unsigned NumElts) { |
| 12006 | SmallVector<Constant *, 16> Mask; |
| 12007 | for (unsigned i = 0; i < NumElts; i++) |
| 12008 | Mask.push_back(Builder.getInt32(Start + i)); |
| 12009 | |
| 12010 | return ConstantVector::get(Mask); |
| 12011 | } |
| 12012 | |
| 12013 | /// \brief Lower an interleaved store into a vstN intrinsic. |
| 12014 | /// |
| 12015 | /// E.g. Lower an interleaved store (Factor = 3): |
| 12016 | /// %i.vec = shuffle <8 x i32> %v0, <8 x i32> %v1, |
| 12017 | /// <0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11> |
| 12018 | /// store <12 x i32> %i.vec, <12 x i32>* %ptr, align 4 |
| 12019 | /// |
| 12020 | /// Into: |
| 12021 | /// %sub.v0 = shuffle <8 x i32> %v0, <8 x i32> v1, <0, 1, 2, 3> |
| 12022 | /// %sub.v1 = shuffle <8 x i32> %v0, <8 x i32> v1, <4, 5, 6, 7> |
| 12023 | /// %sub.v2 = shuffle <8 x i32> %v0, <8 x i32> v1, <8, 9, 10, 11> |
| 12024 | /// call void llvm.arm.neon.vst3(%ptr, %sub.v0, %sub.v1, %sub.v2, 4) |
| 12025 | /// |
| 12026 | /// Note that the new shufflevectors will be removed and we'll only generate one |
| 12027 | /// vst3 instruction in CodeGen. |
| 12028 | bool ARMTargetLowering::lowerInterleavedStore(StoreInst *SI, |
| 12029 | ShuffleVectorInst *SVI, |
| 12030 | unsigned Factor) const { |
| 12031 | assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() && |
| 12032 | "Invalid interleave factor"); |
| 12033 | |
| 12034 | VectorType *VecTy = SVI->getType(); |
| 12035 | assert(VecTy->getVectorNumElements() % Factor == 0 && |
| 12036 | "Invalid interleaved store"); |
| 12037 | |
| 12038 | unsigned NumSubElts = VecTy->getVectorNumElements() / Factor; |
| 12039 | Type *EltTy = VecTy->getVectorElementType(); |
| 12040 | VectorType *SubVecTy = VectorType::get(EltTy, NumSubElts); |
| 12041 | |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12042 | const DataLayout &DL = SI->getModule()->getDataLayout(); |
| 12043 | unsigned SubVecSize = DL.getTypeAllocSizeInBits(SubVecTy); |
| 12044 | bool EltIs64Bits = DL.getTypeAllocSizeInBits(EltTy) == 64; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12045 | |
| Jeroen Ketema | aebca09 | 2015-10-07 14:53:29 +0000 | [diff] [blame] | 12046 | // Skip if we do not have NEON and skip illegal vector types and vector types |
| 12047 | // with i64/f64 elements (vstN doesn't support i64/f64 elements). |
| 12048 | if (!Subtarget->hasNEON() || (SubVecSize != 64 && SubVecSize != 128) || |
| 12049 | EltIs64Bits) |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12050 | return false; |
| 12051 | |
| 12052 | Value *Op0 = SVI->getOperand(0); |
| 12053 | Value *Op1 = SVI->getOperand(1); |
| 12054 | IRBuilder<> Builder(SI); |
| 12055 | |
| 12056 | // StN intrinsics don't support pointer vectors as arguments. Convert pointer |
| 12057 | // vectors to integer vectors. |
| 12058 | if (EltTy->isPointerTy()) { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12059 | Type *IntTy = DL.getIntPtrType(EltTy); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12060 | |
| 12061 | // Convert to the corresponding integer vector. |
| 12062 | Type *IntVecTy = |
| 12063 | VectorType::get(IntTy, Op0->getType()->getVectorNumElements()); |
| 12064 | Op0 = Builder.CreatePtrToInt(Op0, IntVecTy); |
| 12065 | Op1 = Builder.CreatePtrToInt(Op1, IntVecTy); |
| 12066 | |
| 12067 | SubVecTy = VectorType::get(IntTy, NumSubElts); |
| 12068 | } |
| 12069 | |
| Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 12070 | static const Intrinsic::ID StoreInts[3] = {Intrinsic::arm_neon_vst2, |
| 12071 | Intrinsic::arm_neon_vst3, |
| 12072 | Intrinsic::arm_neon_vst4}; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12073 | SmallVector<Value *, 6> Ops; |
| 12074 | |
| 12075 | Type *Int8Ptr = Builder.getInt8PtrTy(SI->getPointerAddressSpace()); |
| 12076 | Ops.push_back(Builder.CreateBitCast(SI->getPointerOperand(), Int8Ptr)); |
| 12077 | |
| Jeroen Ketema | ab99b59 | 2015-09-30 10:56:37 +0000 | [diff] [blame] | 12078 | Type *Tys[] = { Int8Ptr, SubVecTy }; |
| 12079 | Function *VstNFunc = Intrinsic::getDeclaration( |
| 12080 | SI->getModule(), StoreInts[Factor - 2], Tys); |
| 12081 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12082 | // Split the shufflevector operands into sub vectors for the new vstN call. |
| 12083 | for (unsigned i = 0; i < Factor; i++) |
| 12084 | Ops.push_back(Builder.CreateShuffleVector( |
| 12085 | Op0, Op1, getSequentialMask(Builder, NumSubElts * i, NumSubElts))); |
| 12086 | |
| 12087 | Ops.push_back(Builder.getInt32(SI->getAlignment())); |
| 12088 | Builder.CreateCall(VstNFunc, Ops); |
| 12089 | return true; |
| 12090 | } |
| 12091 | |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12092 | enum HABaseType { |
| 12093 | HA_UNKNOWN = 0, |
| 12094 | HA_FLOAT, |
| 12095 | HA_DOUBLE, |
| 12096 | HA_VECT64, |
| 12097 | HA_VECT128 |
| 12098 | }; |
| 12099 | |
| 12100 | static bool isHomogeneousAggregate(Type *Ty, HABaseType &Base, |
| 12101 | uint64_t &Members) { |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12102 | if (auto *ST = dyn_cast<StructType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12103 | for (unsigned i = 0; i < ST->getNumElements(); ++i) { |
| 12104 | uint64_t SubMembers = 0; |
| 12105 | if (!isHomogeneousAggregate(ST->getElementType(i), Base, SubMembers)) |
| 12106 | return false; |
| 12107 | Members += SubMembers; |
| 12108 | } |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12109 | } else if (auto *AT = dyn_cast<ArrayType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12110 | uint64_t SubMembers = 0; |
| 12111 | if (!isHomogeneousAggregate(AT->getElementType(), Base, SubMembers)) |
| 12112 | return false; |
| 12113 | Members += SubMembers * AT->getNumElements(); |
| 12114 | } else if (Ty->isFloatTy()) { |
| 12115 | if (Base != HA_UNKNOWN && Base != HA_FLOAT) |
| 12116 | return false; |
| 12117 | Members = 1; |
| 12118 | Base = HA_FLOAT; |
| 12119 | } else if (Ty->isDoubleTy()) { |
| 12120 | if (Base != HA_UNKNOWN && Base != HA_DOUBLE) |
| 12121 | return false; |
| 12122 | Members = 1; |
| 12123 | Base = HA_DOUBLE; |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12124 | } else if (auto *VT = dyn_cast<VectorType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12125 | Members = 1; |
| 12126 | switch (Base) { |
| 12127 | case HA_FLOAT: |
| 12128 | case HA_DOUBLE: |
| 12129 | return false; |
| 12130 | case HA_VECT64: |
| 12131 | return VT->getBitWidth() == 64; |
| 12132 | case HA_VECT128: |
| 12133 | return VT->getBitWidth() == 128; |
| 12134 | case HA_UNKNOWN: |
| 12135 | switch (VT->getBitWidth()) { |
| 12136 | case 64: |
| 12137 | Base = HA_VECT64; |
| 12138 | return true; |
| 12139 | case 128: |
| 12140 | Base = HA_VECT128; |
| 12141 | return true; |
| 12142 | default: |
| 12143 | return false; |
| 12144 | } |
| 12145 | } |
| 12146 | } |
| 12147 | |
| 12148 | return (Members > 0 && Members <= 4); |
| 12149 | } |
| 12150 | |
| Tim Northover | e95c5b3 | 2015-02-24 17:22:34 +0000 | [diff] [blame] | 12151 | /// \brief Return true if a type is an AAPCS-VFP homogeneous aggregate or one of |
| 12152 | /// [N x i32] or [N x i64]. This allows front-ends to skip emitting padding when |
| 12153 | /// passing according to AAPCS rules. |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12154 | bool ARMTargetLowering::functionArgumentNeedsConsecutiveRegisters( |
| 12155 | Type *Ty, CallingConv::ID CallConv, bool isVarArg) const { |
| Tim Northover | 4f1909f | 2014-05-27 10:43:38 +0000 | [diff] [blame] | 12156 | if (getEffectiveCallingConv(CallConv, isVarArg) != |
| 12157 | CallingConv::ARM_AAPCS_VFP) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12158 | return false; |
| Tim Northover | 4f1909f | 2014-05-27 10:43:38 +0000 | [diff] [blame] | 12159 | |
| 12160 | HABaseType Base = HA_UNKNOWN; |
| 12161 | uint64_t Members = 0; |
| Tim Northover | e95c5b3 | 2015-02-24 17:22:34 +0000 | [diff] [blame] | 12162 | bool IsHA = isHomogeneousAggregate(Ty, Base, Members); |
| 12163 | DEBUG(dbgs() << "isHA: " << IsHA << " "; Ty->dump()); |
| 12164 | |
| 12165 | bool IsIntArray = Ty->isArrayTy() && Ty->getArrayElementType()->isIntegerTy(); |
| 12166 | return IsHA || IsIntArray; |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12167 | } |
| Joseph Tremoulet | f748c89 | 2015-11-07 01:11:31 +0000 | [diff] [blame] | 12168 | |
| 12169 | unsigned ARMTargetLowering::getExceptionPointerRegister( |
| 12170 | const Constant *PersonalityFn) const { |
| 12171 | // Platforms which do not use SjLj EH may return values in these registers |
| 12172 | // via the personality function. |
| 12173 | return Subtarget->useSjLjEH() ? ARM::NoRegister : ARM::R0; |
| 12174 | } |
| 12175 | |
| 12176 | unsigned ARMTargetLowering::getExceptionSelectorRegister( |
| 12177 | const Constant *PersonalityFn) const { |
| 12178 | // Platforms which do not use SjLj EH may return values in these registers |
| 12179 | // via the personality function. |
| 12180 | return Subtarget->useSjLjEH() ? ARM::NoRegister : ARM::R1; |
| 12181 | } |