| 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 | |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 146 | if (!VT.isFloatingPoint() && |
| 147 | VT != MVT::v2i64 && VT != MVT::v1i64) |
| 148 | for (unsigned Opcode : {ISD::SMIN, ISD::SMAX, ISD::UMIN, ISD::UMAX}) |
| 149 | setOperationAction(Opcode, VT, Legal); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 150 | } |
| 151 | |
| Craig Topper | 4fa625f | 2012-08-12 03:16:37 +0000 | [diff] [blame] | 152 | void ARMTargetLowering::addDRTypeForNEON(MVT VT) { |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 153 | addRegisterClass(VT, &ARM::DPRRegClass); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 154 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
| 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::addQRTypeForNEON(MVT VT) { |
| Jakob Stoklund Olesen | 2091206 | 2014-01-14 06:18:34 +0000 | [diff] [blame] | 158 | addRegisterClass(VT, &ARM::DPairRegClass); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 159 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 160 | } |
| 161 | |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 162 | ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM, |
| 163 | const ARMSubtarget &STI) |
| 164 | : TargetLowering(TM), Subtarget(&STI) { |
| 165 | RegInfo = Subtarget->getRegisterInfo(); |
| 166 | Itins = Subtarget->getInstrItineraryData(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 167 | |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 168 | setBooleanVectorContents(ZeroOrNegativeOneBooleanContent); |
| 169 | |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 170 | if (Subtarget->isTargetMachO()) { |
| Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 171 | // Uses VFP for Thumb libfuncs if available. |
| Jim Grosbach | 1d1d6d4 | 2013-10-24 23:07:11 +0000 | [diff] [blame] | 172 | if (Subtarget->isThumb() && Subtarget->hasVFP2() && |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 173 | Subtarget->hasARMOps() && !Subtarget->useSoftFloat()) { |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 174 | static const struct { |
| 175 | const RTLIB::Libcall Op; |
| 176 | const char * const Name; |
| 177 | const ISD::CondCode Cond; |
| 178 | } LibraryCalls[] = { |
| 179 | // Single-precision floating-point arithmetic. |
| 180 | { RTLIB::ADD_F32, "__addsf3vfp", ISD::SETCC_INVALID }, |
| 181 | { RTLIB::SUB_F32, "__subsf3vfp", ISD::SETCC_INVALID }, |
| 182 | { RTLIB::MUL_F32, "__mulsf3vfp", ISD::SETCC_INVALID }, |
| 183 | { RTLIB::DIV_F32, "__divsf3vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 184 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 185 | // Double-precision floating-point arithmetic. |
| 186 | { RTLIB::ADD_F64, "__adddf3vfp", ISD::SETCC_INVALID }, |
| 187 | { RTLIB::SUB_F64, "__subdf3vfp", ISD::SETCC_INVALID }, |
| 188 | { RTLIB::MUL_F64, "__muldf3vfp", ISD::SETCC_INVALID }, |
| 189 | { RTLIB::DIV_F64, "__divdf3vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 190 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 191 | // Single-precision comparisons. |
| 192 | { RTLIB::OEQ_F32, "__eqsf2vfp", ISD::SETNE }, |
| 193 | { RTLIB::UNE_F32, "__nesf2vfp", ISD::SETNE }, |
| 194 | { RTLIB::OLT_F32, "__ltsf2vfp", ISD::SETNE }, |
| 195 | { RTLIB::OLE_F32, "__lesf2vfp", ISD::SETNE }, |
| 196 | { RTLIB::OGE_F32, "__gesf2vfp", ISD::SETNE }, |
| 197 | { RTLIB::OGT_F32, "__gtsf2vfp", ISD::SETNE }, |
| 198 | { RTLIB::UO_F32, "__unordsf2vfp", ISD::SETNE }, |
| 199 | { RTLIB::O_F32, "__unordsf2vfp", ISD::SETEQ }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 200 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 201 | // Double-precision comparisons. |
| 202 | { RTLIB::OEQ_F64, "__eqdf2vfp", ISD::SETNE }, |
| 203 | { RTLIB::UNE_F64, "__nedf2vfp", ISD::SETNE }, |
| 204 | { RTLIB::OLT_F64, "__ltdf2vfp", ISD::SETNE }, |
| 205 | { RTLIB::OLE_F64, "__ledf2vfp", ISD::SETNE }, |
| 206 | { RTLIB::OGE_F64, "__gedf2vfp", ISD::SETNE }, |
| 207 | { RTLIB::OGT_F64, "__gtdf2vfp", ISD::SETNE }, |
| 208 | { RTLIB::UO_F64, "__unorddf2vfp", ISD::SETNE }, |
| 209 | { RTLIB::O_F64, "__unorddf2vfp", ISD::SETEQ }, |
| Evan Cheng | 143576d | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 210 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 211 | // Floating-point to integer conversions. |
| 212 | // i64 conversions are done via library routines even when generating VFP |
| 213 | // instructions, so use the same ones. |
| 214 | { RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp", ISD::SETCC_INVALID }, |
| 215 | { RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp", ISD::SETCC_INVALID }, |
| 216 | { RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp", ISD::SETCC_INVALID }, |
| 217 | { RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 218 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 219 | // Conversions between floating types. |
| 220 | { RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp", ISD::SETCC_INVALID }, |
| 221 | { RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp", ISD::SETCC_INVALID }, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 222 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 223 | // Integer to floating-point conversions. |
| 224 | // i64 conversions are done via library routines even when generating VFP |
| 225 | // instructions, so use the same ones. |
| 226 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 227 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
| 228 | { RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp", ISD::SETCC_INVALID }, |
| 229 | { RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp", ISD::SETCC_INVALID }, |
| 230 | { RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp", ISD::SETCC_INVALID }, |
| 231 | { RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp", ISD::SETCC_INVALID }, |
| 232 | }; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 233 | |
| Saleem Abdulrasool | 67697a7 | 2015-08-04 03:57:52 +0000 | [diff] [blame] | 234 | for (const auto &LC : LibraryCalls) { |
| 235 | setLibcallName(LC.Op, LC.Name); |
| 236 | if (LC.Cond != ISD::SETCC_INVALID) |
| 237 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 238 | } |
| Evan Cheng | c9f22fd1 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 239 | } |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 240 | |
| 241 | // Set the correct calling convention for ARMv7k WatchOS. It's just |
| 242 | // AAPCS_VFP for functions as simple as libcalls. |
| Tim Northover | 042a6c1 | 2016-01-27 19:32:29 +0000 | [diff] [blame] | 243 | if (Subtarget->isTargetWatchABI()) { |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 244 | for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) |
| 245 | setLibcallCallingConv((RTLIB::Libcall)i, CallingConv::ARM_AAPCS_VFP); |
| 246 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 249 | // These libcalls are not available in 32-bit. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 250 | setLibcallName(RTLIB::SHL_I128, nullptr); |
| 251 | setLibcallName(RTLIB::SRL_I128, nullptr); |
| 252 | setLibcallName(RTLIB::SRA_I128, nullptr); |
| Bob Wilson | ccbc17b | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 253 | |
| Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 254 | // RTLIB |
| 255 | if (Subtarget->isAAPCS_ABI() && |
| 256 | (Subtarget->isTargetAEABI() || Subtarget->isTargetGNUAEABI() || |
| 257 | Subtarget->isTargetAndroid())) { |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 258 | static const struct { |
| 259 | const RTLIB::Libcall Op; |
| 260 | const char * const Name; |
| 261 | const CallingConv::ID CC; |
| 262 | const ISD::CondCode Cond; |
| 263 | } LibraryCalls[] = { |
| 264 | // Double-precision floating-point arithmetic helper functions |
| 265 | // RTABI chapter 4.1.2, Table 2 |
| 266 | { RTLIB::ADD_F64, "__aeabi_dadd", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 267 | { RTLIB::DIV_F64, "__aeabi_ddiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 268 | { RTLIB::MUL_F64, "__aeabi_dmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 269 | { RTLIB::SUB_F64, "__aeabi_dsub", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 270 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 271 | // Double-precision floating-point comparison helper functions |
| 272 | // RTABI chapter 4.1.2, Table 3 |
| 273 | { RTLIB::OEQ_F64, "__aeabi_dcmpeq", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 274 | { RTLIB::UNE_F64, "__aeabi_dcmpeq", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| 275 | { RTLIB::OLT_F64, "__aeabi_dcmplt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 276 | { RTLIB::OLE_F64, "__aeabi_dcmple", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 277 | { RTLIB::OGE_F64, "__aeabi_dcmpge", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 278 | { RTLIB::OGT_F64, "__aeabi_dcmpgt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 279 | { RTLIB::UO_F64, "__aeabi_dcmpun", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 280 | { RTLIB::O_F64, "__aeabi_dcmpun", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 281 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 282 | // Single-precision floating-point arithmetic helper functions |
| 283 | // RTABI chapter 4.1.2, Table 4 |
| 284 | { RTLIB::ADD_F32, "__aeabi_fadd", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 285 | { RTLIB::DIV_F32, "__aeabi_fdiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 286 | { RTLIB::MUL_F32, "__aeabi_fmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 287 | { RTLIB::SUB_F32, "__aeabi_fsub", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 288 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 289 | // Single-precision floating-point comparison helper functions |
| 290 | // RTABI chapter 4.1.2, Table 5 |
| 291 | { RTLIB::OEQ_F32, "__aeabi_fcmpeq", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 292 | { RTLIB::UNE_F32, "__aeabi_fcmpeq", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| 293 | { RTLIB::OLT_F32, "__aeabi_fcmplt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 294 | { RTLIB::OLE_F32, "__aeabi_fcmple", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 295 | { RTLIB::OGE_F32, "__aeabi_fcmpge", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 296 | { RTLIB::OGT_F32, "__aeabi_fcmpgt", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 297 | { RTLIB::UO_F32, "__aeabi_fcmpun", CallingConv::ARM_AAPCS, ISD::SETNE }, |
| 298 | { RTLIB::O_F32, "__aeabi_fcmpun", CallingConv::ARM_AAPCS, ISD::SETEQ }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 299 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 300 | // Floating-point to integer conversions. |
| 301 | // RTABI chapter 4.1.2, Table 6 |
| 302 | { RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 303 | { RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 304 | { RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 305 | { RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 306 | { RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 307 | { RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 308 | { RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 309 | { RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 310 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 311 | // Conversions between floating types. |
| 312 | // RTABI chapter 4.1.2, Table 7 |
| 313 | { RTLIB::FPROUND_F64_F32, "__aeabi_d2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Saleem Abdulrasool | 017bd57 | 2014-08-17 22:51:02 +0000 | [diff] [blame] | 314 | { RTLIB::FPROUND_F64_F16, "__aeabi_d2h", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 315 | { RTLIB::FPEXT_F32_F64, "__aeabi_f2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 316 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 317 | // Integer to floating-point conversions. |
| 318 | // RTABI chapter 4.1.2, Table 8 |
| 319 | { RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 320 | { RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 321 | { RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 322 | { RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 323 | { RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 324 | { RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 325 | { RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 326 | { RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 327 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 328 | // Long long helper functions |
| 329 | // RTABI chapter 4.2, Table 9 |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 330 | { RTLIB::MUL_I64, "__aeabi_lmul", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 331 | { RTLIB::SHL_I64, "__aeabi_llsl", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 332 | { RTLIB::SRL_I64, "__aeabi_llsr", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 333 | { RTLIB::SRA_I64, "__aeabi_lasr", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Anton Korobeynikov | 81bdc93 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 334 | |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 335 | // Integer division functions |
| 336 | // RTABI chapter 4.3.1 |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 337 | { RTLIB::SDIV_I8, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 338 | { RTLIB::SDIV_I16, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 339 | { RTLIB::SDIV_I32, "__aeabi_idiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 340 | { RTLIB::SDIV_I64, "__aeabi_ldivmod", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 341 | { RTLIB::UDIV_I8, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 342 | { RTLIB::UDIV_I16, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 343 | { RTLIB::UDIV_I32, "__aeabi_uidiv", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 344 | { RTLIB::UDIV_I64, "__aeabi_uldivmod", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| Saleem Abdulrasool | 8bfb192 | 2014-05-18 16:39:11 +0000 | [diff] [blame] | 345 | }; |
| 346 | |
| 347 | for (const auto &LC : LibraryCalls) { |
| 348 | setLibcallName(LC.Op, LC.Name); |
| 349 | setLibcallCallingConv(LC.Op, LC.CC); |
| 350 | if (LC.Cond != ISD::SETCC_INVALID) |
| 351 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 352 | } |
| Renato Golin | 6d435f1 | 2015-11-09 12:40:30 +0000 | [diff] [blame] | 353 | |
| 354 | // EABI dependent RTLIB |
| 355 | if (TM.Options.EABIVersion == EABI::EABI4 || |
| 356 | TM.Options.EABIVersion == EABI::EABI5) { |
| 357 | static const struct { |
| 358 | const RTLIB::Libcall Op; |
| 359 | const char *const Name; |
| 360 | const CallingConv::ID CC; |
| 361 | const ISD::CondCode Cond; |
| 362 | } MemOpsLibraryCalls[] = { |
| 363 | // Memory operations |
| 364 | // RTABI chapter 4.3.4 |
| 365 | { RTLIB::MEMCPY, "__aeabi_memcpy", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 366 | { RTLIB::MEMMOVE, "__aeabi_memmove", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 367 | { RTLIB::MEMSET, "__aeabi_memset", CallingConv::ARM_AAPCS, ISD::SETCC_INVALID }, |
| 368 | }; |
| 369 | |
| 370 | for (const auto &LC : MemOpsLibraryCalls) { |
| 371 | setLibcallName(LC.Op, LC.Name); |
| 372 | setLibcallCallingConv(LC.Op, LC.CC); |
| 373 | if (LC.Cond != ISD::SETCC_INVALID) |
| 374 | setCmpLibcallCC(LC.Op, LC.Cond); |
| 375 | } |
| 376 | } |
| Anton Korobeynikov | a6b3ce2 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 377 | } |
| 378 | |
| Saleem Abdulrasool | 056fc3d | 2014-05-16 05:41:33 +0000 | [diff] [blame] | 379 | if (Subtarget->isTargetWindows()) { |
| 380 | static const struct { |
| 381 | const RTLIB::Libcall Op; |
| 382 | const char * const Name; |
| 383 | const CallingConv::ID CC; |
| 384 | } LibraryCalls[] = { |
| 385 | { RTLIB::FPTOSINT_F32_I64, "__stoi64", CallingConv::ARM_AAPCS_VFP }, |
| 386 | { RTLIB::FPTOSINT_F64_I64, "__dtoi64", CallingConv::ARM_AAPCS_VFP }, |
| 387 | { RTLIB::FPTOUINT_F32_I64, "__stou64", CallingConv::ARM_AAPCS_VFP }, |
| 388 | { RTLIB::FPTOUINT_F64_I64, "__dtou64", CallingConv::ARM_AAPCS_VFP }, |
| 389 | { RTLIB::SINTTOFP_I64_F32, "__i64tos", CallingConv::ARM_AAPCS_VFP }, |
| 390 | { RTLIB::SINTTOFP_I64_F64, "__i64tod", CallingConv::ARM_AAPCS_VFP }, |
| 391 | { RTLIB::UINTTOFP_I64_F32, "__u64tos", CallingConv::ARM_AAPCS_VFP }, |
| 392 | { RTLIB::UINTTOFP_I64_F64, "__u64tod", CallingConv::ARM_AAPCS_VFP }, |
| Martell Malone | a6b867e | 2015-11-23 13:11:39 +0000 | [diff] [blame] | 393 | { RTLIB::SDIV_I32, "__rt_sdiv", CallingConv::ARM_AAPCS_VFP }, |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 394 | { RTLIB::UDIV_I32, "__rt_udiv", CallingConv::ARM_AAPCS_VFP }, |
| Martell Malone | a6b867e | 2015-11-23 13:11:39 +0000 | [diff] [blame] | 395 | { RTLIB::SDIV_I64, "__rt_sdiv64", CallingConv::ARM_AAPCS_VFP }, |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 396 | { RTLIB::UDIV_I64, "__rt_udiv64", CallingConv::ARM_AAPCS_VFP }, |
| Saleem Abdulrasool | 056fc3d | 2014-05-16 05:41:33 +0000 | [diff] [blame] | 397 | }; |
| 398 | |
| 399 | for (const auto &LC : LibraryCalls) { |
| 400 | setLibcallName(LC.Op, LC.Name); |
| 401 | setLibcallCallingConv(LC.Op, LC.CC); |
| 402 | } |
| 403 | } |
| 404 | |
| Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 405 | // Use divmod compiler-rt calls for iOS 5.0 and later. |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 406 | if (Subtarget->isTargetWatchOS() || |
| 407 | (Subtarget->isTargetIOS() && |
| 408 | !Subtarget->getTargetTriple().isOSVersionLT(5, 0))) { |
| Bob Wilson | bc15899 | 2011-10-07 16:59:21 +0000 | [diff] [blame] | 409 | setLibcallName(RTLIB::SDIVREM_I32, "__divmodsi4"); |
| 410 | setLibcallName(RTLIB::UDIVREM_I32, "__udivmodsi4"); |
| 411 | } |
| 412 | |
| Oliver Stannard | 11790b2 | 2014-08-11 09:12:32 +0000 | [diff] [blame] | 413 | // The half <-> float conversion functions are always soft-float, but are |
| 414 | // needed for some targets which use a hard-float calling convention by |
| 415 | // default. |
| 416 | if (Subtarget->isAAPCS_ABI()) { |
| 417 | setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_AAPCS); |
| 418 | setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_AAPCS); |
| 419 | setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_AAPCS); |
| 420 | } else { |
| 421 | setLibcallCallingConv(RTLIB::FPROUND_F32_F16, CallingConv::ARM_APCS); |
| 422 | setLibcallCallingConv(RTLIB::FPROUND_F64_F16, CallingConv::ARM_APCS); |
| 423 | setLibcallCallingConv(RTLIB::FPEXT_F16_F32, CallingConv::ARM_APCS); |
| 424 | } |
| 425 | |
| Oliver Stannard | d3d114b | 2015-10-07 16:58:49 +0000 | [diff] [blame] | 426 | // In EABI, these functions have an __aeabi_ prefix, but in GNUEABI they have |
| 427 | // a __gnu_ prefix (which is the default). |
| 428 | if (Subtarget->isTargetAEABI()) { |
| 429 | setLibcallName(RTLIB::FPROUND_F32_F16, "__aeabi_f2h"); |
| 430 | setLibcallName(RTLIB::FPROUND_F64_F16, "__aeabi_d2h"); |
| 431 | setLibcallName(RTLIB::FPEXT_F16_F32, "__aeabi_h2f"); |
| 432 | } |
| 433 | |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 434 | if (Subtarget->isThumb1Only()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 435 | addRegisterClass(MVT::i32, &ARM::tGPRRegClass); |
| Jim Grosbach | fde2110 | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 436 | else |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 437 | addRegisterClass(MVT::i32, &ARM::GPRRegClass); |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 438 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 439 | !Subtarget->isThumb1Only()) { |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 440 | addRegisterClass(MVT::f32, &ARM::SPRRegClass); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 441 | addRegisterClass(MVT::f64, &ARM::DPRRegClass); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 442 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 443 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 444 | for (MVT VT : MVT::vector_valuetypes()) { |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 445 | for (MVT InnerVT : MVT::vector_valuetypes()) { |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 446 | setTruncStoreAction(VT, InnerVT, Expand); |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 447 | setLoadExtAction(ISD::SEXTLOAD, VT, InnerVT, Expand); |
| 448 | setLoadExtAction(ISD::ZEXTLOAD, VT, InnerVT, Expand); |
| 449 | setLoadExtAction(ISD::EXTLOAD, VT, InnerVT, Expand); |
| 450 | } |
| Benjamin Kramer | 4dae598 | 2014-04-26 12:06:28 +0000 | [diff] [blame] | 451 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 452 | setOperationAction(ISD::MULHS, VT, Expand); |
| 453 | setOperationAction(ISD::SMUL_LOHI, VT, Expand); |
| 454 | setOperationAction(ISD::MULHU, VT, Expand); |
| 455 | setOperationAction(ISD::UMUL_LOHI, VT, Expand); |
| Benjamin Kramer | f3ad235 | 2014-05-19 13:12:38 +0000 | [diff] [blame] | 456 | |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 457 | setOperationAction(ISD::BSWAP, VT, Expand); |
| Eli Friedman | 6f84fed | 2011-11-08 01:43:53 +0000 | [diff] [blame] | 458 | } |
| 459 | |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 460 | setOperationAction(ISD::ConstantFP, MVT::f32, Custom); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 461 | setOperationAction(ISD::ConstantFP, MVT::f64, Custom); |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 462 | |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 463 | setOperationAction(ISD::READ_REGISTER, MVT::i64, Custom); |
| 464 | setOperationAction(ISD::WRITE_REGISTER, MVT::i64, Custom); |
| 465 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 466 | if (Subtarget->hasNEON()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 467 | addDRTypeForNEON(MVT::v2f32); |
| 468 | addDRTypeForNEON(MVT::v8i8); |
| 469 | addDRTypeForNEON(MVT::v4i16); |
| 470 | addDRTypeForNEON(MVT::v2i32); |
| 471 | addDRTypeForNEON(MVT::v1i64); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 472 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 473 | addQRTypeForNEON(MVT::v4f32); |
| 474 | addQRTypeForNEON(MVT::v2f64); |
| 475 | addQRTypeForNEON(MVT::v16i8); |
| 476 | addQRTypeForNEON(MVT::v8i16); |
| 477 | addQRTypeForNEON(MVT::v4i32); |
| 478 | addQRTypeForNEON(MVT::v2i64); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 479 | |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 480 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 481 | // neither Neon nor VFP support any arithmetic operations on it. |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 482 | // The same with v4f32. But keep in mind that vadd, vsub, vmul are natively |
| 483 | // supported for v4f32. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 484 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 485 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 486 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 487 | // FIXME: Code duplication: FDIV and FREM are expanded always, see |
| 488 | // ARMTargetLowering::addTypeForNEON method for details. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 489 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 490 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 491 | // FIXME: Create unittest. |
| 492 | // In another words, find a way when "copysign" appears in DAG with vector |
| 493 | // operands. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 494 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 495 | // FIXME: Code duplication: SETCC has custom operation action, see |
| 496 | // ARMTargetLowering::addTypeForNEON method for details. |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 497 | setOperationAction(ISD::SETCC, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 498 | // FIXME: Create unittest for FNEG and for FABS. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 499 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 500 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 501 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 502 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 503 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 504 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 505 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 506 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 507 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 508 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 509 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 510 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 511 | // FIXME: Create unittest for FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR. |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 512 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 513 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 514 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 515 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 516 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 517 | setOperationAction(ISD::FMA, MVT::v2f64, Expand); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 518 | |
| Stepan Dyatkovskiy | 4683740 | 2011-12-11 14:35:48 +0000 | [diff] [blame] | 519 | setOperationAction(ISD::FSQRT, MVT::v4f32, Expand); |
| 520 | setOperationAction(ISD::FSIN, MVT::v4f32, Expand); |
| 521 | setOperationAction(ISD::FCOS, MVT::v4f32, Expand); |
| 522 | setOperationAction(ISD::FPOWI, MVT::v4f32, Expand); |
| 523 | setOperationAction(ISD::FPOW, MVT::v4f32, Expand); |
| 524 | setOperationAction(ISD::FLOG, MVT::v4f32, Expand); |
| 525 | setOperationAction(ISD::FLOG2, MVT::v4f32, Expand); |
| 526 | setOperationAction(ISD::FLOG10, MVT::v4f32, Expand); |
| 527 | setOperationAction(ISD::FEXP, MVT::v4f32, Expand); |
| 528 | setOperationAction(ISD::FEXP2, MVT::v4f32, Expand); |
| Craig Topper | 61d0457 | 2012-11-15 06:51:10 +0000 | [diff] [blame] | 529 | setOperationAction(ISD::FCEIL, MVT::v4f32, Expand); |
| 530 | setOperationAction(ISD::FTRUNC, MVT::v4f32, Expand); |
| 531 | setOperationAction(ISD::FRINT, MVT::v4f32, Expand); |
| 532 | setOperationAction(ISD::FNEARBYINT, MVT::v4f32, Expand); |
| Craig Topper | 3e41a5b | 2012-09-08 04:58:43 +0000 | [diff] [blame] | 533 | setOperationAction(ISD::FFLOOR, MVT::v4f32, Expand); |
| Bob Wilson | 194a251 | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 534 | |
| Arnold Schwaighofer | 99cba96 | 2013-03-02 19:38:33 +0000 | [diff] [blame] | 535 | // Mark v2f32 intrinsics. |
| 536 | setOperationAction(ISD::FSQRT, MVT::v2f32, Expand); |
| 537 | setOperationAction(ISD::FSIN, MVT::v2f32, Expand); |
| 538 | setOperationAction(ISD::FCOS, MVT::v2f32, Expand); |
| 539 | setOperationAction(ISD::FPOWI, MVT::v2f32, Expand); |
| 540 | setOperationAction(ISD::FPOW, MVT::v2f32, Expand); |
| 541 | setOperationAction(ISD::FLOG, MVT::v2f32, Expand); |
| 542 | setOperationAction(ISD::FLOG2, MVT::v2f32, Expand); |
| 543 | setOperationAction(ISD::FLOG10, MVT::v2f32, Expand); |
| 544 | setOperationAction(ISD::FEXP, MVT::v2f32, Expand); |
| 545 | setOperationAction(ISD::FEXP2, MVT::v2f32, Expand); |
| 546 | setOperationAction(ISD::FCEIL, MVT::v2f32, Expand); |
| 547 | setOperationAction(ISD::FTRUNC, MVT::v2f32, Expand); |
| 548 | setOperationAction(ISD::FRINT, MVT::v2f32, Expand); |
| 549 | setOperationAction(ISD::FNEARBYINT, MVT::v2f32, Expand); |
| 550 | setOperationAction(ISD::FFLOOR, MVT::v2f32, Expand); |
| 551 | |
| Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 552 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 553 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 554 | // Custom handling for some quad-vector types to detect VMULL. |
| 555 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 556 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 557 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 558 | // Custom handling for some vector types to avoid expensive expansions |
| 559 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 560 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 561 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 562 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 563 | setOperationAction(ISD::SETCC, MVT::v1i64, Expand); |
| 564 | setOperationAction(ISD::SETCC, MVT::v2i64, Expand); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 565 | // 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] | 566 | // a destination type that is wider than the source, and nor does |
| 567 | // it have a FP_TO_[SU]INT instruction with a narrower destination than |
| 568 | // source. |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 569 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 570 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 571 | setOperationAction(ISD::FP_TO_UINT, MVT::v4i16, Custom); |
| 572 | setOperationAction(ISD::FP_TO_SINT, MVT::v4i16, Custom); |
| Bob Wilson | 6cc4657 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 573 | |
| Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 574 | setOperationAction(ISD::FP_ROUND, MVT::v2f32, Expand); |
| Eli Friedman | 3083494 | 2012-11-17 01:52:46 +0000 | [diff] [blame] | 575 | setOperationAction(ISD::FP_EXTEND, MVT::v2f64, Expand); |
| Eli Friedman | e6385e6 | 2012-11-15 22:44:27 +0000 | [diff] [blame] | 576 | |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 577 | // NEON does not have single instruction CTPOP for vectors with element |
| 578 | // types wider than 8-bits. However, custom lowering can leverage the |
| 579 | // v8i8/v16i8 vcnt instruction. |
| 580 | setOperationAction(ISD::CTPOP, MVT::v2i32, Custom); |
| 581 | setOperationAction(ISD::CTPOP, MVT::v4i32, Custom); |
| 582 | setOperationAction(ISD::CTPOP, MVT::v4i16, Custom); |
| 583 | setOperationAction(ISD::CTPOP, MVT::v8i16, Custom); |
| 584 | |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 585 | // NEON does not have single instruction CTTZ for vectors. |
| 586 | setOperationAction(ISD::CTTZ, MVT::v8i8, Custom); |
| 587 | setOperationAction(ISD::CTTZ, MVT::v4i16, Custom); |
| 588 | setOperationAction(ISD::CTTZ, MVT::v2i32, Custom); |
| 589 | setOperationAction(ISD::CTTZ, MVT::v1i64, Custom); |
| 590 | |
| 591 | setOperationAction(ISD::CTTZ, MVT::v16i8, Custom); |
| 592 | setOperationAction(ISD::CTTZ, MVT::v8i16, Custom); |
| 593 | setOperationAction(ISD::CTTZ, MVT::v4i32, Custom); |
| 594 | setOperationAction(ISD::CTTZ, MVT::v2i64, Custom); |
| 595 | |
| 596 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v8i8, Custom); |
| 597 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v4i16, Custom); |
| 598 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v2i32, Custom); |
| 599 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v1i64, Custom); |
| 600 | |
| 601 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v16i8, Custom); |
| 602 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v8i16, Custom); |
| 603 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v4i32, Custom); |
| 604 | setOperationAction(ISD::CTTZ_ZERO_UNDEF, MVT::v2i64, Custom); |
| 605 | |
| Jim Grosbach | 5f21587 | 2013-02-27 21:31:12 +0000 | [diff] [blame] | 606 | // NEON only has FMA instructions as of VFP4. |
| 607 | if (!Subtarget->hasVFP4()) { |
| 608 | setOperationAction(ISD::FMA, MVT::v2f32, Expand); |
| 609 | setOperationAction(ISD::FMA, MVT::v4f32, Expand); |
| 610 | } |
| 611 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 612 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 613 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 614 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 615 | setTargetDAGCombine(ISD::SHL); |
| 616 | setTargetDAGCombine(ISD::SRL); |
| 617 | setTargetDAGCombine(ISD::SRA); |
| 618 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 619 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 620 | setTargetDAGCombine(ISD::ANY_EXTEND); |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 621 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 622 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 623 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 624 | setTargetDAGCombine(ISD::STORE); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 625 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 626 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 627 | setTargetDAGCombine(ISD::FDIV); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 628 | setTargetDAGCombine(ISD::LOAD); |
| Nadav Rotem | 097106b | 2011-10-15 20:03:12 +0000 | [diff] [blame] | 629 | |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 630 | // It is legal to extload from v4i8 to v4i16 or v4i32. |
| Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 631 | for (MVT Ty : {MVT::v8i8, MVT::v4i8, MVT::v2i8, MVT::v4i16, MVT::v2i16, |
| 632 | MVT::v2i32}) { |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 633 | for (MVT VT : MVT::integer_vector_valuetypes()) { |
| Benjamin Kramer | 867bfc5 | 2015-03-07 17:41:00 +0000 | [diff] [blame] | 634 | setLoadExtAction(ISD::EXTLOAD, VT, Ty, Legal); |
| 635 | setLoadExtAction(ISD::ZEXTLOAD, VT, Ty, Legal); |
| 636 | setLoadExtAction(ISD::SEXTLOAD, VT, Ty, Legal); |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 637 | } |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 638 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 641 | // ARM and Thumb2 support UMLAL/SMLAL. |
| 642 | if (!Subtarget->isThumb1Only()) |
| 643 | setTargetDAGCombine(ISD::ADDC); |
| 644 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 645 | if (Subtarget->isFPOnlySP()) { |
| Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 646 | // When targeting a floating-point unit with only single-precision |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 647 | // operations, f64 is legal for the few double-precision instructions which |
| 648 | // are present However, no double-precision operations other than moves, |
| 649 | // loads and stores are provided by the hardware. |
| 650 | setOperationAction(ISD::FADD, MVT::f64, Expand); |
| 651 | setOperationAction(ISD::FSUB, MVT::f64, Expand); |
| 652 | setOperationAction(ISD::FMUL, MVT::f64, Expand); |
| 653 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 654 | setOperationAction(ISD::FDIV, MVT::f64, Expand); |
| 655 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 656 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Expand); |
| 657 | setOperationAction(ISD::FGETSIGN, MVT::f64, Expand); |
| 658 | setOperationAction(ISD::FNEG, MVT::f64, Expand); |
| 659 | setOperationAction(ISD::FABS, MVT::f64, Expand); |
| 660 | setOperationAction(ISD::FSQRT, MVT::f64, Expand); |
| 661 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 662 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 663 | setOperationAction(ISD::FPOWI, MVT::f64, Expand); |
| 664 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 665 | setOperationAction(ISD::FLOG, MVT::f64, Expand); |
| 666 | setOperationAction(ISD::FLOG2, MVT::f64, Expand); |
| 667 | setOperationAction(ISD::FLOG10, MVT::f64, Expand); |
| 668 | setOperationAction(ISD::FEXP, MVT::f64, Expand); |
| 669 | setOperationAction(ISD::FEXP2, MVT::f64, Expand); |
| 670 | setOperationAction(ISD::FCEIL, MVT::f64, Expand); |
| 671 | setOperationAction(ISD::FTRUNC, MVT::f64, Expand); |
| 672 | setOperationAction(ISD::FRINT, MVT::f64, Expand); |
| 673 | setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand); |
| 674 | setOperationAction(ISD::FFLOOR, MVT::f64, Expand); |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 675 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 676 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 677 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 678 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 679 | setOperationAction(ISD::FP_TO_SINT, MVT::f64, Custom); |
| 680 | setOperationAction(ISD::FP_TO_UINT, MVT::f64, Custom); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 681 | setOperationAction(ISD::FP_ROUND, MVT::f32, Custom); |
| 682 | setOperationAction(ISD::FP_EXTEND, MVT::f64, Custom); |
| 683 | } |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 684 | |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 685 | computeRegisterProperties(Subtarget->getRegisterInfo()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 686 | |
| Tim Northover | 4e80b58 | 2014-07-18 13:01:19 +0000 | [diff] [blame] | 687 | // ARM does not have floating-point extending loads. |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 688 | for (MVT VT : MVT::fp_valuetypes()) { |
| 689 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f32, Expand); |
| 690 | setLoadExtAction(ISD::EXTLOAD, VT, MVT::f16, Expand); |
| 691 | } |
| Tim Northover | 4e80b58 | 2014-07-18 13:01:19 +0000 | [diff] [blame] | 692 | |
| 693 | // ... or truncating stores |
| 694 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
| 695 | setTruncStoreAction(MVT::f32, MVT::f16, Expand); |
| 696 | setTruncStoreAction(MVT::f64, MVT::f16, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 697 | |
| Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 698 | // ARM does not have i1 sign extending load. |
| Ahmed Bougacha | 2b6917b | 2015-01-08 00:51:32 +0000 | [diff] [blame] | 699 | for (MVT VT : MVT::integer_valuetypes()) |
| 700 | setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote); |
| Duncan Sands | 95d46ef | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 701 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 702 | // ARM supports all 4 flavors of integer indexed load / store. |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 703 | if (!Subtarget->isThumb1Only()) { |
| 704 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 705 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 706 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 707 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 708 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 709 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 710 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 711 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 712 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 713 | setIndexedStoreAction(im, MVT::i32, Legal); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 714 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 717 | setOperationAction(ISD::SADDO, MVT::i32, Custom); |
| 718 | setOperationAction(ISD::UADDO, MVT::i32, Custom); |
| 719 | setOperationAction(ISD::SSUBO, MVT::i32, Custom); |
| 720 | setOperationAction(ISD::USUBO, MVT::i32, Custom); |
| 721 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 722 | // i64 operation support. |
| Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 723 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 724 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
| Evan Cheng | b24e51e | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 725 | if (Subtarget->isThumb1Only()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 726 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 727 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 728 | } |
| Jim Grosbach | cf1464d | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 729 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| Artyom Skrobov | cf29644 | 2015-09-24 17:31:16 +0000 | [diff] [blame] | 730 | || (Subtarget->isThumb2() && !Subtarget->hasDSP())) |
| Eric Christopher | c721b0db | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 731 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 732 | |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 733 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 734 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 735 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 736 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 737 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 738 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 739 | if (!Subtarget->isThumb1Only()) { |
| 740 | // FIXME: We should do this for Thumb1 as well. |
| 741 | setOperationAction(ISD::ADDC, MVT::i32, Custom); |
| 742 | setOperationAction(ISD::ADDE, MVT::i32, Custom); |
| 743 | setOperationAction(ISD::SUBC, MVT::i32, Custom); |
| 744 | setOperationAction(ISD::SUBE, MVT::i32, Custom); |
| 745 | } |
| 746 | |
| Weiming Zhao | 4b3b13d | 2016-01-08 18:43:41 +0000 | [diff] [blame] | 747 | if (!Subtarget->isThumb1Only() && Subtarget->hasV6T2Ops()) |
| James Molloy | b564098 | 2015-11-13 16:05:22 +0000 | [diff] [blame] | 748 | setOperationAction(ISD::BITREVERSE, MVT::i32, Legal); |
| 749 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 750 | // ARM does not have ROTL. |
| Charlie Turner | 458e79b | 2015-10-27 10:25:20 +0000 | [diff] [blame] | 751 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
| 752 | for (MVT VT : MVT::vector_valuetypes()) { |
| 753 | setOperationAction(ISD::ROTL, VT, Expand); |
| 754 | setOperationAction(ISD::ROTR, VT, Expand); |
| 755 | } |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 756 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 757 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
| David Goodwin | aa294c5 | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 758 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 759 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 760 | |
| Chandler Carruth | 637cc6a | 2011-12-13 01:56:10 +0000 | [diff] [blame] | 761 | // These just redirect to CTTZ and CTLZ on ARM. |
| 762 | setOperationAction(ISD::CTTZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 763 | setOperationAction(ISD::CTLZ_ZERO_UNDEF , MVT::i32 , Expand); |
| 764 | |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 765 | // @llvm.readcyclecounter requires the Performance Monitors extension. |
| 766 | // Default to the 0 expansion on unsupported platforms. |
| 767 | // FIXME: Technically there are older ARM CPUs that have |
| 768 | // implementation-specific ways of obtaining this information. |
| 769 | if (Subtarget->hasPerfMon()) |
| 770 | setOperationAction(ISD::READCYCLECOUNTER, MVT::i64, Custom); |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 771 | |
| Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 772 | // Only ARMv6 has BSWAP. |
| 773 | if (!Subtarget->hasV6Ops()) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 774 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
| Lauro Ramos Venancio | 25d4052 | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 775 | |
| Bradley Smith | 519563e | 2016-01-15 10:25:35 +0000 | [diff] [blame] | 776 | bool hasDivide = Subtarget->isThumb() ? Subtarget->hasDivide() |
| 777 | : Subtarget->hasDivideInARMMode(); |
| 778 | if (!hasDivide) { |
| Bob Wilson | e8a549c | 2012-09-29 21:43:49 +0000 | [diff] [blame] | 779 | // 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] | 780 | setOperationAction(ISD::SDIV, MVT::i32, LibCall); |
| 781 | setOperationAction(ISD::UDIV, MVT::i32, LibCall); |
| Jim Grosbach | 92d99900 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 782 | } |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 783 | |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 784 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 785 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 786 | // Register based DivRem for AEABI (RTABI 4.2) |
| Renato Golin | 6027dd38e | 2016-02-03 16:10:54 +0000 | [diff] [blame] | 787 | if (Subtarget->isTargetAEABI() || Subtarget->isTargetAndroid() || |
| 788 | Subtarget->isTargetGNUAEABI()) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 789 | setOperationAction(ISD::SREM, MVT::i64, Custom); |
| 790 | setOperationAction(ISD::UREM, MVT::i64, Custom); |
| 791 | |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 792 | setLibcallName(RTLIB::SDIVREM_I8, "__aeabi_idivmod"); |
| 793 | setLibcallName(RTLIB::SDIVREM_I16, "__aeabi_idivmod"); |
| 794 | setLibcallName(RTLIB::SDIVREM_I32, "__aeabi_idivmod"); |
| 795 | setLibcallName(RTLIB::SDIVREM_I64, "__aeabi_ldivmod"); |
| 796 | setLibcallName(RTLIB::UDIVREM_I8, "__aeabi_uidivmod"); |
| 797 | setLibcallName(RTLIB::UDIVREM_I16, "__aeabi_uidivmod"); |
| 798 | setLibcallName(RTLIB::UDIVREM_I32, "__aeabi_uidivmod"); |
| 799 | setLibcallName(RTLIB::UDIVREM_I64, "__aeabi_uldivmod"); |
| 800 | |
| 801 | setLibcallCallingConv(RTLIB::SDIVREM_I8, CallingConv::ARM_AAPCS); |
| 802 | setLibcallCallingConv(RTLIB::SDIVREM_I16, CallingConv::ARM_AAPCS); |
| 803 | setLibcallCallingConv(RTLIB::SDIVREM_I32, CallingConv::ARM_AAPCS); |
| 804 | setLibcallCallingConv(RTLIB::SDIVREM_I64, CallingConv::ARM_AAPCS); |
| 805 | setLibcallCallingConv(RTLIB::UDIVREM_I8, CallingConv::ARM_AAPCS); |
| 806 | setLibcallCallingConv(RTLIB::UDIVREM_I16, CallingConv::ARM_AAPCS); |
| 807 | setLibcallCallingConv(RTLIB::UDIVREM_I32, CallingConv::ARM_AAPCS); |
| 808 | setLibcallCallingConv(RTLIB::UDIVREM_I64, CallingConv::ARM_AAPCS); |
| 809 | |
| 810 | setOperationAction(ISD::SDIVREM, MVT::i32, Custom); |
| 811 | setOperationAction(ISD::UDIVREM, MVT::i32, Custom); |
| Renato Golin | 175c6d6 | 2016-03-04 19:19:36 +0000 | [diff] [blame] | 812 | setOperationAction(ISD::SDIVREM, MVT::i64, Custom); |
| 813 | setOperationAction(ISD::UDIVREM, MVT::i64, Custom); |
| Chad Rosier | ad7c910 | 2014-08-23 18:29:43 +0000 | [diff] [blame] | 814 | } else { |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 815 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 816 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
| 817 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 818 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 819 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 820 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 821 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 822 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 823 | |
| Evan Cheng | 74d92c1 | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 824 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
| Evan Cheng | 2fa5a7e | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 825 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 826 | // Use the default implementation. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 827 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 828 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 829 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 830 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 831 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 832 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
| Bill Wendling | 05d6f2f | 2012-02-13 23:47:16 +0000 | [diff] [blame] | 833 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 834 | if (Subtarget->getTargetTriple().isWindowsItaniumEnvironment()) |
| 835 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Custom); |
| 836 | else |
| 837 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
| 838 | |
| Evan Cheng | 6e809de | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 839 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| Jonathan Roelofs | 5e98ff9 | 2014-08-21 14:35:47 +0000 | [diff] [blame] | 840 | // the default expansion. If we are targeting a single threaded system, |
| 841 | // then set them all for expand so we can lower them later into their |
| 842 | // non-atomic form. |
| 843 | if (TM.Options.ThreadModel == ThreadModel::Single) |
| 844 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
| Bradley Smith | 433c22e | 2016-01-15 10:26:51 +0000 | [diff] [blame] | 845 | else if (Subtarget->hasAnyDataBarrier() && (!Subtarget->isThumb() || |
| 846 | Subtarget->hasV8MBaselineOps())) { |
| Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 847 | // ATOMIC_FENCE needs custom lowering; the others should have been expanded |
| 848 | // to ldrex/strex loops already. |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 849 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
| Tim Northover | c882eb0 | 2014-04-03 11:44:58 +0000 | [diff] [blame] | 850 | |
| Amara Emerson | b4ad2f3 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 851 | // On v8, we have particularly efficient implementations of atomic fences |
| 852 | // if they can be combined with nearby atomic loads and stores. |
| 853 | if (!Subtarget->hasV8Ops()) { |
| Robin Morisset | d18cda6 | 2014-08-15 22:17:28 +0000 | [diff] [blame] | 854 | // Automatically insert fences (dmb ish) around ATOMIC_SWAP etc. |
| Amara Emerson | b4ad2f3 | 2013-09-26 12:22:36 +0000 | [diff] [blame] | 855 | setInsertFencesForAtomic(true); |
| 856 | } |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 857 | } else { |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 858 | // If there's anything we can use as a barrier, go through custom lowering |
| 859 | // for ATOMIC_FENCE. |
| 860 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, |
| 861 | Subtarget->hasAnyDataBarrier() ? Custom : Expand); |
| 862 | |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 863 | // Set them all for expansion, which will force libcalls. |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 864 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
| Jim Grosbach | a57c288 | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 865 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 866 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 867 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 868 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 869 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 870 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 871 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 872 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 873 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 874 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
| Jim Grosbach | d4b733e | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 875 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 876 | // Mark ATOMIC_LOAD and ATOMIC_STORE custom so we can handle the |
| 877 | // Unordered/Monotonic case. |
| 878 | setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Custom); |
| 879 | setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Custom); |
| Jim Grosbach | 6860bb7 | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 880 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 881 | |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 882 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
| Evan Cheng | 6f36042 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 883 | |
| Eli Friedman | 8cfa771 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 884 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 885 | if (!Subtarget->hasV6Ops()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 886 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 887 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 888 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 889 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 890 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 891 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 892 | !Subtarget->isThumb1Only()) { |
| Bob Wilson | 6a4491b | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 893 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 894 | // iff target supports vfp2. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 895 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 896 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 897 | } |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 898 | |
| 899 | // We want to custom lower some of our intrinsics. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 900 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 901 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 902 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
| 903 | setOperationAction(ISD::EH_SJLJ_SETUP_DISPATCH, MVT::Other, Custom); |
| Tim Northover | f8e47e4 | 2015-10-28 22:56:36 +0000 | [diff] [blame] | 904 | if (Subtarget->useSjLjEH()) |
| John McCall | 7d84ece | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 905 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 906 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 907 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 908 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 909 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 910 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 911 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 912 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 913 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 914 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 915 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 916 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 917 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 918 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 919 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 920 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 921 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 922 | |
| Dan Gohman | 482732a | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 923 | // We don't support sin/cos/fmod/copysign/pow |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 924 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 925 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 926 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 927 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| Evan Cheng | 0e88c7d | 2013-01-29 02:32:37 +0000 | [diff] [blame] | 928 | setOperationAction(ISD::FSINCOS, MVT::f64, Expand); |
| 929 | setOperationAction(ISD::FSINCOS, MVT::f32, Expand); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 930 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 931 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 932 | if (!Subtarget->useSoftFloat() && Subtarget->hasVFP2() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 933 | !Subtarget->isThumb1Only()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 934 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 935 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
| Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 936 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 937 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 938 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 939 | |
| Evan Cheng | d0007f3 | 2012-04-10 21:40:28 +0000 | [diff] [blame] | 940 | if (!Subtarget->hasVFP4()) { |
| 941 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 942 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 943 | } |
| Cameron Zwarich | f03fa18 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 944 | |
| Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 945 | // Various VFP goodness |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 946 | if (!Subtarget->useSoftFloat() && !Subtarget->isThumb1Only()) { |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 947 | // FP-ARMv8 adds f64 <-> f16 conversion. Before that it should be expanded. |
| 948 | if (!Subtarget->hasFPARMv8() || Subtarget->isFPOnlySP()) { |
| Tim Northover | 53f3bcf | 2014-07-17 11:27:04 +0000 | [diff] [blame] | 949 | setOperationAction(ISD::FP16_TO_FP, MVT::f64, Expand); |
| 950 | setOperationAction(ISD::FP_TO_FP16, MVT::f64, Expand); |
| 951 | } |
| 952 | |
| 953 | // fp16 is a special v7 extension that adds f16 <-> f32 conversions. |
| Anton Korobeynikov | 64578d5 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 954 | if (!Subtarget->hasFP16()) { |
| Tim Northover | fd7e424 | 2014-07-17 10:51:23 +0000 | [diff] [blame] | 955 | setOperationAction(ISD::FP16_TO_FP, MVT::f32, Expand); |
| 956 | setOperationAction(ISD::FP_TO_FP16, MVT::f32, Expand); |
| Anton Korobeynikov | d7fece3 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 957 | } |
| Evan Cheng | 86e476b | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 958 | } |
| Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 959 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 960 | // Combine sin / cos into one node or libcall if possible. |
| 961 | if (Subtarget->hasSinCos()) { |
| 962 | setLibcallName(RTLIB::SINCOS_F32, "sincosf"); |
| 963 | setLibcallName(RTLIB::SINCOS_F64, "sincos"); |
| Tim Northover | 042a6c1 | 2016-01-27 19:32:29 +0000 | [diff] [blame] | 964 | if (Subtarget->isTargetWatchABI()) { |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 965 | setLibcallCallingConv(RTLIB::SINCOS_F32, CallingConv::ARM_AAPCS_VFP); |
| 966 | setLibcallCallingConv(RTLIB::SINCOS_F64, CallingConv::ARM_AAPCS_VFP); |
| 967 | } |
| 968 | if (Subtarget->isTargetIOS() || Subtarget->isTargetWatchOS()) { |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 969 | // For iOS, we don't want to the normal expansion of a libcall to |
| 970 | // sincos. We want to issue a libcall to __sincos_stret. |
| 971 | setOperationAction(ISD::FSINCOS, MVT::f64, Custom); |
| 972 | setOperationAction(ISD::FSINCOS, MVT::f32, Custom); |
| 973 | } |
| 974 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 975 | |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 976 | // FP-ARMv8 implements a lot of rounding-like FP operations. |
| 977 | if (Subtarget->hasFPARMv8()) { |
| 978 | setOperationAction(ISD::FFLOOR, MVT::f32, Legal); |
| 979 | setOperationAction(ISD::FCEIL, MVT::f32, Legal); |
| 980 | setOperationAction(ISD::FROUND, MVT::f32, Legal); |
| 981 | setOperationAction(ISD::FTRUNC, MVT::f32, Legal); |
| 982 | setOperationAction(ISD::FNEARBYINT, MVT::f32, Legal); |
| 983 | setOperationAction(ISD::FRINT, MVT::f32, Legal); |
| James Molloy | ea3a687 | 2015-08-11 12:06:22 +0000 | [diff] [blame] | 984 | setOperationAction(ISD::FMINNUM, MVT::f32, Legal); |
| 985 | setOperationAction(ISD::FMAXNUM, MVT::f32, Legal); |
| James Molloy | ee868b2 | 2015-08-11 12:06:25 +0000 | [diff] [blame] | 986 | setOperationAction(ISD::FMINNUM, MVT::v2f32, Legal); |
| 987 | setOperationAction(ISD::FMAXNUM, MVT::v2f32, Legal); |
| 988 | setOperationAction(ISD::FMINNUM, MVT::v4f32, Legal); |
| 989 | setOperationAction(ISD::FMAXNUM, MVT::v4f32, Legal); |
| 990 | |
| Oliver Stannard | d4e0a4f | 2014-10-01 13:13:18 +0000 | [diff] [blame] | 991 | if (!Subtarget->isFPOnlySP()) { |
| 992 | setOperationAction(ISD::FFLOOR, MVT::f64, Legal); |
| 993 | setOperationAction(ISD::FCEIL, MVT::f64, Legal); |
| 994 | setOperationAction(ISD::FROUND, MVT::f64, Legal); |
| 995 | setOperationAction(ISD::FTRUNC, MVT::f64, Legal); |
| 996 | setOperationAction(ISD::FNEARBYINT, MVT::f64, Legal); |
| 997 | setOperationAction(ISD::FRINT, MVT::f64, Legal); |
| James Molloy | ea3a687 | 2015-08-11 12:06:22 +0000 | [diff] [blame] | 998 | setOperationAction(ISD::FMINNUM, MVT::f64, Legal); |
| 999 | setOperationAction(ISD::FMAXNUM, MVT::f64, Legal); |
| Chad Rosier | b1bbf6f | 2014-08-15 21:38:16 +0000 | [diff] [blame] | 1000 | } |
| 1001 | } |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1002 | |
| James Molloy | 974838f | 2015-08-17 19:37:12 +0000 | [diff] [blame] | 1003 | if (Subtarget->hasNEON()) { |
| 1004 | // vmin and vmax aren't available in a scalar form, so we use |
| 1005 | // a NEON instruction with an undef lane instead. |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1006 | setOperationAction(ISD::FMINNAN, MVT::f32, Legal); |
| 1007 | setOperationAction(ISD::FMAXNAN, MVT::f32, Legal); |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 1008 | setOperationAction(ISD::FMINNAN, MVT::v2f32, Legal); |
| 1009 | setOperationAction(ISD::FMAXNAN, MVT::v2f32, Legal); |
| 1010 | setOperationAction(ISD::FMINNAN, MVT::v4f32, Legal); |
| 1011 | setOperationAction(ISD::FMAXNAN, MVT::v4f32, Legal); |
| 1012 | } |
| James Molloy | db8ee4b | 2015-08-11 12:06:15 +0000 | [diff] [blame] | 1013 | |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 1014 | // We have target-specific dag combine patterns for the following nodes: |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1015 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 1016 | setTargetDAGCombine(ISD::ADD); |
| 1017 | setTargetDAGCombine(ISD::SUB); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 1018 | setTargetDAGCombine(ISD::MUL); |
| Jakob Stoklund Olesen | e45e22b | 2012-09-07 17:34:15 +0000 | [diff] [blame] | 1019 | setTargetDAGCombine(ISD::AND); |
| 1020 | setTargetDAGCombine(ISD::OR); |
| 1021 | setTargetDAGCombine(ISD::XOR); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 1022 | |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 1023 | if (Subtarget->hasV6Ops()) |
| 1024 | setTargetDAGCombine(ISD::SRL); |
| 1025 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1026 | setStackPointerRegisterToSaveRestore(ARM::SP); |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1027 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 1028 | if (Subtarget->useSoftFloat() || Subtarget->isThumb1Only() || |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1029 | !Subtarget->hasVFP2()) |
| Evan Cheng | 34c2604 | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 1030 | setSchedulingPreference(Sched::RegPressure); |
| 1031 | else |
| 1032 | setSchedulingPreference(Sched::Hybrid); |
| Dale Johannesen | 58698d2 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 1033 | |
| Evan Cheng | 3ae2b79 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 1034 | //// temporary - rewrite interface to use type |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1035 | MaxStoresPerMemset = 8; |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1036 | MaxStoresPerMemsetOptSize = 4; |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1037 | MaxStoresPerMemcpy = 4; // For @llvm.memcpy -> sequence of stores |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1038 | MaxStoresPerMemcpyOptSize = 2; |
| Jim Grosbach | 341ad3e | 2013-02-20 21:13:59 +0000 | [diff] [blame] | 1039 | MaxStoresPerMemmove = 4; // For @llvm.memmove -> sequence of stores |
| Sanjay Patel | 1166f2f | 2015-07-30 21:41:50 +0000 | [diff] [blame] | 1040 | MaxStoresPerMemmoveOptSize = 2; |
| Evan Cheng | b71233f | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 1041 | |
| Rafael Espindola | a76eccf | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 1042 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 1043 | // are at least 4 bytes aligned. |
| 1044 | setMinStackArgumentAlignment(4); |
| 1045 | |
| Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 1046 | // Prefer likely predicted branches to selects on out-of-order cores. |
| Junmo Park | 453f4aa | 2016-02-23 09:56:58 +0000 | [diff] [blame] | 1047 | PredictableSelectIsExpensive = Subtarget->getSchedModel().isOutOfOrder(); |
| Benjamin Kramer | e31f31e | 2012-05-05 12:49:14 +0000 | [diff] [blame] | 1048 | |
| Eli Friedman | 2518f83 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 1049 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1050 | } |
| 1051 | |
| Eric Christopher | 824f42f | 2015-05-12 01:26:05 +0000 | [diff] [blame] | 1052 | bool ARMTargetLowering::useSoftFloat() const { |
| 1053 | return Subtarget->useSoftFloat(); |
| 1054 | } |
| 1055 | |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1056 | // FIXME: It might make sense to define the representative register class as the |
| 1057 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 1058 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 1059 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 1060 | // pressure tracking were modified such that a register use would increment the |
| 1061 | // pressure of the register class's representative and all of it's super |
| 1062 | // classes' representatives transitively. We have not implemented this because |
| 1063 | // of the difficulty prior to coalescing of modeling operand register classes |
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1064 | // due to the common occurrence of cross class copies and subregister insertions |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1065 | // and extractions. |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 1066 | std::pair<const TargetRegisterClass *, uint8_t> |
| 1067 | ARMTargetLowering::findRepresentativeClass(const TargetRegisterInfo *TRI, |
| 1068 | MVT VT) const { |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1069 | const TargetRegisterClass *RRC = nullptr; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1070 | uint8_t Cost = 1; |
| Patrik Hagglund | f9eb168 | 2012-12-19 11:30:36 +0000 | [diff] [blame] | 1071 | switch (VT.SimpleTy) { |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1072 | default: |
| Eric Christopher | 23a3a7c | 2015-02-26 00:00:24 +0000 | [diff] [blame] | 1073 | return TargetLowering::findRepresentativeClass(TRI, VT); |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1074 | // Use DPR as representative register class for all floating point |
| 1075 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 1076 | // the cost is 1 for both f32 and f64. |
| 1077 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1078 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1079 | RRC = &ARM::DPRRegClass; |
| Andrew Trick | 43f2563 | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 1080 | // When NEON is used for SP, only half of the register file is available |
| 1081 | // because operations that define both SP and DP results will be constrained |
| 1082 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 1083 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 1084 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 1085 | Cost = 2; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1086 | break; |
| 1087 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 1088 | case MVT::v4f32: case MVT::v2f64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1089 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1090 | Cost = 2; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | case MVT::v4i64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1093 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1094 | Cost = 4; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1095 | break; |
| 1096 | case MVT::v8i64: |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1097 | RRC = &ARM::DPRRegClass; |
| Evan Cheng | 2859038 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 1098 | Cost = 8; |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1099 | break; |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1100 | } |
| Evan Cheng | a77f3d3 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 1101 | return std::make_pair(RRC, Cost); |
| Evan Cheng | 10f99a3 | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 1102 | } |
| 1103 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1104 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1105 | switch ((ARMISD::NodeType)Opcode) { |
| 1106 | case ARMISD::FIRST_NUMBER: break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1107 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1108 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1109 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| Matthias Braun | f45afee | 2015-05-07 22:16:10 +0000 | [diff] [blame] | 1110 | case ARMISD::COPY_STRUCT_BYVAL: return "ARMISD::COPY_STRUCT_BYVAL"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1111 | case ARMISD::CALL: return "ARMISD::CALL"; |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1112 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1113 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 1114 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 1115 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 1116 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
| Evan Cheng | c6d70ae | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 1117 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1118 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 1119 | case ARMISD::INTRET_FLAG: return "ARMISD::INTRET_FLAG"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1120 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 1121 | case ARMISD::CMP: return "ARMISD::CMP"; |
| Bill Wendling | 4b79647 | 2012-06-11 08:07:26 +0000 | [diff] [blame] | 1122 | case ARMISD::CMN: return "ARMISD::CMN"; |
| David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 1123 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1124 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 1125 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 1126 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1127 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 1128 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1129 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1130 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1131 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 1132 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 1133 | case ARMISD::RRX: return "ARMISD::RRX"; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1134 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 1135 | case ARMISD::ADDC: return "ARMISD::ADDC"; |
| 1136 | case ARMISD::ADDE: return "ARMISD::ADDE"; |
| 1137 | case ARMISD::SUBC: return "ARMISD::SUBC"; |
| 1138 | case ARMISD::SUBE: return "ARMISD::SUBE"; |
| 1139 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 1140 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 1141 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1142 | |
| Evan Cheng | ec6d7c9 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 1143 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 1144 | case ARMISD::EH_SJLJ_LONGJMP: return "ARMISD::EH_SJLJ_LONGJMP"; |
| 1145 | case ARMISD::EH_SJLJ_SETUP_DISPATCH: return "ARMISD::EH_SJLJ_SETUP_DISPATCH"; |
| Evan Cheng | ec6d7c9 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 1146 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1147 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1148 | |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1149 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1150 | |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 1151 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 1152 | |
| Bob Wilson | 7ed5971 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 1153 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
| Jim Grosbach | 53e8854 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 1154 | |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 1155 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 1156 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 1157 | case ARMISD::WIN__CHKSTK: return "ARMISD:::WIN__CHKSTK"; |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 1158 | case ARMISD::WIN__DBZCHK: return "ARMISD::WIN__DBZCHK"; |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 1159 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1160 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1161 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1162 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1163 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 1164 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1165 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 1166 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
| Bob Wilson | f268d03 | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 1167 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 1168 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1169 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 1170 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 1171 | |
| 1172 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 1173 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 1174 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1175 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 1176 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 1177 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 1178 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 1179 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 1180 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 1181 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 1182 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 1183 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 1184 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 1185 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 1186 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1187 | case ARMISD::VSLI: return "ARMISD::VSLI"; |
| 1188 | case ARMISD::VSRI: return "ARMISD::VSRI"; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1189 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 1190 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 1191 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 1192 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 1193 | case ARMISD::VMOVFPIMM: return "ARMISD::VMOVFPIMM"; |
| Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 1194 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
| Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 1195 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 1196 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 1197 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 1198 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 1199 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 1200 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 1201 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 1202 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 1203 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 1204 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 1205 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 1206 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 1207 | case ARMISD::UMLAL: return "ARMISD::UMLAL"; |
| 1208 | case ARMISD::SMLAL: return "ARMISD::SMLAL"; |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 1209 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
| Jim Grosbach | 6e3b5fa | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 1210 | case ARMISD::BFI: return "ARMISD::BFI"; |
| Bob Wilson | 62a6f7e | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 1211 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 1212 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 1213 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 1214 | case ARMISD::MEMCPY: return "ARMISD::MEMCPY"; |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 1215 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 1216 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 1217 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 1218 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 1219 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 1220 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 1221 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 1222 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 1223 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 1224 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 1225 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 1226 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 1227 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 1228 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 1229 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 1230 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 1231 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 1232 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 1233 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 1234 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1235 | } |
| Matthias Braun | d04893f | 2015-05-07 21:33:59 +0000 | [diff] [blame] | 1236 | return nullptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1237 | } |
| 1238 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1239 | EVT ARMTargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &, |
| 1240 | EVT VT) const { |
| 1241 | if (!VT.isVector()) |
| 1242 | return getPointerTy(DL); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 1243 | return VT.changeVectorElementTypeToInteger(); |
| 1244 | } |
| 1245 | |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1246 | /// getRegClassFor - Return the register class that should be used for the |
| 1247 | /// specified value type. |
| Patrik Hagglund | 5e6c361 | 2012-12-13 06:34:11 +0000 | [diff] [blame] | 1248 | const TargetRegisterClass *ARMTargetLowering::getRegClassFor(MVT VT) const { |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1249 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 1250 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 1251 | // load / store 4 to 8 consecutive D registers. |
| Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1252 | if (Subtarget->hasNEON()) { |
| 1253 | if (VT == MVT::v4i64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 1254 | return &ARM::QQPRRegClass; |
| 1255 | if (VT == MVT::v8i64) |
| 1256 | return &ARM::QQQQPRRegClass; |
| Evan Cheng | 3d214cd | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 1257 | } |
| Evan Cheng | 4cad68e | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 1258 | return TargetLowering::getRegClassFor(VT); |
| 1259 | } |
| 1260 | |
| John Brawn | 0dbcd65 | 2015-03-18 12:01:59 +0000 | [diff] [blame] | 1261 | // memcpy, and other memory intrinsics, typically tries to use LDM/STM if the |
| 1262 | // source/dest is aligned and the copy size is large enough. We therefore want |
| 1263 | // to align such objects passed to memory intrinsics. |
| 1264 | bool ARMTargetLowering::shouldAlignPointerArgs(CallInst *CI, unsigned &MinSize, |
| 1265 | unsigned &PrefAlign) const { |
| 1266 | if (!isa<MemIntrinsic>(CI)) |
| 1267 | return false; |
| 1268 | MinSize = 8; |
| 1269 | // On ARM11 onwards (excluding M class) 8-byte aligned LDM is typically 1 |
| 1270 | // cycle faster than 4-byte aligned LDM. |
| 1271 | PrefAlign = (Subtarget->hasV6Ops() && !Subtarget->isMClass() ? 8 : 4); |
| 1272 | return true; |
| 1273 | } |
| 1274 | |
| Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1275 | // Create a fast isel object. |
| 1276 | FastISel * |
| Bob Wilson | 3e6fa46 | 2012-08-03 04:06:28 +0000 | [diff] [blame] | 1277 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo, |
| 1278 | const TargetLibraryInfo *libInfo) const { |
| 1279 | return ARM::createFastISel(funcInfo, libInfo); |
| Eric Christopher | 84bdfd8 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 1280 | } |
| 1281 | |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1282 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1283 | unsigned NumVals = N->getNumValues(); |
| 1284 | if (!NumVals) |
| 1285 | return Sched::RegPressure; |
| 1286 | |
| 1287 | for (unsigned i = 0; i != NumVals; ++i) { |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1288 | EVT VT = N->getValueType(i); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1289 | if (VT == MVT::Glue || VT == MVT::Other) |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1290 | continue; |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1291 | if (VT.isFloatingPoint() || VT.isVector()) |
| Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1292 | return Sched::ILP; |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1293 | } |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1294 | |
| 1295 | if (!N->isMachineOpcode()) |
| 1296 | return Sched::RegPressure; |
| 1297 | |
| 1298 | // Load are scheduled for latency even if there instruction itinerary |
| 1299 | // is not available. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 1300 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1301 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1302 | |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1303 | if (MCID.getNumDefs() == 0) |
| Evan Cheng | 0c4c5ca | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 1304 | return Sched::RegPressure; |
| 1305 | if (!Itins->isEmpty() && |
| Evan Cheng | 6cc775f | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 1306 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
| Dan Gohman | 4ed1afa | 2011-10-24 17:55:11 +0000 | [diff] [blame] | 1307 | return Sched::ILP; |
| Evan Cheng | bf91499 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 1308 | |
| Evan Cheng | 4401f88 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 1309 | return Sched::RegPressure; |
| 1310 | } |
| 1311 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1312 | //===----------------------------------------------------------------------===// |
| 1313 | // Lowering Code |
| 1314 | //===----------------------------------------------------------------------===// |
| 1315 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1316 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 1317 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 1318 | switch (CC) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1319 | default: llvm_unreachable("Unknown condition code!"); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1320 | case ISD::SETNE: return ARMCC::NE; |
| 1321 | case ISD::SETEQ: return ARMCC::EQ; |
| 1322 | case ISD::SETGT: return ARMCC::GT; |
| 1323 | case ISD::SETGE: return ARMCC::GE; |
| 1324 | case ISD::SETLT: return ARMCC::LT; |
| 1325 | case ISD::SETLE: return ARMCC::LE; |
| 1326 | case ISD::SETUGT: return ARMCC::HI; |
| 1327 | case ISD::SETUGE: return ARMCC::HS; |
| 1328 | case ISD::SETULT: return ARMCC::LO; |
| 1329 | case ISD::SETULE: return ARMCC::LS; |
| 1330 | } |
| 1331 | } |
| 1332 | |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1333 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 1334 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1335 | ARMCC::CondCodes &CondCode2) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1336 | CondCode2 = ARMCC::AL; |
| 1337 | switch (CC) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1338 | default: llvm_unreachable("Unknown FP condition!"); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1339 | case ISD::SETEQ: |
| 1340 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 1341 | case ISD::SETGT: |
| 1342 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 1343 | case ISD::SETGE: |
| 1344 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 1345 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1346 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1347 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1348 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1349 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1350 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1351 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1352 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1353 | case ISD::SETLT: |
| 1354 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1355 | case ISD::SETLE: |
| 1356 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1357 | case ISD::SETNE: |
| 1358 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1359 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1362 | //===----------------------------------------------------------------------===// |
| 1363 | // Calling Convention Implementation |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1364 | //===----------------------------------------------------------------------===// |
| 1365 | |
| 1366 | #include "ARMGenCallingConv.inc" |
| 1367 | |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1368 | /// getEffectiveCallingConv - Get the effective calling convention, taking into |
| 1369 | /// account presence of floating point hardware and calling convention |
| 1370 | /// limitations, such as support for variadic functions. |
| 1371 | CallingConv::ID |
| 1372 | ARMTargetLowering::getEffectiveCallingConv(CallingConv::ID CC, |
| 1373 | bool isVarArg) const { |
| Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1374 | switch (CC) { |
| 1375 | default: |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1376 | llvm_unreachable("Unsupported calling convention"); |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1377 | case CallingConv::ARM_AAPCS: |
| 1378 | case CallingConv::ARM_APCS: |
| 1379 | case CallingConv::GHC: |
| 1380 | return CC; |
| Roman Levenstein | 2792b3f | 2016-03-10 04:35:09 +0000 | [diff] [blame] | 1381 | case CallingConv::PreserveMost: |
| 1382 | return CallingConv::PreserveMost; |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1383 | case CallingConv::ARM_AAPCS_VFP: |
| 1384 | return isVarArg ? CallingConv::ARM_AAPCS : CallingConv::ARM_AAPCS_VFP; |
| 1385 | case CallingConv::C: |
| Evan Cheng | 08dd8c8 | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1386 | if (!Subtarget->isAAPCS_ABI()) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1387 | return CallingConv::ARM_APCS; |
| Oliver Stannard | b5e596f | 2014-06-13 08:33:03 +0000 | [diff] [blame] | 1388 | else if (Subtarget->hasVFP2() && !Subtarget->isThumb1Only() && |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 1389 | getTargetMachine().Options.FloatABIType == FloatABI::Hard && |
| 1390 | !isVarArg) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 1391 | return CallingConv::ARM_AAPCS_VFP; |
| 1392 | else |
| 1393 | return CallingConv::ARM_AAPCS; |
| 1394 | case CallingConv::Fast: |
| Manman Ren | 1602605 | 2016-01-11 23:50:43 +0000 | [diff] [blame] | 1395 | case CallingConv::CXX_FAST_TLS: |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 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); |
| Roman Levenstein | 2792b3f | 2016-03-10 04:35:09 +0000 | [diff] [blame] | 1425 | case CallingConv::PreserveMost: |
| 1426 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| Anton Korobeynikov | a8fd40b | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1430 | /// LowerCallResult - Lower the result values of a call into the |
| 1431 | /// appropriate copies out of appropriate physical registers. |
| 1432 | SDValue |
| 1433 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1434 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1435 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1436 | SDLoc dl, SelectionDAG &DAG, |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1437 | SmallVectorImpl<SDValue> &InVals, |
| 1438 | bool isThisReturn, SDValue ThisVal) const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1439 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1440 | // Assign locations to each value returned by this call. |
| 1441 | SmallVector<CCValAssign, 16> RVLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1442 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 1443 | *DAG.getContext(), Call); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1444 | CCInfo.AnalyzeCallResult(Ins, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1445 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1446 | isVarArg)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1447 | |
| 1448 | // Copy all of the result registers out of their specified physreg. |
| 1449 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1450 | CCValAssign VA = RVLocs[i]; |
| 1451 | |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1452 | // Pass 'this' value directly from the argument to return value, to avoid |
| 1453 | // reg unit interference |
| 1454 | if (i == 0 && isThisReturn) { |
| Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1455 | assert(!VA.needsCustom() && VA.getLocVT() == MVT::i32 && |
| 1456 | "unexpected return calling convention register assignment"); |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1457 | InVals.push_back(ThisVal); |
| 1458 | continue; |
| 1459 | } |
| 1460 | |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1461 | SDValue Val; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1462 | if (VA.needsCustom()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1463 | // Handle f64 or half of a v2f64. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1464 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1465 | InFlag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1466 | Chain = Lo.getValue(1); |
| 1467 | InFlag = Lo.getValue(2); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1468 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1469 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1470 | InFlag); |
| 1471 | Chain = Hi.getValue(1); |
| 1472 | InFlag = Hi.getValue(2); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1473 | if (!Subtarget->isLittle()) |
| 1474 | std::swap (Lo, Hi); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1475 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1476 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1477 | if (VA.getLocVT() == MVT::v2f64) { |
| 1478 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1479 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1480 | DAG.getConstant(0, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1481 | |
| 1482 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1483 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1484 | Chain = Lo.getValue(1); |
| 1485 | InFlag = Lo.getValue(2); |
| 1486 | VA = RVLocs[++i]; // skip ahead to next loc |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1487 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1488 | Chain = Hi.getValue(1); |
| 1489 | InFlag = Hi.getValue(2); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1490 | if (!Subtarget->isLittle()) |
| 1491 | std::swap (Lo, Hi); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1492 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1493 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1494 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1495 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1496 | } else { |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1497 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1498 | InFlag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1499 | Chain = Val.getValue(1); |
| 1500 | InFlag = Val.getValue(2); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1501 | } |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1502 | |
| 1503 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1504 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1505 | case CCValAssign::Full: break; |
| 1506 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1507 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
| Bob Wilson | 0041bd3 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1508 | break; |
| 1509 | } |
| 1510 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1511 | InVals.push_back(Val); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1514 | return Chain; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1517 | /// LowerMemOpCallTo - Store the argument to the stack. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1518 | SDValue |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1519 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1520 | SDValue StackPtr, SDValue Arg, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1521 | SDLoc dl, SelectionDAG &DAG, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1522 | const CCValAssign &VA, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1523 | ISD::ArgFlagsTy Flags) const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1524 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1525 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1526 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(DAG.getDataLayout()), |
| 1527 | StackPtr, PtrOff); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1528 | return DAG.getStore( |
| 1529 | Chain, dl, Arg, PtrOff, |
| 1530 | MachinePointerInfo::getStack(DAG.getMachineFunction(), LocMemOffset), |
| 1531 | false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 1534 | void ARMTargetLowering::PassF64ArgInRegs(SDLoc dl, SelectionDAG &DAG, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1535 | SDValue Chain, SDValue &Arg, |
| 1536 | RegsToPassVector &RegsToPass, |
| 1537 | CCValAssign &VA, CCValAssign &NextVA, |
| 1538 | SDValue &StackPtr, |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1539 | SmallVectorImpl<SDValue> &MemOpChains, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1540 | ISD::ArgFlagsTy Flags) const { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1541 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1542 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1543 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1544 | unsigned id = Subtarget->isLittle() ? 0 : 1; |
| 1545 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd.getValue(id))); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1546 | |
| 1547 | if (NextVA.isRegLoc()) |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1548 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1-id))); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1549 | else { |
| 1550 | assert(NextVA.isMemLoc()); |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 1551 | if (!StackPtr.getNode()) |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1552 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, |
| 1553 | getPointerTy(DAG.getDataLayout())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1554 | |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 1555 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1-id), |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1556 | dl, DAG, NextVA, |
| 1557 | Flags)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1558 | } |
| 1559 | } |
| 1560 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1561 | /// LowerCall - Lowering a call into a callseq_start <- |
| Evan Cheng | 4b6c8f7 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1562 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1563 | /// nodes. |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1564 | SDValue |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1565 | ARMTargetLowering::LowerCall(TargetLowering::CallLoweringInfo &CLI, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1566 | SmallVectorImpl<SDValue> &InVals) const { |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1567 | SelectionDAG &DAG = CLI.DAG; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1568 | SDLoc &dl = CLI.DL; |
| Craig Topper | b94011f | 2013-07-14 04:42:23 +0000 | [diff] [blame] | 1569 | SmallVectorImpl<ISD::OutputArg> &Outs = CLI.Outs; |
| 1570 | SmallVectorImpl<SDValue> &OutVals = CLI.OutVals; |
| 1571 | SmallVectorImpl<ISD::InputArg> &Ins = CLI.Ins; |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 1572 | SDValue Chain = CLI.Chain; |
| 1573 | SDValue Callee = CLI.Callee; |
| 1574 | bool &isTailCall = CLI.IsTailCall; |
| 1575 | CallingConv::ID CallConv = CLI.CallConv; |
| 1576 | bool doesNotRet = CLI.DoesNotReturn; |
| 1577 | bool isVarArg = CLI.IsVarArg; |
| 1578 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1579 | MachineFunction &MF = DAG.getMachineFunction(); |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1580 | bool isStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1581 | bool isThisReturn = false; |
| 1582 | bool isSibCall = false; |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 1583 | auto Attr = MF.getFunction()->getFnAttribute("disable-tail-calls"); |
| Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1584 | |
| Bob Wilson | 8decdc4 | 2011-10-07 17:17:49 +0000 | [diff] [blame] | 1585 | // Disable tail calls if they're not supported. |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 1586 | if (!Subtarget->supportsTailCall() || Attr.getValueAsString() == "true") |
| Bob Wilson | 3c9ed76 | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1587 | isTailCall = false; |
| Saleem Abdulrasool | 0d96f3d | 2014-03-11 15:09:54 +0000 | [diff] [blame] | 1588 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1589 | if (isTailCall) { |
| 1590 | // Check if it's really possible to do a tail call. |
| 1591 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1592 | isVarArg, isStructRet, MF.getFunction()->hasStructRetAttr(), |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1593 | Outs, OutVals, Ins, DAG); |
| Reid Kleckner | 5772b77 | 2014-04-24 20:14:34 +0000 | [diff] [blame] | 1594 | if (!isTailCall && CLI.CS && CLI.CS->isMustTailCall()) |
| 1595 | report_fatal_error("failed to perform tail call elimination on a call " |
| 1596 | "site marked musttail"); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1597 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1598 | // detected sibcalls. |
| 1599 | if (isTailCall) { |
| 1600 | ++NumTailCalls; |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1601 | isSibCall = true; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1602 | } |
| 1603 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1604 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1605 | // Analyze operands of the call, assigning locations to each operand. |
| 1606 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 1607 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 1608 | *DAG.getContext(), Call); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1609 | CCInfo.AnalyzeCallOperands(Outs, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1610 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1611 | isVarArg)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1612 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1613 | // Get a count of how many bytes are to be pushed on the stack. |
| 1614 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1615 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1616 | // For tail calls, memory operands are available in our caller's stack. |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1617 | if (isSibCall) |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1618 | NumBytes = 0; |
| 1619 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1620 | // Adjust the stack pointer for the new arguments... |
| 1621 | // These operations are automatically eliminated by the prolog/epilog pass |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1622 | if (!isSibCall) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1623 | Chain = DAG.getCALLSEQ_START(Chain, |
| 1624 | DAG.getIntPtrConstant(NumBytes, dl, true), dl); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1625 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1626 | SDValue StackPtr = |
| 1627 | DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy(DAG.getDataLayout())); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1628 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1629 | RegsToPassVector RegsToPass; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1630 | SmallVector<SDValue, 8> MemOpChains; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1631 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1632 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1633 | // of tail call optimization, arguments are handled later. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1634 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1635 | i != e; |
| 1636 | ++i, ++realArgIdx) { |
| 1637 | CCValAssign &VA = ArgLocs[i]; |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1638 | SDValue Arg = OutVals[realArgIdx]; |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1639 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1640 | bool isByVal = Flags.isByVal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1641 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1642 | // Promote the value if needed. |
| 1643 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1644 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1645 | case CCValAssign::Full: break; |
| 1646 | case CCValAssign::SExt: |
| 1647 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1648 | break; |
| 1649 | case CCValAssign::ZExt: |
| 1650 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1651 | break; |
| 1652 | case CCValAssign::AExt: |
| 1653 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1654 | break; |
| 1655 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1656 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1657 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1660 | // 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] | 1661 | if (VA.needsCustom()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1662 | if (VA.getLocVT() == MVT::v2f64) { |
| 1663 | SDValue Op0 = 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(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1665 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1666 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1667 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1668 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1669 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1670 | |
| 1671 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1672 | if (VA.isRegLoc()) { |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1673 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1674 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1675 | } else { |
| 1676 | assert(VA.isMemLoc()); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1677 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1678 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1679 | dl, DAG, VA, Flags)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1680 | } |
| 1681 | } else { |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1682 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1683 | StackPtr, MemOpChains, Flags); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1684 | } |
| 1685 | } else if (VA.isRegLoc()) { |
| Stephen Lin | 8118e0b | 2013-04-23 19:42:25 +0000 | [diff] [blame] | 1686 | if (realArgIdx == 0 && Flags.isReturned() && Outs[0].VT == MVT::i32) { |
| 1687 | assert(VA.getLocVT() == MVT::i32 && |
| 1688 | "unexpected calling convention register assignment"); |
| 1689 | assert(!Ins.empty() && Ins[0].VT == MVT::i32 && |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1690 | "unexpected use of 'returned'"); |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1691 | isThisReturn = true; |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1692 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1693 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1694 | } else if (isByVal) { |
| 1695 | assert(VA.isMemLoc()); |
| 1696 | unsigned offset = 0; |
| 1697 | |
| 1698 | // True if this byval aggregate will be split between registers |
| 1699 | // and memory. |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1700 | unsigned ByValArgsCount = CCInfo.getInRegsParamsCount(); |
| Daniel Sanders | 8104b75 | 2014-11-01 19:32:23 +0000 | [diff] [blame] | 1701 | unsigned CurByValIdx = CCInfo.getInRegsParamsProcessed(); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1702 | |
| 1703 | if (CurByValIdx < ByValArgsCount) { |
| 1704 | |
| 1705 | unsigned RegBegin, RegEnd; |
| 1706 | CCInfo.getInRegsParamInfo(CurByValIdx, RegBegin, RegEnd); |
| 1707 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1708 | EVT PtrVT = |
| 1709 | DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1710 | unsigned int i, j; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1711 | for (i = 0, j = RegBegin; j < RegEnd; i++, j++) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1712 | SDValue Const = DAG.getConstant(4*i, dl, MVT::i32); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1713 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1714 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1715 | MachinePointerInfo(), |
| Manman Ren | 5a78755 | 2013-10-07 19:47:53 +0000 | [diff] [blame] | 1716 | false, false, false, |
| 1717 | DAG.InferPtrAlignment(AddArg)); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1718 | MemOpChains.push_back(Load.getValue(1)); |
| 1719 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1720 | } |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1721 | |
| 1722 | // If parameter size outsides register area, "offset" value |
| 1723 | // helps us to calculate stack slot for remained part properly. |
| 1724 | offset = RegEnd - RegBegin; |
| 1725 | |
| 1726 | CCInfo.nextInRegsParam(); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1729 | if (Flags.getByValSize() > 4*offset) { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1730 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1731 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1732 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1733 | SDValue Dst = DAG.getNode(ISD::ADD, dl, PtrVT, StackPtr, StkPtrOff); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1734 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset, dl); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1735 | SDValue Src = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, SrcOffset); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1736 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, dl, |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1737 | MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1738 | SDValue AlignNode = DAG.getConstant(Flags.getByValAlign(), dl, |
| 1739 | MVT::i32); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1740 | |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1741 | SDVTList VTs = DAG.getVTList(MVT::Other, MVT::Glue); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 1742 | SDValue Ops[] = { Chain, Dst, Src, SizeNode, AlignNode}; |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1743 | MemOpChains.push_back(DAG.getNode(ARMISD::COPY_STRUCT_BYVAL, dl, VTs, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1744 | Ops)); |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 1745 | } |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1746 | } else if (!isSibCall) { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1747 | assert(VA.isMemLoc()); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1748 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1749 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1750 | dl, DAG, VA, Flags)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1751 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1752 | } |
| 1753 | |
| 1754 | if (!MemOpChains.empty()) |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1755 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOpChains); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1756 | |
| 1757 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1758 | // and flag operands which copy the outgoing args into the appropriate regs. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1759 | SDValue InFlag; |
| Dale Johannesen | 44f9dfc | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1760 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1761 | // tail call optimization the copies to registers are lowered later. |
| 1762 | if (!isTailCall) |
| 1763 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1764 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1765 | RegsToPass[i].second, InFlag); |
| 1766 | InFlag = Chain.getValue(1); |
| 1767 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1768 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1769 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1770 | if (isTailCall) { |
| 1771 | // Force all the incoming stack arguments to be loaded from the stack |
| 1772 | // before any new outgoing arguments are stored to the stack, because the |
| 1773 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1774 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1775 | // than necessary, because it means that each store effectively depends |
| 1776 | // on every argument instead of just those arguments it would clobber. |
| 1777 | |
| Chris Lattner | 0ab5e2c | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1778 | // Do not flag preceding copytoreg stuff together with the following stuff. |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1779 | InFlag = SDValue(); |
| 1780 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1781 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1782 | RegsToPass[i].second, InFlag); |
| 1783 | InFlag = Chain.getValue(1); |
| 1784 | } |
| Stephen Lin | d36fd2c | 2013-04-20 00:47:48 +0000 | [diff] [blame] | 1785 | InFlag = SDValue(); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1786 | } |
| 1787 | |
| Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1788 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1789 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1790 | // node so that legalize doesn't hack it. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1791 | bool isDirect = false; |
| 1792 | bool isARMFunc = false; |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1793 | bool isLocalARMFunc = false; |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1794 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1795 | auto PtrVt = getPointerTy(DAG.getDataLayout()); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1796 | |
| Akira Hatanaka | 1bc8af7 | 2015-07-07 06:54:42 +0000 | [diff] [blame] | 1797 | if (Subtarget->genLongCalls()) { |
| Saleem Abdulrasool | 90386ad | 2014-06-07 20:29:27 +0000 | [diff] [blame] | 1798 | assert((Subtarget->isTargetWindows() || |
| 1799 | getTargetMachine().getRelocationModel() == Reloc::Static) && |
| 1800 | "long-calls with non-static relocation model!"); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1801 | // Handle a global address or an external symbol. If it's not one of |
| 1802 | // those, the target's already in a register, so we don't need to do |
| 1803 | // anything extra. |
| 1804 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Anders Carlsson | 47bccf7 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1805 | const GlobalValue *GV = G->getGlobal(); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1806 | // Create a constant pool entry for the callee address |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1807 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 1808 | ARMConstantPoolValue *CPV = |
| 1809 | ARMConstantPoolConstant::Create(GV, ARMPCLabelIndex, ARMCP::CPValue, 0); |
| 1810 | |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1811 | // Get the address of the callee into a register |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1812 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1813 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1814 | Callee = DAG.getLoad( |
| 1815 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1816 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1817 | false, false, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1818 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1819 | const char *Sym = S->getSymbol(); |
| 1820 | |
| 1821 | // Create a constant pool entry for the callee address |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1822 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1823 | ARMConstantPoolValue *CPV = |
| 1824 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1825 | ARMPCLabelIndex, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1826 | // Get the address of the callee into a register |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1827 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1828 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1829 | Callee = DAG.getLoad( |
| 1830 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1831 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1832 | false, false, 0); |
| Jim Grosbach | 32bb362 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1833 | } |
| 1834 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1835 | const GlobalValue *GV = G->getGlobal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1836 | isDirect = true; |
| Peter Collingbourne | 6a9d177 | 2015-07-05 20:52:35 +0000 | [diff] [blame] | 1837 | bool isDef = GV->isStrongDefinitionForLinker(); |
| 1838 | bool isStub = (!isDef && Subtarget->isTargetMachO()) && |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1839 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| Tim Northover | 2a417b9 | 2014-08-06 11:13:14 +0000 | [diff] [blame] | 1840 | isARMFunc = !Subtarget->isThumb() || (isStub && !Subtarget->isMClass()); |
| Evan Cheng | c3c949b4 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1841 | // ARM call to a local ARM function is predicable. |
| Peter Collingbourne | 6a9d177 | 2015-07-05 20:52:35 +0000 | [diff] [blame] | 1842 | isLocalARMFunc = !Subtarget->isThumb() && (isDef || !ARMInterworking); |
| Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1843 | // tBX takes a register source operand. |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 1844 | if (isStub && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1845 | assert(Subtarget->isTargetMachO() && "WrapperPIC use on non-MachO?"); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1846 | Callee = DAG.getNode( |
| 1847 | ARMISD::WrapperPIC, dl, PtrVt, |
| 1848 | DAG.getTargetGlobalAddress(GV, dl, PtrVt, 0, ARMII::MO_NONLAZY)); |
| 1849 | Callee = DAG.getLoad(PtrVt, dl, DAG.getEntryNode(), Callee, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1850 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 1851 | false, false, true, 0); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 1852 | } else if (Subtarget->isTargetCOFF()) { |
| 1853 | assert(Subtarget->isTargetWindows() && |
| 1854 | "Windows is the only supported COFF target"); |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 1855 | unsigned TargetFlags = GV->hasDLLImportStorageClass() |
| 1856 | ? ARMII::MO_DLLIMPORT |
| 1857 | : ARMII::MO_NO_FLAG; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1858 | Callee = |
| 1859 | DAG.getTargetGlobalAddress(GV, dl, PtrVt, /*Offset=*/0, TargetFlags); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 1860 | if (GV->hasDLLImportStorageClass()) |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1861 | Callee = |
| 1862 | DAG.getLoad(PtrVt, dl, DAG.getEntryNode(), |
| 1863 | DAG.getNode(ARMISD::Wrapper, dl, PtrVt, Callee), |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1864 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 1865 | false, false, false, 0); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1866 | } else { |
| 1867 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1868 | unsigned OpFlags = 0; |
| 1869 | if (Subtarget->isTargetELF() && |
| Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 1870 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1871 | OpFlags = ARMII::MO_PLT; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1872 | Callee = DAG.getTargetGlobalAddress(GV, dl, PtrVt, 0, OpFlags); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1873 | } |
| Bill Wendling | 24c79f2 | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1874 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1875 | isDirect = true; |
| Tim Northover | d6a729b | 2014-01-06 14:28:05 +0000 | [diff] [blame] | 1876 | bool isStub = Subtarget->isTargetMachO() && |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1877 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| Tim Northover | 2a417b9 | 2014-08-06 11:13:14 +0000 | [diff] [blame] | 1878 | isARMFunc = !Subtarget->isThumb() || (isStub && !Subtarget->isMClass()); |
| Evan Cheng | 83f3517 | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1879 | // tBX takes a register source operand. |
| 1880 | const char *Sym = S->getSymbol(); |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1881 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1882 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | c214cb0 | 2011-10-01 08:58:29 +0000 | [diff] [blame] | 1883 | ARMConstantPoolValue *CPV = |
| 1884 | ARMConstantPoolSymbol::Create(*DAG.getContext(), Sym, |
| 1885 | ARMPCLabelIndex, 4); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1886 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVt, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1887 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 1888 | Callee = DAG.getLoad( |
| 1889 | PtrVt, dl, DAG.getEntryNode(), CPAddr, |
| 1890 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 1891 | false, false, 0); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1892 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1893 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVt, Callee, PICLabel); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1894 | } else { |
| 1895 | unsigned OpFlags = 0; |
| 1896 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1897 | if (Subtarget->isTargetELF() && |
| 1898 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1899 | OpFlags = ARMII::MO_PLT; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 1900 | Callee = DAG.getTargetExternalSymbol(Sym, PtrVt, OpFlags); |
| Jim Grosbach | 85dcd3d | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1901 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1902 | } |
| 1903 | |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1904 | // FIXME: handle tail calls differently. |
| 1905 | unsigned CallOpc; |
| Evan Cheng | 6ab54fd | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1906 | if (Subtarget->isThumb()) { |
| 1907 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1908 | CallOpc = ARMISD::CALL_NOLINK; |
| 1909 | else |
| 1910 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1911 | } else { |
| Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1912 | if (!isDirect && !Subtarget->hasV5TOps()) |
| Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1913 | CallOpc = ARMISD::CALL_NOLINK; |
| Evan Cheng | 21b0348 | 2012-11-10 02:09:05 +0000 | [diff] [blame] | 1914 | else if (doesNotRet && isDirect && Subtarget->hasRAS() && |
| Sanjay Patel | 924879a | 2015-08-04 15:49:57 +0000 | [diff] [blame] | 1915 | // Emit regular call when code size is the priority |
| 1916 | !MF.getFunction()->optForMinSize()) |
| Evan Cheng | 65f9d19 | 2012-02-28 18:51:51 +0000 | [diff] [blame] | 1917 | // "mov lr, pc; b _foo" to avoid confusing the RSP |
| 1918 | CallOpc = ARMISD::CALL_NOLINK; |
| 1919 | else |
| 1920 | CallOpc = isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL; |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1921 | } |
| Lauro Ramos Venancio | a88c4a7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1922 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1923 | std::vector<SDValue> Ops; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1924 | Ops.push_back(Chain); |
| 1925 | Ops.push_back(Callee); |
| 1926 | |
| 1927 | // Add argument registers to the end of the list so that they are known live |
| 1928 | // into the call. |
| 1929 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1930 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1931 | RegsToPass[i].second.getValueType())); |
| 1932 | |
| Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1933 | // Add a register mask operand representing the call-preserved registers. |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1934 | if (!isTailCall) { |
| 1935 | const uint32_t *Mask; |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 1936 | const ARMBaseRegisterInfo *ARI = Subtarget->getRegisterInfo(); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1937 | if (isThisReturn) { |
| 1938 | // For 'this' returns, use the R0-preserving mask if applicable |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1939 | Mask = ARI->getThisReturnPreservedMask(MF, CallConv); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1940 | if (!Mask) { |
| 1941 | // Set isThisReturn to false if the calling convention is not one that |
| 1942 | // allows 'returned' to be modeled in this way, so LowerCallResult does |
| 1943 | // not try to pass 'this' straight through |
| 1944 | isThisReturn = false; |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1945 | Mask = ARI->getCallPreservedMask(MF, CallConv); |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1946 | } |
| 1947 | } else |
| Eric Christopher | 9deb75d | 2015-03-11 22:42:13 +0000 | [diff] [blame] | 1948 | Mask = ARI->getCallPreservedMask(MF, CallConv); |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1949 | |
| Matthias Braun | c22630e | 2013-10-04 16:52:54 +0000 | [diff] [blame] | 1950 | assert(Mask && "Missing call preserved mask for calling convention"); |
| 1951 | Ops.push_back(DAG.getRegisterMask(Mask)); |
| 1952 | } |
| Jakob Stoklund Olesen | fa7a537 | 2012-02-24 01:19:29 +0000 | [diff] [blame] | 1953 | |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1954 | if (InFlag.getNode()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1955 | Ops.push_back(InFlag); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1956 | |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1957 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 1958 | if (isTailCall) { |
| 1959 | MF.getFrameInfo()->setHasTailCall(); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1960 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, Ops); |
| Arnold Schwaighofer | f54b73d | 2015-05-08 23:52:00 +0000 | [diff] [blame] | 1961 | } |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1962 | |
| Duncan Sands | 739a054 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1963 | // Returns a chain and a flag for retval copy to use. |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 1964 | Chain = DAG.getNode(CallOpc, dl, NodeTys, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1965 | InFlag = Chain.getValue(1); |
| 1966 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 1967 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, dl, true), |
| 1968 | DAG.getIntPtrConstant(0, dl, true), InFlag, dl); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1969 | if (!Ins.empty()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1970 | InFlag = Chain.getValue(1); |
| 1971 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1972 | // Handle result values, copying them out of physregs into vregs that we |
| 1973 | // return. |
| Stephen Lin | b8bd232 | 2013-04-20 05:14:40 +0000 | [diff] [blame] | 1974 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, dl, DAG, |
| Stephen Lin | 4eedb29 | 2013-04-23 19:30:12 +0000 | [diff] [blame] | 1975 | InVals, isThisReturn, |
| 1976 | isThisReturn ? OutVals[0] : SDValue()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1977 | } |
| 1978 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1979 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1980 | /// on the stack. Remember the next parameter register to allocate, |
| 1981 | /// and then confiscate the rest of the parameter registers to insure |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1982 | /// this. |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1983 | void ARMTargetLowering::HandleByVal(CCState *State, unsigned &Size, |
| 1984 | unsigned Align) const { |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1985 | assert((State->getCallOrPrologue() == Prologue || |
| 1986 | State->getCallOrPrologue() == Call) && |
| 1987 | "unhandled ParmContext"); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1988 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1989 | // Byval (as with any stack) slots are always at least 4 byte aligned. |
| 1990 | Align = std::max(Align, 4U); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1991 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1992 | unsigned Reg = State->AllocateReg(GPRArgRegs); |
| 1993 | if (!Reg) |
| 1994 | return; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 1995 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 1996 | unsigned AlignInRegs = Align / 4; |
| 1997 | unsigned Waste = (ARM::R4 - Reg) % AlignInRegs; |
| 1998 | for (unsigned i = 0; i < Waste; ++i) |
| 1999 | Reg = State->AllocateReg(GPRArgRegs); |
| 2000 | |
| 2001 | if (!Reg) |
| 2002 | return; |
| 2003 | |
| 2004 | unsigned Excess = 4 * (ARM::R4 - Reg); |
| 2005 | |
| 2006 | // Special case when NSAA != SP and parameter size greater than size of |
| 2007 | // all remained GPR regs. In that case we can't split parameter, we must |
| 2008 | // send it to stack. We also must set NCRN to R4, so waste all |
| 2009 | // remained registers. |
| 2010 | const unsigned NSAAOffset = State->getNextStackOffset(); |
| 2011 | if (NSAAOffset != 0 && Size > Excess) { |
| 2012 | while (State->AllocateReg(GPRArgRegs)) |
| 2013 | ; |
| 2014 | return; |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2015 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 2016 | |
| 2017 | // First register for byval parameter is the first register that wasn't |
| 2018 | // allocated before this method call, so it would be "reg". |
| 2019 | // If parameter is small enough to be saved in range [reg, r4), then |
| 2020 | // the end (first after last) register would be reg + param-size-in-regs, |
| 2021 | // else parameter would be splitted between registers and stack, |
| 2022 | // end register would be r4 in this case. |
| 2023 | unsigned ByValRegBegin = Reg; |
| 2024 | unsigned ByValRegEnd = std::min<unsigned>(Reg + Size / 4, ARM::R4); |
| 2025 | State->addInRegsParamInfo(ByValRegBegin, ByValRegEnd); |
| 2026 | // Note, first register is allocated in the beginning of function already, |
| 2027 | // allocate remained amount of registers we need. |
| 2028 | for (unsigned i = Reg + 1; i != ByValRegEnd; ++i) |
| 2029 | State->AllocateReg(GPRArgRegs); |
| 2030 | // A byval parameter that is split between registers and memory needs its |
| 2031 | // size truncated here. |
| 2032 | // In the case where the entire structure fits in registers, we set the |
| 2033 | // size in memory to zero. |
| 2034 | Size = std::max<int>(Size - Excess, 0); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2037 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 2038 | /// already available in the same position (relatively) of the caller's |
| 2039 | /// incoming argument stack. |
| 2040 | static |
| 2041 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 2042 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| Craig Topper | 07720d8 | 2012-03-25 23:49:58 +0000 | [diff] [blame] | 2043 | const TargetInstrInfo *TII) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2044 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 2045 | int FI = INT_MAX; |
| 2046 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 2047 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
| Jakob Stoklund Olesen | 2fb5b31 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 2048 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2049 | return false; |
| 2050 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 2051 | if (!Def) |
| 2052 | return false; |
| 2053 | if (!Flags.isByVal()) { |
| 2054 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 2055 | return false; |
| 2056 | } else { |
| Dale Johannesen | e228928 | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 2057 | return false; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2058 | } |
| 2059 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 2060 | if (Flags.isByVal()) |
| 2061 | // ByVal argument is passed in as a pointer but it's now being |
| 2062 | // dereferenced. e.g. |
| 2063 | // define @foo(%struct.X* %A) { |
| 2064 | // tail call @bar(%struct.X* byval %A) |
| 2065 | // } |
| 2066 | return false; |
| 2067 | SDValue Ptr = Ld->getBasePtr(); |
| 2068 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 2069 | if (!FINode) |
| 2070 | return false; |
| 2071 | FI = FINode->getIndex(); |
| 2072 | } else |
| 2073 | return false; |
| 2074 | |
| 2075 | assert(FI != INT_MAX); |
| 2076 | if (!MFI->isFixedObjectIndex(FI)) |
| 2077 | return false; |
| 2078 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 2079 | } |
| 2080 | |
| 2081 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 2082 | /// for tail call optimization. Targets which want to do tail call |
| 2083 | /// optimization should implement this function. |
| 2084 | bool |
| 2085 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 2086 | CallingConv::ID CalleeCC, |
| 2087 | bool isVarArg, |
| 2088 | bool isCalleeStructRet, |
| 2089 | bool isCallerStructRet, |
| 2090 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2091 | const SmallVectorImpl<SDValue> &OutVals, |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2092 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 2093 | SelectionDAG& DAG) const { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2094 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 2095 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 2096 | bool CCMatch = CallerCC == CalleeCC; |
| 2097 | |
| Artyom Skrobov | ad8a063 | 2015-09-28 09:44:11 +0000 | [diff] [blame] | 2098 | assert(Subtarget->supportsTailCall()); |
| 2099 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2100 | // Look for obvious safe cases to perform tail call optimization that do not |
| 2101 | // require ABI changes. This is what gcc calls sibcall. |
| 2102 | |
| Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2103 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 2104 | // any arguments. |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2105 | if (isVarArg && !Outs.empty()) |
| 2106 | return false; |
| 2107 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2108 | // Exception-handling functions need a special set of instructions to indicate |
| 2109 | // a return to the hardware. Tail-calling another function would probably |
| 2110 | // break this. |
| 2111 | if (CallerF->hasFnAttribute("interrupt")) |
| 2112 | return false; |
| 2113 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2114 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 2115 | // return semantics. |
| 2116 | if (isCalleeStructRet || isCallerStructRet) |
| 2117 | return false; |
| 2118 | |
| Oliver Stannard | 12993dd | 2014-08-18 12:42:15 +0000 | [diff] [blame] | 2119 | // Externally-defined functions with weak linkage should not be |
| 2120 | // tail-called on ARM when the OS does not support dynamic |
| 2121 | // pre-emption of symbols, as the AAELF spec requires normal calls |
| 2122 | // to undefined weak functions to be replaced with a NOP or jump to the |
| 2123 | // next instruction. The behaviour of branch instructions in this |
| 2124 | // situation (as used for tail calls) is implementation-defined, so we |
| 2125 | // cannot rely on the linker replacing the tail call with a return. |
| 2126 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
| 2127 | const GlobalValue *GV = G->getGlobal(); |
| Daniel Sanders | c81f450 | 2015-06-16 15:44:21 +0000 | [diff] [blame] | 2128 | const Triple &TT = getTargetMachine().getTargetTriple(); |
| Saleem Abdulrasool | 67f7299 | 2015-01-03 21:35:00 +0000 | [diff] [blame] | 2129 | if (GV->hasExternalWeakLinkage() && |
| 2130 | (!TT.isOSWindows() || TT.isOSBinFormatELF() || TT.isOSBinFormatMachO())) |
| Oliver Stannard | 12993dd | 2014-08-18 12:42:15 +0000 | [diff] [blame] | 2131 | return false; |
| 2132 | } |
| 2133 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2134 | // If the calling conventions do not match, then we'd better make sure the |
| 2135 | // results are returned in the same way as what the caller expects. |
| 2136 | if (!CCMatch) { |
| 2137 | SmallVector<CCValAssign, 16> RVLocs1; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2138 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), RVLocs1, |
| 2139 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2140 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 2141 | |
| 2142 | SmallVector<CCValAssign, 16> RVLocs2; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2143 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), RVLocs2, |
| 2144 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2145 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 2146 | |
| 2147 | if (RVLocs1.size() != RVLocs2.size()) |
| 2148 | return false; |
| 2149 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 2150 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 2151 | return false; |
| 2152 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 2153 | return false; |
| 2154 | if (RVLocs1[i].isRegLoc()) { |
| 2155 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 2156 | return false; |
| 2157 | } else { |
| 2158 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 2159 | return false; |
| 2160 | } |
| 2161 | } |
| 2162 | } |
| 2163 | |
| Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 2164 | // If Caller's vararg or byval argument has been split between registers and |
| 2165 | // stack, do not perform tail call, since part of the argument is in caller's |
| 2166 | // local frame. |
| 2167 | const ARMFunctionInfo *AFI_Caller = DAG.getMachineFunction(). |
| 2168 | getInfo<ARMFunctionInfo>(); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 2169 | if (AFI_Caller->getArgRegsSaveSize()) |
| Manman Ren | 7e48b25 | 2012-10-12 23:39:43 +0000 | [diff] [blame] | 2170 | return false; |
| 2171 | |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2172 | // If the callee takes no arguments then go on to check the results of the |
| 2173 | // call. |
| 2174 | if (!Outs.empty()) { |
| 2175 | // Check if stack adjustment is needed. For now, do not do this if any |
| 2176 | // argument is passed on the stack. |
| 2177 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2178 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 2179 | *DAG.getContext(), Call); |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2180 | CCInfo.AnalyzeCallOperands(Outs, |
| 2181 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 2182 | if (CCInfo.getNextStackOffset()) { |
| 2183 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2184 | |
| 2185 | // Check if the arguments are already laid out in the right way as |
| 2186 | // the caller's fixed stack objects. |
| 2187 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2188 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 2189 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2190 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 2191 | i != e; |
| 2192 | ++i, ++realArgIdx) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2193 | CCValAssign &VA = ArgLocs[i]; |
| 2194 | EVT RegVT = VA.getLocVT(); |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2195 | SDValue Arg = OutVals[realArgIdx]; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2196 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2197 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 2198 | return false; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2199 | if (VA.needsCustom()) { |
| 2200 | // f64 and vector types are split into multiple registers or |
| 2201 | // register/stack-slot combinations. The types will not match |
| 2202 | // the registers; give up on memory f64 refs until we figure |
| 2203 | // out what to do about this. |
| 2204 | if (!VA.isRegLoc()) |
| 2205 | return false; |
| 2206 | if (!ArgLocs[++i].isRegLoc()) |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 2207 | return false; |
| Dale Johannesen | 81ef35b | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 2208 | if (RegVT == MVT::v2f64) { |
| 2209 | if (!ArgLocs[++i].isRegLoc()) |
| 2210 | return false; |
| 2211 | if (!ArgLocs[++i].isRegLoc()) |
| 2212 | return false; |
| 2213 | } |
| 2214 | } else if (!VA.isRegLoc()) { |
| Dale Johannesen | d679ff7 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 2215 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 2216 | MFI, MRI, TII)) |
| 2217 | return false; |
| 2218 | } |
| 2219 | } |
| 2220 | } |
| 2221 | } |
| 2222 | |
| 2223 | return true; |
| 2224 | } |
| 2225 | |
| Benjamin Kramer | b1996da | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2226 | bool |
| 2227 | ARMTargetLowering::CanLowerReturn(CallingConv::ID CallConv, |
| 2228 | MachineFunction &MF, bool isVarArg, |
| 2229 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| 2230 | LLVMContext &Context) const { |
| 2231 | SmallVector<CCValAssign, 16> RVLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2232 | CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context); |
| Benjamin Kramer | b1996da | 2012-11-28 20:55:10 +0000 | [diff] [blame] | 2233 | return CCInfo.CheckReturn(Outs, CCAssignFnForNode(CallConv, /*Return=*/true, |
| 2234 | isVarArg)); |
| 2235 | } |
| 2236 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2237 | static SDValue LowerInterruptReturn(SmallVectorImpl<SDValue> &RetOps, |
| 2238 | SDLoc DL, SelectionDAG &DAG) { |
| 2239 | const MachineFunction &MF = DAG.getMachineFunction(); |
| 2240 | const Function *F = MF.getFunction(); |
| 2241 | |
| 2242 | StringRef IntKind = F->getFnAttribute("interrupt").getValueAsString(); |
| 2243 | |
| 2244 | // See ARM ARM v7 B1.8.3. On exception entry LR is set to a possibly offset |
| 2245 | // version of the "preferred return address". These offsets affect the return |
| 2246 | // instruction if this is a return from PL1 without hypervisor extensions. |
| 2247 | // IRQ/FIQ: +4 "subs pc, lr, #4" |
| 2248 | // SWI: 0 "subs pc, lr, #0" |
| 2249 | // ABORT: +4 "subs pc, lr, #4" |
| 2250 | // UNDEF: +4/+2 "subs pc, lr, #0" |
| 2251 | // UNDEF varies depending on where the exception came from ARM or Thumb |
| 2252 | // mode. Alongside GCC, we throw our hands up in disgust and pretend it's 0. |
| 2253 | |
| 2254 | int64_t LROffset; |
| 2255 | if (IntKind == "" || IntKind == "IRQ" || IntKind == "FIQ" || |
| 2256 | IntKind == "ABORT") |
| 2257 | LROffset = 4; |
| 2258 | else if (IntKind == "SWI" || IntKind == "UNDEF") |
| 2259 | LROffset = 0; |
| 2260 | else |
| 2261 | report_fatal_error("Unsupported interrupt attribute. If present, value " |
| 2262 | "must be one of: IRQ, FIQ, SWI, ABORT or UNDEF"); |
| 2263 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2264 | RetOps.insert(RetOps.begin() + 1, |
| 2265 | DAG.getConstant(LROffset, DL, MVT::i32, false)); |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2266 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2267 | return DAG.getNode(ARMISD::INTRET_FLAG, DL, MVT::Other, RetOps); |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2270 | SDValue |
| 2271 | ARMTargetLowering::LowerReturn(SDValue Chain, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2272 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2273 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2274 | const SmallVectorImpl<SDValue> &OutVals, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2275 | SDLoc dl, SelectionDAG &DAG) const { |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2276 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2277 | // CCValAssign - represent the assignment of the return value to a location. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2278 | SmallVector<CCValAssign, 16> RVLocs; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2279 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2280 | // CCState - Info about the registers and stack slots. |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 2281 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), RVLocs, |
| 2282 | *DAG.getContext(), Call); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2283 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2284 | // Analyze outgoing return values. |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2285 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 2286 | isVarArg)); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2287 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2288 | SDValue Flag; |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2289 | SmallVector<SDValue, 4> RetOps; |
| 2290 | RetOps.push_back(Chain); // Operand #0 = Chain (updated below) |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2291 | bool isLittleEndian = Subtarget->isLittle(); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2292 | |
| Jonathan Roelofs | ef84bda | 2014-08-05 21:32:21 +0000 | [diff] [blame] | 2293 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2294 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2295 | AFI->setReturnRegsCount(RVLocs.size()); |
| 2296 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2297 | // Copy the result values into the output registers. |
| 2298 | for (unsigned i = 0, realRVLocIdx = 0; |
| 2299 | i != RVLocs.size(); |
| 2300 | ++i, ++realRVLocIdx) { |
| 2301 | CCValAssign &VA = RVLocs[i]; |
| 2302 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 2303 | |
| Dan Gohman | fe7532a | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 2304 | SDValue Arg = OutVals[realRVLocIdx]; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2305 | |
| 2306 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2307 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2308 | case CCValAssign::Full: break; |
| 2309 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2310 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2311 | break; |
| 2312 | } |
| 2313 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2314 | if (VA.needsCustom()) { |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2315 | if (VA.getLocVT() == MVT::v2f64) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2316 | // Extract the first half and return it in two registers. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2317 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2318 | DAG.getConstant(0, dl, MVT::i32)); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2319 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2320 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2321 | |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2322 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2323 | HalfGPRs.getValue(isLittleEndian ? 0 : 1), |
| 2324 | Flag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2325 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2326 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2327 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2328 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2329 | HalfGPRs.getValue(isLittleEndian ? 1 : 0), |
| 2330 | Flag); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2331 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2332 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2333 | VA = RVLocs[++i]; // skip ahead to next loc |
| 2334 | |
| 2335 | // 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] | 2336 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2337 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2338 | } |
| 2339 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 2340 | // available. |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2341 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2342 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2343 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2344 | fmrrd.getValue(isLittleEndian ? 0 : 1), |
| 2345 | Flag); |
| Bob Wilson | f134b2d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 2346 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2347 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2348 | VA = RVLocs[++i]; // skip ahead to next loc |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 2349 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 2350 | fmrrd.getValue(isLittleEndian ? 1 : 0), |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2351 | Flag); |
| 2352 | } else |
| 2353 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 2354 | |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2355 | // Guarantee that all emitted copies are |
| 2356 | // stuck together, avoiding something bad. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2357 | Flag = Chain.getValue(1); |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2358 | RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT())); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2359 | } |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 2360 | const ARMBaseRegisterInfo *TRI = Subtarget->getRegisterInfo(); |
| 2361 | const MCPhysReg *I = |
| 2362 | TRI->getCalleeSavedRegsViaCopy(&DAG.getMachineFunction()); |
| 2363 | if (I) { |
| 2364 | for (; *I; ++I) { |
| 2365 | if (ARM::GPRRegClass.contains(*I)) |
| 2366 | RetOps.push_back(DAG.getRegister(*I, MVT::i32)); |
| 2367 | else if (ARM::DPRRegClass.contains(*I)) |
| 2368 | RetOps.push_back(DAG.getRegister(*I, MVT::getFloatingPointVT(64))); |
| 2369 | else |
| 2370 | llvm_unreachable("Unexpected register class in CSRsViaCopy!"); |
| 2371 | } |
| 2372 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2373 | |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2374 | // Update chain and glue. |
| 2375 | RetOps[0] = Chain; |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2376 | if (Flag.getNode()) |
| Jakob Stoklund Olesen | f90fb6e | 2013-02-05 18:08:40 +0000 | [diff] [blame] | 2377 | RetOps.push_back(Flag); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2378 | |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2379 | // CPUs which aren't M-class use a special sequence to return from |
| 2380 | // exceptions (roughly, any instruction setting pc and cpsr simultaneously, |
| 2381 | // though we use "subs pc, lr, #N"). |
| 2382 | // |
| 2383 | // M-class CPUs actually use a normal return sequence with a special |
| 2384 | // (hardware-provided) value in LR, so the normal code path works. |
| 2385 | if (DAG.getMachineFunction().getFunction()->hasFnAttribute("interrupt") && |
| 2386 | !Subtarget->isMClass()) { |
| 2387 | if (Subtarget->isThumb1Only()) |
| 2388 | report_fatal_error("interrupt attribute is not supported in Thumb1"); |
| 2389 | return LowerInterruptReturn(RetOps, dl, DAG); |
| 2390 | } |
| 2391 | |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 2392 | return DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, RetOps); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2393 | } |
| 2394 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2395 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N, SDValue &Chain) const { |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2396 | if (N->getNumValues() != 1) |
| 2397 | return false; |
| 2398 | if (!N->hasNUsesOfValue(1, 0)) |
| 2399 | return false; |
| 2400 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2401 | SDValue TCChain = Chain; |
| 2402 | SDNode *Copy = *N->use_begin(); |
| 2403 | if (Copy->getOpcode() == ISD::CopyToReg) { |
| 2404 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2405 | // perform a tail call. |
| 2406 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2407 | return false; |
| 2408 | TCChain = Copy->getOperand(0); |
| 2409 | } else if (Copy->getOpcode() == ARMISD::VMOVRRD) { |
| 2410 | SDNode *VMov = Copy; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2411 | // f64 returned in a pair of GPRs. |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2412 | SmallPtrSet<SDNode*, 2> Copies; |
| 2413 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2414 | UI != UE; ++UI) { |
| 2415 | if (UI->getOpcode() != ISD::CopyToReg) |
| 2416 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2417 | Copies.insert(*UI); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2418 | } |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2419 | if (Copies.size() > 2) |
| 2420 | return false; |
| 2421 | |
| 2422 | for (SDNode::use_iterator UI = VMov->use_begin(), UE = VMov->use_end(); |
| 2423 | UI != UE; ++UI) { |
| 2424 | SDValue UseChain = UI->getOperand(0); |
| 2425 | if (Copies.count(UseChain.getNode())) |
| 2426 | // Second CopyToReg |
| 2427 | Copy = *UI; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2428 | else { |
| 2429 | // We are at the top of this chain. |
| 2430 | // If the copy has a glue operand, we conservatively assume it |
| 2431 | // isn't safe to perform a tail call. |
| 2432 | if (UI->getOperand(UI->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2433 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2434 | // First CopyToReg |
| 2435 | TCChain = UseChain; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2436 | } |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2437 | } |
| 2438 | } else if (Copy->getOpcode() == ISD::BITCAST) { |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2439 | // f32 returned in a single GPR. |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2440 | if (!Copy->hasOneUse()) |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2441 | return false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2442 | Copy = *Copy->use_begin(); |
| 2443 | if (Copy->getOpcode() != ISD::CopyToReg || !Copy->hasNUsesOfValue(1, 0)) |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2444 | return false; |
| Quentin Colombet | 17799fe | 2014-09-18 21:17:50 +0000 | [diff] [blame] | 2445 | // If the copy has a glue operand, we conservatively assume it isn't safe to |
| 2446 | // perform a tail call. |
| 2447 | if (Copy->getOperand(Copy->getNumOperands()-1).getValueType() == MVT::Glue) |
| 2448 | return false; |
| Lang Hames | 67c09b3 | 2013-05-13 10:21:19 +0000 | [diff] [blame] | 2449 | TCChain = Copy->getOperand(0); |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2450 | } else { |
| 2451 | return false; |
| 2452 | } |
| 2453 | |
| Evan Cheng | 419ea28 | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 2454 | bool HasRet = false; |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2455 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 2456 | UI != UE; ++UI) { |
| Tim Northover | d840745 | 2013-10-01 14:33:28 +0000 | [diff] [blame] | 2457 | if (UI->getOpcode() != ARMISD::RET_FLAG && |
| 2458 | UI->getOpcode() != ARMISD::INTRET_FLAG) |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2459 | return false; |
| 2460 | HasRet = true; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2461 | } |
| 2462 | |
| Evan Cheng | f8bad08 | 2012-04-10 01:51:00 +0000 | [diff] [blame] | 2463 | if (!HasRet) |
| 2464 | return false; |
| 2465 | |
| 2466 | Chain = TCChain; |
| 2467 | return true; |
| Evan Cheng | d4b0873 | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 2468 | } |
| 2469 | |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2470 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| Saleem Abdulrasool | b720a6b | 2014-03-11 15:09:49 +0000 | [diff] [blame] | 2471 | if (!Subtarget->supportsTailCall()) |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2472 | return false; |
| 2473 | |
| Akira Hatanaka | d9699bc | 2015-06-09 19:07:19 +0000 | [diff] [blame] | 2474 | auto Attr = |
| 2475 | CI->getParent()->getParent()->getFnAttribute("disable-tail-calls"); |
| 2476 | if (!CI->isTailCall() || Attr.getValueAsString() == "true") |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2477 | return false; |
| 2478 | |
| Artyom Skrobov | ad8a063 | 2015-09-28 09:44:11 +0000 | [diff] [blame] | 2479 | return true; |
| Evan Cheng | 0663f23 | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 2480 | } |
| 2481 | |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 2482 | // Trying to write a 64 bit value so need to split into two 32 bit values first, |
| 2483 | // and pass the lower and high parts through. |
| 2484 | static SDValue LowerWRITE_REGISTER(SDValue Op, SelectionDAG &DAG) { |
| 2485 | SDLoc DL(Op); |
| 2486 | SDValue WriteValue = Op->getOperand(2); |
| 2487 | |
| 2488 | // This function is only supposed to be called for i64 type argument. |
| 2489 | assert(WriteValue.getValueType() == MVT::i64 |
| 2490 | && "LowerWRITE_REGISTER called for non-i64 type argument."); |
| 2491 | |
| 2492 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, WriteValue, |
| 2493 | DAG.getConstant(0, DL, MVT::i32)); |
| 2494 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, WriteValue, |
| 2495 | DAG.getConstant(1, DL, MVT::i32)); |
| 2496 | SDValue Ops[] = { Op->getOperand(0), Op->getOperand(1), Lo, Hi }; |
| 2497 | return DAG.getNode(ISD::WRITE_REGISTER, DL, MVT::Other, Ops); |
| 2498 | } |
| 2499 | |
| Bob Wilson | b389f2a | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 2500 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 2501 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 2502 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 2503 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 2504 | // be used to form addressing mode. These wrapped nodes will be selected |
| 2505 | // into MOVi. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2506 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2507 | EVT PtrVT = Op.getValueType(); |
| Dale Johannesen | 62fd95d | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2508 | // FIXME there is no actual debug info here |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2509 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2510 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2511 | SDValue Res; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2512 | if (CP->isMachineConstantPoolEntry()) |
| 2513 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 2514 | CP->getAlignment()); |
| 2515 | else |
| 2516 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 2517 | CP->getAlignment()); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2518 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2519 | } |
| 2520 | |
| Jim Grosbach | 8d3ba73 | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 2521 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 2522 | return MachineJumpTableInfo::EK_Inline; |
| 2523 | } |
| 2524 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2525 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 2526 | SelectionDAG &DAG) const { |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2527 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2528 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2529 | unsigned ARMPCLabelIndex = 0; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2530 | SDLoc DL(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2531 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2532 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2533 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2534 | SDValue CPAddr; |
| 2535 | if (RelocM == Reloc::Static) { |
| 2536 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 2537 | } else { |
| 2538 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2539 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2540 | ARMConstantPoolValue *CPV = |
| 2541 | ARMConstantPoolConstant::Create(BA, ARMPCLabelIndex, |
| 2542 | ARMCP::CPBlockAddress, PCAdj); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2543 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 2544 | } |
| 2545 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2546 | SDValue Result = |
| 2547 | DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
| 2548 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), |
| 2549 | false, false, false, 0); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2550 | if (RelocM == Reloc::Static) |
| 2551 | return Result; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2552 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, DL, MVT::i32); |
| Bob Wilson | 1c66e8a | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 2553 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 2554 | } |
| 2555 | |
| Tim Northover | bd41cf8 | 2016-01-07 09:03:03 +0000 | [diff] [blame] | 2556 | /// \brief Convert a TLS address reference into the correct sequence of loads |
| 2557 | /// and calls to compute the variable's address for Darwin, and return an |
| 2558 | /// SDValue containing the final node. |
| 2559 | |
| 2560 | /// Darwin only has one TLS scheme which must be capable of dealing with the |
| 2561 | /// fully general situation, in the worst case. This means: |
| 2562 | /// + "extern __thread" declaration. |
| 2563 | /// + Defined in a possibly unknown dynamic library. |
| 2564 | /// |
| 2565 | /// The general system is that each __thread variable has a [3 x i32] descriptor |
| 2566 | /// which contains information used by the runtime to calculate the address. The |
| 2567 | /// only part of this the compiler needs to know about is the first word, which |
| 2568 | /// contains a function pointer that must be called with the address of the |
| 2569 | /// entire descriptor in "r0". |
| 2570 | /// |
| 2571 | /// Since this descriptor may be in a different unit, in general access must |
| 2572 | /// proceed along the usual ARM rules. A common sequence to produce is: |
| 2573 | /// |
| 2574 | /// movw rT1, :lower16:_var$non_lazy_ptr |
| 2575 | /// movt rT1, :upper16:_var$non_lazy_ptr |
| 2576 | /// ldr r0, [rT1] |
| 2577 | /// ldr rT2, [r0] |
| 2578 | /// blx rT2 |
| 2579 | /// [...address now in r0...] |
| 2580 | SDValue |
| 2581 | ARMTargetLowering::LowerGlobalTLSAddressDarwin(SDValue Op, |
| 2582 | SelectionDAG &DAG) const { |
| 2583 | assert(Subtarget->isTargetDarwin() && "TLS only supported on Darwin"); |
| 2584 | SDLoc DL(Op); |
| 2585 | |
| 2586 | // First step is to get the address of the actua global symbol. This is where |
| 2587 | // the TLS descriptor lives. |
| 2588 | SDValue DescAddr = LowerGlobalAddressDarwin(Op, DAG); |
| 2589 | |
| 2590 | // The first entry in the descriptor is a function pointer that we must call |
| 2591 | // to obtain the address of the variable. |
| 2592 | SDValue Chain = DAG.getEntryNode(); |
| 2593 | SDValue FuncTLVGet = |
| 2594 | DAG.getLoad(MVT::i32, DL, Chain, DescAddr, |
| 2595 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 2596 | false, true, true, 4); |
| 2597 | Chain = FuncTLVGet.getValue(1); |
| 2598 | |
| 2599 | MachineFunction &F = DAG.getMachineFunction(); |
| 2600 | MachineFrameInfo *MFI = F.getFrameInfo(); |
| 2601 | MFI->setAdjustsStack(true); |
| 2602 | |
| 2603 | // TLS calls preserve all registers except those that absolutely must be |
| 2604 | // trashed: R0 (it takes an argument), LR (it's a call) and CPSR (let's not be |
| 2605 | // silly). |
| 2606 | auto TRI = |
| 2607 | getTargetMachine().getSubtargetImpl(*F.getFunction())->getRegisterInfo(); |
| 2608 | auto ARI = static_cast<const ARMRegisterInfo *>(TRI); |
| 2609 | const uint32_t *Mask = ARI->getTLSCallPreservedMask(DAG.getMachineFunction()); |
| 2610 | |
| 2611 | // Finally, we can make the call. This is just a degenerate version of a |
| 2612 | // normal AArch64 call node: r0 takes the address of the descriptor, and |
| 2613 | // returns the address of the variable in this thread. |
| 2614 | Chain = DAG.getCopyToReg(Chain, DL, ARM::R0, DescAddr, SDValue()); |
| 2615 | Chain = |
| 2616 | DAG.getNode(ARMISD::CALL, DL, DAG.getVTList(MVT::Other, MVT::Glue), |
| 2617 | Chain, FuncTLVGet, DAG.getRegister(ARM::R0, MVT::i32), |
| 2618 | DAG.getRegisterMask(Mask), Chain.getValue(1)); |
| 2619 | return DAG.getCopyFromReg(Chain, DL, ARM::R0, MVT::i32, Chain.getValue(1)); |
| 2620 | } |
| 2621 | |
| Saleem Abdulrasool | f36005a | 2016-02-03 18:21:59 +0000 | [diff] [blame] | 2622 | SDValue |
| 2623 | ARMTargetLowering::LowerGlobalTLSAddressWindows(SDValue Op, |
| 2624 | SelectionDAG &DAG) const { |
| 2625 | assert(Subtarget->isTargetWindows() && "Windows specific TLS lowering"); |
| 2626 | SDValue Chain = DAG.getEntryNode(); |
| 2627 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 2628 | SDLoc DL(Op); |
| 2629 | |
| 2630 | // Load the current TEB (thread environment block) |
| 2631 | SDValue Ops[] = {Chain, |
| 2632 | DAG.getConstant(Intrinsic::arm_mrc, DL, MVT::i32), |
| 2633 | DAG.getConstant(15, DL, MVT::i32), |
| 2634 | DAG.getConstant(0, DL, MVT::i32), |
| 2635 | DAG.getConstant(13, DL, MVT::i32), |
| 2636 | DAG.getConstant(0, DL, MVT::i32), |
| 2637 | DAG.getConstant(2, DL, MVT::i32)}; |
| 2638 | SDValue CurrentTEB = DAG.getNode(ISD::INTRINSIC_W_CHAIN, DL, |
| 2639 | DAG.getVTList(MVT::i32, MVT::Other), Ops); |
| 2640 | |
| 2641 | SDValue TEB = CurrentTEB.getValue(0); |
| 2642 | Chain = CurrentTEB.getValue(1); |
| 2643 | |
| 2644 | // Load the ThreadLocalStoragePointer from the TEB |
| 2645 | // A pointer to the TLS array is located at offset 0x2c from the TEB. |
| 2646 | SDValue TLSArray = |
| 2647 | DAG.getNode(ISD::ADD, DL, PtrVT, TEB, DAG.getIntPtrConstant(0x2c, DL)); |
| 2648 | TLSArray = DAG.getLoad(PtrVT, DL, Chain, TLSArray, MachinePointerInfo(), |
| 2649 | false, false, false, 0); |
| 2650 | |
| 2651 | // The pointer to the thread's TLS data area is at the TLS Index scaled by 4 |
| 2652 | // offset into the TLSArray. |
| 2653 | |
| 2654 | // Load the TLS index from the C runtime |
| 2655 | SDValue TLSIndex = |
| 2656 | DAG.getTargetExternalSymbol("_tls_index", PtrVT, ARMII::MO_NO_FLAG); |
| 2657 | TLSIndex = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, TLSIndex); |
| 2658 | TLSIndex = DAG.getLoad(PtrVT, DL, Chain, TLSIndex, MachinePointerInfo(), |
| 2659 | false, false, false, 0); |
| 2660 | |
| 2661 | SDValue Slot = DAG.getNode(ISD::SHL, DL, PtrVT, TLSIndex, |
| 2662 | DAG.getConstant(2, DL, MVT::i32)); |
| 2663 | SDValue TLS = DAG.getLoad(PtrVT, DL, Chain, |
| 2664 | DAG.getNode(ISD::ADD, DL, PtrVT, TLSArray, Slot), |
| 2665 | MachinePointerInfo(), false, false, false, 0); |
| 2666 | |
| 2667 | return DAG.getNode(ISD::ADD, DL, PtrVT, TLS, |
| 2668 | LowerGlobalAddressWindows(Op, DAG)); |
| 2669 | } |
| 2670 | |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2671 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2672 | SDValue |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2673 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2674 | SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2675 | SDLoc dl(GA); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2676 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2677 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2678 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2679 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2680 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2681 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2682 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2683 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2684 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2685 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2686 | Argument = |
| 2687 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
| 2688 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), |
| 2689 | false, false, false, 0); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2690 | SDValue Chain = Argument.getValue(1); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2691 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2692 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2693 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2694 | |
| 2695 | // call __tls_get_addr. |
| 2696 | ArgListTy Args; |
| 2697 | ArgListEntry Entry; |
| 2698 | Entry.Node = Argument; |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 2699 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2700 | Args.push_back(Entry); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2701 | |
| Dale Johannesen | 555a375 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 2702 | // FIXME: is there useful debug info available here? |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2703 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 2704 | CLI.setDebugLoc(dl).setChain(Chain) |
| 2705 | .setCallee(CallingConv::C, Type::getInt32Ty(*DAG.getContext()), |
| Juergen Ributzka | 3bd03c7 | 2014-07-01 22:01:54 +0000 | [diff] [blame] | 2706 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), std::move(Args), |
| 2707 | 0); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 2708 | |
| Justin Holewinski | aa58397 | 2012-05-25 16:35:28 +0000 | [diff] [blame] | 2709 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2710 | return CallResult.first; |
| 2711 | } |
| 2712 | |
| 2713 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 2714 | // "local exec" model. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2715 | SDValue |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2716 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2717 | SelectionDAG &DAG, |
| 2718 | TLSModel::Model model) const { |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2719 | const GlobalValue *GV = GA->getGlobal(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2720 | SDLoc dl(GA); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2721 | SDValue Offset; |
| 2722 | SDValue Chain = DAG.getEntryNode(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2723 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2724 | // Get the Thread Pointer |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2725 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2726 | |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2727 | if (model == TLSModel::InitialExec) { |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2728 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2729 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2730 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2731 | // Initial exec model. |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2732 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2733 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2734 | ARMConstantPoolConstant::Create(GA->getGlobal(), ARMPCLabelIndex, |
| 2735 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, |
| 2736 | true); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2737 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2738 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2739 | Offset = DAG.getLoad( |
| 2740 | PtrVT, dl, Chain, Offset, |
| 2741 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2742 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2743 | Chain = Offset.getValue(1); |
| 2744 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2745 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2746 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2747 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2748 | Offset = DAG.getLoad( |
| 2749 | PtrVT, dl, Chain, Offset, |
| 2750 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2751 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2752 | } else { |
| 2753 | // local exec model |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2754 | assert(model == TLSModel::LocalExec); |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2755 | ARMConstantPoolValue *CPV = |
| 2756 | ARMConstantPoolConstant::Create(GV, ARMCP::TPOFF); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2757 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2758 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2759 | Offset = DAG.getLoad( |
| 2760 | PtrVT, dl, Chain, Offset, |
| 2761 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2762 | false, false, 0); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2763 | } |
| 2764 | |
| 2765 | // The address of the thread local variable is the add of the thread |
| 2766 | // pointer with the offset of the variable. |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2767 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2770 | SDValue |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2771 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
| Tim Northover | bd41cf8 | 2016-01-07 09:03:03 +0000 | [diff] [blame] | 2772 | if (Subtarget->isTargetDarwin()) |
| 2773 | return LowerGlobalTLSAddressDarwin(Op, DAG); |
| 2774 | |
| Saleem Abdulrasool | f36005a | 2016-02-03 18:21:59 +0000 | [diff] [blame] | 2775 | if (Subtarget->isTargetWindows()) |
| 2776 | return LowerGlobalTLSAddressWindows(Op, DAG); |
| 2777 | |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2778 | // TODO: implement the "local dynamic" model |
| Tim Northover | bd41cf8 | 2016-01-07 09:03:03 +0000 | [diff] [blame] | 2779 | assert(Subtarget->isTargetELF() && "Only ELF implemented here"); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2780 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| Chih-Hung Hsieh | 1e85958 | 2015-07-28 16:24:05 +0000 | [diff] [blame] | 2781 | if (DAG.getTarget().Options.EmulatedTLS) |
| 2782 | return LowerToTLSEmulatedModel(GA, DAG); |
| Hans Wennborg | aea4120 | 2012-05-04 09:40:39 +0000 | [diff] [blame] | 2783 | |
| 2784 | TLSModel::Model model = getTargetMachine().getTLSModel(GA->getGlobal()); |
| 2785 | |
| 2786 | switch (model) { |
| 2787 | case TLSModel::GeneralDynamic: |
| 2788 | case TLSModel::LocalDynamic: |
| 2789 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2790 | case TLSModel::InitialExec: |
| 2791 | case TLSModel::LocalExec: |
| 2792 | return LowerToTLSExecModels(GA, DAG, model); |
| 2793 | } |
| Matt Beaumont-Gay | e82ab6b | 2012-05-04 18:34:27 +0000 | [diff] [blame] | 2794 | llvm_unreachable("bogus TLS model"); |
| Lauro Ramos Venancio | c39c12a | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2797 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2798 | SelectionDAG &DAG) const { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2799 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2800 | SDLoc dl(Op); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2801 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Chad Rosier | 537ff50 | 2013-02-28 19:16:42 +0000 | [diff] [blame] | 2802 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2803 | bool UseGOT_PREL = |
| Peter Collingbourne | 99fac80 | 2015-10-26 20:46:44 +0000 | [diff] [blame] | 2804 | !(GV->hasHiddenVisibility() || GV->hasLocalLinkage()); |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2805 | |
| 2806 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2807 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2808 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| 2809 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| 2810 | SDLoc dl(Op); |
| 2811 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 2812 | ARMConstantPoolValue *CPV = ARMConstantPoolConstant::Create( |
| 2813 | GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj, |
| 2814 | UseGOT_PREL ? ARMCP::GOT_PREL : ARMCP::no_modifier, |
| 2815 | /*AddCurrentAddress=*/UseGOT_PREL); |
| Evan Cheng | 1fb8aed | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2816 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2817 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2818 | SDValue Result = DAG.getLoad( |
| 2819 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2820 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2821 | false, false, 0); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2822 | SDValue Chain = Result.getValue(1); |
| Peter Collingbourne | 97aae40 | 2015-10-26 18:23:16 +0000 | [diff] [blame] | 2823 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| 2824 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2825 | if (UseGOT_PREL) |
| Anton Korobeynikov | 75b59fb | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2826 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2827 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 2828 | false, false, false, 0); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2829 | return Result; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | // 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] | 2833 | // pair. This is always cheaper. |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2834 | if (Subtarget->useMovt(DAG.getMachineFunction())) { |
| Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2835 | ++NumMovwMovt; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2836 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2837 | // operands, expand this into two nodes. |
| 2838 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2839 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2840 | } else { |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2841 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2842 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2843 | return DAG.getLoad( |
| 2844 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2845 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2846 | false, false, 0); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2847 | } |
| 2848 | } |
| 2849 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2850 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2851 | SelectionDAG &DAG) const { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2852 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2853 | SDLoc dl(Op); |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2854 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2855 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2856 | |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2857 | if (Subtarget->useMovt(DAG.getMachineFunction())) |
| Evan Cheng | 68aec14 | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2858 | ++NumMovwMovt; |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2859 | |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2860 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2861 | // operands, expand this into multiple nodes |
| 2862 | unsigned Wrapper = |
| 2863 | RelocM == Reloc::PIC_ ? ARMISD::WrapperPIC : ARMISD::Wrapper; |
| Tim Northover | db962e2c | 2013-11-25 16:24:52 +0000 | [diff] [blame] | 2864 | |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2865 | SDValue G = DAG.getTargetGlobalAddress(GV, dl, PtrVT, 0, ARMII::MO_NONLAZY); |
| 2866 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, G); |
| Evan Cheng | 43b9ca6 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2867 | |
| Evan Cheng | 1b38952 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2868 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| Tim Northover | 72360d2 | 2013-12-02 10:35:41 +0000 | [diff] [blame] | 2869 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2870 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 2871 | false, false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2872 | return Result; |
| 2873 | } |
| 2874 | |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2875 | SDValue ARMTargetLowering::LowerGlobalAddressWindows(SDValue Op, |
| 2876 | SelectionDAG &DAG) const { |
| 2877 | assert(Subtarget->isTargetWindows() && "non-Windows COFF is not supported"); |
| Eric Christopher | c1058df | 2014-07-04 01:55:26 +0000 | [diff] [blame] | 2878 | assert(Subtarget->useMovt(DAG.getMachineFunction()) && |
| 2879 | "Windows on ARM expects to use movw/movt"); |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2880 | |
| 2881 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 2882 | const ARMII::TOF TargetFlags = |
| 2883 | (GV->hasDLLImportStorageClass() ? ARMII::MO_DLLIMPORT : ARMII::MO_NO_FLAG); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2884 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2885 | SDValue Result; |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2886 | SDLoc DL(Op); |
| 2887 | |
| 2888 | ++NumMovwMovt; |
| 2889 | |
| 2890 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2891 | // operands, expand this into two nodes. |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2892 | Result = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, |
| 2893 | DAG.getTargetGlobalAddress(GV, DL, PtrVT, /*Offset=*/0, |
| Reid Kleckner | c35e7f5 | 2015-06-11 01:31:48 +0000 | [diff] [blame] | 2894 | TargetFlags)); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2895 | if (GV->hasDLLImportStorageClass()) |
| 2896 | Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), Result, |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2897 | MachinePointerInfo::getGOT(DAG.getMachineFunction()), |
| 2898 | false, false, false, 0); |
| Saleem Abdulrasool | 763f9a5 | 2014-07-07 05:18:35 +0000 | [diff] [blame] | 2899 | return Result; |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2902 | SDValue |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2903 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2904 | SDLoc dl(Op); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2905 | SDValue Val = DAG.getConstant(0, dl, MVT::i32); |
| Bill Wendling | 7ecfbd9 | 2011-10-07 21:25:38 +0000 | [diff] [blame] | 2906 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, |
| 2907 | DAG.getVTList(MVT::i32, MVT::Other), Op.getOperand(0), |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2908 | Op.getOperand(1), Val); |
| 2909 | } |
| 2910 | |
| 2911 | SDValue |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2912 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2913 | SDLoc dl(Op); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2914 | 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] | 2915 | Op.getOperand(1), DAG.getConstant(0, dl, MVT::i32)); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2916 | } |
| 2917 | |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 2918 | SDValue ARMTargetLowering::LowerEH_SJLJ_SETUP_DISPATCH(SDValue Op, |
| 2919 | SelectionDAG &DAG) const { |
| 2920 | SDLoc dl(Op); |
| 2921 | return DAG.getNode(ARMISD::EH_SJLJ_SETUP_DISPATCH, dl, MVT::Other, |
| 2922 | Op.getOperand(0)); |
| 2923 | } |
| 2924 | |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2925 | SDValue |
| Jim Grosbach | a570d05 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2926 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
| Jim Grosbach | e3864cc | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2927 | const ARMSubtarget *Subtarget) const { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2928 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2929 | SDLoc dl(Op); |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2930 | switch (IntNo) { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2931 | default: return SDValue(); // Don't custom lower most intrinsics. |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2932 | case Intrinsic::arm_rbit: { |
| Yi Kong | c655f0c | 2014-08-20 10:40:20 +0000 | [diff] [blame] | 2933 | assert(Op.getOperand(1).getValueType() == MVT::i32 && |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2934 | "RBIT intrinsic must have i32 type!"); |
| James Molloy | b564098 | 2015-11-13 16:05:22 +0000 | [diff] [blame] | 2935 | return DAG.getNode(ISD::BITREVERSE, dl, MVT::i32, Op.getOperand(1)); |
| Jim Grosbach | 07393ba | 2014-06-16 21:55:30 +0000 | [diff] [blame] | 2936 | } |
| Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2937 | case Intrinsic::arm_thread_pointer: { |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2938 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Bob Wilson | 17f8878 | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2939 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2940 | } |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2941 | case Intrinsic::eh_sjlj_lsda: { |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2942 | MachineFunction &MF = DAG.getMachineFunction(); |
| Evan Cheng | 408aa56 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2943 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Evan Cheng | dfce83c | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2944 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 2945 | EVT PtrVT = getPointerTy(DAG.getDataLayout()); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2946 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2947 | SDValue CPAddr; |
| 2948 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2949 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2950 | ARMConstantPoolValue *CPV = |
| Bill Wendling | 7753d66 | 2011-10-01 08:00:54 +0000 | [diff] [blame] | 2951 | ARMConstantPoolConstant::Create(MF.getFunction(), ARMPCLabelIndex, |
| 2952 | ARMCP::CPLSDA, PCAdj); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2953 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2954 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 2955 | SDValue Result = DAG.getLoad( |
| 2956 | PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2957 | MachinePointerInfo::getConstantPool(DAG.getMachineFunction()), false, |
| 2958 | false, false, 0); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2959 | |
| 2960 | if (RelocM == Reloc::PIC_) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 2961 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, dl, MVT::i32); |
| Jim Grosbach | 693e36a | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2962 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2963 | } |
| 2964 | return Result; |
| 2965 | } |
| Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2966 | case Intrinsic::arm_neon_vmulls: |
| 2967 | case Intrinsic::arm_neon_vmullu: { |
| 2968 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2969 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 2970 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| Evan Cheng | 18381b4 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2971 | Op.getOperand(1), Op.getOperand(2)); |
| 2972 | } |
| James Molloy | ee868b2 | 2015-08-11 12:06:25 +0000 | [diff] [blame] | 2973 | case Intrinsic::arm_neon_vminnm: |
| 2974 | case Intrinsic::arm_neon_vmaxnm: { |
| 2975 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vminnm) |
| 2976 | ? ISD::FMINNUM : ISD::FMAXNUM; |
| 2977 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2978 | Op.getOperand(1), Op.getOperand(2)); |
| 2979 | } |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 2980 | case Intrinsic::arm_neon_vminu: |
| 2981 | case Intrinsic::arm_neon_vmaxu: { |
| 2982 | if (Op.getValueType().isFloatingPoint()) |
| 2983 | return SDValue(); |
| 2984 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vminu) |
| 2985 | ? ISD::UMIN : ISD::UMAX; |
| 2986 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2987 | Op.getOperand(1), Op.getOperand(2)); |
| 2988 | } |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 2989 | case Intrinsic::arm_neon_vmins: |
| 2990 | case Intrinsic::arm_neon_vmaxs: { |
| 2991 | // v{min,max}s is overloaded between signed integers and floats. |
| Silviu Baranga | ad1b19f | 2015-08-19 14:11:27 +0000 | [diff] [blame] | 2992 | if (!Op.getValueType().isFloatingPoint()) { |
| 2993 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmins) |
| 2994 | ? ISD::SMIN : ISD::SMAX; |
| 2995 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 2996 | Op.getOperand(1), Op.getOperand(2)); |
| 2997 | } |
| James Molloy | d616c64 | 2015-08-11 12:06:28 +0000 | [diff] [blame] | 2998 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmins) |
| 2999 | ? ISD::FMINNAN : ISD::FMAXNAN; |
| 3000 | return DAG.getNode(NewOpc, SDLoc(Op), Op.getValueType(), |
| 3001 | Op.getOperand(1), Op.getOperand(2)); |
| 3002 | } |
| Lauro Ramos Venancio | f6a67bf | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 3003 | } |
| 3004 | } |
| 3005 | |
| Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 3006 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 3007 | const ARMSubtarget *Subtarget) { |
| 3008 | // FIXME: handle "fence singlethread" more efficiently. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3009 | SDLoc dl(Op); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 3010 | if (!Subtarget->hasDataBarrier()) { |
| 3011 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 3012 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 3013 | // here. |
| 3014 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| Tim Northover | c7ea804 | 2013-10-25 09:30:24 +0000 | [diff] [blame] | 3015 | "Unexpected ISD::ATOMIC_FENCE encountered. Should be libcall!"); |
| Eli Friedman | 30a49e9 | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 3016 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3017 | DAG.getConstant(0, dl, MVT::i32)); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 3018 | } |
| 3019 | |
| Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 3020 | ConstantSDNode *OrdN = cast<ConstantSDNode>(Op.getOperand(1)); |
| 3021 | AtomicOrdering Ord = static_cast<AtomicOrdering>(OrdN->getZExtValue()); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 3022 | ARM_MB::MemBOpt Domain = ARM_MB::ISH; |
| Tim Northover | f576988 | 2013-08-28 14:39:19 +0000 | [diff] [blame] | 3023 | if (Subtarget->isMClass()) { |
| 3024 | // Only a full system barrier exists in the M-class architectures. |
| 3025 | Domain = ARM_MB::SY; |
| 3026 | } else if (Subtarget->isSwift() && Ord == Release) { |
| Tim Northover | 36b2417 | 2013-07-03 09:20:36 +0000 | [diff] [blame] | 3027 | // Swift happens to implement ISHST barriers in a way that's compatible with |
| 3028 | // Release semantics but weaker than ISH so we'd be fools not to use |
| 3029 | // it. Beware: other processors probably don't! |
| 3030 | Domain = ARM_MB::ISHST; |
| 3031 | } |
| 3032 | |
| Joey Gouly | 926d3f5 | 2013-09-05 15:35:24 +0000 | [diff] [blame] | 3033 | return DAG.getNode(ISD::INTRINSIC_VOID, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3034 | DAG.getConstant(Intrinsic::arm_dmb, dl, MVT::i32), |
| 3035 | DAG.getConstant(Domain, dl, MVT::i32)); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 3036 | } |
| 3037 | |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 3038 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 3039 | const ARMSubtarget *Subtarget) { |
| 3040 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 3041 | if (!(Subtarget->isThumb2() || |
| 3042 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 3043 | // Just preserve the chain. |
| 3044 | return Op.getOperand(0); |
| 3045 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3046 | SDLoc dl(Op); |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 3047 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 3048 | if (!isRead && |
| 3049 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 3050 | // ARMv7 with MP extension has PLDW. |
| 3051 | return Op.getOperand(0); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 3052 | |
| Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 3053 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 3054 | if (Subtarget->isThumb()) { |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 3055 | // Invert the bits. |
| Evan Cheng | 21acf9f | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 3056 | isRead = ~isRead & 1; |
| Bruno Cardoso Lopes | dc9ff3a | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 3057 | isData = ~isData & 1; |
| 3058 | } |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 3059 | |
| 3060 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3061 | Op.getOperand(1), DAG.getConstant(isRead, dl, MVT::i32), |
| 3062 | DAG.getConstant(isData, dl, MVT::i32)); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 3063 | } |
| 3064 | |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3065 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 3066 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3067 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 3068 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3069 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 3070 | // memory location argument. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3071 | SDLoc dl(Op); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3072 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(DAG.getDataLayout()); |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 3073 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
| Dan Gohman | 2d489b5 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 3074 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
| Chris Lattner | 886250c | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 3075 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 3076 | MachinePointerInfo(SV), false, false, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3077 | } |
| 3078 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3079 | SDValue |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3080 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 3081 | SDValue &Root, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3082 | SDLoc dl) const { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3083 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3084 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 3085 | |
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 3086 | const TargetRegisterClass *RC; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3087 | if (AFI->isThumb1OnlyFunction()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3088 | RC = &ARM::tGPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3089 | else |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3090 | RC = &ARM::GPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3091 | |
| 3092 | // Transform the arguments stored in physical registers into virtual ones. |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3093 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3094 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3095 | |
| 3096 | SDValue ArgValue2; |
| 3097 | if (NextVA.isMemLoc()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3098 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 3099 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3100 | |
| 3101 | // Create load node to retrieve arguments from the stack. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3102 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy(DAG.getDataLayout())); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3103 | ArgValue2 = DAG.getLoad( |
| 3104 | MVT::i32, dl, Root, FIN, |
| 3105 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), false, |
| 3106 | false, false, 0); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3107 | } else { |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3108 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3109 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3110 | } |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 3111 | if (!Subtarget->isLittle()) |
| 3112 | std::swap (ArgValue, ArgValue2); |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3113 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3116 | // The remaining GPRs hold either the beginning of variable-argument |
| David Peixotto | 4299cf8 | 2013-02-13 00:36:35 +0000 | [diff] [blame] | 3117 | // data, or the beginning of an aggregate passed by value (usually |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3118 | // byval). Either way, we allocate stack slots adjacent to the data |
| 3119 | // provided by our caller, and store the unallocated registers there. |
| 3120 | // If this is a variadic function, the va_list pointer will begin with |
| 3121 | // these values; otherwise, this reassembles a (byval) structure that |
| 3122 | // was split between registers and memory. |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3123 | // Return: The frame index registers were stored into. |
| 3124 | int |
| 3125 | ARMTargetLowering::StoreByValRegs(CCState &CCInfo, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3126 | SDLoc dl, SDValue &Chain, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3127 | const Value *OrigArg, |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3128 | unsigned InRegsParamRecordIdx, |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3129 | int ArgOffset, |
| 3130 | unsigned ArgSize) const { |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3131 | // Currently, two use-cases possible: |
| Alp Toker | f907b89 | 2013-12-05 05:44:44 +0000 | [diff] [blame] | 3132 | // Case #1. Non-var-args function, and we meet first byval parameter. |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3133 | // Setup first unallocated register as first byval register; |
| 3134 | // eat all remained registers |
| 3135 | // (these two actions are performed by HandleByVal method). |
| 3136 | // Then, here, we initialize stack frame with |
| 3137 | // "store-reg" instructions. |
| 3138 | // Case #2. Var-args function, that doesn't contain byval parameters. |
| 3139 | // The same: eat all remained unallocated registers, |
| 3140 | // initialize stack frame. |
| 3141 | |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3142 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3143 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3144 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3145 | unsigned RBegin, REnd; |
| 3146 | if (InRegsParamRecordIdx < CCInfo.getInRegsParamsCount()) { |
| 3147 | CCInfo.getInRegsParamInfo(InRegsParamRecordIdx, RBegin, REnd); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3148 | } else { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3149 | unsigned RBeginIdx = CCInfo.getFirstUnallocated(GPRArgRegs); |
| Aaron Ballman | c579d66 | 2015-03-12 13:24:06 +0000 | [diff] [blame] | 3150 | RBegin = RBeginIdx == 4 ? (unsigned)ARM::R4 : GPRArgRegs[RBeginIdx]; |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3151 | REnd = ARM::R4; |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3152 | } |
| 3153 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3154 | if (REnd != RBegin) |
| 3155 | ArgOffset = -4 * (ARM::R4 - RBegin); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3156 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3157 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3158 | int FrameIndex = MFI->CreateFixedObject(ArgSize, ArgOffset, false); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3159 | SDValue FIN = DAG.getFrameIndex(FrameIndex, PtrVT); |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3160 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3161 | SmallVector<SDValue, 4> MemOps; |
| 3162 | const TargetRegisterClass *RC = |
| 3163 | AFI->isThumb1OnlyFunction() ? &ARM::tGPRRegClass : &ARM::GPRRegClass; |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3164 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3165 | for (unsigned Reg = RBegin, i = 0; Reg < REnd; ++Reg, ++i) { |
| 3166 | unsigned VReg = MF.addLiveIn(Reg, RC); |
| 3167 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 3168 | SDValue Store = |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3169 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3170 | MachinePointerInfo(OrigArg, 4 * i), false, false, 0); |
| 3171 | MemOps.push_back(Store); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3172 | 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] | 3173 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3174 | |
| 3175 | if (!MemOps.empty()) |
| 3176 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, MemOps); |
| 3177 | return FrameIndex; |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | // Setup stack frame, the va_list pointer will start from. |
| 3181 | void |
| 3182 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3183 | SDLoc dl, SDValue &Chain, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3184 | unsigned ArgOffset, |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3185 | unsigned TotalArgRegsSaveSize, |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3186 | bool ForceMutable) const { |
| 3187 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3188 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 3189 | |
| 3190 | // Try to store any remaining integer argument regs |
| 3191 | // to their spots on the stack so that they may be loaded by deferencing |
| 3192 | // the result of va_next. |
| 3193 | // If there is no regs to be stored, just point address after last |
| 3194 | // argument passed via stack. |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3195 | int FrameIndex = StoreByValRegs(CCInfo, DAG, dl, Chain, nullptr, |
| 3196 | CCInfo.getInRegsParamsCount(), |
| 3197 | CCInfo.getNextStackOffset(), 4); |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3198 | AFI->setVarArgsFrameIndex(FrameIndex); |
| Stuart Hastings | 45fe3c3 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 3199 | } |
| 3200 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3201 | SDValue |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3202 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
| Sandeep Patel | 68c5f47 | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 3203 | CallingConv::ID CallConv, bool isVarArg, |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3204 | const SmallVectorImpl<ISD::InputArg> |
| 3205 | &Ins, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3206 | SDLoc dl, SelectionDAG &DAG, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3207 | SmallVectorImpl<SDValue> &InVals) |
| 3208 | const { |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3209 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3210 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3211 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3212 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 3213 | |
| 3214 | // Assign locations to all of the incoming arguments. |
| 3215 | SmallVector<CCValAssign, 16> ArgLocs; |
| Eric Christopher | b521750 | 2014-08-06 18:45:26 +0000 | [diff] [blame] | 3216 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs, |
| 3217 | *DAG.getContext(), Prologue); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3218 | CCInfo.AnalyzeFormalArguments(Ins, |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 3219 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 3220 | isVarArg)); |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 3221 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3222 | SmallVector<SDValue, 16> ArgValues; |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3223 | SDValue ArgValue; |
| Stepan Dyatkovskiy | f13dbb8 | 2012-10-10 11:37:36 +0000 | [diff] [blame] | 3224 | Function::const_arg_iterator CurOrigArg = MF.getFunction()->arg_begin(); |
| 3225 | unsigned CurArgIdx = 0; |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3226 | |
| 3227 | // Initially ArgRegsSaveSize is zero. |
| 3228 | // Then we increase this value each time we meet byval parameter. |
| 3229 | // We also increase this value in case of varargs function. |
| 3230 | AFI->setArgRegsSaveSize(0); |
| 3231 | |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3232 | // Calculate the amount of stack space that we need to allocate to store |
| 3233 | // byval and variadic arguments that are passed in registers. |
| 3234 | // We need to know this before we allocate the first byval or variadic |
| 3235 | // argument, as they will be allocated a stack slot below the CFA (Canonical |
| 3236 | // Frame Address, the stack pointer at entry to the function). |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3237 | unsigned ArgRegBegin = ARM::R4; |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3238 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3239 | if (CCInfo.getInRegsParamsProcessed() >= CCInfo.getInRegsParamsCount()) |
| 3240 | break; |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3241 | |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3242 | CCValAssign &VA = ArgLocs[i]; |
| 3243 | unsigned Index = VA.getValNo(); |
| 3244 | ISD::ArgFlagsTy Flags = Ins[Index].Flags; |
| 3245 | if (!Flags.isByVal()) |
| 3246 | continue; |
| 3247 | |
| 3248 | assert(VA.isMemLoc() && "unexpected byval pointer in reg"); |
| 3249 | unsigned RBegin, REnd; |
| 3250 | CCInfo.getInRegsParamInfo(CCInfo.getInRegsParamsProcessed(), RBegin, REnd); |
| 3251 | ArgRegBegin = std::min(ArgRegBegin, RBegin); |
| 3252 | |
| 3253 | CCInfo.nextInRegsParam(); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3254 | } |
| 3255 | CCInfo.rewindByValRegsInfo(); |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3256 | |
| 3257 | int lastInsIndex = -1; |
| Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 3258 | if (isVarArg && MFI->hasVAStart()) { |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3259 | unsigned RegIdx = CCInfo.getFirstUnallocated(GPRArgRegs); |
| 3260 | if (RegIdx != array_lengthof(GPRArgRegs)) |
| 3261 | ArgRegBegin = std::min(ArgRegBegin, (unsigned)GPRArgRegs[RegIdx]); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3262 | } |
| Tim Northover | 8cda34f | 2015-03-11 18:54:22 +0000 | [diff] [blame] | 3263 | |
| 3264 | unsigned TotalArgRegsSaveSize = 4 * (ARM::R4 - ArgRegBegin); |
| 3265 | AFI->setArgRegsSaveSize(TotalArgRegsSaveSize); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3266 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3267 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3268 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 3269 | CCValAssign &VA = ArgLocs[i]; |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3270 | if (Ins[VA.getValNo()].isOrigArg()) { |
| 3271 | std::advance(CurOrigArg, |
| 3272 | Ins[VA.getValNo()].getOrigArgIndex() - CurArgIdx); |
| 3273 | CurArgIdx = Ins[VA.getValNo()].getOrigArgIndex(); |
| 3274 | } |
| Bob Wilson | ea09d4a | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 3275 | // Arguments stored in registers. |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3276 | if (VA.isRegLoc()) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3277 | EVT RegVT = VA.getLocVT(); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3278 | |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3279 | if (VA.needsCustom()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3280 | // f64 and vector types are split up into multiple registers or |
| 3281 | // combinations of registers and stack slots. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3282 | if (VA.getLocVT() == MVT::v2f64) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3283 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3284 | Chain, DAG, dl); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3285 | VA = ArgLocs[++i]; // skip ahead to next loc |
| Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 3286 | SDValue ArgValue2; |
| 3287 | if (VA.isMemLoc()) { |
| Evan Cheng | 0664a67 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 3288 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3289 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3290 | ArgValue2 = DAG.getLoad( |
| 3291 | MVT::f64, dl, Chain, FIN, |
| 3292 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), |
| 3293 | false, false, false, 0); |
| Bob Wilson | 699bdf7 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 3294 | } else { |
| 3295 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 3296 | Chain, DAG, dl); |
| 3297 | } |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3298 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 3299 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3300 | ArgValue, ArgValue1, |
| 3301 | DAG.getIntPtrConstant(0, dl)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3302 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3303 | ArgValue, ArgValue2, |
| 3304 | DAG.getIntPtrConstant(1, dl)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3305 | } else |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3306 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3307 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3308 | } else { |
| Craig Topper | 760b134 | 2012-02-22 05:59:10 +0000 | [diff] [blame] | 3309 | const TargetRegisterClass *RC; |
| Anton Korobeynikov | 22ef751 | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 3310 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3311 | if (RegVT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3312 | RC = &ARM::SPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3313 | else if (RegVT == MVT::f64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3314 | RC = &ARM::DPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3315 | else if (RegVT == MVT::v2f64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 3316 | RC = &ARM::QPRRegClass; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3317 | else if (RegVT == MVT::i32) |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 3318 | RC = AFI->isThumb1OnlyFunction() ? &ARM::tGPRRegClass |
| 3319 | : &ARM::GPRRegClass; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3320 | else |
| Anton Korobeynikov | ef98dbe | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 3321 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3322 | |
| 3323 | // Transform the arguments in physical registers into virtual ones. |
| Devang Patel | f3292b2 | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3324 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3325 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 3329 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 3330 | // truncate to the right size. |
| 3331 | switch (VA.getLocInfo()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3332 | default: llvm_unreachable("Unknown loc info!"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3333 | case CCValAssign::Full: break; |
| 3334 | case CCValAssign::BCvt: |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3335 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3336 | break; |
| 3337 | case CCValAssign::SExt: |
| 3338 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 3339 | DAG.getValueType(VA.getValVT())); |
| 3340 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 3341 | break; |
| 3342 | case CCValAssign::ZExt: |
| 3343 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 3344 | DAG.getValueType(VA.getValVT())); |
| 3345 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 3346 | break; |
| 3347 | } |
| 3348 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3349 | InVals.push_back(ArgValue); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3350 | |
| 3351 | } else { // VA.isRegLoc() |
| 3352 | |
| 3353 | // sanity check |
| 3354 | assert(VA.isMemLoc()); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3355 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3356 | |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3357 | int index = VA.getValNo(); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3358 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3359 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 3360 | // Process them only once. |
| 3361 | if (index != lastInsIndex) |
| 3362 | { |
| 3363 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 3364 | // FIXME: For now, all byval parameter objects are marked mutable. |
| Eric Christopher | e02e07c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 3365 | // This can be changed with more analysis. |
| 3366 | // In case of tail call optimization mark all arguments mutable. |
| 3367 | // Since they could be overwritten by lowering of arguments in case of |
| 3368 | // a tail call. |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3369 | if (Flags.isByVal()) { |
| Andrew Trick | 05938a5 | 2015-02-16 18:10:47 +0000 | [diff] [blame] | 3370 | assert(Ins[index].isOrigArg() && |
| 3371 | "Byval arguments cannot be implicit"); |
| Daniel Sanders | 8104b75 | 2014-11-01 19:32:23 +0000 | [diff] [blame] | 3372 | unsigned CurByValIndex = CCInfo.getInRegsParamsProcessed(); |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3373 | |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 3374 | int FrameIndex = StoreByValRegs( |
| 3375 | CCInfo, DAG, dl, Chain, &*CurOrigArg, CurByValIndex, |
| 3376 | VA.getLocMemOffset(), Flags.getByValSize()); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3377 | InVals.push_back(DAG.getFrameIndex(FrameIndex, PtrVT)); |
| Stepan Dyatkovskiy | 8c02c98 | 2013-05-05 07:48:36 +0000 | [diff] [blame] | 3378 | CCInfo.nextInRegsParam(); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3379 | } else { |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3380 | unsigned FIOffset = VA.getLocMemOffset(); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3381 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| Stepan Dyatkovskiy | d0e34a2 | 2013-05-20 08:01:34 +0000 | [diff] [blame] | 3382 | FIOffset, true); |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3383 | |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3384 | // Create load nodes to retrieve arguments from the stack. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3385 | SDValue FIN = DAG.getFrameIndex(FI, PtrVT); |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 3386 | InVals.push_back(DAG.getLoad( |
| 3387 | VA.getValVT(), dl, Chain, FIN, |
| 3388 | MachinePointerInfo::getFixedStack(DAG.getMachineFunction(), FI), |
| 3389 | false, false, false, 0)); |
| Stuart Hastings | 67c5c3e | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 3390 | } |
| 3391 | lastInsIndex = index; |
| 3392 | } |
| Bob Wilson | a4c2290 | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 3393 | } |
| 3394 | } |
| 3395 | |
| 3396 | // varargs |
| Reid Kleckner | 2d9bb65 | 2014-08-22 21:59:26 +0000 | [diff] [blame] | 3397 | if (isVarArg && MFI->hasVAStart()) |
| Stepan Dyatkovskiy | f5aa83d | 2013-04-30 07:19:58 +0000 | [diff] [blame] | 3398 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, |
| Oliver Stannard | d55e115 | 2014-03-05 15:25:27 +0000 | [diff] [blame] | 3399 | CCInfo.getNextStackOffset(), |
| 3400 | TotalArgRegsSaveSize); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3401 | |
| Oliver Stannard | b14c625 | 2014-04-02 16:10:33 +0000 | [diff] [blame] | 3402 | AFI->setArgumentStackSize(CCInfo.getNextStackOffset()); |
| 3403 | |
| Dan Gohman | f9bbcd1 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 3404 | return Chain; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3405 | } |
| 3406 | |
| 3407 | /// isFloatingPointZero - Return true if this is +0.0. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3408 | static bool isFloatingPointZero(SDValue Op) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3409 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3410 | return CFP->getValueAPF().isPosZero(); |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3411 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3412 | // Maybe this has already been legalized into the constant pool? |
| 3413 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3414 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3415 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
| Dan Gohman | bcaf681 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 3416 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
| Dale Johannesen | 3cf889f | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 3417 | return CFP->getValueAPF().isPosZero(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3418 | } |
| Renato Golin | 6fb9c2e | 2014-10-23 15:31:50 +0000 | [diff] [blame] | 3419 | } else if (Op->getOpcode() == ISD::BITCAST && |
| 3420 | Op->getValueType(0) == MVT::f64) { |
| 3421 | // Handle (ISD::BITCAST (ARMISD::VMOVIMM (ISD::TargetConstant 0)) MVT::f64) |
| 3422 | // created by LowerConstantFP(). |
| 3423 | SDValue BitcastOp = Op->getOperand(0); |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 3424 | if (BitcastOp->getOpcode() == ARMISD::VMOVIMM && |
| 3425 | isNullConstant(BitcastOp->getOperand(0))) |
| 3426 | return true; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3427 | } |
| 3428 | return false; |
| 3429 | } |
| 3430 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3431 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 3432 | /// the given operands. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3433 | SDValue |
| 3434 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3435 | SDValue &ARMcc, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3436 | SDLoc dl) const { |
| Gabor Greif | f304a7a | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 3437 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3438 | unsigned C = RHSC->getZExtValue(); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 3439 | if (!isLegalICmpImmediate(C)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3440 | // Constant does not fit, try adjusting it by one? |
| 3441 | switch (CC) { |
| 3442 | default: break; |
| 3443 | case ISD::SETLT: |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3444 | case ISD::SETGE: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3445 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3446 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3447 | RHS = DAG.getConstant(C - 1, dl, MVT::i32); |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3448 | } |
| 3449 | break; |
| 3450 | case ISD::SETULT: |
| 3451 | case ISD::SETUGE: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3452 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3453 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3454 | RHS = DAG.getConstant(C - 1, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3455 | } |
| 3456 | break; |
| 3457 | case ISD::SETLE: |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3458 | case ISD::SETGT: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3459 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3460 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3461 | RHS = DAG.getConstant(C + 1, dl, MVT::i32); |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3462 | } |
| 3463 | break; |
| 3464 | case ISD::SETULE: |
| 3465 | case ISD::SETUGT: |
| Daniel Dunbar | a54a1b0 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 3466 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
| Evan Cheng | 48b094d | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 3467 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3468 | RHS = DAG.getConstant(C + 1, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3469 | } |
| 3470 | break; |
| 3471 | } |
| 3472 | } |
| 3473 | } |
| 3474 | |
| 3475 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3476 | ARMISD::NodeType CompareType; |
| 3477 | switch (CondCode) { |
| 3478 | default: |
| 3479 | CompareType = ARMISD::CMP; |
| 3480 | break; |
| 3481 | case ARMCC::EQ: |
| 3482 | case ARMCC::NE: |
| David Goodwin | dbf11ba | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 3483 | // Uses only Z Flag |
| 3484 | CompareType = ARMISD::CMPZ; |
| Lauro Ramos Venancio | 6be8533 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 3485 | break; |
| 3486 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3487 | ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3488 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
| 3491 | /// 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] | 3492 | SDValue |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3493 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3494 | SDLoc dl) const { |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3495 | assert(!Subtarget->isFPOnlySP() || RHS.getValueType() != MVT::f64); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3496 | SDValue Cmp; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3497 | if (!isFloatingPointZero(RHS)) |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3498 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3499 | else |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3500 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 3501 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3502 | } |
| 3503 | |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3504 | /// duplicateCmp - Glue values can have only one use, so this function |
| 3505 | /// duplicates a comparison node. |
| 3506 | SDValue |
| 3507 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 3508 | unsigned Opc = Cmp.getOpcode(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3509 | SDLoc DL(Cmp); |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3510 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 3511 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3512 | |
| 3513 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 3514 | Cmp = Cmp.getOperand(0); |
| 3515 | Opc = Cmp.getOpcode(); |
| 3516 | if (Opc == ARMISD::CMPFP) |
| 3517 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 3518 | else { |
| 3519 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 3520 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 3521 | } |
| 3522 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 3523 | } |
| 3524 | |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3525 | std::pair<SDValue, SDValue> |
| 3526 | ARMTargetLowering::getARMXALUOOp(SDValue Op, SelectionDAG &DAG, |
| 3527 | SDValue &ARMcc) const { |
| 3528 | assert(Op.getValueType() == MVT::i32 && "Unsupported value type"); |
| 3529 | |
| 3530 | SDValue Value, OverflowCmp; |
| 3531 | SDValue LHS = Op.getOperand(0); |
| 3532 | SDValue RHS = Op.getOperand(1); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3533 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3534 | |
| 3535 | // FIXME: We are currently always generating CMPs because we don't support |
| 3536 | // generating CMN through the backend. This is not as good as the natural |
| 3537 | // CMP case because it causes a register dependency and cannot be folded |
| 3538 | // later. |
| 3539 | |
| 3540 | switch (Op.getOpcode()) { |
| 3541 | default: |
| 3542 | llvm_unreachable("Unknown overflow instruction!"); |
| 3543 | case ISD::SADDO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3544 | ARMcc = DAG.getConstant(ARMCC::VC, dl, MVT::i32); |
| 3545 | Value = DAG.getNode(ISD::ADD, dl, Op.getValueType(), LHS, RHS); |
| 3546 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, Value, LHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3547 | break; |
| 3548 | case ISD::UADDO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3549 | ARMcc = DAG.getConstant(ARMCC::HS, dl, MVT::i32); |
| 3550 | Value = DAG.getNode(ISD::ADD, dl, Op.getValueType(), LHS, RHS); |
| 3551 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, Value, LHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3552 | break; |
| 3553 | case ISD::SSUBO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3554 | ARMcc = DAG.getConstant(ARMCC::VC, dl, MVT::i32); |
| 3555 | Value = DAG.getNode(ISD::SUB, dl, Op.getValueType(), LHS, RHS); |
| 3556 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, LHS, RHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3557 | break; |
| 3558 | case ISD::USUBO: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3559 | ARMcc = DAG.getConstant(ARMCC::HS, dl, MVT::i32); |
| 3560 | Value = DAG.getNode(ISD::SUB, dl, Op.getValueType(), LHS, RHS); |
| 3561 | OverflowCmp = DAG.getNode(ARMISD::CMP, dl, MVT::Glue, LHS, RHS); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3562 | break; |
| 3563 | } // switch (...) |
| 3564 | |
| 3565 | return std::make_pair(Value, OverflowCmp); |
| 3566 | } |
| 3567 | |
| 3568 | |
| 3569 | SDValue |
| 3570 | ARMTargetLowering::LowerXALUO(SDValue Op, SelectionDAG &DAG) const { |
| 3571 | // Let legalize expand this if it isn't a legal type yet. |
| 3572 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Op.getValueType())) |
| 3573 | return SDValue(); |
| 3574 | |
| 3575 | SDValue Value, OverflowCmp; |
| 3576 | SDValue ARMcc; |
| 3577 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Op, DAG, ARMcc); |
| 3578 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3579 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3580 | // We use 0 and 1 as false and true values. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3581 | SDValue TVal = DAG.getConstant(1, dl, MVT::i32); |
| 3582 | SDValue FVal = DAG.getConstant(0, dl, MVT::i32); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3583 | EVT VT = Op.getValueType(); |
| 3584 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3585 | SDValue Overflow = DAG.getNode(ARMISD::CMOV, dl, VT, TVal, FVal, |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3586 | ARMcc, CCR, OverflowCmp); |
| 3587 | |
| 3588 | SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3589 | return DAG.getNode(ISD::MERGE_VALUES, dl, VTs, Value, Overflow); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3593 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 3594 | SDValue Cond = Op.getOperand(0); |
| 3595 | SDValue SelectTrue = Op.getOperand(1); |
| 3596 | SDValue SelectFalse = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3597 | SDLoc dl(Op); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3598 | unsigned Opc = Cond.getOpcode(); |
| 3599 | |
| 3600 | if (Cond.getResNo() == 1 && |
| 3601 | (Opc == ISD::SADDO || Opc == ISD::UADDO || Opc == ISD::SSUBO || |
| 3602 | Opc == ISD::USUBO)) { |
| 3603 | if (!DAG.getTargetLoweringInfo().isTypeLegal(Cond->getValueType(0))) |
| 3604 | return SDValue(); |
| 3605 | |
| 3606 | SDValue Value, OverflowCmp; |
| 3607 | SDValue ARMcc; |
| 3608 | std::tie(Value, OverflowCmp) = getARMXALUOOp(Cond, DAG, ARMcc); |
| 3609 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3610 | EVT VT = Op.getValueType(); |
| 3611 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3612 | return getCMOV(dl, VT, SelectTrue, SelectFalse, ARMcc, CCR, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3613 | OverflowCmp, DAG); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 3614 | } |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3615 | |
| 3616 | // Convert: |
| 3617 | // |
| 3618 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 3619 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 3620 | // |
| 3621 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 3622 | const ConstantSDNode *CMOVTrue = |
| 3623 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 3624 | const ConstantSDNode *CMOVFalse = |
| 3625 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 3626 | |
| 3627 | if (CMOVTrue && CMOVFalse) { |
| 3628 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 3629 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 3630 | |
| 3631 | SDValue True; |
| 3632 | SDValue False; |
| 3633 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 3634 | True = SelectTrue; |
| 3635 | False = SelectFalse; |
| 3636 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 3637 | True = SelectFalse; |
| 3638 | False = SelectTrue; |
| 3639 | } |
| 3640 | |
| 3641 | if (True.getNode() && False.getNode()) { |
| Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3642 | EVT VT = Op.getValueType(); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3643 | SDValue ARMcc = Cond.getOperand(2); |
| 3644 | SDValue CCR = Cond.getOperand(3); |
| Bob Wilson | 45acbd0 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 3645 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
| Evan Cheng | 522fbfe | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 3646 | assert(True.getValueType() == VT); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3647 | return getCMOV(dl, VT, True, False, ARMcc, CCR, Cmp, DAG); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3648 | } |
| 3649 | } |
| 3650 | } |
| 3651 | |
| Dan Gohman | d4a77c4 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3652 | // ARM's BooleanContents value is UndefinedBooleanContent. Mask out the |
| 3653 | // undefined bits before doing a full-word comparison with zero. |
| 3654 | Cond = DAG.getNode(ISD::AND, dl, Cond.getValueType(), Cond, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3655 | DAG.getConstant(1, dl, Cond.getValueType())); |
| Dan Gohman | d4a77c4 | 2012-02-24 00:09:36 +0000 | [diff] [blame] | 3656 | |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3657 | return DAG.getSelectCC(dl, Cond, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3658 | DAG.getConstant(0, dl, Cond.getValueType()), |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 3659 | SelectTrue, SelectFalse, ISD::SETNE); |
| 3660 | } |
| 3661 | |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3662 | static void checkVSELConstraints(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
| 3663 | bool &swpCmpOps, bool &swpVselOps) { |
| 3664 | // Start by selecting the GE condition code for opcodes that return true for |
| 3665 | // 'equality' |
| 3666 | if (CC == ISD::SETUGE || CC == ISD::SETOGE || CC == ISD::SETOLE || |
| 3667 | CC == ISD::SETULE) |
| 3668 | CondCode = ARMCC::GE; |
| 3669 | |
| 3670 | // and GT for opcodes that return false for 'equality'. |
| 3671 | else if (CC == ISD::SETUGT || CC == ISD::SETOGT || CC == ISD::SETOLT || |
| 3672 | CC == ISD::SETULT) |
| 3673 | CondCode = ARMCC::GT; |
| 3674 | |
| 3675 | // Since we are constrained to GE/GT, if the opcode contains 'less', we need |
| 3676 | // to swap the compare operands. |
| 3677 | if (CC == ISD::SETOLE || CC == ISD::SETULE || CC == ISD::SETOLT || |
| 3678 | CC == ISD::SETULT) |
| 3679 | swpCmpOps = true; |
| 3680 | |
| 3681 | // Both GT and GE are ordered comparisons, and return false for 'unordered'. |
| 3682 | // If we have an unordered opcode, we need to swap the operands to the VSEL |
| 3683 | // instruction (effectively negating the condition). |
| 3684 | // |
| 3685 | // This also has the effect of swapping which one of 'less' or 'greater' |
| 3686 | // returns true, so we also swap the compare operands. It also switches |
| 3687 | // whether we return true for 'equality', so we compensate by picking the |
| 3688 | // opposite condition code to our original choice. |
| 3689 | if (CC == ISD::SETULE || CC == ISD::SETULT || CC == ISD::SETUGE || |
| 3690 | CC == ISD::SETUGT) { |
| 3691 | swpCmpOps = !swpCmpOps; |
| 3692 | swpVselOps = !swpVselOps; |
| 3693 | CondCode = CondCode == ARMCC::GT ? ARMCC::GE : ARMCC::GT; |
| 3694 | } |
| 3695 | |
| 3696 | // 'ordered' is 'anything but unordered', so use the VS condition code and |
| 3697 | // swap the VSEL operands. |
| 3698 | if (CC == ISD::SETO) { |
| 3699 | CondCode = ARMCC::VS; |
| 3700 | swpVselOps = true; |
| 3701 | } |
| 3702 | |
| 3703 | // 'unordered or not equal' is 'anything but equal', so use the EQ condition |
| 3704 | // code and swap the VSEL operands. |
| 3705 | if (CC == ISD::SETUNE) { |
| 3706 | CondCode = ARMCC::EQ; |
| 3707 | swpVselOps = true; |
| 3708 | } |
| 3709 | } |
| 3710 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3711 | SDValue ARMTargetLowering::getCMOV(SDLoc dl, EVT VT, SDValue FalseVal, |
| 3712 | SDValue TrueVal, SDValue ARMcc, SDValue CCR, |
| 3713 | SDValue Cmp, SelectionDAG &DAG) const { |
| 3714 | if (Subtarget->isFPOnlySP() && VT == MVT::f64) { |
| 3715 | FalseVal = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3716 | DAG.getVTList(MVT::i32, MVT::i32), FalseVal); |
| 3717 | TrueVal = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3718 | DAG.getVTList(MVT::i32, MVT::i32), TrueVal); |
| 3719 | |
| 3720 | SDValue TrueLow = TrueVal.getValue(0); |
| 3721 | SDValue TrueHigh = TrueVal.getValue(1); |
| 3722 | SDValue FalseLow = FalseVal.getValue(0); |
| 3723 | SDValue FalseHigh = FalseVal.getValue(1); |
| 3724 | |
| 3725 | SDValue Low = DAG.getNode(ARMISD::CMOV, dl, MVT::i32, FalseLow, TrueLow, |
| 3726 | ARMcc, CCR, Cmp); |
| 3727 | SDValue High = DAG.getNode(ARMISD::CMOV, dl, MVT::i32, FalseHigh, TrueHigh, |
| 3728 | ARMcc, CCR, duplicateCmp(Cmp, DAG)); |
| 3729 | |
| 3730 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Low, High); |
| 3731 | } else { |
| 3732 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR, |
| 3733 | Cmp); |
| 3734 | } |
| 3735 | } |
| 3736 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3737 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3738 | EVT VT = Op.getValueType(); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3739 | SDValue LHS = Op.getOperand(0); |
| 3740 | SDValue RHS = Op.getOperand(1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3741 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3742 | SDValue TrueVal = Op.getOperand(2); |
| 3743 | SDValue FalseVal = Op.getOperand(3); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3744 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3745 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3746 | if (Subtarget->isFPOnlySP() && LHS.getValueType() == MVT::f64) { |
| 3747 | DAG.getTargetLoweringInfo().softenSetCCOperands(DAG, MVT::f64, LHS, RHS, CC, |
| 3748 | dl); |
| 3749 | |
| 3750 | // If softenSetCCOperands only returned one value, we should compare it to |
| 3751 | // zero. |
| 3752 | if (!RHS.getNode()) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3753 | RHS = DAG.getConstant(0, dl, LHS.getValueType()); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3754 | CC = ISD::SETNE; |
| 3755 | } |
| 3756 | } |
| 3757 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3758 | if (LHS.getValueType() == MVT::i32) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3759 | // Try to generate VSEL on ARMv8. |
| 3760 | // The VSEL instruction can't use all the usual ARM condition |
| 3761 | // codes: it only has two bits to select the condition code, so it's |
| 3762 | // constrained to use only GE, GT, VS and EQ. |
| 3763 | // |
| 3764 | // To implement all the various ISD::SETXXX opcodes, we sometimes need to |
| 3765 | // swap the operands of the previous compare instruction (effectively |
| 3766 | // inverting the compare condition, swapping 'less' and 'greater') and |
| 3767 | // sometimes need to swap the operands to the VSEL (which inverts the |
| 3768 | // condition in the sense of firing whenever the previous condition didn't) |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 3769 | if (Subtarget->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
| 3770 | TrueVal.getValueType() == MVT::f64)) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3771 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 3772 | if (CondCode == ARMCC::LT || CondCode == ARMCC::LE || |
| 3773 | CondCode == ARMCC::VC || CondCode == ARMCC::NE) { |
| Artyom Skrobov | 3f8eae9 | 2015-05-06 11:44:10 +0000 | [diff] [blame] | 3774 | CC = ISD::getSetCCInverse(CC, true); |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3775 | std::swap(TrueVal, FalseVal); |
| 3776 | } |
| 3777 | } |
| 3778 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3779 | SDValue ARMcc; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3780 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3781 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3782 | return getCMOV(dl, VT, FalseVal, TrueVal, ARMcc, CCR, Cmp, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3783 | } |
| 3784 | |
| 3785 | ARMCC::CondCodes CondCode, CondCode2; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3786 | FPCCToARMCC(CC, CondCode, CondCode2); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3787 | |
| Scott Douglass | 7ad7792 | 2015-04-08 17:18:28 +0000 | [diff] [blame] | 3788 | // Try to generate VMAXNM/VMINNM on ARMv8. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 3789 | if (Subtarget->hasFPARMv8() && (TrueVal.getValueType() == MVT::f32 || |
| 3790 | TrueVal.getValueType() == MVT::f64)) { |
| Joey Gouly | 881eab5 | 2013-08-22 15:29:11 +0000 | [diff] [blame] | 3791 | bool swpCmpOps = false; |
| 3792 | bool swpVselOps = false; |
| 3793 | checkVSELConstraints(CC, CondCode, swpCmpOps, swpVselOps); |
| 3794 | |
| 3795 | if (CondCode == ARMCC::GT || CondCode == ARMCC::GE || |
| 3796 | CondCode == ARMCC::VS || CondCode == ARMCC::EQ) { |
| 3797 | if (swpCmpOps) |
| 3798 | std::swap(LHS, RHS); |
| 3799 | if (swpVselOps) |
| 3800 | std::swap(TrueVal, FalseVal); |
| 3801 | } |
| 3802 | } |
| 3803 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3804 | SDValue ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3805 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3806 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3807 | SDValue Result = getCMOV(dl, VT, FalseVal, TrueVal, ARMcc, CCR, Cmp, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3808 | if (CondCode2 != ARMCC::AL) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3809 | SDValue ARMcc2 = DAG.getConstant(CondCode2, dl, MVT::i32); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3810 | // FIXME: Needs another CMP because flag can have but one use. |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3811 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3812 | Result = getCMOV(dl, VT, Result, TrueVal, ARMcc2, CCR, Cmp2, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3813 | } |
| 3814 | return Result; |
| 3815 | } |
| 3816 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3817 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 3818 | /// to morph to an integer compare sequence. |
| 3819 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 3820 | const ARMSubtarget *Subtarget) { |
| 3821 | SDNode *N = Op.getNode(); |
| 3822 | if (!N->hasOneUse()) |
| 3823 | // Otherwise it requires moving the value from fp to integer registers. |
| 3824 | return false; |
| 3825 | if (!N->getNumValues()) |
| 3826 | return false; |
| 3827 | EVT VT = Op.getValueType(); |
| 3828 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 3829 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 3830 | // vmrs are very slow, e.g. cortex-a8. |
| 3831 | return false; |
| 3832 | |
| 3833 | if (isFloatingPointZero(Op)) { |
| 3834 | SeenZero = true; |
| 3835 | return true; |
| 3836 | } |
| 3837 | return ISD::isNormalLoad(N); |
| 3838 | } |
| 3839 | |
| 3840 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 3841 | if (isFloatingPointZero(Op)) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3842 | return DAG.getConstant(0, SDLoc(Op), MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3843 | |
| 3844 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3845 | return DAG.getLoad(MVT::i32, SDLoc(Op), |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3846 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3847 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3848 | Ld->isInvariant(), Ld->getAlignment()); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3849 | |
| 3850 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3851 | } |
| 3852 | |
| 3853 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 3854 | SDValue &RetVal1, SDValue &RetVal2) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3855 | SDLoc dl(Op); |
| 3856 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3857 | if (isFloatingPointZero(Op)) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3858 | RetVal1 = DAG.getConstant(0, dl, MVT::i32); |
| 3859 | RetVal2 = DAG.getConstant(0, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3860 | return; |
| 3861 | } |
| 3862 | |
| 3863 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 3864 | SDValue Ptr = Ld->getBasePtr(); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3865 | RetVal1 = DAG.getLoad(MVT::i32, dl, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3866 | Ld->getChain(), Ptr, |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3867 | Ld->getPointerInfo(), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3868 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3869 | Ld->isInvariant(), Ld->getAlignment()); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3870 | |
| 3871 | EVT PtrType = Ptr.getValueType(); |
| 3872 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3873 | SDValue NewPtr = DAG.getNode(ISD::ADD, dl, |
| 3874 | PtrType, Ptr, DAG.getConstant(4, dl, PtrType)); |
| 3875 | RetVal2 = DAG.getLoad(MVT::i32, dl, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3876 | Ld->getChain(), NewPtr, |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3877 | Ld->getPointerInfo().getWithOffset(4), |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3878 | Ld->isVolatile(), Ld->isNonTemporal(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 3879 | Ld->isInvariant(), NewAlign); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3880 | return; |
| 3881 | } |
| 3882 | |
| 3883 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 3884 | } |
| 3885 | |
| 3886 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 3887 | /// f32 and even f64 comparisons to integer ones. |
| 3888 | SDValue |
| 3889 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 3890 | SDValue Chain = Op.getOperand(0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3891 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3892 | SDValue LHS = Op.getOperand(2); |
| 3893 | SDValue RHS = Op.getOperand(3); |
| 3894 | SDValue Dest = Op.getOperand(4); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3895 | SDLoc dl(Op); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3896 | |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3897 | bool LHSSeenZero = false; |
| 3898 | bool LHSOk = canChangeToInt(LHS, LHSSeenZero, Subtarget); |
| 3899 | bool RHSSeenZero = false; |
| 3900 | bool RHSOk = canChangeToInt(RHS, RHSSeenZero, Subtarget); |
| 3901 | if (LHSOk && RHSOk && (LHSSeenZero || RHSSeenZero)) { |
| Bob Wilson | 70bd363 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 3902 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 3903 | // 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] | 3904 | // to an integer comparison. |
| 3905 | if (CC == ISD::SETOEQ) |
| 3906 | CC = ISD::SETEQ; |
| 3907 | else if (CC == ISD::SETUNE) |
| 3908 | CC = ISD::SETNE; |
| 3909 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3910 | SDValue Mask = DAG.getConstant(0x7fffffff, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3911 | SDValue ARMcc; |
| 3912 | if (LHS.getValueType() == MVT::f32) { |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3913 | LHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3914 | bitcastf32Toi32(LHS, DAG), Mask); |
| 3915 | RHS = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3916 | bitcastf32Toi32(RHS, DAG), Mask); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3917 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 3918 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3919 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 3920 | Chain, Dest, ARMcc, CCR, Cmp); |
| 3921 | } |
| 3922 | |
| 3923 | SDValue LHS1, LHS2; |
| 3924 | SDValue RHS1, RHS2; |
| 3925 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 3926 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| Evan Cheng | d12af5d | 2012-03-01 23:27:13 +0000 | [diff] [blame] | 3927 | LHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, LHS2, Mask); |
| 3928 | RHS2 = DAG.getNode(ISD::AND, dl, MVT::i32, RHS2, Mask); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3929 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3930 | ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3931 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3932 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3933 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
| 3936 | return SDValue(); |
| 3937 | } |
| 3938 | |
| 3939 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 3940 | SDValue Chain = Op.getOperand(0); |
| 3941 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 3942 | SDValue LHS = Op.getOperand(2); |
| 3943 | SDValue RHS = Op.getOperand(3); |
| 3944 | SDValue Dest = Op.getOperand(4); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3945 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3946 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3947 | if (Subtarget->isFPOnlySP() && LHS.getValueType() == MVT::f64) { |
| 3948 | DAG.getTargetLoweringInfo().softenSetCCOperands(DAG, MVT::f64, LHS, RHS, CC, |
| 3949 | dl); |
| 3950 | |
| 3951 | // If softenSetCCOperands only returned one value, we should compare it to |
| 3952 | // zero. |
| 3953 | if (!RHS.getNode()) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3954 | RHS = DAG.getConstant(0, dl, LHS.getValueType()); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 3955 | CC = ISD::SETNE; |
| 3956 | } |
| 3957 | } |
| 3958 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3959 | if (LHS.getValueType() == MVT::i32) { |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3960 | SDValue ARMcc; |
| 3961 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3962 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3963 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3964 | Chain, Dest, ARMcc, CCR, Cmp); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3965 | } |
| 3966 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3967 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3968 | |
| Nick Lewycky | 50f02cb | 2011-12-02 22:16:29 +0000 | [diff] [blame] | 3969 | if (getTargetMachine().Options.UnsafeFPMath && |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3970 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 3971 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 3972 | if (SDValue Result = OptimizeVFPBrcond(Op, DAG)) |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3973 | return Result; |
| 3974 | } |
| 3975 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3976 | ARMCC::CondCodes CondCode, CondCode2; |
| Bob Wilson | a2e8333 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 3977 | FPCCToARMCC(CC, CondCode, CondCode2); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3978 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3979 | SDValue ARMcc = DAG.getConstant(CondCode, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3980 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3981 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Chris Lattner | 3e5fbd7 | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3982 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3983 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3984 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3985 | if (CondCode2 != ARMCC::AL) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 3986 | ARMcc = DAG.getConstant(CondCode2, dl, MVT::i32); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3987 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 3988 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3989 | } |
| 3990 | return Res; |
| 3991 | } |
| 3992 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3993 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3994 | SDValue Chain = Op.getOperand(0); |
| 3995 | SDValue Table = Op.getOperand(1); |
| 3996 | SDValue Index = Op.getOperand(2); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 3997 | SDLoc dl(Op); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3998 | |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 3999 | EVT PTy = getPointerTy(DAG.getDataLayout()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4000 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4001 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 4002 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4003 | 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] | 4004 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4005 | if (Subtarget->isThumb2()) { |
| 4006 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 4007 | // which does another jump to the destination. This also makes it easier |
| 4008 | // to translate it to TBB / TBH later. |
| 4009 | // FIXME: This might not work if the function is extremely large. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4010 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 4011 | Addr, Op.getOperand(2), JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4012 | } |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4013 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 4014 | Addr = |
| 4015 | DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
| 4016 | MachinePointerInfo::getJumpTable(DAG.getMachineFunction()), |
| 4017 | false, false, false, 0); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4018 | Chain = Addr.getValue(1); |
| Dale Johannesen | 021052a | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 4019 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 4020 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4021 | } else { |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 4022 | Addr = |
| 4023 | DAG.getLoad(PTy, dl, Chain, Addr, |
| 4024 | MachinePointerInfo::getJumpTable(DAG.getMachineFunction()), |
| 4025 | false, false, false, 0); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4026 | Chain = Addr.getValue(1); |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 4027 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI); |
| Evan Cheng | f3a1fce | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 4028 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 4031 | static SDValue LowerVectorFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 4032 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4033 | SDLoc dl(Op); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 4034 | |
| James Molloy | 547d4c0 | 2012-02-20 09:24:05 +0000 | [diff] [blame] | 4035 | if (Op.getValueType().getVectorElementType() == MVT::i32) { |
| 4036 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::f32) |
| 4037 | return Op; |
| 4038 | return DAG.UnrollVectorOp(Op.getNode()); |
| 4039 | } |
| 4040 | |
| 4041 | assert(Op.getOperand(0).getValueType() == MVT::v4f32 && |
| 4042 | "Invalid type for custom lowering!"); |
| 4043 | if (VT != MVT::v4i16) |
| 4044 | return DAG.UnrollVectorOp(Op.getNode()); |
| 4045 | |
| 4046 | Op = DAG.getNode(Op.getOpcode(), dl, MVT::v4i32, Op.getOperand(0)); |
| 4047 | return DAG.getNode(ISD::TRUNCATE, dl, VT, Op); |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 4048 | } |
| 4049 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4050 | SDValue ARMTargetLowering::LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) const { |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 4051 | EVT VT = Op.getValueType(); |
| 4052 | if (VT.isVector()) |
| 4053 | return LowerVectorFP_TO_INT(Op, DAG); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4054 | if (Subtarget->isFPOnlySP() && Op.getOperand(0).getValueType() == MVT::f64) { |
| 4055 | RTLIB::Libcall LC; |
| 4056 | if (Op.getOpcode() == ISD::FP_TO_SINT) |
| 4057 | LC = RTLIB::getFPTOSINT(Op.getOperand(0).getValueType(), |
| 4058 | Op.getValueType()); |
| 4059 | else |
| 4060 | LC = RTLIB::getFPTOUINT(Op.getOperand(0).getValueType(), |
| 4061 | Op.getValueType()); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 4062 | return makeLibCall(DAG, LC, Op.getValueType(), Op.getOperand(0), |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4063 | /*isSigned*/ false, SDLoc(Op)).first; |
| 4064 | } |
| 4065 | |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 4066 | return Op; |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 4069 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 4070 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4071 | SDLoc dl(Op); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 4072 | |
| Eli Friedman | 2d4055b | 2011-11-09 23:36:02 +0000 | [diff] [blame] | 4073 | if (Op.getOperand(0).getValueType().getVectorElementType() == MVT::i32) { |
| 4074 | if (VT.getVectorElementType() == MVT::f32) |
| 4075 | return Op; |
| 4076 | return DAG.UnrollVectorOp(Op.getNode()); |
| 4077 | } |
| 4078 | |
| Duncan Sands | a41634e | 2011-08-12 14:54:45 +0000 | [diff] [blame] | 4079 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 4080 | "Invalid type for custom lowering!"); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 4081 | if (VT != MVT::v4f32) |
| 4082 | return DAG.UnrollVectorOp(Op.getNode()); |
| 4083 | |
| 4084 | unsigned CastOpc; |
| 4085 | unsigned Opc; |
| 4086 | switch (Op.getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 4087 | default: llvm_unreachable("Invalid opcode!"); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 4088 | case ISD::SINT_TO_FP: |
| 4089 | CastOpc = ISD::SIGN_EXTEND; |
| 4090 | Opc = ISD::SINT_TO_FP; |
| 4091 | break; |
| 4092 | case ISD::UINT_TO_FP: |
| 4093 | CastOpc = ISD::ZERO_EXTEND; |
| 4094 | Opc = ISD::UINT_TO_FP; |
| 4095 | break; |
| 4096 | } |
| 4097 | |
| 4098 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 4099 | return DAG.getNode(Opc, dl, VT, Op); |
| 4100 | } |
| 4101 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4102 | SDValue ARMTargetLowering::LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) const { |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4103 | EVT VT = Op.getValueType(); |
| Cameron Zwarich | 143f9ae | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 4104 | if (VT.isVector()) |
| 4105 | return LowerVectorINT_TO_FP(Op, DAG); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4106 | if (Subtarget->isFPOnlySP() && Op.getValueType() == MVT::f64) { |
| 4107 | RTLIB::Libcall LC; |
| 4108 | if (Op.getOpcode() == ISD::SINT_TO_FP) |
| 4109 | LC = RTLIB::getSINTTOFP(Op.getOperand(0).getValueType(), |
| 4110 | Op.getValueType()); |
| 4111 | else |
| 4112 | LC = RTLIB::getUINTTOFP(Op.getOperand(0).getValueType(), |
| 4113 | Op.getValueType()); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 4114 | return makeLibCall(DAG, LC, Op.getValueType(), Op.getOperand(0), |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4115 | /*isSigned*/ false, SDLoc(Op)).first; |
| 4116 | } |
| 4117 | |
| James Molloy | fa04115 | 2015-03-23 16:15:16 +0000 | [diff] [blame] | 4118 | return Op; |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4119 | } |
| 4120 | |
| Evan Cheng | 25f9364 | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 4121 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4122 | // Implement fcopysign with a fabs and a conditional fneg. |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4123 | SDValue Tmp0 = Op.getOperand(0); |
| 4124 | SDValue Tmp1 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4125 | SDLoc dl(Op); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4126 | EVT VT = Op.getValueType(); |
| 4127 | EVT SrcVT = Tmp1.getValueType(); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4128 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 4129 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 4130 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 4131 | |
| 4132 | if (UseNEON) { |
| 4133 | // Use VBSL to copy the sign bit. |
| 4134 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 4135 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4136 | DAG.getTargetConstant(EncodedVal, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4137 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 4138 | if (VT == MVT::f64) |
| 4139 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 4140 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4141 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4142 | else /*if (VT == MVT::f32)*/ |
| 4143 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 4144 | if (SrcVT == MVT::f32) { |
| 4145 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 4146 | if (VT == MVT::f64) |
| 4147 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 4148 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4149 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | 12bb05b | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 4150 | } else if (VT == MVT::f32) |
| 4151 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 4152 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4153 | DAG.getConstant(32, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4154 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 4155 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 4156 | |
| 4157 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4158 | dl, MVT::i32); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4159 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 4160 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 4161 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4162 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4163 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 4164 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 4165 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
| Evan Cheng | 6e3d443 | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 4166 | if (VT == MVT::f32) { |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4167 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 4168 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4169 | DAG.getConstant(0, dl, MVT::i32)); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4170 | } else { |
| 4171 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 4172 | } |
| 4173 | |
| 4174 | return Res; |
| 4175 | } |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4176 | |
| 4177 | // Bitcast operand 1 to i32. |
| 4178 | if (SrcVT == MVT::f64) |
| 4179 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4180 | Tmp1).getValue(1); |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4181 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 4182 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4183 | // Or in the signbit with integer operations. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4184 | SDValue Mask1 = DAG.getConstant(0x80000000, dl, MVT::i32); |
| 4185 | SDValue Mask2 = DAG.getConstant(0x7fffffff, dl, MVT::i32); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4186 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 4187 | if (VT == MVT::f32) { |
| 4188 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 4189 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 4190 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 4191 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
| Evan Cheng | 2da1c95 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 4192 | } |
| 4193 | |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4194 | // f64: Or the high part with signbit and then combine two parts. |
| 4195 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4196 | Tmp0); |
| Evan Cheng | d6b641e | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 4197 | SDValue Lo = Tmp0.getValue(0); |
| 4198 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 4199 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 4200 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4203 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 4204 | MachineFunction &MF = DAG.getMachineFunction(); |
| 4205 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 4206 | MFI->setReturnAddressIsTaken(true); |
| 4207 | |
| Bill Wendling | 908bf81 | 2014-01-06 00:43:20 +0000 | [diff] [blame] | 4208 | if (verifyReturnAddressArgumentIsConstant(Op, DAG)) |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 4209 | return SDValue(); |
| Bill Wendling | df7dd28 | 2014-01-05 01:47:20 +0000 | [diff] [blame] | 4210 | |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4211 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4212 | SDLoc dl(Op); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4213 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 4214 | if (Depth) { |
| 4215 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4216 | SDValue Offset = DAG.getConstant(4, dl, MVT::i32); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4217 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 4218 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4219 | MachinePointerInfo(), false, false, false, 0); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | // 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] | 4223 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4224 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 4225 | } |
| 4226 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4227 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
| Saleem Abdulrasool | f11f4b4 | 2014-05-18 03:18:09 +0000 | [diff] [blame] | 4228 | const ARMBaseRegisterInfo &ARI = |
| 4229 | *static_cast<const ARMBaseRegisterInfo*>(RegInfo); |
| 4230 | MachineFunction &MF = DAG.getMachineFunction(); |
| 4231 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4232 | MFI->setFrameAddressIsTaken(true); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4233 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4234 | EVT VT = Op.getValueType(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4235 | SDLoc dl(Op); // FIXME probably not meaningful |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4236 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| Saleem Abdulrasool | f11f4b4 | 2014-05-18 03:18:09 +0000 | [diff] [blame] | 4237 | unsigned FrameReg = ARI.getFrameRegister(MF); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4238 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 4239 | while (Depth--) |
| Chris Lattner | 7727d05 | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 4240 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 4241 | MachinePointerInfo(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 4242 | false, false, false, 0); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4243 | return FrameAddr; |
| 4244 | } |
| 4245 | |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4246 | // FIXME? Maybe this could be a TableGen attribute on some registers and |
| 4247 | // this table could be generated automatically from RegInfo. |
| Pat Gavlin | a717f25 | 2015-07-09 17:40:29 +0000 | [diff] [blame] | 4248 | unsigned ARMTargetLowering::getRegisterByName(const char* RegName, EVT VT, |
| 4249 | SelectionDAG &DAG) const { |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4250 | unsigned Reg = StringSwitch<unsigned>(RegName) |
| 4251 | .Case("sp", ARM::SP) |
| 4252 | .Default(0); |
| 4253 | if (Reg) |
| 4254 | return Reg; |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 4255 | report_fatal_error(Twine("Invalid register name \"" |
| 4256 | + StringRef(RegName) + "\".")); |
| 4257 | } |
| 4258 | |
| 4259 | // Result is 64 bit value so split into two 32 bit values and return as a |
| 4260 | // pair of values. |
| 4261 | static void ExpandREAD_REGISTER(SDNode *N, SmallVectorImpl<SDValue> &Results, |
| 4262 | SelectionDAG &DAG) { |
| 4263 | SDLoc DL(N); |
| 4264 | |
| 4265 | // This function is only supposed to be called for i64 type destination. |
| 4266 | assert(N->getValueType(0) == MVT::i64 |
| 4267 | && "ExpandREAD_REGISTER called for non-i64 type result."); |
| 4268 | |
| 4269 | SDValue Read = DAG.getNode(ISD::READ_REGISTER, DL, |
| 4270 | DAG.getVTList(MVT::i32, MVT::i32, MVT::Other), |
| 4271 | N->getOperand(0), |
| 4272 | N->getOperand(1)); |
| 4273 | |
| 4274 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Read.getValue(0), |
| 4275 | Read.getValue(1))); |
| 4276 | Results.push_back(Read.getOperand(0)); |
| Renato Golin | c7aea40 | 2014-05-06 16:51:25 +0000 | [diff] [blame] | 4277 | } |
| 4278 | |
| Quentin Colombet | 901f036 | 2015-12-04 01:53:14 +0000 | [diff] [blame] | 4279 | /// \p BC is a bitcast that is about to be turned into a VMOVDRR. |
| 4280 | /// When \p DstVT, the destination type of \p BC, is on the vector |
| 4281 | /// register bank and the source of bitcast, \p Op, operates on the same bank, |
| 4282 | /// it might be possible to combine them, such that everything stays on the |
| 4283 | /// vector register bank. |
| 4284 | /// \p return The node that would replace \p BT, if the combine |
| 4285 | /// is possible. |
| 4286 | static SDValue CombineVMOVDRRCandidateWithVecOp(const SDNode *BC, |
| 4287 | SelectionDAG &DAG) { |
| 4288 | SDValue Op = BC->getOperand(0); |
| 4289 | EVT DstVT = BC->getValueType(0); |
| 4290 | |
| 4291 | // The only vector instruction that can produce a scalar (remember, |
| 4292 | // since the bitcast was about to be turned into VMOVDRR, the source |
| 4293 | // type is i64) from a vector is EXTRACT_VECTOR_ELT. |
| 4294 | // Moreover, we can do this combine only if there is one use. |
| 4295 | // Finally, if the destination type is not a vector, there is not |
| 4296 | // much point on forcing everything on the vector bank. |
| 4297 | if (!DstVT.isVector() || Op.getOpcode() != ISD::EXTRACT_VECTOR_ELT || |
| 4298 | !Op.hasOneUse()) |
| 4299 | return SDValue(); |
| 4300 | |
| 4301 | // If the index is not constant, we will introduce an additional |
| 4302 | // multiply that will stick. |
| 4303 | // Give up in that case. |
| 4304 | ConstantSDNode *Index = dyn_cast<ConstantSDNode>(Op.getOperand(1)); |
| 4305 | if (!Index) |
| 4306 | return SDValue(); |
| 4307 | unsigned DstNumElt = DstVT.getVectorNumElements(); |
| 4308 | |
| 4309 | // Compute the new index. |
| 4310 | const APInt &APIntIndex = Index->getAPIntValue(); |
| 4311 | APInt NewIndex(APIntIndex.getBitWidth(), DstNumElt); |
| 4312 | NewIndex *= APIntIndex; |
| 4313 | // Check if the new constant index fits into i32. |
| 4314 | if (NewIndex.getBitWidth() > 32) |
| 4315 | return SDValue(); |
| 4316 | |
| 4317 | // vMTy bitcast(i64 extractelt vNi64 src, i32 index) -> |
| 4318 | // vMTy extractsubvector vNxMTy (bitcast vNi64 src), i32 index*M) |
| 4319 | SDLoc dl(Op); |
| 4320 | SDValue ExtractSrc = Op.getOperand(0); |
| 4321 | EVT VecVT = EVT::getVectorVT( |
| 4322 | *DAG.getContext(), DstVT.getScalarType(), |
| 4323 | ExtractSrc.getValueType().getVectorNumElements() * DstNumElt); |
| 4324 | SDValue BitCast = DAG.getNode(ISD::BITCAST, dl, VecVT, ExtractSrc); |
| 4325 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DstVT, BitCast, |
| 4326 | DAG.getConstant(NewIndex.getZExtValue(), dl, MVT::i32)); |
| 4327 | } |
| 4328 | |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4329 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4330 | /// expand a bit convert where either the source or destination type is i64 to |
| 4331 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 4332 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 4333 | /// vectors), since the legalizer won't know what to do with that. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4334 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4335 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4336 | SDLoc dl(N); |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4337 | SDValue Op = N->getOperand(0); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4338 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4339 | // This function is only supposed to be called for i64 types, either as the |
| 4340 | // source or destination of the bit convert. |
| 4341 | EVT SrcVT = Op.getValueType(); |
| 4342 | EVT DstVT = N->getValueType(0); |
| 4343 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4344 | "ExpandBITCAST called for non-i64 type"); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4345 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4346 | // Turn i64->f64 into VMOVDRR. |
| 4347 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
| Quentin Colombet | 901f036 | 2015-12-04 01:53:14 +0000 | [diff] [blame] | 4348 | // Do not force values to GPRs (this is what VMOVDRR does for the inputs) |
| 4349 | // if we can combine the bitcast with its source. |
| 4350 | if (SDValue Val = CombineVMOVDRRCandidateWithVecOp(N, DAG)) |
| 4351 | return Val; |
| 4352 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4353 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4354 | DAG.getConstant(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4355 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4356 | DAG.getConstant(1, dl, MVT::i32)); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4357 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
| Bob Wilson | f07d33d | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 4358 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
| Evan Cheng | 297b32a | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 4359 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4360 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 4361 | // Turn f64->i64 into VMOVRRD. |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4362 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame] | 4363 | SDValue Cvt; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 4364 | if (DAG.getDataLayout().isBigEndian() && SrcVT.isVector() && |
| Christian Pirker | 6692e7c | 2014-05-14 16:59:44 +0000 | [diff] [blame] | 4365 | SrcVT.getVectorNumElements() > 1) |
| Christian Pirker | 238c7c1 | 2014-05-12 11:19:20 +0000 | [diff] [blame] | 4366 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 4367 | DAG.getVTList(MVT::i32, MVT::i32), |
| 4368 | DAG.getNode(ARMISD::VREV64, dl, SrcVT, Op)); |
| 4369 | else |
| 4370 | Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 4371 | DAG.getVTList(MVT::i32, MVT::i32), Op); |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4372 | // Merge the pieces into a single i64 value. |
| 4373 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 4374 | } |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4375 | |
| Bob Wilson | 59b70ea | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 4376 | return SDValue(); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4379 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4380 | /// Zero vectors are used to represent vector negation and in those cases |
| 4381 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 4382 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 4383 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 4384 | /// zero vector. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4385 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, SDLoc dl) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4386 | assert(VT.isVector() && "Expected a vector type"); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4387 | // The canonical modified immediate encoding of a zero vector is....0! |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4388 | SDValue EncodedVal = DAG.getTargetConstant(0, dl, MVT::i32); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4389 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 4390 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4391 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4394 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 4395 | /// 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] | 4396 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 4397 | SelectionDAG &DAG) const { |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4398 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 4399 | EVT VT = Op.getValueType(); |
| 4400 | unsigned VTBits = VT.getSizeInBits(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4401 | SDLoc dl(Op); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4402 | SDValue ShOpLo = Op.getOperand(0); |
| 4403 | SDValue ShOpHi = Op.getOperand(1); |
| 4404 | SDValue ShAmt = Op.getOperand(2); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4405 | SDValue ARMcc; |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4406 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4407 | |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4408 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 4409 | |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4410 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4411 | DAG.getConstant(VTBits, dl, MVT::i32), ShAmt); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4412 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 4413 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4414 | DAG.getConstant(VTBits, dl, MVT::i32)); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4415 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 4416 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4417 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4418 | |
| 4419 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4420 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, dl, MVT::i32), |
| 4421 | ISD::SETGE, ARMcc, DAG, dl); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4422 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4423 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4424 | CCR, Cmp); |
| 4425 | |
| 4426 | SDValue Ops[2] = { Lo, Hi }; |
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4427 | return DAG.getMergeValues(Ops, dl); |
| Jim Grosbach | 624fcb2 | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 4428 | } |
| 4429 | |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4430 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 4431 | /// 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] | 4432 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 4433 | SelectionDAG &DAG) const { |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4434 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 4435 | EVT VT = Op.getValueType(); |
| 4436 | unsigned VTBits = VT.getSizeInBits(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4437 | SDLoc dl(Op); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4438 | SDValue ShOpLo = Op.getOperand(0); |
| 4439 | SDValue ShOpHi = Op.getOperand(1); |
| 4440 | SDValue ShAmt = Op.getOperand(2); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4441 | SDValue ARMcc; |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4442 | |
| 4443 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 4444 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4445 | DAG.getConstant(VTBits, dl, MVT::i32), ShAmt); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4446 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 4447 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4448 | DAG.getConstant(VTBits, dl, MVT::i32)); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4449 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 4450 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 4451 | |
| 4452 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 4453 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4454 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, dl, MVT::i32), |
| 4455 | ISD::SETGE, ARMcc, DAG, dl); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4456 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 4457 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4458 | CCR, Cmp); |
| 4459 | |
| 4460 | SDValue Ops[2] = { Lo, Hi }; |
| Craig Topper | 64941d9 | 2014-04-27 19:20:57 +0000 | [diff] [blame] | 4461 | return DAG.getMergeValues(Ops, dl); |
| Jim Grosbach | 5d99404 | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4464 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4465 | SelectionDAG &DAG) const { |
| 4466 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 4467 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 4468 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 4469 | // so that the shift + and get folded into a bitfield extract. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4470 | SDLoc dl(Op); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4471 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4472 | DAG.getConstant(Intrinsic::arm_get_fpscr, dl, |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4473 | MVT::i32)); |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4474 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4475 | DAG.getConstant(1U << 22, dl, MVT::i32)); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4476 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4477 | DAG.getConstant(22, dl, MVT::i32)); |
| Jim Grosbach | 535d3b4 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 4478 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4479 | DAG.getConstant(3, dl, MVT::i32)); |
| Nate Begeman | b69b182 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 4480 | } |
| 4481 | |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4482 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 4483 | const ARMSubtarget *ST) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4484 | SDLoc dl(N); |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 4485 | EVT VT = N->getValueType(0); |
| 4486 | if (VT.isVector()) { |
| 4487 | assert(ST->hasNEON()); |
| 4488 | |
| 4489 | // Compute the least significant set bit: LSB = X & -X |
| 4490 | SDValue X = N->getOperand(0); |
| 4491 | SDValue NX = DAG.getNode(ISD::SUB, dl, VT, getZeroVector(VT, DAG, dl), X); |
| 4492 | SDValue LSB = DAG.getNode(ISD::AND, dl, VT, X, NX); |
| 4493 | |
| 4494 | EVT ElemTy = VT.getVectorElementType(); |
| 4495 | |
| 4496 | if (ElemTy == MVT::i8) { |
| 4497 | // Compute with: cttz(x) = ctpop(lsb - 1) |
| 4498 | SDValue One = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4499 | DAG.getTargetConstant(1, dl, ElemTy)); |
| 4500 | SDValue Bits = DAG.getNode(ISD::SUB, dl, VT, LSB, One); |
| 4501 | return DAG.getNode(ISD::CTPOP, dl, VT, Bits); |
| 4502 | } |
| 4503 | |
| 4504 | if ((ElemTy == MVT::i16 || ElemTy == MVT::i32) && |
| 4505 | (N->getOpcode() == ISD::CTTZ_ZERO_UNDEF)) { |
| 4506 | // Compute with: cttz(x) = (width - 1) - ctlz(lsb), if x != 0 |
| 4507 | unsigned NumBits = ElemTy.getSizeInBits(); |
| 4508 | SDValue WidthMinus1 = |
| 4509 | DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4510 | DAG.getTargetConstant(NumBits - 1, dl, ElemTy)); |
| 4511 | SDValue CTLZ = DAG.getNode(ISD::CTLZ, dl, VT, LSB); |
| 4512 | return DAG.getNode(ISD::SUB, dl, VT, WidthMinus1, CTLZ); |
| 4513 | } |
| 4514 | |
| 4515 | // Compute with: cttz(x) = ctpop(lsb - 1) |
| 4516 | |
| 4517 | // Since we can only compute the number of bits in a byte with vcnt.8, we |
| 4518 | // have to gather the result with pairwise addition (vpaddl) for i16, i32, |
| 4519 | // and i64. |
| 4520 | |
| 4521 | // Compute LSB - 1. |
| 4522 | SDValue Bits; |
| 4523 | if (ElemTy == MVT::i64) { |
| 4524 | // Load constant 0xffff'ffff'ffff'ffff to register. |
| 4525 | SDValue FF = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4526 | DAG.getTargetConstant(0x1eff, dl, MVT::i32)); |
| 4527 | Bits = DAG.getNode(ISD::ADD, dl, VT, LSB, FF); |
| 4528 | } else { |
| 4529 | SDValue One = DAG.getNode(ARMISD::VMOVIMM, dl, VT, |
| 4530 | DAG.getTargetConstant(1, dl, ElemTy)); |
| 4531 | Bits = DAG.getNode(ISD::SUB, dl, VT, LSB, One); |
| 4532 | } |
| 4533 | |
| 4534 | // Count #bits with vcnt.8. |
| 4535 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 4536 | SDValue BitsVT8 = DAG.getNode(ISD::BITCAST, dl, VT8Bit, Bits); |
| 4537 | SDValue Cnt8 = DAG.getNode(ISD::CTPOP, dl, VT8Bit, BitsVT8); |
| 4538 | |
| 4539 | // Gather the #bits with vpaddl (pairwise add.) |
| 4540 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 4541 | SDValue Cnt16 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT16Bit, |
| 4542 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4543 | Cnt8); |
| 4544 | if (ElemTy == MVT::i16) |
| 4545 | return Cnt16; |
| 4546 | |
| 4547 | EVT VT32Bit = VT.is64BitVector() ? MVT::v2i32 : MVT::v4i32; |
| 4548 | SDValue Cnt32 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT32Bit, |
| 4549 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4550 | Cnt16); |
| 4551 | if (ElemTy == MVT::i32) |
| 4552 | return Cnt32; |
| 4553 | |
| 4554 | assert(ElemTy == MVT::i64); |
| 4555 | SDValue Cnt64 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 4556 | DAG.getTargetConstant(Intrinsic::arm_neon_vpaddlu, dl, MVT::i32), |
| 4557 | Cnt32); |
| 4558 | return Cnt64; |
| 4559 | } |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4560 | |
| 4561 | if (!ST->hasV6T2Ops()) |
| 4562 | return SDValue(); |
| 4563 | |
| James Molloy | b564098 | 2015-11-13 16:05:22 +0000 | [diff] [blame] | 4564 | SDValue rbit = DAG.getNode(ISD::BITREVERSE, dl, VT, N->getOperand(0)); |
| Jim Grosbach | 8546ec9 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4565 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 4566 | } |
| 4567 | |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4568 | /// getCTPOP16BitCounts - Returns a v8i8/v16i8 vector containing the bit-count |
| 4569 | /// for each 16-bit element from operand, repeated. The basic idea is to |
| 4570 | /// leverage vcnt to get the 8-bit counts, gather and add the results. |
| 4571 | /// |
| 4572 | /// Trace for v4i16: |
| 4573 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 4574 | /// cast: N0 = [w0 w1 w2 w3 w4 w5 w6 w7] (v0 = [w0 w1], wi 8-bit element) |
| 4575 | /// 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] | 4576 | /// vrev: N2 = [b1 b0 b3 b2 b5 b4 b7 b6] |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4577 | /// [b0 b1 b2 b3 b4 b5 b6 b7] |
| 4578 | /// +[b1 b0 b3 b2 b5 b4 b7 b6] |
| 4579 | /// N3=N1+N2 = [k0 k0 k1 k1 k2 k2 k3 k3] (k0 = b0+b1 = bit-count of 16-bit v0, |
| 4580 | /// vuzp: = [k0 k1 k2 k3 k0 k1 k2 k3] each ki is 8-bits) |
| 4581 | static SDValue getCTPOP16BitCounts(SDNode *N, SelectionDAG &DAG) { |
| 4582 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4583 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4584 | |
| 4585 | EVT VT8Bit = VT.is64BitVector() ? MVT::v8i8 : MVT::v16i8; |
| 4586 | SDValue N0 = DAG.getNode(ISD::BITCAST, DL, VT8Bit, N->getOperand(0)); |
| 4587 | SDValue N1 = DAG.getNode(ISD::CTPOP, DL, VT8Bit, N0); |
| 4588 | SDValue N2 = DAG.getNode(ARMISD::VREV16, DL, VT8Bit, N1); |
| 4589 | SDValue N3 = DAG.getNode(ISD::ADD, DL, VT8Bit, N1, N2); |
| 4590 | return DAG.getNode(ARMISD::VUZP, DL, VT8Bit, N3, N3); |
| 4591 | } |
| 4592 | |
| 4593 | /// lowerCTPOP16BitElements - Returns a v4i16/v8i16 vector containing the |
| 4594 | /// bit-count for each 16-bit element from the operand. We need slightly |
| 4595 | /// different sequencing for v4i16 and v8i16 to stay within NEON's available |
| 4596 | /// 64/128-bit registers. |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 4597 | /// |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4598 | /// Trace for v4i16: |
| 4599 | /// input = [v0 v1 v2 v3 ] (vi 16-bit element) |
| 4600 | /// v8i8: BitCounts = [k0 k1 k2 k3 k0 k1 k2 k3 ] (ki is the bit-count of vi) |
| 4601 | /// v8i16:Extended = [k0 k1 k2 k3 k0 k1 k2 k3 ] |
| 4602 | /// v4i16:Extracted = [k0 k1 k2 k3 ] |
| 4603 | static SDValue lowerCTPOP16BitElements(SDNode *N, SelectionDAG &DAG) { |
| 4604 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4605 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4606 | |
| 4607 | SDValue BitCounts = getCTPOP16BitCounts(N, DAG); |
| 4608 | if (VT.is64BitVector()) { |
| 4609 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, BitCounts); |
| 4610 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, Extended, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4611 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4612 | } else { |
| 4613 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v8i8, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4614 | BitCounts, DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4615 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v8i16, Extracted); |
| 4616 | } |
| 4617 | } |
| 4618 | |
| 4619 | /// lowerCTPOP32BitElements - Returns a v2i32/v4i32 vector containing the |
| 4620 | /// bit-count for each 32-bit element from the operand. The idea here is |
| 4621 | /// to split the vector into 16-bit elements, leverage the 16-bit count |
| 4622 | /// routine, and then combine the results. |
| 4623 | /// |
| 4624 | /// Trace for v2i32 (v4i32 similar with Extracted/Extended exchanged): |
| 4625 | /// input = [v0 v1 ] (vi: 32-bit elements) |
| 4626 | /// Bitcast = [w0 w1 w2 w3 ] (wi: 16-bit elements, v0 = [w0 w1]) |
| 4627 | /// 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] | 4628 | /// vrev: N0 = [k1 k0 k3 k2 ] |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4629 | /// [k0 k1 k2 k3 ] |
| 4630 | /// N1 =+[k1 k0 k3 k2 ] |
| 4631 | /// [k0 k2 k1 k3 ] |
| 4632 | /// N2 =+[k1 k3 k0 k2 ] |
| 4633 | /// [k0 k2 k1 k3 ] |
| 4634 | /// Extended =+[k1 k3 k0 k2 ] |
| 4635 | /// [k0 k2 ] |
| 4636 | /// Extracted=+[k1 k3 ] |
| 4637 | /// |
| 4638 | static SDValue lowerCTPOP32BitElements(SDNode *N, SelectionDAG &DAG) { |
| 4639 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4640 | SDLoc DL(N); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4641 | |
| 4642 | EVT VT16Bit = VT.is64BitVector() ? MVT::v4i16 : MVT::v8i16; |
| 4643 | |
| 4644 | SDValue Bitcast = DAG.getNode(ISD::BITCAST, DL, VT16Bit, N->getOperand(0)); |
| 4645 | SDValue Counts16 = lowerCTPOP16BitElements(Bitcast.getNode(), DAG); |
| 4646 | SDValue N0 = DAG.getNode(ARMISD::VREV32, DL, VT16Bit, Counts16); |
| 4647 | SDValue N1 = DAG.getNode(ISD::ADD, DL, VT16Bit, Counts16, N0); |
| 4648 | SDValue N2 = DAG.getNode(ARMISD::VUZP, DL, VT16Bit, N1, N1); |
| 4649 | |
| 4650 | if (VT.is64BitVector()) { |
| 4651 | SDValue Extended = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, N2); |
| 4652 | return DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v2i32, Extended, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4653 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4654 | } else { |
| 4655 | SDValue Extracted = DAG.getNode(ISD::EXTRACT_SUBVECTOR, DL, MVT::v4i16, N2, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4656 | DAG.getIntPtrConstant(0, DL)); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4657 | return DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::v4i32, Extracted); |
| 4658 | } |
| 4659 | } |
| 4660 | |
| 4661 | static SDValue LowerCTPOP(SDNode *N, SelectionDAG &DAG, |
| 4662 | const ARMSubtarget *ST) { |
| 4663 | EVT VT = N->getValueType(0); |
| 4664 | |
| 4665 | assert(ST->hasNEON() && "Custom ctpop lowering requires NEON."); |
| Matt Beaumont-Gay | 50f61b6 | 2012-12-04 23:54:02 +0000 | [diff] [blame] | 4666 | assert((VT == MVT::v2i32 || VT == MVT::v4i32 || |
| 4667 | VT == MVT::v4i16 || VT == MVT::v8i16) && |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 4668 | "Unexpected type for custom ctpop lowering"); |
| 4669 | |
| 4670 | if (VT.getVectorElementType() == MVT::i32) |
| 4671 | return lowerCTPOP32BitElements(N, DAG); |
| 4672 | else |
| 4673 | return lowerCTPOP16BitElements(N, DAG); |
| 4674 | } |
| 4675 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4676 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 4677 | const ARMSubtarget *ST) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4678 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4679 | SDLoc dl(N); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4680 | |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4681 | if (!VT.isVector()) |
| 4682 | return SDValue(); |
| 4683 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4684 | // Lower vector shifts on NEON to use VSHL. |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4685 | assert(ST->hasNEON() && "unexpected vector shift"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4686 | |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4687 | // Left shifts translate directly to the vshiftu intrinsic. |
| 4688 | if (N->getOpcode() == ISD::SHL) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4689 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4690 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, dl, |
| 4691 | MVT::i32), |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4692 | N->getOperand(0), N->getOperand(1)); |
| 4693 | |
| 4694 | assert((N->getOpcode() == ISD::SRA || |
| 4695 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 4696 | |
| 4697 | // NEON uses the same intrinsics for both left and right shifts. For |
| 4698 | // right shifts, the shift amounts are negative, so negate the vector of |
| 4699 | // shift amounts. |
| 4700 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 4701 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 4702 | getZeroVector(ShiftVT, DAG, dl), |
| 4703 | N->getOperand(1)); |
| 4704 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 4705 | Intrinsic::arm_neon_vshifts : |
| 4706 | Intrinsic::arm_neon_vshiftu); |
| 4707 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4708 | DAG.getConstant(vshiftInt, dl, MVT::i32), |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4709 | N->getOperand(0), NegatedCount); |
| 4710 | } |
| 4711 | |
| 4712 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 4713 | const ARMSubtarget *ST) { |
| 4714 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4715 | SDLoc dl(N); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4716 | |
| Eli Friedman | 682d8c1 | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 4717 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 4718 | if (VT != MVT::i64) |
| 4719 | return SDValue(); |
| 4720 | |
| 4721 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4722 | "Unknown shift to lower!"); |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4723 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4724 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 4725 | if (!isOneConstant(N->getOperand(1))) |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4726 | return SDValue(); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4727 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4728 | // If we are in thumb mode, we don't have RRX. |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 4729 | if (ST->isThumb1Only()) return SDValue(); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4730 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4731 | // 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] | 4732 | 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] | 4733 | DAG.getConstant(0, dl, MVT::i32)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4734 | 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] | 4735 | DAG.getConstant(1, dl, MVT::i32)); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4736 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4737 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 4738 | // captures the result into a carry flag. |
| 4739 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 4740 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), Hi); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4741 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4742 | // 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] | 4743 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 4744 | |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4745 | // Merge the pieces into a single i64 value. |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4746 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4747 | } |
| 4748 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4749 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 4750 | SDValue TmpOp0, TmpOp1; |
| 4751 | bool Invert = false; |
| 4752 | bool Swap = false; |
| 4753 | unsigned Opc = 0; |
| 4754 | |
| 4755 | SDValue Op0 = Op.getOperand(0); |
| 4756 | SDValue Op1 = Op.getOperand(1); |
| 4757 | SDValue CC = Op.getOperand(2); |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4758 | EVT CmpVT = Op0.getValueType().changeVectorElementTypeToInteger(); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 4759 | EVT VT = Op.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4760 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 4761 | SDLoc dl(Op); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4762 | |
| James Molloy | bf17009 | 2015-08-20 16:33:44 +0000 | [diff] [blame] | 4763 | if (CmpVT.getVectorElementType() == MVT::i64) |
| 4764 | // 64-bit comparisons are not legal. We've marked SETCC as non-Custom, |
| 4765 | // but it's possible that our operands are 64-bit but our result is 32-bit. |
| 4766 | // Bail in this case. |
| 4767 | return SDValue(); |
| 4768 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 4769 | if (Op1.getValueType().isFloatingPoint()) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4770 | switch (SetCCOpcode) { |
| David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4771 | default: llvm_unreachable("Illegal FP comparison"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4772 | case ISD::SETUNE: |
| 4773 | case ISD::SETNE: Invert = true; // Fallthrough |
| 4774 | case ISD::SETOEQ: |
| 4775 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 4776 | case ISD::SETOLT: |
| 4777 | case ISD::SETLT: Swap = true; // Fallthrough |
| 4778 | case ISD::SETOGT: |
| 4779 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 4780 | case ISD::SETOLE: |
| 4781 | case ISD::SETLE: Swap = true; // Fallthrough |
| 4782 | case ISD::SETOGE: |
| 4783 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 4784 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 4785 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 4786 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 4787 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 4788 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 4789 | case ISD::SETONE: |
| 4790 | // Expand this to (OLT | OGT). |
| 4791 | TmpOp0 = Op0; |
| 4792 | TmpOp1 = Op1; |
| 4793 | Opc = ISD::OR; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4794 | Op0 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp1, TmpOp0); |
| 4795 | Op1 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp0, TmpOp1); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4796 | break; |
| 4797 | case ISD::SETUO: Invert = true; // Fallthrough |
| 4798 | case ISD::SETO: |
| 4799 | // Expand this to (OLT | OGE). |
| 4800 | TmpOp0 = Op0; |
| 4801 | TmpOp1 = Op1; |
| 4802 | Opc = ISD::OR; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4803 | Op0 = DAG.getNode(ARMISD::VCGT, dl, CmpVT, TmpOp1, TmpOp0); |
| 4804 | Op1 = DAG.getNode(ARMISD::VCGE, dl, CmpVT, TmpOp0, TmpOp1); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4805 | break; |
| 4806 | } |
| 4807 | } else { |
| 4808 | // Integer comparisons. |
| 4809 | switch (SetCCOpcode) { |
| David Blaikie | 46a9f01 | 2012-01-20 21:51:11 +0000 | [diff] [blame] | 4810 | default: llvm_unreachable("Illegal integer comparison"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4811 | case ISD::SETNE: Invert = true; |
| 4812 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 4813 | case ISD::SETLT: Swap = true; |
| 4814 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 4815 | case ISD::SETLE: Swap = true; |
| 4816 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 4817 | case ISD::SETULT: Swap = true; |
| 4818 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 4819 | case ISD::SETULE: Swap = true; |
| 4820 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 4821 | } |
| 4822 | |
| Nick Lewycky | a21d3da | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 4823 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4824 | if (Opc == ARMISD::VCEQ) { |
| 4825 | |
| 4826 | SDValue AndOp; |
| 4827 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4828 | AndOp = Op0; |
| 4829 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 4830 | AndOp = Op1; |
| 4831 | |
| 4832 | // Ignore bitconvert. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4833 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4834 | AndOp = AndOp.getOperand(0); |
| 4835 | |
| 4836 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 4837 | Opc = ARMISD::VTST; |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4838 | Op0 = DAG.getNode(ISD::BITCAST, dl, CmpVT, AndOp.getOperand(0)); |
| 4839 | Op1 = DAG.getNode(ISD::BITCAST, dl, CmpVT, AndOp.getOperand(1)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4840 | Invert = !Invert; |
| 4841 | } |
| 4842 | } |
| 4843 | } |
| 4844 | |
| 4845 | if (Swap) |
| 4846 | std::swap(Op0, Op1); |
| 4847 | |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4848 | // If one of the operands is a constant vector zero, attempt to fold the |
| 4849 | // comparison to a specialized compare-against-zero form. |
| 4850 | SDValue SingleOp; |
| 4851 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 4852 | SingleOp = Op0; |
| 4853 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 4854 | if (Opc == ARMISD::VCGE) |
| 4855 | Opc = ARMISD::VCLEZ; |
| 4856 | else if (Opc == ARMISD::VCGT) |
| 4857 | Opc = ARMISD::VCLTZ; |
| 4858 | SingleOp = Op1; |
| 4859 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4860 | |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4861 | SDValue Result; |
| 4862 | if (SingleOp.getNode()) { |
| 4863 | switch (Opc) { |
| 4864 | case ARMISD::VCEQ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4865 | Result = DAG.getNode(ARMISD::VCEQZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4866 | case ARMISD::VCGE: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4867 | Result = DAG.getNode(ARMISD::VCGEZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4868 | case ARMISD::VCLEZ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4869 | Result = DAG.getNode(ARMISD::VCLEZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4870 | case ARMISD::VCGT: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4871 | Result = DAG.getNode(ARMISD::VCGTZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4872 | case ARMISD::VCLTZ: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4873 | Result = DAG.getNode(ARMISD::VCLTZ, dl, CmpVT, SingleOp); break; |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4874 | default: |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4875 | Result = DAG.getNode(Opc, dl, CmpVT, Op0, Op1); |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4876 | } |
| 4877 | } else { |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4878 | Result = DAG.getNode(Opc, dl, CmpVT, Op0, Op1); |
| Owen Anderson | c7baee3 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 4879 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4880 | |
| Tim Northover | 45aa89c | 2015-02-08 00:50:47 +0000 | [diff] [blame] | 4881 | Result = DAG.getSExtOrTrunc(Result, dl, VT); |
| 4882 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4883 | if (Invert) |
| 4884 | Result = DAG.getNOT(dl, Result, VT); |
| 4885 | |
| 4886 | return Result; |
| 4887 | } |
| 4888 | |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4889 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 4890 | /// valid vector constant for a NEON instruction with a "modified immediate" |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4891 | /// operand (e.g., VMOV). If so, return the encoded value. |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 4892 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 4893 | unsigned SplatBitSize, SelectionDAG &DAG, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 4894 | SDLoc dl, EVT &VT, bool is128Bits, |
| 4895 | NEONModImmType type) { |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4896 | unsigned OpCmode, Imm; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4897 | |
| Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4898 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 4899 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 4900 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 4901 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 4902 | // 32-bit version. |
| 4903 | if (SplatBits == 0) |
| 4904 | SplatBitSize = 32; |
| 4905 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4906 | switch (SplatBitSize) { |
| 4907 | case 8: |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4908 | if (type != VMOVModImm) |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4909 | return SDValue(); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4910 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4911 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4912 | OpCmode = 0xe; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4913 | Imm = SplatBits; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4914 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4915 | break; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4916 | |
| 4917 | case 16: |
| 4918 | // 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] | 4919 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4920 | if ((SplatBits & ~0xff) == 0) { |
| 4921 | // Value = 0x00nn: Op=x, Cmode=100x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4922 | OpCmode = 0x8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4923 | Imm = SplatBits; |
| 4924 | break; |
| 4925 | } |
| 4926 | if ((SplatBits & ~0xff00) == 0) { |
| 4927 | // Value = 0xnn00: Op=x, Cmode=101x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4928 | OpCmode = 0xa; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4929 | Imm = SplatBits >> 8; |
| 4930 | break; |
| 4931 | } |
| 4932 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4933 | |
| 4934 | case 32: |
| 4935 | // NEON's 32-bit VMOV supports splat values where: |
| 4936 | // * only one byte is nonzero, or |
| 4937 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 4938 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 4939 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4940 | if ((SplatBits & ~0xff) == 0) { |
| 4941 | // Value = 0x000000nn: Op=x, Cmode=000x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4942 | OpCmode = 0; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4943 | Imm = SplatBits; |
| 4944 | break; |
| 4945 | } |
| 4946 | if ((SplatBits & ~0xff00) == 0) { |
| 4947 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4948 | OpCmode = 0x2; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4949 | Imm = SplatBits >> 8; |
| 4950 | break; |
| 4951 | } |
| 4952 | if ((SplatBits & ~0xff0000) == 0) { |
| 4953 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4954 | OpCmode = 0x4; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4955 | Imm = SplatBits >> 16; |
| 4956 | break; |
| 4957 | } |
| 4958 | if ((SplatBits & ~0xff000000) == 0) { |
| 4959 | // Value = 0xnn000000: Op=x, Cmode=011x. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4960 | OpCmode = 0x6; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4961 | Imm = SplatBits >> 24; |
| 4962 | break; |
| 4963 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4964 | |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4965 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 4966 | if (type == OtherModImm) return SDValue(); |
| 4967 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4968 | if ((SplatBits & ~0xffff) == 0 && |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4969 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 4970 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4971 | OpCmode = 0xc; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4972 | Imm = SplatBits >> 8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4973 | break; |
| 4974 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4975 | |
| 4976 | if ((SplatBits & ~0xffffff) == 0 && |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4977 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 4978 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 4979 | OpCmode = 0xd; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4980 | Imm = SplatBits >> 16; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4981 | break; |
| 4982 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4983 | |
| 4984 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 4985 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 4986 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 4987 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 4988 | // caller would also need to check and handle the change in size. |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4989 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4990 | |
| 4991 | case 64: { |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 4992 | if (type != VMOVModImm) |
| Bob Wilson | f3f7a77 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 4993 | return SDValue(); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 4994 | // 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] | 4995 | uint64_t BitMask = 0xff; |
| 4996 | uint64_t Val = 0; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 4997 | unsigned ImmMask = 1; |
| 4998 | Imm = 0; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4999 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5000 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5001 | Val |= BitMask; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5002 | Imm |= ImmMask; |
| 5003 | } else if ((SplatBits & BitMask) != 0) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5004 | return SDValue(); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5005 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5006 | BitMask <<= 8; |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5007 | ImmMask <<= 1; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5008 | } |
| Christian Pirker | 6f81e75 | 2014-06-23 18:05:53 +0000 | [diff] [blame] | 5009 | |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 5010 | if (DAG.getDataLayout().isBigEndian()) |
| Christian Pirker | 6f81e75 | 2014-06-23 18:05:53 +0000 | [diff] [blame] | 5011 | // swap higher and lower 32 bit word |
| 5012 | Imm = ((Imm & 0xf) << 4) | ((Imm & 0xf0) >> 4); |
| 5013 | |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5014 | // Op=1, Cmode=1110. |
| Bob Wilson | c1c6f47 | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 5015 | OpCmode = 0x1e; |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5016 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5017 | break; |
| 5018 | } |
| 5019 | |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5020 | default: |
| Bob Wilson | 0ae0893 | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 5021 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
| Bob Wilson | 6eae520 | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5024 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5025 | return DAG.getTargetConstant(EncodedVal, dl, MVT::i32); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5028 | SDValue ARMTargetLowering::LowerConstantFP(SDValue Op, SelectionDAG &DAG, |
| 5029 | const ARMSubtarget *ST) const { |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5030 | if (!ST->hasVFP3()) |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5031 | return SDValue(); |
| 5032 | |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5033 | bool IsDouble = Op.getValueType() == MVT::f64; |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5034 | ConstantFPSDNode *CFP = cast<ConstantFPSDNode>(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5035 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 5036 | // Use the default (constant pool) lowering for double constants when we have |
| 5037 | // an SP-only FPU |
| 5038 | if (IsDouble && Subtarget->isFPOnlySP()) |
| 5039 | return SDValue(); |
| 5040 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5041 | // Try splatting with a VMOV.f32... |
| 5042 | APFloat FPVal = CFP->getValueAPF(); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5043 | int ImmVal = IsDouble ? ARM_AM::getFP64Imm(FPVal) : ARM_AM::getFP32Imm(FPVal); |
| 5044 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5045 | if (ImmVal != -1) { |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5046 | if (IsDouble || !ST->useNEONForSinglePrecisionFP()) { |
| 5047 | // We have code in place to select a valid ConstantFP already, no need to |
| 5048 | // do any mangling. |
| 5049 | return Op; |
| 5050 | } |
| 5051 | |
| 5052 | // It's a float and we are trying to use NEON operations where |
| 5053 | // possible. Lower it to a splat followed by an extract. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5054 | SDLoc DL(Op); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5055 | SDValue NewVal = DAG.getTargetConstant(ImmVal, DL, MVT::i32); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5056 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVFPIMM, DL, MVT::v2f32, |
| 5057 | NewVal); |
| 5058 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5059 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5060 | } |
| 5061 | |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5062 | // The rest of our options are NEON only, make sure that's allowed before |
| 5063 | // proceeding.. |
| 5064 | if (!ST->hasNEON() || (!IsDouble && !ST->useNEONForSinglePrecisionFP())) |
| 5065 | return SDValue(); |
| 5066 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5067 | EVT VMovVT; |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5068 | uint64_t iVal = FPVal.bitcastToAPInt().getZExtValue(); |
| 5069 | |
| 5070 | // It wouldn't really be worth bothering for doubles except for one very |
| 5071 | // important value, which does happen to match: 0.0. So make sure we don't do |
| 5072 | // anything stupid. |
| 5073 | if (IsDouble && (iVal & 0xffffffff) != (iVal >> 32)) |
| 5074 | return SDValue(); |
| 5075 | |
| 5076 | // Try a VMOV.i32 (FIXME: i8, i16, or i64 could work too). |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5077 | SDValue NewVal = isNEONModifiedImm(iVal & 0xffffffffU, 0, 32, DAG, SDLoc(Op), |
| 5078 | VMovVT, false, VMOVModImm); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5079 | if (NewVal != SDValue()) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5080 | SDLoc DL(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5081 | SDValue VecConstant = DAG.getNode(ARMISD::VMOVIMM, DL, VMovVT, |
| 5082 | NewVal); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5083 | if (IsDouble) |
| 5084 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); |
| 5085 | |
| 5086 | // It's a float: cast and extract a vector element. |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5087 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 5088 | VecConstant); |
| 5089 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5090 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | // Finally, try a VMVN.i32 |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5094 | NewVal = isNEONModifiedImm(~iVal & 0xffffffffU, 0, 32, DAG, SDLoc(Op), VMovVT, |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5095 | false, VMVNModImm); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5096 | if (NewVal != SDValue()) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5097 | SDLoc DL(Op); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5098 | SDValue VecConstant = DAG.getNode(ARMISD::VMVNIMM, DL, VMovVT, NewVal); |
| Tim Northover | f79c3a5 | 2013-08-20 08:57:11 +0000 | [diff] [blame] | 5099 | |
| 5100 | if (IsDouble) |
| 5101 | return DAG.getNode(ISD::BITCAST, DL, MVT::f64, VecConstant); |
| 5102 | |
| 5103 | // It's a float: cast and extract a vector element. |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5104 | SDValue VecFConstant = DAG.getNode(ISD::BITCAST, DL, MVT::v2f32, |
| 5105 | VecConstant); |
| 5106 | return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, VecFConstant, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5107 | DAG.getConstant(0, DL, MVT::i32)); |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | return SDValue(); |
| 5111 | } |
| 5112 | |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 5113 | // check if an VEXT instruction can handle the shuffle mask when the |
| 5114 | // vector sources of the shuffle are the same. |
| 5115 | static bool isSingletonVEXTMask(ArrayRef<int> M, EVT VT, unsigned &Imm) { |
| 5116 | unsigned NumElts = VT.getVectorNumElements(); |
| 5117 | |
| 5118 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 5119 | if (M[0] < 0) |
| 5120 | return false; |
| 5121 | |
| 5122 | Imm = M[0]; |
| 5123 | |
| 5124 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 5125 | // element. The other shuffle indices must be the successive elements after |
| 5126 | // the first one. |
| 5127 | unsigned ExpectedElt = Imm; |
| 5128 | for (unsigned i = 1; i < NumElts; ++i) { |
| 5129 | // Increment the expected index. If it wraps around, just follow it |
| 5130 | // back to index zero and keep going. |
| 5131 | ++ExpectedElt; |
| 5132 | if (ExpectedElt == NumElts) |
| 5133 | ExpectedElt = 0; |
| 5134 | |
| 5135 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 5136 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| 5137 | return false; |
| 5138 | } |
| 5139 | |
| 5140 | return true; |
| 5141 | } |
| 5142 | |
| Lang Hames | 591cdaf | 2012-03-29 21:56:11 +0000 | [diff] [blame] | 5143 | |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5144 | static bool isVEXTMask(ArrayRef<int> M, EVT VT, |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5145 | bool &ReverseVEXT, unsigned &Imm) { |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5146 | unsigned NumElts = VT.getVectorNumElements(); |
| 5147 | ReverseVEXT = false; |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5148 | |
| 5149 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 5150 | if (M[0] < 0) |
| 5151 | return false; |
| 5152 | |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5153 | Imm = M[0]; |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5154 | |
| 5155 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 5156 | // element. The other shuffle indices must be the successive elements after |
| 5157 | // the first one. |
| 5158 | unsigned ExpectedElt = Imm; |
| 5159 | for (unsigned i = 1; i < NumElts; ++i) { |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5160 | // Increment the expected index. If it wraps around, it may still be |
| 5161 | // a VEXT but the source vectors must be swapped. |
| 5162 | ExpectedElt += 1; |
| 5163 | if (ExpectedElt == NumElts * 2) { |
| 5164 | ExpectedElt = 0; |
| 5165 | ReverseVEXT = true; |
| 5166 | } |
| 5167 | |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5168 | if (M[i] < 0) continue; // ignore UNDEF indices |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5169 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | |
| 5173 | // Adjust the index value if the source operands will be swapped. |
| 5174 | if (ReverseVEXT) |
| 5175 | Imm -= NumElts; |
| 5176 | |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 5177 | return true; |
| 5178 | } |
| 5179 | |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5180 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 5181 | /// instruction with the specified blocksize. (The order of the elements |
| 5182 | /// within each block of the vector is reversed.) |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5183 | static bool isVREVMask(ArrayRef<int> M, EVT VT, unsigned BlockSize) { |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5184 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 5185 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 5186 | |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5187 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5188 | if (EltSz == 64) |
| 5189 | return false; |
| 5190 | |
| 5191 | unsigned NumElts = VT.getVectorNumElements(); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5192 | unsigned BlockElts = M[0] + 1; |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5193 | // If the first shuffle index is UNDEF, be optimistic. |
| 5194 | if (M[0] < 0) |
| 5195 | BlockElts = BlockSize / EltSz; |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5196 | |
| 5197 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 5198 | return false; |
| 5199 | |
| 5200 | for (unsigned i = 0; i < NumElts; ++i) { |
| Bob Wilson | 411dfad | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 5201 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 5202 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
| Bob Wilson | 8a37bbe | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 5203 | return false; |
| 5204 | } |
| 5205 | |
| 5206 | return true; |
| 5207 | } |
| 5208 | |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5209 | static bool isVTBLMask(ArrayRef<int> M, EVT VT) { |
| Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 5210 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 5211 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 5212 | // of 8 elements can work here. |
| 5213 | return VT == MVT::v8i8 && M.size() == 8; |
| 5214 | } |
| 5215 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5216 | // Checks whether the shuffle mask represents a vector transpose (VTRN) by |
| 5217 | // checking that pairs of elements in the shuffle mask represent the same index |
| 5218 | // in each vector, incrementing the expected index by 2 at each step. |
| 5219 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 4, 2, 6] |
| 5220 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,e,c,g} |
| 5221 | // v2={e,f,g,h} |
| 5222 | // WhichResult gives the offset for each element in the mask based on which |
| 5223 | // of the two results it belongs to. |
| 5224 | // |
| 5225 | // The transpose can be represented either as: |
| 5226 | // result1 = shufflevector v1, v2, result1_shuffle_mask |
| 5227 | // result2 = shufflevector v1, v2, result2_shuffle_mask |
| 5228 | // where v1/v2 and the shuffle masks have the same number of elements |
| 5229 | // (here WhichResult (see below) indicates which result is being checked) |
| 5230 | // |
| 5231 | // or as: |
| 5232 | // results = shufflevector v1, v2, shuffle_mask |
| 5233 | // where both results are returned in one vector and the shuffle mask has twice |
| 5234 | // as many elements as v1/v2 (here WhichResult will always be 0 if true) here we |
| 5235 | // want to check the low half and high half of the shuffle mask as if it were |
| 5236 | // the other case |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5237 | static bool isVTRNMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5238 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5239 | if (EltSz == 64) |
| 5240 | return false; |
| 5241 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5242 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5243 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5244 | return false; |
| 5245 | |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5246 | // If the mask is twice as long as the input vector then we need to check the |
| 5247 | // upper and lower parts of the mask with a matching value for WhichResult |
| 5248 | // FIXME: A mask with only even values will be rejected in case the first |
| 5249 | // element is undefined, e.g. [-1, 4, 2, 6] will be rejected, because only |
| 5250 | // M[0] is used to determine WhichResult |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5251 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5252 | if (M.size() == NumElts * 2) |
| 5253 | WhichResult = i / NumElts; |
| 5254 | else |
| 5255 | WhichResult = M[i] == 0 ? 0 : 1; |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5256 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5257 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != j + WhichResult) || |
| 5258 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != j + NumElts + WhichResult)) |
| 5259 | return false; |
| 5260 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5261 | } |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5262 | |
| 5263 | if (M.size() == NumElts*2) |
| 5264 | WhichResult = 0; |
| 5265 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5266 | return true; |
| 5267 | } |
| 5268 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5269 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 5270 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5271 | /// 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] | 5272 | 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] | 5273 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5274 | if (EltSz == 64) |
| 5275 | return false; |
| 5276 | |
| 5277 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5278 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5279 | return false; |
| 5280 | |
| 5281 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| James Molloy | 8c995a9 | 2015-09-10 08:42:28 +0000 | [diff] [blame] | 5282 | if (M.size() == NumElts * 2) |
| 5283 | WhichResult = i / NumElts; |
| 5284 | else |
| 5285 | WhichResult = M[i] == 0 ? 0 : 1; |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5286 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5287 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != j + WhichResult) || |
| 5288 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != j + WhichResult)) |
| 5289 | return false; |
| 5290 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5291 | } |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5292 | |
| 5293 | if (M.size() == NumElts*2) |
| 5294 | WhichResult = 0; |
| 5295 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5296 | return true; |
| 5297 | } |
| 5298 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5299 | // Checks whether the shuffle mask represents a vector unzip (VUZP) by checking |
| 5300 | // that the mask elements are either all even and in steps of size 2 or all odd |
| 5301 | // and in steps of size 2. |
| 5302 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 2, 4, 6] |
| 5303 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,c,e,g} |
| 5304 | // v2={e,f,g,h} |
| 5305 | // Requires similar checks to that of isVTRNMask with |
| 5306 | // respect the how results are returned. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5307 | static bool isVUZPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5308 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5309 | if (EltSz == 64) |
| 5310 | return false; |
| 5311 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5312 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5313 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5314 | return false; |
| 5315 | |
| 5316 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5317 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5318 | for (unsigned j = 0; j < NumElts; ++j) { |
| 5319 | if (M[i+j] >= 0 && (unsigned) M[i+j] != 2 * j + WhichResult) |
| 5320 | return false; |
| 5321 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5324 | if (M.size() == NumElts*2) |
| 5325 | WhichResult = 0; |
| 5326 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5327 | // 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] | 5328 | if (VT.is64BitVector() && EltSz == 32) |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5329 | return false; |
| 5330 | |
| 5331 | return true; |
| 5332 | } |
| 5333 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5334 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 5335 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5336 | /// 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] | 5337 | 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] | 5338 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5339 | if (EltSz == 64) |
| 5340 | return false; |
| 5341 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5342 | unsigned NumElts = VT.getVectorNumElements(); |
| 5343 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5344 | return false; |
| 5345 | |
| 5346 | unsigned Half = NumElts / 2; |
| 5347 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5348 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5349 | for (unsigned j = 0; j < NumElts; j += Half) { |
| 5350 | unsigned Idx = WhichResult; |
| 5351 | for (unsigned k = 0; k < Half; ++k) { |
| 5352 | int MIdx = M[i + j + k]; |
| 5353 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
| 5354 | return false; |
| 5355 | Idx += 2; |
| 5356 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5357 | } |
| 5358 | } |
| 5359 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5360 | if (M.size() == NumElts*2) |
| 5361 | WhichResult = 0; |
| 5362 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5363 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 5364 | if (VT.is64BitVector() && EltSz == 32) |
| 5365 | return false; |
| 5366 | |
| 5367 | return true; |
| 5368 | } |
| 5369 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5370 | // Checks whether the shuffle mask represents a vector zip (VZIP) by checking |
| 5371 | // that pairs of elements of the shufflemask represent the same index in each |
| 5372 | // vector incrementing sequentially through the vectors. |
| 5373 | // e.g. For v1,v2 of type v4i32 a valid shuffle mask is: [0, 4, 1, 5] |
| 5374 | // v1={a,b,c,d} => x=shufflevector v1, v2 shufflemask => x={a,e,b,f} |
| 5375 | // v2={e,f,g,h} |
| 5376 | // Requires similar checks to that of isVTRNMask with respect the how results |
| 5377 | // are returned. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 5378 | static bool isVZIPMask(ArrayRef<int> M, EVT VT, unsigned &WhichResult) { |
| Bob Wilson | 854530a | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 5379 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5380 | if (EltSz == 64) |
| 5381 | return false; |
| 5382 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5383 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5384 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5385 | return false; |
| 5386 | |
| 5387 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5388 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5389 | unsigned Idx = WhichResult * NumElts / 2; |
| 5390 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5391 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != Idx) || |
| 5392 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != Idx + NumElts)) |
| 5393 | return false; |
| 5394 | Idx += 1; |
| 5395 | } |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5396 | } |
| 5397 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5398 | if (M.size() == NumElts*2) |
| 5399 | WhichResult = 0; |
| 5400 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5401 | // 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] | 5402 | if (VT.is64BitVector() && EltSz == 32) |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5403 | return false; |
| 5404 | |
| 5405 | return true; |
| 5406 | } |
| 5407 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5408 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 5409 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 5410 | /// 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] | 5411 | 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] | 5412 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 5413 | if (EltSz == 64) |
| 5414 | return false; |
| 5415 | |
| 5416 | unsigned NumElts = VT.getVectorNumElements(); |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5417 | if (M.size() != NumElts && M.size() != NumElts*2) |
| 5418 | return false; |
| 5419 | |
| 5420 | for (unsigned i = 0; i < M.size(); i += NumElts) { |
| 5421 | WhichResult = M[i] == 0 ? 0 : 1; |
| 5422 | unsigned Idx = WhichResult * NumElts / 2; |
| 5423 | for (unsigned j = 0; j < NumElts; j += 2) { |
| 5424 | if ((M[i+j] >= 0 && (unsigned) M[i+j] != Idx) || |
| 5425 | (M[i+j+1] >= 0 && (unsigned) M[i+j+1] != Idx)) |
| 5426 | return false; |
| 5427 | Idx += 1; |
| 5428 | } |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5429 | } |
| 5430 | |
| Luke Cheeseman | 4d45ff2 | 2015-07-24 09:57:05 +0000 | [diff] [blame] | 5431 | if (M.size() == NumElts*2) |
| 5432 | WhichResult = 0; |
| 5433 | |
| Bob Wilson | 0bbd307 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 5434 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 5435 | if (VT.is64BitVector() && EltSz == 32) |
| 5436 | return false; |
| 5437 | |
| 5438 | return true; |
| 5439 | } |
| 5440 | |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5441 | /// Check if \p ShuffleMask is a NEON two-result shuffle (VZIP, VUZP, VTRN), |
| 5442 | /// and return the corresponding ARMISD opcode if it is, or 0 if it isn't. |
| 5443 | static unsigned isNEONTwoResultShuffleMask(ArrayRef<int> ShuffleMask, EVT VT, |
| 5444 | unsigned &WhichResult, |
| 5445 | bool &isV_UNDEF) { |
| 5446 | isV_UNDEF = false; |
| 5447 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 5448 | return ARMISD::VTRN; |
| 5449 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 5450 | return ARMISD::VUZP; |
| 5451 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 5452 | return ARMISD::VZIP; |
| 5453 | |
| 5454 | isV_UNDEF = true; |
| 5455 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5456 | return ARMISD::VTRN; |
| 5457 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5458 | return ARMISD::VUZP; |
| 5459 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 5460 | return ARMISD::VZIP; |
| 5461 | |
| 5462 | return 0; |
| 5463 | } |
| 5464 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5465 | /// \return true if this is a reverse operation on an vector. |
| 5466 | static bool isReverseMask(ArrayRef<int> M, EVT VT) { |
| 5467 | unsigned NumElts = VT.getVectorNumElements(); |
| 5468 | // Make sure the mask has the right size. |
| 5469 | if (NumElts != M.size()) |
| 5470 | return false; |
| 5471 | |
| 5472 | // Look for <15, ..., 3, -1, 1, 0>. |
| 5473 | for (unsigned i = 0; i != NumElts; ++i) |
| 5474 | if (M[i] >= 0 && M[i] != (int) (NumElts - 1 - i)) |
| 5475 | return false; |
| 5476 | |
| 5477 | return true; |
| 5478 | } |
| 5479 | |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5480 | // If N is an integer constant that can be moved into a register in one |
| 5481 | // instruction, return an SDValue of such a constant (will become a MOV |
| 5482 | // instruction). Otherwise return null. |
| 5483 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5484 | const ARMSubtarget *ST, SDLoc dl) { |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5485 | uint64_t Val; |
| 5486 | if (!isa<ConstantSDNode>(N)) |
| 5487 | return SDValue(); |
| 5488 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 5489 | |
| 5490 | if (ST->isThumb1Only()) { |
| 5491 | if (Val <= 255 || ~Val <= 255) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5492 | return DAG.getConstant(Val, dl, MVT::i32); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5493 | } else { |
| 5494 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5495 | return DAG.getConstant(Val, dl, MVT::i32); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5496 | } |
| 5497 | return SDValue(); |
| 5498 | } |
| 5499 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5500 | // If this is a case we can't handle, return null and let the default |
| 5501 | // expansion code take care of it. |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5502 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 5503 | const ARMSubtarget *ST) const { |
| Bob Wilson | fcd6361 | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 5504 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5505 | SDLoc dl(Op); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5506 | EVT VT = Op.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5507 | |
| 5508 | APInt SplatBits, SplatUndef; |
| 5509 | unsigned SplatBitSize; |
| 5510 | bool HasAnyUndefs; |
| 5511 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 5512 | if (SplatBitSize <= 64) { |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 5513 | // Check if an immediate VMOV works. |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5514 | EVT VmovVT; |
| Bob Wilson | 5b2b504 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 5515 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5516 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5517 | DAG, dl, VmovVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5518 | VMOVModImm); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5519 | if (Val.getNode()) { |
| 5520 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5521 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | a3f1901 | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 5522 | } |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5523 | |
| 5524 | // Try an immediate VMVN. |
| Eli Friedman | aa6ec39 | 2011-10-13 22:40:23 +0000 | [diff] [blame] | 5525 | uint64_t NegatedImm = (~SplatBits).getZExtValue(); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5526 | Val = isNEONModifiedImm(NegatedImm, |
| 5527 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5528 | DAG, dl, VmovVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5529 | VMVNModImm); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5530 | if (Val.getNode()) { |
| 5531 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5532 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 5533 | } |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5534 | |
| 5535 | // Use vmov.f32 to materialize other v2f32 and v4f32 splats. |
| Eli Friedman | c9bf1b1 | 2011-12-15 22:56:53 +0000 | [diff] [blame] | 5536 | if ((VT == MVT::v2f32 || VT == MVT::v4f32) && SplatBitSize == 32) { |
| Eli Friedman | 4e36a93 | 2011-12-09 23:54:42 +0000 | [diff] [blame] | 5537 | int ImmVal = ARM_AM::getFP32Imm(SplatBits); |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5538 | if (ImmVal != -1) { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5539 | SDValue Val = DAG.getTargetConstant(ImmVal, dl, MVT::i32); |
| Evan Cheng | 7ca4b6e | 2011-11-15 02:12:34 +0000 | [diff] [blame] | 5540 | return DAG.getNode(ARMISD::VMOVFPIMM, dl, VT, Val); |
| 5541 | } |
| 5542 | } |
| Anton Korobeynikov | ece642a | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 5543 | } |
| Bob Wilson | 0dbdec8 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 5544 | } |
| 5545 | |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5546 | // Scan through the operands to see if only one value is used. |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5547 | // |
| 5548 | // As an optimisation, even if more than one value is used it may be more |
| 5549 | // profitable to splat with one value then change some lanes. |
| 5550 | // |
| 5551 | // Heuristically we decide to do this if the vector has a "dominant" value, |
| 5552 | // defined as splatted to more than half of the lanes. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5553 | unsigned NumElts = VT.getVectorNumElements(); |
| 5554 | bool isOnlyLowElement = true; |
| 5555 | bool usesOnlyOneValue = true; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5556 | bool hasDominantValue = false; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5557 | bool isConstant = true; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5558 | |
| 5559 | // Map of the number of times a particular SDValue appears in the |
| 5560 | // element list. |
| James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 5561 | DenseMap<SDValue, unsigned> ValueCounts; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5562 | SDValue Value; |
| 5563 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5564 | SDValue V = Op.getOperand(i); |
| 5565 | if (V.getOpcode() == ISD::UNDEF) |
| 5566 | continue; |
| 5567 | if (i > 0) |
| 5568 | isOnlyLowElement = false; |
| 5569 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 5570 | isConstant = false; |
| 5571 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5572 | ValueCounts.insert(std::make_pair(V, 0)); |
| James Molloy | 9d30dc2 | 2012-09-06 10:32:08 +0000 | [diff] [blame] | 5573 | unsigned &Count = ValueCounts[V]; |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 5574 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5575 | // Is this value dominant? (takes up more than half of the lanes) |
| 5576 | if (++Count > (NumElts / 2)) { |
| 5577 | hasDominantValue = true; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5578 | Value = V; |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5579 | } |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5580 | } |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5581 | if (ValueCounts.size() != 1) |
| 5582 | usesOnlyOneValue = false; |
| 5583 | if (!Value.getNode() && ValueCounts.size() > 0) |
| 5584 | Value = ValueCounts.begin()->first; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5585 | |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5586 | if (ValueCounts.size() == 0) |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5587 | return DAG.getUNDEF(VT); |
| 5588 | |
| Quentin Colombet | 0f2fe74 | 2013-07-23 22:34:47 +0000 | [diff] [blame] | 5589 | // Loads are better lowered with insert_vector_elt/ARMISD::BUILD_VECTOR. |
| 5590 | // Keep going if we are hitting this case. |
| 5591 | if (isOnlyLowElement && !ISD::isNormalLoad(Value.getNode())) |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5592 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 5593 | |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5594 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5595 | |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5596 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 5597 | // i32 and try again. |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5598 | if (hasDominantValue && EltSize <= 32) { |
| 5599 | if (!isConstant) { |
| 5600 | SDValue N; |
| 5601 | |
| 5602 | // If we are VDUPing a value that comes directly from a vector, that will |
| 5603 | // 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] | 5604 | // just use VDUPLANE. We can only do this if the lane being extracted |
| 5605 | // is at a constant index, as the VDUP from lane instructions only have |
| 5606 | // constant-index forms. |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 5607 | ConstantSDNode *constIndex; |
| Jim Grosbach | a3c5c76 | 2013-03-02 20:16:24 +0000 | [diff] [blame] | 5608 | if (Value->getOpcode() == ISD::EXTRACT_VECTOR_ELT && |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 5609 | (constIndex = dyn_cast<ConstantSDNode>(Value->getOperand(1)))) { |
| Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5610 | // We need to create a new undef vector to use for the VDUPLANE if the |
| 5611 | // size of the vector from which we get the value is different than the |
| 5612 | // size of the vector that we need to create. We will insert the element |
| 5613 | // such that the register coalescer will remove unnecessary copies. |
| 5614 | if (VT != Value->getOperand(0).getValueType()) { |
| Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5615 | unsigned index = constIndex->getAPIntValue().getLimitedValue() % |
| 5616 | VT.getVectorNumElements(); |
| 5617 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| 5618 | DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, DAG.getUNDEF(VT), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5619 | Value, DAG.getConstant(index, dl, MVT::i32)), |
| 5620 | DAG.getConstant(index, dl, MVT::i32)); |
| Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5621 | } else |
| Silviu Baranga | b140970 | 2012-10-15 09:41:32 +0000 | [diff] [blame] | 5622 | N = DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5623 | Value->getOperand(0), Value->getOperand(1)); |
| Jim Grosbach | c6f1914 | 2013-03-02 20:16:19 +0000 | [diff] [blame] | 5624 | } else |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5625 | N = DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 5626 | |
| 5627 | if (!usesOnlyOneValue) { |
| 5628 | // The dominant value was splatted as 'N', but we now have to insert |
| 5629 | // all differing elements. |
| 5630 | for (unsigned I = 0; I < NumElts; ++I) { |
| 5631 | if (Op.getOperand(I) == Value) |
| 5632 | continue; |
| 5633 | SmallVector<SDValue, 3> Ops; |
| 5634 | Ops.push_back(N); |
| 5635 | Ops.push_back(Op.getOperand(I)); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5636 | Ops.push_back(DAG.getConstant(I, dl, MVT::i32)); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5637 | N = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Ops); |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5638 | } |
| 5639 | } |
| 5640 | return N; |
| 5641 | } |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5642 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 5643 | SmallVector<SDValue, 8> Ops; |
| 5644 | for (unsigned i = 0; i < NumElts; ++i) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5645 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
| Dale Johannesen | 710a2d9 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 5646 | Op.getOperand(i))); |
| Nate Begeman | ca52411 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 5647 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5648 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Dale Johannesen | ff37675 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 5649 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 5650 | if (Val.getNode()) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5651 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5652 | } |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5653 | if (usesOnlyOneValue) { |
| 5654 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 5655 | if (isConstant && Val.getNode()) |
| Jim Grosbach | 54efea0 | 2013-03-02 20:16:15 +0000 | [diff] [blame] | 5656 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
| James Molloy | 49bdbce | 2012-09-06 09:55:02 +0000 | [diff] [blame] | 5657 | } |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 5658 | } |
| 5659 | |
| 5660 | // If all elements are constants and the case above didn't get hit, fall back |
| 5661 | // to the default expansion, which will generate a load from the constant |
| 5662 | // pool. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5663 | if (isConstant) |
| 5664 | return SDValue(); |
| 5665 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5666 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 5667 | if (NumElts >= 4) { |
| 5668 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 5669 | if (shuffle != SDValue()) |
| 5670 | return shuffle; |
| 5671 | } |
| 5672 | |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5673 | // 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] | 5674 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 5675 | // will be legalized. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 5676 | if (EltSize >= 32) { |
| 5677 | // Do the expansion with floating-point types, since that is what the VFP |
| 5678 | // registers are defined to use, and since i64 is not legal. |
| 5679 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 5680 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 5681 | SmallVector<SDValue, 8> Ops; |
| 5682 | for (unsigned i = 0; i < NumElts; ++i) |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5683 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 5684 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5685 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
| Jim Grosbach | 24e102a | 2013-07-08 18:18:52 +0000 | [diff] [blame] | 5688 | // If all else fails, just use a sequence of INSERT_VECTOR_ELT when we |
| 5689 | // know the default expansion would otherwise fall back on something even |
| 5690 | // worse. For a vector with one or two non-undef values, that's |
| 5691 | // scalar_to_vector for the elements followed by a shuffle (provided the |
| 5692 | // shuffle is valid for the target) and materialization element by element |
| 5693 | // on the stack followed by a load for everything else. |
| 5694 | if (!isConstant && !usesOnlyOneValue) { |
| 5695 | SDValue Vec = DAG.getUNDEF(VT); |
| 5696 | for (unsigned i = 0 ; i < NumElts; ++i) { |
| 5697 | SDValue V = Op.getOperand(i); |
| 5698 | if (V.getOpcode() == ISD::UNDEF) |
| 5699 | continue; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 5700 | SDValue LaneIdx = DAG.getConstant(i, dl, MVT::i32); |
| Jim Grosbach | 24e102a | 2013-07-08 18:18:52 +0000 | [diff] [blame] | 5701 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VT, Vec, V, LaneIdx); |
| 5702 | } |
| 5703 | return Vec; |
| 5704 | } |
| 5705 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 5706 | return SDValue(); |
| 5707 | } |
| 5708 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5709 | // Gather data to see if the operation can be modelled as a |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5710 | // shuffle in combination with VEXTs. |
| Eric Christopher | 2af9551 | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 5711 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 5712 | SelectionDAG &DAG) const { |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5713 | assert(Op.getOpcode() == ISD::BUILD_VECTOR && "Unknown opcode!"); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5714 | SDLoc dl(Op); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5715 | EVT VT = Op.getValueType(); |
| 5716 | unsigned NumElts = VT.getVectorNumElements(); |
| 5717 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5718 | struct ShuffleSourceInfo { |
| 5719 | SDValue Vec; |
| 5720 | unsigned MinElt; |
| 5721 | unsigned MaxElt; |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5722 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5723 | // We may insert some combination of BITCASTs and VEXT nodes to force Vec to |
| 5724 | // be compatible with the shuffle we intend to construct. As a result |
| 5725 | // ShuffleVec will be some sliding window into the original Vec. |
| 5726 | SDValue ShuffleVec; |
| 5727 | |
| 5728 | // Code should guarantee that element i in Vec starts at element "WindowBase |
| 5729 | // + i * WindowScale in ShuffleVec". |
| 5730 | int WindowBase; |
| 5731 | int WindowScale; |
| 5732 | |
| 5733 | bool operator ==(SDValue OtherVec) { return Vec == OtherVec; } |
| 5734 | ShuffleSourceInfo(SDValue Vec) |
| 5735 | : Vec(Vec), MinElt(UINT_MAX), MaxElt(0), ShuffleVec(Vec), WindowBase(0), |
| 5736 | WindowScale(1) {} |
| 5737 | }; |
| 5738 | |
| 5739 | // First gather all vectors used as an immediate source for this BUILD_VECTOR |
| 5740 | // node. |
| 5741 | SmallVector<ShuffleSourceInfo, 2> Sources; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5742 | for (unsigned i = 0; i < NumElts; ++i) { |
| 5743 | SDValue V = Op.getOperand(i); |
| 5744 | if (V.getOpcode() == ISD::UNDEF) |
| 5745 | continue; |
| 5746 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 5747 | // A shuffle can only come from building a vector from various |
| 5748 | // elements of other vectors. |
| 5749 | return SDValue(); |
| Ahmed Bougacha | 699a9dd | 2015-09-01 21:56:00 +0000 | [diff] [blame] | 5750 | } else if (!isa<ConstantSDNode>(V.getOperand(1))) { |
| 5751 | // Furthermore, shuffles require a constant mask, whereas extractelts |
| 5752 | // accept variable indices. |
| 5753 | return SDValue(); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5754 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5755 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5756 | // 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] | 5757 | SDValue SourceVec = V.getOperand(0); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5758 | auto Source = std::find(Sources.begin(), Sources.end(), SourceVec); |
| 5759 | if (Source == Sources.end()) |
| 5760 | Source = Sources.insert(Sources.end(), ShuffleSourceInfo(SourceVec)); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5761 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5762 | // Update the minimum and maximum lane number seen. |
| 5763 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 5764 | Source->MinElt = std::min(Source->MinElt, EltNo); |
| 5765 | Source->MaxElt = std::max(Source->MaxElt, EltNo); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5766 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5767 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5768 | // Currently only do something sane when at most two source vectors |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5769 | // are involved. |
| 5770 | if (Sources.size() > 2) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5771 | return SDValue(); |
| 5772 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5773 | // Find out the smallest element size among result and two sources, and use |
| 5774 | // it as element size to build the shuffle_vector. |
| 5775 | EVT SmallestEltTy = VT.getVectorElementType(); |
| 5776 | for (auto &Source : Sources) { |
| 5777 | EVT SrcEltTy = Source.Vec.getValueType().getVectorElementType(); |
| 5778 | if (SrcEltTy.bitsLT(SmallestEltTy)) |
| 5779 | SmallestEltTy = SrcEltTy; |
| 5780 | } |
| 5781 | unsigned ResMultiplier = |
| 5782 | VT.getVectorElementType().getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5783 | NumElts = VT.getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5784 | EVT ShuffleVT = EVT::getVectorVT(*DAG.getContext(), SmallestEltTy, NumElts); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5785 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5786 | // If the source vector is too wide or too narrow, we may nevertheless be able |
| 5787 | // to construct a compatible shuffle either by concatenating it with UNDEF or |
| 5788 | // extracting a suitable range of elements. |
| 5789 | for (auto &Src : Sources) { |
| 5790 | EVT SrcVT = Src.ShuffleVec.getValueType(); |
| 5791 | |
| 5792 | if (SrcVT.getSizeInBits() == VT.getSizeInBits()) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5793 | continue; |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5794 | |
| 5795 | // This stage of the search produces a source with the same element type as |
| 5796 | // the original, but with a total width matching the BUILD_VECTOR output. |
| 5797 | EVT EltVT = SrcVT.getVectorElementType(); |
| 5798 | unsigned NumSrcElts = VT.getSizeInBits() / EltVT.getSizeInBits(); |
| 5799 | EVT DestVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumSrcElts); |
| 5800 | |
| 5801 | if (SrcVT.getSizeInBits() < VT.getSizeInBits()) { |
| 5802 | if (2 * SrcVT.getSizeInBits() != VT.getSizeInBits()) |
| 5803 | return SDValue(); |
| 5804 | // We can pad out the smaller vector for free, so if it's part of a |
| 5805 | // shuffle... |
| 5806 | Src.ShuffleVec = |
| 5807 | DAG.getNode(ISD::CONCAT_VECTORS, dl, DestVT, Src.ShuffleVec, |
| 5808 | DAG.getUNDEF(Src.ShuffleVec.getValueType())); |
| 5809 | continue; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5810 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5811 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5812 | if (SrcVT.getSizeInBits() != 2 * VT.getSizeInBits()) |
| 5813 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5814 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5815 | if (Src.MaxElt - Src.MinElt >= NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5816 | // Span too large for a VEXT to cope |
| 5817 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5818 | } |
| 5819 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5820 | if (Src.MinElt >= NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5821 | // The extraction can just take the second half |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5822 | Src.ShuffleVec = |
| 5823 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5824 | DAG.getConstant(NumSrcElts, dl, MVT::i32)); |
| 5825 | Src.WindowBase = -NumSrcElts; |
| 5826 | } else if (Src.MaxElt < NumSrcElts) { |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5827 | // The extraction can just take the first half |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5828 | Src.ShuffleVec = |
| 5829 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5830 | DAG.getConstant(0, dl, MVT::i32)); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5831 | } else { |
| 5832 | // An actual VEXT is needed |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5833 | SDValue VEXTSrc1 = |
| 5834 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5835 | DAG.getConstant(0, dl, MVT::i32)); |
| 5836 | SDValue VEXTSrc2 = |
| 5837 | DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, DestVT, Src.ShuffleVec, |
| 5838 | DAG.getConstant(NumSrcElts, dl, MVT::i32)); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5839 | |
| 5840 | Src.ShuffleVec = DAG.getNode(ARMISD::VEXT, dl, DestVT, VEXTSrc1, |
| 5841 | VEXTSrc2, |
| Jeroen Ketema | 41681a5 | 2015-09-21 20:28:04 +0000 | [diff] [blame] | 5842 | DAG.getConstant(Src.MinElt, dl, MVT::i32)); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5843 | Src.WindowBase = -Src.MinElt; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5844 | } |
| 5845 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5846 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5847 | // Another possible incompatibility occurs from the vector element types. We |
| 5848 | // can fix this by bitcasting the source vectors to the same type we intend |
| 5849 | // for the shuffle. |
| 5850 | for (auto &Src : Sources) { |
| 5851 | EVT SrcEltTy = Src.ShuffleVec.getValueType().getVectorElementType(); |
| 5852 | if (SrcEltTy == SmallestEltTy) |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5853 | continue; |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5854 | assert(ShuffleVT.getVectorElementType() == SmallestEltTy); |
| 5855 | Src.ShuffleVec = DAG.getNode(ISD::BITCAST, dl, ShuffleVT, Src.ShuffleVec); |
| 5856 | Src.WindowScale = SrcEltTy.getSizeInBits() / SmallestEltTy.getSizeInBits(); |
| 5857 | Src.WindowBase *= Src.WindowScale; |
| 5858 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5859 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5860 | // Final sanity check before we try to actually produce a shuffle. |
| Silviu Baranga | a07090f | 2015-08-07 12:05:46 +0000 | [diff] [blame] | 5861 | DEBUG( |
| 5862 | for (auto Src : Sources) |
| 5863 | assert(Src.ShuffleVec.getValueType() == ShuffleVT); |
| 5864 | ); |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5865 | |
| 5866 | // The stars all align, our next step is to produce the mask for the shuffle. |
| 5867 | SmallVector<int, 8> Mask(ShuffleVT.getVectorNumElements(), -1); |
| 5868 | int BitsPerShuffleLane = ShuffleVT.getVectorElementType().getSizeInBits(); |
| 5869 | for (unsigned i = 0; i < VT.getVectorNumElements(); ++i) { |
| 5870 | SDValue Entry = Op.getOperand(i); |
| 5871 | if (Entry.getOpcode() == ISD::UNDEF) |
| 5872 | continue; |
| 5873 | |
| 5874 | auto Src = std::find(Sources.begin(), Sources.end(), Entry.getOperand(0)); |
| 5875 | int EltNo = cast<ConstantSDNode>(Entry.getOperand(1))->getSExtValue(); |
| 5876 | |
| 5877 | // EXTRACT_VECTOR_ELT performs an implicit any_ext; BUILD_VECTOR an implicit |
| 5878 | // trunc. So only std::min(SrcBits, DestBits) actually get defined in this |
| 5879 | // segment. |
| 5880 | EVT OrigEltTy = Entry.getOperand(0).getValueType().getVectorElementType(); |
| 5881 | int BitsDefined = std::min(OrigEltTy.getSizeInBits(), |
| 5882 | VT.getVectorElementType().getSizeInBits()); |
| 5883 | int LanesDefined = BitsDefined / BitsPerShuffleLane; |
| 5884 | |
| 5885 | // This source is expected to fill ResMultiplier lanes of the final shuffle, |
| 5886 | // starting at the appropriate offset. |
| 5887 | int *LaneMask = &Mask[i * ResMultiplier]; |
| 5888 | |
| 5889 | int ExtractBase = EltNo * Src->WindowScale + Src->WindowBase; |
| 5890 | ExtractBase += NumElts * (Src - Sources.begin()); |
| 5891 | for (int j = 0; j < LanesDefined; ++j) |
| 5892 | LaneMask[j] = ExtractBase + j; |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5893 | } |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5894 | |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5895 | // Final check before we try to produce nonsense... |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5896 | if (!isShuffleMaskLegal(Mask, ShuffleVT)) |
| 5897 | return SDValue(); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5898 | |
| Silviu Baranga | 3e8e51c | 2015-08-07 11:40:46 +0000 | [diff] [blame] | 5899 | // We can't handle more than two sources. This should have already |
| 5900 | // been checked before this point. |
| 5901 | assert(Sources.size() <= 2 && "Too many sources!"); |
| 5902 | |
| 5903 | SDValue ShuffleOps[] = { DAG.getUNDEF(ShuffleVT), DAG.getUNDEF(ShuffleVT) }; |
| 5904 | for (unsigned i = 0; i < Sources.size(); ++i) |
| 5905 | ShuffleOps[i] = Sources[i].ShuffleVec; |
| 5906 | |
| 5907 | SDValue Shuffle = DAG.getVectorShuffle(ShuffleVT, dl, ShuffleOps[0], |
| 5908 | ShuffleOps[1], &Mask[0]); |
| 5909 | return DAG.getNode(ISD::BITCAST, dl, VT, Shuffle); |
| Bob Wilson | 6f2b896 | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 5910 | } |
| 5911 | |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5912 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 5913 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 5914 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 5915 | /// are assumed to be legal. |
| 5916 | bool |
| 5917 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 5918 | EVT VT) const { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5919 | if (VT.getVectorNumElements() == 4 && |
| 5920 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 5921 | unsigned PFIndexes[4]; |
| 5922 | for (unsigned i = 0; i != 4; ++i) { |
| 5923 | if (M[i] < 0) |
| 5924 | PFIndexes[i] = 8; |
| 5925 | else |
| 5926 | PFIndexes[i] = M[i]; |
| 5927 | } |
| 5928 | |
| 5929 | // Compute the index in the perfect shuffle table. |
| 5930 | unsigned PFTableIndex = |
| 5931 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 5932 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 5933 | unsigned Cost = (PFEntry >> 30); |
| 5934 | |
| 5935 | if (Cost <= 4) |
| 5936 | return true; |
| 5937 | } |
| 5938 | |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5939 | bool ReverseVEXT, isV_UNDEF; |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5940 | unsigned Imm, WhichResult; |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5941 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 5942 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 5943 | return (EltSize >= 32 || |
| 5944 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5945 | isVREVMask(M, VT, 64) || |
| 5946 | isVREVMask(M, VT, 32) || |
| 5947 | isVREVMask(M, VT, 16) || |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 5948 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
| Bill Wendling | 865f8b5 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 5949 | isVTBLMask(M, VT) || |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 5950 | isNEONTwoResultShuffleMask(M, VT, WhichResult, isV_UNDEF) || |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 5951 | ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(M, VT))); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 5952 | } |
| 5953 | |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5954 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 5955 | /// the specified operations to build the shuffle. |
| 5956 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 5957 | SDValue RHS, SelectionDAG &DAG, |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 5958 | SDLoc dl) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 5959 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 5960 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 5961 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 5962 | |
| 5963 | enum { |
| 5964 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 5965 | OP_VREV, |
| 5966 | OP_VDUP0, |
| 5967 | OP_VDUP1, |
| 5968 | OP_VDUP2, |
| 5969 | OP_VDUP3, |
| 5970 | OP_VEXT1, |
| 5971 | OP_VEXT2, |
| 5972 | OP_VEXT3, |
| 5973 | OP_VUZPL, // VUZP, left result |
| 5974 | OP_VUZPR, // VUZP, right result |
| 5975 | OP_VZIPL, // VZIP, left result |
| 5976 | OP_VZIPR, // VZIP, right result |
| 5977 | OP_VTRNL, // VTRN, left result |
| 5978 | OP_VTRNR // VTRN, right result |
| 5979 | }; |
| 5980 | |
| 5981 | if (OpNum == OP_COPY) { |
| 5982 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 5983 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 5984 | return RHS; |
| 5985 | } |
| 5986 | |
| 5987 | SDValue OpLHS, OpRHS; |
| 5988 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 5989 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 5990 | EVT VT = OpLHS.getValueType(); |
| 5991 | |
| 5992 | switch (OpNum) { |
| 5993 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 5994 | case OP_VREV: |
| Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5995 | // VREV divides the vector in half and swaps within the half. |
| Tanya Lattner | 1d11720 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 5996 | if (VT.getVectorElementType() == MVT::i32 || |
| 5997 | VT.getVectorElementType() == MVT::f32) |
| Tanya Lattner | 48b182c | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 5998 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 5999 | // vrev <4 x i16> -> VREV32 |
| 6000 | if (VT.getVectorElementType() == MVT::i16) |
| 6001 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 6002 | // vrev <4 x i8> -> VREV16 |
| 6003 | assert(VT.getVectorElementType() == MVT::i8); |
| 6004 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6005 | case OP_VDUP0: |
| 6006 | case OP_VDUP1: |
| 6007 | case OP_VDUP2: |
| 6008 | case OP_VDUP3: |
| 6009 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6010 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, dl, MVT::i32)); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6011 | case OP_VEXT1: |
| 6012 | case OP_VEXT2: |
| 6013 | case OP_VEXT3: |
| 6014 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 6015 | OpLHS, OpRHS, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6016 | DAG.getConstant(OpNum - OP_VEXT1 + 1, dl, MVT::i32)); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6017 | case OP_VUZPL: |
| 6018 | case OP_VUZPR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 6019 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6020 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 6021 | case OP_VZIPL: |
| 6022 | case OP_VZIPR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 6023 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6024 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 6025 | case OP_VTRNL: |
| 6026 | case OP_VTRNR: |
| Anton Korobeynikov | 232b19c | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 6027 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 6028 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6029 | } |
| 6030 | } |
| 6031 | |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6032 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 6033 | ArrayRef<int> ShuffleMask, |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6034 | SelectionDAG &DAG) { |
| 6035 | // Check to see if we can use the VTBL instruction. |
| 6036 | SDValue V1 = Op.getOperand(0); |
| 6037 | SDValue V2 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6038 | SDLoc DL(Op); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6039 | |
| 6040 | SmallVector<SDValue, 8> VTBLMask; |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 6041 | for (ArrayRef<int>::iterator |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6042 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6043 | VTBLMask.push_back(DAG.getConstant(*I, DL, MVT::i32)); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6044 | |
| 6045 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 6046 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6047 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
| Bill Wendling | ebecb33 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 6048 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6049 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6050 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, VTBLMask)); |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6051 | } |
| 6052 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 6053 | static SDValue LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(SDValue Op, |
| 6054 | SelectionDAG &DAG) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6055 | SDLoc DL(Op); |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 6056 | SDValue OpLHS = Op.getOperand(0); |
| 6057 | EVT VT = OpLHS.getValueType(); |
| 6058 | |
| 6059 | assert((VT == MVT::v8i16 || VT == MVT::v16i8) && |
| 6060 | "Expect an v8i16/v16i8 type"); |
| 6061 | OpLHS = DAG.getNode(ARMISD::VREV64, DL, VT, OpLHS); |
| 6062 | // For a v16i8 type: After the VREV, we have got <8, ...15, 8, ..., 0>. Now, |
| 6063 | // extract the first 8 bytes into the top double word and the last 8 bytes |
| 6064 | // into the bottom double word. The v8i16 case is similar. |
| 6065 | unsigned ExtractNum = (VT == MVT::v16i8) ? 8 : 4; |
| 6066 | return DAG.getNode(ARMISD::VEXT, DL, VT, OpLHS, OpLHS, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6067 | DAG.getConstant(ExtractNum, DL, MVT::i32)); |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 6068 | } |
| 6069 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6070 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6071 | SDValue V1 = Op.getOperand(0); |
| 6072 | SDValue V2 = Op.getOperand(1); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6073 | SDLoc dl(Op); |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 6074 | EVT VT = Op.getValueType(); |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6075 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 6076 | |
| Bob Wilson | c6800b5 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 6077 | // Convert shuffles that are directly supported on NEON to target-specific |
| 6078 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 6079 | // during code selection. This is more efficient and avoids the possibility |
| 6080 | // of inconsistencies between legalization and selection. |
| Bob Wilson | 3e4c012 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 6081 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 6082 | // of the same time so that they get CSEd properly. |
| Benjamin Kramer | 339ced4 | 2012-01-15 13:16:05 +0000 | [diff] [blame] | 6083 | ArrayRef<int> ShuffleMask = SVN->getMask(); |
| Anton Korobeynikov | c32e99e | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 6084 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6085 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 6086 | if (EltSize <= 32) { |
| 6087 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 6088 | int Lane = SVN->getSplatIndex(); |
| 6089 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 6090 | if (Lane == -1) Lane = 0; |
| Anton Korobeynikov | 4d23754 | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 6091 | |
| Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 6092 | // Test if V1 is a SCALAR_TO_VECTOR. |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6093 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 6094 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 6095 | } |
| Dan Gohman | 198b7ff | 2011-11-03 21:49:52 +0000 | [diff] [blame] | 6096 | // Test if V1 is a BUILD_VECTOR which is equivalent to a SCALAR_TO_VECTOR |
| 6097 | // (and probably will turn into a SCALAR_TO_VECTOR once legalization |
| 6098 | // reaches it). |
| 6099 | if (Lane == 0 && V1.getOpcode() == ISD::BUILD_VECTOR && |
| 6100 | !isa<ConstantSDNode>(V1.getOperand(0))) { |
| 6101 | bool IsScalarToVector = true; |
| 6102 | for (unsigned i = 1, e = V1.getNumOperands(); i != e; ++i) |
| 6103 | if (V1.getOperand(i).getOpcode() != ISD::UNDEF) { |
| 6104 | IsScalarToVector = false; |
| 6105 | break; |
| 6106 | } |
| 6107 | if (IsScalarToVector) |
| 6108 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 6109 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6110 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6111 | DAG.getConstant(Lane, dl, MVT::i32)); |
| Bob Wilson | eb54d51 | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 6112 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6113 | |
| 6114 | bool ReverseVEXT; |
| 6115 | unsigned Imm; |
| 6116 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 6117 | if (ReverseVEXT) |
| 6118 | std::swap(V1, V2); |
| 6119 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6120 | DAG.getConstant(Imm, dl, MVT::i32)); |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 6124 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 6125 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 6126 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 6127 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 6128 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 6129 | |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 6130 | if (V2->getOpcode() == ISD::UNDEF && |
| 6131 | isSingletonVEXTMask(ShuffleMask, VT, Imm)) { |
| 6132 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6133 | DAG.getConstant(Imm, dl, MVT::i32)); |
| Quentin Colombet | 8e1fe84 | 2012-11-02 21:32:17 +0000 | [diff] [blame] | 6134 | } |
| 6135 | |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6136 | // Check for Neon shuffles that modify both input vectors in place. |
| 6137 | // If both results are used, i.e., if there are two shuffles with the same |
| 6138 | // source operands and with masks corresponding to both results of one of |
| 6139 | // these operations, DAG memoization will ensure that a single node is |
| 6140 | // used for both shuffles. |
| 6141 | unsigned WhichResult; |
| Ahmed Bougacha | 2ffa91f | 2015-06-19 02:25:01 +0000 | [diff] [blame] | 6142 | bool isV_UNDEF; |
| 6143 | if (unsigned ShuffleOpc = isNEONTwoResultShuffleMask( |
| 6144 | ShuffleMask, VT, WhichResult, isV_UNDEF)) { |
| 6145 | if (isV_UNDEF) |
| 6146 | V2 = V1; |
| 6147 | return DAG.getNode(ShuffleOpc, dl, DAG.getVTList(VT, VT), V1, V2) |
| 6148 | .getValue(WhichResult); |
| 6149 | } |
| Bob Wilson | 846bd79 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 6150 | |
| Ahmed Bougacha | 9a90942 | 2015-06-19 02:32:35 +0000 | [diff] [blame] | 6151 | // Also check for these shuffles through CONCAT_VECTORS: we canonicalize |
| 6152 | // shuffles that produce a result larger than their operands with: |
| 6153 | // shuffle(concat(v1, undef), concat(v2, undef)) |
| 6154 | // -> |
| 6155 | // shuffle(concat(v1, v2), undef) |
| 6156 | // because we can access quad vectors (see PerformVECTOR_SHUFFLECombine). |
| 6157 | // |
| 6158 | // This is useful in the general case, but there are special cases where |
| 6159 | // native shuffles produce larger results: the two-result ops. |
| 6160 | // |
| 6161 | // Look through the concat when lowering them: |
| 6162 | // shuffle(concat(v1, v2), undef) |
| 6163 | // -> |
| 6164 | // concat(VZIP(v1, v2):0, :1) |
| 6165 | // |
| 6166 | if (V1->getOpcode() == ISD::CONCAT_VECTORS && |
| 6167 | V2->getOpcode() == ISD::UNDEF) { |
| 6168 | SDValue SubV1 = V1->getOperand(0); |
| 6169 | SDValue SubV2 = V1->getOperand(1); |
| 6170 | EVT SubVT = SubV1.getValueType(); |
| 6171 | |
| 6172 | // We expect these to have been canonicalized to -1. |
| 6173 | assert(std::all_of(ShuffleMask.begin(), ShuffleMask.end(), [&](int i) { |
| 6174 | return i < (int)VT.getVectorNumElements(); |
| 6175 | }) && "Unexpected shuffle index into UNDEF operand!"); |
| 6176 | |
| 6177 | if (unsigned ShuffleOpc = isNEONTwoResultShuffleMask( |
| 6178 | ShuffleMask, SubVT, WhichResult, isV_UNDEF)) { |
| 6179 | if (isV_UNDEF) |
| 6180 | SubV2 = SubV1; |
| 6181 | assert((WhichResult == 0) && |
| 6182 | "In-place shuffle of concat can only have one result!"); |
| 6183 | SDValue Res = DAG.getNode(ShuffleOpc, dl, DAG.getVTList(SubVT, SubVT), |
| 6184 | SubV1, SubV2); |
| 6185 | return DAG.getNode(ISD::CONCAT_VECTORS, dl, VT, Res.getValue(0), |
| 6186 | Res.getValue(1)); |
| 6187 | } |
| 6188 | } |
| Bob Wilson | cce31f6 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 6189 | } |
| Bob Wilson | 32cd855 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 6190 | |
| Bob Wilson | a706231 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 6191 | // If the shuffle is not directly supported and it has 4 elements, use |
| 6192 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6193 | unsigned NumElts = VT.getVectorNumElements(); |
| 6194 | if (NumElts == 4) { |
| Anton Korobeynikov | 9a232f4 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 6195 | unsigned PFIndexes[4]; |
| 6196 | for (unsigned i = 0; i != 4; ++i) { |
| 6197 | if (ShuffleMask[i] < 0) |
| 6198 | PFIndexes[i] = 8; |
| 6199 | else |
| 6200 | PFIndexes[i] = ShuffleMask[i]; |
| 6201 | } |
| 6202 | |
| 6203 | // Compute the index in the perfect shuffle table. |
| 6204 | unsigned PFTableIndex = |
| 6205 | 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] | 6206 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 6207 | unsigned Cost = (PFEntry >> 30); |
| 6208 | |
| 6209 | if (Cost <= 4) |
| 6210 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 6211 | } |
| Bob Wilson | ea3a402 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 6212 | |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6213 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6214 | if (EltSize >= 32) { |
| 6215 | // Do the expansion with floating-point types, since that is what the VFP |
| 6216 | // registers are defined to use, and since i64 is not legal. |
| 6217 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 6218 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6219 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 6220 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6221 | SmallVector<SDValue, 8> Ops; |
| Bob Wilson | 91fdf68 | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 6222 | for (unsigned i = 0; i < NumElts; ++i) { |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6223 | if (ShuffleMask[i] < 0) |
| Bob Wilson | d8a9a04 | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 6224 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 6225 | else |
| 6226 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 6227 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 6228 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6229 | dl, MVT::i32))); |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6230 | } |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6231 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, Ops); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6232 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
| Bob Wilson | 5954994 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 6233 | } |
| 6234 | |
| Arnold Schwaighofer | 1f3d3ca | 2013-02-12 01:58:32 +0000 | [diff] [blame] | 6235 | if ((VT == MVT::v8i16 || VT == MVT::v16i8) && isReverseMask(ShuffleMask, VT)) |
| 6236 | return LowerReverse_VECTOR_SHUFFLEv16i8_v8i16(Op, DAG); |
| 6237 | |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 6238 | if (VT == MVT::v8i8) |
| 6239 | if (SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG)) |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6240 | return NewOp; |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6241 | |
| Bob Wilson | 6f34e27 | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 6242 | return SDValue(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6243 | } |
| 6244 | |
| Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 6245 | static SDValue LowerINSERT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| 6246 | // INSERT_VECTOR_ELT is legal only for immediate indexes. |
| 6247 | SDValue Lane = Op.getOperand(2); |
| 6248 | if (!isa<ConstantSDNode>(Lane)) |
| 6249 | return SDValue(); |
| 6250 | |
| 6251 | return Op; |
| 6252 | } |
| 6253 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6254 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6255 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6256 | SDValue Lane = Op.getOperand(1); |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6257 | if (!isa<ConstantSDNode>(Lane)) |
| 6258 | return SDValue(); |
| 6259 | |
| 6260 | SDValue Vec = Op.getOperand(0); |
| 6261 | if (Op.getValueType() == MVT::i32 && |
| 6262 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6263 | SDLoc dl(Op); |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6264 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 6265 | } |
| 6266 | |
| 6267 | return Op; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6268 | } |
| 6269 | |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6270 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 6271 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 6272 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 6273 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 6274 | "unexpected CONCAT_VECTORS"); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6275 | SDLoc dl(Op); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6276 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6277 | SDValue Op0 = Op.getOperand(0); |
| 6278 | SDValue Op1 = Op.getOperand(1); |
| 6279 | if (Op0.getOpcode() != ISD::UNDEF) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6280 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6281 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6282 | DAG.getIntPtrConstant(0, dl)); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 6283 | if (Op1.getOpcode() != ISD::UNDEF) |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6284 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6285 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6286 | DAG.getIntPtrConstant(1, dl)); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6287 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6288 | } |
| 6289 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6290 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 6291 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 6292 | /// from an integer type half its size. |
| 6293 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 6294 | bool isSigned) { |
| 6295 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 6296 | EVT VT = N->getValueType(0); |
| 6297 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 6298 | SDNode *BVN = N->getOperand(0).getNode(); |
| 6299 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 6300 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 6301 | return false; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 6302 | unsigned LoElt = DAG.getDataLayout().isBigEndian() ? 1 : 0; |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6303 | unsigned HiElt = 1 - LoElt; |
| 6304 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 6305 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 6306 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 6307 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 6308 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 6309 | return false; |
| 6310 | if (isSigned) { |
| 6311 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 6312 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 6313 | return true; |
| 6314 | } else { |
| 6315 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 6316 | return true; |
| 6317 | } |
| 6318 | return false; |
| 6319 | } |
| 6320 | |
| 6321 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 6322 | return false; |
| 6323 | |
| 6324 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 6325 | SDNode *Elt = N->getOperand(i).getNode(); |
| 6326 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 6327 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 6328 | unsigned HalfSize = EltSize / 2; |
| 6329 | if (isSigned) { |
| Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 6330 | if (!isIntN(HalfSize, C->getSExtValue())) |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6331 | return false; |
| 6332 | } else { |
| Bob Wilson | 93b0f7b | 2011-10-18 18:46:49 +0000 | [diff] [blame] | 6333 | if (!isUIntN(HalfSize, C->getZExtValue())) |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6334 | return false; |
| 6335 | } |
| 6336 | continue; |
| 6337 | } |
| 6338 | return false; |
| 6339 | } |
| 6340 | |
| 6341 | return true; |
| 6342 | } |
| 6343 | |
| 6344 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 6345 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 6346 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 6347 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 6348 | return true; |
| 6349 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 6350 | return true; |
| 6351 | return false; |
| 6352 | } |
| 6353 | |
| 6354 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 6355 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 6356 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 6357 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 6358 | return true; |
| 6359 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 6360 | return true; |
| 6361 | return false; |
| 6362 | } |
| 6363 | |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6364 | static EVT getExtensionTo64Bits(const EVT &OrigVT) { |
| 6365 | if (OrigVT.getSizeInBits() >= 64) |
| 6366 | return OrigVT; |
| 6367 | |
| 6368 | assert(OrigVT.isSimple() && "Expecting a simple value type"); |
| 6369 | |
| 6370 | MVT::SimpleValueType OrigSimpleTy = OrigVT.getSimpleVT().SimpleTy; |
| 6371 | switch (OrigSimpleTy) { |
| 6372 | default: llvm_unreachable("Unexpected Vector Type"); |
| 6373 | case MVT::v2i8: |
| 6374 | case MVT::v2i16: |
| 6375 | return MVT::v2i32; |
| 6376 | case MVT::v4i8: |
| 6377 | return MVT::v4i16; |
| 6378 | } |
| 6379 | } |
| 6380 | |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6381 | /// AddRequiredExtensionForVMULL - Add a sign/zero extension to extend the total |
| 6382 | /// value size to 64 bits. We need a 64-bit D register as an operand to VMULL. |
| 6383 | /// We insert the required extension here to get the vector to fill a D register. |
| 6384 | static SDValue AddRequiredExtensionForVMULL(SDValue N, SelectionDAG &DAG, |
| 6385 | const EVT &OrigTy, |
| 6386 | const EVT &ExtTy, |
| 6387 | unsigned ExtOpcode) { |
| 6388 | // The vector originally had a size of OrigTy. It was then extended to ExtTy. |
| 6389 | // We expect the ExtTy to be 128-bits total. If the OrigTy is less than |
| 6390 | // 64-bits we need to insert a new extension so that it will be 64-bits. |
| 6391 | assert(ExtTy.is128BitVector() && "Unexpected extension size"); |
| 6392 | if (OrigTy.getSizeInBits() >= 64) |
| 6393 | return N; |
| 6394 | |
| 6395 | // 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] | 6396 | EVT NewVT = getExtensionTo64Bits(OrigTy); |
| 6397 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6398 | return DAG.getNode(ExtOpcode, SDLoc(N), NewVT, N); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6399 | } |
| 6400 | |
| 6401 | /// SkipLoadExtensionForVMULL - return a load of the original vector size that |
| 6402 | /// does not do any sign/zero extension. If the original vector is less |
| 6403 | /// than 64 bits, an appropriate extension will be added after the load to |
| 6404 | /// reach a total size of 64 bits. We have to add the extension separately |
| 6405 | /// because ARM does not have a sign/zero extending load for vectors. |
| 6406 | static SDValue SkipLoadExtensionForVMULL(LoadSDNode *LD, SelectionDAG& DAG) { |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6407 | EVT ExtendedTy = getExtensionTo64Bits(LD->getMemoryVT()); |
| 6408 | |
| 6409 | // The load already has the right type. |
| 6410 | if (ExtendedTy == LD->getMemoryVT()) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6411 | return DAG.getLoad(LD->getMemoryVT(), SDLoc(LD), LD->getChain(), |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6412 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 6413 | LD->isNonTemporal(), LD->isInvariant(), |
| 6414 | LD->getAlignment()); |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6415 | |
| 6416 | // We need to create a zextload/sextload. We cannot just create a load |
| 6417 | // followed by a zext/zext node because LowerMUL is also run during normal |
| 6418 | // operation legalization where we can't create illegal types. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6419 | return DAG.getExtLoad(LD->getExtensionType(), SDLoc(LD), ExtendedTy, |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6420 | LD->getChain(), LD->getBasePtr(), LD->getPointerInfo(), |
| Louis Gerbarg | 67474e3 | 2014-07-31 21:45:05 +0000 | [diff] [blame] | 6421 | LD->getMemoryVT(), LD->isVolatile(), LD->isInvariant(), |
| Arnold Schwaighofer | af85f60 | 2013-05-14 22:33:24 +0000 | [diff] [blame] | 6422 | LD->isNonTemporal(), LD->getAlignment()); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6423 | } |
| 6424 | |
| 6425 | /// SkipExtensionForVMULL - For a node that is a SIGN_EXTEND, ZERO_EXTEND, |
| 6426 | /// extending load, or BUILD_VECTOR with extended elements, return the |
| 6427 | /// unextended value. The unextended vector should be 64 bits so that it can |
| 6428 | /// be used as an operand to a VMULL instruction. If the original vector size |
| 6429 | /// before extension is less than 64 bits we add a an extension to resize |
| 6430 | /// the vector to 64 bits. |
| 6431 | static SDValue SkipExtensionForVMULL(SDNode *N, SelectionDAG &DAG) { |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6432 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6433 | return AddRequiredExtensionForVMULL(N->getOperand(0), DAG, |
| 6434 | N->getOperand(0)->getValueType(0), |
| 6435 | N->getValueType(0), |
| 6436 | N->getOpcode()); |
| 6437 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6438 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6439 | return SkipLoadExtensionForVMULL(LD, DAG); |
| 6440 | |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6441 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 6442 | // have been legalized as a BITCAST from v4i32. |
| 6443 | if (N->getOpcode() == ISD::BITCAST) { |
| 6444 | SDNode *BVN = N->getOperand(0).getNode(); |
| 6445 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 6446 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 6447 | unsigned LowElt = DAG.getDataLayout().isBigEndian() ? 1 : 0; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6448 | return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(N), MVT::v2i32, |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6449 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 6450 | } |
| 6451 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 6452 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 6453 | EVT VT = N->getValueType(0); |
| 6454 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 6455 | unsigned NumElts = VT.getVectorNumElements(); |
| 6456 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 6457 | SmallVector<SDValue, 8> Ops; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6458 | SDLoc dl(N); |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6459 | for (unsigned i = 0; i != NumElts; ++i) { |
| 6460 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 6461 | const APInt &CInt = C->getAPIntValue(); |
| Bob Wilson | 9245c93 | 2012-04-30 16:53:34 +0000 | [diff] [blame] | 6462 | // Element types smaller than 32 bits are not legal, so use i32 elements. |
| 6463 | // The values are implicitly truncated so sext vs. zext doesn't matter. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6464 | Ops.push_back(DAG.getConstant(CInt.zextOrTrunc(32), dl, MVT::i32)); |
| Bob Wilson | d7d2cf7 | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 6465 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6466 | return DAG.getNode(ISD::BUILD_VECTOR, dl, |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 6467 | MVT::getVectorVT(TruncVT, NumElts), Ops); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6468 | } |
| 6469 | |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6470 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 6471 | unsigned Opcode = N->getOpcode(); |
| 6472 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 6473 | SDNode *N0 = N->getOperand(0).getNode(); |
| 6474 | SDNode *N1 = N->getOperand(1).getNode(); |
| 6475 | return N0->hasOneUse() && N1->hasOneUse() && |
| 6476 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 6477 | } |
| 6478 | return false; |
| 6479 | } |
| 6480 | |
| 6481 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 6482 | unsigned Opcode = N->getOpcode(); |
| 6483 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 6484 | SDNode *N0 = N->getOperand(0).getNode(); |
| 6485 | SDNode *N1 = N->getOperand(1).getNode(); |
| 6486 | return N0->hasOneUse() && N1->hasOneUse() && |
| 6487 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 6488 | } |
| 6489 | return false; |
| 6490 | } |
| 6491 | |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6492 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 6493 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 6494 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 6495 | EVT VT = Op.getValueType(); |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6496 | assert(VT.is128BitVector() && VT.isInteger() && |
| 6497 | "unexpected type for custom-lowering ISD::MUL"); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6498 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 6499 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 6500 | unsigned NewOpc = 0; |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6501 | bool isMLA = false; |
| 6502 | bool isN0SExt = isSignExtended(N0, DAG); |
| 6503 | bool isN1SExt = isSignExtended(N1, DAG); |
| 6504 | if (isN0SExt && isN1SExt) |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6505 | NewOpc = ARMISD::VMULLs; |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6506 | else { |
| 6507 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 6508 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 6509 | if (isN0ZExt && isN1ZExt) |
| 6510 | NewOpc = ARMISD::VMULLu; |
| 6511 | else if (isN1SExt || isN1ZExt) { |
| 6512 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 6513 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 6514 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 6515 | NewOpc = ARMISD::VMULLs; |
| 6516 | isMLA = true; |
| 6517 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 6518 | NewOpc = ARMISD::VMULLu; |
| 6519 | isMLA = true; |
| 6520 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 6521 | std::swap(N0, N1); |
| 6522 | NewOpc = ARMISD::VMULLu; |
| 6523 | isMLA = true; |
| 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | if (!NewOpc) { |
| 6528 | if (VT == MVT::v2i64) |
| 6529 | // Fall through to expand this. It is not legal. |
| 6530 | return SDValue(); |
| 6531 | else |
| 6532 | // Other vector multiplications are legal. |
| 6533 | return Op; |
| 6534 | } |
| 6535 | } |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6536 | |
| 6537 | // Legalize to a VMULL instruction. |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6538 | SDLoc DL(Op); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6539 | SDValue Op0; |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6540 | SDValue Op1 = SkipExtensionForVMULL(N1, DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6541 | if (!isMLA) { |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6542 | Op0 = SkipExtensionForVMULL(N0, DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6543 | assert(Op0.getValueType().is64BitVector() && |
| 6544 | Op1.getValueType().is64BitVector() && |
| 6545 | "unexpected types for extended operands to VMULL"); |
| 6546 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 6547 | } |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6548 | |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6549 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 6550 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 6551 | // vmull q0, d4, d6 |
| 6552 | // vmlal q0, d5, d6 |
| 6553 | // is faster than |
| 6554 | // vaddl q0, d4, d5 |
| 6555 | // vmovl q1, d6 |
| 6556 | // vmul q0, q0, q1 |
| Sebastian Pop | a204f72 | 2012-11-30 19:08:04 +0000 | [diff] [blame] | 6557 | SDValue N00 = SkipExtensionForVMULL(N0->getOperand(0).getNode(), DAG); |
| 6558 | SDValue N01 = SkipExtensionForVMULL(N0->getOperand(1).getNode(), DAG); |
| Evan Cheng | e2086e7 | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 6559 | EVT Op1VT = Op1.getValueType(); |
| 6560 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 6561 | DAG.getNode(NewOpc, DL, VT, |
| 6562 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 6563 | DAG.getNode(NewOpc, DL, VT, |
| 6564 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 6565 | } |
| 6566 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6567 | static SDValue |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6568 | LowerSDIV_v4i8(SDValue X, SDValue Y, SDLoc dl, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6569 | // TODO: Should this propagate fast-math-flags? |
| 6570 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6571 | // Convert to float |
| 6572 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 6573 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 6574 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 6575 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 6576 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 6577 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 6578 | // Get reciprocal estimate. |
| 6579 | // float4 recip = vrecpeq_f32(yf); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6580 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6581 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6582 | Y); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6583 | // Because char has a smaller range than uchar, we can actually get away |
| 6584 | // without any newton steps. This requires that we use a weird bias |
| 6585 | // of 0xb000, however (again, this has been exhaustively tested). |
| 6586 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 6587 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 6588 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 6589 | Y = DAG.getConstant(0xb000, dl, MVT::v4i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6590 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 6591 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 6592 | // Convert back to short. |
| 6593 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 6594 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 6595 | return X; |
| 6596 | } |
| 6597 | |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6598 | static SDValue |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6599 | LowerSDIV_v4i16(SDValue N0, SDValue N1, SDLoc dl, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6600 | // TODO: Should this propagate fast-math-flags? |
| 6601 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6602 | SDValue N2; |
| 6603 | // Convert to float. |
| 6604 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 6605 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 6606 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 6607 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 6608 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 6609 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6610 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6611 | // Use reciprocal estimate and one refinement step. |
| 6612 | // float4 recip = vrecpeq_f32(yf); |
| 6613 | // recip *= vrecpsq_f32(yf, recip); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6614 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6615 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6616 | N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6617 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6618 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6619 | N1, N2); |
| 6620 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 6621 | // Because short has a smaller range than ushort, we can actually get away |
| 6622 | // with only a single newton step. This requires that we use a weird bias |
| 6623 | // of 89, however (again, this has been exhaustively tested). |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6624 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6625 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 6626 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 6627 | N1 = DAG.getConstant(0x89, dl, MVT::v4i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6628 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 6629 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 6630 | // Convert back to integer and return. |
| 6631 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 6632 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 6633 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 6634 | return N0; |
| 6635 | } |
| 6636 | |
| 6637 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 6638 | EVT VT = Op.getValueType(); |
| 6639 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 6640 | "unexpected type for custom-lowering ISD::SDIV"); |
| 6641 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6642 | SDLoc dl(Op); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6643 | SDValue N0 = Op.getOperand(0); |
| 6644 | SDValue N1 = Op.getOperand(1); |
| 6645 | SDValue N2, N3; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6646 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6647 | if (VT == MVT::v8i8) { |
| 6648 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 6649 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6650 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6651 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6652 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6653 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6654 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6655 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6656 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6657 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6658 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6659 | |
| 6660 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 6661 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 6662 | |
| 6663 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 6664 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6665 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6666 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 6667 | return N0; |
| 6668 | } |
| 6669 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 6670 | } |
| 6671 | |
| 6672 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| Sanjay Patel | a260701 | 2015-09-16 16:31:21 +0000 | [diff] [blame] | 6673 | // TODO: Should this propagate fast-math-flags? |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6674 | EVT VT = Op.getValueType(); |
| 6675 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 6676 | "unexpected type for custom-lowering ISD::UDIV"); |
| 6677 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6678 | SDLoc dl(Op); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6679 | SDValue N0 = Op.getOperand(0); |
| 6680 | SDValue N1 = Op.getOperand(1); |
| 6681 | SDValue N2, N3; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6682 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6683 | if (VT == MVT::v8i8) { |
| 6684 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 6685 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6686 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6687 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6688 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6689 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6690 | DAG.getIntPtrConstant(4, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6691 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6692 | DAG.getIntPtrConstant(0, dl)); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6693 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6694 | DAG.getIntPtrConstant(0, dl)); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6695 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6696 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 6697 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6698 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6699 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 6700 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6701 | |
| 6702 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6703 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, dl, |
| 6704 | MVT::i32), |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6705 | N0); |
| 6706 | return N0; |
| 6707 | } |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6708 | |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6709 | // v4i16 sdiv ... Convert to float. |
| 6710 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 6711 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 6712 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 6713 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 6714 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6715 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6716 | |
| 6717 | // Use reciprocal estimate and two refinement steps. |
| 6718 | // float4 recip = vrecpeq_f32(yf); |
| 6719 | // recip *= vrecpsq_f32(yf, recip); |
| 6720 | // recip *= vrecpsq_f32(yf, recip); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6721 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6722 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, dl, MVT::i32), |
| 6723 | BN1); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6724 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6725 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6726 | BN1, N2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6727 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6728 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6729 | DAG.getConstant(Intrinsic::arm_neon_vrecps, dl, MVT::i32), |
| Mon P Wang | 6d9e1c7 | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 6730 | BN1, N2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6731 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 6732 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 6733 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 6734 | // 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] | 6735 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6736 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 6737 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| Ahmed Bougacha | 93cff7f | 2016-02-15 18:07:29 +0000 | [diff] [blame] | 6738 | N1 = DAG.getConstant(2, dl, MVT::v4i32); |
| Nate Begeman | fa62d50 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 6739 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 6740 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 6741 | // Convert back to integer and return. |
| 6742 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 6743 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 6744 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 6745 | return N0; |
| 6746 | } |
| 6747 | |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6748 | static SDValue LowerADDC_ADDE_SUBC_SUBE(SDValue Op, SelectionDAG &DAG) { |
| 6749 | EVT VT = Op.getNode()->getValueType(0); |
| 6750 | SDVTList VTs = DAG.getVTList(VT, MVT::i32); |
| 6751 | |
| 6752 | unsigned Opc; |
| 6753 | bool ExtraOp = false; |
| 6754 | switch (Op.getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 6755 | default: llvm_unreachable("Invalid code"); |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6756 | case ISD::ADDC: Opc = ARMISD::ADDC; break; |
| 6757 | case ISD::ADDE: Opc = ARMISD::ADDE; ExtraOp = true; break; |
| 6758 | case ISD::SUBC: Opc = ARMISD::SUBC; break; |
| 6759 | case ISD::SUBE: Opc = ARMISD::SUBE; ExtraOp = true; break; |
| 6760 | } |
| 6761 | |
| 6762 | if (!ExtraOp) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6763 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6764 | Op.getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6765 | return DAG.getNode(Opc, SDLoc(Op), VTs, Op.getOperand(0), |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 6766 | Op.getOperand(1), Op.getOperand(2)); |
| 6767 | } |
| 6768 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6769 | SDValue ARMTargetLowering::LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const { |
| 6770 | assert(Subtarget->isTargetDarwin()); |
| 6771 | |
| 6772 | // For iOS, we want to call an alternative entry point: __sincos_stret, |
| 6773 | // return values are passed via sret. |
| 6774 | SDLoc dl(Op); |
| 6775 | SDValue Arg = Op.getOperand(0); |
| 6776 | EVT ArgVT = Arg.getValueType(); |
| 6777 | Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext()); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6778 | auto PtrVT = getPointerTy(DAG.getDataLayout()); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6779 | |
| 6780 | MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo(); |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6781 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6782 | |
| 6783 | // Pair of floats / doubles used to pass the result. |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6784 | Type *RetTy = StructType::get(ArgTy, ArgTy, nullptr); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6785 | auto &DL = DAG.getDataLayout(); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6786 | |
| 6787 | ArgListTy Args; |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6788 | bool ShouldUseSRet = Subtarget->isAPCS_ABI(); |
| 6789 | SDValue SRet; |
| 6790 | if (ShouldUseSRet) { |
| 6791 | // Create stack object for sret. |
| 6792 | const uint64_t ByteSize = DL.getTypeAllocSize(RetTy); |
| 6793 | const unsigned StackAlign = DL.getPrefTypeAlignment(RetTy); |
| 6794 | int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign, false); |
| 6795 | SRet = DAG.getFrameIndex(FrameIdx, TLI.getPointerTy(DL)); |
| 6796 | |
| 6797 | ArgListEntry Entry; |
| 6798 | Entry.Node = SRet; |
| 6799 | Entry.Ty = RetTy->getPointerTo(); |
| 6800 | Entry.isSExt = false; |
| 6801 | Entry.isZExt = false; |
| 6802 | Entry.isSRet = true; |
| 6803 | Args.push_back(Entry); |
| 6804 | RetTy = Type::getVoidTy(*DAG.getContext()); |
| 6805 | } |
| 6806 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6807 | ArgListEntry Entry; |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6808 | Entry.Node = Arg; |
| 6809 | Entry.Ty = ArgTy; |
| 6810 | Entry.isSExt = false; |
| 6811 | Entry.isZExt = false; |
| 6812 | Args.push_back(Entry); |
| 6813 | |
| Saleem Abdulrasool | 4966f58 | 2015-09-20 03:19:09 +0000 | [diff] [blame] | 6814 | const char *LibcallName = |
| 6815 | (ArgVT == MVT::f64) ? "__sincos_stret" : "__sincosf_stret"; |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6816 | RTLIB::Libcall LC = |
| 6817 | (ArgVT == MVT::f64) ? RTLIB::SINCOS_F64 : RTLIB::SINCOS_F32; |
| 6818 | CallingConv::ID CC = getLibcallCallingConv(LC); |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6819 | SDValue Callee = DAG.getExternalSymbol(LibcallName, getPointerTy(DL)); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6820 | |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 6821 | TargetLowering::CallLoweringInfo CLI(DAG); |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6822 | CLI.setDebugLoc(dl) |
| 6823 | .setChain(DAG.getEntryNode()) |
| 6824 | .setCallee(CC, RetTy, Callee, std::move(Args), 0) |
| 6825 | .setDiscardResult(ShouldUseSRet); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6826 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| 6827 | |
| Tim Northover | 8b40366 | 2015-10-28 22:51:16 +0000 | [diff] [blame] | 6828 | if (!ShouldUseSRet) |
| 6829 | return CallResult.first; |
| 6830 | |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6831 | SDValue LoadSin = DAG.getLoad(ArgVT, dl, CallResult.second, SRet, |
| 6832 | MachinePointerInfo(), false, false, false, 0); |
| 6833 | |
| 6834 | // Address of cos field. |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 6835 | SDValue Add = DAG.getNode(ISD::ADD, dl, PtrVT, SRet, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 6836 | DAG.getIntPtrConstant(ArgVT.getStoreSize(), dl)); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 6837 | SDValue LoadCos = DAG.getLoad(ArgVT, dl, LoadSin.getValue(1), Add, |
| 6838 | MachinePointerInfo(), false, false, false, 0); |
| 6839 | |
| 6840 | SDVTList Tys = DAG.getVTList(ArgVT, ArgVT); |
| 6841 | return DAG.getNode(ISD::MERGE_VALUES, dl, Tys, |
| 6842 | LoadSin.getValue(0), LoadCos.getValue(0)); |
| 6843 | } |
| 6844 | |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6845 | SDValue ARMTargetLowering::LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG, |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6846 | bool Signed, |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6847 | SDValue &Chain) const { |
| 6848 | EVT VT = Op.getValueType(); |
| 6849 | assert((VT == MVT::i32 || VT == MVT::i64) && |
| 6850 | "unexpected type for custom lowering DIV"); |
| 6851 | SDLoc dl(Op); |
| 6852 | |
| 6853 | const auto &DL = DAG.getDataLayout(); |
| 6854 | const auto &TLI = DAG.getTargetLoweringInfo(); |
| 6855 | |
| 6856 | const char *Name = nullptr; |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6857 | if (Signed) |
| 6858 | Name = (VT == MVT::i32) ? "__rt_sdiv" : "__rt_sdiv64"; |
| 6859 | else |
| 6860 | Name = (VT == MVT::i32) ? "__rt_udiv" : "__rt_udiv64"; |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6861 | |
| 6862 | SDValue ES = DAG.getExternalSymbol(Name, TLI.getPointerTy(DL)); |
| 6863 | |
| 6864 | ARMTargetLowering::ArgListTy Args; |
| 6865 | |
| 6866 | for (auto AI : {1, 0}) { |
| 6867 | ArgListEntry Arg; |
| 6868 | Arg.Node = Op.getOperand(AI); |
| 6869 | Arg.Ty = Arg.Node.getValueType().getTypeForEVT(*DAG.getContext()); |
| 6870 | Args.push_back(Arg); |
| 6871 | } |
| 6872 | |
| 6873 | CallLoweringInfo CLI(DAG); |
| 6874 | CLI.setDebugLoc(dl) |
| 6875 | .setChain(Chain) |
| 6876 | .setCallee(CallingConv::ARM_AAPCS_VFP, VT.getTypeForEVT(*DAG.getContext()), |
| 6877 | ES, std::move(Args), 0); |
| 6878 | |
| 6879 | return LowerCallTo(CLI).first; |
| 6880 | } |
| 6881 | |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6882 | SDValue ARMTargetLowering::LowerDIV_Windows(SDValue Op, SelectionDAG &DAG, |
| 6883 | bool Signed) const { |
| Saleem Abdulrasool | 8e99f50 | 2015-09-25 05:41:02 +0000 | [diff] [blame] | 6884 | assert(Op.getValueType() == MVT::i32 && |
| 6885 | "unexpected type for custom lowering DIV"); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6886 | SDLoc dl(Op); |
| 6887 | |
| 6888 | SDValue DBZCHK = DAG.getNode(ARMISD::WIN__DBZCHK, dl, MVT::Other, |
| 6889 | DAG.getEntryNode(), Op.getOperand(1)); |
| 6890 | |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6891 | return LowerWindowsDIVLibCall(Op, DAG, Signed, DBZCHK); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6892 | } |
| 6893 | |
| 6894 | void ARMTargetLowering::ExpandDIV_Windows( |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6895 | SDValue Op, SelectionDAG &DAG, bool Signed, |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6896 | SmallVectorImpl<SDValue> &Results) const { |
| 6897 | const auto &DL = DAG.getDataLayout(); |
| 6898 | const auto &TLI = DAG.getTargetLoweringInfo(); |
| 6899 | |
| Saleem Abdulrasool | 8e99f50 | 2015-09-25 05:41:02 +0000 | [diff] [blame] | 6900 | assert(Op.getValueType() == MVT::i64 && |
| 6901 | "unexpected type for custom lowering DIV"); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6902 | SDLoc dl(Op); |
| 6903 | |
| 6904 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op.getOperand(1), |
| 6905 | DAG.getConstant(0, dl, MVT::i32)); |
| 6906 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op.getOperand(1), |
| 6907 | DAG.getConstant(1, dl, MVT::i32)); |
| 6908 | SDValue Or = DAG.getNode(ISD::OR, dl, MVT::i32, Lo, Hi); |
| 6909 | |
| 6910 | SDValue DBZCHK = |
| 6911 | DAG.getNode(ARMISD::WIN__DBZCHK, dl, MVT::Other, DAG.getEntryNode(), Or); |
| 6912 | |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 6913 | SDValue Result = LowerWindowsDIVLibCall(Op, DAG, Signed, DBZCHK); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 6914 | |
| 6915 | SDValue Lower = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Result); |
| 6916 | SDValue Upper = DAG.getNode(ISD::SRL, dl, MVT::i64, Result, |
| 6917 | DAG.getConstant(32, dl, TLI.getPointerTy(DL))); |
| 6918 | Upper = DAG.getNode(ISD::TRUNCATE, dl, MVT::i32, Upper); |
| 6919 | |
| 6920 | Results.push_back(Lower); |
| 6921 | Results.push_back(Upper); |
| 6922 | } |
| 6923 | |
| Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 6924 | static SDValue LowerAtomicLoadStore(SDValue Op, SelectionDAG &DAG) { |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6925 | // Monotonic load/store is legal for all targets |
| 6926 | if (cast<AtomicSDNode>(Op)->getOrdering() <= Monotonic) |
| 6927 | return Op; |
| 6928 | |
| Alp Toker | cb40291 | 2014-01-24 17:20:08 +0000 | [diff] [blame] | 6929 | // Acquire/Release load/store is not legal for targets without a |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 6930 | // dmb or equivalent available. |
| 6931 | return SDValue(); |
| 6932 | } |
| 6933 | |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6934 | static void ReplaceREADCYCLECOUNTER(SDNode *N, |
| 6935 | SmallVectorImpl<SDValue> &Results, |
| 6936 | SelectionDAG &DAG, |
| 6937 | const ARMSubtarget *Subtarget) { |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 6938 | SDLoc DL(N); |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 6939 | // Under Power Management extensions, the cycle-count is: |
| 6940 | // mrc p15, #0, <Rt>, c9, c13, #0 |
| 6941 | SDValue Ops[] = { N->getOperand(0), // Chain |
| 6942 | DAG.getConstant(Intrinsic::arm_mrc, DL, MVT::i32), |
| 6943 | DAG.getConstant(15, DL, MVT::i32), |
| 6944 | DAG.getConstant(0, DL, MVT::i32), |
| 6945 | DAG.getConstant(9, DL, MVT::i32), |
| 6946 | DAG.getConstant(13, DL, MVT::i32), |
| 6947 | DAG.getConstant(0, DL, MVT::i32) |
| 6948 | }; |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6949 | |
| Ahmed Bougacha | f9c19da | 2015-08-28 01:49:59 +0000 | [diff] [blame] | 6950 | SDValue Cycles32 = DAG.getNode(ISD::INTRINSIC_W_CHAIN, DL, |
| 6951 | DAG.getVTList(MVT::i32, MVT::Other), Ops); |
| 6952 | Results.push_back(DAG.getNode(ISD::BUILD_PAIR, DL, MVT::i64, Cycles32, |
| 6953 | DAG.getConstant(0, DL, MVT::i32))); |
| 6954 | Results.push_back(Cycles32.getValue(1)); |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 6955 | } |
| 6956 | |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 6957 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6958 | switch (Op.getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6959 | default: llvm_unreachable("Don't know how to custom lower this!"); |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 6960 | case ISD::WRITE_REGISTER: return LowerWRITE_REGISTER(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6961 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
| Bob Wilson | 1cf0b03 | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 6962 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
| Lauro Ramos Venancio | ee2d164 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 6963 | case ISD::GlobalAddress: |
| Saleem Abdulrasool | 40bca0a | 2014-05-09 00:58:32 +0000 | [diff] [blame] | 6964 | switch (Subtarget->getTargetTriple().getObjectFormat()) { |
| 6965 | default: llvm_unreachable("unknown object format"); |
| 6966 | case Triple::COFF: |
| 6967 | return LowerGlobalAddressWindows(Op, DAG); |
| 6968 | case Triple::ELF: |
| 6969 | return LowerGlobalAddressELF(Op, DAG); |
| 6970 | case Triple::MachO: |
| 6971 | return LowerGlobalAddressDarwin(Op, DAG); |
| 6972 | } |
| Bill Wendling | e1fd78f | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 6973 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
| Bill Wendling | 6a98131 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 6974 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6975 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 6976 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6977 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
| Dan Gohman | 31ae586 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 6978 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
| Eli Friedman | 26a4848 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 6979 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
| Evan Cheng | 8740ee3 | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 6980 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
| Bob Wilson | e4191e7 | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 6981 | case ISD::SINT_TO_FP: |
| 6982 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 6983 | case ISD::FP_TO_SINT: |
| 6984 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 6985 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
| Evan Cheng | 168ced9 | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 6986 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
| Jim Grosbach | aeca45d | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 6987 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
| Jim Grosbach | c98892f | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 6988 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
| Jim Grosbach | bd9485d | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 6989 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 6990 | 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] | 6991 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 6992 | Subtarget); |
| Evan Cheng | 383ecd8 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 6993 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6994 | case ISD::SHL: |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 6995 | case ISD::SRL: |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6996 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 6997 | case ISD::SREM: return LowerREM(Op.getNode(), DAG); |
| 6998 | case ISD::UREM: return LowerREM(Op.getNode(), DAG); |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 6999 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
| Jim Grosbach | 8fe6fd7 | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 7000 | case ISD::SRL_PARTS: |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 7001 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
| Logan Chien | 0a43abc | 2015-07-13 15:37:30 +0000 | [diff] [blame] | 7002 | case ISD::CTTZ: |
| 7003 | case ISD::CTTZ_ZERO_UNDEF: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
| Evan Cheng | b4eae13 | 2012-12-04 22:41:50 +0000 | [diff] [blame] | 7004 | case ISD::CTPOP: return LowerCTPOP(Op.getNode(), DAG, Subtarget); |
| Duncan Sands | f2641e1 | 2011-09-06 19:07:46 +0000 | [diff] [blame] | 7005 | case ISD::SETCC: return LowerVSETCC(Op, DAG); |
| Lang Hames | c35ee8b | 2012-03-15 18:49:02 +0000 | [diff] [blame] | 7006 | case ISD::ConstantFP: return LowerConstantFP(Op, DAG, Subtarget); |
| Dale Johannesen | 2bff505 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 7007 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7008 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
| Eli Friedman | a5e244c | 2011-10-24 23:08:52 +0000 | [diff] [blame] | 7009 | case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7010 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
| Bob Wilson | f307e0b | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 7011 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
| Bob Wilson | 9a511c0 | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 7012 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
| Bob Wilson | 38ab35a | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 7013 | case ISD::MUL: return LowerMUL(Op, DAG); |
| Martell Malone | a6b867e | 2015-11-23 13:11:39 +0000 | [diff] [blame] | 7014 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 7015 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
| Evan Cheng | e891654 | 2011-08-30 01:34:54 +0000 | [diff] [blame] | 7016 | case ISD::ADDC: |
| 7017 | case ISD::ADDE: |
| 7018 | case ISD::SUBC: |
| 7019 | case ISD::SUBE: return LowerADDC_ADDE_SUBC_SUBE(Op, DAG); |
| Louis Gerbarg | 3342bf1 | 2014-05-09 17:02:49 +0000 | [diff] [blame] | 7020 | case ISD::SADDO: |
| 7021 | case ISD::UADDO: |
| 7022 | case ISD::SSUBO: |
| 7023 | case ISD::USUBO: |
| 7024 | return LowerXALUO(Op, DAG); |
| Eli Friedman | ba912e0 | 2011-09-15 22:18:49 +0000 | [diff] [blame] | 7025 | case ISD::ATOMIC_LOAD: |
| Eli Friedman | 10f9ce2 | 2011-09-15 22:26:18 +0000 | [diff] [blame] | 7026 | case ISD::ATOMIC_STORE: return LowerAtomicLoadStore(Op, DAG); |
| Bob Wilson | e7dde0c | 2013-11-03 06:14:38 +0000 | [diff] [blame] | 7027 | case ISD::FSINCOS: return LowerFSINCOS(Op, DAG); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 7028 | case ISD::SDIVREM: |
| 7029 | case ISD::UDIVREM: return LowerDivRem(Op, DAG); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7030 | case ISD::DYNAMIC_STACKALLOC: |
| 7031 | if (Subtarget->getTargetTriple().isWindowsItaniumEnvironment()) |
| 7032 | return LowerDYNAMIC_STACKALLOC(Op, DAG); |
| 7033 | llvm_unreachable("Don't know how to custom lower this!"); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 7034 | case ISD::FP_ROUND: return LowerFP_ROUND(Op, DAG); |
| 7035 | case ISD::FP_EXTEND: return LowerFP_EXTEND(Op, DAG); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 7036 | case ARMISD::WIN__DBZCHK: return SDValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7037 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7038 | } |
| 7039 | |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 7040 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 7041 | /// type with new values built out of custom code. |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 7042 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 7043 | SmallVectorImpl<SDValue> &Results, |
| Dan Gohman | 21cea8a | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 7044 | SelectionDAG &DAG) const { |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 7045 | SDValue Res; |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 7046 | switch (N->getOpcode()) { |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 7047 | default: |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 7048 | llvm_unreachable("Don't know how to custom expand this!"); |
| Luke Cheeseman | 85fd06d | 2015-06-01 12:02:47 +0000 | [diff] [blame] | 7049 | case ISD::READ_REGISTER: |
| 7050 | ExpandREAD_REGISTER(N, Results, DAG); |
| 7051 | break; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7052 | case ISD::BITCAST: |
| 7053 | Res = ExpandBITCAST(N, DAG); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 7054 | break; |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 7055 | case ISD::SRL: |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 7056 | case ISD::SRA: |
| Bob Wilson | 7d47133 | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 7057 | Res = Expand64BitShift(N, DAG, Subtarget); |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 7058 | break; |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 7059 | case ISD::SREM: |
| 7060 | case ISD::UREM: |
| 7061 | Res = LowerREM(N, DAG); |
| 7062 | break; |
| Renato Golin | 175c6d6 | 2016-03-04 19:19:36 +0000 | [diff] [blame] | 7063 | case ISD::SDIVREM: |
| 7064 | case ISD::UDIVREM: |
| 7065 | Res = LowerDivRem(SDValue(N, 0), DAG); |
| 7066 | assert(Res.getNumOperands() == 2 && "DivRem needs two values"); |
| 7067 | Results.push_back(Res.getValue(0)); |
| 7068 | Results.push_back(Res.getValue(1)); |
| 7069 | return; |
| Tim Northover | bc93308 | 2013-05-23 19:11:20 +0000 | [diff] [blame] | 7070 | case ISD::READCYCLECOUNTER: |
| 7071 | ReplaceREADCYCLECOUNTER(N, Results, DAG, Subtarget); |
| 7072 | return; |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 7073 | case ISD::UDIV: |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 7074 | case ISD::SDIV: |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 7075 | assert(Subtarget->isTargetWindows() && "can only expand DIV on Windows"); |
| Martell Malone | d122924 | 2015-11-26 15:34:03 +0000 | [diff] [blame] | 7076 | return ExpandDIV_Windows(SDValue(N, 0), DAG, N->getOpcode() == ISD::SDIV, |
| 7077 | Results); |
| Duncan Sands | 6ed4014 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 7078 | } |
| Bob Wilson | c05b887 | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 7079 | if (Res.getNode()) |
| 7080 | Results.push_back(Res); |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 7081 | } |
| Chris Lattner | f81d588 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 7082 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7083 | //===----------------------------------------------------------------------===// |
| 7084 | // ARM Scheduler Hooks |
| 7085 | //===----------------------------------------------------------------------===// |
| 7086 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7087 | /// SetupEntryBlockForSjLj - Insert code into the entry block that creates and |
| 7088 | /// registers the function context. |
| 7089 | void ARMTargetLowering:: |
| 7090 | SetupEntryBlockForSjLj(MachineInstr *MI, MachineBasicBlock *MBB, |
| 7091 | MachineBasicBlock *DispatchBB, int FI) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7092 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7093 | DebugLoc dl = MI->getDebugLoc(); |
| 7094 | MachineFunction *MF = MBB->getParent(); |
| 7095 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| 7096 | MachineConstantPool *MCP = MF->getConstantPool(); |
| 7097 | ARMFunctionInfo *AFI = MF->getInfo<ARMFunctionInfo>(); |
| 7098 | const Function *F = MF->getFunction(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7099 | |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7100 | bool isThumb = Subtarget->isThumb(); |
| Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 7101 | bool isThumb2 = Subtarget->isThumb2(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7102 | |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7103 | unsigned PCLabelId = AFI->createPICLabelUId(); |
| Bill Wendling | 1eab54f | 2011-10-03 22:44:15 +0000 | [diff] [blame] | 7104 | unsigned PCAdj = (isThumb || isThumb2) ? 4 : 8; |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7105 | ARMConstantPoolValue *CPV = |
| 7106 | ARMConstantPoolMBB::Create(F->getContext(), DispatchBB, PCLabelId, PCAdj); |
| 7107 | unsigned CPI = MCP->getConstantPoolIndex(CPV, 4); |
| 7108 | |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7109 | const TargetRegisterClass *TRC = isThumb ? &ARM::tGPRRegClass |
| 7110 | : &ARM::GPRRegClass; |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7111 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7112 | // Grab constant pool and fixed stack memory operands. |
| 7113 | MachineMemOperand *CPMMO = |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7114 | MF->getMachineMemOperand(MachinePointerInfo::getConstantPool(*MF), |
| 7115 | MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7116 | |
| 7117 | MachineMemOperand *FIMMOSt = |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7118 | MF->getMachineMemOperand(MachinePointerInfo::getFixedStack(*MF, FI), |
| 7119 | MachineMemOperand::MOStore, 4, 4); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7120 | |
| 7121 | // Load the address of the dispatch MBB into the jump buffer. |
| 7122 | if (isThumb2) { |
| 7123 | // Incoming value: jbuf |
| 7124 | // ldr.n r5, LCPI1_1 |
| 7125 | // orr r5, r5, #1 |
| 7126 | // add r5, pc |
| 7127 | // str r5, [$jbuf, #+4] ; &jbuf[1] |
| 7128 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7129 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2LDRpci), NewVReg1) |
| 7130 | .addConstantPoolIndex(CPI) |
| 7131 | .addMemOperand(CPMMO)); |
| 7132 | // Set the low bit because of thumb mode. |
| 7133 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7134 | AddDefaultCC( |
| 7135 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2ORRri), NewVReg2) |
| 7136 | .addReg(NewVReg1, RegState::Kill) |
| 7137 | .addImm(0x01))); |
| 7138 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 7139 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg3) |
| 7140 | .addReg(NewVReg2, RegState::Kill) |
| 7141 | .addImm(PCLabelId); |
| 7142 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::t2STRi12)) |
| 7143 | .addReg(NewVReg3, RegState::Kill) |
| 7144 | .addFrameIndex(FI) |
| 7145 | .addImm(36) // &jbuf[1] :: pc |
| 7146 | .addMemOperand(FIMMOSt)); |
| 7147 | } else if (isThumb) { |
| 7148 | // Incoming value: jbuf |
| 7149 | // ldr.n r1, LCPI1_4 |
| 7150 | // add r1, pc |
| 7151 | // mov r2, #1 |
| 7152 | // orrs r1, r2 |
| 7153 | // add r2, $jbuf, #+4 ; &jbuf[1] |
| 7154 | // str r1, [r2] |
| 7155 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7156 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tLDRpci), NewVReg1) |
| 7157 | .addConstantPoolIndex(CPI) |
| 7158 | .addMemOperand(CPMMO)); |
| 7159 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7160 | BuildMI(*MBB, MI, dl, TII->get(ARM::tPICADD), NewVReg2) |
| 7161 | .addReg(NewVReg1, RegState::Kill) |
| 7162 | .addImm(PCLabelId); |
| 7163 | // Set the low bit because of thumb mode. |
| 7164 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 7165 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tMOVi8), NewVReg3) |
| 7166 | .addReg(ARM::CPSR, RegState::Define) |
| 7167 | .addImm(1)); |
| 7168 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 7169 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tORR), NewVReg4) |
| 7170 | .addReg(ARM::CPSR, RegState::Define) |
| 7171 | .addReg(NewVReg2, RegState::Kill) |
| 7172 | .addReg(NewVReg3, RegState::Kill)); |
| 7173 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| Tim Northover | 23075cc | 2014-10-20 21:28:41 +0000 | [diff] [blame] | 7174 | BuildMI(*MBB, MI, dl, TII->get(ARM::tADDframe), NewVReg5) |
| 7175 | .addFrameIndex(FI) |
| 7176 | .addImm(36); // &jbuf[1] :: pc |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7177 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::tSTRi)) |
| 7178 | .addReg(NewVReg4, RegState::Kill) |
| 7179 | .addReg(NewVReg5, RegState::Kill) |
| 7180 | .addImm(0) |
| 7181 | .addMemOperand(FIMMOSt)); |
| 7182 | } else { |
| 7183 | // Incoming value: jbuf |
| 7184 | // ldr r1, LCPI1_1 |
| 7185 | // add r1, pc, r1 |
| 7186 | // str r1, [$jbuf, #+4] ; &jbuf[1] |
| 7187 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7188 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 7189 | .addConstantPoolIndex(CPI) |
| 7190 | .addImm(0) |
| 7191 | .addMemOperand(CPMMO)); |
| 7192 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7193 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::PICADD), NewVReg2) |
| 7194 | .addReg(NewVReg1, RegState::Kill) |
| 7195 | .addImm(PCLabelId)); |
| 7196 | AddDefaultPred(BuildMI(*MBB, MI, dl, TII->get(ARM::STRi12)) |
| 7197 | .addReg(NewVReg2, RegState::Kill) |
| 7198 | .addFrameIndex(FI) |
| 7199 | .addImm(36) // &jbuf[1] :: pc |
| 7200 | .addMemOperand(FIMMOSt)); |
| 7201 | } |
| 7202 | } |
| 7203 | |
| Matthias Braun | eec4efc | 2015-04-28 00:37:05 +0000 | [diff] [blame] | 7204 | void ARMTargetLowering::EmitSjLjDispatchBlock(MachineInstr *MI, |
| 7205 | MachineBasicBlock *MBB) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7206 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7207 | DebugLoc dl = MI->getDebugLoc(); |
| 7208 | MachineFunction *MF = MBB->getParent(); |
| 7209 | MachineRegisterInfo *MRI = &MF->getRegInfo(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7210 | MachineFrameInfo *MFI = MF->getFrameInfo(); |
| 7211 | int FI = MFI->getFunctionContextIndex(); |
| 7212 | |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7213 | const TargetRegisterClass *TRC = Subtarget->isThumb() ? &ARM::tGPRRegClass |
| 7214 | : &ARM::GPRnopcRegClass; |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7215 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7216 | // Get a mapping of the call site numbers to all of the landing pads they're |
| 7217 | // associated with. |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7218 | DenseMap<unsigned, SmallVector<MachineBasicBlock*, 2> > CallSiteNumToLPad; |
| 7219 | unsigned MaxCSNum = 0; |
| 7220 | MachineModuleInfo &MMI = MF->getMMI(); |
| Jim Grosbach | 0c509fa | 2012-04-06 23:43:50 +0000 | [diff] [blame] | 7221 | for (MachineFunction::iterator BB = MF->begin(), E = MF->end(); BB != E; |
| 7222 | ++BB) { |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7223 | if (!BB->isEHPad()) continue; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7224 | |
| 7225 | // FIXME: We should assert that the EH_LABEL is the first MI in the landing |
| 7226 | // pad. |
| 7227 | for (MachineBasicBlock::iterator |
| 7228 | II = BB->begin(), IE = BB->end(); II != IE; ++II) { |
| 7229 | if (!II->isEHLabel()) continue; |
| 7230 | |
| 7231 | MCSymbol *Sym = II->getOperand(0).getMCSymbol(); |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7232 | if (!MMI.hasCallSiteLandingPad(Sym)) continue; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7233 | |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7234 | SmallVectorImpl<unsigned> &CallSiteIdxs = MMI.getCallSiteLandingPad(Sym); |
| 7235 | for (SmallVectorImpl<unsigned>::iterator |
| 7236 | CSI = CallSiteIdxs.begin(), CSE = CallSiteIdxs.end(); |
| 7237 | CSI != CSE; ++CSI) { |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 7238 | CallSiteNumToLPad[*CSI].push_back(&*BB); |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7239 | MaxCSNum = std::max(MaxCSNum, *CSI); |
| 7240 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7241 | break; |
| 7242 | } |
| 7243 | } |
| 7244 | |
| 7245 | // Get an ordered list of the machine basic blocks for the jump table. |
| 7246 | std::vector<MachineBasicBlock*> LPadList; |
| Matthias Braun | b30f2f51 | 2016-01-30 01:24:31 +0000 | [diff] [blame] | 7247 | SmallPtrSet<MachineBasicBlock*, 32> InvokeBBs; |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7248 | LPadList.reserve(CallSiteNumToLPad.size()); |
| 7249 | for (unsigned I = 1; I <= MaxCSNum; ++I) { |
| 7250 | SmallVectorImpl<MachineBasicBlock*> &MBBList = CallSiteNumToLPad[I]; |
| 7251 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7252 | II = MBBList.begin(), IE = MBBList.end(); II != IE; ++II) { |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7253 | LPadList.push_back(*II); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7254 | InvokeBBs.insert((*II)->pred_begin(), (*II)->pred_end()); |
| 7255 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7256 | } |
| 7257 | |
| Bill Wendling | f793e7e | 2011-10-05 23:28:57 +0000 | [diff] [blame] | 7258 | assert(!LPadList.empty() && |
| 7259 | "No landing pad destinations for the dispatch jump table!"); |
| 7260 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7261 | // Create the jump table and associated information. |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7262 | MachineJumpTableInfo *JTI = |
| 7263 | MF->getOrCreateJumpTableInfo(MachineJumpTableInfo::EK_Inline); |
| 7264 | unsigned MJTI = JTI->createJumpTableIndex(LPadList); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7265 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7266 | |
| Bill Wendling | 362c1b0 | 2011-10-06 21:29:56 +0000 | [diff] [blame] | 7267 | // Create the MBBs for the dispatch code. |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7268 | |
| 7269 | // Shove the dispatch's address into the return slot in the function context. |
| 7270 | MachineBasicBlock *DispatchBB = MF->CreateMachineBasicBlock(); |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7271 | DispatchBB->setIsEHPad(); |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7272 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7273 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7274 | unsigned trap_opcode; |
| Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 7275 | if (Subtarget->isThumb()) |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7276 | trap_opcode = ARM::tTRAP; |
| Chad Rosier | 11a9828 | 2013-02-28 18:54:27 +0000 | [diff] [blame] | 7277 | else |
| 7278 | trap_opcode = Subtarget->useNaClTrap() ? ARM::TRAPNaCl : ARM::TRAP; |
| 7279 | |
| Eli Bendersky | 2e2ce49 | 2013-01-30 16:30:19 +0000 | [diff] [blame] | 7280 | BuildMI(TrapBB, dl, TII->get(trap_opcode)); |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7281 | DispatchBB->addSuccessor(TrapBB); |
| 7282 | |
| 7283 | MachineBasicBlock *DispContBB = MF->CreateMachineBasicBlock(); |
| 7284 | DispatchBB->addSuccessor(DispContBB); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7285 | |
| Bill Wendling | 510fbcd | 2011-10-17 21:32:56 +0000 | [diff] [blame] | 7286 | // Insert and MBBs. |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7287 | MF->insert(MF->end(), DispatchBB); |
| 7288 | MF->insert(MF->end(), DispContBB); |
| 7289 | MF->insert(MF->end(), TrapBB); |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7290 | |
| Bill Wendling | 030b58e | 2011-10-06 22:18:16 +0000 | [diff] [blame] | 7291 | // Insert code into the entry block that creates and registers the function |
| 7292 | // context. |
| 7293 | SetupEntryBlockForSjLj(MI, MBB, DispatchBB, FI); |
| 7294 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7295 | MachineMemOperand *FIMMOLd = MF->getMachineMemOperand( |
| 7296 | MachinePointerInfo::getFixedStack(*MF, FI), |
| 7297 | MachineMemOperand::MOLoad | MachineMemOperand::MOVolatile, 4, 4); |
| Bill Wendling | 6134655 | 2011-10-06 00:53:33 +0000 | [diff] [blame] | 7298 | |
| Chad Rosier | 1ec8e40 | 2012-11-06 23:05:24 +0000 | [diff] [blame] | 7299 | MachineInstrBuilder MIB; |
| 7300 | MIB = BuildMI(DispatchBB, dl, TII->get(ARM::Int_eh_sjlj_dispatchsetup)); |
| 7301 | |
| 7302 | const ARMBaseInstrInfo *AII = static_cast<const ARMBaseInstrInfo*>(TII); |
| 7303 | const ARMBaseRegisterInfo &RI = AII->getRegisterInfo(); |
| 7304 | |
| 7305 | // Add a register mask with no preserved registers. This results in all |
| 7306 | // registers being marked as clobbered. |
| 7307 | MIB.addRegMask(RI.getNoPreservedMask()); |
| Bob Wilson | f6d1728 | 2011-11-16 07:11:57 +0000 | [diff] [blame] | 7308 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7309 | unsigned NumLPads = LPadList.size(); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7310 | if (Subtarget->isThumb2()) { |
| 7311 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7312 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2LDRi12), NewVReg1) |
| 7313 | .addFrameIndex(FI) |
| 7314 | .addImm(4) |
| 7315 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7316 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7317 | if (NumLPads < 256) { |
| 7318 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPri)) |
| 7319 | .addReg(NewVReg1) |
| 7320 | .addImm(LPadList.size())); |
| 7321 | } else { |
| 7322 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7323 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVi16), VReg1) |
| Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 7324 | .addImm(NumLPads & 0xFFFF)); |
| 7325 | |
| 7326 | unsigned VReg2 = VReg1; |
| 7327 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 7328 | VReg2 = MRI->createVirtualRegister(TRC); |
| 7329 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2MOVTi16), VReg2) |
| 7330 | .addReg(VReg1) |
| 7331 | .addImm(NumLPads >> 16)); |
| 7332 | } |
| 7333 | |
| Bill Wendling | 85833f7 | 2011-10-18 22:49:07 +0000 | [diff] [blame] | 7334 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::t2CMPrr)) |
| 7335 | .addReg(NewVReg1) |
| 7336 | .addReg(VReg2)); |
| 7337 | } |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7338 | |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7339 | BuildMI(DispatchBB, dl, TII->get(ARM::t2Bcc)) |
| 7340 | .addMBB(TrapBB) |
| 7341 | .addImm(ARMCC::HI) |
| 7342 | .addReg(ARM::CPSR); |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7343 | |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7344 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| 7345 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::t2LEApcrelJT),NewVReg3) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7346 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7347 | |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7348 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7349 | AddDefaultCC( |
| 7350 | AddDefaultPred( |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7351 | BuildMI(DispContBB, dl, TII->get(ARM::t2ADDrs), NewVReg4) |
| 7352 | .addReg(NewVReg3, RegState::Kill) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7353 | .addReg(NewVReg1) |
| 7354 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| 7355 | |
| 7356 | BuildMI(DispContBB, dl, TII->get(ARM::t2BR_JT)) |
| Bill Wendling | b2a703d | 2011-10-18 21:55:58 +0000 | [diff] [blame] | 7357 | .addReg(NewVReg4, RegState::Kill) |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7358 | .addReg(NewVReg1) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7359 | .addJumpTableIndex(MJTI); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7360 | } else if (Subtarget->isThumb()) { |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7361 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7362 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRspi), NewVReg1) |
| 7363 | .addFrameIndex(FI) |
| 7364 | .addImm(1) |
| 7365 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | f9f5e45 | 2011-10-07 22:08:37 +0000 | [diff] [blame] | 7366 | |
| Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 7367 | if (NumLPads < 256) { |
| 7368 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPi8)) |
| 7369 | .addReg(NewVReg1) |
| 7370 | .addImm(NumLPads)); |
| 7371 | } else { |
| 7372 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7373 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7374 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 7375 | |
| 7376 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7377 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7378 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7379 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7380 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| Bill Wendling | 64e6bfc | 2011-10-18 23:11:05 +0000 | [diff] [blame] | 7381 | |
| 7382 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7383 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tLDRpci)) |
| 7384 | .addReg(VReg1, RegState::Define) |
| 7385 | .addConstantPoolIndex(Idx)); |
| 7386 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::tCMPr)) |
| 7387 | .addReg(NewVReg1) |
| 7388 | .addReg(VReg1)); |
| 7389 | } |
| 7390 | |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7391 | BuildMI(DispatchBB, dl, TII->get(ARM::tBcc)) |
| 7392 | .addMBB(TrapBB) |
| 7393 | .addImm(ARMCC::HI) |
| 7394 | .addReg(ARM::CPSR); |
| 7395 | |
| 7396 | unsigned NewVReg2 = MRI->createVirtualRegister(TRC); |
| 7397 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLSLri), NewVReg2) |
| 7398 | .addReg(ARM::CPSR, RegState::Define) |
| 7399 | .addReg(NewVReg1) |
| 7400 | .addImm(2)); |
| 7401 | |
| 7402 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 8d50ea0 | 2011-10-06 23:41:14 +0000 | [diff] [blame] | 7403 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLEApcrelJT), NewVReg3) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7404 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7405 | |
| 7406 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 7407 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg4) |
| 7408 | .addReg(ARM::CPSR, RegState::Define) |
| 7409 | .addReg(NewVReg2, RegState::Kill) |
| 7410 | .addReg(NewVReg3)); |
| 7411 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7412 | MachineMemOperand *JTMMOLd = MF->getMachineMemOperand( |
| 7413 | MachinePointerInfo::getJumpTable(*MF), MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7414 | |
| 7415 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| 7416 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tLDRi), NewVReg5) |
| 7417 | .addReg(NewVReg4, RegState::Kill) |
| 7418 | .addImm(0) |
| 7419 | .addMemOperand(JTMMOLd)); |
| 7420 | |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7421 | unsigned NewVReg6 = NewVReg5; |
| 7422 | if (RelocM == Reloc::PIC_) { |
| 7423 | NewVReg6 = MRI->createVirtualRegister(TRC); |
| 7424 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::tADDrr), NewVReg6) |
| 7425 | .addReg(ARM::CPSR, RegState::Define) |
| 7426 | .addReg(NewVReg5, RegState::Kill) |
| 7427 | .addReg(NewVReg3)); |
| 7428 | } |
| Bill Wendling | b3d4678 | 2011-10-06 23:37:36 +0000 | [diff] [blame] | 7429 | |
| 7430 | BuildMI(DispContBB, dl, TII->get(ARM::tBR_JTr)) |
| 7431 | .addReg(NewVReg6, RegState::Kill) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7432 | .addJumpTableIndex(MJTI); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7433 | } else { |
| 7434 | unsigned NewVReg1 = MRI->createVirtualRegister(TRC); |
| 7435 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRi12), NewVReg1) |
| 7436 | .addFrameIndex(FI) |
| 7437 | .addImm(4) |
| 7438 | .addMemOperand(FIMMOLd)); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7439 | |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7440 | if (NumLPads < 256) { |
| 7441 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPri)) |
| 7442 | .addReg(NewVReg1) |
| 7443 | .addImm(NumLPads)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7444 | } else if (Subtarget->hasV6T2Ops() && isUInt<16>(NumLPads)) { |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7445 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7446 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVi16), VReg1) |
| Bill Wendling | 94f6001 | 2011-10-18 23:19:55 +0000 | [diff] [blame] | 7447 | .addImm(NumLPads & 0xFFFF)); |
| 7448 | |
| 7449 | unsigned VReg2 = VReg1; |
| 7450 | if ((NumLPads & 0xFFFF0000) != 0) { |
| 7451 | VReg2 = MRI->createVirtualRegister(TRC); |
| 7452 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::MOVTi16), VReg2) |
| 7453 | .addReg(VReg1) |
| 7454 | .addImm(NumLPads >> 16)); |
| 7455 | } |
| 7456 | |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7457 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 7458 | .addReg(NewVReg1) |
| 7459 | .addReg(VReg2)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7460 | } else { |
| 7461 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 7462 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7463 | const Constant *C = ConstantInt::get(Int32Ty, NumLPads); |
| 7464 | |
| 7465 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7466 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7467 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7468 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7469 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 7470 | |
| 7471 | unsigned VReg1 = MRI->createVirtualRegister(TRC); |
| 7472 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::LDRcp)) |
| 7473 | .addReg(VReg1, RegState::Define) |
| Bill Wendling | cf7bdf4 | 2011-10-20 20:37:11 +0000 | [diff] [blame] | 7474 | .addConstantPoolIndex(Idx) |
| 7475 | .addImm(0)); |
| Bill Wendling | 2977a15 | 2011-10-19 09:24:02 +0000 | [diff] [blame] | 7476 | AddDefaultPred(BuildMI(DispatchBB, dl, TII->get(ARM::CMPrr)) |
| 7477 | .addReg(NewVReg1) |
| 7478 | .addReg(VReg1, RegState::Kill)); |
| Bill Wendling | 4969dcd | 2011-10-18 22:52:20 +0000 | [diff] [blame] | 7479 | } |
| 7480 | |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7481 | BuildMI(DispatchBB, dl, TII->get(ARM::Bcc)) |
| 7482 | .addMBB(TrapBB) |
| 7483 | .addImm(ARMCC::HI) |
| 7484 | .addReg(ARM::CPSR); |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7485 | |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7486 | unsigned NewVReg3 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7487 | AddDefaultCC( |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7488 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::MOVsi), NewVReg3) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7489 | .addReg(NewVReg1) |
| 7490 | .addImm(ARM_AM::getSORegOpc(ARM_AM::lsl, 2)))); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7491 | unsigned NewVReg4 = MRI->createVirtualRegister(TRC); |
| 7492 | AddDefaultPred(BuildMI(DispContBB, dl, TII->get(ARM::LEApcrelJT), NewVReg4) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7493 | .addJumpTableIndex(MJTI)); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7494 | |
| Alex Lorenz | e40c8a2 | 2015-08-11 23:09:45 +0000 | [diff] [blame] | 7495 | MachineMemOperand *JTMMOLd = MF->getMachineMemOperand( |
| 7496 | MachinePointerInfo::getJumpTable(*MF), MachineMemOperand::MOLoad, 4, 4); |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7497 | unsigned NewVReg5 = MRI->createVirtualRegister(TRC); |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7498 | AddDefaultPred( |
| Bill Wendling | 973c817 | 2011-10-18 22:11:18 +0000 | [diff] [blame] | 7499 | BuildMI(DispContBB, dl, TII->get(ARM::LDRrs), NewVReg5) |
| 7500 | .addReg(NewVReg3, RegState::Kill) |
| 7501 | .addReg(NewVReg4) |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7502 | .addImm(0) |
| 7503 | .addMemOperand(JTMMOLd)); |
| 7504 | |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7505 | if (RelocM == Reloc::PIC_) { |
| 7506 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTadd)) |
| 7507 | .addReg(NewVReg5, RegState::Kill) |
| 7508 | .addReg(NewVReg4) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7509 | .addJumpTableIndex(MJTI); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7510 | } else { |
| 7511 | BuildMI(DispContBB, dl, TII->get(ARM::BR_JTr)) |
| 7512 | .addReg(NewVReg5, RegState::Kill) |
| Tim Northover | 4998a47 | 2015-05-13 20:28:38 +0000 | [diff] [blame] | 7513 | .addJumpTableIndex(MJTI); |
| Chad Rosier | 9660343 | 2013-03-01 18:30:38 +0000 | [diff] [blame] | 7514 | } |
| Bill Wendling | 5626c66 | 2011-10-06 22:53:00 +0000 | [diff] [blame] | 7515 | } |
| Bill Wendling | 202803e | 2011-10-05 00:02:33 +0000 | [diff] [blame] | 7516 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7517 | // Add the jump table entries as successors to the MBB. |
| Jakob Stoklund Olesen | 710093e | 2012-08-20 20:52:03 +0000 | [diff] [blame] | 7518 | SmallPtrSet<MachineBasicBlock*, 8> SeenMBBs; |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7519 | for (std::vector<MachineBasicBlock*>::iterator |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7520 | I = LPadList.begin(), E = LPadList.end(); I != E; ++I) { |
| 7521 | MachineBasicBlock *CurMBB = *I; |
| David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 7522 | if (SeenMBBs.insert(CurMBB).second) |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7523 | DispContBB->addSuccessor(CurMBB); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7524 | } |
| 7525 | |
| Bill Wendling | 26d2780 | 2011-10-17 05:25:09 +0000 | [diff] [blame] | 7526 | // 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] | 7527 | const MCPhysReg *SavedRegs = RI.getCalleeSavedRegs(MF); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7528 | SmallVector<MachineBasicBlock*, 64> MBBLPads; |
| Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 7529 | for (MachineBasicBlock *BB : InvokeBBs) { |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7530 | |
| 7531 | // Remove the landing pad successor from the invoke block and replace it |
| 7532 | // with the new dispatch block. |
| Bill Wendling | 1414bc5 | 2011-10-26 07:16:18 +0000 | [diff] [blame] | 7533 | SmallVector<MachineBasicBlock*, 4> Successors(BB->succ_begin(), |
| 7534 | BB->succ_end()); |
| 7535 | while (!Successors.empty()) { |
| 7536 | MachineBasicBlock *SMBB = Successors.pop_back_val(); |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7537 | if (SMBB->isEHPad()) { |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7538 | BB->removeSuccessor(SMBB); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7539 | MBBLPads.push_back(SMBB); |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7540 | } |
| 7541 | } |
| 7542 | |
| Cong Hou | d97c100 | 2015-12-01 05:29:22 +0000 | [diff] [blame] | 7543 | BB->addSuccessor(DispatchBB, BranchProbability::getZero()); |
| Cong Hou | c106989 | 2015-12-13 09:26:17 +0000 | [diff] [blame] | 7544 | BB->normalizeSuccProbs(); |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7545 | |
| 7546 | // Find the invoke call and mark all of the callee-saved registers as |
| 7547 | // 'implicit defined' so that they're spilled. This prevents code from |
| 7548 | // moving instructions to before the EH block, where they will never be |
| 7549 | // executed. |
| 7550 | for (MachineBasicBlock::reverse_iterator |
| 7551 | II = BB->rbegin(), IE = BB->rend(); II != IE; ++II) { |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 7552 | if (!II->isCall()) continue; |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7553 | |
| 7554 | DenseMap<unsigned, bool> DefRegs; |
| 7555 | for (MachineInstr::mop_iterator |
| 7556 | OI = II->operands_begin(), OE = II->operands_end(); |
| 7557 | OI != OE; ++OI) { |
| 7558 | if (!OI->isReg()) continue; |
| 7559 | DefRegs[OI->getReg()] = true; |
| 7560 | } |
| 7561 | |
| Jakob Stoklund Olesen | b159b5f | 2012-12-19 21:31:56 +0000 | [diff] [blame] | 7562 | MachineInstrBuilder MIB(*MF, &*II); |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7563 | |
| Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 7564 | for (unsigned i = 0; SavedRegs[i] != 0; ++i) { |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7565 | unsigned Reg = SavedRegs[i]; |
| 7566 | if (Subtarget->isThumb2() && |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7567 | !ARM::tGPRRegClass.contains(Reg) && |
| 7568 | !ARM::hGPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7569 | continue; |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7570 | if (Subtarget->isThumb1Only() && !ARM::tGPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7571 | continue; |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 7572 | if (!Subtarget->isThumb() && !ARM::GPRRegClass.contains(Reg)) |
| Bill Wendling | 94e6643 | 2011-10-22 00:29:28 +0000 | [diff] [blame] | 7573 | continue; |
| 7574 | if (!DefRegs[Reg]) |
| 7575 | MIB.addReg(Reg, RegState::ImplicitDefine | RegState::Dead); |
| Bill Wendling | 9e0cd1e | 2011-10-14 23:55:44 +0000 | [diff] [blame] | 7576 | } |
| Bill Wendling | 6f3f9a3 | 2011-10-14 23:34:37 +0000 | [diff] [blame] | 7577 | |
| 7578 | break; |
| 7579 | } |
| Bill Wendling | 883ec97 | 2011-10-07 23:18:02 +0000 | [diff] [blame] | 7580 | } |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7581 | |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7582 | // Mark all former landing pads as non-landing pads. The dispatch is the only |
| 7583 | // landing pad now. |
| 7584 | for (SmallVectorImpl<MachineBasicBlock*>::iterator |
| 7585 | I = MBBLPads.begin(), E = MBBLPads.end(); I != E; ++I) |
| Reid Kleckner | 0e28823 | 2015-08-27 23:27:47 +0000 | [diff] [blame] | 7586 | (*I)->setIsEHPad(false); |
| Bill Wendling | 617075f | 2011-10-18 18:30:49 +0000 | [diff] [blame] | 7587 | |
| Bill Wendling | 324be98 | 2011-10-05 00:39:32 +0000 | [diff] [blame] | 7588 | // The instruction is gone now. |
| 7589 | MI->eraseFromParent(); |
| Bill Wendling | 374ee19 | 2011-10-03 21:25:38 +0000 | [diff] [blame] | 7590 | } |
| 7591 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 7592 | static |
| 7593 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 7594 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 7595 | E = MBB->succ_end(); I != E; ++I) |
| 7596 | if (*I != Succ) |
| 7597 | return *I; |
| 7598 | llvm_unreachable("Expecting a BB with two successors!"); |
| 7599 | } |
| 7600 | |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7601 | /// Return the load opcode for a given load size. If load size >= 8, |
| 7602 | /// neon opcode will be returned. |
| 7603 | static unsigned getLdOpcode(unsigned LdSize, bool IsThumb1, bool IsThumb2) { |
| 7604 | if (LdSize >= 8) |
| 7605 | return LdSize == 16 ? ARM::VLD1q32wb_fixed |
| 7606 | : LdSize == 8 ? ARM::VLD1d32wb_fixed : 0; |
| 7607 | if (IsThumb1) |
| 7608 | return LdSize == 4 ? ARM::tLDRi |
| 7609 | : LdSize == 2 ? ARM::tLDRHi |
| 7610 | : LdSize == 1 ? ARM::tLDRBi : 0; |
| 7611 | if (IsThumb2) |
| 7612 | return LdSize == 4 ? ARM::t2LDR_POST |
| 7613 | : LdSize == 2 ? ARM::t2LDRH_POST |
| 7614 | : LdSize == 1 ? ARM::t2LDRB_POST : 0; |
| 7615 | return LdSize == 4 ? ARM::LDR_POST_IMM |
| 7616 | : LdSize == 2 ? ARM::LDRH_POST |
| 7617 | : LdSize == 1 ? ARM::LDRB_POST_IMM : 0; |
| 7618 | } |
| 7619 | |
| 7620 | /// Return the store opcode for a given store size. If store size >= 8, |
| 7621 | /// neon opcode will be returned. |
| 7622 | static unsigned getStOpcode(unsigned StSize, bool IsThumb1, bool IsThumb2) { |
| 7623 | if (StSize >= 8) |
| 7624 | return StSize == 16 ? ARM::VST1q32wb_fixed |
| 7625 | : StSize == 8 ? ARM::VST1d32wb_fixed : 0; |
| 7626 | if (IsThumb1) |
| 7627 | return StSize == 4 ? ARM::tSTRi |
| 7628 | : StSize == 2 ? ARM::tSTRHi |
| 7629 | : StSize == 1 ? ARM::tSTRBi : 0; |
| 7630 | if (IsThumb2) |
| 7631 | return StSize == 4 ? ARM::t2STR_POST |
| 7632 | : StSize == 2 ? ARM::t2STRH_POST |
| 7633 | : StSize == 1 ? ARM::t2STRB_POST : 0; |
| 7634 | return StSize == 4 ? ARM::STR_POST_IMM |
| 7635 | : StSize == 2 ? ARM::STRH_POST |
| 7636 | : StSize == 1 ? ARM::STRB_POST_IMM : 0; |
| 7637 | } |
| 7638 | |
| 7639 | /// Emit a post-increment load operation with given size. The instructions |
| 7640 | /// will be added to BB at Pos. |
| 7641 | static void emitPostLd(MachineBasicBlock *BB, MachineInstr *Pos, |
| 7642 | const TargetInstrInfo *TII, DebugLoc dl, |
| 7643 | unsigned LdSize, unsigned Data, unsigned AddrIn, |
| 7644 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { |
| 7645 | unsigned LdOpc = getLdOpcode(LdSize, IsThumb1, IsThumb2); |
| 7646 | assert(LdOpc != 0 && "Should have a load opcode"); |
| 7647 | if (LdSize >= 8) { |
| 7648 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7649 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7650 | .addImm(0)); |
| 7651 | } else if (IsThumb1) { |
| 7652 | // load + update AddrIn |
| 7653 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7654 | .addReg(AddrIn).addImm(0)); |
| 7655 | MachineInstrBuilder MIB = |
| 7656 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); |
| 7657 | MIB = AddDefaultT1CC(MIB); |
| 7658 | MIB.addReg(AddrIn).addImm(LdSize); |
| 7659 | AddDefaultPred(MIB); |
| 7660 | } else if (IsThumb2) { |
| 7661 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7662 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7663 | .addImm(LdSize)); |
| 7664 | } else { // arm |
| 7665 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(LdOpc), Data) |
| 7666 | .addReg(AddrOut, RegState::Define).addReg(AddrIn) |
| 7667 | .addReg(0).addImm(LdSize)); |
| 7668 | } |
| 7669 | } |
| 7670 | |
| 7671 | /// Emit a post-increment store operation with given size. The instructions |
| 7672 | /// will be added to BB at Pos. |
| 7673 | static void emitPostSt(MachineBasicBlock *BB, MachineInstr *Pos, |
| 7674 | const TargetInstrInfo *TII, DebugLoc dl, |
| 7675 | unsigned StSize, unsigned Data, unsigned AddrIn, |
| 7676 | unsigned AddrOut, bool IsThumb1, bool IsThumb2) { |
| 7677 | unsigned StOpc = getStOpcode(StSize, IsThumb1, IsThumb2); |
| 7678 | assert(StOpc != 0 && "Should have a store opcode"); |
| 7679 | if (StSize >= 8) { |
| 7680 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7681 | .addReg(AddrIn).addImm(0).addReg(Data)); |
| 7682 | } else if (IsThumb1) { |
| 7683 | // store + update AddrIn |
| 7684 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc)).addReg(Data) |
| 7685 | .addReg(AddrIn).addImm(0)); |
| 7686 | MachineInstrBuilder MIB = |
| 7687 | BuildMI(*BB, Pos, dl, TII->get(ARM::tADDi8), AddrOut); |
| 7688 | MIB = AddDefaultT1CC(MIB); |
| 7689 | MIB.addReg(AddrIn).addImm(StSize); |
| 7690 | AddDefaultPred(MIB); |
| 7691 | } else if (IsThumb2) { |
| 7692 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7693 | .addReg(Data).addReg(AddrIn).addImm(StSize)); |
| 7694 | } else { // arm |
| 7695 | AddDefaultPred(BuildMI(*BB, Pos, dl, TII->get(StOpc), AddrOut) |
| 7696 | .addReg(Data).addReg(AddrIn).addReg(0) |
| 7697 | .addImm(StSize)); |
| 7698 | } |
| 7699 | } |
| 7700 | |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7701 | MachineBasicBlock * |
| 7702 | ARMTargetLowering::EmitStructByval(MachineInstr *MI, |
| 7703 | MachineBasicBlock *BB) const { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7704 | // This pseudo instruction has 3 operands: dst, src, size |
| 7705 | // We expand it to a loop if size > Subtarget->getMaxInlineSizeThreshold(). |
| 7706 | // Otherwise, we will generate unrolled scalar copies. |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7707 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7708 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 7709 | MachineFunction::iterator It = ++BB->getIterator(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7710 | |
| 7711 | unsigned dest = MI->getOperand(0).getReg(); |
| 7712 | unsigned src = MI->getOperand(1).getReg(); |
| 7713 | unsigned SizeVal = MI->getOperand(2).getImm(); |
| 7714 | unsigned Align = MI->getOperand(3).getImm(); |
| 7715 | DebugLoc dl = MI->getDebugLoc(); |
| 7716 | |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7717 | MachineFunction *MF = BB->getParent(); |
| 7718 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7719 | unsigned UnitSize = 0; |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 7720 | const TargetRegisterClass *TRC = nullptr; |
| 7721 | const TargetRegisterClass *VecTRC = nullptr; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7722 | |
| 7723 | bool IsThumb1 = Subtarget->isThumb1Only(); |
| 7724 | bool IsThumb2 = Subtarget->isThumb2(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7725 | |
| 7726 | if (Align & 1) { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7727 | UnitSize = 1; |
| 7728 | } else if (Align & 2) { |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7729 | UnitSize = 2; |
| 7730 | } else { |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7731 | // Check whether we can use NEON instructions. |
| Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 7732 | if (!MF->getFunction()->hasFnAttribute(Attribute::NoImplicitFloat) && |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7733 | Subtarget->hasNEON()) { |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7734 | if ((Align % 16 == 0) && SizeVal >= 16) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7735 | UnitSize = 16; |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7736 | else if ((Align % 8 == 0) && SizeVal >= 8) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7737 | UnitSize = 8; |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7738 | } |
| 7739 | // Can't use NEON instructions. |
| David Peixotto | c32e24a | 2013-10-17 19:49:22 +0000 | [diff] [blame] | 7740 | if (UnitSize == 0) |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7741 | UnitSize = 4; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7742 | } |
| Manman Ren | 6e1fd46 | 2012-06-18 22:23:48 +0000 | [diff] [blame] | 7743 | |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7744 | // Select the correct opcode and register class for unit size load/store |
| 7745 | bool IsNeon = UnitSize >= 8; |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7746 | TRC = (IsThumb1 || IsThumb2) ? &ARM::tGPRRegClass : &ARM::GPRRegClass; |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7747 | if (IsNeon) |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 7748 | VecTRC = UnitSize == 16 ? &ARM::DPairRegClass |
| 7749 | : UnitSize == 8 ? &ARM::DPRRegClass |
| 7750 | : nullptr; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7751 | |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7752 | unsigned BytesLeft = SizeVal % UnitSize; |
| 7753 | unsigned LoopSize = SizeVal - BytesLeft; |
| 7754 | |
| 7755 | if (SizeVal <= Subtarget->getMaxInlineSizeThreshold()) { |
| 7756 | // Use LDR and STR to copy. |
| 7757 | // [scratch, srcOut] = LDR_POST(srcIn, UnitSize) |
| 7758 | // [destOut] = STR_POST(scratch, destIn, UnitSize) |
| 7759 | unsigned srcIn = src; |
| 7760 | unsigned destIn = dest; |
| 7761 | for (unsigned i = 0; i < LoopSize; i+=UnitSize) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7762 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7763 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7764 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7765 | emitPostLd(BB, MI, TII, dl, UnitSize, scratch, srcIn, srcOut, |
| 7766 | IsThumb1, IsThumb2); |
| 7767 | emitPostSt(BB, MI, TII, dl, UnitSize, scratch, destIn, destOut, |
| 7768 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7769 | srcIn = srcOut; |
| 7770 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7771 | } |
| 7772 | |
| 7773 | // Handle the leftover bytes with LDRB and STRB. |
| 7774 | // [scratch, srcOut] = LDRB_POST(srcIn, 1) |
| 7775 | // [destOut] = STRB_POST(scratch, destIn, 1) |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7776 | for (unsigned i = 0; i < BytesLeft; i++) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7777 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7778 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7779 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7780 | emitPostLd(BB, MI, TII, dl, 1, scratch, srcIn, srcOut, |
| 7781 | IsThumb1, IsThumb2); |
| 7782 | emitPostSt(BB, MI, TII, dl, 1, scratch, destIn, destOut, |
| 7783 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7784 | srcIn = srcOut; |
| 7785 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7786 | } |
| 7787 | MI->eraseFromParent(); // The instruction is gone now. |
| 7788 | return BB; |
| 7789 | } |
| 7790 | |
| 7791 | // Expand the pseudo op to a loop. |
| 7792 | // thisMBB: |
| 7793 | // ... |
| 7794 | // movw varEnd, # --> with thumb2 |
| 7795 | // movt varEnd, # |
| 7796 | // ldrcp varEnd, idx --> without thumb2 |
| 7797 | // fallthrough --> loopMBB |
| 7798 | // loopMBB: |
| 7799 | // PHI varPhi, varEnd, varLoop |
| 7800 | // PHI srcPhi, src, srcLoop |
| 7801 | // PHI destPhi, dst, destLoop |
| 7802 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7803 | // [destLoop] = STR_POST(scratch, destPhi, UnitSize) |
| 7804 | // subs varLoop, varPhi, #UnitSize |
| 7805 | // bne loopMBB |
| 7806 | // fallthrough --> exitMBB |
| 7807 | // exitMBB: |
| 7808 | // epilogue to handle left-over bytes |
| 7809 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7810 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7811 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7812 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 7813 | MF->insert(It, loopMBB); |
| 7814 | MF->insert(It, exitMBB); |
| 7815 | |
| 7816 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 7817 | exitMBB->splice(exitMBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 7818 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7819 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 7820 | |
| 7821 | // Load an immediate to varEnd. |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7822 | unsigned varEnd = MRI.createVirtualRegister(TRC); |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7823 | if (Subtarget->useMovt(*MF)) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7824 | unsigned Vtmp = varEnd; |
| 7825 | if ((LoopSize & 0xFFFF0000) != 0) |
| 7826 | Vtmp = MRI.createVirtualRegister(TRC); |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7827 | AddDefaultPred(BuildMI(BB, dl, |
| 7828 | TII->get(IsThumb2 ? ARM::t2MOVi16 : ARM::MOVi16), |
| 7829 | Vtmp).addImm(LoopSize & 0xFFFF)); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7830 | |
| 7831 | if ((LoopSize & 0xFFFF0000) != 0) |
| Derek Schuff | b051389 | 2015-03-26 22:11:00 +0000 | [diff] [blame] | 7832 | AddDefaultPred(BuildMI(BB, dl, |
| 7833 | TII->get(IsThumb2 ? ARM::t2MOVTi16 : ARM::MOVTi16), |
| 7834 | varEnd) |
| 7835 | .addReg(Vtmp) |
| 7836 | .addImm(LoopSize >> 16)); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7837 | } else { |
| 7838 | MachineConstantPool *ConstantPool = MF->getConstantPool(); |
| 7839 | Type *Int32Ty = Type::getInt32Ty(MF->getFunction()->getContext()); |
| 7840 | const Constant *C = ConstantInt::get(Int32Ty, LoopSize); |
| 7841 | |
| 7842 | // MachineConstantPool wants an explicit alignment. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7843 | unsigned Align = MF->getDataLayout().getPrefTypeAlignment(Int32Ty); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7844 | if (Align == 0) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 7845 | Align = MF->getDataLayout().getTypeAllocSize(C->getType()); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7846 | unsigned Idx = ConstantPool->getConstantPoolIndex(C, Align); |
| 7847 | |
| 7848 | if (IsThumb1) |
| 7849 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::tLDRpci)).addReg( |
| 7850 | varEnd, RegState::Define).addConstantPoolIndex(Idx)); |
| 7851 | else |
| 7852 | AddDefaultPred(BuildMI(*BB, MI, dl, TII->get(ARM::LDRcp)).addReg( |
| 7853 | varEnd, RegState::Define).addConstantPoolIndex(Idx).addImm(0)); |
| 7854 | } |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7855 | BB->addSuccessor(loopMBB); |
| 7856 | |
| 7857 | // Generate the loop body: |
| 7858 | // varPhi = PHI(varLoop, varEnd) |
| 7859 | // srcPhi = PHI(srcLoop, src) |
| 7860 | // destPhi = PHI(destLoop, dst) |
| 7861 | MachineBasicBlock *entryBB = BB; |
| 7862 | BB = loopMBB; |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7863 | unsigned varLoop = MRI.createVirtualRegister(TRC); |
| 7864 | unsigned varPhi = MRI.createVirtualRegister(TRC); |
| 7865 | unsigned srcLoop = MRI.createVirtualRegister(TRC); |
| 7866 | unsigned srcPhi = MRI.createVirtualRegister(TRC); |
| 7867 | unsigned destLoop = MRI.createVirtualRegister(TRC); |
| 7868 | unsigned destPhi = MRI.createVirtualRegister(TRC); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7869 | |
| 7870 | BuildMI(*BB, BB->begin(), dl, TII->get(ARM::PHI), varPhi) |
| 7871 | .addReg(varLoop).addMBB(loopMBB) |
| 7872 | .addReg(varEnd).addMBB(entryBB); |
| 7873 | BuildMI(BB, dl, TII->get(ARM::PHI), srcPhi) |
| 7874 | .addReg(srcLoop).addMBB(loopMBB) |
| 7875 | .addReg(src).addMBB(entryBB); |
| 7876 | BuildMI(BB, dl, TII->get(ARM::PHI), destPhi) |
| 7877 | .addReg(destLoop).addMBB(loopMBB) |
| 7878 | .addReg(dest).addMBB(entryBB); |
| 7879 | |
| 7880 | // [scratch, srcLoop] = LDR_POST(srcPhi, UnitSize) |
| 7881 | // [destLoop] = STR_POST(scratch, destPhi, UnitSiz) |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7882 | unsigned scratch = MRI.createVirtualRegister(IsNeon ? VecTRC : TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7883 | emitPostLd(BB, BB->end(), TII, dl, UnitSize, scratch, srcPhi, srcLoop, |
| 7884 | IsThumb1, IsThumb2); |
| 7885 | emitPostSt(BB, BB->end(), TII, dl, UnitSize, scratch, destPhi, destLoop, |
| 7886 | IsThumb1, IsThumb2); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7887 | |
| 7888 | // Decrement loop variable by UnitSize. |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7889 | if (IsThumb1) { |
| 7890 | MachineInstrBuilder MIB = |
| 7891 | BuildMI(*BB, BB->end(), dl, TII->get(ARM::tSUBi8), varLoop); |
| 7892 | MIB = AddDefaultT1CC(MIB); |
| 7893 | MIB.addReg(varPhi).addImm(UnitSize); |
| 7894 | AddDefaultPred(MIB); |
| 7895 | } else { |
| 7896 | MachineInstrBuilder MIB = |
| 7897 | BuildMI(*BB, BB->end(), dl, |
| 7898 | TII->get(IsThumb2 ? ARM::t2SUBri : ARM::SUBri), varLoop); |
| 7899 | AddDefaultCC(AddDefaultPred(MIB.addReg(varPhi).addImm(UnitSize))); |
| 7900 | MIB->getOperand(5).setReg(ARM::CPSR); |
| 7901 | MIB->getOperand(5).setIsDef(true); |
| 7902 | } |
| 7903 | BuildMI(*BB, BB->end(), dl, |
| 7904 | TII->get(IsThumb1 ? ARM::tBcc : IsThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 7905 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7906 | |
| 7907 | // loopMBB can loop back to loopMBB or fall through to exitMBB. |
| 7908 | BB->addSuccessor(loopMBB); |
| 7909 | BB->addSuccessor(exitMBB); |
| 7910 | |
| 7911 | // Add epilogue to handle BytesLeft. |
| 7912 | BB = exitMBB; |
| 7913 | MachineInstr *StartOfExit = exitMBB->begin(); |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7914 | |
| 7915 | // [scratch, srcOut] = LDRB_POST(srcLoop, 1) |
| 7916 | // [destOut] = STRB_POST(scratch, destLoop, 1) |
| 7917 | unsigned srcIn = srcLoop; |
| 7918 | unsigned destIn = destLoop; |
| 7919 | for (unsigned i = 0; i < BytesLeft; i++) { |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7920 | unsigned srcOut = MRI.createVirtualRegister(TRC); |
| 7921 | unsigned destOut = MRI.createVirtualRegister(TRC); |
| 7922 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| Manman Ren | b504f49 | 2013-10-29 22:27:32 +0000 | [diff] [blame] | 7923 | emitPostLd(BB, StartOfExit, TII, dl, 1, scratch, srcIn, srcOut, |
| 7924 | IsThumb1, IsThumb2); |
| 7925 | emitPostSt(BB, StartOfExit, TII, dl, 1, scratch, destIn, destOut, |
| 7926 | IsThumb1, IsThumb2); |
| David Peixotto | b0653e53 | 2013-10-24 16:39:36 +0000 | [diff] [blame] | 7927 | srcIn = srcOut; |
| 7928 | destIn = destOut; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 7929 | } |
| 7930 | |
| 7931 | MI->eraseFromParent(); // The instruction is gone now. |
| 7932 | return BB; |
| 7933 | } |
| 7934 | |
| Jim Grosbach | 8f9a3ac | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 7935 | MachineBasicBlock * |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7936 | ARMTargetLowering::EmitLowered__chkstk(MachineInstr *MI, |
| 7937 | MachineBasicBlock *MBB) const { |
| 7938 | const TargetMachine &TM = getTargetMachine(); |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 7939 | const TargetInstrInfo &TII = *Subtarget->getInstrInfo(); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7940 | DebugLoc DL = MI->getDebugLoc(); |
| 7941 | |
| 7942 | assert(Subtarget->isTargetWindows() && |
| 7943 | "__chkstk is only supported on Windows"); |
| 7944 | assert(Subtarget->isThumb2() && "Windows on ARM requires Thumb-2 mode"); |
| 7945 | |
| 7946 | // __chkstk takes the number of words to allocate on the stack in R4, and |
| 7947 | // returns the stack adjustment in number of bytes in R4. This will not |
| 7948 | // clober any other registers (other than the obvious lr). |
| 7949 | // |
| 7950 | // Although, technically, IP should be considered a register which may be |
| 7951 | // clobbered, the call itself will not touch it. Windows on ARM is a pure |
| 7952 | // thumb-2 environment, so there is no interworking required. As a result, we |
| 7953 | // do not expect a veneer to be emitted by the linker, clobbering IP. |
| 7954 | // |
| Alp Toker | 1d099d9 | 2014-06-19 19:41:26 +0000 | [diff] [blame] | 7955 | // 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] | 7956 | // required, again, ensuring that IP is not clobbered. |
| 7957 | // |
| 7958 | // Finally, although some linkers may theoretically provide a trampoline for |
| 7959 | // out of range calls (which is quite common due to a 32M range limitation of |
| 7960 | // branches for Thumb), we can generate the long-call version via |
| 7961 | // -mcmodel=large, alleviating the need for the trampoline which may clobber |
| 7962 | // IP. |
| 7963 | |
| 7964 | switch (TM.getCodeModel()) { |
| 7965 | case CodeModel::Small: |
| 7966 | case CodeModel::Medium: |
| 7967 | case CodeModel::Default: |
| 7968 | case CodeModel::Kernel: |
| 7969 | BuildMI(*MBB, MI, DL, TII.get(ARM::tBL)) |
| 7970 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 7971 | .addExternalSymbol("__chkstk") |
| 7972 | .addReg(ARM::R4, RegState::Implicit | RegState::Kill) |
| 7973 | .addReg(ARM::R4, RegState::Implicit | RegState::Define) |
| 7974 | .addReg(ARM::R12, RegState::Implicit | RegState::Define | RegState::Dead); |
| 7975 | break; |
| 7976 | case CodeModel::Large: |
| 7977 | case CodeModel::JITDefault: { |
| 7978 | MachineRegisterInfo &MRI = MBB->getParent()->getRegInfo(); |
| 7979 | unsigned Reg = MRI.createVirtualRegister(&ARM::rGPRRegClass); |
| 7980 | |
| 7981 | BuildMI(*MBB, MI, DL, TII.get(ARM::t2MOVi32imm), Reg) |
| 7982 | .addExternalSymbol("__chkstk"); |
| 7983 | BuildMI(*MBB, MI, DL, TII.get(ARM::tBLXr)) |
| 7984 | .addImm((unsigned)ARMCC::AL).addReg(0) |
| 7985 | .addReg(Reg, RegState::Kill) |
| 7986 | .addReg(ARM::R4, RegState::Implicit | RegState::Kill) |
| 7987 | .addReg(ARM::R4, RegState::Implicit | RegState::Define) |
| 7988 | .addReg(ARM::R12, RegState::Implicit | RegState::Define | RegState::Dead); |
| 7989 | break; |
| 7990 | } |
| 7991 | } |
| 7992 | |
| 7993 | AddDefaultCC(AddDefaultPred(BuildMI(*MBB, MI, DL, TII.get(ARM::t2SUBrr), |
| 7994 | ARM::SP) |
| Saleem Abdulrasool | c4e0028 | 2014-07-19 01:29:51 +0000 | [diff] [blame] | 7995 | .addReg(ARM::SP).addReg(ARM::R4))); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 7996 | |
| 7997 | MI->eraseFromParent(); |
| 7998 | return MBB; |
| 7999 | } |
| 8000 | |
| 8001 | MachineBasicBlock * |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 8002 | ARMTargetLowering::EmitLowered__dbzchk(MachineInstr *MI, |
| 8003 | MachineBasicBlock *MBB) const { |
| 8004 | DebugLoc DL = MI->getDebugLoc(); |
| 8005 | MachineFunction *MF = MBB->getParent(); |
| 8006 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| 8007 | |
| 8008 | MachineBasicBlock *ContBB = MF->CreateMachineBasicBlock(); |
| 8009 | MF->push_back(ContBB); |
| 8010 | ContBB->splice(ContBB->begin(), MBB, |
| 8011 | std::next(MachineBasicBlock::iterator(MI)), MBB->end()); |
| 8012 | MBB->addSuccessor(ContBB); |
| 8013 | |
| 8014 | MachineBasicBlock *TrapBB = MF->CreateMachineBasicBlock(); |
| 8015 | MF->push_back(TrapBB); |
| 8016 | BuildMI(TrapBB, DL, TII->get(ARM::t2UDF)).addImm(249); |
| 8017 | MBB->addSuccessor(TrapBB); |
| 8018 | |
| 8019 | BuildMI(*MBB, MI, DL, TII->get(ARM::tCBZ)) |
| 8020 | .addReg(MI->getOperand(0).getReg()) |
| 8021 | .addMBB(TrapBB); |
| 8022 | |
| 8023 | MI->eraseFromParent(); |
| 8024 | return ContBB; |
| 8025 | } |
| 8026 | |
| 8027 | MachineBasicBlock * |
| Evan Cheng | 29cfb67 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 8028 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
| Dan Gohman | 25c1653 | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 8029 | MachineBasicBlock *BB) const { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 8030 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| Dale Johannesen | 7647da6 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 8031 | DebugLoc dl = MI->getDebugLoc(); |
| Jim Grosbach | 57ccc19 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 8032 | bool isThumb2 = Subtarget->isThumb2(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8033 | switch (MI->getOpcode()) { |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8034 | default: { |
| Jim Grosbach | 5c4e99f | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 8035 | MI->dump(); |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 8036 | llvm_unreachable("Unexpected instr type to insert"); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8037 | } |
| Jim Grosbach | 9c0b86a | 2011-09-16 21:55:56 +0000 | [diff] [blame] | 8038 | // The Thumb2 pre-indexed stores have the same MI operands, they just |
| 8039 | // define them differently in the .td files from the isel patterns, so |
| 8040 | // they need pseudos. |
| 8041 | case ARM::t2STR_preidx: |
| 8042 | MI->setDesc(TII->get(ARM::t2STR_PRE)); |
| 8043 | return BB; |
| 8044 | case ARM::t2STRB_preidx: |
| 8045 | MI->setDesc(TII->get(ARM::t2STRB_PRE)); |
| 8046 | return BB; |
| 8047 | case ARM::t2STRH_preidx: |
| 8048 | MI->setDesc(TII->get(ARM::t2STRH_PRE)); |
| 8049 | return BB; |
| 8050 | |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 8051 | case ARM::STRi_preidx: |
| 8052 | case ARM::STRBi_preidx: { |
| Jim Grosbach | 5e80abb | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 8053 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 8054 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 8055 | // Decode the offset. |
| 8056 | unsigned Offset = MI->getOperand(4).getImm(); |
| 8057 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 8058 | Offset = ARM_AM::getAM2Offset(Offset); |
| 8059 | if (isSub) |
| 8060 | Offset = -Offset; |
| 8061 | |
| Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 8062 | MachineMemOperand *MMO = *MI->memoperands_begin(); |
| Benjamin Kramer | 61a1ff5 | 2011-08-27 17:36:14 +0000 | [diff] [blame] | 8063 | BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 8064 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 8065 | .addOperand(MI->getOperand(1)) // Rt |
| 8066 | .addOperand(MI->getOperand(2)) // Rn |
| 8067 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 8068 | .addOperand(MI->getOperand(5)) // pred |
| Jim Grosbach | f402f69 | 2011-08-12 21:02:34 +0000 | [diff] [blame] | 8069 | .addOperand(MI->getOperand(6)) |
| 8070 | .addMemOperand(MMO); |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 8071 | MI->eraseFromParent(); |
| 8072 | return BB; |
| 8073 | } |
| 8074 | case ARM::STRr_preidx: |
| Jim Grosbach | d886f8c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 8075 | case ARM::STRBr_preidx: |
| 8076 | case ARM::STRH_preidx: { |
| 8077 | unsigned NewOpc; |
| 8078 | switch (MI->getOpcode()) { |
| 8079 | default: llvm_unreachable("unexpected opcode!"); |
| 8080 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 8081 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 8082 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 8083 | } |
| Jim Grosbach | f0c95ca | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 8084 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 8085 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 8086 | MIB.addOperand(MI->getOperand(i)); |
| 8087 | MI->eraseFromParent(); |
| 8088 | return BB; |
| 8089 | } |
| Eli Friedman | c3f9c4a | 2011-08-31 00:31:29 +0000 | [diff] [blame] | 8090 | |
| Evan Cheng | bb2af35 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 8091 | case ARM::tMOVCCr_pseudo: { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8092 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 8093 | // diamond control-flow pattern. The incoming instruction knows the |
| 8094 | // destination vreg to set, the condition code register to branch on, the |
| 8095 | // true/false values to select between, and a branch opcode to use. |
| 8096 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 8097 | MachineFunction::iterator It = ++BB->getIterator(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8098 | |
| 8099 | // thisMBB: |
| 8100 | // ... |
| 8101 | // TrueVal = ... |
| 8102 | // cmpTY ccX, r1, r2 |
| 8103 | // bCC copy1MBB |
| 8104 | // fallthrough --> copy0MBB |
| 8105 | MachineBasicBlock *thisMBB = BB; |
| Dan Gohman | 3b46030 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 8106 | MachineFunction *F = BB->getParent(); |
| 8107 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 8108 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
| Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 8109 | F->insert(It, copy0MBB); |
| 8110 | F->insert(It, sinkMBB); |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8111 | |
| 8112 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 8113 | sinkMBB->splice(sinkMBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8114 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8115 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 8116 | |
| Dan Gohman | f4f0410 | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 8117 | BB->addSuccessor(copy0MBB); |
| 8118 | BB->addSuccessor(sinkMBB); |
| Dan Gohman | 1220564 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 8119 | |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8120 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 8121 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 8122 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8123 | // copy0MBB: |
| 8124 | // %FalseValue = ... |
| 8125 | // # fallthrough to sinkMBB |
| 8126 | BB = copy0MBB; |
| 8127 | |
| 8128 | // Update machine-CFG edges |
| 8129 | BB->addSuccessor(sinkMBB); |
| 8130 | |
| 8131 | // sinkMBB: |
| 8132 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 8133 | // ... |
| 8134 | BB = sinkMBB; |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8135 | BuildMI(*BB, BB->begin(), dl, |
| 8136 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8137 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 8138 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 8139 | |
| Dan Gohman | 3439629 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 8140 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8141 | return BB; |
| 8142 | } |
| Evan Cheng | b972e56 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 8143 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 8144 | case ARM::BCCi64: |
| 8145 | case ARM::BCCZi64: { |
| Bob Wilson | 36be00c | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 8146 | // If there is an unconditional branch to the other successor, remove it. |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8147 | BB->erase(std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Andrew Trick | 5eb0a30 | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 8148 | |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 8149 | // Compare both parts that make up the double comparison separately for |
| 8150 | // equality. |
| 8151 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 8152 | |
| 8153 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 8154 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 8155 | if (RHSisZero) { |
| 8156 | AddDefaultPred(BuildMI(BB, dl, |
| 8157 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 8158 | .addReg(LHS1).addImm(0)); |
| 8159 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 8160 | .addReg(LHS2).addImm(0) |
| 8161 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 8162 | } else { |
| 8163 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 8164 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 8165 | AddDefaultPred(BuildMI(BB, dl, |
| 8166 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 8167 | .addReg(LHS1).addReg(RHS1)); |
| 8168 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 8169 | .addReg(LHS2).addReg(RHS2) |
| 8170 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 8171 | } |
| 8172 | |
| 8173 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 8174 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 8175 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 8176 | std::swap(destMBB, exitMBB); |
| 8177 | |
| 8178 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 8179 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| Owen Anderson | 29cfe6c | 2011-09-09 21:48:23 +0000 | [diff] [blame] | 8180 | if (isThumb2) |
| 8181 | AddDefaultPred(BuildMI(BB, dl, TII->get(ARM::t2B)).addMBB(exitMBB)); |
| 8182 | else |
| 8183 | BuildMI(BB, dl, TII->get(ARM::B)) .addMBB(exitMBB); |
| Evan Cheng | 0cc4ad9 | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 8184 | |
| 8185 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 8186 | return BB; |
| 8187 | } |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8188 | |
| Bill Wendling | f7f223f | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 8189 | case ARM::Int_eh_sjlj_setjmp: |
| 8190 | case ARM::Int_eh_sjlj_setjmp_nofp: |
| 8191 | case ARM::tInt_eh_sjlj_setjmp: |
| 8192 | case ARM::t2Int_eh_sjlj_setjmp: |
| 8193 | case ARM::t2Int_eh_sjlj_setjmp_nofp: |
| Matthias Braun | 3cd00c1 | 2015-07-16 22:34:16 +0000 | [diff] [blame] | 8194 | return BB; |
| 8195 | |
| 8196 | case ARM::Int_eh_sjlj_setup_dispatch: |
| Bill Wendling | f7f223f | 2011-10-17 20:37:20 +0000 | [diff] [blame] | 8197 | EmitSjLjDispatchBlock(MI, BB); |
| 8198 | return BB; |
| 8199 | |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8200 | case ARM::ABS: |
| 8201 | case ARM::t2ABS: { |
| 8202 | // To insert an ABS instruction, we have to insert the |
| 8203 | // diamond control-flow pattern. The incoming instruction knows the |
| 8204 | // source vreg to test against 0, the destination vreg to set, |
| 8205 | // the condition code register to branch on, the |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8206 | // true/false values to select between, and a branch opcode to use. |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8207 | // It transforms |
| 8208 | // V1 = ABS V0 |
| 8209 | // into |
| 8210 | // V2 = MOVS V0 |
| 8211 | // BCC (branch to SinkBB if V0 >= 0) |
| 8212 | // RSBBB: V3 = RSBri V2, 0 (compute ABS if V2 < 0) |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8213 | // SinkBB: V1 = PHI(V2, V3) |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8214 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| Duncan P. N. Exon Smith | 9f9559e | 2015-10-19 23:25:57 +0000 | [diff] [blame] | 8215 | MachineFunction::iterator BBI = ++BB->getIterator(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8216 | MachineFunction *Fn = BB->getParent(); |
| 8217 | MachineBasicBlock *RSBBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 8218 | MachineBasicBlock *SinkBB = Fn->CreateMachineBasicBlock(LLVM_BB); |
| 8219 | Fn->insert(BBI, RSBBB); |
| 8220 | Fn->insert(BBI, SinkBB); |
| 8221 | |
| 8222 | unsigned int ABSSrcReg = MI->getOperand(1).getReg(); |
| 8223 | unsigned int ABSDstReg = MI->getOperand(0).getReg(); |
| Pete Cooper | 5111881 | 2015-04-30 22:15:59 +0000 | [diff] [blame] | 8224 | bool ABSSrcKIll = MI->getOperand(1).isKill(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8225 | bool isThumb2 = Subtarget->isThumb2(); |
| 8226 | MachineRegisterInfo &MRI = Fn->getRegInfo(); |
| 8227 | // In Thumb mode S must not be specified if source register is the SP or |
| 8228 | // PC and if destination register is the SP, so restrict register class |
| Craig Topper | 61e88f4 | 2014-11-21 05:58:21 +0000 | [diff] [blame] | 8229 | unsigned NewRsbDstReg = |
| 8230 | MRI.createVirtualRegister(isThumb2 ? &ARM::rGPRRegClass : &ARM::GPRRegClass); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8231 | |
| 8232 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 8233 | SinkBB->splice(SinkBB->begin(), BB, |
| Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 8234 | std::next(MachineBasicBlock::iterator(MI)), BB->end()); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8235 | SinkBB->transferSuccessorsAndUpdatePHIs(BB); |
| 8236 | |
| 8237 | BB->addSuccessor(RSBBB); |
| 8238 | BB->addSuccessor(SinkBB); |
| 8239 | |
| 8240 | // fall through to SinkMBB |
| 8241 | RSBBB->addSuccessor(SinkBB); |
| 8242 | |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8243 | // insert a cmp at the end of BB |
| Andrew Trick | bc32516 | 2012-07-18 18:34:24 +0000 | [diff] [blame] | 8244 | AddDefaultPred(BuildMI(BB, dl, |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8245 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 8246 | .addReg(ABSSrcReg).addImm(0)); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8247 | |
| 8248 | // 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] | 8249 | BuildMI(BB, dl, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8250 | TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)).addMBB(SinkBB) |
| 8251 | .addImm(ARMCC::getOppositeCondition(ARMCC::MI)).addReg(ARM::CPSR); |
| 8252 | |
| 8253 | // insert rsbri in RSBBB |
| 8254 | // Note: BCC and rsbri will be converted into predicated rsbmi |
| 8255 | // by if-conversion pass |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8256 | BuildMI(*RSBBB, RSBBB->begin(), dl, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8257 | TII->get(isThumb2 ? ARM::t2RSBri : ARM::RSBri), NewRsbDstReg) |
| Pete Cooper | 5111881 | 2015-04-30 22:15:59 +0000 | [diff] [blame] | 8258 | .addReg(ABSSrcReg, ABSSrcKIll ? RegState::Kill : 0) |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8259 | .addImm(0).addImm((unsigned)ARMCC::AL).addReg(0).addReg(0); |
| 8260 | |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8261 | // insert PHI in SinkBB, |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8262 | // reuse ABSDstReg to not change uses of ABS instruction |
| 8263 | BuildMI(*SinkBB, SinkBB->begin(), dl, |
| 8264 | TII->get(ARM::PHI), ABSDstReg) |
| 8265 | .addReg(NewRsbDstReg).addMBB(RSBBB) |
| Manman Ren | e0763c7 | 2012-06-15 21:32:12 +0000 | [diff] [blame] | 8266 | .addReg(ABSSrcReg).addMBB(BB); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8267 | |
| 8268 | // remove ABS instruction |
| Andrew Trick | 3f07c42 | 2011-10-18 18:40:53 +0000 | [diff] [blame] | 8269 | MI->eraseFromParent(); |
| Bill Wendling | a7d697e | 2011-10-10 22:59:55 +0000 | [diff] [blame] | 8270 | |
| 8271 | // return last added BB |
| 8272 | return SinkBB; |
| 8273 | } |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 8274 | case ARM::COPY_STRUCT_BYVAL_I32: |
| Manman Ren | 9f91116 | 2012-06-01 02:44:42 +0000 | [diff] [blame] | 8275 | ++NumLoopByVals; |
| Manman Ren | e873552 | 2012-06-01 19:33:18 +0000 | [diff] [blame] | 8276 | return EmitStructByval(MI, BB); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 8277 | case ARM::WIN__CHKSTK: |
| 8278 | return EmitLowered__chkstk(MI, BB); |
| Saleem Abdulrasool | fe83b50 | 2015-09-25 05:15:46 +0000 | [diff] [blame] | 8279 | case ARM::WIN__DBZCHK: |
| 8280 | return EmitLowered__dbzchk(MI, BB); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8281 | } |
| 8282 | } |
| 8283 | |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 8284 | /// \brief Attaches vregs to MEMCPY that it will use as scratch registers |
| 8285 | /// when it is expanded into LDM/STM. This is done as a post-isel lowering |
| 8286 | /// instead of as a custom inserter because we need the use list from the SDNode. |
| 8287 | static void attachMEMCPYScratchRegs(const ARMSubtarget *Subtarget, |
| 8288 | MachineInstr *MI, const SDNode *Node) { |
| 8289 | bool isThumb1 = Subtarget->isThumb1Only(); |
| 8290 | |
| 8291 | DebugLoc DL = MI->getDebugLoc(); |
| 8292 | MachineFunction *MF = MI->getParent()->getParent(); |
| 8293 | MachineRegisterInfo &MRI = MF->getRegInfo(); |
| 8294 | MachineInstrBuilder MIB(*MF, MI); |
| 8295 | |
| 8296 | // If the new dst/src is unused mark it as dead. |
| 8297 | if (!Node->hasAnyUseOfValue(0)) { |
| 8298 | MI->getOperand(0).setIsDead(true); |
| 8299 | } |
| 8300 | if (!Node->hasAnyUseOfValue(1)) { |
| 8301 | MI->getOperand(1).setIsDead(true); |
| 8302 | } |
| 8303 | |
| 8304 | // The MEMCPY both defines and kills the scratch registers. |
| 8305 | for (unsigned I = 0; I != MI->getOperand(4).getImm(); ++I) { |
| 8306 | unsigned TmpReg = MRI.createVirtualRegister(isThumb1 ? &ARM::tGPRRegClass |
| 8307 | : &ARM::GPRRegClass); |
| 8308 | MIB.addReg(TmpReg, RegState::Define|RegState::Dead); |
| 8309 | } |
| 8310 | } |
| 8311 | |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8312 | void ARMTargetLowering::AdjustInstrPostInstrSelection(MachineInstr *MI, |
| 8313 | SDNode *Node) const { |
| Scott Douglass | 953f908 | 2015-10-05 14:49:54 +0000 | [diff] [blame] | 8314 | if (MI->getOpcode() == ARM::MEMCPY) { |
| 8315 | attachMEMCPYScratchRegs(Subtarget, MI, Node); |
| 8316 | return; |
| 8317 | } |
| 8318 | |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 8319 | const MCInstrDesc *MCID = &MI->getDesc(); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8320 | // Adjust potentially 's' setting instructions after isel, i.e. ADC, SBC, RSB, |
| 8321 | // RSC. Coming out of isel, they have an implicit CPSR def, but the optional |
| 8322 | // operand is still set to noreg. If needed, set the optional operand's |
| 8323 | // register to CPSR, and remove the redundant implicit def. |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8324 | // |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8325 | // e.g. ADCS (..., CPSR<imp-def>) -> ADC (... opt:CPSR<def>). |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8326 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8327 | // Rename pseudo opcodes. |
| 8328 | unsigned NewOpc = convertAddSubFlagsOpcode(MI->getOpcode()); |
| 8329 | if (NewOpc) { |
| Eric Christopher | 1889fdc | 2015-01-29 00:19:39 +0000 | [diff] [blame] | 8330 | const ARMBaseInstrInfo *TII = Subtarget->getInstrInfo(); |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8331 | MCID = &TII->get(NewOpc); |
| 8332 | |
| 8333 | assert(MCID->getNumOperands() == MI->getDesc().getNumOperands() + 1 && |
| 8334 | "converted opcode should be the same except for cc_out"); |
| 8335 | |
| 8336 | MI->setDesc(*MCID); |
| 8337 | |
| 8338 | // Add the optional cc_out operand |
| 8339 | MI->addOperand(MachineOperand::CreateReg(0, /*isDef=*/true)); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8340 | } |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8341 | unsigned ccOutIdx = MCID->getNumOperands() - 1; |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8342 | |
| 8343 | // Any ARM instruction that sets the 's' bit should specify an optional |
| 8344 | // "cc_out" operand in the last operand position. |
| Evan Cheng | 7f8e563 | 2011-12-07 07:15:52 +0000 | [diff] [blame] | 8345 | if (!MI->hasOptionalDef() || !MCID->OpInfo[ccOutIdx].isOptionalDef()) { |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8346 | assert(!NewOpc && "Optional cc_out operand required"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8347 | return; |
| 8348 | } |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8349 | // Look for an implicit def of CPSR added by MachineInstr ctor. Remove it |
| 8350 | // since we already have an optional CPSR def. |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8351 | bool definesCPSR = false; |
| 8352 | bool deadCPSR = false; |
| Andrew Trick | 88b2450 | 2011-10-18 19:18:52 +0000 | [diff] [blame] | 8353 | for (unsigned i = MCID->getNumOperands(), e = MI->getNumOperands(); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8354 | i != e; ++i) { |
| 8355 | const MachineOperand &MO = MI->getOperand(i); |
| 8356 | if (MO.isReg() && MO.isDef() && MO.getReg() == ARM::CPSR) { |
| 8357 | definesCPSR = true; |
| 8358 | if (MO.isDead()) |
| 8359 | deadCPSR = true; |
| 8360 | MI->RemoveOperand(i); |
| 8361 | break; |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8362 | } |
| 8363 | } |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8364 | if (!definesCPSR) { |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8365 | assert(!NewOpc && "Optional cc_out operand required"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8366 | return; |
| 8367 | } |
| 8368 | assert(deadCPSR == !Node->hasAnyUseOfValue(1) && "inconsistent dead flag"); |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8369 | if (deadCPSR) { |
| 8370 | assert(!MI->getOperand(ccOutIdx).getReg() && |
| 8371 | "expect uninitialized optional cc_out operand"); |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8372 | return; |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8373 | } |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8374 | |
| Andrew Trick | 924123a | 2011-09-21 02:20:46 +0000 | [diff] [blame] | 8375 | // If this instruction was defined with an optional CPSR def and its dag node |
| 8376 | // had a live implicit CPSR def, then activate the optional CPSR def. |
| Andrew Trick | 8586e62 | 2011-09-20 03:17:40 +0000 | [diff] [blame] | 8377 | MachineOperand &MO = MI->getOperand(ccOutIdx); |
| 8378 | MO.setReg(ARM::CPSR); |
| 8379 | MO.setIsDef(true); |
| Evan Cheng | e6fba77 | 2011-08-30 19:09:48 +0000 | [diff] [blame] | 8380 | } |
| 8381 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 8382 | //===----------------------------------------------------------------------===// |
| 8383 | // ARM Optimization Hooks |
| 8384 | //===----------------------------------------------------------------------===// |
| 8385 | |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8386 | // Helper function that checks if N is a null or all ones constant. |
| 8387 | static inline bool isZeroOrAllOnes(SDValue N, bool AllOnes) { |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 8388 | return AllOnes ? isAllOnesConstant(N) : isNullConstant(N); |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8389 | } |
| 8390 | |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8391 | // Return true if N is conditionally 0 or all ones. |
| 8392 | // Detects these expressions where cc is an i1 value: |
| 8393 | // |
| 8394 | // (select cc 0, y) [AllOnes=0] |
| 8395 | // (select cc y, 0) [AllOnes=0] |
| 8396 | // (zext cc) [AllOnes=0] |
| 8397 | // (sext cc) [AllOnes=0/1] |
| 8398 | // (select cc -1, y) [AllOnes=1] |
| 8399 | // (select cc y, -1) [AllOnes=1] |
| 8400 | // |
| 8401 | // Invert is set when N is the null/all ones constant when CC is false. |
| 8402 | // OtherOp is set to the alternative value of N. |
| 8403 | static bool isConditionalZeroOrAllOnes(SDNode *N, bool AllOnes, |
| 8404 | SDValue &CC, bool &Invert, |
| 8405 | SDValue &OtherOp, |
| 8406 | SelectionDAG &DAG) { |
| 8407 | switch (N->getOpcode()) { |
| 8408 | default: return false; |
| 8409 | case ISD::SELECT: { |
| 8410 | CC = N->getOperand(0); |
| 8411 | SDValue N1 = N->getOperand(1); |
| 8412 | SDValue N2 = N->getOperand(2); |
| 8413 | if (isZeroOrAllOnes(N1, AllOnes)) { |
| 8414 | Invert = false; |
| 8415 | OtherOp = N2; |
| 8416 | return true; |
| 8417 | } |
| 8418 | if (isZeroOrAllOnes(N2, AllOnes)) { |
| 8419 | Invert = true; |
| 8420 | OtherOp = N1; |
| 8421 | return true; |
| 8422 | } |
| 8423 | return false; |
| 8424 | } |
| 8425 | case ISD::ZERO_EXTEND: |
| 8426 | // (zext cc) can never be the all ones value. |
| 8427 | if (AllOnes) |
| 8428 | return false; |
| 8429 | // Fall through. |
| 8430 | case ISD::SIGN_EXTEND: { |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8431 | SDLoc dl(N); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8432 | EVT VT = N->getValueType(0); |
| 8433 | CC = N->getOperand(0); |
| 8434 | if (CC.getValueType() != MVT::i1) |
| 8435 | return false; |
| 8436 | Invert = !AllOnes; |
| 8437 | if (AllOnes) |
| 8438 | // When looking for an AllOnes constant, N is an sext, and the 'other' |
| 8439 | // value is 0. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8440 | OtherOp = DAG.getConstant(0, dl, VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8441 | else if (N->getOpcode() == ISD::ZERO_EXTEND) |
| 8442 | // When looking for a 0 constant, N can be zext or sext. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8443 | OtherOp = DAG.getConstant(1, dl, VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8444 | else |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8445 | OtherOp = DAG.getConstant(APInt::getAllOnesValue(VT.getSizeInBits()), dl, |
| 8446 | VT); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8447 | return true; |
| 8448 | } |
| 8449 | } |
| 8450 | } |
| 8451 | |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8452 | // Combine a constant select operand into its use: |
| 8453 | // |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8454 | // (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 8455 | // (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 8456 | // (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) [AllOnes=1] |
| 8457 | // (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| 8458 | // (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] | 8459 | // |
| 8460 | // 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] | 8461 | // is null, or all ones when AllOnes is set. |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8462 | // |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8463 | // Also recognize sext/zext from i1: |
| 8464 | // |
| 8465 | // (add (zext cc), x) -> (select cc (add x, 1), x) |
| 8466 | // (add (sext cc), x) -> (select cc (add x, -1), x) |
| 8467 | // |
| 8468 | // These transformations eventually create predicated instructions. |
| 8469 | // |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8470 | // @param N The node to transform. |
| 8471 | // @param Slct The N operand that is a select. |
| 8472 | // @param OtherOp The other N operand (x above). |
| 8473 | // @param DCI Context. |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8474 | // @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] | 8475 | // @returns The new node, or SDValue() on failure. |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8476 | static |
| 8477 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8478 | TargetLowering::DAGCombinerInfo &DCI, |
| 8479 | bool AllOnes = false) { |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8480 | SelectionDAG &DAG = DCI.DAG; |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 8481 | EVT VT = N->getValueType(0); |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8482 | SDValue NonConstantVal; |
| 8483 | SDValue CCOp; |
| 8484 | bool SwapSelectOps; |
| 8485 | if (!isConditionalZeroOrAllOnes(Slct.getNode(), AllOnes, CCOp, SwapSelectOps, |
| 8486 | NonConstantVal, DAG)) |
| Jakob Stoklund Olesen | c1dee48 | 2012-08-17 16:59:09 +0000 | [diff] [blame] | 8487 | return SDValue(); |
| 8488 | |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8489 | // Slct is now know to be the desired identity constant when CC is true. |
| 8490 | SDValue TrueVal = OtherOp; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8491 | SDValue FalseVal = DAG.getNode(N->getOpcode(), SDLoc(N), VT, |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8492 | OtherOp, NonConstantVal); |
| 8493 | // Unless SwapSelectOps says CC should be false. |
| 8494 | if (SwapSelectOps) |
| 8495 | std::swap(TrueVal, FalseVal); |
| 8496 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8497 | return DAG.getNode(ISD::SELECT, SDLoc(N), VT, |
| Jakob Stoklund Olesen | dded061 | 2012-08-18 21:25:22 +0000 | [diff] [blame] | 8498 | CCOp, TrueVal, FalseVal); |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8499 | } |
| 8500 | |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8501 | // Attempt combineSelectAndUse on each operand of a commutative operator N. |
| 8502 | static |
| 8503 | SDValue combineSelectAndUseCommutative(SDNode *N, bool AllOnes, |
| 8504 | TargetLowering::DAGCombinerInfo &DCI) { |
| 8505 | SDValue N0 = N->getOperand(0); |
| 8506 | SDValue N1 = N->getOperand(1); |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8507 | if (N0.getNode()->hasOneUse()) |
| 8508 | if (SDValue Result = combineSelectAndUse(N, N0, N1, DCI, AllOnes)) |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8509 | return Result; |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8510 | if (N1.getNode()->hasOneUse()) |
| 8511 | if (SDValue Result = combineSelectAndUse(N, N1, N0, DCI, AllOnes)) |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8512 | return Result; |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8513 | return SDValue(); |
| 8514 | } |
| 8515 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8516 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8517 | // (only after legalization). |
| 8518 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 8519 | TargetLowering::DAGCombinerInfo &DCI, |
| 8520 | const ARMSubtarget *Subtarget) { |
| 8521 | |
| 8522 | // Only perform optimization if after legalize, and if NEON is available. We |
| 8523 | // also expected both operands to be BUILD_VECTORs. |
| 8524 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 8525 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 8526 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 8527 | return SDValue(); |
| 8528 | |
| 8529 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 8530 | EVT VT = N->getValueType(0); |
| 8531 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 8532 | return SDValue(); |
| 8533 | |
| 8534 | // Check that the vector operands are of the right form. |
| 8535 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 8536 | // operands, where N is the size of the formed vector. |
| 8537 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 8538 | // index such that we have a pair wise add pattern. |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8539 | |
| 8540 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
| Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 8541 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8542 | return SDValue(); |
| Bob Wilson | 4b12a11 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 8543 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 8544 | SDNode *V = Vec.getNode(); |
| 8545 | unsigned nextIndex = 0; |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8546 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8547 | // For each operands to the ADD which are BUILD_VECTORs, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8548 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 8549 | // the same vector and appropriate index. |
| 8550 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 8551 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 8552 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8553 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8554 | SDValue ExtVec0 = N0->getOperand(i); |
| 8555 | SDValue ExtVec1 = N1->getOperand(i); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8556 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8557 | // First operand is the vector, verify its the same. |
| 8558 | if (V != ExtVec0->getOperand(0).getNode() || |
| 8559 | V != ExtVec1->getOperand(0).getNode()) |
| 8560 | return SDValue(); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8561 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8562 | // Second is the constant, verify its correct. |
| 8563 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 8564 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8565 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8566 | // For the constant, we want to see all the even or all the odd. |
| 8567 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 8568 | || C1->getZExtValue() != nextIndex+1) |
| 8569 | return SDValue(); |
| 8570 | |
| 8571 | // Increment index. |
| 8572 | nextIndex+=2; |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8573 | } else |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8574 | return SDValue(); |
| 8575 | } |
| 8576 | |
| 8577 | // Create VPADDL node. |
| 8578 | SelectionDAG &DAG = DCI.DAG; |
| 8579 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8580 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8581 | SDLoc dl(N); |
| 8582 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8583 | // Build operand list. |
| 8584 | SmallVector<SDValue, 8> Ops; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8585 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, dl, |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 8586 | TLI.getPointerTy(DAG.getDataLayout()))); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8587 | |
| 8588 | // Input is the vector. |
| 8589 | Ops.push_back(Vec); |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8590 | |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8591 | // Get widened type and narrowed type. |
| 8592 | MVT widenType; |
| 8593 | unsigned numElem = VT.getVectorNumElements(); |
| Junmo Park | 1108ab0 | 2016-02-19 01:46:04 +0000 | [diff] [blame] | 8594 | |
| Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 8595 | EVT inputLaneType = Vec.getValueType().getVectorElementType(); |
| 8596 | switch (inputLaneType.getSimpleVT().SimpleTy) { |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8597 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 8598 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 8599 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 8600 | default: |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 8601 | llvm_unreachable("Invalid vector element type for padd optimization."); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8602 | } |
| 8603 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8604 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, widenType, Ops); |
| Silviu Baranga | a3106e6 | 2014-04-03 10:44:27 +0000 | [diff] [blame] | 8605 | unsigned ExtOp = VT.bitsGT(tmp.getValueType()) ? ISD::ANY_EXTEND : ISD::TRUNCATE; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8606 | return DAG.getNode(ExtOp, dl, VT, tmp); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8607 | } |
| 8608 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8609 | static SDValue findMUL_LOHI(SDValue V) { |
| 8610 | if (V->getOpcode() == ISD::UMUL_LOHI || |
| 8611 | V->getOpcode() == ISD::SMUL_LOHI) |
| 8612 | return V; |
| 8613 | return SDValue(); |
| 8614 | } |
| 8615 | |
| 8616 | static SDValue AddCombineTo64bitMLAL(SDNode *AddcNode, |
| 8617 | TargetLowering::DAGCombinerInfo &DCI, |
| 8618 | const ARMSubtarget *Subtarget) { |
| 8619 | |
| 8620 | if (Subtarget->isThumb1Only()) return SDValue(); |
| 8621 | |
| 8622 | // Only perform the checks after legalize when the pattern is available. |
| 8623 | if (DCI.isBeforeLegalize()) return SDValue(); |
| 8624 | |
| 8625 | // Look for multiply add opportunities. |
| 8626 | // The pattern is a ISD::UMUL_LOHI followed by two add nodes, where |
| 8627 | // each add nodes consumes a value from ISD::UMUL_LOHI and there is |
| 8628 | // a glue link from the first add to the second add. |
| 8629 | // If we find this pattern, we can replace the U/SMUL_LOHI, ADDC, and ADDE by |
| 8630 | // a S/UMLAL instruction. |
| Matthias Braun | 6091208 | 2015-05-20 18:40:06 +0000 | [diff] [blame] | 8631 | // UMUL_LOHI |
| 8632 | // / :lo \ :hi |
| 8633 | // / \ [no multiline comment] |
| 8634 | // loAdd -> ADDE | |
| 8635 | // \ :glue / |
| 8636 | // \ / |
| 8637 | // ADDC <- hiAdd |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8638 | // |
| 8639 | assert(AddcNode->getOpcode() == ISD::ADDC && "Expect an ADDC"); |
| 8640 | SDValue AddcOp0 = AddcNode->getOperand(0); |
| 8641 | SDValue AddcOp1 = AddcNode->getOperand(1); |
| 8642 | |
| 8643 | // Check if the two operands are from the same mul_lohi node. |
| 8644 | if (AddcOp0.getNode() == AddcOp1.getNode()) |
| 8645 | return SDValue(); |
| 8646 | |
| 8647 | assert(AddcNode->getNumValues() == 2 && |
| 8648 | AddcNode->getValueType(0) == MVT::i32 && |
| Michael Gottesman | b2a7056 | 2013-06-18 20:49:40 +0000 | [diff] [blame] | 8649 | "Expect ADDC with two result values. First: i32"); |
| 8650 | |
| 8651 | // Check that we have a glued ADDC node. |
| 8652 | if (AddcNode->getValueType(1) != MVT::Glue) |
| 8653 | return SDValue(); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8654 | |
| 8655 | // Check that the ADDC adds the low result of the S/UMUL_LOHI. |
| 8656 | if (AddcOp0->getOpcode() != ISD::UMUL_LOHI && |
| 8657 | AddcOp0->getOpcode() != ISD::SMUL_LOHI && |
| 8658 | AddcOp1->getOpcode() != ISD::UMUL_LOHI && |
| 8659 | AddcOp1->getOpcode() != ISD::SMUL_LOHI) |
| 8660 | return SDValue(); |
| 8661 | |
| 8662 | // Look for the glued ADDE. |
| 8663 | SDNode* AddeNode = AddcNode->getGluedUser(); |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8664 | if (!AddeNode) |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8665 | return SDValue(); |
| 8666 | |
| 8667 | // Make sure it is really an ADDE. |
| 8668 | if (AddeNode->getOpcode() != ISD::ADDE) |
| 8669 | return SDValue(); |
| 8670 | |
| 8671 | assert(AddeNode->getNumOperands() == 3 && |
| 8672 | AddeNode->getOperand(2).getValueType() == MVT::Glue && |
| 8673 | "ADDE node has the wrong inputs"); |
| 8674 | |
| 8675 | // Check for the triangle shape. |
| 8676 | SDValue AddeOp0 = AddeNode->getOperand(0); |
| 8677 | SDValue AddeOp1 = AddeNode->getOperand(1); |
| 8678 | |
| 8679 | // Make sure that the ADDE operands are not coming from the same node. |
| 8680 | if (AddeOp0.getNode() == AddeOp1.getNode()) |
| 8681 | return SDValue(); |
| 8682 | |
| 8683 | // Find the MUL_LOHI node walking up ADDE's operands. |
| 8684 | bool IsLeftOperandMUL = false; |
| 8685 | SDValue MULOp = findMUL_LOHI(AddeOp0); |
| 8686 | if (MULOp == SDValue()) |
| 8687 | MULOp = findMUL_LOHI(AddeOp1); |
| 8688 | else |
| 8689 | IsLeftOperandMUL = true; |
| 8690 | if (MULOp == SDValue()) |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8691 | return SDValue(); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8692 | |
| 8693 | // Figure out the right opcode. |
| 8694 | unsigned Opc = MULOp->getOpcode(); |
| 8695 | unsigned FinalOpc = (Opc == ISD::SMUL_LOHI) ? ARMISD::SMLAL : ARMISD::UMLAL; |
| 8696 | |
| 8697 | // Figure out the high and low input values to the MLAL node. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8698 | SDValue* HiAdd = nullptr; |
| 8699 | SDValue* LoMul = nullptr; |
| 8700 | SDValue* LowAdd = nullptr; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8701 | |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8702 | // Ensure that ADDE is from high result of ISD::SMUL_LOHI. |
| 8703 | if ((AddeOp0 != MULOp.getValue(1)) && (AddeOp1 != MULOp.getValue(1))) |
| 8704 | return SDValue(); |
| 8705 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8706 | if (IsLeftOperandMUL) |
| 8707 | HiAdd = &AddeOp1; |
| 8708 | else |
| 8709 | HiAdd = &AddeOp0; |
| 8710 | |
| 8711 | |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8712 | // Ensure that LoMul and LowAdd are taken from correct ISD::SMUL_LOHI node |
| 8713 | // whose low result is fed to the ADDC we are checking. |
| 8714 | |
| 8715 | if (AddcOp0 == MULOp.getValue(0)) { |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8716 | LoMul = &AddcOp0; |
| 8717 | LowAdd = &AddcOp1; |
| 8718 | } |
| Jyoti Allur | f1d7050 | 2015-01-23 09:10:03 +0000 | [diff] [blame] | 8719 | if (AddcOp1 == MULOp.getValue(0)) { |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8720 | LoMul = &AddcOp1; |
| 8721 | LowAdd = &AddcOp0; |
| 8722 | } |
| 8723 | |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 8724 | if (!LoMul) |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8725 | return SDValue(); |
| 8726 | |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8727 | // Create the merged node. |
| 8728 | SelectionDAG &DAG = DCI.DAG; |
| 8729 | |
| 8730 | // Build operand list. |
| 8731 | SmallVector<SDValue, 8> Ops; |
| 8732 | Ops.push_back(LoMul->getOperand(0)); |
| 8733 | Ops.push_back(LoMul->getOperand(1)); |
| 8734 | Ops.push_back(*LowAdd); |
| 8735 | Ops.push_back(*HiAdd); |
| 8736 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8737 | SDValue MLALNode = DAG.getNode(FinalOpc, SDLoc(AddcNode), |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 8738 | DAG.getVTList(MVT::i32, MVT::i32), Ops); |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 8739 | |
| 8740 | // Replace the ADDs' nodes uses by the MLA node's values. |
| 8741 | SDValue HiMLALResult(MLALNode.getNode(), 1); |
| 8742 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddeNode, 0), HiMLALResult); |
| 8743 | |
| 8744 | SDValue LoMLALResult(MLALNode.getNode(), 0); |
| 8745 | DAG.ReplaceAllUsesOfValueWith(SDValue(AddcNode, 0), LoMLALResult); |
| 8746 | |
| 8747 | // Return original node to notify the driver to stop replacing. |
| 8748 | SDValue resNode(AddcNode, 0); |
| 8749 | return resNode; |
| 8750 | } |
| 8751 | |
| 8752 | /// PerformADDCCombine - Target-specific dag combine transform from |
| 8753 | /// ISD::ADDC, ISD::ADDE, and ISD::MUL_LOHI to MLAL. |
| 8754 | static SDValue PerformADDCCombine(SDNode *N, |
| 8755 | TargetLowering::DAGCombinerInfo &DCI, |
| 8756 | const ARMSubtarget *Subtarget) { |
| 8757 | |
| 8758 | return AddCombineTo64bitMLAL(N, DCI, Subtarget); |
| 8759 | |
| 8760 | } |
| 8761 | |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8762 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 8763 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 8764 | /// called with the default operands, and if that fails, with commuted |
| 8765 | /// operands. |
| 8766 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8767 | TargetLowering::DAGCombinerInfo &DCI, |
| 8768 | const ARMSubtarget *Subtarget){ |
| 8769 | |
| 8770 | // Attempt to create vpaddl for this add. |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8771 | if (SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget)) |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8772 | return Result; |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 8773 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8774 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8775 | if (N0.getNode()->hasOneUse()) |
| 8776 | if (SDValue Result = combineSelectAndUse(N, N0, N1, DCI)) |
| 8777 | return Result; |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8778 | return SDValue(); |
| 8779 | } |
| 8780 | |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8781 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 8782 | /// |
| 8783 | static SDValue PerformADDCombine(SDNode *N, |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8784 | TargetLowering::DAGCombinerInfo &DCI, |
| 8785 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8786 | SDValue N0 = N->getOperand(0); |
| 8787 | SDValue N1 = N->getOperand(1); |
| 8788 | |
| 8789 | // First try with the default operand order. |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8790 | if (SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget)) |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8791 | return Result; |
| 8792 | |
| 8793 | // If that didn't work, try again with the operands commuted. |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 8794 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8795 | } |
| 8796 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8797 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8798 | /// |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8799 | static SDValue PerformSUBCombine(SDNode *N, |
| 8800 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 728eb29 | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 8801 | SDValue N0 = N->getOperand(0); |
| 8802 | SDValue N1 = N->getOperand(1); |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8803 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8804 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8805 | if (N1.getNode()->hasOneUse()) |
| 8806 | if (SDValue Result = combineSelectAndUse(N, N1, N0, DCI)) |
| 8807 | return Result; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 8808 | |
| Chris Lattner | 4147f08 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 8809 | return SDValue(); |
| 8810 | } |
| 8811 | |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8812 | /// PerformVMULCombine |
| 8813 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 8814 | /// special multiplier accumulator forwarding. |
| 8815 | /// vmul d3, d0, d2 |
| 8816 | /// vmla d3, d1, d2 |
| 8817 | /// is faster than |
| 8818 | /// vadd d3, d0, d1 |
| 8819 | /// vmul d3, d3, d2 |
| Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 8820 | // However, for (A + B) * (A + B), |
| 8821 | // vadd d2, d0, d1 |
| 8822 | // vmul d3, d0, d2 |
| 8823 | // vmla d3, d1, d2 |
| 8824 | // is slower than |
| 8825 | // vadd d2, d0, d1 |
| 8826 | // vmul d3, d2, d2 |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8827 | static SDValue PerformVMULCombine(SDNode *N, |
| 8828 | TargetLowering::DAGCombinerInfo &DCI, |
| 8829 | const ARMSubtarget *Subtarget) { |
| 8830 | if (!Subtarget->hasVMLxForwarding()) |
| 8831 | return SDValue(); |
| 8832 | |
| 8833 | SelectionDAG &DAG = DCI.DAG; |
| 8834 | SDValue N0 = N->getOperand(0); |
| 8835 | SDValue N1 = N->getOperand(1); |
| 8836 | unsigned Opcode = N0.getOpcode(); |
| 8837 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8838 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
| Chad Rosier | 2730162 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 8839 | Opcode = N1.getOpcode(); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8840 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 8841 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 8842 | return SDValue(); |
| 8843 | std::swap(N0, N1); |
| 8844 | } |
| 8845 | |
| Weiming Zhao | 2052f48 | 2013-09-25 23:12:06 +0000 | [diff] [blame] | 8846 | if (N0 == N1) |
| 8847 | return SDValue(); |
| 8848 | |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8849 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8850 | SDLoc DL(N); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8851 | SDValue N00 = N0->getOperand(0); |
| 8852 | SDValue N01 = N0->getOperand(1); |
| 8853 | return DAG.getNode(Opcode, DL, VT, |
| 8854 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 8855 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 8856 | } |
| 8857 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8858 | static SDValue PerformMULCombine(SDNode *N, |
| 8859 | TargetLowering::DAGCombinerInfo &DCI, |
| 8860 | const ARMSubtarget *Subtarget) { |
| 8861 | SelectionDAG &DAG = DCI.DAG; |
| 8862 | |
| 8863 | if (Subtarget->isThumb1Only()) |
| 8864 | return SDValue(); |
| 8865 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8866 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 8867 | return SDValue(); |
| 8868 | |
| 8869 | EVT VT = N->getValueType(0); |
| Evan Cheng | 38bf5ad | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 8870 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 8871 | return PerformVMULCombine(N, DCI, Subtarget); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8872 | if (VT != MVT::i32) |
| 8873 | return SDValue(); |
| 8874 | |
| 8875 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 8876 | if (!C) |
| 8877 | return SDValue(); |
| 8878 | |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8879 | int64_t MulAmt = C->getSExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 8880 | unsigned ShiftAmt = countTrailingZeros<uint64_t>(MulAmt); |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8881 | |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8882 | ShiftAmt = ShiftAmt & (32 - 1); |
| 8883 | SDValue V = N->getOperand(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8884 | SDLoc DL(N); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8885 | |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8886 | SDValue Res; |
| 8887 | MulAmt >>= ShiftAmt; |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8888 | |
| 8889 | if (MulAmt >= 0) { |
| 8890 | if (isPowerOf2_32(MulAmt - 1)) { |
| 8891 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 8892 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8893 | V, |
| 8894 | DAG.getNode(ISD::SHL, DL, VT, |
| 8895 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8896 | DAG.getConstant(Log2_32(MulAmt - 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8897 | MVT::i32))); |
| 8898 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 8899 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 8900 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8901 | DAG.getNode(ISD::SHL, DL, VT, |
| 8902 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8903 | DAG.getConstant(Log2_32(MulAmt + 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8904 | MVT::i32)), |
| 8905 | V); |
| 8906 | } else |
| 8907 | return SDValue(); |
| 8908 | } else { |
| 8909 | uint64_t MulAmtAbs = -MulAmt; |
| 8910 | if (isPowerOf2_32(MulAmtAbs + 1)) { |
| 8911 | // (mul x, -(2^N - 1)) => (sub x, (shl x, N)) |
| 8912 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 8913 | V, |
| 8914 | DAG.getNode(ISD::SHL, DL, VT, |
| 8915 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8916 | DAG.getConstant(Log2_32(MulAmtAbs + 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8917 | MVT::i32))); |
| 8918 | } else if (isPowerOf2_32(MulAmtAbs - 1)) { |
| 8919 | // (mul x, -(2^N + 1)) => - (add (shl x, N), x) |
| 8920 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 8921 | V, |
| 8922 | DAG.getNode(ISD::SHL, DL, VT, |
| 8923 | V, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8924 | DAG.getConstant(Log2_32(MulAmtAbs - 1), DL, |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8925 | MVT::i32))); |
| 8926 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8927 | DAG.getConstant(0, DL, MVT::i32), Res); |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8928 | |
| 8929 | } else |
| 8930 | return SDValue(); |
| 8931 | } |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8932 | |
| 8933 | if (ShiftAmt != 0) |
| Anton Korobeynikov | 3edd854d | 2012-03-19 19:19:50 +0000 | [diff] [blame] | 8934 | Res = DAG.getNode(ISD::SHL, DL, VT, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8935 | Res, DAG.getConstant(ShiftAmt, DL, MVT::i32)); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8936 | |
| 8937 | // Do not add new nodes to DAG combiner worklist. |
| Anton Korobeynikov | 4c719c4 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 8938 | DCI.CombineTo(N, Res, false); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 8939 | return SDValue(); |
| 8940 | } |
| 8941 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8942 | static SDValue PerformANDCombine(SDNode *N, |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8943 | TargetLowering::DAGCombinerInfo &DCI, |
| 8944 | const ARMSubtarget *Subtarget) { |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 8945 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8946 | // Attempt to use immediate-form VBIC |
| 8947 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8948 | SDLoc dl(N); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8949 | EVT VT = N->getValueType(0); |
| 8950 | SelectionDAG &DAG = DCI.DAG; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8951 | |
| Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8952 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8953 | return SDValue(); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8954 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8955 | APInt SplatBits, SplatUndef; |
| 8956 | unsigned SplatBitSize; |
| 8957 | bool HasAnyUndefs; |
| 8958 | if (BVN && |
| 8959 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 8960 | if (SplatBitSize <= 64) { |
| 8961 | EVT VbicVT; |
| 8962 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 8963 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 8964 | DAG, dl, VbicVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 8965 | OtherModImm); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8966 | if (Val.getNode()) { |
| 8967 | SDValue Input = |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8968 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8969 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8970 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8971 | } |
| 8972 | } |
| 8973 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8974 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8975 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8976 | // fold (and (select cc, -1, c), x) -> (select cc, x, (and, x, c)) |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 8977 | if (SDValue Result = combineSelectAndUseCommutative(N, true, DCI)) |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 8978 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 8979 | } |
| 8980 | |
| Owen Anderson | 30c4892 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 8981 | return SDValue(); |
| 8982 | } |
| 8983 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 8984 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 8985 | static SDValue PerformORCombine(SDNode *N, |
| 8986 | TargetLowering::DAGCombinerInfo &DCI, |
| 8987 | const ARMSubtarget *Subtarget) { |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8988 | // Attempt to use immediate-form VORR |
| 8989 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 8990 | SDLoc dl(N); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8991 | EVT VT = N->getValueType(0); |
| 8992 | SelectionDAG &DAG = DCI.DAG; |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 8993 | |
| Tanya Lattner | 266792a | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 8994 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 8995 | return SDValue(); |
| Andrew Trick | 0ed5778 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 8996 | |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 8997 | APInt SplatBits, SplatUndef; |
| 8998 | unsigned SplatBitSize; |
| 8999 | bool HasAnyUndefs; |
| 9000 | if (BVN && Subtarget->hasNEON() && |
| 9001 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 9002 | if (SplatBitSize <= 64) { |
| 9003 | EVT VorrVT; |
| 9004 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 9005 | SplatUndef.getZExtValue(), SplatBitSize, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9006 | DAG, dl, VorrVT, VT.is128BitVector(), |
| Owen Anderson | a407692 | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 9007 | OtherModImm); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 9008 | if (Val.getNode()) { |
| 9009 | SDValue Input = |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9010 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 9011 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9012 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
| Owen Anderson | bc9b31c | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 9013 | } |
| 9014 | } |
| 9015 | } |
| 9016 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9017 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 9018 | // fold (or (select cc, 0, c), x) -> (select cc, x, (or, x, c)) |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 9019 | if (SDValue Result = combineSelectAndUseCommutative(N, false, DCI)) |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 9020 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9021 | } |
| 9022 | |
| Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 9023 | // The code below optimizes (or (and X, Y), Z). |
| 9024 | // The AND operand needs to have a single user to make these optimizations |
| 9025 | // profitable. |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 9026 | SDValue N0 = N->getOperand(0); |
| Nadav Rotem | 3a94c54 | 2012-08-13 18:52:44 +0000 | [diff] [blame] | 9027 | if (N0.getOpcode() != ISD::AND || !N0.hasOneUse()) |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 9028 | return SDValue(); |
| 9029 | SDValue N1 = N->getOperand(1); |
| 9030 | |
| 9031 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 9032 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 9033 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 9034 | APInt SplatUndef; |
| 9035 | unsigned SplatBitSize; |
| 9036 | bool HasAnyUndefs; |
| 9037 | |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 9038 | APInt SplatBits0, SplatBits1; |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 9039 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 9040 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 9041 | // Ensure that the second operand of both ands are constants |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 9042 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| Saleem Abdulrasool | 0c2ee5a | 2013-07-30 04:43:08 +0000 | [diff] [blame] | 9043 | HasAnyUndefs) && !HasAnyUndefs) { |
| 9044 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 9045 | HasAnyUndefs) && !HasAnyUndefs) { |
| 9046 | // Ensure that the bit width of the constants are the same and that |
| 9047 | // the splat arguments are logical inverses as per the pattern we |
| 9048 | // are trying to simplify. |
| 9049 | if (SplatBits0.getBitWidth() == SplatBits1.getBitWidth() && |
| 9050 | SplatBits0 == ~SplatBits1) { |
| 9051 | // Canonicalize the vector type to make instruction selection |
| 9052 | // simpler. |
| 9053 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 9054 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 9055 | N0->getOperand(1), |
| 9056 | N0->getOperand(0), |
| 9057 | N1->getOperand(0)); |
| 9058 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 9059 | } |
| 9060 | } |
| Cameron Zwarich | 53dd03d | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 9061 | } |
| 9062 | } |
| 9063 | |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9064 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 9065 | // reasonable. |
| 9066 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9067 | // BFI is only available on V6T2+ |
| 9068 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 9069 | return SDValue(); |
| 9070 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9071 | SDLoc DL(N); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9072 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 9073 | // iff (val & mask) == val |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9074 | // |
| 9075 | // 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] | 9076 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 9077 | // && mask == ~mask2 |
| Sylvestre Ledru | 91ce36c | 2012-09-27 10:14:43 +0000 | [diff] [blame] | 9078 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 9079 | // && ~mask == mask2 |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9080 | // (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] | 9081 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9082 | if (VT != MVT::i32) |
| 9083 | return SDValue(); |
| 9084 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9085 | SDValue N00 = N0.getOperand(0); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9086 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9087 | // The value and the mask need to be constants so we can verify this is |
| 9088 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 9089 | // via a movt instruction, so don't use BFI in that case. |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9090 | SDValue MaskOp = N0.getOperand(1); |
| 9091 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 9092 | if (!MaskC) |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9093 | return SDValue(); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9094 | unsigned Mask = MaskC->getZExtValue(); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9095 | if (Mask == 0xffff) |
| 9096 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9097 | SDValue Res; |
| 9098 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9099 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 9100 | if (N1C) { |
| 9101 | unsigned Val = N1C->getZExtValue(); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 9102 | if ((Val & ~Mask) != Val) |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9103 | return SDValue(); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9104 | |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 9105 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9106 | Val >>= countTrailingZeros(~Mask); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9107 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9108 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9109 | DAG.getConstant(Val, DL, MVT::i32), |
| 9110 | DAG.getConstant(Mask, DL, MVT::i32)); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 9111 | |
| 9112 | // Do not add new nodes to DAG combiner worklist. |
| 9113 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9114 | return SDValue(); |
| Evan Cheng | 3434575 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 9115 | } |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9116 | } else if (N1.getOpcode() == ISD::AND) { |
| 9117 | // 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] | 9118 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 9119 | if (!N11C) |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9120 | return SDValue(); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9121 | unsigned Mask2 = N11C->getZExtValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9122 | |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 9123 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 9124 | // as is to match. |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9125 | if (ARM::isBitFieldInvertedMask(Mask) && |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 9126 | (Mask == ~Mask2)) { |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9127 | // The pack halfword instruction works better for masks that fit it, |
| 9128 | // so use that when it's available. |
| 9129 | if (Subtarget->hasT2ExtractPack() && |
| 9130 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 9131 | return SDValue(); |
| 9132 | // 2a |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9133 | unsigned amt = countTrailingZeros(Mask2); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9134 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9135 | DAG.getConstant(amt, DL, MVT::i32)); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9136 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9137 | DAG.getConstant(Mask, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9138 | // Do not add new nodes to DAG combiner worklist. |
| 9139 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9140 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9141 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
| Eric Christopher | d553096 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 9142 | (~Mask == Mask2)) { |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9143 | // The pack halfword instruction works better for masks that fit it, |
| 9144 | // so use that when it's available. |
| 9145 | if (Subtarget->hasT2ExtractPack() && |
| 9146 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 9147 | return SDValue(); |
| 9148 | // 2b |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9149 | unsigned lsb = countTrailingZeros(Mask); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9150 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9151 | DAG.getConstant(lsb, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9152 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9153 | DAG.getConstant(Mask2, DL, MVT::i32)); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9154 | // Do not add new nodes to DAG combiner worklist. |
| 9155 | DCI.CombineTo(N, Res, false); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9156 | return SDValue(); |
| Jim Grosbach | b97e2bb | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 9157 | } |
| 9158 | } |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9159 | |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9160 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 9161 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 9162 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 9163 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 9164 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 9165 | SDValue ShAmt = N00.getOperand(1); |
| 9166 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9167 | unsigned LSB = countTrailingZeros(Mask); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9168 | if (ShAmtC != LSB) |
| 9169 | return SDValue(); |
| 9170 | |
| 9171 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9172 | DAG.getConstant(~Mask, DL, MVT::i32)); |
| Evan Cheng | 2e51bb4 | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 9173 | |
| 9174 | // Do not add new nodes to DAG combiner worklist. |
| 9175 | DCI.CombineTo(N, Res, false); |
| 9176 | } |
| 9177 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 9178 | return SDValue(); |
| 9179 | } |
| 9180 | |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9181 | static SDValue PerformXORCombine(SDNode *N, |
| 9182 | TargetLowering::DAGCombinerInfo &DCI, |
| 9183 | const ARMSubtarget *Subtarget) { |
| 9184 | EVT VT = N->getValueType(0); |
| 9185 | SelectionDAG &DAG = DCI.DAG; |
| 9186 | |
| 9187 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 9188 | return SDValue(); |
| 9189 | |
| 9190 | if (!Subtarget->isThumb1Only()) { |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 9191 | // fold (xor (select cc, 0, c), x) -> (select cc, x, (xor, x, c)) |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 9192 | if (SDValue Result = combineSelectAndUseCommutative(N, false, DCI)) |
| Jakob Stoklund Olesen | aab43db | 2012-08-18 21:25:16 +0000 | [diff] [blame] | 9193 | return Result; |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 9194 | } |
| 9195 | |
| 9196 | return SDValue(); |
| 9197 | } |
| 9198 | |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9199 | // ParseBFI - given a BFI instruction in N, extract the "from" value (Rn) and return it, |
| 9200 | // and fill in FromMask and ToMask with (consecutive) bits in "from" to be extracted and |
| 9201 | // their position in "to" (Rd). |
| 9202 | static SDValue ParseBFI(SDNode *N, APInt &ToMask, APInt &FromMask) { |
| 9203 | assert(N->getOpcode() == ARMISD::BFI); |
| Chad Rosier | 353d719 | 2015-12-21 18:08:05 +0000 | [diff] [blame] | 9204 | |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9205 | SDValue From = N->getOperand(1); |
| 9206 | ToMask = ~cast<ConstantSDNode>(N->getOperand(2))->getAPIntValue(); |
| 9207 | FromMask = APInt::getLowBitsSet(ToMask.getBitWidth(), ToMask.countPopulation()); |
| 9208 | |
| 9209 | // If the Base came from a SHR #C, we can deduce that it is really testing bit |
| 9210 | // #C in the base of the SHR. |
| 9211 | if (From->getOpcode() == ISD::SRL && |
| 9212 | isa<ConstantSDNode>(From->getOperand(1))) { |
| 9213 | APInt Shift = cast<ConstantSDNode>(From->getOperand(1))->getAPIntValue(); |
| 9214 | assert(Shift.getLimitedValue() < 32 && "Shift too large!"); |
| 9215 | FromMask <<= Shift.getLimitedValue(31); |
| 9216 | From = From->getOperand(0); |
| 9217 | } |
| 9218 | |
| 9219 | return From; |
| 9220 | } |
| 9221 | |
| 9222 | // If A and B contain one contiguous set of bits, does A | B == A . B? |
| 9223 | // |
| 9224 | // Neither A nor B must be zero. |
| 9225 | static bool BitsProperlyConcatenate(const APInt &A, const APInt &B) { |
| 9226 | unsigned LastActiveBitInA = A.countTrailingZeros(); |
| 9227 | unsigned FirstActiveBitInB = B.getBitWidth() - B.countLeadingZeros() - 1; |
| 9228 | return LastActiveBitInA - 1 == FirstActiveBitInB; |
| 9229 | } |
| 9230 | |
| 9231 | static SDValue FindBFIToCombineWith(SDNode *N) { |
| 9232 | // We have a BFI in N. Follow a possible chain of BFIs and find a BFI it can combine with, |
| 9233 | // if one exists. |
| 9234 | APInt ToMask, FromMask; |
| 9235 | SDValue From = ParseBFI(N, ToMask, FromMask); |
| 9236 | SDValue To = N->getOperand(0); |
| 9237 | |
| 9238 | // Now check for a compatible BFI to merge with. We can pass through BFIs that |
| 9239 | // aren't compatible, but not if they set the same bit in their destination as |
| 9240 | // we do (or that of any BFI we're going to combine with). |
| 9241 | SDValue V = To; |
| 9242 | APInt CombinedToMask = ToMask; |
| 9243 | while (V.getOpcode() == ARMISD::BFI) { |
| 9244 | APInt NewToMask, NewFromMask; |
| 9245 | SDValue NewFrom = ParseBFI(V.getNode(), NewToMask, NewFromMask); |
| 9246 | if (NewFrom != From) { |
| 9247 | // This BFI has a different base. Keep going. |
| 9248 | CombinedToMask |= NewToMask; |
| 9249 | V = V.getOperand(0); |
| 9250 | continue; |
| 9251 | } |
| 9252 | |
| 9253 | // Do the written bits conflict with any we've seen so far? |
| 9254 | if ((NewToMask & CombinedToMask).getBoolValue()) |
| 9255 | // Conflicting bits - bail out because going further is unsafe. |
| 9256 | return SDValue(); |
| 9257 | |
| 9258 | // Are the new bits contiguous when combined with the old bits? |
| 9259 | if (BitsProperlyConcatenate(ToMask, NewToMask) && |
| 9260 | BitsProperlyConcatenate(FromMask, NewFromMask)) |
| 9261 | return V; |
| 9262 | if (BitsProperlyConcatenate(NewToMask, ToMask) && |
| 9263 | BitsProperlyConcatenate(NewFromMask, FromMask)) |
| 9264 | return V; |
| Chad Rosier | 353d719 | 2015-12-21 18:08:05 +0000 | [diff] [blame] | 9265 | |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9266 | // We've seen a write to some bits, so track it. |
| 9267 | CombinedToMask |= NewToMask; |
| 9268 | // Keep going... |
| 9269 | V = V.getOperand(0); |
| 9270 | } |
| 9271 | |
| 9272 | return SDValue(); |
| 9273 | } |
| 9274 | |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9275 | static SDValue PerformBFICombine(SDNode *N, |
| 9276 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9277 | SDValue N1 = N->getOperand(1); |
| 9278 | if (N1.getOpcode() == ISD::AND) { |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9279 | // (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 9280 | // 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] | 9281 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 9282 | if (!N11C) |
| 9283 | return SDValue(); |
| Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 9284 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| Michael J. Spencer | df1ecbd7 | 2013-05-24 22:23:49 +0000 | [diff] [blame] | 9285 | unsigned LSB = countTrailingZeros(~InvMask); |
| 9286 | unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB; |
| Aaron Ballman | 0d6a010 | 2014-12-16 14:04:11 +0000 | [diff] [blame] | 9287 | assert(Width < |
| 9288 | static_cast<unsigned>(std::numeric_limits<unsigned>::digits) && |
| Michael Ilseman | addddc4 | 2014-12-15 18:48:43 +0000 | [diff] [blame] | 9289 | "undefined behavior"); |
| 9290 | unsigned Mask = (1u << Width) - 1; |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9291 | unsigned Mask2 = N11C->getZExtValue(); |
| Evan Cheng | 6d02d90 | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 9292 | if ((Mask & (~Mask2)) == 0) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9293 | return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0), |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9294 | N->getOperand(0), N1.getOperand(0), |
| 9295 | N->getOperand(2)); |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9296 | } else if (N->getOperand(0).getOpcode() == ARMISD::BFI) { |
| 9297 | // We have a BFI of a BFI. Walk up the BFI chain to see how long it goes. |
| 9298 | // Keep track of any consecutive bits set that all come from the same base |
| 9299 | // value. We can combine these together into a single BFI. |
| 9300 | SDValue CombineBFI = FindBFIToCombineWith(N); |
| 9301 | if (CombineBFI == SDValue()) |
| 9302 | return SDValue(); |
| 9303 | |
| 9304 | // We've found a BFI. |
| 9305 | APInt ToMask1, FromMask1; |
| 9306 | SDValue From1 = ParseBFI(N, ToMask1, FromMask1); |
| 9307 | |
| 9308 | APInt ToMask2, FromMask2; |
| Diego Novillo | 0767ae5 | 2015-11-11 16:39:22 +0000 | [diff] [blame] | 9309 | SDValue From2 = ParseBFI(CombineBFI.getNode(), ToMask2, FromMask2); |
| 9310 | assert(From1 == From2); |
| 9311 | (void)From2; |
| Chad Rosier | 353d719 | 2015-12-21 18:08:05 +0000 | [diff] [blame] | 9312 | |
| James Molloy | ce12c92 | 2015-11-11 15:40:40 +0000 | [diff] [blame] | 9313 | // First, unlink CombineBFI. |
| 9314 | DCI.DAG.ReplaceAllUsesWith(CombineBFI, CombineBFI.getOperand(0)); |
| 9315 | // Then create a new BFI, combining the two together. |
| 9316 | APInt NewFromMask = FromMask1 | FromMask2; |
| 9317 | APInt NewToMask = ToMask1 | ToMask2; |
| 9318 | |
| 9319 | EVT VT = N->getValueType(0); |
| 9320 | SDLoc dl(N); |
| 9321 | |
| 9322 | if (NewFromMask[0] == 0) |
| 9323 | From1 = DCI.DAG.getNode( |
| 9324 | ISD::SRL, dl, VT, From1, |
| 9325 | DCI.DAG.getConstant(NewFromMask.countTrailingZeros(), dl, VT)); |
| 9326 | return DCI.DAG.getNode(ARMISD::BFI, dl, VT, N->getOperand(0), From1, |
| 9327 | DCI.DAG.getConstant(~NewToMask, dl, VT)); |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 9328 | } |
| 9329 | return SDValue(); |
| 9330 | } |
| 9331 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9332 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 9333 | /// ARMISD::VMOVRRD. |
| 9334 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9335 | TargetLowering::DAGCombinerInfo &DCI, |
| 9336 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9337 | // vmovrrd(vmovdrr x, y) -> x,y |
| 9338 | SDValue InDouble = N->getOperand(0); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9339 | if (InDouble.getOpcode() == ARMISD::VMOVDRR && !Subtarget->isFPOnlySP()) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9340 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9341 | |
| 9342 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 9343 | SDNode *InNode = InDouble.getNode(); |
| 9344 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 9345 | InNode->getValueType(0) == MVT::f64 && |
| 9346 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 9347 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 9348 | // TODO: Should this be done for non-FrameIndex operands? |
| 9349 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 9350 | |
| 9351 | SelectionDAG &DAG = DCI.DAG; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9352 | SDLoc DL(LD); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9353 | SDValue BasePtr = LD->getBasePtr(); |
| 9354 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 9355 | LD->getPointerInfo(), LD->isVolatile(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 9356 | LD->isNonTemporal(), LD->isInvariant(), |
| 9357 | LD->getAlignment()); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9358 | |
| 9359 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9360 | DAG.getConstant(4, DL, MVT::i32)); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9361 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 9362 | LD->getPointerInfo(), LD->isVolatile(), |
| Pete Cooper | 82cd9e8 | 2011-11-08 18:42:53 +0000 | [diff] [blame] | 9363 | LD->isNonTemporal(), LD->isInvariant(), |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9364 | std::min(4U, LD->getAlignment() / 2)); |
| 9365 | |
| 9366 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 9367 | if (DCI.DAG.getDataLayout().isBigEndian()) |
| Christian Pirker | 762b2c6 | 2014-06-01 09:30:52 +0000 | [diff] [blame] | 9368 | std::swap (NewLD1, NewLD2); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9369 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| Cameron Zwarich | 6fe5c29 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 9370 | return Result; |
| 9371 | } |
| 9372 | |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9373 | return SDValue(); |
| 9374 | } |
| 9375 | |
| 9376 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 9377 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 9378 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 9379 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 9380 | SDValue Op0 = N->getOperand(0); |
| 9381 | SDValue Op1 = N->getOperand(1); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9382 | if (Op0.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9383 | Op0 = Op0.getOperand(0); |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9384 | if (Op1.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9385 | Op1 = Op1.getOperand(0); |
| 9386 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 9387 | Op0.getNode() == Op1.getNode() && |
| 9388 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9389 | return DAG.getNode(ISD::BITCAST, SDLoc(N), |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 9390 | N->getValueType(0), Op0.getOperand(0)); |
| 9391 | return SDValue(); |
| 9392 | } |
| 9393 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9394 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 9395 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 9396 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 9397 | /// directly into a VFP register. |
| 9398 | static bool hasNormalLoadOperand(SDNode *N) { |
| 9399 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 9400 | for (unsigned i = 0; i < NumElts; ++i) { |
| 9401 | SDNode *Elt = N->getOperand(i).getNode(); |
| 9402 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 9403 | return true; |
| 9404 | } |
| 9405 | return false; |
| 9406 | } |
| 9407 | |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9408 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 9409 | /// ISD::BUILD_VECTOR. |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9410 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 9411 | TargetLowering::DAGCombinerInfo &DCI, |
| 9412 | const ARMSubtarget *Subtarget) { |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9413 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 9414 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 9415 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 9416 | // 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] | 9417 | SelectionDAG &DAG = DCI.DAG; |
| Ahmed Bougacha | f8dfb47 | 2016-02-09 22:54:12 +0000 | [diff] [blame] | 9418 | if (N->getNumOperands() == 2) |
| 9419 | if (SDValue RV = PerformVMOVDRRCombine(N, DAG)) |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9420 | return RV; |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9421 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9422 | // Load i64 elements as f64 values so that type legalization does not split |
| 9423 | // them up into i32 values. |
| 9424 | EVT VT = N->getValueType(0); |
| 9425 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 9426 | return SDValue(); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9427 | SDLoc dl(N); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9428 | SmallVector<SDValue, 8> Ops; |
| 9429 | unsigned NumElts = VT.getVectorNumElements(); |
| 9430 | for (unsigned i = 0; i < NumElts; ++i) { |
| 9431 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 9432 | Ops.push_back(V); |
| 9433 | // Make the DAGCombiner fold the bitcast. |
| 9434 | DCI.AddToWorklist(V.getNode()); |
| 9435 | } |
| 9436 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| Craig Topper | 48d114b | 2014-04-26 18:35:24 +0000 | [diff] [blame] | 9437 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9438 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 9439 | } |
| 9440 | |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9441 | /// \brief Target-specific dag combine xforms for ARMISD::BUILD_VECTOR. |
| 9442 | static SDValue |
| 9443 | PerformARMBUILD_VECTORCombine(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 9444 | // ARMISD::BUILD_VECTOR is introduced when legalizing ISD::BUILD_VECTOR. |
| 9445 | // At that time, we may have inserted bitcasts from integer to float. |
| 9446 | // If these bitcasts have survived DAGCombine, change the lowering of this |
| 9447 | // BUILD_VECTOR in something more vector friendly, i.e., that does not |
| 9448 | // force to use floating point types. |
| 9449 | |
| 9450 | // Make sure we can change the type of the vector. |
| 9451 | // This is possible iff: |
| 9452 | // 1. The vector is only used in a bitcast to a integer type. I.e., |
| 9453 | // 1.1. Vector is used only once. |
| 9454 | // 1.2. Use is a bit convert to an integer type. |
| 9455 | // 2. The size of its operands are 32-bits (64-bits are not legal). |
| 9456 | EVT VT = N->getValueType(0); |
| 9457 | EVT EltVT = VT.getVectorElementType(); |
| 9458 | |
| 9459 | // Check 1.1. and 2. |
| 9460 | if (EltVT.getSizeInBits() != 32 || !N->hasOneUse()) |
| 9461 | return SDValue(); |
| 9462 | |
| 9463 | // By construction, the input type must be float. |
| 9464 | assert(EltVT == MVT::f32 && "Unexpected type!"); |
| 9465 | |
| 9466 | // Check 1.2. |
| 9467 | SDNode *Use = *N->use_begin(); |
| 9468 | if (Use->getOpcode() != ISD::BITCAST || |
| 9469 | Use->getValueType(0).isFloatingPoint()) |
| 9470 | return SDValue(); |
| 9471 | |
| 9472 | // Check profitability. |
| 9473 | // Model is, if more than half of the relevant operands are bitcast from |
| 9474 | // i32, turn the build_vector into a sequence of insert_vector_elt. |
| 9475 | // Relevant operands are everything that is not statically |
| 9476 | // (i.e., at compile time) bitcasted. |
| 9477 | unsigned NumOfBitCastedElts = 0; |
| 9478 | unsigned NumElts = VT.getVectorNumElements(); |
| 9479 | unsigned NumOfRelevantElts = NumElts; |
| 9480 | for (unsigned Idx = 0; Idx < NumElts; ++Idx) { |
| 9481 | SDValue Elt = N->getOperand(Idx); |
| 9482 | if (Elt->getOpcode() == ISD::BITCAST) { |
| 9483 | // Assume only bit cast to i32 will go away. |
| 9484 | if (Elt->getOperand(0).getValueType() == MVT::i32) |
| 9485 | ++NumOfBitCastedElts; |
| 9486 | } else if (Elt.getOpcode() == ISD::UNDEF || isa<ConstantSDNode>(Elt)) |
| 9487 | // Constants are statically casted, thus do not count them as |
| 9488 | // relevant operands. |
| 9489 | --NumOfRelevantElts; |
| 9490 | } |
| 9491 | |
| 9492 | // Check if more than half of the elements require a non-free bitcast. |
| 9493 | if (NumOfBitCastedElts <= NumOfRelevantElts / 2) |
| 9494 | return SDValue(); |
| 9495 | |
| 9496 | SelectionDAG &DAG = DCI.DAG; |
| 9497 | // Create the new vector type. |
| 9498 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 9499 | // Check if the type is legal. |
| 9500 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9501 | if (!TLI.isTypeLegal(VecVT)) |
| 9502 | return SDValue(); |
| 9503 | |
| 9504 | // Combine: |
| 9505 | // ARMISD::BUILD_VECTOR E1, E2, ..., EN. |
| 9506 | // => BITCAST INSERT_VECTOR_ELT |
| 9507 | // (INSERT_VECTOR_ELT (...), (BITCAST EN-1), N-1), |
| 9508 | // (BITCAST EN), N. |
| 9509 | SDValue Vec = DAG.getUNDEF(VecVT); |
| 9510 | SDLoc dl(N); |
| 9511 | for (unsigned Idx = 0 ; Idx < NumElts; ++Idx) { |
| 9512 | SDValue V = N->getOperand(Idx); |
| 9513 | if (V.getOpcode() == ISD::UNDEF) |
| 9514 | continue; |
| 9515 | if (V.getOpcode() == ISD::BITCAST && |
| 9516 | V->getOperand(0).getValueType() == MVT::i32) |
| 9517 | // Fold obvious case. |
| 9518 | V = V.getOperand(0); |
| 9519 | else { |
| Jim Grosbach | 1a59711 | 2014-04-03 23:43:18 +0000 | [diff] [blame] | 9520 | V = DAG.getNode(ISD::BITCAST, SDLoc(V), MVT::i32, V); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9521 | // Make the DAGCombiner fold the bitcasts. |
| 9522 | DCI.AddToWorklist(V.getNode()); |
| 9523 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9524 | SDValue LaneIdx = DAG.getConstant(Idx, dl, MVT::i32); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 9525 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, VecVT, Vec, V, LaneIdx); |
| 9526 | } |
| 9527 | Vec = DAG.getNode(ISD::BITCAST, dl, VT, Vec); |
| 9528 | // Make the DAGCombiner fold the bitcasts. |
| 9529 | DCI.AddToWorklist(Vec.getNode()); |
| 9530 | return Vec; |
| 9531 | } |
| 9532 | |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9533 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 9534 | /// ISD::INSERT_VECTOR_ELT. |
| 9535 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 9536 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9537 | // Bitcast an i64 load inserted into a vector to f64. |
| 9538 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 9539 | EVT VT = N->getValueType(0); |
| 9540 | SDNode *Elt = N->getOperand(1).getNode(); |
| 9541 | if (VT.getVectorElementType() != MVT::i64 || |
| 9542 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 9543 | return SDValue(); |
| 9544 | |
| 9545 | SelectionDAG &DAG = DCI.DAG; |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9546 | SDLoc dl(N); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 9547 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 9548 | VT.getVectorNumElements()); |
| 9549 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 9550 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 9551 | // Make the DAGCombiner fold the bitcasts. |
| 9552 | DCI.AddToWorklist(Vec.getNode()); |
| 9553 | DCI.AddToWorklist(V.getNode()); |
| 9554 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 9555 | Vec, V, N->getOperand(2)); |
| 9556 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
| Bob Wilson | cb6db98 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 9557 | } |
| 9558 | |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9559 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 9560 | /// ISD::VECTOR_SHUFFLE. |
| 9561 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 9562 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 9563 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 9564 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 9565 | // operands do not match the mask length, they are extended by concatenating |
| 9566 | // them with undef vectors. That is probably the right thing for other |
| 9567 | // targets, but for NEON it is better to concatenate two double-register |
| 9568 | // size vector operands into a single quad-register size vector. Do that |
| 9569 | // transformation here: |
| 9570 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 9571 | // shuffle(concat(v1, v2), undef) |
| 9572 | SDValue Op0 = N->getOperand(0); |
| 9573 | SDValue Op1 = N->getOperand(1); |
| 9574 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 9575 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 9576 | Op0.getNumOperands() != 2 || |
| 9577 | Op1.getNumOperands() != 2) |
| 9578 | return SDValue(); |
| 9579 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 9580 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 9581 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 9582 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 9583 | return SDValue(); |
| 9584 | // Skip the transformation if any of the types are illegal. |
| 9585 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9586 | EVT VT = N->getValueType(0); |
| 9587 | if (!TLI.isTypeLegal(VT) || |
| 9588 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 9589 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 9590 | return SDValue(); |
| 9591 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9592 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(N), VT, |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9593 | Op0.getOperand(0), Op1.getOperand(0)); |
| 9594 | // Translate the shuffle mask. |
| 9595 | SmallVector<int, 16> NewMask; |
| 9596 | unsigned NumElts = VT.getVectorNumElements(); |
| 9597 | unsigned HalfElts = NumElts/2; |
| 9598 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 9599 | for (unsigned n = 0; n < NumElts; ++n) { |
| 9600 | int MaskElt = SVN->getMaskElt(n); |
| 9601 | int NewElt = -1; |
| Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 9602 | if (MaskElt < (int)HalfElts) |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9603 | NewElt = MaskElt; |
| Bob Wilson | 6c55007 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 9604 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9605 | NewElt = HalfElts + MaskElt - NumElts; |
| 9606 | NewMask.push_back(NewElt); |
| 9607 | } |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9608 | return DAG.getVectorShuffle(VT, SDLoc(N), NewConcat, |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 9609 | DAG.getUNDEF(VT), NewMask.data()); |
| 9610 | } |
| 9611 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9612 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP, |
| 9613 | /// NEON load/store intrinsics, and generic vector load/stores, to merge |
| 9614 | /// base address updates. |
| 9615 | /// For generic load/stores, the memory type is assumed to be a vector. |
| 9616 | /// The caller is assumed to have checked legality. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9617 | static SDValue CombineBaseUpdate(SDNode *N, |
| 9618 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9619 | SelectionDAG &DAG = DCI.DAG; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9620 | const bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 9621 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9622 | const bool isStore = N->getOpcode() == ISD::STORE; |
| 9623 | const unsigned AddrOpIdx = ((isIntrinsic || isStore) ? 2 : 1); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9624 | SDValue Addr = N->getOperand(AddrOpIdx); |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9625 | MemSDNode *MemN = cast<MemSDNode>(N); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9626 | SDLoc dl(N); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9627 | |
| 9628 | // Search for a use of the address operand that is an increment. |
| 9629 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 9630 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 9631 | SDNode *User = *UI; |
| 9632 | if (User->getOpcode() != ISD::ADD || |
| 9633 | UI.getUse().getResNo() != Addr.getResNo()) |
| 9634 | continue; |
| 9635 | |
| 9636 | // Check that the add is independent of the load/store. Otherwise, folding |
| 9637 | // it would create a cycle. |
| 9638 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 9639 | continue; |
| 9640 | |
| 9641 | // Find the new opcode for the updating load/store. |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9642 | bool isLoadOp = true; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9643 | bool isLaneOp = false; |
| 9644 | unsigned NewOpc = 0; |
| 9645 | unsigned NumVecs = 0; |
| 9646 | if (isIntrinsic) { |
| 9647 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 9648 | switch (IntNo) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 9649 | default: llvm_unreachable("unexpected intrinsic for Neon base update"); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9650 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 9651 | NumVecs = 1; break; |
| 9652 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 9653 | NumVecs = 2; break; |
| 9654 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 9655 | NumVecs = 3; break; |
| 9656 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 9657 | NumVecs = 4; break; |
| 9658 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 9659 | NumVecs = 2; isLaneOp = true; break; |
| 9660 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 9661 | NumVecs = 3; isLaneOp = true; break; |
| 9662 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 9663 | NumVecs = 4; isLaneOp = true; break; |
| 9664 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9665 | NumVecs = 1; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9666 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9667 | NumVecs = 2; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9668 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9669 | NumVecs = 3; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9670 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9671 | NumVecs = 4; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9672 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9673 | NumVecs = 2; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9674 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9675 | NumVecs = 3; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9676 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9677 | NumVecs = 4; isLoadOp = false; isLaneOp = true; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9678 | } |
| 9679 | } else { |
| 9680 | isLaneOp = true; |
| 9681 | switch (N->getOpcode()) { |
| Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 9682 | default: llvm_unreachable("unexpected opcode for Neon base update"); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9683 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 9684 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 9685 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9686 | case ISD::LOAD: NewOpc = ARMISD::VLD1_UPD; |
| 9687 | NumVecs = 1; isLaneOp = false; break; |
| 9688 | case ISD::STORE: NewOpc = ARMISD::VST1_UPD; |
| 9689 | NumVecs = 1; isLaneOp = false; isLoadOp = false; break; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9690 | } |
| 9691 | } |
| 9692 | |
| 9693 | // Find the size of memory referenced by the load/store. |
| 9694 | EVT VecTy; |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9695 | if (isLoadOp) { |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9696 | VecTy = N->getValueType(0); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9697 | } else if (isIntrinsic) { |
| Renato Golin | 2a5c0a5 | 2015-02-04 10:11:59 +0000 | [diff] [blame] | 9698 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9699 | } else { |
| 9700 | assert(isStore && "Node has to be a load, a store, or an intrinsic!"); |
| 9701 | VecTy = N->getOperand(1).getValueType(); |
| 9702 | } |
| 9703 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9704 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 9705 | if (isLaneOp) |
| 9706 | NumBytes /= VecTy.getVectorNumElements(); |
| 9707 | |
| 9708 | // If the increment is a constant, it must match the memory ref size. |
| 9709 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 9710 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 9711 | uint64_t IncVal = CInc->getZExtValue(); |
| 9712 | if (IncVal != NumBytes) |
| 9713 | continue; |
| 9714 | } else if (NumBytes >= 3 * 16) { |
| 9715 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 9716 | // separate instructions that make it harder to use a non-constant update. |
| 9717 | continue; |
| 9718 | } |
| 9719 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9720 | // OK, we found an ADD we can fold into the base update. |
| 9721 | // Now, create a _UPD node, taking care of not breaking alignment. |
| 9722 | |
| 9723 | EVT AlignedVecTy = VecTy; |
| 9724 | unsigned Alignment = MemN->getAlignment(); |
| 9725 | |
| 9726 | // If this is a less-than-standard-aligned load/store, change the type to |
| 9727 | // match the standard alignment. |
| 9728 | // The alignment is overlooked when selecting _UPD variants; and it's |
| 9729 | // easier to introduce bitcasts here than fix that. |
| 9730 | // There are 3 ways to get to this base-update combine: |
| 9731 | // - intrinsics: they are assumed to be properly aligned (to the standard |
| 9732 | // alignment of the memory type), so we don't need to do anything. |
| 9733 | // - ARMISD::VLDx nodes: they are only generated from the aforementioned |
| 9734 | // intrinsics, so, likewise, there's nothing to do. |
| 9735 | // - generic load/store instructions: the alignment is specified as an |
| 9736 | // explicit operand, rather than implicitly as the standard alignment |
| 9737 | // of the memory type (like the intrisics). We need to change the |
| 9738 | // memory type to match the explicit alignment. That way, we don't |
| 9739 | // generate non-standard-aligned ARMISD::VLDx nodes. |
| 9740 | if (isa<LSBaseSDNode>(N)) { |
| 9741 | if (Alignment == 0) |
| 9742 | Alignment = 1; |
| 9743 | if (Alignment < VecTy.getScalarSizeInBits() / 8) { |
| 9744 | MVT EltTy = MVT::getIntegerVT(Alignment * 8); |
| 9745 | assert(NumVecs == 1 && "Unexpected multi-element generic load/store."); |
| 9746 | assert(!isLaneOp && "Unexpected generic load/store lane."); |
| 9747 | unsigned NumElts = NumBytes / (EltTy.getSizeInBits() / 8); |
| 9748 | AlignedVecTy = MVT::getVectorVT(EltTy, NumElts); |
| 9749 | } |
| 9750 | // Don't set an explicit alignment on regular load/stores that we want |
| 9751 | // to transform to VLD/VST 1_UPD nodes. |
| 9752 | // This matches the behavior of regular load/stores, which only get an |
| 9753 | // explicit alignment if the MMO alignment is larger than the standard |
| 9754 | // alignment of the memory type. |
| 9755 | // Intrinsics, however, always get an explicit alignment, set to the |
| 9756 | // alignment of the MMO. |
| 9757 | Alignment = 1; |
| 9758 | } |
| 9759 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9760 | // Create the new updating load/store node. |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9761 | // First, create an SDVTList for the new updating node's results. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9762 | EVT Tys[6]; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9763 | unsigned NumResultVecs = (isLoadOp ? NumVecs : 0); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9764 | unsigned n; |
| 9765 | for (n = 0; n < NumResultVecs; ++n) |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9766 | Tys[n] = AlignedVecTy; |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9767 | Tys[n++] = MVT::i32; |
| 9768 | Tys[n] = MVT::Other; |
| Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 9769 | SDVTList SDTys = DAG.getVTList(makeArrayRef(Tys, NumResultVecs+2)); |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9770 | |
| 9771 | // Then, gather the new node's operands. |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9772 | SmallVector<SDValue, 8> Ops; |
| 9773 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 9774 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 9775 | Ops.push_back(Inc); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9776 | |
| 9777 | if (StoreSDNode *StN = dyn_cast<StoreSDNode>(N)) { |
| 9778 | // Try to match the intrinsic's signature |
| 9779 | Ops.push_back(StN->getValue()); |
| 9780 | } else { |
| 9781 | // Loads (and of course intrinsics) match the intrinsics' signature, |
| 9782 | // so just add all but the alignment operand. |
| 9783 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands() - 1; ++i) |
| 9784 | Ops.push_back(N->getOperand(i)); |
| 9785 | } |
| 9786 | |
| 9787 | // For all node types, the alignment operand is always the last one. |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9788 | Ops.push_back(DAG.getConstant(Alignment, dl, MVT::i32)); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9789 | |
| 9790 | // If this is a non-standard-aligned STORE, the penultimate operand is the |
| 9791 | // stored value. Bitcast it to the aligned type. |
| 9792 | if (AlignedVecTy != VecTy && N->getOpcode() == ISD::STORE) { |
| 9793 | SDValue &StVal = Ops[Ops.size()-2]; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9794 | StVal = DAG.getNode(ISD::BITCAST, dl, AlignedVecTy, StVal); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9795 | } |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9796 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9797 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, dl, SDTys, |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9798 | Ops, AlignedVecTy, |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9799 | MemN->getMemOperand()); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9800 | |
| 9801 | // Update the uses. |
| Ahmed Bougacha | 4c2b078 | 2015-02-19 23:13:10 +0000 | [diff] [blame] | 9802 | SmallVector<SDValue, 5> NewResults; |
| Ahmed Bougacha | dfdf54b | 2015-02-19 23:30:37 +0000 | [diff] [blame] | 9803 | for (unsigned i = 0; i < NumResultVecs; ++i) |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9804 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9805 | |
| 9806 | // If this is an non-standard-aligned LOAD, the first result is the loaded |
| 9807 | // value. Bitcast it to the expected result type. |
| 9808 | if (AlignedVecTy != VecTy && N->getOpcode() == ISD::LOAD) { |
| 9809 | SDValue &LdVal = NewResults[0]; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 9810 | LdVal = DAG.getNode(ISD::BITCAST, dl, VecTy, LdVal); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9811 | } |
| 9812 | |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9813 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 9814 | DCI.CombineTo(N, NewResults); |
| 9815 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 9816 | |
| 9817 | break; |
| Owen Anderson | 77aa266 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 9818 | } |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 9819 | return SDValue(); |
| 9820 | } |
| 9821 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9822 | static SDValue PerformVLDCombine(SDNode *N, |
| 9823 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9824 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 9825 | return SDValue(); |
| 9826 | |
| 9827 | return CombineBaseUpdate(N, DCI); |
| 9828 | } |
| 9829 | |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9830 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 9831 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 9832 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 9833 | /// return true. |
| 9834 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 9835 | SelectionDAG &DAG = DCI.DAG; |
| 9836 | EVT VT = N->getValueType(0); |
| 9837 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 9838 | if (!VT.is64BitVector()) |
| 9839 | return false; |
| 9840 | |
| 9841 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 9842 | SDNode *VLD = N->getOperand(0).getNode(); |
| 9843 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 9844 | return false; |
| 9845 | unsigned NumVecs = 0; |
| 9846 | unsigned NewOpc = 0; |
| 9847 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 9848 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 9849 | NumVecs = 2; |
| 9850 | NewOpc = ARMISD::VLD2DUP; |
| 9851 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 9852 | NumVecs = 3; |
| 9853 | NewOpc = ARMISD::VLD3DUP; |
| 9854 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 9855 | NumVecs = 4; |
| 9856 | NewOpc = ARMISD::VLD4DUP; |
| 9857 | } else { |
| 9858 | return false; |
| 9859 | } |
| 9860 | |
| 9861 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 9862 | // numbers match the load. |
| 9863 | unsigned VLDLaneNo = |
| 9864 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 9865 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9866 | UI != UE; ++UI) { |
| 9867 | // Ignore uses of the chain result. |
| 9868 | if (UI.getUse().getResNo() == NumVecs) |
| 9869 | continue; |
| 9870 | SDNode *User = *UI; |
| 9871 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 9872 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 9873 | return false; |
| 9874 | } |
| 9875 | |
| 9876 | // Create the vldN-dup node. |
| 9877 | EVT Tys[5]; |
| 9878 | unsigned n; |
| 9879 | for (n = 0; n < NumVecs; ++n) |
| 9880 | Tys[n] = VT; |
| 9881 | Tys[n] = MVT::Other; |
| Craig Topper | e1d1294 | 2014-08-27 05:25:25 +0000 | [diff] [blame] | 9882 | SDVTList SDTys = DAG.getVTList(makeArrayRef(Tys, NumVecs+1)); |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9883 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 9884 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9885 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, SDLoc(VLD), SDTys, |
| Craig Topper | 206fcd4 | 2014-04-26 19:29:41 +0000 | [diff] [blame] | 9886 | Ops, VLDMemInt->getMemoryVT(), |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9887 | VLDMemInt->getMemOperand()); |
| 9888 | |
| 9889 | // Update the uses. |
| 9890 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 9891 | UI != UE; ++UI) { |
| 9892 | unsigned ResNo = UI.getUse().getResNo(); |
| 9893 | // Ignore uses of the chain result. |
| 9894 | if (ResNo == NumVecs) |
| 9895 | continue; |
| 9896 | SDNode *User = *UI; |
| 9897 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 9898 | } |
| 9899 | |
| 9900 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 9901 | // Update uses of the chain. |
| 9902 | std::vector<SDValue> VLDDupResults; |
| 9903 | for (unsigned n = 0; n < NumVecs; ++n) |
| 9904 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 9905 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 9906 | DCI.CombineTo(VLD, VLDDupResults); |
| 9907 | |
| 9908 | return true; |
| 9909 | } |
| 9910 | |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9911 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 9912 | /// ARMISD::VDUPLANE. |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9913 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 9914 | TargetLowering::DAGCombinerInfo &DCI) { |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9915 | SDValue Op = N->getOperand(0); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9916 | |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9917 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 9918 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 9919 | if (CombineVLDDUP(N, DCI)) |
| 9920 | return SDValue(N, 0); |
| 9921 | |
| 9922 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 9923 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 9924 | while (Op.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9925 | Op = Op.getOperand(0); |
| Bob Wilson | bad47f6 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 9926 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9927 | return SDValue(); |
| 9928 | |
| 9929 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 9930 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 9931 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 9932 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 9933 | unsigned EltBits; |
| 9934 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 9935 | EltSize = 8; |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 9936 | EVT VT = N->getValueType(0); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9937 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 9938 | return SDValue(); |
| 9939 | |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 9940 | return DCI.DAG.getNode(ISD::BITCAST, SDLoc(N), VT, Op); |
| Bob Wilson | 103a0dc | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 9941 | } |
| 9942 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 9943 | static SDValue PerformLOADCombine(SDNode *N, |
| 9944 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9945 | EVT VT = N->getValueType(0); |
| 9946 | |
| 9947 | // If this is a legal vector load, try to combine it into a VLD1_UPD. |
| 9948 | if (ISD::isNormalLoad(N) && VT.isVector() && |
| 9949 | DCI.DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 9950 | return CombineBaseUpdate(N, DCI); |
| 9951 | |
| 9952 | return SDValue(); |
| 9953 | } |
| 9954 | |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9955 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 9956 | /// ISD::STORE. |
| 9957 | static SDValue PerformSTORECombine(SDNode *N, |
| 9958 | TargetLowering::DAGCombinerInfo &DCI) { |
| 9959 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 9960 | if (St->isVolatile()) |
| 9961 | return SDValue(); |
| 9962 | |
| 9963 | // Optimize trunc store (of multiple scalars) to shuffle and store. First, |
| 9964 | // pack all of the elements in one place. Next, store to memory in fewer |
| 9965 | // chunks. |
| 9966 | SDValue StVal = St->getValue(); |
| 9967 | EVT VT = StVal.getValueType(); |
| 9968 | if (St->isTruncatingStore() && VT.isVector()) { |
| 9969 | SelectionDAG &DAG = DCI.DAG; |
| 9970 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 9971 | EVT StVT = St->getMemoryVT(); |
| 9972 | unsigned NumElems = VT.getVectorNumElements(); |
| 9973 | assert(StVT != VT && "Cannot truncate to the same type"); |
| 9974 | unsigned FromEltSz = VT.getVectorElementType().getSizeInBits(); |
| 9975 | unsigned ToEltSz = StVT.getVectorElementType().getSizeInBits(); |
| 9976 | |
| 9977 | // From, To sizes and ElemCount must be pow of two |
| 9978 | if (!isPowerOf2_32(NumElems * FromEltSz * ToEltSz)) return SDValue(); |
| 9979 | |
| 9980 | // We are going to use the original vector elt for storing. |
| 9981 | // Accumulated smaller vector elements must be a multiple of the store size. |
| 9982 | if (0 != (NumElems * FromEltSz) % ToEltSz) return SDValue(); |
| 9983 | |
| 9984 | unsigned SizeRatio = FromEltSz / ToEltSz; |
| 9985 | assert(SizeRatio * NumElems * ToEltSz == VT.getSizeInBits()); |
| 9986 | |
| 9987 | // Create a type on which we perform the shuffle. |
| 9988 | EVT WideVecVT = EVT::getVectorVT(*DAG.getContext(), StVT.getScalarType(), |
| 9989 | NumElems*SizeRatio); |
| 9990 | assert(WideVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 9991 | |
| 9992 | SDLoc DL(St); |
| 9993 | SDValue WideVec = DAG.getNode(ISD::BITCAST, DL, WideVecVT, StVal); |
| 9994 | SmallVector<int, 8> ShuffleVec(NumElems * SizeRatio, -1); |
| 9995 | for (unsigned i = 0; i < NumElems; ++i) |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 9996 | ShuffleVec[i] = DAG.getDataLayout().isBigEndian() |
| 9997 | ? (i + 1) * SizeRatio - 1 |
| 9998 | : i * SizeRatio; |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 9999 | |
| 10000 | // Can't shuffle using an illegal type. |
| 10001 | if (!TLI.isTypeLegal(WideVecVT)) return SDValue(); |
| 10002 | |
| 10003 | SDValue Shuff = DAG.getVectorShuffle(WideVecVT, DL, WideVec, |
| 10004 | DAG.getUNDEF(WideVec.getValueType()), |
| 10005 | ShuffleVec.data()); |
| 10006 | // At this point all of the data is stored at the bottom of the |
| 10007 | // register. We now need to save it to mem. |
| 10008 | |
| 10009 | // Find the largest store unit |
| 10010 | MVT StoreType = MVT::i8; |
| Ahmed Bougacha | 67dd2d2 | 2015-01-07 21:27:10 +0000 | [diff] [blame] | 10011 | for (MVT Tp : MVT::integer_valuetypes()) { |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10012 | if (TLI.isTypeLegal(Tp) && Tp.getSizeInBits() <= NumElems * ToEltSz) |
| 10013 | StoreType = Tp; |
| 10014 | } |
| 10015 | // Didn't find a legal store type. |
| 10016 | if (!TLI.isTypeLegal(StoreType)) |
| 10017 | return SDValue(); |
| 10018 | |
| 10019 | // Bitcast the original vector into a vector of store-size units |
| 10020 | EVT StoreVecVT = EVT::getVectorVT(*DAG.getContext(), |
| 10021 | StoreType, VT.getSizeInBits()/EVT(StoreType).getSizeInBits()); |
| 10022 | assert(StoreVecVT.getSizeInBits() == VT.getSizeInBits()); |
| 10023 | SDValue ShuffWide = DAG.getNode(ISD::BITCAST, DL, StoreVecVT, Shuff); |
| 10024 | SmallVector<SDValue, 8> Chains; |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 10025 | SDValue Increment = DAG.getConstant(StoreType.getSizeInBits() / 8, DL, |
| 10026 | TLI.getPointerTy(DAG.getDataLayout())); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10027 | SDValue BasePtr = St->getBasePtr(); |
| 10028 | |
| 10029 | // Perform one or more big stores into memory. |
| 10030 | unsigned E = (ToEltSz*NumElems)/StoreType.getSizeInBits(); |
| 10031 | for (unsigned I = 0; I < E; I++) { |
| 10032 | SDValue SubVec = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, |
| 10033 | StoreType, ShuffWide, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10034 | DAG.getIntPtrConstant(I, DL)); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10035 | SDValue Ch = DAG.getStore(St->getChain(), DL, SubVec, BasePtr, |
| 10036 | St->getPointerInfo(), St->isVolatile(), |
| 10037 | St->isNonTemporal(), St->getAlignment()); |
| 10038 | BasePtr = DAG.getNode(ISD::ADD, DL, BasePtr.getValueType(), BasePtr, |
| 10039 | Increment); |
| 10040 | Chains.push_back(Ch); |
| 10041 | } |
| 10042 | return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains); |
| 10043 | } |
| 10044 | |
| 10045 | if (!ISD::isNormalStore(St)) |
| 10046 | return SDValue(); |
| 10047 | |
| 10048 | // Split a store of a VMOVDRR into two integer stores to avoid mixing NEON and |
| 10049 | // ARM stores of arguments in the same cache line. |
| 10050 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 10051 | StVal.getNode()->hasOneUse()) { |
| 10052 | SelectionDAG &DAG = DCI.DAG; |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 10053 | bool isBigEndian = DAG.getDataLayout().isBigEndian(); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10054 | SDLoc DL(St); |
| 10055 | SDValue BasePtr = St->getBasePtr(); |
| 10056 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 10057 | StVal.getNode()->getOperand(isBigEndian ? 1 : 0 ), |
| 10058 | BasePtr, St->getPointerInfo(), St->isVolatile(), |
| 10059 | St->isNonTemporal(), St->getAlignment()); |
| 10060 | |
| 10061 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10062 | DAG.getConstant(4, DL, MVT::i32)); |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10063 | return DAG.getStore(NewST1.getValue(0), DL, |
| 10064 | StVal.getNode()->getOperand(isBigEndian ? 0 : 1), |
| 10065 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 10066 | St->isNonTemporal(), |
| 10067 | std::min(4U, St->getAlignment() / 2)); |
| 10068 | } |
| 10069 | |
| 10070 | if (StVal.getValueType() == MVT::i64 && |
| 10071 | StVal.getNode()->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 10072 | |
| 10073 | // Bitcast an i64 store extracted from a vector to f64. |
| 10074 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 10075 | SelectionDAG &DAG = DCI.DAG; |
| 10076 | SDLoc dl(StVal); |
| 10077 | SDValue IntVec = StVal.getOperand(0); |
| 10078 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 10079 | IntVec.getValueType().getVectorNumElements()); |
| 10080 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 10081 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 10082 | Vec, StVal.getOperand(1)); |
| 10083 | dl = SDLoc(N); |
| 10084 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 10085 | // Make the DAGCombiner fold the bitcasts. |
| 10086 | DCI.AddToWorklist(Vec.getNode()); |
| 10087 | DCI.AddToWorklist(ExtElt.getNode()); |
| 10088 | DCI.AddToWorklist(V.getNode()); |
| 10089 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 10090 | St->getPointerInfo(), St->isVolatile(), |
| 10091 | St->isNonTemporal(), St->getAlignment(), |
| 10092 | St->getAAInfo()); |
| 10093 | } |
| 10094 | |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10095 | // If this is a legal vector store, try to combine it into a VST1_UPD. |
| 10096 | if (ISD::isNormalStore(N) && VT.isVector() && |
| 10097 | DCI.DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 10098 | return CombineBaseUpdate(N, DCI); |
| 10099 | |
| Ahmed Bougacha | 2316746 | 2014-12-09 21:26:53 +0000 | [diff] [blame] | 10100 | return SDValue(); |
| 10101 | } |
| 10102 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10103 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 10104 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 10105 | /// when the VMUL has a constant operand that is a power of 2. |
| 10106 | /// |
| 10107 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 10108 | /// vmul.f32 d16, d17, d16 |
| 10109 | /// vcvt.s32.f32 d16, d16 |
| 10110 | /// becomes: |
| 10111 | /// vcvt.s32.f32 d16, d16, #3 |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10112 | static SDValue PerformVCVTCombine(SDNode *N, SelectionDAG &DAG, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10113 | const ARMSubtarget *Subtarget) { |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10114 | if (!Subtarget->hasNEON()) |
| 10115 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10116 | |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10117 | SDValue Op = N->getOperand(0); |
| 10118 | if (!Op.getValueType().isVector() || Op.getOpcode() != ISD::FMUL) |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10119 | return SDValue(); |
| 10120 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10121 | SDValue ConstVec = Op->getOperand(1); |
| Chad Rosier | aed910b | 2015-10-06 20:51:26 +0000 | [diff] [blame] | 10122 | if (!isa<BuildVectorSDNode>(ConstVec)) |
| 10123 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10124 | |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10125 | MVT FloatTy = Op.getSimpleValueType().getVectorElementType(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 10126 | uint32_t FloatBits = FloatTy.getSizeInBits(); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10127 | MVT IntTy = N->getSimpleValueType(0).getVectorElementType(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 10128 | uint32_t IntBits = IntTy.getSizeInBits(); |
| Bradley Smith | ececb7f | 2014-12-16 10:59:27 +0000 | [diff] [blame] | 10129 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 10130 | if (FloatBits != 32 || IntBits > 32 || NumLanes > 4) { |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10131 | // These instructions only exist converting from f32 to i32. We can handle |
| 10132 | // smaller integers by generating an extra truncate, but larger ones would |
| Bradley Smith | ececb7f | 2014-12-16 10:59:27 +0000 | [diff] [blame] | 10133 | // be lossy. We also can't handle more then 4 lanes, since these intructions |
| 10134 | // only support v2i32/v4i32 types. |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10135 | return SDValue(); |
| 10136 | } |
| 10137 | |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10138 | BitVector UndefElements; |
| 10139 | BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec); |
| 10140 | int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, 33); |
| 10141 | if (C == -1 || C == 0 || C > 32) |
| Chad Rosier | db71abf | 2015-10-07 13:40:44 +0000 | [diff] [blame] | 10142 | return SDValue(); |
| 10143 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10144 | SDLoc dl(N); |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10145 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10146 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 10147 | Intrinsic::arm_neon_vcvtfp2fxu; |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 10148 | SDValue FixConv = DAG.getNode( |
| 10149 | ISD::INTRINSIC_WO_CHAIN, dl, NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, |
| 10150 | DAG.getConstant(IntrinsicOpcode, dl, MVT::i32), Op->getOperand(0), |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10151 | DAG.getConstant(C, dl, MVT::i32)); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10152 | |
| Chad Rosier | 9df4aff | 2015-10-06 20:45:45 +0000 | [diff] [blame] | 10153 | if (IntBits < FloatBits) |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10154 | FixConv = DAG.getNode(ISD::TRUNCATE, dl, N->getValueType(0), FixConv); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10155 | |
| 10156 | return FixConv; |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10157 | } |
| 10158 | |
| 10159 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 10160 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 10161 | /// when the VDIV has a constant operand that is a power of 2. |
| 10162 | /// |
| 10163 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 10164 | /// vcvt.f32.s32 d16, d16 |
| 10165 | /// vdiv.f32 d16, d17, d16 |
| 10166 | /// becomes: |
| 10167 | /// vcvt.f32.s32 d16, d16, #3 |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10168 | static SDValue PerformVDIVCombine(SDNode *N, SelectionDAG &DAG, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10169 | const ARMSubtarget *Subtarget) { |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10170 | if (!Subtarget->hasNEON()) |
| 10171 | return SDValue(); |
| 10172 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10173 | SDValue Op = N->getOperand(0); |
| 10174 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10175 | if (!N->getValueType(0).isVector() || |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10176 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 10177 | return SDValue(); |
| 10178 | |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10179 | SDValue ConstVec = N->getOperand(1); |
| Chad Rosier | aed910b | 2015-10-06 20:51:26 +0000 | [diff] [blame] | 10180 | if (!isa<BuildVectorSDNode>(ConstVec)) |
| 10181 | return SDValue(); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10182 | |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10183 | MVT FloatTy = N->getSimpleValueType(0).getVectorElementType(); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 10184 | uint32_t FloatBits = FloatTy.getSizeInBits(); |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10185 | MVT IntTy = Op.getOperand(0).getSimpleValueType().getVectorElementType(); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 10186 | uint32_t IntBits = IntTy.getSizeInBits(); |
| Chad Rosier | 17436bf | 2015-10-07 16:15:40 +0000 | [diff] [blame] | 10187 | unsigned NumLanes = Op.getValueType().getVectorNumElements(); |
| 10188 | if (FloatBits != 32 || IntBits > 32 || NumLanes > 4) { |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10189 | // These instructions only exist converting from i32 to f32. We can handle |
| 10190 | // smaller integers by generating an extra extend, but larger ones would |
| Chad Rosier | 17436bf | 2015-10-07 16:15:40 +0000 | [diff] [blame] | 10191 | // be lossy. We also can't handle more then 4 lanes, since these intructions |
| 10192 | // only support v2i32/v4i32 types. |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10193 | return SDValue(); |
| 10194 | } |
| 10195 | |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10196 | BitVector UndefElements; |
| 10197 | BuildVectorSDNode *BV = cast<BuildVectorSDNode>(ConstVec); |
| 10198 | int32_t C = BV->getConstantFPSplatPow2ToLog2Int(&UndefElements, 33); |
| 10199 | if (C == -1 || C == 0 || C > 32) |
| Chad Rosier | db71abf | 2015-10-07 13:40:44 +0000 | [diff] [blame] | 10200 | return SDValue(); |
| 10201 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10202 | SDLoc dl(N); |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10203 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10204 | SDValue ConvInput = Op.getOperand(0); |
| Chad Rosier | dca46b4 | 2015-10-06 20:58:42 +0000 | [diff] [blame] | 10205 | if (IntBits < FloatBits) |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10206 | ConvInput = DAG.getNode(isSigned ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10207 | dl, NumLanes == 2 ? MVT::v2i32 : MVT::v4i32, |
| Tim Northover | 7cbc215 | 2013-06-28 15:29:25 +0000 | [diff] [blame] | 10208 | ConvInput); |
| 10209 | |
| Eric Christopher | 1b8b9419 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 10210 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10211 | Intrinsic::arm_neon_vcvtfxu2fp; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10212 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10213 | Op.getValueType(), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10214 | DAG.getConstant(IntrinsicOpcode, dl, MVT::i32), |
| Chad Rosier | 169865f | 2015-10-07 17:28:58 +0000 | [diff] [blame] | 10215 | ConvInput, DAG.getConstant(C, dl, MVT::i32)); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10216 | } |
| 10217 | |
| 10218 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10219 | /// operand of a vector shift operation, where all the elements of the |
| 10220 | /// build_vector must have the same constant integer value. |
| 10221 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 10222 | // Ignore bit_converts. |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 10223 | while (Op.getOpcode() == ISD::BITCAST) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10224 | Op = Op.getOperand(0); |
| 10225 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 10226 | APInt SplatBits, SplatUndef; |
| 10227 | unsigned SplatBitSize; |
| 10228 | bool HasAnyUndefs; |
| 10229 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 10230 | HasAnyUndefs, ElementBits) || |
| 10231 | SplatBitSize > ElementBits) |
| 10232 | return false; |
| 10233 | Cnt = SplatBits.getSExtValue(); |
| 10234 | return true; |
| 10235 | } |
| 10236 | |
| 10237 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 10238 | /// operand of a vector shift left operation. That value must be in the range: |
| 10239 | /// 0 <= Value < ElementBits for a left shift; or |
| 10240 | /// 0 <= Value <= ElementBits for a long left shift. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10241 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10242 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 10243 | int64_t ElementBits = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10244 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 10245 | return false; |
| 10246 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 10247 | } |
| 10248 | |
| 10249 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 10250 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 10251 | /// is positive, but for an intrinsic the value count must be negative. The |
| 10252 | /// absolute value must be in the range: |
| 10253 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 10254 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10255 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10256 | int64_t &Cnt) { |
| 10257 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 10258 | int64_t ElementBits = VT.getVectorElementType().getSizeInBits(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10259 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 10260 | return false; |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 10261 | if (!isIntrinsic) |
| 10262 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 10263 | if (Cnt >= -(isNarrow ? ElementBits/2 : ElementBits) && Cnt <= -1) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10264 | Cnt = -Cnt; |
| Luke Cheeseman | b5c627a | 2015-07-24 09:31:48 +0000 | [diff] [blame] | 10265 | return true; |
| 10266 | } |
| 10267 | return false; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10268 | } |
| 10269 | |
| 10270 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 10271 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 10272 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 10273 | switch (IntNo) { |
| 10274 | default: |
| 10275 | // Don't do anything for most intrinsics. |
| 10276 | break; |
| 10277 | |
| 10278 | // Vector shifts: check for immediate versions and lower them. |
| 10279 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 10280 | // the build_vectors for 64-bit vector element shift counts are generally |
| 10281 | // not legal, and it is hard to see their values after they get legalized to |
| 10282 | // loads from a constant pool. |
| 10283 | case Intrinsic::arm_neon_vshifts: |
| 10284 | case Intrinsic::arm_neon_vshiftu: |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10285 | case Intrinsic::arm_neon_vrshifts: |
| 10286 | case Intrinsic::arm_neon_vrshiftu: |
| 10287 | case Intrinsic::arm_neon_vrshiftn: |
| 10288 | case Intrinsic::arm_neon_vqshifts: |
| 10289 | case Intrinsic::arm_neon_vqshiftu: |
| 10290 | case Intrinsic::arm_neon_vqshiftsu: |
| 10291 | case Intrinsic::arm_neon_vqshiftns: |
| 10292 | case Intrinsic::arm_neon_vqshiftnu: |
| 10293 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10294 | case Intrinsic::arm_neon_vqrshiftns: |
| 10295 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10296 | case Intrinsic::arm_neon_vqrshiftnsu: { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10297 | EVT VT = N->getOperand(1).getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10298 | int64_t Cnt; |
| 10299 | unsigned VShiftOpc = 0; |
| 10300 | |
| 10301 | switch (IntNo) { |
| 10302 | case Intrinsic::arm_neon_vshifts: |
| 10303 | case Intrinsic::arm_neon_vshiftu: |
| 10304 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 10305 | VShiftOpc = ARMISD::VSHL; |
| 10306 | break; |
| 10307 | } |
| 10308 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 10309 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 10310 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 10311 | break; |
| 10312 | } |
| 10313 | return SDValue(); |
| 10314 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10315 | case Intrinsic::arm_neon_vrshifts: |
| 10316 | case Intrinsic::arm_neon_vrshiftu: |
| 10317 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 10318 | break; |
| 10319 | return SDValue(); |
| 10320 | |
| 10321 | case Intrinsic::arm_neon_vqshifts: |
| 10322 | case Intrinsic::arm_neon_vqshiftu: |
| 10323 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 10324 | break; |
| 10325 | return SDValue(); |
| 10326 | |
| 10327 | case Intrinsic::arm_neon_vqshiftsu: |
| 10328 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 10329 | break; |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10330 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10331 | |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10332 | case Intrinsic::arm_neon_vrshiftn: |
| 10333 | case Intrinsic::arm_neon_vqshiftns: |
| 10334 | case Intrinsic::arm_neon_vqshiftnu: |
| 10335 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10336 | case Intrinsic::arm_neon_vqrshiftns: |
| 10337 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10338 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 10339 | // Narrowing shifts require an immediate right shift. |
| 10340 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 10341 | break; |
| Jim Grosbach | 84511e1 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 10342 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 10343 | "intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10344 | |
| 10345 | default: |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10346 | llvm_unreachable("unhandled vector shift"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10347 | } |
| 10348 | |
| 10349 | switch (IntNo) { |
| 10350 | case Intrinsic::arm_neon_vshifts: |
| 10351 | case Intrinsic::arm_neon_vshiftu: |
| 10352 | // Opcode already set above. |
| 10353 | break; |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10354 | case Intrinsic::arm_neon_vrshifts: |
| 10355 | VShiftOpc = ARMISD::VRSHRs; break; |
| 10356 | case Intrinsic::arm_neon_vrshiftu: |
| 10357 | VShiftOpc = ARMISD::VRSHRu; break; |
| 10358 | case Intrinsic::arm_neon_vrshiftn: |
| 10359 | VShiftOpc = ARMISD::VRSHRN; break; |
| 10360 | case Intrinsic::arm_neon_vqshifts: |
| 10361 | VShiftOpc = ARMISD::VQSHLs; break; |
| 10362 | case Intrinsic::arm_neon_vqshiftu: |
| 10363 | VShiftOpc = ARMISD::VQSHLu; break; |
| 10364 | case Intrinsic::arm_neon_vqshiftsu: |
| 10365 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 10366 | case Intrinsic::arm_neon_vqshiftns: |
| 10367 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 10368 | case Intrinsic::arm_neon_vqshiftnu: |
| 10369 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 10370 | case Intrinsic::arm_neon_vqshiftnsu: |
| 10371 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 10372 | case Intrinsic::arm_neon_vqrshiftns: |
| 10373 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 10374 | case Intrinsic::arm_neon_vqrshiftnu: |
| 10375 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 10376 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 10377 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 10378 | } |
| 10379 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10380 | SDLoc dl(N); |
| 10381 | return DAG.getNode(VShiftOpc, dl, N->getValueType(0), |
| 10382 | N->getOperand(1), DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10383 | } |
| 10384 | |
| 10385 | case Intrinsic::arm_neon_vshiftins: { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10386 | EVT VT = N->getOperand(1).getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10387 | int64_t Cnt; |
| 10388 | unsigned VShiftOpc = 0; |
| 10389 | |
| 10390 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 10391 | VShiftOpc = ARMISD::VSLI; |
| 10392 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 10393 | VShiftOpc = ARMISD::VSRI; |
| 10394 | else { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10395 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10396 | } |
| 10397 | |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10398 | SDLoc dl(N); |
| 10399 | return DAG.getNode(VShiftOpc, dl, N->getValueType(0), |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10400 | N->getOperand(1), N->getOperand(2), |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10401 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10402 | } |
| 10403 | |
| 10404 | case Intrinsic::arm_neon_vqrshifts: |
| 10405 | case Intrinsic::arm_neon_vqrshiftu: |
| 10406 | // No immediate versions of these to check for. |
| 10407 | break; |
| 10408 | } |
| 10409 | |
| 10410 | return SDValue(); |
| 10411 | } |
| 10412 | |
| 10413 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 10414 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 10415 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 10416 | /// vector element shift counts are generally not legal, and it is hard to see |
| 10417 | /// their values after they get legalized to loads from a constant pool. |
| 10418 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 10419 | const ARMSubtarget *ST) { |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10420 | EVT VT = N->getValueType(0); |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 10421 | if (N->getOpcode() == ISD::SRL && VT == MVT::i32 && ST->hasV6Ops()) { |
| 10422 | // Canonicalize (srl (bswap x), 16) to (rotr (bswap x), 16) if the high |
| 10423 | // 16-bits of x is zero. This optimizes rev + lsr 16 to rev16. |
| 10424 | SDValue N1 = N->getOperand(1); |
| 10425 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(N1)) { |
| 10426 | SDValue N0 = N->getOperand(0); |
| 10427 | if (C->getZExtValue() == 16 && N0.getOpcode() == ISD::BSWAP && |
| 10428 | DAG.MaskedValueIsZero(N0.getOperand(0), |
| 10429 | APInt::getHighBitsSet(32, 16))) |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10430 | return DAG.getNode(ISD::ROTR, SDLoc(N), VT, N0, N1); |
| Evan Cheng | f258a15 | 2012-02-23 02:58:19 +0000 | [diff] [blame] | 10431 | } |
| 10432 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10433 | |
| 10434 | // Nothing to be done for scalar shifts. |
| Tanya Lattner | cd68095 | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 10435 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 10436 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10437 | return SDValue(); |
| 10438 | |
| 10439 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 10440 | int64_t Cnt; |
| 10441 | |
| 10442 | switch (N->getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10443 | default: llvm_unreachable("unexpected shift opcode"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10444 | |
| 10445 | case ISD::SHL: |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10446 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) { |
| 10447 | SDLoc dl(N); |
| 10448 | return DAG.getNode(ARMISD::VSHL, dl, VT, N->getOperand(0), |
| 10449 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| 10450 | } |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10451 | break; |
| 10452 | |
| 10453 | case ISD::SRA: |
| 10454 | case ISD::SRL: |
| 10455 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 10456 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 10457 | ARMISD::VSHRs : ARMISD::VSHRu); |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 10458 | SDLoc dl(N); |
| 10459 | return DAG.getNode(VShiftOpc, dl, VT, N->getOperand(0), |
| 10460 | DAG.getConstant(Cnt, dl, MVT::i32)); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10461 | } |
| 10462 | } |
| 10463 | return SDValue(); |
| 10464 | } |
| 10465 | |
| 10466 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 10467 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 10468 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 10469 | const ARMSubtarget *ST) { |
| 10470 | SDValue N0 = N->getOperand(0); |
| 10471 | |
| 10472 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 10473 | // and 16-bit vector elements. NEON supports these directly. They are |
| 10474 | // handled during DAG combining because type legalization will promote them |
| 10475 | // to 32-bit types and it is messy to recognize the operations after that. |
| 10476 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 10477 | SDValue Vec = N0.getOperand(0); |
| 10478 | SDValue Lane = N0.getOperand(1); |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10479 | EVT VT = N->getValueType(0); |
| 10480 | EVT EltVT = N0.getValueType(); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10481 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 10482 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10483 | if (VT == MVT::i32 && |
| 10484 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
| Bob Wilson | ceb4929 | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 10485 | TLI.isTypeLegal(Vec.getValueType()) && |
| 10486 | isa<ConstantSDNode>(Lane)) { |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10487 | |
| 10488 | unsigned Opc = 0; |
| 10489 | switch (N->getOpcode()) { |
| Torok Edwin | fbcc663 | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 10490 | default: llvm_unreachable("unexpected opcode"); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10491 | case ISD::SIGN_EXTEND: |
| 10492 | Opc = ARMISD::VGETLANEs; |
| 10493 | break; |
| 10494 | case ISD::ZERO_EXTEND: |
| 10495 | case ISD::ANY_EXTEND: |
| 10496 | Opc = ARMISD::VGETLANEu; |
| 10497 | break; |
| 10498 | } |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10499 | return DAG.getNode(Opc, SDLoc(N), VT, Vec, Lane); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10500 | } |
| 10501 | } |
| 10502 | |
| 10503 | return SDValue(); |
| 10504 | } |
| 10505 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10506 | static void computeKnownBits(SelectionDAG &DAG, SDValue Op, APInt &KnownZero, |
| 10507 | APInt &KnownOne) { |
| 10508 | if (Op.getOpcode() == ARMISD::BFI) { |
| 10509 | // Conservatively, we can recurse down the first operand |
| 10510 | // and just mask out all affected bits. |
| 10511 | computeKnownBits(DAG, Op.getOperand(0), KnownZero, KnownOne); |
| 10512 | |
| 10513 | // The operand to BFI is already a mask suitable for removing the bits it |
| 10514 | // sets. |
| 10515 | ConstantSDNode *CI = cast<ConstantSDNode>(Op.getOperand(2)); |
| 10516 | APInt Mask = CI->getAPIntValue(); |
| 10517 | KnownZero &= Mask; |
| 10518 | KnownOne &= Mask; |
| 10519 | return; |
| 10520 | } |
| 10521 | if (Op.getOpcode() == ARMISD::CMOV) { |
| 10522 | APInt KZ2(KnownZero.getBitWidth(), 0); |
| 10523 | APInt KO2(KnownOne.getBitWidth(), 0); |
| 10524 | computeKnownBits(DAG, Op.getOperand(1), KnownZero, KnownOne); |
| 10525 | computeKnownBits(DAG, Op.getOperand(2), KZ2, KO2); |
| 10526 | |
| 10527 | KnownZero &= KZ2; |
| 10528 | KnownOne &= KO2; |
| 10529 | return; |
| 10530 | } |
| 10531 | return DAG.computeKnownBits(Op, KnownZero, KnownOne); |
| 10532 | } |
| 10533 | |
| 10534 | SDValue ARMTargetLowering::PerformCMOVToBFICombine(SDNode *CMOV, SelectionDAG &DAG) const { |
| 10535 | // If we have a CMOV, OR and AND combination such as: |
| 10536 | // if (x & CN) |
| 10537 | // y |= CM; |
| 10538 | // |
| 10539 | // And: |
| 10540 | // * CN is a single bit; |
| 10541 | // * All bits covered by CM are known zero in y |
| 10542 | // |
| 10543 | // Then we can convert this into a sequence of BFI instructions. This will |
| 10544 | // always be a win if CM is a single bit, will always be no worse than the |
| 10545 | // TST&OR sequence if CM is two bits, and for thumb will be no worse if CM is |
| 10546 | // three bits (due to the extra IT instruction). |
| 10547 | |
| 10548 | SDValue Op0 = CMOV->getOperand(0); |
| 10549 | SDValue Op1 = CMOV->getOperand(1); |
| James Molloy | 8e99e97 | 2015-11-12 13:49:17 +0000 | [diff] [blame] | 10550 | auto CCNode = cast<ConstantSDNode>(CMOV->getOperand(2)); |
| 10551 | auto CC = CCNode->getAPIntValue().getLimitedValue(); |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10552 | SDValue CmpZ = CMOV->getOperand(4); |
| 10553 | |
| James Molloy | 2018091 | 2015-11-16 10:49:25 +0000 | [diff] [blame] | 10554 | // The compare must be against zero. |
| Artyom Skrobov | 314ee04 | 2015-11-25 19:41:11 +0000 | [diff] [blame] | 10555 | if (!isNullConstant(CmpZ->getOperand(1))) |
| James Molloy | 2018091 | 2015-11-16 10:49:25 +0000 | [diff] [blame] | 10556 | return SDValue(); |
| 10557 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10558 | assert(CmpZ->getOpcode() == ARMISD::CMPZ); |
| 10559 | SDValue And = CmpZ->getOperand(0); |
| 10560 | if (And->getOpcode() != ISD::AND) |
| 10561 | return SDValue(); |
| 10562 | ConstantSDNode *AndC = dyn_cast<ConstantSDNode>(And->getOperand(1)); |
| 10563 | if (!AndC || !AndC->getAPIntValue().isPowerOf2()) |
| 10564 | return SDValue(); |
| 10565 | SDValue X = And->getOperand(0); |
| 10566 | |
| James Molloy | 8e99e97 | 2015-11-12 13:49:17 +0000 | [diff] [blame] | 10567 | if (CC == ARMCC::EQ) { |
| 10568 | // We're performing an "equal to zero" compare. Swap the operands so we |
| 10569 | // canonicalize on a "not equal to zero" compare. |
| 10570 | std::swap(Op0, Op1); |
| 10571 | } else { |
| 10572 | assert(CC == ARMCC::NE && "How can a CMPZ node not be EQ or NE?"); |
| 10573 | } |
| Junmo Park | 1108ab0 | 2016-02-19 01:46:04 +0000 | [diff] [blame] | 10574 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10575 | if (Op1->getOpcode() != ISD::OR) |
| 10576 | return SDValue(); |
| 10577 | |
| 10578 | ConstantSDNode *OrC = dyn_cast<ConstantSDNode>(Op1->getOperand(1)); |
| 10579 | if (!OrC) |
| 10580 | return SDValue(); |
| 10581 | SDValue Y = Op1->getOperand(0); |
| 10582 | |
| 10583 | if (Op0 != Y) |
| 10584 | return SDValue(); |
| 10585 | |
| 10586 | // Now, is it profitable to continue? |
| 10587 | APInt OrCI = OrC->getAPIntValue(); |
| 10588 | unsigned Heuristic = Subtarget->isThumb() ? 3 : 2; |
| 10589 | if (OrCI.countPopulation() > Heuristic) |
| 10590 | return SDValue(); |
| 10591 | |
| 10592 | // Lastly, can we determine that the bits defined by OrCI |
| 10593 | // are zero in Y? |
| 10594 | APInt KnownZero, KnownOne; |
| 10595 | computeKnownBits(DAG, Y, KnownZero, KnownOne); |
| 10596 | if ((OrCI & KnownZero) != OrCI) |
| 10597 | return SDValue(); |
| 10598 | |
| 10599 | // OK, we can do the combine. |
| 10600 | SDValue V = Y; |
| 10601 | SDLoc dl(X); |
| 10602 | EVT VT = X.getValueType(); |
| 10603 | unsigned BitInX = AndC->getAPIntValue().logBase2(); |
| Junmo Park | 1108ab0 | 2016-02-19 01:46:04 +0000 | [diff] [blame] | 10604 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10605 | if (BitInX != 0) { |
| 10606 | // We must shift X first. |
| 10607 | X = DAG.getNode(ISD::SRL, dl, VT, X, |
| 10608 | DAG.getConstant(BitInX, dl, VT)); |
| 10609 | } |
| 10610 | |
| 10611 | for (unsigned BitInY = 0, NumActiveBits = OrCI.getActiveBits(); |
| 10612 | BitInY < NumActiveBits; ++BitInY) { |
| 10613 | if (OrCI[BitInY] == 0) |
| 10614 | continue; |
| 10615 | APInt Mask(VT.getSizeInBits(), 0); |
| 10616 | Mask.setBit(BitInY); |
| 10617 | V = DAG.getNode(ARMISD::BFI, dl, VT, V, X, |
| 10618 | // Confusingly, the operand is an *inverted* mask. |
| 10619 | DAG.getConstant(~Mask, dl, VT)); |
| 10620 | } |
| 10621 | |
| 10622 | return V; |
| 10623 | } |
| 10624 | |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10625 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 10626 | SDValue |
| 10627 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 10628 | SDValue Cmp = N->getOperand(4); |
| 10629 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 10630 | // Only looking at EQ and NE cases. |
| 10631 | return SDValue(); |
| 10632 | |
| 10633 | EVT VT = N->getValueType(0); |
| Andrew Trick | ef9de2a | 2013-05-25 02:42:55 +0000 | [diff] [blame] | 10634 | SDLoc dl(N); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10635 | SDValue LHS = Cmp.getOperand(0); |
| 10636 | SDValue RHS = Cmp.getOperand(1); |
| 10637 | SDValue FalseVal = N->getOperand(0); |
| 10638 | SDValue TrueVal = N->getOperand(1); |
| 10639 | SDValue ARMcc = N->getOperand(2); |
| Jim Grosbach | e7e2aca | 2011-09-13 20:30:37 +0000 | [diff] [blame] | 10640 | ARMCC::CondCodes CC = |
| 10641 | (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10642 | |
| James Molloy | 9d55f19 | 2015-11-10 14:22:05 +0000 | [diff] [blame] | 10643 | // BFI is only available on V6T2+. |
| 10644 | if (!Subtarget->isThumb1Only() && Subtarget->hasV6T2Ops()) { |
| 10645 | SDValue R = PerformCMOVToBFICombine(N, DAG); |
| 10646 | if (R) |
| 10647 | return R; |
| 10648 | } |
| 10649 | |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10650 | // Simplify |
| 10651 | // mov r1, r0 |
| 10652 | // cmp r1, x |
| 10653 | // mov r0, y |
| 10654 | // moveq r0, x |
| 10655 | // to |
| 10656 | // cmp r0, x |
| 10657 | // movne r0, y |
| 10658 | // |
| 10659 | // mov r1, r0 |
| 10660 | // cmp r1, x |
| 10661 | // mov r0, x |
| 10662 | // movne r0, y |
| 10663 | // to |
| 10664 | // cmp r0, x |
| 10665 | // movne r0, y |
| 10666 | /// FIXME: Turn this into a target neutral optimization? |
| 10667 | SDValue Res; |
| Evan Cheng | 8156376 | 2011-09-28 23:16:31 +0000 | [diff] [blame] | 10668 | if (CC == ARMCC::NE && FalseVal == RHS && FalseVal != LHS) { |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10669 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 10670 | N->getOperand(3), Cmp); |
| 10671 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 10672 | SDValue ARMcc; |
| 10673 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 10674 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 10675 | N->getOperand(3), NewCmp); |
| 10676 | } |
| 10677 | |
| 10678 | if (Res.getNode()) { |
| 10679 | APInt KnownZero, KnownOne; |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 10680 | DAG.computeKnownBits(SDValue(N,0), KnownZero, KnownOne); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10681 | // Capture demanded bits information that would be otherwise lost. |
| 10682 | if (KnownZero == 0xfffffffe) |
| 10683 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10684 | DAG.getValueType(MVT::i1)); |
| 10685 | else if (KnownZero == 0xffffff00) |
| 10686 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10687 | DAG.getValueType(MVT::i8)); |
| 10688 | else if (KnownZero == 0xffff0000) |
| 10689 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 10690 | DAG.getValueType(MVT::i16)); |
| 10691 | } |
| 10692 | |
| 10693 | return Res; |
| 10694 | } |
| 10695 | |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10696 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 10697 | DAGCombinerInfo &DCI) const { |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10698 | switch (N->getOpcode()) { |
| 10699 | default: break; |
| Arnold Schwaighofer | f00fb1c | 2012-09-04 14:37:49 +0000 | [diff] [blame] | 10700 | case ISD::ADDC: return PerformADDCCombine(N, DCI, Subtarget); |
| Tanya Lattner | e9e6705 | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 10701 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10702 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
| Anton Korobeynikov | 1bf28a1 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 10703 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 10704 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
| Evan Cheng | e87681c | 2012-02-23 01:19:06 +0000 | [diff] [blame] | 10705 | case ISD::XOR: return PerformXORCombine(N, DCI, Subtarget); |
| 10706 | case ISD::AND: return PerformANDCombine(N, DCI, Subtarget); |
| Evan Cheng | c177813 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 10707 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 10708 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI, Subtarget); |
| Bob Wilson | 2280674 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 10709 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 10710 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 10711 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI, Subtarget); |
| Bob Wilson | 1a20c2a | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 10712 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
| Bob Wilson | c7334a1 | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 10713 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
| Bob Wilson | 2d790df | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 10714 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
| Chad Rosier | fa8d893 | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 10715 | case ISD::FP_TO_SINT: |
| Chad Rosier | a087fd2 | 2015-10-06 20:23:42 +0000 | [diff] [blame] | 10716 | case ISD::FP_TO_UINT: |
| 10717 | return PerformVCVTCombine(N, DCI.DAG, Subtarget); |
| 10718 | case ISD::FDIV: |
| 10719 | return PerformVDIVCombine(N, DCI.DAG, Subtarget); |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10720 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10721 | case ISD::SHL: |
| 10722 | case ISD::SRA: |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10723 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
| Bob Wilson | 2e076c4 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 10724 | case ISD::SIGN_EXTEND: |
| 10725 | case ISD::ZERO_EXTEND: |
| Bob Wilson | c6c13a3 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 10726 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| Evan Cheng | f863e3f | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 10727 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10728 | case ISD::LOAD: return PerformLOADCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10729 | case ARMISD::VLD2DUP: |
| 10730 | case ARMISD::VLD3DUP: |
| 10731 | case ARMISD::VLD4DUP: |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10732 | return PerformVLDCombine(N, DCI); |
| Quentin Colombet | 04b3a0f | 2013-07-03 21:42:57 +0000 | [diff] [blame] | 10733 | case ARMISD::BUILD_VECTOR: |
| 10734 | return PerformARMBUILD_VECTORCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10735 | case ISD::INTRINSIC_VOID: |
| 10736 | case ISD::INTRINSIC_W_CHAIN: |
| 10737 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 10738 | case Intrinsic::arm_neon_vld1: |
| 10739 | case Intrinsic::arm_neon_vld2: |
| 10740 | case Intrinsic::arm_neon_vld3: |
| 10741 | case Intrinsic::arm_neon_vld4: |
| 10742 | case Intrinsic::arm_neon_vld2lane: |
| 10743 | case Intrinsic::arm_neon_vld3lane: |
| 10744 | case Intrinsic::arm_neon_vld4lane: |
| 10745 | case Intrinsic::arm_neon_vst1: |
| 10746 | case Intrinsic::arm_neon_vst2: |
| 10747 | case Intrinsic::arm_neon_vst3: |
| 10748 | case Intrinsic::arm_neon_vst4: |
| 10749 | case Intrinsic::arm_neon_vst2lane: |
| 10750 | case Intrinsic::arm_neon_vst3lane: |
| 10751 | case Intrinsic::arm_neon_vst4lane: |
| Ahmed Bougacha | db141ac | 2015-02-19 23:52:41 +0000 | [diff] [blame] | 10752 | return PerformVLDCombine(N, DCI); |
| Bob Wilson | 06fce87 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 10753 | default: break; |
| 10754 | } |
| 10755 | break; |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10756 | } |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 10757 | return SDValue(); |
| Chris Lattner | f3f4ad9 | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 10758 | } |
| 10759 | |
| Evan Cheng | d42641c | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 10760 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 10761 | EVT VT) const { |
| 10762 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 10763 | } |
| 10764 | |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10765 | bool ARMTargetLowering::allowsMisalignedMemoryAccesses(EVT VT, |
| 10766 | unsigned, |
| 10767 | unsigned, |
| 10768 | bool *Fast) const { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10769 | // The AllowsUnaliged flag models the SCTLR.A setting in ARM cpus |
| Chad Rosier | 66bb178 | 2012-11-09 18:25:27 +0000 | [diff] [blame] | 10770 | bool AllowsUnaligned = Subtarget->allowsUnalignedMem(); |
| Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 10771 | |
| 10772 | switch (VT.getSimpleVT().SimpleTy) { |
| 10773 | default: |
| 10774 | return false; |
| 10775 | case MVT::i8: |
| 10776 | case MVT::i16: |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10777 | case MVT::i32: { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10778 | // Unaligned access can use (for example) LRDB, LRDH, LDR |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10779 | if (AllowsUnaligned) { |
| 10780 | if (Fast) |
| 10781 | *Fast = Subtarget->hasV7Ops(); |
| 10782 | return true; |
| 10783 | } |
| 10784 | return false; |
| 10785 | } |
| Evan Cheng | eec6bc6 | 2012-08-15 17:44:53 +0000 | [diff] [blame] | 10786 | case MVT::f64: |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10787 | case MVT::v2f64: { |
| Evan Cheng | 90ae8f8 | 2012-09-18 01:42:45 +0000 | [diff] [blame] | 10788 | // For any little-endian targets with neon, we can support unaligned ld/st |
| 10789 | // 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] | 10790 | // A big-endian target may also explicitly support unaligned accesses |
| Mehdi Amini | ffc1402 | 2015-07-08 01:00:38 +0000 | [diff] [blame] | 10791 | if (Subtarget->hasNEON() && (AllowsUnaligned || Subtarget->isLittle())) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10792 | if (Fast) |
| 10793 | *Fast = true; |
| 10794 | return true; |
| 10795 | } |
| 10796 | return false; |
| 10797 | } |
| Bill Wendling | bae6b2c | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 10798 | } |
| 10799 | } |
| 10800 | |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10801 | static bool memOpAlign(unsigned DstAlign, unsigned SrcAlign, |
| 10802 | unsigned AlignCheck) { |
| 10803 | return ((SrcAlign == 0 || SrcAlign % AlignCheck == 0) && |
| 10804 | (DstAlign == 0 || DstAlign % AlignCheck == 0)); |
| 10805 | } |
| 10806 | |
| 10807 | EVT ARMTargetLowering::getOptimalMemOpType(uint64_t Size, |
| 10808 | unsigned DstAlign, unsigned SrcAlign, |
| Evan Cheng | 962711e | 2012-12-12 02:34:41 +0000 | [diff] [blame] | 10809 | bool IsMemset, bool ZeroMemset, |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10810 | bool MemcpyStrSrc, |
| 10811 | MachineFunction &MF) const { |
| 10812 | const Function *F = MF.getFunction(); |
| 10813 | |
| 10814 | // See if we can use NEON instructions for this... |
| Duncan P. N. Exon Smith | 2cff9e1 | 2015-02-14 02:24:44 +0000 | [diff] [blame] | 10815 | if ((!IsMemset || ZeroMemset) && Subtarget->hasNEON() && |
| 10816 | !F->hasFnAttribute(Attribute::NoImplicitFloat)) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10817 | bool Fast; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10818 | if (Size >= 16 && |
| 10819 | (memOpAlign(SrcAlign, DstAlign, 16) || |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10820 | (allowsMisalignedMemoryAccesses(MVT::v2f64, 0, 1, &Fast) && Fast))) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10821 | return MVT::v2f64; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10822 | } else if (Size >= 8 && |
| 10823 | (memOpAlign(SrcAlign, DstAlign, 8) || |
| Matt Arsenault | 6f2a526 | 2014-07-27 17:46:40 +0000 | [diff] [blame] | 10824 | (allowsMisalignedMemoryAccesses(MVT::f64, 0, 1, &Fast) && |
| 10825 | Fast))) { |
| Evan Cheng | 79e2ca9 | 2012-12-10 23:21:26 +0000 | [diff] [blame] | 10826 | return MVT::f64; |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10827 | } |
| 10828 | } |
| 10829 | |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10830 | // Lowering to i32/i16 if the size permits. |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10831 | if (Size >= 4) |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10832 | return MVT::i32; |
| Evan Cheng | c2bd620 | 2012-12-11 02:31:57 +0000 | [diff] [blame] | 10833 | else if (Size >= 2) |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10834 | return MVT::i16; |
| Lang Hames | b85fcd0 | 2011-11-08 18:56:23 +0000 | [diff] [blame] | 10835 | |
| Lang Hames | 9929c42 | 2011-11-02 22:52:45 +0000 | [diff] [blame] | 10836 | // Let the target-independent logic figure it out. |
| 10837 | return MVT::Other; |
| 10838 | } |
| 10839 | |
| Evan Cheng | 9ec512d | 2012-12-06 19:13:27 +0000 | [diff] [blame] | 10840 | bool ARMTargetLowering::isZExtFree(SDValue Val, EVT VT2) const { |
| 10841 | if (Val.getOpcode() != ISD::LOAD) |
| 10842 | return false; |
| 10843 | |
| 10844 | EVT VT1 = Val.getValueType(); |
| 10845 | if (!VT1.isSimple() || !VT1.isInteger() || |
| 10846 | !VT2.isSimple() || !VT2.isInteger()) |
| 10847 | return false; |
| 10848 | |
| 10849 | switch (VT1.getSimpleVT().SimpleTy) { |
| 10850 | default: break; |
| 10851 | case MVT::i1: |
| 10852 | case MVT::i8: |
| 10853 | case MVT::i16: |
| 10854 | // 8-bit and 16-bit loads implicitly zero-extend to 32-bits. |
| 10855 | return true; |
| 10856 | } |
| 10857 | |
| 10858 | return false; |
| 10859 | } |
| 10860 | |
| Ahmed Bougacha | 4200cc9 | 2015-03-05 19:37:53 +0000 | [diff] [blame] | 10861 | bool ARMTargetLowering::isVectorLoadExtDesirable(SDValue ExtVal) const { |
| 10862 | EVT VT = ExtVal.getValueType(); |
| 10863 | |
| 10864 | if (!isTypeLegal(VT)) |
| 10865 | return false; |
| 10866 | |
| 10867 | // Don't create a loadext if we can fold the extension into a wide/long |
| 10868 | // instruction. |
| 10869 | // If there's more than one user instruction, the loadext is desirable no |
| 10870 | // matter what. There can be two uses by the same instruction. |
| 10871 | if (ExtVal->use_empty() || |
| 10872 | !ExtVal->use_begin()->isOnlyUserOf(ExtVal.getNode())) |
| 10873 | return true; |
| 10874 | |
| 10875 | SDNode *U = *ExtVal->use_begin(); |
| 10876 | if ((U->getOpcode() == ISD::ADD || U->getOpcode() == ISD::SUB || |
| 10877 | U->getOpcode() == ISD::SHL || U->getOpcode() == ARMISD::VSHL)) |
| 10878 | return false; |
| 10879 | |
| 10880 | return true; |
| 10881 | } |
| 10882 | |
| Tim Northover | cc2e903 | 2013-08-06 13:58:03 +0000 | [diff] [blame] | 10883 | bool ARMTargetLowering::allowTruncateForTailCall(Type *Ty1, Type *Ty2) const { |
| 10884 | if (!Ty1->isIntegerTy() || !Ty2->isIntegerTy()) |
| 10885 | return false; |
| 10886 | |
| 10887 | if (!isTypeLegal(EVT::getEVT(Ty1))) |
| 10888 | return false; |
| 10889 | |
| 10890 | assert(Ty1->getPrimitiveSizeInBits() <= 64 && "i128 is probably not a noop"); |
| 10891 | |
| 10892 | // Assuming the caller doesn't have a zeroext or signext return parameter, |
| 10893 | // truncation all the way down to i1 is valid. |
| 10894 | return true; |
| 10895 | } |
| 10896 | |
| 10897 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10898 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 10899 | if (V < 0) |
| 10900 | return false; |
| 10901 | |
| 10902 | unsigned Scale = 1; |
| 10903 | switch (VT.getSimpleVT().SimpleTy) { |
| 10904 | default: return false; |
| 10905 | case MVT::i1: |
| 10906 | case MVT::i8: |
| 10907 | // Scale == 1; |
| 10908 | break; |
| 10909 | case MVT::i16: |
| 10910 | // Scale == 2; |
| 10911 | Scale = 2; |
| 10912 | break; |
| 10913 | case MVT::i32: |
| 10914 | // Scale == 4; |
| 10915 | Scale = 4; |
| 10916 | break; |
| 10917 | } |
| 10918 | |
| 10919 | if ((V & (Scale - 1)) != 0) |
| 10920 | return false; |
| 10921 | V /= Scale; |
| 10922 | return V == (V & ((1LL << 5) - 1)); |
| 10923 | } |
| 10924 | |
| 10925 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 10926 | const ARMSubtarget *Subtarget) { |
| 10927 | bool isNeg = false; |
| 10928 | if (V < 0) { |
| 10929 | isNeg = true; |
| 10930 | V = - V; |
| 10931 | } |
| 10932 | |
| 10933 | switch (VT.getSimpleVT().SimpleTy) { |
| 10934 | default: return false; |
| 10935 | case MVT::i1: |
| 10936 | case MVT::i8: |
| 10937 | case MVT::i16: |
| 10938 | case MVT::i32: |
| 10939 | // + imm12 or - imm8 |
| 10940 | if (isNeg) |
| 10941 | return V == (V & ((1LL << 8) - 1)); |
| 10942 | return V == (V & ((1LL << 12) - 1)); |
| 10943 | case MVT::f32: |
| 10944 | case MVT::f64: |
| 10945 | // Same as ARM mode. FIXME: NEON? |
| 10946 | if (!Subtarget->hasVFP2()) |
| 10947 | return false; |
| 10948 | if ((V & 3) != 0) |
| 10949 | return false; |
| 10950 | V >>= 2; |
| 10951 | return V == (V & ((1LL << 8) - 1)); |
| 10952 | } |
| 10953 | } |
| 10954 | |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10955 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 10956 | /// as the offset of the target addressing mode for load / store of the |
| 10957 | /// given type. |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 10958 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 10959 | const ARMSubtarget *Subtarget) { |
| Evan Cheng | 507eefa | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 10960 | if (V == 0) |
| 10961 | return true; |
| 10962 | |
| Evan Cheng | ce5dfb6 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 10963 | if (!VT.isSimple()) |
| 10964 | return false; |
| 10965 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10966 | if (Subtarget->isThumb1Only()) |
| 10967 | return isLegalT1AddressImmediate(V, VT); |
| 10968 | else if (Subtarget->isThumb2()) |
| 10969 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10970 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10971 | // ARM mode. |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10972 | if (V < 0) |
| 10973 | V = - V; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10974 | switch (VT.getSimpleVT().SimpleTy) { |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10975 | default: return false; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10976 | case MVT::i1: |
| 10977 | case MVT::i8: |
| 10978 | case MVT::i32: |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10979 | // +- imm12 |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10980 | return V == (V & ((1LL << 12) - 1)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10981 | case MVT::i16: |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10982 | // +- imm8 |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10983 | return V == (V & ((1LL << 8) - 1)); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 10984 | case MVT::f32: |
| 10985 | case MVT::f64: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10986 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10987 | return false; |
| Evan Cheng | bef131de | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 10988 | if ((V & 3) != 0) |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10989 | return false; |
| 10990 | V >>= 2; |
| Anton Korobeynikov | 40d67c5 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 10991 | return V == (V & ((1LL << 8) - 1)); |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 10992 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 10993 | } |
| 10994 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 10995 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 10996 | EVT VT) const { |
| 10997 | int Scale = AM.Scale; |
| 10998 | if (Scale < 0) |
| 10999 | return false; |
| 11000 | |
| 11001 | switch (VT.getSimpleVT().SimpleTy) { |
| 11002 | default: return false; |
| 11003 | case MVT::i1: |
| 11004 | case MVT::i8: |
| 11005 | case MVT::i16: |
| 11006 | case MVT::i32: |
| 11007 | if (Scale == 1) |
| 11008 | return true; |
| 11009 | // r + r << imm |
| 11010 | Scale = Scale & ~1; |
| 11011 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 11012 | case MVT::i64: |
| 11013 | // r + r |
| 11014 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 11015 | return true; |
| 11016 | return false; |
| 11017 | case MVT::isVoid: |
| 11018 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 11019 | // stores), because arm allows folding a scale into many arithmetic |
| 11020 | // operations. This should be made more precise and revisited later. |
| 11021 | |
| 11022 | // Allow r << imm, but the imm has to be a multiple of two. |
| 11023 | if (Scale & 1) return false; |
| 11024 | return isPowerOf2_32(Scale); |
| 11025 | } |
| 11026 | } |
| 11027 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11028 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 11029 | /// 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] | 11030 | bool ARMTargetLowering::isLegalAddressingMode(const DataLayout &DL, |
| 11031 | const AddrMode &AM, Type *Ty, |
| Matt Arsenault | bd7d80a | 2015-06-01 05:31:59 +0000 | [diff] [blame] | 11032 | unsigned AS) const { |
| Mehdi Amini | 0cdec1e | 2015-07-09 02:09:40 +0000 | [diff] [blame] | 11033 | EVT VT = getValueType(DL, Ty, true); |
| Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 11034 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 11035 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11036 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11037 | // Can never fold addr of global into load/store. |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11038 | if (AM.BaseGV) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11039 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11040 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11041 | switch (AM.Scale) { |
| 11042 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 11043 | break; |
| 11044 | case 1: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 11045 | if (Subtarget->isThumb1Only()) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11046 | return false; |
| Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 11047 | // FALL THROUGH. |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11048 | default: |
| Chris Lattner | 502c3f4 | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 11049 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 11050 | if (AM.BaseOffs) |
| 11051 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11052 | |
| Bob Wilson | 866c174 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 11053 | if (!VT.isSimple()) |
| 11054 | return false; |
| 11055 | |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 11056 | if (Subtarget->isThumb2()) |
| 11057 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 11058 | |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 11059 | int Scale = AM.Scale; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11060 | switch (VT.getSimpleVT().SimpleTy) { |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11061 | default: return false; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11062 | case MVT::i1: |
| 11063 | case MVT::i8: |
| 11064 | case MVT::i32: |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 11065 | if (Scale < 0) Scale = -Scale; |
| 11066 | if (Scale == 1) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11067 | return true; |
| 11068 | // r + r << imm |
| Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 11069 | return isPowerOf2_32(Scale & ~1); |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11070 | case MVT::i16: |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 11071 | case MVT::i64: |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11072 | // r + r |
| Chris Lattner | 9b6d69e | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 11073 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11074 | return true; |
| Chris Lattner | fe926e2 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 11075 | return false; |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11076 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11077 | case MVT::isVoid: |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11078 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 11079 | // stores), because arm allows folding a scale into many arithmetic |
| 11080 | // operations. This should be made more precise and revisited later. |
| Bob Wilson | 7117a91 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 11081 | |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11082 | // 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] | 11083 | if (Scale & 1) return false; |
| 11084 | return isPowerOf2_32(Scale); |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11085 | } |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 11086 | } |
| Chris Lattner | d44e24c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 11087 | return true; |
| Evan Cheng | 2150b92 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 11088 | } |
| 11089 | |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 11090 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 11091 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 11092 | /// a register against the immediate without having to materialize the |
| 11093 | /// immediate into a register. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 11094 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
| Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 11095 | // Thumb2 and ARM modes can use cmn for negative immediates. |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 11096 | if (!Subtarget->isThumb()) |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 11097 | return ARM_AM::getSOImmVal(std::abs(Imm)) != -1; |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 11098 | if (Subtarget->isThumb2()) |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 11099 | return ARM_AM::getT2SOImmVal(std::abs(Imm)) != -1; |
| Jakob Stoklund Olesen | 967b86a | 2012-04-06 17:45:04 +0000 | [diff] [blame] | 11100 | // Thumb1 doesn't have cmn, and only 8-bit immediates. |
| Evan Cheng | 15b80e4 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 11101 | return Imm >= 0 && Imm <= 255; |
| Evan Cheng | 3d3c24a | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 11102 | } |
| 11103 | |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 11104 | /// isLegalAddImmediate - Return true if the specified immediate is a legal add |
| 11105 | /// *or sub* immediate, that is the target has add or sub instructions which can |
| 11106 | /// add a register with the immediate without having to materialize the |
| Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 11107 | /// immediate into a register. |
| 11108 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 11109 | // Same encoding for add/sub, just flip the sign. |
| Benjamin Kramer | 7bd1f7c | 2015-03-09 20:20:16 +0000 | [diff] [blame] | 11110 | int64_t AbsImm = std::abs(Imm); |
| Andrew Trick | a22cdb7 | 2012-07-18 18:34:27 +0000 | [diff] [blame] | 11111 | if (!Subtarget->isThumb()) |
| 11112 | return ARM_AM::getSOImmVal(AbsImm) != -1; |
| 11113 | if (Subtarget->isThumb2()) |
| 11114 | return ARM_AM::getT2SOImmVal(AbsImm) != -1; |
| 11115 | // Thumb1 only has 8-bit unsigned immediate. |
| 11116 | return AbsImm >= 0 && AbsImm <= 255; |
| Dan Gohman | 6136e94 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 11117 | } |
| 11118 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 11119 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11120 | bool isSEXTLoad, SDValue &Base, |
| 11121 | SDValue &Offset, bool &isInc, |
| 11122 | SelectionDAG &DAG) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11123 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 11124 | return false; |
| 11125 | |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11126 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11127 | // AddressingMode 3 |
| 11128 | Base = Ptr->getOperand(0); |
| 11129 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 11130 | int RHSC = (int)RHS->getZExtValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11131 | if (RHSC < 0 && RHSC > -256) { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11132 | assert(Ptr->getOpcode() == ISD::ADD); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11133 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11134 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11135 | return true; |
| 11136 | } |
| 11137 | } |
| 11138 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 11139 | Offset = Ptr->getOperand(1); |
| 11140 | return true; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11141 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11142 | // AddressingMode 2 |
| 11143 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| Dan Gohman | effb894 | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 11144 | int RHSC = (int)RHS->getZExtValue(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11145 | if (RHSC < 0 && RHSC > -0x1000) { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11146 | assert(Ptr->getOpcode() == ISD::ADD); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11147 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11148 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11149 | Base = Ptr->getOperand(0); |
| 11150 | return true; |
| 11151 | } |
| 11152 | } |
| 11153 | |
| 11154 | if (Ptr->getOpcode() == ISD::ADD) { |
| 11155 | isInc = true; |
| Evan Cheng | a20cde3 | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 11156 | ARM_AM::ShiftOpc ShOpcVal= |
| 11157 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11158 | if (ShOpcVal != ARM_AM::no_shift) { |
| 11159 | Base = Ptr->getOperand(1); |
| 11160 | Offset = Ptr->getOperand(0); |
| 11161 | } else { |
| 11162 | Base = Ptr->getOperand(0); |
| 11163 | Offset = Ptr->getOperand(1); |
| 11164 | } |
| 11165 | return true; |
| 11166 | } |
| 11167 | |
| 11168 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 11169 | Base = Ptr->getOperand(0); |
| 11170 | Offset = Ptr->getOperand(1); |
| 11171 | return true; |
| 11172 | } |
| 11173 | |
| Jim Grosbach | d7cf55c | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 11174 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11175 | return false; |
| 11176 | } |
| 11177 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 11178 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11179 | bool isSEXTLoad, SDValue &Base, |
| 11180 | SDValue &Offset, bool &isInc, |
| 11181 | SelectionDAG &DAG) { |
| 11182 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 11183 | return false; |
| 11184 | |
| 11185 | Base = Ptr->getOperand(0); |
| 11186 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 11187 | int RHSC = (int)RHS->getZExtValue(); |
| 11188 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 11189 | assert(Ptr->getOpcode() == ISD::ADD); |
| 11190 | isInc = false; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11191 | Offset = DAG.getConstant(-RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11192 | return true; |
| 11193 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 11194 | isInc = Ptr->getOpcode() == ISD::ADD; |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11195 | Offset = DAG.getConstant(RHSC, SDLoc(Ptr), RHS->getValueType(0)); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11196 | return true; |
| 11197 | } |
| 11198 | } |
| 11199 | |
| 11200 | return false; |
| 11201 | } |
| 11202 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11203 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 11204 | /// offset pointer and addressing mode by reference if the node's address |
| 11205 | /// can be legally represented as pre-indexed load / store address. |
| 11206 | bool |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11207 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 11208 | SDValue &Offset, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11209 | ISD::MemIndexedMode &AM, |
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 11210 | SelectionDAG &DAG) const { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11211 | if (Subtarget->isThumb1Only()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11212 | return false; |
| 11213 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 11214 | EVT VT; |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11215 | SDValue Ptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11216 | bool isSEXTLoad = false; |
| 11217 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 11218 | Ptr = LD->getBasePtr(); |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 11219 | VT = LD->getMemoryVT(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11220 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 11221 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 11222 | Ptr = ST->getBasePtr(); |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 11223 | VT = ST->getMemoryVT(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11224 | } else |
| 11225 | return false; |
| 11226 | |
| 11227 | bool isInc; |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11228 | bool isLegal = false; |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 11229 | if (Subtarget->isThumb2()) |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11230 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 11231 | Offset, isInc, DAG); |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 11232 | else |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11233 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| Evan Cheng | 844f0b4 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 11234 | Offset, isInc, DAG); |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11235 | if (!isLegal) |
| 11236 | return false; |
| 11237 | |
| 11238 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 11239 | return true; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11240 | } |
| 11241 | |
| 11242 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 11243 | /// offset pointer and addressing mode by reference if this node can be |
| 11244 | /// combined with a load / store to form a post-indexed load / store. |
| 11245 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11246 | SDValue &Base, |
| 11247 | SDValue &Offset, |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11248 | ISD::MemIndexedMode &AM, |
| Dan Gohman | 02b9313 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 11249 | SelectionDAG &DAG) const { |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11250 | if (Subtarget->isThumb1Only()) |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11251 | return false; |
| 11252 | |
| Owen Anderson | 53aa7a9 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 11253 | EVT VT; |
| Dan Gohman | 2ce6f2a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 11254 | SDValue Ptr; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11255 | bool isSEXTLoad = false; |
| 11256 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 11257 | VT = LD->getMemoryVT(); |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 11258 | Ptr = LD->getBasePtr(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11259 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 11260 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| Dan Gohman | 47a7d6f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 11261 | VT = ST->getMemoryVT(); |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 11262 | Ptr = ST->getBasePtr(); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11263 | } else |
| 11264 | return false; |
| 11265 | |
| 11266 | bool isInc; |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11267 | bool isLegal = false; |
| Evan Cheng | dc49a8d | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 11268 | if (Subtarget->isThumb2()) |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11269 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 11270 | isInc, DAG); |
| Jim Grosbach | f24f9d9 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 11271 | else |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11272 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 11273 | isInc, DAG); |
| 11274 | if (!isLegal) |
| 11275 | return false; |
| 11276 | |
| Evan Cheng | f19384d | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 11277 | if (Ptr != Base) { |
| 11278 | // Swap base ptr and offset to catch more post-index load / store when |
| 11279 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 11280 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 11281 | !Subtarget->isThumb2()) |
| 11282 | std::swap(Base, Offset); |
| 11283 | |
| 11284 | // Post-indexed load / store update the base pointer. |
| 11285 | if (Ptr != Base) |
| 11286 | return false; |
| 11287 | } |
| 11288 | |
| Evan Cheng | 84c6cda | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 11289 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 11290 | return true; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11291 | } |
| 11292 | |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11293 | void ARMTargetLowering::computeKnownBitsForTargetNode(const SDValue Op, |
| 11294 | APInt &KnownZero, |
| 11295 | APInt &KnownOne, |
| 11296 | const SelectionDAG &DAG, |
| 11297 | unsigned Depth) const { |
| Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 11298 | unsigned BitWidth = KnownOne.getBitWidth(); |
| 11299 | KnownZero = KnownOne = APInt(BitWidth, 0); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11300 | switch (Op.getOpcode()) { |
| 11301 | default: break; |
| Michael Gottesman | 696e44e | 2013-06-18 20:49:45 +0000 | [diff] [blame] | 11302 | case ARMISD::ADDC: |
| 11303 | case ARMISD::ADDE: |
| 11304 | case ARMISD::SUBC: |
| 11305 | case ARMISD::SUBE: |
| 11306 | // These nodes' second result is a boolean |
| 11307 | if (Op.getResNo() == 0) |
| 11308 | break; |
| 11309 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - 1); |
| 11310 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11311 | case ARMISD::CMOV: { |
| 11312 | // Bits are known zero/one if known on the LHS and RHS. |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11313 | DAG.computeKnownBits(Op.getOperand(0), KnownZero, KnownOne, Depth+1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11314 | if (KnownZero == 0 && KnownOne == 0) return; |
| 11315 | |
| Dan Gohman | f990faf | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 11316 | APInt KnownZeroRHS, KnownOneRHS; |
| Jay Foad | a0653a3 | 2014-05-14 21:14:37 +0000 | [diff] [blame] | 11317 | DAG.computeKnownBits(Op.getOperand(1), KnownZeroRHS, KnownOneRHS, Depth+1); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11318 | KnownZero &= KnownZeroRHS; |
| 11319 | KnownOne &= KnownOneRHS; |
| 11320 | return; |
| 11321 | } |
| Tim Northover | 01b4aa9 | 2014-04-03 15:10:35 +0000 | [diff] [blame] | 11322 | case ISD::INTRINSIC_W_CHAIN: { |
| 11323 | ConstantSDNode *CN = cast<ConstantSDNode>(Op->getOperand(1)); |
| 11324 | Intrinsic::ID IntID = static_cast<Intrinsic::ID>(CN->getZExtValue()); |
| 11325 | switch (IntID) { |
| 11326 | default: return; |
| 11327 | case Intrinsic::arm_ldaex: |
| 11328 | case Intrinsic::arm_ldrex: { |
| 11329 | EVT VT = cast<MemIntrinsicSDNode>(Op)->getMemoryVT(); |
| 11330 | unsigned MemBits = VT.getScalarType().getSizeInBits(); |
| 11331 | KnownZero |= APInt::getHighBitsSet(BitWidth, BitWidth - MemBits); |
| 11332 | return; |
| 11333 | } |
| 11334 | } |
| 11335 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11336 | } |
| 11337 | } |
| 11338 | |
| 11339 | //===----------------------------------------------------------------------===// |
| 11340 | // ARM Inline Assembly Support |
| 11341 | //===----------------------------------------------------------------------===// |
| 11342 | |
| Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 11343 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 11344 | // Looking for "rev" which is V6+. |
| 11345 | if (!Subtarget->hasV6Ops()) |
| 11346 | return false; |
| 11347 | |
| 11348 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 11349 | std::string AsmStr = IA->getAsmString(); |
| 11350 | SmallVector<StringRef, 4> AsmPieces; |
| 11351 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 11352 | |
| 11353 | switch (AsmPieces.size()) { |
| 11354 | default: return false; |
| 11355 | case 1: |
| 11356 | AsmStr = AsmPieces[0]; |
| 11357 | AsmPieces.clear(); |
| 11358 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 11359 | |
| 11360 | // rev $0, $1 |
| 11361 | if (AsmPieces.size() == 3 && |
| 11362 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 11363 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11364 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
| Evan Cheng | 078b0b0 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 11365 | if (Ty && Ty->getBitWidth() == 32) |
| 11366 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 11367 | } |
| 11368 | break; |
| 11369 | } |
| 11370 | |
| 11371 | return false; |
| 11372 | } |
| 11373 | |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11374 | /// getConstraintType - Given a constraint letter, return the type of |
| 11375 | /// constraint it is for this target. |
| 11376 | ARMTargetLowering::ConstraintType |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11377 | ARMTargetLowering::getConstraintType(StringRef Constraint) const { |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11378 | if (Constraint.size() == 1) { |
| 11379 | switch (Constraint[0]) { |
| 11380 | default: break; |
| 11381 | case 'l': return C_RegisterClass; |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11382 | case 'w': return C_RegisterClass; |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11383 | case 'h': return C_RegisterClass; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11384 | case 'x': return C_RegisterClass; |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11385 | case 't': return C_RegisterClass; |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11386 | case 'j': return C_Other; // Constant for movw. |
| Eric Christopher | aa50300 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 11387 | // An address with a single base register. Due to the way we |
| 11388 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 11389 | case 'Q': return C_Memory; |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11390 | } |
| Eric Christopher | e256cd0 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 11391 | } else if (Constraint.size() == 2) { |
| 11392 | switch (Constraint[0]) { |
| 11393 | default: break; |
| 11394 | // All 'U+' constraints are addresses. |
| 11395 | case 'U': return C_Memory; |
| 11396 | } |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11397 | } |
| Chris Lattner | d685514 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 11398 | return TargetLowering::getConstraintType(Constraint); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11399 | } |
| 11400 | |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11401 | /// Examine constraint type and operand type and determine a weight value. |
| 11402 | /// This object must already have been set up with the operand type |
| 11403 | /// and the current alternative constraint selected. |
| 11404 | TargetLowering::ConstraintWeight |
| 11405 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 11406 | AsmOperandInfo &info, const char *constraint) const { |
| 11407 | ConstraintWeight weight = CW_Invalid; |
| 11408 | Value *CallOperandVal = info.CallOperandVal; |
| 11409 | // If we don't have a value, we can't do a match, |
| 11410 | // but allow it at the lowest weight. |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11411 | if (!CallOperandVal) |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11412 | return CW_Default; |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11413 | Type *type = CallOperandVal->getType(); |
| John Thompson | e8360b7 | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 11414 | // Look at the constraint type. |
| 11415 | switch (*constraint) { |
| 11416 | default: |
| 11417 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 11418 | break; |
| 11419 | case 'l': |
| 11420 | if (type->isIntegerTy()) { |
| 11421 | if (Subtarget->isThumb()) |
| 11422 | weight = CW_SpecificReg; |
| 11423 | else |
| 11424 | weight = CW_Register; |
| 11425 | } |
| 11426 | break; |
| 11427 | case 'w': |
| 11428 | if (type->isFloatingPointTy()) |
| 11429 | weight = CW_Register; |
| 11430 | break; |
| 11431 | } |
| 11432 | return weight; |
| 11433 | } |
| 11434 | |
| Eric Christopher | cf2007c | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 11435 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| Benjamin Kramer | 9bfb627 | 2015-07-05 19:29:18 +0000 | [diff] [blame] | 11436 | RCPair ARMTargetLowering::getRegForInlineAsmConstraint( |
| 11437 | const TargetRegisterInfo *TRI, StringRef Constraint, MVT VT) const { |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11438 | if (Constraint.size() == 1) { |
| Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 11439 | // GCC ARM Constraint Letters |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11440 | switch (Constraint[0]) { |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11441 | case 'l': // Low regs or general regs. |
| Jakob Stoklund Olesen | 0ca14e4 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 11442 | if (Subtarget->isThumb()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11443 | return RCPair(0U, &ARM::tGPRRegClass); |
| 11444 | return RCPair(0U, &ARM::GPRRegClass); |
| Eric Christopher | f45daac | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 11445 | case 'h': // High regs or no regs. |
| 11446 | if (Subtarget->isThumb()) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11447 | return RCPair(0U, &ARM::hGPRRegClass); |
| Eric Christopher | f09b0f1 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 11448 | break; |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11449 | case 'r': |
| Akira Hatanaka | b961534 | 2014-11-03 20:37:04 +0000 | [diff] [blame] | 11450 | if (Subtarget->isThumb1Only()) |
| 11451 | return RCPair(0U, &ARM::tGPRRegClass); |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11452 | return RCPair(0U, &ARM::GPRRegClass); |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11453 | case 'w': |
| Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 11454 | if (VT == MVT::Other) |
| 11455 | break; |
| Owen Anderson | 9f94459 | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 11456 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11457 | return RCPair(0U, &ARM::SPRRegClass); |
| Bob Wilson | 3152b047 | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 11458 | if (VT.getSizeInBits() == 64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11459 | return RCPair(0U, &ARM::DPRRegClass); |
| Evan Cheng | 0c2544f | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 11460 | if (VT.getSizeInBits() == 128) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11461 | return RCPair(0U, &ARM::QPRRegClass); |
| Chris Lattner | 6223e83 | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 11462 | break; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11463 | case 'x': |
| Tim Northover | 28adfbb | 2013-11-14 17:15:39 +0000 | [diff] [blame] | 11464 | if (VT == MVT::Other) |
| 11465 | break; |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11466 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11467 | return RCPair(0U, &ARM::SPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11468 | if (VT.getSizeInBits() == 64) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11469 | return RCPair(0U, &ARM::DPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11470 | if (VT.getSizeInBits() == 128) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11471 | return RCPair(0U, &ARM::QPR_8RegClass); |
| Eric Christopher | f1c7459 | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 11472 | break; |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11473 | case 't': |
| 11474 | if (VT == MVT::f32) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11475 | return RCPair(0U, &ARM::SPRRegClass); |
| Eric Christopher | c011d31 | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 11476 | break; |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11477 | } |
| 11478 | } |
| Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 11479 | if (StringRef("{cc}").equals_lower(Constraint)) |
| Craig Topper | c7242e0 | 2012-04-20 07:30:17 +0000 | [diff] [blame] | 11480 | return std::make_pair(unsigned(ARM::CPSR), &ARM::CCRRegClass); |
| Bob Wilson | 3f2293b | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 11481 | |
| Eric Christopher | 11e4df7 | 2015-02-26 22:38:43 +0000 | [diff] [blame] | 11482 | return TargetLowering::getRegForInlineAsmConstraint(TRI, Constraint, VT); |
| Evan Cheng | 10043e2 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 11483 | } |
| 11484 | |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11485 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 11486 | /// vector. If it is invalid, don't add anything to Ops. |
| 11487 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11488 | std::string &Constraint, |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11489 | std::vector<SDValue>&Ops, |
| 11490 | SelectionDAG &DAG) const { |
| Craig Topper | 062a2ba | 2014-04-25 05:30:21 +0000 | [diff] [blame] | 11491 | SDValue Result; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11492 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11493 | // Currently only support length 1 constraints. |
| 11494 | if (Constraint.length() != 1) return; |
| Eric Christopher | 0713a9d | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 11495 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11496 | char ConstraintLetter = Constraint[0]; |
| 11497 | switch (ConstraintLetter) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11498 | default: break; |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11499 | case 'j': |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11500 | case 'I': case 'J': case 'K': case 'L': |
| 11501 | case 'M': case 'N': case 'O': |
| 11502 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 11503 | if (!C) |
| 11504 | return; |
| 11505 | |
| 11506 | int64_t CVal64 = C->getSExtValue(); |
| 11507 | int CVal = (int) CVal64; |
| 11508 | // None of these constraints allow values larger than 32 bits. Check |
| 11509 | // that the value fits in an int. |
| 11510 | if (CVal != CVal64) |
| 11511 | return; |
| 11512 | |
| Eric Christopher | de9399b | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 11513 | switch (ConstraintLetter) { |
| Eric Christopher | 29f1db8 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 11514 | case 'j': |
| Andrew Trick | 53df4b6 | 2011-09-20 03:06:13 +0000 | [diff] [blame] | 11515 | // Constant suitable for movw, must be between 0 and |
| 11516 | // 65535. |
| 11517 | if (Subtarget->hasV6T2Ops()) |
| 11518 | if (CVal >= 0 && CVal <= 65535) |
| 11519 | break; |
| 11520 | return; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11521 | case 'I': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11522 | if (Subtarget->isThumb1Only()) { |
| 11523 | // This must be a constant between 0 and 255, for ADD |
| 11524 | // immediates. |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11525 | if (CVal >= 0 && CVal <= 255) |
| 11526 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11527 | } else if (Subtarget->isThumb2()) { |
| 11528 | // A constant that can be used as an immediate value in a |
| 11529 | // data-processing instruction. |
| 11530 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 11531 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11532 | } else { |
| 11533 | // A constant that can be used as an immediate value in a |
| 11534 | // data-processing instruction. |
| 11535 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 11536 | break; |
| 11537 | } |
| 11538 | return; |
| 11539 | |
| 11540 | case 'J': |
| Eric Christopher | b793230 | 2016-01-08 00:34:44 +0000 | [diff] [blame] | 11541 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11542 | // This must be a constant between -255 and -1, for negated ADD |
| 11543 | // immediates. This can be used in GCC with an "n" modifier that |
| 11544 | // prints the negated value, for use with SUB instructions. It is |
| 11545 | // not useful otherwise but is implemented for compatibility. |
| 11546 | if (CVal >= -255 && CVal <= -1) |
| 11547 | break; |
| 11548 | } else { |
| 11549 | // This must be a constant between -4095 and 4095. It is not clear |
| 11550 | // what this constraint is intended for. Implemented for |
| 11551 | // compatibility with GCC. |
| 11552 | if (CVal >= -4095 && CVal <= 4095) |
| 11553 | break; |
| 11554 | } |
| 11555 | return; |
| 11556 | |
| 11557 | case 'K': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11558 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11559 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 11560 | // zero to match GCC. This constraint is used by GCC internally for |
| 11561 | // constants that can be loaded with a move/shift combination. |
| 11562 | // It is not useful otherwise but is implemented for compatibility. |
| 11563 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 11564 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11565 | } else if (Subtarget->isThumb2()) { |
| 11566 | // A constant whose bitwise inverse can be used as an immediate |
| 11567 | // value in a data-processing instruction. This can be used in GCC |
| 11568 | // with a "B" modifier that prints the inverted value, for use with |
| 11569 | // BIC and MVN instructions. It is not useful otherwise but is |
| 11570 | // implemented for compatibility. |
| 11571 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 11572 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11573 | } else { |
| 11574 | // A constant whose bitwise inverse can be used as an immediate |
| 11575 | // value in a data-processing instruction. This can be used in GCC |
| 11576 | // with a "B" modifier that prints the inverted value, for use with |
| 11577 | // BIC and MVN instructions. It is not useful otherwise but is |
| 11578 | // implemented for compatibility. |
| 11579 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 11580 | break; |
| 11581 | } |
| 11582 | return; |
| 11583 | |
| 11584 | case 'L': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11585 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11586 | // This must be a constant between -7 and 7, |
| 11587 | // for 3-operand ADD/SUB immediate instructions. |
| 11588 | if (CVal >= -7 && CVal < 7) |
| 11589 | break; |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11590 | } else if (Subtarget->isThumb2()) { |
| 11591 | // A constant whose negation can be used as an immediate value in a |
| 11592 | // data-processing instruction. This can be used in GCC with an "n" |
| 11593 | // modifier that prints the negated value, for use with SUB |
| 11594 | // instructions. It is not useful otherwise but is implemented for |
| 11595 | // compatibility. |
| 11596 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 11597 | break; |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11598 | } else { |
| 11599 | // A constant whose negation can be used as an immediate value in a |
| 11600 | // data-processing instruction. This can be used in GCC with an "n" |
| 11601 | // modifier that prints the negated value, for use with SUB |
| 11602 | // instructions. It is not useful otherwise but is implemented for |
| 11603 | // compatibility. |
| 11604 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 11605 | break; |
| 11606 | } |
| 11607 | return; |
| 11608 | |
| 11609 | case 'M': |
| Eric Christopher | b793230 | 2016-01-08 00:34:44 +0000 | [diff] [blame] | 11610 | if (Subtarget->isThumb1Only()) { |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11611 | // This must be a multiple of 4 between 0 and 1020, for |
| 11612 | // ADD sp + immediate. |
| 11613 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 11614 | break; |
| 11615 | } else { |
| 11616 | // A power of two or a constant between 0 and 32. This is used in |
| 11617 | // GCC for the shift amount on shifted register operands, but it is |
| 11618 | // useful in general for any shift amounts. |
| 11619 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 11620 | break; |
| 11621 | } |
| 11622 | return; |
| 11623 | |
| 11624 | case 'N': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11625 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11626 | // This must be a constant between 0 and 31, for shift amounts. |
| 11627 | if (CVal >= 0 && CVal <= 31) |
| 11628 | break; |
| 11629 | } |
| 11630 | return; |
| 11631 | |
| 11632 | case 'O': |
| David Goodwin | 22c2fba | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 11633 | if (Subtarget->isThumb()) { // FIXME thumb2 |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11634 | // This must be a multiple of 4 between -508 and 508, for |
| 11635 | // ADD/SUB sp = sp + immediate. |
| 11636 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 11637 | break; |
| 11638 | } |
| 11639 | return; |
| 11640 | } |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11641 | Result = DAG.getTargetConstant(CVal, SDLoc(Op), Op.getValueType()); |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11642 | break; |
| 11643 | } |
| 11644 | |
| 11645 | if (Result.getNode()) { |
| 11646 | Ops.push_back(Result); |
| 11647 | return; |
| 11648 | } |
| Dale Johannesen | ce97d55 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 11649 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
| Bob Wilson | cf1ec2c | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 11650 | } |
| Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 11651 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11652 | static RTLIB::Libcall getDivRemLibcall( |
| 11653 | const SDNode *N, MVT::SimpleValueType SVT) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11654 | assert((N->getOpcode() == ISD::SDIVREM || N->getOpcode() == ISD::UDIVREM || |
| 11655 | N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM) && |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11656 | "Unhandled Opcode in getDivRemLibcall"); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11657 | bool isSigned = N->getOpcode() == ISD::SDIVREM || |
| 11658 | N->getOpcode() == ISD::SREM; |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11659 | RTLIB::Libcall LC; |
| 11660 | switch (SVT) { |
| 11661 | default: llvm_unreachable("Unexpected request for libcall!"); |
| 11662 | case MVT::i8: LC = isSigned ? RTLIB::SDIVREM_I8 : RTLIB::UDIVREM_I8; break; |
| 11663 | case MVT::i16: LC = isSigned ? RTLIB::SDIVREM_I16 : RTLIB::UDIVREM_I16; break; |
| 11664 | case MVT::i32: LC = isSigned ? RTLIB::SDIVREM_I32 : RTLIB::UDIVREM_I32; break; |
| 11665 | case MVT::i64: LC = isSigned ? RTLIB::SDIVREM_I64 : RTLIB::UDIVREM_I64; break; |
| 11666 | } |
| 11667 | return LC; |
| 11668 | } |
| 11669 | |
| 11670 | static TargetLowering::ArgListTy getDivRemArgList( |
| 11671 | const SDNode *N, LLVMContext *Context) { |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11672 | assert((N->getOpcode() == ISD::SDIVREM || N->getOpcode() == ISD::UDIVREM || |
| 11673 | N->getOpcode() == ISD::SREM || N->getOpcode() == ISD::UREM) && |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11674 | "Unhandled Opcode in getDivRemArgList"); |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11675 | bool isSigned = N->getOpcode() == ISD::SDIVREM || |
| 11676 | N->getOpcode() == ISD::SREM; |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11677 | TargetLowering::ArgListTy Args; |
| 11678 | TargetLowering::ArgListEntry Entry; |
| 11679 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 11680 | EVT ArgVT = N->getOperand(i).getValueType(); |
| 11681 | Type *ArgTy = ArgVT.getTypeForEVT(*Context); |
| 11682 | Entry.Node = N->getOperand(i); |
| 11683 | Entry.Ty = ArgTy; |
| 11684 | Entry.isSExt = isSigned; |
| 11685 | Entry.isZExt = !isSigned; |
| 11686 | Args.push_back(Entry); |
| 11687 | } |
| 11688 | return Args; |
| 11689 | } |
| 11690 | |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11691 | SDValue ARMTargetLowering::LowerDivRem(SDValue Op, SelectionDAG &DAG) const { |
| Renato Golin | 6027dd38e | 2016-02-03 16:10:54 +0000 | [diff] [blame] | 11692 | assert((Subtarget->isTargetAEABI() || Subtarget->isTargetAndroid() || |
| 11693 | Subtarget->isTargetGNUAEABI()) && |
| Sumanth Gundapaneni | 532a136 | 2015-07-31 00:45:12 +0000 | [diff] [blame] | 11694 | "Register-based DivRem lowering only"); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11695 | unsigned Opcode = Op->getOpcode(); |
| 11696 | assert((Opcode == ISD::SDIVREM || Opcode == ISD::UDIVREM) && |
| Saleem Abdulrasool | 740be89 | 2014-08-17 22:50:59 +0000 | [diff] [blame] | 11697 | "Invalid opcode for Div/Rem lowering"); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11698 | bool isSigned = (Opcode == ISD::SDIVREM); |
| 11699 | EVT VT = Op->getValueType(0); |
| 11700 | Type *Ty = VT.getTypeForEVT(*DAG.getContext()); |
| 11701 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11702 | RTLIB::Libcall LC = getDivRemLibcall(Op.getNode(), |
| 11703 | VT.getSimpleVT().SimpleTy); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11704 | SDValue InChain = DAG.getEntryNode(); |
| 11705 | |
| Scott Douglass | d2974a6 | 2015-08-24 09:17:11 +0000 | [diff] [blame] | 11706 | TargetLowering::ArgListTy Args = getDivRemArgList(Op.getNode(), |
| 11707 | DAG.getContext()); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11708 | |
| 11709 | SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), |
| Mehdi Amini | 44ede33 | 2015-07-09 02:09:04 +0000 | [diff] [blame] | 11710 | getPointerTy(DAG.getDataLayout())); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11711 | |
| Reid Kleckner | 343c395 | 2014-11-20 23:51:47 +0000 | [diff] [blame] | 11712 | Type *RetTy = (Type*)StructType::get(Ty, Ty, nullptr); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11713 | |
| 11714 | SDLoc dl(Op); |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11715 | TargetLowering::CallLoweringInfo CLI(DAG); |
| 11716 | CLI.setDebugLoc(dl).setChain(InChain) |
| Juergen Ributzka | 3bd03c7 | 2014-07-01 22:01:54 +0000 | [diff] [blame] | 11717 | .setCallee(getLibcallCallingConv(LC), RetTy, Callee, std::move(Args), 0) |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11718 | .setInRegister().setSExtResult(isSigned).setZExtResult(!isSigned); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11719 | |
| Saleem Abdulrasool | f3a5a5c | 2014-05-17 21:50:17 +0000 | [diff] [blame] | 11720 | std::pair<SDValue, SDValue> CallInfo = LowerCallTo(CLI); |
| Renato Golin | 8761069 | 2013-07-16 09:32:17 +0000 | [diff] [blame] | 11721 | return CallInfo.first; |
| 11722 | } |
| 11723 | |
| Scott Douglass | bdef604 | 2015-08-24 09:17:18 +0000 | [diff] [blame] | 11724 | // Lowers REM using divmod helpers |
| 11725 | // see RTABI section 4.2/4.3 |
| 11726 | SDValue ARMTargetLowering::LowerREM(SDNode *N, SelectionDAG &DAG) const { |
| 11727 | // Build return types (div and rem) |
| 11728 | std::vector<Type*> RetTyParams; |
| 11729 | Type *RetTyElement; |
| 11730 | |
| 11731 | switch (N->getValueType(0).getSimpleVT().SimpleTy) { |
| 11732 | default: llvm_unreachable("Unexpected request for libcall!"); |
| 11733 | case MVT::i8: RetTyElement = Type::getInt8Ty(*DAG.getContext()); break; |
| 11734 | case MVT::i16: RetTyElement = Type::getInt16Ty(*DAG.getContext()); break; |
| 11735 | case MVT::i32: RetTyElement = Type::getInt32Ty(*DAG.getContext()); break; |
| 11736 | case MVT::i64: RetTyElement = Type::getInt64Ty(*DAG.getContext()); break; |
| 11737 | } |
| 11738 | |
| 11739 | RetTyParams.push_back(RetTyElement); |
| 11740 | RetTyParams.push_back(RetTyElement); |
| 11741 | ArrayRef<Type*> ret = ArrayRef<Type*>(RetTyParams); |
| 11742 | Type *RetTy = StructType::get(*DAG.getContext(), ret); |
| 11743 | |
| 11744 | RTLIB::Libcall LC = getDivRemLibcall(N, N->getValueType(0).getSimpleVT(). |
| 11745 | SimpleTy); |
| 11746 | SDValue InChain = DAG.getEntryNode(); |
| 11747 | TargetLowering::ArgListTy Args = getDivRemArgList(N, DAG.getContext()); |
| 11748 | bool isSigned = N->getOpcode() == ISD::SREM; |
| 11749 | SDValue Callee = DAG.getExternalSymbol(getLibcallName(LC), |
| 11750 | getPointerTy(DAG.getDataLayout())); |
| 11751 | |
| 11752 | // Lower call |
| 11753 | CallLoweringInfo CLI(DAG); |
| 11754 | CLI.setChain(InChain) |
| 11755 | .setCallee(CallingConv::ARM_AAPCS, RetTy, Callee, std::move(Args), 0) |
| 11756 | .setSExtResult(isSigned).setZExtResult(!isSigned).setDebugLoc(SDLoc(N)); |
| 11757 | std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI); |
| 11758 | |
| 11759 | // Return second (rem) result operand (first contains div) |
| 11760 | SDNode *ResNode = CallResult.first.getNode(); |
| 11761 | assert(ResNode->getNumOperands() == 2 && "divmod should return two operands"); |
| 11762 | return ResNode->getOperand(1); |
| 11763 | } |
| 11764 | |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11765 | SDValue |
| 11766 | ARMTargetLowering::LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const { |
| 11767 | assert(Subtarget->isTargetWindows() && "unsupported target platform"); |
| 11768 | SDLoc DL(Op); |
| 11769 | |
| 11770 | // Get the inputs. |
| 11771 | SDValue Chain = Op.getOperand(0); |
| 11772 | SDValue Size = Op.getOperand(1); |
| 11773 | |
| 11774 | SDValue Words = DAG.getNode(ISD::SRL, DL, MVT::i32, Size, |
| Sergey Dmitrouk | 842a51b | 2015-04-28 14:05:47 +0000 | [diff] [blame] | 11775 | DAG.getConstant(2, DL, MVT::i32)); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11776 | |
| 11777 | SDValue Flag; |
| 11778 | Chain = DAG.getCopyToReg(Chain, DL, ARM::R4, Words, Flag); |
| 11779 | Flag = Chain.getValue(1); |
| 11780 | |
| Saleem Abdulrasool | c4e0028 | 2014-07-19 01:29:51 +0000 | [diff] [blame] | 11781 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
| Saleem Abdulrasool | abac6e9 | 2014-06-09 20:18:42 +0000 | [diff] [blame] | 11782 | Chain = DAG.getNode(ARMISD::WIN__CHKSTK, DL, NodeTys, Chain, Flag); |
| 11783 | |
| 11784 | SDValue NewSP = DAG.getCopyFromReg(Chain, DL, ARM::SP, MVT::i32); |
| 11785 | Chain = NewSP.getValue(1); |
| 11786 | |
| 11787 | SDValue Ops[2] = { NewSP, Chain }; |
| 11788 | return DAG.getMergeValues(Ops, DL); |
| 11789 | } |
| 11790 | |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11791 | SDValue ARMTargetLowering::LowerFP_EXTEND(SDValue Op, SelectionDAG &DAG) const { |
| 11792 | assert(Op.getValueType() == MVT::f64 && Subtarget->isFPOnlySP() && |
| 11793 | "Unexpected type for custom-lowering FP_EXTEND"); |
| 11794 | |
| 11795 | RTLIB::Libcall LC; |
| 11796 | LC = RTLIB::getFPEXT(Op.getOperand(0).getValueType(), Op.getValueType()); |
| 11797 | |
| 11798 | SDValue SrcVal = Op.getOperand(0); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 11799 | return makeLibCall(DAG, LC, Op.getValueType(), SrcVal, /*isSigned*/ false, |
| 11800 | SDLoc(Op)).first; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11801 | } |
| 11802 | |
| 11803 | SDValue ARMTargetLowering::LowerFP_ROUND(SDValue Op, SelectionDAG &DAG) const { |
| 11804 | assert(Op.getOperand(0).getValueType() == MVT::f64 && |
| 11805 | Subtarget->isFPOnlySP() && |
| 11806 | "Unexpected type for custom-lowering FP_ROUND"); |
| 11807 | |
| 11808 | RTLIB::Libcall LC; |
| 11809 | LC = RTLIB::getFPROUND(Op.getOperand(0).getValueType(), Op.getValueType()); |
| 11810 | |
| 11811 | SDValue SrcVal = Op.getOperand(0); |
| Craig Topper | 8fe40e0 | 2015-10-22 17:05:00 +0000 | [diff] [blame] | 11812 | return makeLibCall(DAG, LC, Op.getValueType(), SrcVal, /*isSigned*/ false, |
| 11813 | SDLoc(Op)).first; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11814 | } |
| 11815 | |
| Anton Korobeynikov | 29a44df | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 11816 | bool |
| 11817 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 11818 | // The ARM target isn't yet aware of offsets. |
| 11819 | return false; |
| 11820 | } |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11821 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11822 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 11823 | if (v == 0xffffffff) |
| Benjamin Kramer | 8bad66e | 2013-05-19 22:01:57 +0000 | [diff] [blame] | 11824 | return false; |
| 11825 | |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11826 | // there can be 1's on either or both "outsides", all the "inside" |
| 11827 | // bits must be 0's |
| Benjamin Kramer | 5f6a907 | 2015-02-12 15:35:40 +0000 | [diff] [blame] | 11828 | return isShiftedMask_32(~v); |
| Jim Grosbach | 11013ed | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 11829 | } |
| 11830 | |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11831 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 11832 | /// specified FP immediate natively. If false, the legalizer will |
| 11833 | /// materialize the FP immediate as a load from a constant pool. |
| 11834 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 11835 | if (!Subtarget->hasVFP3()) |
| 11836 | return false; |
| 11837 | if (VT == MVT::f32) |
| Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 11838 | return ARM_AM::getFP32Imm(Imm) != -1; |
| Oliver Stannard | 51b1d46 | 2014-08-21 12:50:31 +0000 | [diff] [blame] | 11839 | if (VT == MVT::f64 && !Subtarget->isFPOnlySP()) |
| Jim Grosbach | efc761a | 2011-09-30 00:50:06 +0000 | [diff] [blame] | 11840 | return ARM_AM::getFP64Imm(Imm) != -1; |
| Evan Cheng | 4a609f3c | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 11841 | return false; |
| 11842 | } |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11843 | |
| Wesley Peck | 527da1b | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 11844 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11845 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 11846 | /// specified in the intrinsic calls. |
| 11847 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 11848 | const CallInst &I, |
| 11849 | unsigned Intrinsic) const { |
| 11850 | switch (Intrinsic) { |
| 11851 | case Intrinsic::arm_neon_vld1: |
| 11852 | case Intrinsic::arm_neon_vld2: |
| 11853 | case Intrinsic::arm_neon_vld3: |
| 11854 | case Intrinsic::arm_neon_vld4: |
| 11855 | case Intrinsic::arm_neon_vld2lane: |
| 11856 | case Intrinsic::arm_neon_vld3lane: |
| 11857 | case Intrinsic::arm_neon_vld4lane: { |
| 11858 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11859 | // Conservatively set memVT to the entire set of vectors loaded. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11860 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Ahmed Bougacha | 97564c3 | 2015-12-09 01:19:50 +0000 | [diff] [blame] | 11861 | uint64_t NumElts = DL.getTypeSizeInBits(I.getType()) / 64; |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11862 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 11863 | Info.ptrVal = I.getArgOperand(0); |
| 11864 | Info.offset = 0; |
| 11865 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 11866 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 11867 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 11868 | Info.readMem = true; |
| 11869 | Info.writeMem = false; |
| 11870 | return true; |
| 11871 | } |
| 11872 | case Intrinsic::arm_neon_vst1: |
| 11873 | case Intrinsic::arm_neon_vst2: |
| 11874 | case Intrinsic::arm_neon_vst3: |
| 11875 | case Intrinsic::arm_neon_vst4: |
| 11876 | case Intrinsic::arm_neon_vst2lane: |
| 11877 | case Intrinsic::arm_neon_vst3lane: |
| 11878 | case Intrinsic::arm_neon_vst4lane: { |
| 11879 | Info.opc = ISD::INTRINSIC_VOID; |
| 11880 | // Conservatively set memVT to the entire set of vectors stored. |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11881 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11882 | unsigned NumElts = 0; |
| 11883 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
| Chris Lattner | 229907c | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 11884 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11885 | if (!ArgTy->isVectorTy()) |
| 11886 | break; |
| Ahmed Bougacha | 97564c3 | 2015-12-09 01:19:50 +0000 | [diff] [blame] | 11887 | NumElts += DL.getTypeSizeInBits(ArgTy) / 64; |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11888 | } |
| 11889 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 11890 | Info.ptrVal = I.getArgOperand(0); |
| 11891 | Info.offset = 0; |
| 11892 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 11893 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 11894 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 11895 | Info.readMem = false; |
| 11896 | Info.writeMem = true; |
| 11897 | return true; |
| 11898 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11899 | case Intrinsic::arm_ldaex: |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11900 | case Intrinsic::arm_ldrex: { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11901 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11902 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(0)->getType()); |
| 11903 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11904 | Info.memVT = MVT::getVT(PtrTy->getElementType()); |
| 11905 | Info.ptrVal = I.getArgOperand(0); |
| 11906 | Info.offset = 0; |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11907 | Info.align = DL.getABITypeAlignment(PtrTy->getElementType()); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11908 | Info.vol = true; |
| 11909 | Info.readMem = true; |
| 11910 | Info.writeMem = false; |
| 11911 | return true; |
| 11912 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11913 | case Intrinsic::arm_stlex: |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11914 | case Intrinsic::arm_strex: { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11915 | auto &DL = I.getCalledFunction()->getParent()->getDataLayout(); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11916 | PointerType *PtrTy = cast<PointerType>(I.getArgOperand(1)->getType()); |
| 11917 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11918 | Info.memVT = MVT::getVT(PtrTy->getElementType()); |
| 11919 | Info.ptrVal = I.getArgOperand(1); |
| 11920 | Info.offset = 0; |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 11921 | Info.align = DL.getABITypeAlignment(PtrTy->getElementType()); |
| Tim Northover | a7ecd24 | 2013-07-16 09:46:55 +0000 | [diff] [blame] | 11922 | Info.vol = true; |
| 11923 | Info.readMem = false; |
| 11924 | Info.writeMem = true; |
| 11925 | return true; |
| 11926 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11927 | case Intrinsic::arm_stlexd: |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11928 | case Intrinsic::arm_strexd: { |
| 11929 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11930 | Info.memVT = MVT::i64; |
| 11931 | Info.ptrVal = I.getArgOperand(2); |
| 11932 | Info.offset = 0; |
| 11933 | Info.align = 8; |
| Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 11934 | Info.vol = true; |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11935 | Info.readMem = false; |
| 11936 | Info.writeMem = true; |
| 11937 | return true; |
| 11938 | } |
| Tim Northover | 1ff5f29 | 2014-03-26 14:39:31 +0000 | [diff] [blame] | 11939 | case Intrinsic::arm_ldaexd: |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11940 | case Intrinsic::arm_ldrexd: { |
| 11941 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 11942 | Info.memVT = MVT::i64; |
| 11943 | Info.ptrVal = I.getArgOperand(0); |
| 11944 | Info.offset = 0; |
| 11945 | Info.align = 8; |
| Bruno Cardoso Lopes | d66ab9e | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 11946 | Info.vol = true; |
| Bruno Cardoso Lopes | 325110f | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 11947 | Info.readMem = true; |
| 11948 | Info.writeMem = false; |
| 11949 | return true; |
| 11950 | } |
| Bob Wilson | 5549d49 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 11951 | default: |
| 11952 | break; |
| 11953 | } |
| 11954 | |
| 11955 | return false; |
| 11956 | } |
| Juergen Ributzka | 659ce00 | 2014-01-28 01:20:14 +0000 | [diff] [blame] | 11957 | |
| 11958 | /// \brief Returns true if it is beneficial to convert a load of a constant |
| 11959 | /// to just the constant itself. |
| 11960 | bool ARMTargetLowering::shouldConvertConstantLoadToIntImm(const APInt &Imm, |
| 11961 | Type *Ty) const { |
| 11962 | assert(Ty->isIntegerTy()); |
| 11963 | |
| 11964 | unsigned Bits = Ty->getPrimitiveSizeInBits(); |
| 11965 | if (Bits == 0 || Bits > 32) |
| 11966 | return false; |
| 11967 | return true; |
| 11968 | } |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 11969 | |
| Robin Morisset | 5349e8e | 2014-09-18 18:56:04 +0000 | [diff] [blame] | 11970 | Instruction* ARMTargetLowering::makeDMB(IRBuilder<> &Builder, |
| 11971 | ARM_MB::MemBOpt Domain) const { |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11972 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| Robin Morisset | 5349e8e | 2014-09-18 18:56:04 +0000 | [diff] [blame] | 11973 | |
| 11974 | // First, if the target has no DMB, see what fallback we can use. |
| 11975 | if (!Subtarget->hasDataBarrier()) { |
| 11976 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 11977 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 11978 | // here. |
| 11979 | if (Subtarget->hasV6Ops() && !Subtarget->isThumb()) { |
| 11980 | Function *MCR = llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_mcr); |
| 11981 | Value* args[6] = {Builder.getInt32(15), Builder.getInt32(0), |
| 11982 | Builder.getInt32(0), Builder.getInt32(7), |
| 11983 | Builder.getInt32(10), Builder.getInt32(5)}; |
| 11984 | return Builder.CreateCall(MCR, args); |
| 11985 | } else { |
| 11986 | // Instead of using barriers, atomic accesses on these subtargets use |
| 11987 | // libcalls. |
| 11988 | llvm_unreachable("makeDMB on a target so old that it has no barriers"); |
| 11989 | } |
| 11990 | } else { |
| 11991 | Function *DMB = llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_dmb); |
| 11992 | // Only a full system barrier exists in the M-class architectures. |
| 11993 | Domain = Subtarget->isMClass() ? ARM_MB::SY : Domain; |
| 11994 | Constant *CDomain = Builder.getInt32(Domain); |
| 11995 | return Builder.CreateCall(DMB, CDomain); |
| 11996 | } |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 11997 | } |
| 11998 | |
| 11999 | // Based on http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12000 | Instruction* ARMTargetLowering::emitLeadingFence(IRBuilder<> &Builder, |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12001 | AtomicOrdering Ord, bool IsStore, |
| 12002 | bool IsLoad) const { |
| 12003 | if (!getInsertFencesForAtomic()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12004 | return nullptr; |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12005 | |
| 12006 | switch (Ord) { |
| 12007 | case NotAtomic: |
| 12008 | case Unordered: |
| 12009 | llvm_unreachable("Invalid fence: unordered/non-atomic"); |
| 12010 | case Monotonic: |
| 12011 | case Acquire: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12012 | return nullptr; // Nothing to do |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12013 | case SequentiallyConsistent: |
| 12014 | if (!IsStore) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12015 | return nullptr; // Nothing to do |
| 12016 | /*FALLTHROUGH*/ |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12017 | case Release: |
| 12018 | case AcquireRelease: |
| 12019 | if (Subtarget->isSwift()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12020 | return makeDMB(Builder, ARM_MB::ISHST); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12021 | // FIXME: add a comment with a link to documentation justifying this. |
| 12022 | else |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12023 | return makeDMB(Builder, ARM_MB::ISH); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12024 | } |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12025 | llvm_unreachable("Unknown fence ordering in emitLeadingFence"); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12026 | } |
| 12027 | |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12028 | Instruction* ARMTargetLowering::emitTrailingFence(IRBuilder<> &Builder, |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12029 | AtomicOrdering Ord, bool IsStore, |
| 12030 | bool IsLoad) const { |
| 12031 | if (!getInsertFencesForAtomic()) |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12032 | return nullptr; |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12033 | |
| 12034 | switch (Ord) { |
| 12035 | case NotAtomic: |
| 12036 | case Unordered: |
| 12037 | llvm_unreachable("Invalid fence: unordered/not-atomic"); |
| 12038 | case Monotonic: |
| 12039 | case Release: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12040 | return nullptr; // Nothing to do |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12041 | case Acquire: |
| 12042 | case AcquireRelease: |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12043 | case SequentiallyConsistent: |
| 12044 | return makeDMB(Builder, ARM_MB::ISH); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12045 | } |
| Robin Morisset | dedef33 | 2014-09-23 20:31:14 +0000 | [diff] [blame] | 12046 | llvm_unreachable("Unknown fence ordering in emitTrailingFence"); |
| Robin Morisset | a47cb41 | 2014-09-03 21:01:03 +0000 | [diff] [blame] | 12047 | } |
| 12048 | |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 12049 | // Loads and stores less than 64-bits are already atomic; ones above that |
| 12050 | // are doomed anyway, so defer to the default libcall and blame the OS when |
| 12051 | // things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit |
| 12052 | // anything for those. |
| 12053 | bool ARMTargetLowering::shouldExpandAtomicStoreInIR(StoreInst *SI) const { |
| 12054 | unsigned Size = SI->getValueOperand()->getType()->getPrimitiveSizeInBits(); |
| 12055 | return (Size == 64) && !Subtarget->isMClass(); |
| 12056 | } |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12057 | |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 12058 | // Loads and stores less than 64-bits are already atomic; ones above that |
| 12059 | // are doomed anyway, so defer to the default libcall and blame the OS when |
| 12060 | // things go wrong. Cortex M doesn't have ldrexd/strexd though, so don't emit |
| 12061 | // anything for those. |
| Robin Morisset | a7b357f | 2014-09-23 18:33:21 +0000 | [diff] [blame] | 12062 | // FIXME: ldrd and strd are atomic if the CPU has LPAE (e.g. A15 has that |
| 12063 | // guarantee, see DDI0406C ARM architecture reference manual, |
| 12064 | // sections A8.8.72-74 LDRD) |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 12065 | TargetLowering::AtomicExpansionKind |
| 12066 | ARMTargetLowering::shouldExpandAtomicLoadInIR(LoadInst *LI) const { |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 12067 | unsigned Size = LI->getType()->getPrimitiveSizeInBits(); |
| Tim Northover | f520eff | 2015-12-02 18:12:57 +0000 | [diff] [blame] | 12068 | return ((Size == 64) && !Subtarget->isMClass()) ? AtomicExpansionKind::LLOnly |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 12069 | : AtomicExpansionKind::None; |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 12070 | } |
| 12071 | |
| 12072 | // For the real atomic operations, we have ldrex/strex up to 32 bits, |
| 12073 | // and up to 64 bits on the non-M profiles |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 12074 | TargetLowering::AtomicExpansionKind |
| JF Bastien | f14889e | 2015-03-04 15:47:57 +0000 | [diff] [blame] | 12075 | ARMTargetLowering::shouldExpandAtomicRMWInIR(AtomicRMWInst *AI) const { |
| Robin Morisset | ed3d48f | 2014-09-03 21:29:59 +0000 | [diff] [blame] | 12076 | unsigned Size = AI->getType()->getPrimitiveSizeInBits(); |
| JF Bastien | f14889e | 2015-03-04 15:47:57 +0000 | [diff] [blame] | 12077 | return (Size <= (Subtarget->isMClass() ? 32U : 64U)) |
| Ahmed Bougacha | 9d67713 | 2015-09-11 17:08:17 +0000 | [diff] [blame] | 12078 | ? AtomicExpansionKind::LLSC |
| 12079 | : AtomicExpansionKind::None; |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12080 | } |
| 12081 | |
| Ahmed Bougacha | 5246867 | 2015-09-11 17:08:28 +0000 | [diff] [blame] | 12082 | bool ARMTargetLowering::shouldExpandAtomicCmpXchgInIR( |
| 12083 | AtomicCmpXchgInst *AI) const { |
| 12084 | return true; |
| 12085 | } |
| 12086 | |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 12087 | // This has so far only been implemented for MachO. |
| 12088 | bool ARMTargetLowering::useLoadStackGuardNode() const { |
| Eric Christopher | 66322e8 | 2014-12-05 00:22:35 +0000 | [diff] [blame] | 12089 | return Subtarget->isTargetMachO(); |
| Akira Hatanaka | e5b6e0d | 2014-07-25 19:31:34 +0000 | [diff] [blame] | 12090 | } |
| 12091 | |
| Quentin Colombet | c32615d | 2014-10-31 17:52:53 +0000 | [diff] [blame] | 12092 | bool ARMTargetLowering::canCombineStoreAndExtract(Type *VectorTy, Value *Idx, |
| 12093 | unsigned &Cost) const { |
| 12094 | // If we do not have NEON, vector types are not natively supported. |
| 12095 | if (!Subtarget->hasNEON()) |
| 12096 | return false; |
| 12097 | |
| 12098 | // Floating point values and vector values map to the same register file. |
| Benjamin Kramer | df005cb | 2015-08-08 18:27:36 +0000 | [diff] [blame] | 12099 | // 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] | 12100 | // better to leave at float as we have more freedom in the addressing mode for |
| 12101 | // those. |
| 12102 | if (VectorTy->isFPOrFPVectorTy()) |
| 12103 | return false; |
| 12104 | |
| 12105 | // If the index is unknown at compile time, this is very expensive to lower |
| 12106 | // and it is not possible to combine the store with the extract. |
| 12107 | if (!isa<ConstantInt>(Idx)) |
| 12108 | return false; |
| 12109 | |
| 12110 | assert(VectorTy->isVectorTy() && "VectorTy is not a vector type"); |
| 12111 | unsigned BitWidth = cast<VectorType>(VectorTy)->getBitWidth(); |
| 12112 | // We can do a store + vector extract on any vector that fits perfectly in a D |
| 12113 | // or Q register. |
| 12114 | if (BitWidth == 64 || BitWidth == 128) { |
| 12115 | Cost = 0; |
| 12116 | return true; |
| 12117 | } |
| 12118 | return false; |
| 12119 | } |
| 12120 | |
| Sanjay Patel | af1b48b | 2015-11-10 19:24:31 +0000 | [diff] [blame] | 12121 | bool ARMTargetLowering::isCheapToSpeculateCttz() const { |
| 12122 | return Subtarget->hasV6T2Ops(); |
| 12123 | } |
| 12124 | |
| 12125 | bool ARMTargetLowering::isCheapToSpeculateCtlz() const { |
| 12126 | return Subtarget->hasV6T2Ops(); |
| 12127 | } |
| 12128 | |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12129 | Value *ARMTargetLowering::emitLoadLinked(IRBuilder<> &Builder, Value *Addr, |
| 12130 | AtomicOrdering Ord) const { |
| 12131 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| 12132 | Type *ValTy = cast<PointerType>(Addr->getType())->getElementType(); |
| Robin Morisset | b155f52 | 2014-08-18 16:48:58 +0000 | [diff] [blame] | 12133 | bool IsAcquire = isAtLeastAcquire(Ord); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12134 | |
| 12135 | // Since i64 isn't legal and intrinsics don't get type-lowered, the ldrexd |
| 12136 | // intrinsic must return {i32, i32} and we have to recombine them into a |
| 12137 | // single i64 here. |
| 12138 | if (ValTy->getPrimitiveSizeInBits() == 64) { |
| 12139 | Intrinsic::ID Int = |
| 12140 | IsAcquire ? Intrinsic::arm_ldaexd : Intrinsic::arm_ldrexd; |
| 12141 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int); |
| 12142 | |
| 12143 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); |
| 12144 | Value *LoHi = Builder.CreateCall(Ldrex, Addr, "lohi"); |
| 12145 | |
| 12146 | Value *Lo = Builder.CreateExtractValue(LoHi, 0, "lo"); |
| 12147 | Value *Hi = Builder.CreateExtractValue(LoHi, 1, "hi"); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 12148 | if (!Subtarget->isLittle()) |
| 12149 | std::swap (Lo, Hi); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12150 | Lo = Builder.CreateZExt(Lo, ValTy, "lo64"); |
| 12151 | Hi = Builder.CreateZExt(Hi, ValTy, "hi64"); |
| 12152 | return Builder.CreateOr( |
| 12153 | Lo, Builder.CreateShl(Hi, ConstantInt::get(ValTy, 32)), "val64"); |
| 12154 | } |
| 12155 | |
| 12156 | Type *Tys[] = { Addr->getType() }; |
| 12157 | Intrinsic::ID Int = IsAcquire ? Intrinsic::arm_ldaex : Intrinsic::arm_ldrex; |
| 12158 | Function *Ldrex = llvm::Intrinsic::getDeclaration(M, Int, Tys); |
| 12159 | |
| 12160 | return Builder.CreateTruncOrBitCast( |
| 12161 | Builder.CreateCall(Ldrex, Addr), |
| 12162 | cast<PointerType>(Addr->getType())->getElementType()); |
| 12163 | } |
| 12164 | |
| Ahmed Bougacha | 81616a7 | 2015-09-22 17:22:58 +0000 | [diff] [blame] | 12165 | void ARMTargetLowering::emitAtomicCmpXchgNoStoreLLBalance( |
| 12166 | IRBuilder<> &Builder) const { |
| Ahmed Bougacha | e81610f | 2015-09-26 00:14:02 +0000 | [diff] [blame] | 12167 | if (!Subtarget->hasV7Ops()) |
| 12168 | return; |
| Ahmed Bougacha | 81616a7 | 2015-09-22 17:22:58 +0000 | [diff] [blame] | 12169 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| 12170 | Builder.CreateCall(llvm::Intrinsic::getDeclaration(M, Intrinsic::arm_clrex)); |
| 12171 | } |
| 12172 | |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12173 | Value *ARMTargetLowering::emitStoreConditional(IRBuilder<> &Builder, Value *Val, |
| 12174 | Value *Addr, |
| 12175 | AtomicOrdering Ord) const { |
| 12176 | Module *M = Builder.GetInsertBlock()->getParent()->getParent(); |
| Robin Morisset | b155f52 | 2014-08-18 16:48:58 +0000 | [diff] [blame] | 12177 | bool IsRelease = isAtLeastRelease(Ord); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12178 | |
| 12179 | // Since the intrinsics must have legal type, the i64 intrinsics take two |
| 12180 | // parameters: "i32, i32". We must marshal Val into the appropriate form |
| 12181 | // before the call. |
| 12182 | if (Val->getType()->getPrimitiveSizeInBits() == 64) { |
| 12183 | Intrinsic::ID Int = |
| 12184 | IsRelease ? Intrinsic::arm_stlexd : Intrinsic::arm_strexd; |
| 12185 | Function *Strex = Intrinsic::getDeclaration(M, Int); |
| 12186 | Type *Int32Ty = Type::getInt32Ty(M->getContext()); |
| 12187 | |
| 12188 | Value *Lo = Builder.CreateTrunc(Val, Int32Ty, "lo"); |
| 12189 | Value *Hi = Builder.CreateTrunc(Builder.CreateLShr(Val, 32), Int32Ty, "hi"); |
| Christian Pirker | b572819 | 2014-05-08 14:06:24 +0000 | [diff] [blame] | 12190 | if (!Subtarget->isLittle()) |
| 12191 | std::swap (Lo, Hi); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12192 | Addr = Builder.CreateBitCast(Addr, Type::getInt8PtrTy(M->getContext())); |
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 12193 | return Builder.CreateCall(Strex, {Lo, Hi, Addr}); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12194 | } |
| 12195 | |
| 12196 | Intrinsic::ID Int = IsRelease ? Intrinsic::arm_stlex : Intrinsic::arm_strex; |
| 12197 | Type *Tys[] = { Addr->getType() }; |
| 12198 | Function *Strex = Intrinsic::getDeclaration(M, Int, Tys); |
| 12199 | |
| David Blaikie | ff6409d | 2015-05-18 22:13:54 +0000 | [diff] [blame] | 12200 | return Builder.CreateCall( |
| 12201 | Strex, {Builder.CreateZExtOrBitCast( |
| 12202 | Val, Strex->getFunctionType()->getParamType(0)), |
| 12203 | Addr}); |
| Tim Northover | 037f26f2 | 2014-04-17 18:22:47 +0000 | [diff] [blame] | 12204 | } |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12205 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12206 | /// \brief Lower an interleaved load into a vldN intrinsic. |
| 12207 | /// |
| 12208 | /// E.g. Lower an interleaved load (Factor = 2): |
| 12209 | /// %wide.vec = load <8 x i32>, <8 x i32>* %ptr, align 4 |
| 12210 | /// %v0 = shuffle %wide.vec, undef, <0, 2, 4, 6> ; Extract even elements |
| 12211 | /// %v1 = shuffle %wide.vec, undef, <1, 3, 5, 7> ; Extract odd elements |
| 12212 | /// |
| 12213 | /// Into: |
| 12214 | /// %vld2 = { <4 x i32>, <4 x i32> } call llvm.arm.neon.vld2(%ptr, 4) |
| 12215 | /// %vec0 = extractelement { <4 x i32>, <4 x i32> } %vld2, i32 0 |
| 12216 | /// %vec1 = extractelement { <4 x i32>, <4 x i32> } %vld2, i32 1 |
| 12217 | bool ARMTargetLowering::lowerInterleavedLoad( |
| 12218 | LoadInst *LI, ArrayRef<ShuffleVectorInst *> Shuffles, |
| 12219 | ArrayRef<unsigned> Indices, unsigned Factor) const { |
| 12220 | assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() && |
| 12221 | "Invalid interleave factor"); |
| 12222 | assert(!Shuffles.empty() && "Empty shufflevector input"); |
| 12223 | assert(Shuffles.size() == Indices.size() && |
| 12224 | "Unmatched number of shufflevectors and indices"); |
| 12225 | |
| 12226 | VectorType *VecTy = Shuffles[0]->getType(); |
| 12227 | Type *EltTy = VecTy->getVectorElementType(); |
| 12228 | |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12229 | const DataLayout &DL = LI->getModule()->getDataLayout(); |
| Ahmed Bougacha | 97564c3 | 2015-12-09 01:19:50 +0000 | [diff] [blame] | 12230 | unsigned VecSize = DL.getTypeSizeInBits(VecTy); |
| 12231 | bool EltIs64Bits = DL.getTypeSizeInBits(EltTy) == 64; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12232 | |
| Jeroen Ketema | aebca09 | 2015-10-07 14:53:29 +0000 | [diff] [blame] | 12233 | // Skip if we do not have NEON and skip illegal vector types and vector types |
| 12234 | // with i64/f64 elements (vldN doesn't support i64/f64 elements). |
| 12235 | if (!Subtarget->hasNEON() || (VecSize != 64 && VecSize != 128) || EltIs64Bits) |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12236 | return false; |
| 12237 | |
| 12238 | // A pointer vector can not be the return type of the ldN intrinsics. Need to |
| 12239 | // load integer vectors first and then convert to pointer vectors. |
| 12240 | if (EltTy->isPointerTy()) |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12241 | VecTy = |
| 12242 | VectorType::get(DL.getIntPtrType(EltTy), VecTy->getVectorNumElements()); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12243 | |
| 12244 | static const Intrinsic::ID LoadInts[3] = {Intrinsic::arm_neon_vld2, |
| 12245 | Intrinsic::arm_neon_vld3, |
| 12246 | Intrinsic::arm_neon_vld4}; |
| 12247 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12248 | IRBuilder<> Builder(LI); |
| 12249 | SmallVector<Value *, 2> Ops; |
| 12250 | |
| 12251 | Type *Int8Ptr = Builder.getInt8PtrTy(LI->getPointerAddressSpace()); |
| 12252 | Ops.push_back(Builder.CreateBitCast(LI->getPointerOperand(), Int8Ptr)); |
| 12253 | Ops.push_back(Builder.getInt32(LI->getAlignment())); |
| 12254 | |
| Jeroen Ketema | ab99b59 | 2015-09-30 10:56:37 +0000 | [diff] [blame] | 12255 | Type *Tys[] = { VecTy, Int8Ptr }; |
| 12256 | Function *VldnFunc = |
| 12257 | Intrinsic::getDeclaration(LI->getModule(), LoadInts[Factor - 2], Tys); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12258 | CallInst *VldN = Builder.CreateCall(VldnFunc, Ops, "vldN"); |
| 12259 | |
| 12260 | // Replace uses of each shufflevector with the corresponding vector loaded |
| 12261 | // by ldN. |
| 12262 | for (unsigned i = 0; i < Shuffles.size(); i++) { |
| 12263 | ShuffleVectorInst *SV = Shuffles[i]; |
| 12264 | unsigned Index = Indices[i]; |
| 12265 | |
| 12266 | Value *SubVec = Builder.CreateExtractValue(VldN, Index); |
| 12267 | |
| 12268 | // Convert the integer vector to pointer vector if the element is pointer. |
| 12269 | if (EltTy->isPointerTy()) |
| 12270 | SubVec = Builder.CreateIntToPtr(SubVec, SV->getType()); |
| 12271 | |
| 12272 | SV->replaceAllUsesWith(SubVec); |
| 12273 | } |
| 12274 | |
| 12275 | return true; |
| 12276 | } |
| 12277 | |
| 12278 | /// \brief Get a mask consisting of sequential integers starting from \p Start. |
| 12279 | /// |
| 12280 | /// I.e. <Start, Start + 1, ..., Start + NumElts - 1> |
| 12281 | static Constant *getSequentialMask(IRBuilder<> &Builder, unsigned Start, |
| 12282 | unsigned NumElts) { |
| 12283 | SmallVector<Constant *, 16> Mask; |
| 12284 | for (unsigned i = 0; i < NumElts; i++) |
| 12285 | Mask.push_back(Builder.getInt32(Start + i)); |
| 12286 | |
| 12287 | return ConstantVector::get(Mask); |
| 12288 | } |
| 12289 | |
| 12290 | /// \brief Lower an interleaved store into a vstN intrinsic. |
| 12291 | /// |
| 12292 | /// E.g. Lower an interleaved store (Factor = 3): |
| 12293 | /// %i.vec = shuffle <8 x i32> %v0, <8 x i32> %v1, |
| 12294 | /// <0, 4, 8, 1, 5, 9, 2, 6, 10, 3, 7, 11> |
| 12295 | /// store <12 x i32> %i.vec, <12 x i32>* %ptr, align 4 |
| 12296 | /// |
| 12297 | /// Into: |
| 12298 | /// %sub.v0 = shuffle <8 x i32> %v0, <8 x i32> v1, <0, 1, 2, 3> |
| 12299 | /// %sub.v1 = shuffle <8 x i32> %v0, <8 x i32> v1, <4, 5, 6, 7> |
| 12300 | /// %sub.v2 = shuffle <8 x i32> %v0, <8 x i32> v1, <8, 9, 10, 11> |
| 12301 | /// call void llvm.arm.neon.vst3(%ptr, %sub.v0, %sub.v1, %sub.v2, 4) |
| 12302 | /// |
| 12303 | /// Note that the new shufflevectors will be removed and we'll only generate one |
| 12304 | /// vst3 instruction in CodeGen. |
| 12305 | bool ARMTargetLowering::lowerInterleavedStore(StoreInst *SI, |
| 12306 | ShuffleVectorInst *SVI, |
| 12307 | unsigned Factor) const { |
| 12308 | assert(Factor >= 2 && Factor <= getMaxSupportedInterleaveFactor() && |
| 12309 | "Invalid interleave factor"); |
| 12310 | |
| 12311 | VectorType *VecTy = SVI->getType(); |
| 12312 | assert(VecTy->getVectorNumElements() % Factor == 0 && |
| 12313 | "Invalid interleaved store"); |
| 12314 | |
| 12315 | unsigned NumSubElts = VecTy->getVectorNumElements() / Factor; |
| 12316 | Type *EltTy = VecTy->getVectorElementType(); |
| 12317 | VectorType *SubVecTy = VectorType::get(EltTy, NumSubElts); |
| 12318 | |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12319 | const DataLayout &DL = SI->getModule()->getDataLayout(); |
| Ahmed Bougacha | 97564c3 | 2015-12-09 01:19:50 +0000 | [diff] [blame] | 12320 | unsigned SubVecSize = DL.getTypeSizeInBits(SubVecTy); |
| 12321 | bool EltIs64Bits = DL.getTypeSizeInBits(EltTy) == 64; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12322 | |
| Jeroen Ketema | aebca09 | 2015-10-07 14:53:29 +0000 | [diff] [blame] | 12323 | // Skip if we do not have NEON and skip illegal vector types and vector types |
| 12324 | // with i64/f64 elements (vstN doesn't support i64/f64 elements). |
| 12325 | if (!Subtarget->hasNEON() || (SubVecSize != 64 && SubVecSize != 128) || |
| 12326 | EltIs64Bits) |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12327 | return false; |
| 12328 | |
| 12329 | Value *Op0 = SVI->getOperand(0); |
| 12330 | Value *Op1 = SVI->getOperand(1); |
| 12331 | IRBuilder<> Builder(SI); |
| 12332 | |
| 12333 | // StN intrinsics don't support pointer vectors as arguments. Convert pointer |
| 12334 | // vectors to integer vectors. |
| 12335 | if (EltTy->isPointerTy()) { |
| Mehdi Amini | a749f2a | 2015-07-09 02:09:52 +0000 | [diff] [blame] | 12336 | Type *IntTy = DL.getIntPtrType(EltTy); |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12337 | |
| 12338 | // Convert to the corresponding integer vector. |
| 12339 | Type *IntVecTy = |
| 12340 | VectorType::get(IntTy, Op0->getType()->getVectorNumElements()); |
| 12341 | Op0 = Builder.CreatePtrToInt(Op0, IntVecTy); |
| 12342 | Op1 = Builder.CreatePtrToInt(Op1, IntVecTy); |
| 12343 | |
| 12344 | SubVecTy = VectorType::get(IntTy, NumSubElts); |
| 12345 | } |
| 12346 | |
| Craig Topper | 2626094 | 2015-10-18 05:15:34 +0000 | [diff] [blame] | 12347 | static const Intrinsic::ID StoreInts[3] = {Intrinsic::arm_neon_vst2, |
| 12348 | Intrinsic::arm_neon_vst3, |
| 12349 | Intrinsic::arm_neon_vst4}; |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12350 | SmallVector<Value *, 6> Ops; |
| 12351 | |
| 12352 | Type *Int8Ptr = Builder.getInt8PtrTy(SI->getPointerAddressSpace()); |
| 12353 | Ops.push_back(Builder.CreateBitCast(SI->getPointerOperand(), Int8Ptr)); |
| 12354 | |
| Jeroen Ketema | ab99b59 | 2015-09-30 10:56:37 +0000 | [diff] [blame] | 12355 | Type *Tys[] = { Int8Ptr, SubVecTy }; |
| 12356 | Function *VstNFunc = Intrinsic::getDeclaration( |
| 12357 | SI->getModule(), StoreInts[Factor - 2], Tys); |
| 12358 | |
| Hao Liu | 2cd34bb | 2015-06-26 02:45:36 +0000 | [diff] [blame] | 12359 | // Split the shufflevector operands into sub vectors for the new vstN call. |
| 12360 | for (unsigned i = 0; i < Factor; i++) |
| 12361 | Ops.push_back(Builder.CreateShuffleVector( |
| 12362 | Op0, Op1, getSequentialMask(Builder, NumSubElts * i, NumSubElts))); |
| 12363 | |
| 12364 | Ops.push_back(Builder.getInt32(SI->getAlignment())); |
| 12365 | Builder.CreateCall(VstNFunc, Ops); |
| 12366 | return true; |
| 12367 | } |
| 12368 | |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12369 | enum HABaseType { |
| 12370 | HA_UNKNOWN = 0, |
| 12371 | HA_FLOAT, |
| 12372 | HA_DOUBLE, |
| 12373 | HA_VECT64, |
| 12374 | HA_VECT128 |
| 12375 | }; |
| 12376 | |
| 12377 | static bool isHomogeneousAggregate(Type *Ty, HABaseType &Base, |
| 12378 | uint64_t &Members) { |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12379 | if (auto *ST = dyn_cast<StructType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12380 | for (unsigned i = 0; i < ST->getNumElements(); ++i) { |
| 12381 | uint64_t SubMembers = 0; |
| 12382 | if (!isHomogeneousAggregate(ST->getElementType(i), Base, SubMembers)) |
| 12383 | return false; |
| 12384 | Members += SubMembers; |
| 12385 | } |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12386 | } else if (auto *AT = dyn_cast<ArrayType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12387 | uint64_t SubMembers = 0; |
| 12388 | if (!isHomogeneousAggregate(AT->getElementType(), Base, SubMembers)) |
| 12389 | return false; |
| 12390 | Members += SubMembers * AT->getNumElements(); |
| 12391 | } else if (Ty->isFloatTy()) { |
| 12392 | if (Base != HA_UNKNOWN && Base != HA_FLOAT) |
| 12393 | return false; |
| 12394 | Members = 1; |
| 12395 | Base = HA_FLOAT; |
| 12396 | } else if (Ty->isDoubleTy()) { |
| 12397 | if (Base != HA_UNKNOWN && Base != HA_DOUBLE) |
| 12398 | return false; |
| 12399 | Members = 1; |
| 12400 | Base = HA_DOUBLE; |
| Craig Topper | e3dcce9 | 2015-08-01 22:20:21 +0000 | [diff] [blame] | 12401 | } else if (auto *VT = dyn_cast<VectorType>(Ty)) { |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12402 | Members = 1; |
| 12403 | switch (Base) { |
| 12404 | case HA_FLOAT: |
| 12405 | case HA_DOUBLE: |
| 12406 | return false; |
| 12407 | case HA_VECT64: |
| 12408 | return VT->getBitWidth() == 64; |
| 12409 | case HA_VECT128: |
| 12410 | return VT->getBitWidth() == 128; |
| 12411 | case HA_UNKNOWN: |
| 12412 | switch (VT->getBitWidth()) { |
| 12413 | case 64: |
| 12414 | Base = HA_VECT64; |
| 12415 | return true; |
| 12416 | case 128: |
| 12417 | Base = HA_VECT128; |
| 12418 | return true; |
| 12419 | default: |
| 12420 | return false; |
| 12421 | } |
| 12422 | } |
| 12423 | } |
| 12424 | |
| 12425 | return (Members > 0 && Members <= 4); |
| 12426 | } |
| 12427 | |
| Tim Northover | e95c5b3 | 2015-02-24 17:22:34 +0000 | [diff] [blame] | 12428 | /// \brief Return true if a type is an AAPCS-VFP homogeneous aggregate or one of |
| 12429 | /// [N x i32] or [N x i64]. This allows front-ends to skip emitting padding when |
| 12430 | /// passing according to AAPCS rules. |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12431 | bool ARMTargetLowering::functionArgumentNeedsConsecutiveRegisters( |
| 12432 | Type *Ty, CallingConv::ID CallConv, bool isVarArg) const { |
| Tim Northover | 4f1909f | 2014-05-27 10:43:38 +0000 | [diff] [blame] | 12433 | if (getEffectiveCallingConv(CallConv, isVarArg) != |
| 12434 | CallingConv::ARM_AAPCS_VFP) |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12435 | return false; |
| Tim Northover | 4f1909f | 2014-05-27 10:43:38 +0000 | [diff] [blame] | 12436 | |
| 12437 | HABaseType Base = HA_UNKNOWN; |
| 12438 | uint64_t Members = 0; |
| Tim Northover | e95c5b3 | 2015-02-24 17:22:34 +0000 | [diff] [blame] | 12439 | bool IsHA = isHomogeneousAggregate(Ty, Base, Members); |
| 12440 | DEBUG(dbgs() << "isHA: " << IsHA << " "; Ty->dump()); |
| 12441 | |
| 12442 | bool IsIntArray = Ty->isArrayTy() && Ty->getArrayElementType()->isIntegerTy(); |
| 12443 | return IsHA || IsIntArray; |
| Oliver Stannard | c24f217 | 2014-05-09 14:01:47 +0000 | [diff] [blame] | 12444 | } |
| Joseph Tremoulet | f748c89 | 2015-11-07 01:11:31 +0000 | [diff] [blame] | 12445 | |
| 12446 | unsigned ARMTargetLowering::getExceptionPointerRegister( |
| 12447 | const Constant *PersonalityFn) const { |
| 12448 | // Platforms which do not use SjLj EH may return values in these registers |
| 12449 | // via the personality function. |
| 12450 | return Subtarget->useSjLjEH() ? ARM::NoRegister : ARM::R0; |
| 12451 | } |
| 12452 | |
| 12453 | unsigned ARMTargetLowering::getExceptionSelectorRegister( |
| 12454 | const Constant *PersonalityFn) const { |
| 12455 | // Platforms which do not use SjLj EH may return values in these registers |
| 12456 | // via the personality function. |
| 12457 | return Subtarget->useSjLjEH() ? ARM::NoRegister : ARM::R1; |
| 12458 | } |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 12459 | |
| 12460 | void ARMTargetLowering::initializeSplitCSR(MachineBasicBlock *Entry) const { |
| 12461 | // Update IsSplitCSR in ARMFunctionInfo. |
| 12462 | ARMFunctionInfo *AFI = Entry->getParent()->getInfo<ARMFunctionInfo>(); |
| 12463 | AFI->setIsSplitCSR(true); |
| 12464 | } |
| 12465 | |
| 12466 | void ARMTargetLowering::insertCopiesSplitCSR( |
| 12467 | MachineBasicBlock *Entry, |
| 12468 | const SmallVectorImpl<MachineBasicBlock *> &Exits) const { |
| 12469 | const ARMBaseRegisterInfo *TRI = Subtarget->getRegisterInfo(); |
| 12470 | const MCPhysReg *IStart = TRI->getCalleeSavedRegsViaCopy(Entry->getParent()); |
| 12471 | if (!IStart) |
| 12472 | return; |
| 12473 | |
| 12474 | const TargetInstrInfo *TII = Subtarget->getInstrInfo(); |
| 12475 | MachineRegisterInfo *MRI = &Entry->getParent()->getRegInfo(); |
| Manman Ren | e5f807f | 2016-01-15 20:24:11 +0000 | [diff] [blame] | 12476 | MachineBasicBlock::iterator MBBI = Entry->begin(); |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 12477 | for (const MCPhysReg *I = IStart; *I; ++I) { |
| 12478 | const TargetRegisterClass *RC = nullptr; |
| 12479 | if (ARM::GPRRegClass.contains(*I)) |
| 12480 | RC = &ARM::GPRRegClass; |
| 12481 | else if (ARM::DPRRegClass.contains(*I)) |
| 12482 | RC = &ARM::DPRRegClass; |
| 12483 | else |
| 12484 | llvm_unreachable("Unexpected register class in CSRsViaCopy!"); |
| 12485 | |
| 12486 | unsigned NewVR = MRI->createVirtualRegister(RC); |
| 12487 | // Create copy from CSR to a virtual register. |
| 12488 | // FIXME: this currently does not emit CFI pseudo-instructions, it works |
| 12489 | // fine for CXX_FAST_TLS since the C++-style TLS access functions should be |
| 12490 | // nounwind. If we want to generalize this later, we may need to emit |
| 12491 | // CFI pseudo-instructions. |
| 12492 | assert(Entry->getParent()->getFunction()->hasFnAttribute( |
| 12493 | Attribute::NoUnwind) && |
| 12494 | "Function should be nounwind in insertCopiesSplitCSR!"); |
| 12495 | Entry->addLiveIn(*I); |
| Manman Ren | e5f807f | 2016-01-15 20:24:11 +0000 | [diff] [blame] | 12496 | BuildMI(*Entry, MBBI, DebugLoc(), TII->get(TargetOpcode::COPY), NewVR) |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 12497 | .addReg(*I); |
| 12498 | |
| Manman Ren | e5f807f | 2016-01-15 20:24:11 +0000 | [diff] [blame] | 12499 | // Insert the copy-back instructions right before the terminator. |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 12500 | for (auto *Exit : Exits) |
| Manman Ren | e5f807f | 2016-01-15 20:24:11 +0000 | [diff] [blame] | 12501 | BuildMI(*Exit, Exit->getFirstTerminator(), DebugLoc(), |
| 12502 | TII->get(TargetOpcode::COPY), *I) |
| Manman Ren | 5e9e65e | 2016-01-12 00:47:18 +0000 | [diff] [blame] | 12503 | .addReg(NewVR); |
| 12504 | } |
| 12505 | } |