Evan Cheng | a8e2989 | 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 | 4ee451d | 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 | a8e2989 | 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 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 15 | #define DEBUG_TYPE "arm-isel" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 16 | #include "ARM.h" |
Eric Christopher | 6f2ccef | 2010-09-10 22:42:06 +0000 | [diff] [blame] | 17 | #include "ARMCallingConv.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 18 | #include "ARMConstantPoolValue.h" |
| 19 | #include "ARMISelLowering.h" |
| 20 | #include "ARMMachineFunctionInfo.h" |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 21 | #include "ARMPerfectShuffle.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 22 | #include "ARMRegisterInfo.h" |
| 23 | #include "ARMSubtarget.h" |
| 24 | #include "ARMTargetMachine.h" |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 25 | #include "ARMTargetObjectFile.h" |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 26 | #include "MCTargetDesc/ARMAddressingModes.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 27 | #include "llvm/CallingConv.h" |
| 28 | #include "llvm/Constants.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 29 | #include "llvm/Function.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 30 | #include "llvm/GlobalValue.h" |
Evan Cheng | 2770747 | 2007-03-16 08:43:56 +0000 | [diff] [blame] | 31 | #include "llvm/Instruction.h" |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 32 | #include "llvm/Instructions.h" |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 33 | #include "llvm/Intrinsics.h" |
Benjamin Kramer | 174101e | 2009-10-20 11:44:38 +0000 | [diff] [blame] | 34 | #include "llvm/Type.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 35 | #include "llvm/CodeGen/CallingConvLower.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 36 | #include "llvm/CodeGen/IntrinsicLowering.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 37 | #include "llvm/CodeGen/MachineBasicBlock.h" |
| 38 | #include "llvm/CodeGen/MachineFrameInfo.h" |
| 39 | #include "llvm/CodeGen/MachineFunction.h" |
| 40 | #include "llvm/CodeGen/MachineInstrBuilder.h" |
Chris Lattner | 84bc542 | 2007-12-31 04:13:23 +0000 | [diff] [blame] | 41 | #include "llvm/CodeGen/MachineRegisterInfo.h" |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 42 | #include "llvm/CodeGen/PseudoSourceValue.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 43 | #include "llvm/CodeGen/SelectionDAG.h" |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 44 | #include "llvm/MC/MCSectionMachO.h" |
Evan Cheng | b6ab254 | 2007-01-31 08:40:13 +0000 | [diff] [blame] | 45 | #include "llvm/Target/TargetOptions.h" |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 46 | #include "llvm/ADT/VectorExtras.h" |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 47 | #include "llvm/ADT/StringExtras.h" |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 48 | #include "llvm/ADT/Statistic.h" |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 49 | #include "llvm/Support/CommandLine.h" |
Torok Edwin | ab7c09b | 2009-07-08 18:01:40 +0000 | [diff] [blame] | 50 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 51 | #include "llvm/Support/MathExtras.h" |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 52 | #include "llvm/Support/raw_ostream.h" |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 53 | #include <sstream> |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 54 | using namespace llvm; |
| 55 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 56 | STATISTIC(NumTailCalls, "Number of tail calls"); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 57 | STATISTIC(NumMovwMovt, "Number of GAs materialized with movw + movt"); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 58 | |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 59 | // This option should go away when tail calls fully work. |
| 60 | static cl::opt<bool> |
| 61 | EnableARMTailCalls("arm-tail-calls", cl::Hidden, |
| 62 | cl::desc("Generate tail calls (TEMPORARY OPTION)."), |
| 63 | cl::init(false)); |
| 64 | |
Eric Christopher | 836c624 | 2010-12-15 23:47:29 +0000 | [diff] [blame] | 65 | cl::opt<bool> |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 66 | EnableARMLongCalls("arm-long-calls", cl::Hidden, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 67 | cl::desc("Generate calls via indirect call instructions"), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 68 | cl::init(false)); |
| 69 | |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 70 | static cl::opt<bool> |
| 71 | ARMInterworking("arm-interworking", cl::Hidden, |
| 72 | cl::desc("Enable / disable ARM interworking (for debugging only)"), |
| 73 | cl::init(true)); |
| 74 | |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 75 | namespace llvm { |
| 76 | class ARMCCState : public CCState { |
| 77 | public: |
| 78 | ARMCCState(CallingConv::ID CC, bool isVarArg, MachineFunction &MF, |
| 79 | const TargetMachine &TM, SmallVector<CCValAssign, 16> &locs, |
| 80 | LLVMContext &C, ParmContext PC) |
| 81 | : CCState(CC, isVarArg, MF, TM, locs, C) { |
| 82 | assert(((PC == Call) || (PC == Prologue)) && |
| 83 | "ARMCCState users must specify whether their context is call" |
| 84 | "or prologue generation."); |
| 85 | CallOrPrologue = PC; |
| 86 | } |
| 87 | }; |
| 88 | } |
| 89 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 90 | // The APCS parameter registers. |
| 91 | static const unsigned GPRArgRegs[] = { |
| 92 | ARM::R0, ARM::R1, ARM::R2, ARM::R3 |
| 93 | }; |
| 94 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 95 | void ARMTargetLowering::addTypeForNEON(EVT VT, EVT PromotedLdStVT, |
| 96 | EVT PromotedBitwiseVT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 97 | if (VT != PromotedLdStVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 98 | setOperationAction(ISD::LOAD, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 99 | AddPromotedToType (ISD::LOAD, VT.getSimpleVT(), |
| 100 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 101 | |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 102 | setOperationAction(ISD::STORE, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 103 | AddPromotedToType (ISD::STORE, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 104 | PromotedLdStVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 107 | EVT ElemTy = VT.getVectorElementType(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 108 | if (ElemTy != MVT::i64 && ElemTy != MVT::f64) |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 109 | setOperationAction(ISD::VSETCC, VT.getSimpleVT(), Custom); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 110 | setOperationAction(ISD::EXTRACT_VECTOR_ELT, VT.getSimpleVT(), Custom); |
Bob Wilson | 0696fdf | 2009-09-16 20:20:44 +0000 | [diff] [blame] | 111 | if (ElemTy != MVT::i32) { |
| 112 | setOperationAction(ISD::SINT_TO_FP, VT.getSimpleVT(), Expand); |
| 113 | setOperationAction(ISD::UINT_TO_FP, VT.getSimpleVT(), Expand); |
| 114 | setOperationAction(ISD::FP_TO_SINT, VT.getSimpleVT(), Expand); |
| 115 | setOperationAction(ISD::FP_TO_UINT, VT.getSimpleVT(), Expand); |
| 116 | } |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 117 | setOperationAction(ISD::BUILD_VECTOR, VT.getSimpleVT(), Custom); |
| 118 | setOperationAction(ISD::VECTOR_SHUFFLE, VT.getSimpleVT(), Custom); |
Bob Wilson | 07f6e80 | 2010-06-16 21:34:01 +0000 | [diff] [blame] | 119 | setOperationAction(ISD::CONCAT_VECTORS, VT.getSimpleVT(), Legal); |
Bob Wilson | 5e8b833 | 2011-01-07 04:59:04 +0000 | [diff] [blame] | 120 | setOperationAction(ISD::EXTRACT_SUBVECTOR, VT.getSimpleVT(), Legal); |
Bob Wilson | d0910c4 | 2010-04-06 22:02:24 +0000 | [diff] [blame] | 121 | setOperationAction(ISD::SELECT, VT.getSimpleVT(), Expand); |
| 122 | setOperationAction(ISD::SELECT_CC, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 123 | if (VT.isInteger()) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 124 | setOperationAction(ISD::SHL, VT.getSimpleVT(), Custom); |
| 125 | setOperationAction(ISD::SRA, VT.getSimpleVT(), Custom); |
| 126 | setOperationAction(ISD::SRL, VT.getSimpleVT(), Custom); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 127 | setLoadExtAction(ISD::SEXTLOAD, VT.getSimpleVT(), Expand); |
| 128 | setLoadExtAction(ISD::ZEXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 24645a1 | 2010-11-01 18:31:39 +0000 | [diff] [blame] | 129 | for (unsigned InnerVT = (unsigned)MVT::FIRST_VECTOR_VALUETYPE; |
| 130 | InnerVT <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++InnerVT) |
| 131 | setTruncStoreAction(VT.getSimpleVT(), |
| 132 | (MVT::SimpleValueType)InnerVT, Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 133 | } |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 134 | setLoadExtAction(ISD::EXTLOAD, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 135 | |
| 136 | // Promote all bit-wise operations. |
| 137 | if (VT.isInteger() && VT != PromotedBitwiseVT) { |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 138 | setOperationAction(ISD::AND, VT.getSimpleVT(), Promote); |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 139 | AddPromotedToType (ISD::AND, VT.getSimpleVT(), |
| 140 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 141 | setOperationAction(ISD::OR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 142 | AddPromotedToType (ISD::OR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 143 | PromotedBitwiseVT.getSimpleVT()); |
Owen Anderson | 7067184 | 2009-08-10 20:18:46 +0000 | [diff] [blame] | 144 | setOperationAction(ISD::XOR, VT.getSimpleVT(), Promote); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 145 | AddPromotedToType (ISD::XOR, VT.getSimpleVT(), |
Owen Anderson | d6662ad | 2009-08-10 20:46:15 +0000 | [diff] [blame] | 146 | PromotedBitwiseVT.getSimpleVT()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 147 | } |
Bob Wilson | 1633076 | 2009-09-16 00:17:28 +0000 | [diff] [blame] | 148 | |
| 149 | // Neon does not support vector divide/remainder operations. |
| 150 | setOperationAction(ISD::SDIV, VT.getSimpleVT(), Expand); |
| 151 | setOperationAction(ISD::UDIV, VT.getSimpleVT(), Expand); |
| 152 | setOperationAction(ISD::FDIV, VT.getSimpleVT(), Expand); |
| 153 | setOperationAction(ISD::SREM, VT.getSimpleVT(), Expand); |
| 154 | setOperationAction(ISD::UREM, VT.getSimpleVT(), Expand); |
| 155 | setOperationAction(ISD::FREM, VT.getSimpleVT(), Expand); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 158 | void ARMTargetLowering::addDRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 159 | addRegisterClass(VT, ARM::DPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 160 | addTypeForNEON(VT, MVT::f64, MVT::v2i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 161 | } |
| 162 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 163 | void ARMTargetLowering::addQRTypeForNEON(EVT VT) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 164 | addRegisterClass(VT, ARM::QPRRegisterClass); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 165 | addTypeForNEON(VT, MVT::v2f64, MVT::v4i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 166 | } |
| 167 | |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 168 | static TargetLoweringObjectFile *createTLOF(TargetMachine &TM) { |
| 169 | if (TM.getSubtarget<ARMSubtarget>().isTargetDarwin()) |
Bill Wendling | 505ad8b | 2010-03-15 21:09:38 +0000 | [diff] [blame] | 170 | return new TargetLoweringObjectFileMachO(); |
Bill Wendling | 94a1c63 | 2010-03-09 02:46:12 +0000 | [diff] [blame] | 171 | |
Chris Lattner | 80ec279 | 2009-08-02 00:34:36 +0000 | [diff] [blame] | 172 | return new ARMElfTargetObjectFile(); |
Chris Lattner | f014412 | 2009-07-28 03:13:23 +0000 | [diff] [blame] | 173 | } |
| 174 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 175 | ARMTargetLowering::ARMTargetLowering(TargetMachine &TM) |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 176 | : TargetLowering(TM, createTLOF(TM)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 177 | Subtarget = &TM.getSubtarget<ARMSubtarget>(); |
Evan Cheng | 3144687 | 2010-07-23 22:39:59 +0000 | [diff] [blame] | 178 | RegInfo = TM.getRegisterInfo(); |
Evan Cheng | 3ef1c87 | 2010-09-10 01:29:16 +0000 | [diff] [blame] | 179 | Itins = TM.getInstrItineraryData(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 180 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 181 | if (Subtarget->isTargetDarwin()) { |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 182 | // Uses VFP for Thumb libfuncs if available. |
| 183 | if (Subtarget->isThumb() && Subtarget->hasVFP2()) { |
| 184 | // Single-precision floating-point arithmetic. |
| 185 | setLibcallName(RTLIB::ADD_F32, "__addsf3vfp"); |
| 186 | setLibcallName(RTLIB::SUB_F32, "__subsf3vfp"); |
| 187 | setLibcallName(RTLIB::MUL_F32, "__mulsf3vfp"); |
| 188 | setLibcallName(RTLIB::DIV_F32, "__divsf3vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 189 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 190 | // Double-precision floating-point arithmetic. |
| 191 | setLibcallName(RTLIB::ADD_F64, "__adddf3vfp"); |
| 192 | setLibcallName(RTLIB::SUB_F64, "__subdf3vfp"); |
| 193 | setLibcallName(RTLIB::MUL_F64, "__muldf3vfp"); |
| 194 | setLibcallName(RTLIB::DIV_F64, "__divdf3vfp"); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 195 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 196 | // Single-precision comparisons. |
| 197 | setLibcallName(RTLIB::OEQ_F32, "__eqsf2vfp"); |
| 198 | setLibcallName(RTLIB::UNE_F32, "__nesf2vfp"); |
| 199 | setLibcallName(RTLIB::OLT_F32, "__ltsf2vfp"); |
| 200 | setLibcallName(RTLIB::OLE_F32, "__lesf2vfp"); |
| 201 | setLibcallName(RTLIB::OGE_F32, "__gesf2vfp"); |
| 202 | setLibcallName(RTLIB::OGT_F32, "__gtsf2vfp"); |
| 203 | setLibcallName(RTLIB::UO_F32, "__unordsf2vfp"); |
| 204 | setLibcallName(RTLIB::O_F32, "__unordsf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 205 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 206 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 207 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETNE); |
| 208 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 209 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 210 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 211 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 212 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 213 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
Evan Cheng | 193f850 | 2007-01-31 09:30:58 +0000 | [diff] [blame] | 214 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 215 | // Double-precision comparisons. |
| 216 | setLibcallName(RTLIB::OEQ_F64, "__eqdf2vfp"); |
| 217 | setLibcallName(RTLIB::UNE_F64, "__nedf2vfp"); |
| 218 | setLibcallName(RTLIB::OLT_F64, "__ltdf2vfp"); |
| 219 | setLibcallName(RTLIB::OLE_F64, "__ledf2vfp"); |
| 220 | setLibcallName(RTLIB::OGE_F64, "__gedf2vfp"); |
| 221 | setLibcallName(RTLIB::OGT_F64, "__gtdf2vfp"); |
| 222 | setLibcallName(RTLIB::UO_F64, "__unorddf2vfp"); |
| 223 | setLibcallName(RTLIB::O_F64, "__unorddf2vfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 224 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 225 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 226 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETNE); |
| 227 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 228 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 229 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 230 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 231 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 232 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 233 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 234 | // Floating-point to integer conversions. |
| 235 | // i64 conversions are done via library routines even when generating VFP |
| 236 | // instructions, so use the same ones. |
| 237 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__fixdfsivfp"); |
| 238 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__fixunsdfsivfp"); |
| 239 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__fixsfsivfp"); |
| 240 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__fixunssfsivfp"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 241 | |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 242 | // Conversions between floating types. |
| 243 | setLibcallName(RTLIB::FPROUND_F64_F32, "__truncdfsf2vfp"); |
| 244 | setLibcallName(RTLIB::FPEXT_F32_F64, "__extendsfdf2vfp"); |
| 245 | |
| 246 | // Integer to floating-point conversions. |
| 247 | // i64 conversions are done via library routines even when generating VFP |
| 248 | // instructions, so use the same ones. |
Bob Wilson | 2a14c52 | 2009-03-20 23:16:43 +0000 | [diff] [blame] | 249 | // FIXME: There appears to be some naming inconsistency in ARM libgcc: |
| 250 | // e.g., __floatunsidf vs. __floatunssidfvfp. |
Evan Cheng | b1df8f2 | 2007-04-27 08:15:43 +0000 | [diff] [blame] | 251 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__floatsidfvfp"); |
| 252 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__floatunssidfvfp"); |
| 253 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__floatsisfvfp"); |
| 254 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__floatunssisfvfp"); |
| 255 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Bob Wilson | 2f95461 | 2009-05-22 17:38:41 +0000 | [diff] [blame] | 258 | // These libcalls are not available in 32-bit. |
| 259 | setLibcallName(RTLIB::SHL_I128, 0); |
| 260 | setLibcallName(RTLIB::SRL_I128, 0); |
| 261 | setLibcallName(RTLIB::SRA_I128, 0); |
| 262 | |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 263 | if (Subtarget->isAAPCS_ABI()) { |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 264 | // Double-precision floating-point arithmetic helper functions |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 265 | // RTABI chapter 4.1.2, Table 2 |
| 266 | setLibcallName(RTLIB::ADD_F64, "__aeabi_dadd"); |
| 267 | setLibcallName(RTLIB::DIV_F64, "__aeabi_ddiv"); |
| 268 | setLibcallName(RTLIB::MUL_F64, "__aeabi_dmul"); |
| 269 | setLibcallName(RTLIB::SUB_F64, "__aeabi_dsub"); |
| 270 | setLibcallCallingConv(RTLIB::ADD_F64, CallingConv::ARM_AAPCS); |
| 271 | setLibcallCallingConv(RTLIB::DIV_F64, CallingConv::ARM_AAPCS); |
| 272 | setLibcallCallingConv(RTLIB::MUL_F64, CallingConv::ARM_AAPCS); |
| 273 | setLibcallCallingConv(RTLIB::SUB_F64, CallingConv::ARM_AAPCS); |
| 274 | |
| 275 | // Double-precision floating-point comparison helper functions |
| 276 | // RTABI chapter 4.1.2, Table 3 |
| 277 | setLibcallName(RTLIB::OEQ_F64, "__aeabi_dcmpeq"); |
| 278 | setCmpLibcallCC(RTLIB::OEQ_F64, ISD::SETNE); |
| 279 | setLibcallName(RTLIB::UNE_F64, "__aeabi_dcmpeq"); |
| 280 | setCmpLibcallCC(RTLIB::UNE_F64, ISD::SETEQ); |
| 281 | setLibcallName(RTLIB::OLT_F64, "__aeabi_dcmplt"); |
| 282 | setCmpLibcallCC(RTLIB::OLT_F64, ISD::SETNE); |
| 283 | setLibcallName(RTLIB::OLE_F64, "__aeabi_dcmple"); |
| 284 | setCmpLibcallCC(RTLIB::OLE_F64, ISD::SETNE); |
| 285 | setLibcallName(RTLIB::OGE_F64, "__aeabi_dcmpge"); |
| 286 | setCmpLibcallCC(RTLIB::OGE_F64, ISD::SETNE); |
| 287 | setLibcallName(RTLIB::OGT_F64, "__aeabi_dcmpgt"); |
| 288 | setCmpLibcallCC(RTLIB::OGT_F64, ISD::SETNE); |
| 289 | setLibcallName(RTLIB::UO_F64, "__aeabi_dcmpun"); |
| 290 | setCmpLibcallCC(RTLIB::UO_F64, ISD::SETNE); |
| 291 | setLibcallName(RTLIB::O_F64, "__aeabi_dcmpun"); |
| 292 | setCmpLibcallCC(RTLIB::O_F64, ISD::SETEQ); |
| 293 | setLibcallCallingConv(RTLIB::OEQ_F64, CallingConv::ARM_AAPCS); |
| 294 | setLibcallCallingConv(RTLIB::UNE_F64, CallingConv::ARM_AAPCS); |
| 295 | setLibcallCallingConv(RTLIB::OLT_F64, CallingConv::ARM_AAPCS); |
| 296 | setLibcallCallingConv(RTLIB::OLE_F64, CallingConv::ARM_AAPCS); |
| 297 | setLibcallCallingConv(RTLIB::OGE_F64, CallingConv::ARM_AAPCS); |
| 298 | setLibcallCallingConv(RTLIB::OGT_F64, CallingConv::ARM_AAPCS); |
| 299 | setLibcallCallingConv(RTLIB::UO_F64, CallingConv::ARM_AAPCS); |
| 300 | setLibcallCallingConv(RTLIB::O_F64, CallingConv::ARM_AAPCS); |
| 301 | |
| 302 | // Single-precision floating-point arithmetic helper functions |
| 303 | // RTABI chapter 4.1.2, Table 4 |
| 304 | setLibcallName(RTLIB::ADD_F32, "__aeabi_fadd"); |
| 305 | setLibcallName(RTLIB::DIV_F32, "__aeabi_fdiv"); |
| 306 | setLibcallName(RTLIB::MUL_F32, "__aeabi_fmul"); |
| 307 | setLibcallName(RTLIB::SUB_F32, "__aeabi_fsub"); |
| 308 | setLibcallCallingConv(RTLIB::ADD_F32, CallingConv::ARM_AAPCS); |
| 309 | setLibcallCallingConv(RTLIB::DIV_F32, CallingConv::ARM_AAPCS); |
| 310 | setLibcallCallingConv(RTLIB::MUL_F32, CallingConv::ARM_AAPCS); |
| 311 | setLibcallCallingConv(RTLIB::SUB_F32, CallingConv::ARM_AAPCS); |
| 312 | |
| 313 | // Single-precision floating-point comparison helper functions |
| 314 | // RTABI chapter 4.1.2, Table 5 |
| 315 | setLibcallName(RTLIB::OEQ_F32, "__aeabi_fcmpeq"); |
| 316 | setCmpLibcallCC(RTLIB::OEQ_F32, ISD::SETNE); |
| 317 | setLibcallName(RTLIB::UNE_F32, "__aeabi_fcmpeq"); |
| 318 | setCmpLibcallCC(RTLIB::UNE_F32, ISD::SETEQ); |
| 319 | setLibcallName(RTLIB::OLT_F32, "__aeabi_fcmplt"); |
| 320 | setCmpLibcallCC(RTLIB::OLT_F32, ISD::SETNE); |
| 321 | setLibcallName(RTLIB::OLE_F32, "__aeabi_fcmple"); |
| 322 | setCmpLibcallCC(RTLIB::OLE_F32, ISD::SETNE); |
| 323 | setLibcallName(RTLIB::OGE_F32, "__aeabi_fcmpge"); |
| 324 | setCmpLibcallCC(RTLIB::OGE_F32, ISD::SETNE); |
| 325 | setLibcallName(RTLIB::OGT_F32, "__aeabi_fcmpgt"); |
| 326 | setCmpLibcallCC(RTLIB::OGT_F32, ISD::SETNE); |
| 327 | setLibcallName(RTLIB::UO_F32, "__aeabi_fcmpun"); |
| 328 | setCmpLibcallCC(RTLIB::UO_F32, ISD::SETNE); |
| 329 | setLibcallName(RTLIB::O_F32, "__aeabi_fcmpun"); |
| 330 | setCmpLibcallCC(RTLIB::O_F32, ISD::SETEQ); |
| 331 | setLibcallCallingConv(RTLIB::OEQ_F32, CallingConv::ARM_AAPCS); |
| 332 | setLibcallCallingConv(RTLIB::UNE_F32, CallingConv::ARM_AAPCS); |
| 333 | setLibcallCallingConv(RTLIB::OLT_F32, CallingConv::ARM_AAPCS); |
| 334 | setLibcallCallingConv(RTLIB::OLE_F32, CallingConv::ARM_AAPCS); |
| 335 | setLibcallCallingConv(RTLIB::OGE_F32, CallingConv::ARM_AAPCS); |
| 336 | setLibcallCallingConv(RTLIB::OGT_F32, CallingConv::ARM_AAPCS); |
| 337 | setLibcallCallingConv(RTLIB::UO_F32, CallingConv::ARM_AAPCS); |
| 338 | setLibcallCallingConv(RTLIB::O_F32, CallingConv::ARM_AAPCS); |
| 339 | |
| 340 | // Floating-point to integer conversions. |
| 341 | // RTABI chapter 4.1.2, Table 6 |
| 342 | setLibcallName(RTLIB::FPTOSINT_F64_I32, "__aeabi_d2iz"); |
| 343 | setLibcallName(RTLIB::FPTOUINT_F64_I32, "__aeabi_d2uiz"); |
| 344 | setLibcallName(RTLIB::FPTOSINT_F64_I64, "__aeabi_d2lz"); |
| 345 | setLibcallName(RTLIB::FPTOUINT_F64_I64, "__aeabi_d2ulz"); |
| 346 | setLibcallName(RTLIB::FPTOSINT_F32_I32, "__aeabi_f2iz"); |
| 347 | setLibcallName(RTLIB::FPTOUINT_F32_I32, "__aeabi_f2uiz"); |
| 348 | setLibcallName(RTLIB::FPTOSINT_F32_I64, "__aeabi_f2lz"); |
| 349 | setLibcallName(RTLIB::FPTOUINT_F32_I64, "__aeabi_f2ulz"); |
| 350 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I32, CallingConv::ARM_AAPCS); |
| 351 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I32, CallingConv::ARM_AAPCS); |
| 352 | setLibcallCallingConv(RTLIB::FPTOSINT_F64_I64, CallingConv::ARM_AAPCS); |
| 353 | setLibcallCallingConv(RTLIB::FPTOUINT_F64_I64, CallingConv::ARM_AAPCS); |
| 354 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I32, CallingConv::ARM_AAPCS); |
| 355 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I32, CallingConv::ARM_AAPCS); |
| 356 | setLibcallCallingConv(RTLIB::FPTOSINT_F32_I64, CallingConv::ARM_AAPCS); |
| 357 | setLibcallCallingConv(RTLIB::FPTOUINT_F32_I64, CallingConv::ARM_AAPCS); |
| 358 | |
| 359 | // Conversions between floating types. |
| 360 | // RTABI chapter 4.1.2, Table 7 |
| 361 | setLibcallName(RTLIB::FPROUND_F64_F32, "__aeabi_d2f"); |
| 362 | setLibcallName(RTLIB::FPEXT_F32_F64, "__aeabi_f2d"); |
| 363 | setLibcallCallingConv(RTLIB::FPROUND_F64_F32, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 364 | setLibcallCallingConv(RTLIB::FPEXT_F32_F64, CallingConv::ARM_AAPCS); |
Anton Korobeynikov | 4f922f2 | 2010-09-28 21:39:26 +0000 | [diff] [blame] | 365 | |
| 366 | // Integer to floating-point conversions. |
| 367 | // RTABI chapter 4.1.2, Table 8 |
| 368 | setLibcallName(RTLIB::SINTTOFP_I32_F64, "__aeabi_i2d"); |
| 369 | setLibcallName(RTLIB::UINTTOFP_I32_F64, "__aeabi_ui2d"); |
| 370 | setLibcallName(RTLIB::SINTTOFP_I64_F64, "__aeabi_l2d"); |
| 371 | setLibcallName(RTLIB::UINTTOFP_I64_F64, "__aeabi_ul2d"); |
| 372 | setLibcallName(RTLIB::SINTTOFP_I32_F32, "__aeabi_i2f"); |
| 373 | setLibcallName(RTLIB::UINTTOFP_I32_F32, "__aeabi_ui2f"); |
| 374 | setLibcallName(RTLIB::SINTTOFP_I64_F32, "__aeabi_l2f"); |
| 375 | setLibcallName(RTLIB::UINTTOFP_I64_F32, "__aeabi_ul2f"); |
| 376 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 377 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F64, CallingConv::ARM_AAPCS); |
| 378 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 379 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F64, CallingConv::ARM_AAPCS); |
| 380 | setLibcallCallingConv(RTLIB::SINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 381 | setLibcallCallingConv(RTLIB::UINTTOFP_I32_F32, CallingConv::ARM_AAPCS); |
| 382 | setLibcallCallingConv(RTLIB::SINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 383 | setLibcallCallingConv(RTLIB::UINTTOFP_I64_F32, CallingConv::ARM_AAPCS); |
| 384 | |
| 385 | // Long long helper functions |
| 386 | // RTABI chapter 4.2, Table 9 |
| 387 | setLibcallName(RTLIB::MUL_I64, "__aeabi_lmul"); |
| 388 | setLibcallName(RTLIB::SDIV_I64, "__aeabi_ldivmod"); |
| 389 | setLibcallName(RTLIB::UDIV_I64, "__aeabi_uldivmod"); |
| 390 | setLibcallName(RTLIB::SHL_I64, "__aeabi_llsl"); |
| 391 | setLibcallName(RTLIB::SRL_I64, "__aeabi_llsr"); |
| 392 | setLibcallName(RTLIB::SRA_I64, "__aeabi_lasr"); |
| 393 | setLibcallCallingConv(RTLIB::MUL_I64, CallingConv::ARM_AAPCS); |
| 394 | setLibcallCallingConv(RTLIB::SDIV_I64, CallingConv::ARM_AAPCS); |
| 395 | setLibcallCallingConv(RTLIB::UDIV_I64, CallingConv::ARM_AAPCS); |
| 396 | setLibcallCallingConv(RTLIB::SHL_I64, CallingConv::ARM_AAPCS); |
| 397 | setLibcallCallingConv(RTLIB::SRL_I64, CallingConv::ARM_AAPCS); |
| 398 | setLibcallCallingConv(RTLIB::SRA_I64, CallingConv::ARM_AAPCS); |
| 399 | |
| 400 | // Integer division functions |
| 401 | // RTABI chapter 4.3.1 |
| 402 | setLibcallName(RTLIB::SDIV_I8, "__aeabi_idiv"); |
| 403 | setLibcallName(RTLIB::SDIV_I16, "__aeabi_idiv"); |
| 404 | setLibcallName(RTLIB::SDIV_I32, "__aeabi_idiv"); |
| 405 | setLibcallName(RTLIB::UDIV_I8, "__aeabi_uidiv"); |
| 406 | setLibcallName(RTLIB::UDIV_I16, "__aeabi_uidiv"); |
| 407 | setLibcallName(RTLIB::UDIV_I32, "__aeabi_uidiv"); |
| 408 | setLibcallCallingConv(RTLIB::SDIV_I8, CallingConv::ARM_AAPCS); |
| 409 | setLibcallCallingConv(RTLIB::SDIV_I16, CallingConv::ARM_AAPCS); |
| 410 | setLibcallCallingConv(RTLIB::SDIV_I32, CallingConv::ARM_AAPCS); |
| 411 | setLibcallCallingConv(RTLIB::UDIV_I8, CallingConv::ARM_AAPCS); |
| 412 | setLibcallCallingConv(RTLIB::UDIV_I16, CallingConv::ARM_AAPCS); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 413 | setLibcallCallingConv(RTLIB::UDIV_I32, CallingConv::ARM_AAPCS); |
Renato Golin | 1ec11fb | 2011-05-22 21:41:23 +0000 | [diff] [blame] | 414 | |
| 415 | // Memory operations |
| 416 | // RTABI chapter 4.3.4 |
| 417 | setLibcallName(RTLIB::MEMCPY, "__aeabi_memcpy"); |
| 418 | setLibcallName(RTLIB::MEMMOVE, "__aeabi_memmove"); |
| 419 | setLibcallName(RTLIB::MEMSET, "__aeabi_memset"); |
Anton Korobeynikov | 72977a4 | 2009-08-14 20:10:52 +0000 | [diff] [blame] | 420 | } |
| 421 | |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 422 | if (Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 423 | addRegisterClass(MVT::i32, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 424 | else |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 425 | addRegisterClass(MVT::i32, ARM::GPRRegisterClass); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 426 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 427 | addRegisterClass(MVT::f32, ARM::SPRRegisterClass); |
Jim Grosbach | fcba5e6 | 2010-08-11 15:44:15 +0000 | [diff] [blame] | 428 | if (!Subtarget->isFPOnlySP()) |
| 429 | addRegisterClass(MVT::f64, ARM::DPRRegisterClass); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 430 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 431 | setTruncStoreAction(MVT::f64, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 432 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 433 | |
| 434 | if (Subtarget->hasNEON()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 435 | addDRTypeForNEON(MVT::v2f32); |
| 436 | addDRTypeForNEON(MVT::v8i8); |
| 437 | addDRTypeForNEON(MVT::v4i16); |
| 438 | addDRTypeForNEON(MVT::v2i32); |
| 439 | addDRTypeForNEON(MVT::v1i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 440 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 441 | addQRTypeForNEON(MVT::v4f32); |
| 442 | addQRTypeForNEON(MVT::v2f64); |
| 443 | addQRTypeForNEON(MVT::v16i8); |
| 444 | addQRTypeForNEON(MVT::v8i16); |
| 445 | addQRTypeForNEON(MVT::v4i32); |
| 446 | addQRTypeForNEON(MVT::v2i64); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 447 | |
Bob Wilson | 74dc72e | 2009-09-15 23:55:57 +0000 | [diff] [blame] | 448 | // v2f64 is legal so that QR subregs can be extracted as f64 elements, but |
| 449 | // neither Neon nor VFP support any arithmetic operations on it. |
| 450 | setOperationAction(ISD::FADD, MVT::v2f64, Expand); |
| 451 | setOperationAction(ISD::FSUB, MVT::v2f64, Expand); |
| 452 | setOperationAction(ISD::FMUL, MVT::v2f64, Expand); |
| 453 | setOperationAction(ISD::FDIV, MVT::v2f64, Expand); |
| 454 | setOperationAction(ISD::FREM, MVT::v2f64, Expand); |
| 455 | setOperationAction(ISD::FCOPYSIGN, MVT::v2f64, Expand); |
| 456 | setOperationAction(ISD::VSETCC, MVT::v2f64, Expand); |
| 457 | setOperationAction(ISD::FNEG, MVT::v2f64, Expand); |
| 458 | setOperationAction(ISD::FABS, MVT::v2f64, Expand); |
| 459 | setOperationAction(ISD::FSQRT, MVT::v2f64, Expand); |
| 460 | setOperationAction(ISD::FSIN, MVT::v2f64, Expand); |
| 461 | setOperationAction(ISD::FCOS, MVT::v2f64, Expand); |
| 462 | setOperationAction(ISD::FPOWI, MVT::v2f64, Expand); |
| 463 | setOperationAction(ISD::FPOW, MVT::v2f64, Expand); |
| 464 | setOperationAction(ISD::FLOG, MVT::v2f64, Expand); |
| 465 | setOperationAction(ISD::FLOG2, MVT::v2f64, Expand); |
| 466 | setOperationAction(ISD::FLOG10, MVT::v2f64, Expand); |
| 467 | setOperationAction(ISD::FEXP, MVT::v2f64, Expand); |
| 468 | setOperationAction(ISD::FEXP2, MVT::v2f64, Expand); |
| 469 | setOperationAction(ISD::FCEIL, MVT::v2f64, Expand); |
| 470 | setOperationAction(ISD::FTRUNC, MVT::v2f64, Expand); |
| 471 | setOperationAction(ISD::FRINT, MVT::v2f64, Expand); |
| 472 | setOperationAction(ISD::FNEARBYINT, MVT::v2f64, Expand); |
| 473 | setOperationAction(ISD::FFLOOR, MVT::v2f64, Expand); |
| 474 | |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 475 | setTruncStoreAction(MVT::v2f64, MVT::v2f32, Expand); |
| 476 | |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 477 | // Neon does not support some operations on v1i64 and v2i64 types. |
| 478 | setOperationAction(ISD::MUL, MVT::v1i64, Expand); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 479 | // Custom handling for some quad-vector types to detect VMULL. |
| 480 | setOperationAction(ISD::MUL, MVT::v8i16, Custom); |
| 481 | setOperationAction(ISD::MUL, MVT::v4i32, Custom); |
| 482 | setOperationAction(ISD::MUL, MVT::v2i64, Custom); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 483 | // Custom handling for some vector types to avoid expensive expansions |
| 484 | setOperationAction(ISD::SDIV, MVT::v4i16, Custom); |
| 485 | setOperationAction(ISD::SDIV, MVT::v8i8, Custom); |
| 486 | setOperationAction(ISD::UDIV, MVT::v4i16, Custom); |
| 487 | setOperationAction(ISD::UDIV, MVT::v8i8, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 488 | setOperationAction(ISD::VSETCC, MVT::v1i64, Expand); |
| 489 | setOperationAction(ISD::VSETCC, MVT::v2i64, Expand); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 490 | // Neon does not have single instruction SINT_TO_FP and UINT_TO_FP with |
| 491 | // a destination type that is wider than the source. |
| 492 | setOperationAction(ISD::SINT_TO_FP, MVT::v4i16, Custom); |
| 493 | setOperationAction(ISD::UINT_TO_FP, MVT::v4i16, Custom); |
Bob Wilson | 642b329 | 2009-09-16 00:32:15 +0000 | [diff] [blame] | 494 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 495 | setTargetDAGCombine(ISD::INTRINSIC_VOID); |
| 496 | setTargetDAGCombine(ISD::INTRINSIC_W_CHAIN); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 497 | setTargetDAGCombine(ISD::INTRINSIC_WO_CHAIN); |
| 498 | setTargetDAGCombine(ISD::SHL); |
| 499 | setTargetDAGCombine(ISD::SRL); |
| 500 | setTargetDAGCombine(ISD::SRA); |
| 501 | setTargetDAGCombine(ISD::SIGN_EXTEND); |
| 502 | setTargetDAGCombine(ISD::ZERO_EXTEND); |
| 503 | setTargetDAGCombine(ISD::ANY_EXTEND); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 504 | setTargetDAGCombine(ISD::SELECT_CC); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 505 | setTargetDAGCombine(ISD::BUILD_VECTOR); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 506 | setTargetDAGCombine(ISD::VECTOR_SHUFFLE); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 507 | setTargetDAGCombine(ISD::INSERT_VECTOR_ELT); |
| 508 | setTargetDAGCombine(ISD::STORE); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 509 | setTargetDAGCombine(ISD::FP_TO_SINT); |
| 510 | setTargetDAGCombine(ISD::FP_TO_UINT); |
| 511 | setTargetDAGCombine(ISD::FDIV); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Evan Cheng | 9f8cbd1 | 2007-05-18 00:19:34 +0000 | [diff] [blame] | 514 | computeRegisterProperties(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 515 | |
| 516 | // ARM does not have f32 extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 517 | setLoadExtAction(ISD::EXTLOAD, MVT::f32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 518 | |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 519 | // ARM does not have i1 sign extending load. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 520 | setLoadExtAction(ISD::SEXTLOAD, MVT::i1, Promote); |
Duncan Sands | f9c98e6 | 2008-01-23 20:39:46 +0000 | [diff] [blame] | 521 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 522 | // ARM supports all 4 flavors of integer indexed load / store. |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 523 | if (!Subtarget->isThumb1Only()) { |
| 524 | for (unsigned im = (unsigned)ISD::PRE_INC; |
| 525 | im != (unsigned)ISD::LAST_INDEXED_MODE; ++im) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 526 | setIndexedLoadAction(im, MVT::i1, Legal); |
| 527 | setIndexedLoadAction(im, MVT::i8, Legal); |
| 528 | setIndexedLoadAction(im, MVT::i16, Legal); |
| 529 | setIndexedLoadAction(im, MVT::i32, Legal); |
| 530 | setIndexedStoreAction(im, MVT::i1, Legal); |
| 531 | setIndexedStoreAction(im, MVT::i8, Legal); |
| 532 | setIndexedStoreAction(im, MVT::i16, Legal); |
| 533 | setIndexedStoreAction(im, MVT::i32, Legal); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 534 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | // i64 operation support. |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 538 | setOperationAction(ISD::MUL, MVT::i64, Expand); |
| 539 | setOperationAction(ISD::MULHU, MVT::i32, Expand); |
Evan Cheng | 5b9fcd1 | 2009-07-07 01:17:28 +0000 | [diff] [blame] | 540 | if (Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 541 | setOperationAction(ISD::UMUL_LOHI, MVT::i32, Expand); |
| 542 | setOperationAction(ISD::SMUL_LOHI, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 543 | } |
Jim Grosbach | a760398 | 2011-07-01 21:12:19 +0000 | [diff] [blame] | 544 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6Ops() |
| 545 | || (Subtarget->isThumb2() && !Subtarget->hasThumb2DSP())) |
Eric Christopher | 2cc4013 | 2011-04-19 18:49:19 +0000 | [diff] [blame] | 546 | setOperationAction(ISD::MULHS, MVT::i32, Expand); |
| 547 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 548 | setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 549 | setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 550 | setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 551 | setOperationAction(ISD::SRL, MVT::i64, Custom); |
| 552 | setOperationAction(ISD::SRA, MVT::i64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 553 | |
| 554 | // ARM does not have ROTL. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 555 | setOperationAction(ISD::ROTL, MVT::i32, Expand); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 556 | setOperationAction(ISD::CTTZ, MVT::i32, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 557 | setOperationAction(ISD::CTPOP, MVT::i32, Expand); |
David Goodwin | 24062ac | 2009-06-26 20:47:43 +0000 | [diff] [blame] | 558 | if (!Subtarget->hasV5TOps() || Subtarget->isThumb1Only()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 559 | setOperationAction(ISD::CTLZ, MVT::i32, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 560 | |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 561 | // Only ARMv6 has BSWAP. |
| 562 | if (!Subtarget->hasV6Ops()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 563 | setOperationAction(ISD::BSWAP, MVT::i32, Expand); |
Lauro Ramos Venancio | 368f20f | 2007-03-16 22:54:16 +0000 | [diff] [blame] | 564 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 565 | // These are expanded into libcalls. |
Evan Cheng | 1f190c8 | 2010-11-19 06:28:11 +0000 | [diff] [blame] | 566 | if (!Subtarget->hasDivide() || !Subtarget->isThumb2()) { |
Jim Grosbach | b1dc393 | 2010-05-05 20:44:35 +0000 | [diff] [blame] | 567 | // v7M has a hardware divider |
| 568 | setOperationAction(ISD::SDIV, MVT::i32, Expand); |
| 569 | setOperationAction(ISD::UDIV, MVT::i32, Expand); |
| 570 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 571 | setOperationAction(ISD::SREM, MVT::i32, Expand); |
| 572 | setOperationAction(ISD::UREM, MVT::i32, Expand); |
| 573 | setOperationAction(ISD::SDIVREM, MVT::i32, Expand); |
| 574 | setOperationAction(ISD::UDIVREM, MVT::i32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 575 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 576 | setOperationAction(ISD::GlobalAddress, MVT::i32, Custom); |
| 577 | setOperationAction(ISD::ConstantPool, MVT::i32, Custom); |
| 578 | setOperationAction(ISD::GLOBAL_OFFSET_TABLE, MVT::i32, Custom); |
| 579 | setOperationAction(ISD::GlobalTLSAddress, MVT::i32, Custom); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 580 | setOperationAction(ISD::BlockAddress, MVT::i32, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 581 | |
Evan Cheng | 4da0c7c | 2011-04-08 21:37:21 +0000 | [diff] [blame] | 582 | setOperationAction(ISD::TRAP, MVT::Other, Legal); |
Evan Cheng | fb3611d | 2010-05-11 07:26:32 +0000 | [diff] [blame] | 583 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 584 | // Use the default implementation. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 585 | setOperationAction(ISD::VASTART, MVT::Other, Custom); |
| 586 | setOperationAction(ISD::VAARG, MVT::Other, Expand); |
| 587 | setOperationAction(ISD::VACOPY, MVT::Other, Expand); |
| 588 | setOperationAction(ISD::VAEND, MVT::Other, Expand); |
| 589 | setOperationAction(ISD::STACKSAVE, MVT::Other, Expand); |
| 590 | setOperationAction(ISD::STACKRESTORE, MVT::Other, Expand); |
Jim Grosbach | bff3923 | 2009-08-12 17:38:44 +0000 | [diff] [blame] | 591 | setOperationAction(ISD::EHSELECTION, MVT::i32, Expand); |
Anton Korobeynikov | 5899a60 | 2011-01-24 22:38:45 +0000 | [diff] [blame] | 592 | setOperationAction(ISD::EXCEPTIONADDR, MVT::i32, Expand); |
| 593 | setExceptionPointerRegister(ARM::R0); |
| 594 | setExceptionSelectorRegister(ARM::R1); |
| 595 | |
Evan Cheng | 3a1588a | 2010-04-15 22:20:34 +0000 | [diff] [blame] | 596 | setOperationAction(ISD::DYNAMIC_STACKALLOC, MVT::i32, Expand); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 597 | // ARMv6 Thumb1 (except for CPUs that support dmb / dsb) and earlier use |
| 598 | // the default expansion. |
| 599 | if (Subtarget->hasDataBarrier() || |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 600 | (Subtarget->hasV6Ops() && !Subtarget->isThumb())) { |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 601 | // membarrier needs custom lowering; the rest are legal and handled |
| 602 | // normally. |
| 603 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Custom); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 604 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Custom); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 605 | // Automatically insert fences (dmb ist) around ATOMIC_SWAP etc. |
| 606 | setInsertFencesForAtomic(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 607 | } else { |
| 608 | // Set them all for expansion, which will force libcalls. |
| 609 | setOperationAction(ISD::MEMBARRIER, MVT::Other, Expand); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 610 | setOperationAction(ISD::ATOMIC_FENCE, MVT::Other, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 611 | setOperationAction(ISD::ATOMIC_CMP_SWAP, MVT::i32, Expand); |
Jim Grosbach | ef6eb9c | 2010-06-18 23:03:10 +0000 | [diff] [blame] | 612 | setOperationAction(ISD::ATOMIC_SWAP, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 613 | setOperationAction(ISD::ATOMIC_LOAD_ADD, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 614 | setOperationAction(ISD::ATOMIC_LOAD_SUB, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 615 | setOperationAction(ISD::ATOMIC_LOAD_AND, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 616 | setOperationAction(ISD::ATOMIC_LOAD_OR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 617 | setOperationAction(ISD::ATOMIC_LOAD_XOR, MVT::i32, Expand); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 618 | setOperationAction(ISD::ATOMIC_LOAD_NAND, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 619 | setOperationAction(ISD::ATOMIC_LOAD_MIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 620 | setOperationAction(ISD::ATOMIC_LOAD_MAX, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 621 | setOperationAction(ISD::ATOMIC_LOAD_UMIN, MVT::i32, Expand); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 622 | setOperationAction(ISD::ATOMIC_LOAD_UMAX, MVT::i32, Expand); |
Jim Grosbach | 5def57a | 2010-06-23 16:08:49 +0000 | [diff] [blame] | 623 | // Since the libcalls include locking, fold in the fences |
| 624 | setShouldFoldAtomicFences(true); |
Jim Grosbach | 68741be | 2010-06-18 22:35:32 +0000 | [diff] [blame] | 625 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 626 | |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 627 | setOperationAction(ISD::PREFETCH, MVT::Other, Custom); |
Evan Cheng | bc7deb0 | 2010-11-03 05:14:24 +0000 | [diff] [blame] | 628 | |
Eli Friedman | a2c6f45 | 2010-06-26 04:36:50 +0000 | [diff] [blame] | 629 | // Requires SXTB/SXTH, available on v6 and up in both ARM and Thumb modes. |
| 630 | if (!Subtarget->hasV6Ops()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 631 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand); |
| 632 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 633 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 634 | setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 635 | |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 636 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Bob Wilson | cb9a6aa | 2010-01-19 22:56:26 +0000 | [diff] [blame] | 637 | // Turn f64->i64 into VMOVRRD, i64 -> f64 to VMOVDRR |
| 638 | // iff target supports vfp2. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 639 | setOperationAction(ISD::BITCAST, MVT::i64, Custom); |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 640 | setOperationAction(ISD::FLT_ROUNDS_, MVT::i32, Custom); |
| 641 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 642 | |
| 643 | // We want to custom lower some of our intrinsics. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 644 | setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 645 | if (Subtarget->isTargetDarwin()) { |
| 646 | setOperationAction(ISD::EH_SJLJ_SETJMP, MVT::i32, Custom); |
| 647 | setOperationAction(ISD::EH_SJLJ_LONGJMP, MVT::Other, Custom); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 648 | setOperationAction(ISD::EH_SJLJ_DISPATCHSETUP, MVT::Other, Custom); |
John McCall | 5f8fd54 | 2011-05-29 19:50:32 +0000 | [diff] [blame] | 649 | setLibcallName(RTLIB::UNWIND_RESUME, "_Unwind_SjLj_Resume"); |
Jim Grosbach | e97f968 | 2010-07-07 00:07:57 +0000 | [diff] [blame] | 650 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 651 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 652 | setOperationAction(ISD::SETCC, MVT::i32, Expand); |
| 653 | setOperationAction(ISD::SETCC, MVT::f32, Expand); |
| 654 | setOperationAction(ISD::SETCC, MVT::f64, Expand); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 655 | setOperationAction(ISD::SELECT, MVT::i32, Custom); |
| 656 | setOperationAction(ISD::SELECT, MVT::f32, Custom); |
| 657 | setOperationAction(ISD::SELECT, MVT::f64, Custom); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 658 | setOperationAction(ISD::SELECT_CC, MVT::i32, Custom); |
| 659 | setOperationAction(ISD::SELECT_CC, MVT::f32, Custom); |
| 660 | setOperationAction(ISD::SELECT_CC, MVT::f64, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 661 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 662 | setOperationAction(ISD::BRCOND, MVT::Other, Expand); |
| 663 | setOperationAction(ISD::BR_CC, MVT::i32, Custom); |
| 664 | setOperationAction(ISD::BR_CC, MVT::f32, Custom); |
| 665 | setOperationAction(ISD::BR_CC, MVT::f64, Custom); |
| 666 | setOperationAction(ISD::BR_JT, MVT::Other, Custom); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 667 | |
Dan Gohman | f96e4de | 2007-10-11 23:21:31 +0000 | [diff] [blame] | 668 | // We don't support sin/cos/fmod/copysign/pow |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 669 | setOperationAction(ISD::FSIN, MVT::f64, Expand); |
| 670 | setOperationAction(ISD::FSIN, MVT::f32, Expand); |
| 671 | setOperationAction(ISD::FCOS, MVT::f32, Expand); |
| 672 | setOperationAction(ISD::FCOS, MVT::f64, Expand); |
| 673 | setOperationAction(ISD::FREM, MVT::f64, Expand); |
| 674 | setOperationAction(ISD::FREM, MVT::f32, Expand); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 675 | if (!UseSoftFloat && Subtarget->hasVFP2() && !Subtarget->isThumb1Only()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 676 | setOperationAction(ISD::FCOPYSIGN, MVT::f64, Custom); |
| 677 | setOperationAction(ISD::FCOPYSIGN, MVT::f32, Custom); |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 678 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 679 | setOperationAction(ISD::FPOW, MVT::f64, Expand); |
| 680 | setOperationAction(ISD::FPOW, MVT::f32, Expand); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 681 | |
Cameron Zwarich | 3339084 | 2011-07-08 21:39:21 +0000 | [diff] [blame] | 682 | setOperationAction(ISD::FMA, MVT::f64, Expand); |
| 683 | setOperationAction(ISD::FMA, MVT::f32, Expand); |
| 684 | |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 685 | // Various VFP goodness |
| 686 | if (!UseSoftFloat && !Subtarget->isThumb1Only()) { |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 687 | // int <-> fp are custom expanded into bit_convert + ARMISD ops. |
| 688 | if (Subtarget->hasVFP2()) { |
| 689 | setOperationAction(ISD::SINT_TO_FP, MVT::i32, Custom); |
| 690 | setOperationAction(ISD::UINT_TO_FP, MVT::i32, Custom); |
| 691 | setOperationAction(ISD::FP_TO_UINT, MVT::i32, Custom); |
| 692 | setOperationAction(ISD::FP_TO_SINT, MVT::i32, Custom); |
| 693 | } |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 694 | // Special handling for half-precision FP. |
Anton Korobeynikov | f0d5007 | 2010-03-18 22:35:37 +0000 | [diff] [blame] | 695 | if (!Subtarget->hasFP16()) { |
| 696 | setOperationAction(ISD::FP16_TO_FP32, MVT::f32, Expand); |
| 697 | setOperationAction(ISD::FP32_TO_FP16, MVT::i32, Expand); |
Anton Korobeynikov | bec3dd2 | 2010-03-14 18:42:31 +0000 | [diff] [blame] | 698 | } |
Evan Cheng | 110cf48 | 2008-04-01 01:50:16 +0000 | [diff] [blame] | 699 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 700 | |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 701 | // We have target-specific dag combine patterns for the following nodes: |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 702 | // ARMISD::VMOVRRD - No need to call setTargetDAGCombine |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 703 | setTargetDAGCombine(ISD::ADD); |
| 704 | setTargetDAGCombine(ISD::SUB); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 705 | setTargetDAGCombine(ISD::MUL); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 706 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 707 | if (Subtarget->hasV6T2Ops() || Subtarget->hasNEON()) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 708 | setTargetDAGCombine(ISD::OR); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 709 | if (Subtarget->hasNEON()) |
| 710 | setTargetDAGCombine(ISD::AND); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 711 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 712 | setStackPointerRegisterToSaveRestore(ARM::SP); |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 713 | |
Evan Cheng | f7d87ee | 2010-05-21 00:43:17 +0000 | [diff] [blame] | 714 | if (UseSoftFloat || Subtarget->isThumb1Only() || !Subtarget->hasVFP2()) |
| 715 | setSchedulingPreference(Sched::RegPressure); |
| 716 | else |
| 717 | setSchedulingPreference(Sched::Hybrid); |
Dale Johannesen | 8dd86c1 | 2007-05-17 21:31:21 +0000 | [diff] [blame] | 718 | |
Evan Cheng | 0521928 | 2011-01-06 06:52:41 +0000 | [diff] [blame] | 719 | //// temporary - rewrite interface to use type |
| 720 | maxStoresPerMemcpy = maxStoresPerMemcpyOptSize = 1; |
Evan Cheng | f679939 | 2010-06-26 01:52:05 +0000 | [diff] [blame] | 721 | |
Rafael Espindola | cbeeae2 | 2010-07-11 04:01:49 +0000 | [diff] [blame] | 722 | // On ARM arguments smaller than 4 bytes are extended, so all arguments |
| 723 | // are at least 4 bytes aligned. |
| 724 | setMinStackArgumentAlignment(4); |
| 725 | |
Evan Cheng | fff606d | 2010-09-24 19:07:23 +0000 | [diff] [blame] | 726 | benefitFromCodePlacementOpt = true; |
Eli Friedman | fc5d305 | 2011-05-06 20:34:06 +0000 | [diff] [blame] | 727 | |
| 728 | setMinFunctionAlignment(Subtarget->isThumb() ? 1 : 2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 729 | } |
| 730 | |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 731 | // FIXME: It might make sense to define the representative register class as the |
| 732 | // nearest super-register that has a non-null superset. For example, DPR_VFP2 is |
| 733 | // a super-register of SPR, and DPR is a superset if DPR_VFP2. Consequently, |
| 734 | // SPR's representative would be DPR_VFP2. This should work well if register |
| 735 | // pressure tracking were modified such that a register use would increment the |
| 736 | // pressure of the register class's representative and all of it's super |
| 737 | // classes' representatives transitively. We have not implemented this because |
| 738 | // of the difficulty prior to coalescing of modeling operand register classes |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 739 | // due to the common occurrence of cross class copies and subregister insertions |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 740 | // and extractions. |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 741 | std::pair<const TargetRegisterClass*, uint8_t> |
| 742 | ARMTargetLowering::findRepresentativeClass(EVT VT) const{ |
| 743 | const TargetRegisterClass *RRC = 0; |
| 744 | uint8_t Cost = 1; |
| 745 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 746 | default: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 747 | return TargetLowering::findRepresentativeClass(VT); |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 748 | // Use DPR as representative register class for all floating point |
| 749 | // and vector types. Since there are 32 SPR registers and 32 DPR registers so |
| 750 | // the cost is 1 for both f32 and f64. |
| 751 | case MVT::f32: case MVT::f64: case MVT::v8i8: case MVT::v4i16: |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 752 | case MVT::v2i32: case MVT::v1i64: case MVT::v2f32: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 753 | RRC = ARM::DPRRegisterClass; |
Andrew Trick | 32cec0a | 2011-01-19 02:35:27 +0000 | [diff] [blame] | 754 | // When NEON is used for SP, only half of the register file is available |
| 755 | // because operations that define both SP and DP results will be constrained |
| 756 | // to the VFP2 class (D0-D15). We currently model this constraint prior to |
| 757 | // coalescing by double-counting the SP regs. See the FIXME above. |
| 758 | if (Subtarget->useNEONForSinglePrecisionFP()) |
| 759 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 760 | break; |
| 761 | case MVT::v16i8: case MVT::v8i16: case MVT::v4i32: case MVT::v2i64: |
| 762 | case MVT::v4f32: case MVT::v2f64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 763 | RRC = ARM::DPRRegisterClass; |
| 764 | Cost = 2; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 765 | break; |
| 766 | case MVT::v4i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 767 | RRC = ARM::DPRRegisterClass; |
| 768 | Cost = 4; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 769 | break; |
| 770 | case MVT::v8i64: |
Evan Cheng | 4a863e2 | 2010-07-21 23:53:58 +0000 | [diff] [blame] | 771 | RRC = ARM::DPRRegisterClass; |
| 772 | Cost = 8; |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 773 | break; |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 774 | } |
Evan Cheng | 4f6b467 | 2010-07-21 06:09:07 +0000 | [diff] [blame] | 775 | return std::make_pair(RRC, Cost); |
Evan Cheng | d70f57b | 2010-07-19 22:15:08 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 778 | const char *ARMTargetLowering::getTargetNodeName(unsigned Opcode) const { |
| 779 | switch (Opcode) { |
| 780 | default: return 0; |
| 781 | case ARMISD::Wrapper: return "ARMISD::Wrapper"; |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 782 | case ARMISD::WrapperDYN: return "ARMISD::WrapperDYN"; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 783 | case ARMISD::WrapperPIC: return "ARMISD::WrapperPIC"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 784 | case ARMISD::WrapperJT: return "ARMISD::WrapperJT"; |
| 785 | case ARMISD::CALL: return "ARMISD::CALL"; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 786 | case ARMISD::CALL_PRED: return "ARMISD::CALL_PRED"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 787 | case ARMISD::CALL_NOLINK: return "ARMISD::CALL_NOLINK"; |
| 788 | case ARMISD::tCALL: return "ARMISD::tCALL"; |
| 789 | case ARMISD::BRCOND: return "ARMISD::BRCOND"; |
| 790 | case ARMISD::BR_JT: return "ARMISD::BR_JT"; |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 791 | case ARMISD::BR2_JT: return "ARMISD::BR2_JT"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 792 | case ARMISD::RET_FLAG: return "ARMISD::RET_FLAG"; |
| 793 | case ARMISD::PIC_ADD: return "ARMISD::PIC_ADD"; |
| 794 | case ARMISD::CMP: return "ARMISD::CMP"; |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 795 | case ARMISD::CMPZ: return "ARMISD::CMPZ"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 796 | case ARMISD::CMPFP: return "ARMISD::CMPFP"; |
| 797 | case ARMISD::CMPFPw0: return "ARMISD::CMPFPw0"; |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 798 | case ARMISD::BCC_i64: return "ARMISD::BCC_i64"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 799 | case ARMISD::FMSTAT: return "ARMISD::FMSTAT"; |
| 800 | case ARMISD::CMOV: return "ARMISD::CMOV"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 801 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 802 | case ARMISD::RBIT: return "ARMISD::RBIT"; |
| 803 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 804 | case ARMISD::FTOSI: return "ARMISD::FTOSI"; |
| 805 | case ARMISD::FTOUI: return "ARMISD::FTOUI"; |
| 806 | case ARMISD::SITOF: return "ARMISD::SITOF"; |
| 807 | case ARMISD::UITOF: return "ARMISD::UITOF"; |
| 808 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 809 | case ARMISD::SRL_FLAG: return "ARMISD::SRL_FLAG"; |
| 810 | case ARMISD::SRA_FLAG: return "ARMISD::SRA_FLAG"; |
| 811 | case ARMISD::RRX: return "ARMISD::RRX"; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 812 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 813 | case ARMISD::VMOVRRD: return "ARMISD::VMOVRRD"; |
| 814 | case ARMISD::VMOVDRR: return "ARMISD::VMOVDRR"; |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 815 | |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 816 | case ARMISD::EH_SJLJ_SETJMP: return "ARMISD::EH_SJLJ_SETJMP"; |
| 817 | case ARMISD::EH_SJLJ_LONGJMP:return "ARMISD::EH_SJLJ_LONGJMP"; |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 818 | case ARMISD::EH_SJLJ_DISPATCHSETUP:return "ARMISD::EH_SJLJ_DISPATCHSETUP"; |
Evan Cheng | c594208 | 2009-10-28 06:55:03 +0000 | [diff] [blame] | 819 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 820 | case ARMISD::TC_RETURN: return "ARMISD::TC_RETURN"; |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 821 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 822 | case ARMISD::THREAD_POINTER:return "ARMISD::THREAD_POINTER"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 823 | |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 824 | case ARMISD::DYN_ALLOC: return "ARMISD::DYN_ALLOC"; |
| 825 | |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 826 | case ARMISD::MEMBARRIER: return "ARMISD::MEMBARRIER"; |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 827 | case ARMISD::MEMBARRIER_MCR: return "ARMISD::MEMBARRIER_MCR"; |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 828 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 829 | case ARMISD::PRELOAD: return "ARMISD::PRELOAD"; |
| 830 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 831 | case ARMISD::VCEQ: return "ARMISD::VCEQ"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 832 | case ARMISD::VCEQZ: return "ARMISD::VCEQZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 833 | case ARMISD::VCGE: return "ARMISD::VCGE"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 834 | case ARMISD::VCGEZ: return "ARMISD::VCGEZ"; |
| 835 | case ARMISD::VCLEZ: return "ARMISD::VCLEZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 836 | case ARMISD::VCGEU: return "ARMISD::VCGEU"; |
| 837 | case ARMISD::VCGT: return "ARMISD::VCGT"; |
Bob Wilson | 3a75b9b | 2010-12-18 00:04:26 +0000 | [diff] [blame] | 838 | case ARMISD::VCGTZ: return "ARMISD::VCGTZ"; |
| 839 | case ARMISD::VCLTZ: return "ARMISD::VCLTZ"; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 840 | case ARMISD::VCGTU: return "ARMISD::VCGTU"; |
| 841 | case ARMISD::VTST: return "ARMISD::VTST"; |
| 842 | |
| 843 | case ARMISD::VSHL: return "ARMISD::VSHL"; |
| 844 | case ARMISD::VSHRs: return "ARMISD::VSHRs"; |
| 845 | case ARMISD::VSHRu: return "ARMISD::VSHRu"; |
| 846 | case ARMISD::VSHLLs: return "ARMISD::VSHLLs"; |
| 847 | case ARMISD::VSHLLu: return "ARMISD::VSHLLu"; |
| 848 | case ARMISD::VSHLLi: return "ARMISD::VSHLLi"; |
| 849 | case ARMISD::VSHRN: return "ARMISD::VSHRN"; |
| 850 | case ARMISD::VRSHRs: return "ARMISD::VRSHRs"; |
| 851 | case ARMISD::VRSHRu: return "ARMISD::VRSHRu"; |
| 852 | case ARMISD::VRSHRN: return "ARMISD::VRSHRN"; |
| 853 | case ARMISD::VQSHLs: return "ARMISD::VQSHLs"; |
| 854 | case ARMISD::VQSHLu: return "ARMISD::VQSHLu"; |
| 855 | case ARMISD::VQSHLsu: return "ARMISD::VQSHLsu"; |
| 856 | case ARMISD::VQSHRNs: return "ARMISD::VQSHRNs"; |
| 857 | case ARMISD::VQSHRNu: return "ARMISD::VQSHRNu"; |
| 858 | case ARMISD::VQSHRNsu: return "ARMISD::VQSHRNsu"; |
| 859 | case ARMISD::VQRSHRNs: return "ARMISD::VQRSHRNs"; |
| 860 | case ARMISD::VQRSHRNu: return "ARMISD::VQRSHRNu"; |
| 861 | case ARMISD::VQRSHRNsu: return "ARMISD::VQRSHRNsu"; |
| 862 | case ARMISD::VGETLANEu: return "ARMISD::VGETLANEu"; |
| 863 | case ARMISD::VGETLANEs: return "ARMISD::VGETLANEs"; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 864 | case ARMISD::VMOVIMM: return "ARMISD::VMOVIMM"; |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 865 | case ARMISD::VMVNIMM: return "ARMISD::VMVNIMM"; |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 866 | case ARMISD::VDUP: return "ARMISD::VDUP"; |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 867 | case ARMISD::VDUPLANE: return "ARMISD::VDUPLANE"; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 868 | case ARMISD::VEXT: return "ARMISD::VEXT"; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 869 | case ARMISD::VREV64: return "ARMISD::VREV64"; |
| 870 | case ARMISD::VREV32: return "ARMISD::VREV32"; |
| 871 | case ARMISD::VREV16: return "ARMISD::VREV16"; |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 872 | case ARMISD::VZIP: return "ARMISD::VZIP"; |
| 873 | case ARMISD::VUZP: return "ARMISD::VUZP"; |
| 874 | case ARMISD::VTRN: return "ARMISD::VTRN"; |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 875 | case ARMISD::VTBL1: return "ARMISD::VTBL1"; |
| 876 | case ARMISD::VTBL2: return "ARMISD::VTBL2"; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 877 | case ARMISD::VMULLs: return "ARMISD::VMULLs"; |
| 878 | case ARMISD::VMULLu: return "ARMISD::VMULLu"; |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 879 | case ARMISD::BUILD_VECTOR: return "ARMISD::BUILD_VECTOR"; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 880 | case ARMISD::FMAX: return "ARMISD::FMAX"; |
| 881 | case ARMISD::FMIN: return "ARMISD::FMIN"; |
Jim Grosbach | dd7d28a | 2010-07-17 01:50:57 +0000 | [diff] [blame] | 882 | case ARMISD::BFI: return "ARMISD::BFI"; |
Bob Wilson | 364a72a | 2010-11-28 06:51:11 +0000 | [diff] [blame] | 883 | case ARMISD::VORRIMM: return "ARMISD::VORRIMM"; |
| 884 | case ARMISD::VBICIMM: return "ARMISD::VBICIMM"; |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 885 | case ARMISD::VBSL: return "ARMISD::VBSL"; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 886 | case ARMISD::VLD2DUP: return "ARMISD::VLD2DUP"; |
| 887 | case ARMISD::VLD3DUP: return "ARMISD::VLD3DUP"; |
| 888 | case ARMISD::VLD4DUP: return "ARMISD::VLD4DUP"; |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 889 | case ARMISD::VLD1_UPD: return "ARMISD::VLD1_UPD"; |
| 890 | case ARMISD::VLD2_UPD: return "ARMISD::VLD2_UPD"; |
| 891 | case ARMISD::VLD3_UPD: return "ARMISD::VLD3_UPD"; |
| 892 | case ARMISD::VLD4_UPD: return "ARMISD::VLD4_UPD"; |
| 893 | case ARMISD::VLD2LN_UPD: return "ARMISD::VLD2LN_UPD"; |
| 894 | case ARMISD::VLD3LN_UPD: return "ARMISD::VLD3LN_UPD"; |
| 895 | case ARMISD::VLD4LN_UPD: return "ARMISD::VLD4LN_UPD"; |
| 896 | case ARMISD::VLD2DUP_UPD: return "ARMISD::VLD2DUP_UPD"; |
| 897 | case ARMISD::VLD3DUP_UPD: return "ARMISD::VLD3DUP_UPD"; |
| 898 | case ARMISD::VLD4DUP_UPD: return "ARMISD::VLD4DUP_UPD"; |
| 899 | case ARMISD::VST1_UPD: return "ARMISD::VST1_UPD"; |
| 900 | case ARMISD::VST2_UPD: return "ARMISD::VST2_UPD"; |
| 901 | case ARMISD::VST3_UPD: return "ARMISD::VST3_UPD"; |
| 902 | case ARMISD::VST4_UPD: return "ARMISD::VST4_UPD"; |
| 903 | case ARMISD::VST2LN_UPD: return "ARMISD::VST2LN_UPD"; |
| 904 | case ARMISD::VST3LN_UPD: return "ARMISD::VST3LN_UPD"; |
| 905 | case ARMISD::VST4LN_UPD: return "ARMISD::VST4LN_UPD"; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 906 | } |
| 907 | } |
| 908 | |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 909 | /// getRegClassFor - Return the register class that should be used for the |
| 910 | /// specified value type. |
| 911 | TargetRegisterClass *ARMTargetLowering::getRegClassFor(EVT VT) const { |
| 912 | // Map v4i64 to QQ registers but do not make the type legal. Similarly map |
| 913 | // v8i64 to QQQQ registers. v4i64 and v8i64 are only used for REG_SEQUENCE to |
| 914 | // load / store 4 to 8 consecutive D registers. |
Evan Cheng | 4782b1e | 2010-05-15 02:20:21 +0000 | [diff] [blame] | 915 | if (Subtarget->hasNEON()) { |
| 916 | if (VT == MVT::v4i64) |
| 917 | return ARM::QQPRRegisterClass; |
| 918 | else if (VT == MVT::v8i64) |
| 919 | return ARM::QQQQPRRegisterClass; |
| 920 | } |
Evan Cheng | 06b666c | 2010-05-15 02:18:07 +0000 | [diff] [blame] | 921 | return TargetLowering::getRegClassFor(VT); |
| 922 | } |
| 923 | |
Eric Christopher | ab69588 | 2010-07-21 22:26:11 +0000 | [diff] [blame] | 924 | // Create a fast isel object. |
| 925 | FastISel * |
| 926 | ARMTargetLowering::createFastISel(FunctionLoweringInfo &funcInfo) const { |
| 927 | return ARM::createFastISel(funcInfo); |
| 928 | } |
| 929 | |
Anton Korobeynikov | cec36f4 | 2010-07-24 21:52:08 +0000 | [diff] [blame] | 930 | /// getMaximalGlobalOffset - Returns the maximal possible offset which can |
| 931 | /// be used for loads / stores from the global. |
| 932 | unsigned ARMTargetLowering::getMaximalGlobalOffset() const { |
| 933 | return (Subtarget->isThumb1Only() ? 127 : 4095); |
| 934 | } |
| 935 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 936 | Sched::Preference ARMTargetLowering::getSchedulingPreference(SDNode *N) const { |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 937 | unsigned NumVals = N->getNumValues(); |
| 938 | if (!NumVals) |
| 939 | return Sched::RegPressure; |
| 940 | |
| 941 | for (unsigned i = 0; i != NumVals; ++i) { |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 942 | EVT VT = N->getValueType(i); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 943 | if (VT == MVT::Glue || VT == MVT::Other) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 944 | continue; |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 945 | if (VT.isFloatingPoint() || VT.isVector()) |
| 946 | return Sched::Latency; |
| 947 | } |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 948 | |
| 949 | if (!N->isMachineOpcode()) |
| 950 | return Sched::RegPressure; |
| 951 | |
| 952 | // Load are scheduled for latency even if there instruction itinerary |
| 953 | // is not available. |
| 954 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 955 | const MCInstrDesc &MCID = TII->get(N->getMachineOpcode()); |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 956 | |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 957 | if (MCID.getNumDefs() == 0) |
Evan Cheng | d7e473c | 2010-10-29 18:07:31 +0000 | [diff] [blame] | 958 | return Sched::RegPressure; |
| 959 | if (!Itins->isEmpty() && |
Evan Cheng | e837dea | 2011-06-28 19:10:37 +0000 | [diff] [blame] | 960 | Itins->getOperandCycle(MCID.getSchedClass(), 0) > 2) |
Evan Cheng | c10f543 | 2010-05-28 23:25:23 +0000 | [diff] [blame] | 961 | return Sched::Latency; |
| 962 | |
Evan Cheng | 1cc3984 | 2010-05-20 23:26:43 +0000 | [diff] [blame] | 963 | return Sched::RegPressure; |
| 964 | } |
| 965 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 966 | //===----------------------------------------------------------------------===// |
| 967 | // Lowering Code |
| 968 | //===----------------------------------------------------------------------===// |
| 969 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 970 | /// IntCCToARMCC - Convert a DAG integer condition code to an ARM CC |
| 971 | static ARMCC::CondCodes IntCCToARMCC(ISD::CondCode CC) { |
| 972 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 973 | default: llvm_unreachable("Unknown condition code!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 974 | case ISD::SETNE: return ARMCC::NE; |
| 975 | case ISD::SETEQ: return ARMCC::EQ; |
| 976 | case ISD::SETGT: return ARMCC::GT; |
| 977 | case ISD::SETGE: return ARMCC::GE; |
| 978 | case ISD::SETLT: return ARMCC::LT; |
| 979 | case ISD::SETLE: return ARMCC::LE; |
| 980 | case ISD::SETUGT: return ARMCC::HI; |
| 981 | case ISD::SETUGE: return ARMCC::HS; |
| 982 | case ISD::SETULT: return ARMCC::LO; |
| 983 | case ISD::SETULE: return ARMCC::LS; |
| 984 | } |
| 985 | } |
| 986 | |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 987 | /// FPCCToARMCC - Convert a DAG fp condition code to an ARM CC. |
| 988 | static void FPCCToARMCC(ISD::CondCode CC, ARMCC::CondCodes &CondCode, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 989 | ARMCC::CondCodes &CondCode2) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 990 | CondCode2 = ARMCC::AL; |
| 991 | switch (CC) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 992 | default: llvm_unreachable("Unknown FP condition!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 993 | case ISD::SETEQ: |
| 994 | case ISD::SETOEQ: CondCode = ARMCC::EQ; break; |
| 995 | case ISD::SETGT: |
| 996 | case ISD::SETOGT: CondCode = ARMCC::GT; break; |
| 997 | case ISD::SETGE: |
| 998 | case ISD::SETOGE: CondCode = ARMCC::GE; break; |
| 999 | case ISD::SETOLT: CondCode = ARMCC::MI; break; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 1000 | case ISD::SETOLE: CondCode = ARMCC::LS; break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1001 | case ISD::SETONE: CondCode = ARMCC::MI; CondCode2 = ARMCC::GT; break; |
| 1002 | case ISD::SETO: CondCode = ARMCC::VC; break; |
| 1003 | case ISD::SETUO: CondCode = ARMCC::VS; break; |
| 1004 | case ISD::SETUEQ: CondCode = ARMCC::EQ; CondCode2 = ARMCC::VS; break; |
| 1005 | case ISD::SETUGT: CondCode = ARMCC::HI; break; |
| 1006 | case ISD::SETUGE: CondCode = ARMCC::PL; break; |
| 1007 | case ISD::SETLT: |
| 1008 | case ISD::SETULT: CondCode = ARMCC::LT; break; |
| 1009 | case ISD::SETLE: |
| 1010 | case ISD::SETULE: CondCode = ARMCC::LE; break; |
| 1011 | case ISD::SETNE: |
| 1012 | case ISD::SETUNE: CondCode = ARMCC::NE; break; |
| 1013 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1014 | } |
| 1015 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1016 | //===----------------------------------------------------------------------===// |
| 1017 | // Calling Convention Implementation |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1018 | //===----------------------------------------------------------------------===// |
| 1019 | |
| 1020 | #include "ARMGenCallingConv.inc" |
| 1021 | |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1022 | /// CCAssignFnForNode - Selects the correct CCAssignFn for a the |
| 1023 | /// given CallingConvention value. |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1024 | CCAssignFn *ARMTargetLowering::CCAssignFnForNode(CallingConv::ID CC, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1025 | bool Return, |
| 1026 | bool isVarArg) const { |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1027 | switch (CC) { |
| 1028 | default: |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1029 | llvm_unreachable("Unsupported calling convention"); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1030 | case CallingConv::Fast: |
Evan Cheng | 5c2d428 | 2010-10-23 02:19:37 +0000 | [diff] [blame] | 1031 | if (Subtarget->hasVFP2() && !isVarArg) { |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1032 | if (!Subtarget->isAAPCS_ABI()) |
| 1033 | return (Return ? RetFastCC_ARM_APCS : FastCC_ARM_APCS); |
| 1034 | // For AAPCS ABI targets, just use VFP variant of the calling convention. |
| 1035 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1036 | } |
| 1037 | // Fallthrough |
| 1038 | case CallingConv::C: { |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1039 | // Use target triple & subtarget features to do actual dispatch. |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1040 | if (!Subtarget->isAAPCS_ABI()) |
| 1041 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
| 1042 | else if (Subtarget->hasVFP2() && |
| 1043 | FloatABIType == FloatABI::Hard && !isVarArg) |
| 1044 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
| 1045 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
| 1046 | } |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1047 | case CallingConv::ARM_AAPCS_VFP: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1048 | return (Return ? RetCC_ARM_AAPCS_VFP : CC_ARM_AAPCS_VFP); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1049 | case CallingConv::ARM_AAPCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1050 | return (Return ? RetCC_ARM_AAPCS : CC_ARM_AAPCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1051 | case CallingConv::ARM_APCS: |
Evan Cheng | 76f920d | 2010-10-22 18:23:05 +0000 | [diff] [blame] | 1052 | return (Return ? RetCC_ARM_APCS : CC_ARM_APCS); |
Anton Korobeynikov | 385f5a9 | 2009-06-16 18:50:49 +0000 | [diff] [blame] | 1053 | } |
| 1054 | } |
| 1055 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1056 | /// LowerCallResult - Lower the result values of a call into the |
| 1057 | /// appropriate copies out of appropriate physical registers. |
| 1058 | SDValue |
| 1059 | ARMTargetLowering::LowerCallResult(SDValue Chain, SDValue InFlag, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1060 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1061 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1062 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1063 | SmallVectorImpl<SDValue> &InVals) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1064 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1065 | // Assign locations to each value returned by this call. |
| 1066 | SmallVector<CCValAssign, 16> RVLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1067 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1068 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1069 | CCInfo.AnalyzeCallResult(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1070 | CCAssignFnForNode(CallConv, /* Return*/ true, |
| 1071 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1072 | |
| 1073 | // Copy all of the result registers out of their specified physreg. |
| 1074 | for (unsigned i = 0; i != RVLocs.size(); ++i) { |
| 1075 | CCValAssign VA = RVLocs[i]; |
| 1076 | |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1077 | SDValue Val; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1078 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1079 | // Handle f64 or half of a v2f64. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1080 | SDValue Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1081 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1082 | Chain = Lo.getValue(1); |
| 1083 | InFlag = Lo.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1084 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1085 | SDValue Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1086 | InFlag); |
| 1087 | Chain = Hi.getValue(1); |
| 1088 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1089 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1090 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1091 | if (VA.getLocVT() == MVT::v2f64) { |
| 1092 | SDValue Vec = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 1093 | Vec = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1094 | DAG.getConstant(0, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1095 | |
| 1096 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1097 | Lo = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1098 | Chain = Lo.getValue(1); |
| 1099 | InFlag = Lo.getValue(2); |
| 1100 | VA = RVLocs[++i]; // skip ahead to next loc |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1101 | Hi = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), MVT::i32, InFlag); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1102 | Chain = Hi.getValue(1); |
| 1103 | InFlag = Hi.getValue(2); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1104 | Val = DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1105 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Vec, Val, |
| 1106 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1107 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1108 | } else { |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1109 | Val = DAG.getCopyFromReg(Chain, dl, VA.getLocReg(), VA.getLocVT(), |
| 1110 | InFlag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1111 | Chain = Val.getValue(1); |
| 1112 | InFlag = Val.getValue(2); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1113 | } |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1114 | |
| 1115 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1116 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1117 | case CCValAssign::Full: break; |
| 1118 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1119 | Val = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), Val); |
Bob Wilson | 8091524 | 2009-04-25 00:33:20 +0000 | [diff] [blame] | 1120 | break; |
| 1121 | } |
| 1122 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1123 | InVals.push_back(Val); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1124 | } |
| 1125 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1126 | return Chain; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1129 | /// LowerMemOpCallTo - Store the argument to the stack. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1130 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1131 | ARMTargetLowering::LowerMemOpCallTo(SDValue Chain, |
| 1132 | SDValue StackPtr, SDValue Arg, |
| 1133 | DebugLoc dl, SelectionDAG &DAG, |
| 1134 | const CCValAssign &VA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1135 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1136 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1137 | SDValue PtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1138 | PtrOff = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, PtrOff); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1139 | return DAG.getStore(Chain, dl, Arg, PtrOff, |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 1140 | MachinePointerInfo::getStack(LocMemOffset), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1141 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1144 | void ARMTargetLowering::PassF64ArgInRegs(DebugLoc dl, SelectionDAG &DAG, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1145 | SDValue Chain, SDValue &Arg, |
| 1146 | RegsToPassVector &RegsToPass, |
| 1147 | CCValAssign &VA, CCValAssign &NextVA, |
| 1148 | SDValue &StackPtr, |
| 1149 | SmallVector<SDValue, 8> &MemOpChains, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1150 | ISD::ArgFlagsTy Flags) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1151 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1152 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1153 | DAG.getVTList(MVT::i32, MVT::i32), Arg); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1154 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), fmrrd)); |
| 1155 | |
| 1156 | if (NextVA.isRegLoc()) |
| 1157 | RegsToPass.push_back(std::make_pair(NextVA.getLocReg(), fmrrd.getValue(1))); |
| 1158 | else { |
| 1159 | assert(NextVA.isMemLoc()); |
| 1160 | if (StackPtr.getNode() == 0) |
| 1161 | StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
| 1162 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1163 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, fmrrd.getValue(1), |
| 1164 | dl, DAG, NextVA, |
| 1165 | Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1169 | /// LowerCall - Lowering a call into a callseq_start <- |
Evan Cheng | fc40342 | 2007-02-03 08:53:01 +0000 | [diff] [blame] | 1170 | /// ARMISD:CALL <- callseq_end chain. Also add input and output parameter |
| 1171 | /// nodes. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1172 | SDValue |
Evan Cheng | 022d9e1 | 2010-02-02 23:55:14 +0000 | [diff] [blame] | 1173 | ARMTargetLowering::LowerCall(SDValue Chain, SDValue Callee, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1174 | CallingConv::ID CallConv, bool isVarArg, |
Evan Cheng | 0c439eb | 2010-01-27 00:07:07 +0000 | [diff] [blame] | 1175 | bool &isTailCall, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1176 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1177 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1178 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1179 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1180 | SmallVectorImpl<SDValue> &InVals) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1181 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1182 | bool IsStructRet = (Outs.empty()) ? false : Outs[0].Flags.isSRet(); |
| 1183 | bool IsSibCall = false; |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1184 | // Temporarily disable tail calls so things don't break. |
Evan Cheng | 0b65599 | 2011-05-20 17:38:48 +0000 | [diff] [blame] | 1185 | if (!EnableARMTailCalls) |
Bob Wilson | 703af3a | 2010-08-13 22:43:33 +0000 | [diff] [blame] | 1186 | isTailCall = false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1187 | if (isTailCall) { |
| 1188 | // Check if it's really possible to do a tail call. |
| 1189 | isTailCall = IsEligibleForTailCallOptimization(Callee, CallConv, |
| 1190 | isVarArg, IsStructRet, MF.getFunction()->hasStructRetAttr(), |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1191 | Outs, OutVals, Ins, DAG); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1192 | // We don't support GuaranteedTailCallOpt for ARM, only automatically |
| 1193 | // detected sibcalls. |
| 1194 | if (isTailCall) { |
| 1195 | ++NumTailCalls; |
| 1196 | IsSibCall = true; |
| 1197 | } |
| 1198 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1199 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1200 | // Analyze operands of the call, assigning locations to each operand. |
| 1201 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1202 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1203 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1204 | CCInfo.AnalyzeCallOperands(Outs, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1205 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 1206 | isVarArg)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1207 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1208 | // Get a count of how many bytes are to be pushed on the stack. |
| 1209 | unsigned NumBytes = CCInfo.getNextStackOffset(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1210 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1211 | // For tail calls, memory operands are available in our caller's stack. |
| 1212 | if (IsSibCall) |
| 1213 | NumBytes = 0; |
| 1214 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1215 | // Adjust the stack pointer for the new arguments... |
| 1216 | // These operations are automatically eliminated by the prolog/epilog pass |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1217 | if (!IsSibCall) |
| 1218 | Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes, true)); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1219 | |
Jim Grosbach | f9a4b76 | 2010-02-24 01:43:03 +0000 | [diff] [blame] | 1220 | SDValue StackPtr = DAG.getCopyFromReg(Chain, dl, ARM::SP, getPointerTy()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1221 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1222 | RegsToPassVector RegsToPass; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1223 | SmallVector<SDValue, 8> MemOpChains; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1224 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1225 | // Walk the register/memloc assignments, inserting copies/loads. In the case |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1226 | // of tail call optimization, arguments are handled later. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1227 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1228 | i != e; |
| 1229 | ++i, ++realArgIdx) { |
| 1230 | CCValAssign &VA = ArgLocs[i]; |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1231 | SDValue Arg = OutVals[realArgIdx]; |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1232 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1233 | bool isByVal = Flags.isByVal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1234 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1235 | // Promote the value if needed. |
| 1236 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1237 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1238 | case CCValAssign::Full: break; |
| 1239 | case CCValAssign::SExt: |
| 1240 | Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg); |
| 1241 | break; |
| 1242 | case CCValAssign::ZExt: |
| 1243 | Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg); |
| 1244 | break; |
| 1245 | case CCValAssign::AExt: |
| 1246 | Arg = DAG.getNode(ISD::ANY_EXTEND, dl, VA.getLocVT(), Arg); |
| 1247 | break; |
| 1248 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1249 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1250 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1251 | } |
| 1252 | |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1253 | // f64 and v2f64 might be passed in i32 pairs and must be split into pieces |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1254 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1255 | if (VA.getLocVT() == MVT::v2f64) { |
| 1256 | SDValue Op0 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1257 | DAG.getConstant(0, MVT::i32)); |
| 1258 | SDValue Op1 = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1259 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1260 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1261 | PassF64ArgInRegs(dl, DAG, Chain, Op0, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1262 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1263 | |
| 1264 | VA = ArgLocs[++i]; // skip ahead to next loc |
| 1265 | if (VA.isRegLoc()) { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1266 | PassF64ArgInRegs(dl, DAG, Chain, Op1, RegsToPass, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1267 | VA, ArgLocs[++i], StackPtr, MemOpChains, Flags); |
| 1268 | } else { |
| 1269 | assert(VA.isMemLoc()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1270 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1271 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Op1, |
| 1272 | dl, DAG, VA, Flags)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1273 | } |
| 1274 | } else { |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1275 | PassF64ArgInRegs(dl, DAG, Chain, Arg, RegsToPass, VA, ArgLocs[++i], |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1276 | StackPtr, MemOpChains, Flags); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1277 | } |
| 1278 | } else if (VA.isRegLoc()) { |
| 1279 | RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg)); |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1280 | } else if (isByVal) { |
| 1281 | assert(VA.isMemLoc()); |
| 1282 | unsigned offset = 0; |
| 1283 | |
| 1284 | // True if this byval aggregate will be split between registers |
| 1285 | // and memory. |
| 1286 | if (CCInfo.isFirstByValRegValid()) { |
| 1287 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
| 1288 | unsigned int i, j; |
| 1289 | for (i = 0, j = CCInfo.getFirstByValReg(); j < ARM::R4; i++, j++) { |
| 1290 | SDValue Const = DAG.getConstant(4*i, MVT::i32); |
| 1291 | SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const); |
| 1292 | SDValue Load = DAG.getLoad(PtrVT, dl, Chain, AddArg, |
| 1293 | MachinePointerInfo(), |
| 1294 | false, false, 0); |
| 1295 | MemOpChains.push_back(Load.getValue(1)); |
| 1296 | RegsToPass.push_back(std::make_pair(j, Load)); |
| 1297 | } |
| 1298 | offset = ARM::R4 - CCInfo.getFirstByValReg(); |
| 1299 | CCInfo.clearFirstByValReg(); |
| 1300 | } |
| 1301 | |
| 1302 | unsigned LocMemOffset = VA.getLocMemOffset(); |
| 1303 | SDValue StkPtrOff = DAG.getIntPtrConstant(LocMemOffset); |
| 1304 | SDValue Dst = DAG.getNode(ISD::ADD, dl, getPointerTy(), StackPtr, |
| 1305 | StkPtrOff); |
| 1306 | SDValue SrcOffset = DAG.getIntPtrConstant(4*offset); |
| 1307 | SDValue Src = DAG.getNode(ISD::ADD, dl, getPointerTy(), Arg, SrcOffset); |
| 1308 | SDValue SizeNode = DAG.getConstant(Flags.getByValSize() - 4*offset, |
| 1309 | MVT::i32); |
| 1310 | MemOpChains.push_back(DAG.getMemcpy(Chain, dl, Dst, Src, SizeNode, |
| 1311 | Flags.getByValAlign(), |
| 1312 | /*isVolatile=*/false, |
| 1313 | /*AlwaysInline=*/false, |
| 1314 | MachinePointerInfo(0), |
| 1315 | MachinePointerInfo(0))); |
| 1316 | |
| 1317 | } else if (!IsSibCall) { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1318 | assert(VA.isMemLoc()); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1319 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1320 | MemOpChains.push_back(LowerMemOpCallTo(Chain, StackPtr, Arg, |
| 1321 | dl, DAG, VA, Flags)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1322 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | if (!MemOpChains.empty()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1326 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1327 | &MemOpChains[0], MemOpChains.size()); |
| 1328 | |
| 1329 | // Build a sequence of copy-to-reg nodes chained together with token chain |
| 1330 | // and flag operands which copy the outgoing args into the appropriate regs. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1331 | SDValue InFlag; |
Dale Johannesen | 6470a11 | 2010-06-15 22:08:33 +0000 | [diff] [blame] | 1332 | // Tail call byval lowering might overwrite argument registers so in case of |
| 1333 | // tail call optimization the copies to registers are lowered later. |
| 1334 | if (!isTailCall) |
| 1335 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1336 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1337 | RegsToPass[i].second, InFlag); |
| 1338 | InFlag = Chain.getValue(1); |
| 1339 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1340 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1341 | // For tail calls lower the arguments to the 'real' stack slot. |
| 1342 | if (isTailCall) { |
| 1343 | // Force all the incoming stack arguments to be loaded from the stack |
| 1344 | // before any new outgoing arguments are stored to the stack, because the |
| 1345 | // outgoing stack slots may alias the incoming argument stack slots, and |
| 1346 | // the alias isn't otherwise explicit. This is slightly more conservative |
| 1347 | // than necessary, because it means that each store effectively depends |
| 1348 | // on every argument instead of just those arguments it would clobber. |
| 1349 | |
Chris Lattner | 7a2bdde | 2011-04-15 05:18:47 +0000 | [diff] [blame] | 1350 | // Do not flag preceding copytoreg stuff together with the following stuff. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1351 | InFlag = SDValue(); |
| 1352 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) { |
| 1353 | Chain = DAG.getCopyToReg(Chain, dl, RegsToPass[i].first, |
| 1354 | RegsToPass[i].second, InFlag); |
| 1355 | InFlag = Chain.getValue(1); |
| 1356 | } |
| 1357 | InFlag =SDValue(); |
| 1358 | } |
| 1359 | |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1360 | // If the callee is a GlobalAddress/ExternalSymbol node (quite common, every |
| 1361 | // direct call is) turn it into a TargetGlobalAddress/TargetExternalSymbol |
| 1362 | // node so that legalize doesn't hack it. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1363 | bool isDirect = false; |
| 1364 | bool isARMFunc = false; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1365 | bool isLocalARMFunc = false; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1366 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1367 | |
| 1368 | if (EnableARMLongCalls) { |
| 1369 | assert (getTargetMachine().getRelocationModel() == Reloc::Static |
| 1370 | && "long-calls with non-static relocation model!"); |
| 1371 | // Handle a global address or an external symbol. If it's not one of |
| 1372 | // those, the target's already in a register, so we don't need to do |
| 1373 | // anything extra. |
| 1374 | if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Anders Carlsson | 0dbdca5 | 2010-04-15 03:11:28 +0000 | [diff] [blame] | 1375 | const GlobalValue *GV = G->getGlobal(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1376 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1377 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1378 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
| 1379 | ARMPCLabelIndex, |
| 1380 | ARMCP::CPValue, 0); |
| 1381 | // Get the address of the callee into a register |
| 1382 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1383 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1384 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1385 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1386 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1387 | false, false, 0); |
| 1388 | } else if (ExternalSymbolSDNode *S=dyn_cast<ExternalSymbolSDNode>(Callee)) { |
| 1389 | const char *Sym = S->getSymbol(); |
| 1390 | |
| 1391 | // Create a constant pool entry for the callee address |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1392 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1393 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 1394 | Sym, ARMPCLabelIndex, 0); |
| 1395 | // Get the address of the callee into a register |
| 1396 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
| 1397 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 1398 | Callee = DAG.getLoad(getPointerTy(), dl, |
| 1399 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1400 | MachinePointerInfo::getConstantPool(), |
Jim Grosbach | e7b5252 | 2010-04-14 22:28:31 +0000 | [diff] [blame] | 1401 | false, false, 0); |
| 1402 | } |
| 1403 | } else if (GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee)) { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1404 | const GlobalValue *GV = G->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1405 | isDirect = true; |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1406 | bool isExt = GV->isDeclaration() || GV->isWeakForLinker(); |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1407 | bool isStub = (isExt && Subtarget->isTargetDarwin()) && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1408 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1409 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1410 | // ARM call to a local ARM function is predicable. |
Evan Cheng | 46df4eb | 2010-06-16 07:35:02 +0000 | [diff] [blame] | 1411 | isLocalARMFunc = !Subtarget->isThumb() && (!isExt || !ARMInterworking); |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1412 | // tBX takes a register source operand. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1413 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1414 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1415 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 1416 | ARMPCLabelIndex, |
| 1417 | ARMCP::CPValue, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1418 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1419 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1420 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1421 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1422 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1423 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1424 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1425 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1426 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1427 | } else { |
| 1428 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1429 | unsigned OpFlags = 0; |
| 1430 | if (Subtarget->isTargetELF() && |
| 1431 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1432 | OpFlags = ARMII::MO_PLT; |
| 1433 | Callee = DAG.getTargetGlobalAddress(GV, dl, getPointerTy(), 0, OpFlags); |
| 1434 | } |
Bill Wendling | 056292f | 2008-09-16 21:48:12 +0000 | [diff] [blame] | 1435 | } else if (ExternalSymbolSDNode *S = dyn_cast<ExternalSymbolSDNode>(Callee)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1436 | isDirect = true; |
Evan Cheng | 970a419 | 2007-01-19 19:28:01 +0000 | [diff] [blame] | 1437 | bool isStub = Subtarget->isTargetDarwin() && |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1438 | getTargetMachine().getRelocationModel() != Reloc::Static; |
| 1439 | isARMFunc = !Subtarget->isThumb() || isStub; |
Evan Cheng | c60e76d | 2007-01-30 20:37:08 +0000 | [diff] [blame] | 1440 | // tBX takes a register source operand. |
| 1441 | const char *Sym = S->getSymbol(); |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 1442 | if (isARMFunc && Subtarget->isThumb1Only() && !Subtarget->hasV5TOps()) { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1443 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 1444 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1445 | Sym, ARMPCLabelIndex, 4); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1446 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, getPointerTy(), 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1447 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1448 | Callee = DAG.getLoad(getPointerTy(), dl, |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1449 | DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1450 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1451 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1452 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1453 | Callee = DAG.getNode(ARMISD::PIC_ADD, dl, |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1454 | getPointerTy(), Callee, PICLabel); |
Jim Grosbach | 637d89f | 2010-09-22 23:27:36 +0000 | [diff] [blame] | 1455 | } else { |
| 1456 | unsigned OpFlags = 0; |
| 1457 | // On ELF targets for PIC code, direct calls should go through the PLT |
| 1458 | if (Subtarget->isTargetELF() && |
| 1459 | getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 1460 | OpFlags = ARMII::MO_PLT; |
| 1461 | Callee = DAG.getTargetExternalSymbol(Sym, getPointerTy(), OpFlags); |
| 1462 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1465 | // FIXME: handle tail calls differently. |
| 1466 | unsigned CallOpc; |
Evan Cheng | b620724 | 2009-08-01 00:16:10 +0000 | [diff] [blame] | 1467 | if (Subtarget->isThumb()) { |
| 1468 | if ((!isDirect || isARMFunc) && !Subtarget->hasV5TOps()) |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1469 | CallOpc = ARMISD::CALL_NOLINK; |
| 1470 | else |
| 1471 | CallOpc = isARMFunc ? ARMISD::CALL : ARMISD::tCALL; |
| 1472 | } else { |
| 1473 | CallOpc = (isDirect || Subtarget->hasV5TOps()) |
Evan Cheng | 277f074 | 2007-06-19 21:05:09 +0000 | [diff] [blame] | 1474 | ? (isLocalARMFunc ? ARMISD::CALL_PRED : ARMISD::CALL) |
| 1475 | : ARMISD::CALL_NOLINK; |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1476 | } |
Lauro Ramos Venancio | 64c88d7 | 2007-03-20 17:57:23 +0000 | [diff] [blame] | 1477 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1478 | std::vector<SDValue> Ops; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1479 | Ops.push_back(Chain); |
| 1480 | Ops.push_back(Callee); |
| 1481 | |
| 1482 | // Add argument registers to the end of the list so that they are known live |
| 1483 | // into the call. |
| 1484 | for (unsigned i = 0, e = RegsToPass.size(); i != e; ++i) |
| 1485 | Ops.push_back(DAG.getRegister(RegsToPass[i].first, |
| 1486 | RegsToPass[i].second.getValueType())); |
| 1487 | |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 1488 | if (InFlag.getNode()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1489 | Ops.push_back(InFlag); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1490 | |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 1491 | SDVTList NodeTys = DAG.getVTList(MVT::Other, MVT::Glue); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1492 | if (isTailCall) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1493 | return DAG.getNode(ARMISD::TC_RETURN, dl, NodeTys, &Ops[0], Ops.size()); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1494 | |
Duncan Sands | 4bdcb61 | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 1495 | // Returns a chain and a flag for retval copy to use. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1496 | Chain = DAG.getNode(CallOpc, dl, NodeTys, &Ops[0], Ops.size()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1497 | InFlag = Chain.getValue(1); |
| 1498 | |
Chris Lattner | e563bbc | 2008-10-11 22:08:30 +0000 | [diff] [blame] | 1499 | Chain = DAG.getCALLSEQ_END(Chain, DAG.getIntPtrConstant(NumBytes, true), |
| 1500 | DAG.getIntPtrConstant(0, true), InFlag); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1501 | if (!Ins.empty()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1502 | InFlag = Chain.getValue(1); |
| 1503 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1504 | // Handle result values, copying them out of physregs into vregs that we |
| 1505 | // return. |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1506 | return LowerCallResult(Chain, InFlag, CallConv, isVarArg, Ins, |
| 1507 | dl, DAG, InVals); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1508 | } |
| 1509 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1510 | /// HandleByVal - Every parameter *after* a byval parameter is passed |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1511 | /// on the stack. Remember the next parameter register to allocate, |
| 1512 | /// and then confiscate the rest of the parameter registers to insure |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1513 | /// this. |
| 1514 | void |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 1515 | llvm::ARMTargetLowering::HandleByVal(CCState *State, unsigned &size) const { |
| 1516 | unsigned reg = State->AllocateReg(GPRArgRegs, 4); |
| 1517 | assert((State->getCallOrPrologue() == Prologue || |
| 1518 | State->getCallOrPrologue() == Call) && |
| 1519 | "unhandled ParmContext"); |
| 1520 | if ((!State->isFirstByValRegValid()) && |
| 1521 | (ARM::R0 <= reg) && (reg <= ARM::R3)) { |
| 1522 | State->setFirstByValReg(reg); |
| 1523 | // At a call site, a byval parameter that is split between |
| 1524 | // registers and memory needs its size truncated here. In a |
| 1525 | // function prologue, such byval parameters are reassembled in |
| 1526 | // memory, and are not truncated. |
| 1527 | if (State->getCallOrPrologue() == Call) { |
| 1528 | unsigned excess = 4 * (ARM::R4 - reg); |
| 1529 | assert(size >= excess && "expected larger existing stack allocation"); |
| 1530 | size -= excess; |
| 1531 | } |
| 1532 | } |
| 1533 | // Confiscate any remaining parameter registers to preclude their |
| 1534 | // assignment to subsequent parameters. |
| 1535 | while (State->AllocateReg(GPRArgRegs, 4)) |
| 1536 | ; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1539 | /// MatchingStackOffset - Return true if the given stack call argument is |
| 1540 | /// already available in the same position (relatively) of the caller's |
| 1541 | /// incoming argument stack. |
| 1542 | static |
| 1543 | bool MatchingStackOffset(SDValue Arg, unsigned Offset, ISD::ArgFlagsTy Flags, |
| 1544 | MachineFrameInfo *MFI, const MachineRegisterInfo *MRI, |
| 1545 | const ARMInstrInfo *TII) { |
| 1546 | unsigned Bytes = Arg.getValueType().getSizeInBits() / 8; |
| 1547 | int FI = INT_MAX; |
| 1548 | if (Arg.getOpcode() == ISD::CopyFromReg) { |
| 1549 | unsigned VR = cast<RegisterSDNode>(Arg.getOperand(1))->getReg(); |
Jakob Stoklund Olesen | c9df025 | 2011-01-10 02:58:51 +0000 | [diff] [blame] | 1550 | if (!TargetRegisterInfo::isVirtualRegister(VR)) |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1551 | return false; |
| 1552 | MachineInstr *Def = MRI->getVRegDef(VR); |
| 1553 | if (!Def) |
| 1554 | return false; |
| 1555 | if (!Flags.isByVal()) { |
| 1556 | if (!TII->isLoadFromStackSlot(Def, FI)) |
| 1557 | return false; |
| 1558 | } else { |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1559 | return false; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1560 | } |
| 1561 | } else if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Arg)) { |
| 1562 | if (Flags.isByVal()) |
| 1563 | // ByVal argument is passed in as a pointer but it's now being |
| 1564 | // dereferenced. e.g. |
| 1565 | // define @foo(%struct.X* %A) { |
| 1566 | // tail call @bar(%struct.X* byval %A) |
| 1567 | // } |
| 1568 | return false; |
| 1569 | SDValue Ptr = Ld->getBasePtr(); |
| 1570 | FrameIndexSDNode *FINode = dyn_cast<FrameIndexSDNode>(Ptr); |
| 1571 | if (!FINode) |
| 1572 | return false; |
| 1573 | FI = FINode->getIndex(); |
| 1574 | } else |
| 1575 | return false; |
| 1576 | |
| 1577 | assert(FI != INT_MAX); |
| 1578 | if (!MFI->isFixedObjectIndex(FI)) |
| 1579 | return false; |
| 1580 | return Offset == MFI->getObjectOffset(FI) && Bytes == MFI->getObjectSize(FI); |
| 1581 | } |
| 1582 | |
| 1583 | /// IsEligibleForTailCallOptimization - Check whether the call is eligible |
| 1584 | /// for tail call optimization. Targets which want to do tail call |
| 1585 | /// optimization should implement this function. |
| 1586 | bool |
| 1587 | ARMTargetLowering::IsEligibleForTailCallOptimization(SDValue Callee, |
| 1588 | CallingConv::ID CalleeCC, |
| 1589 | bool isVarArg, |
| 1590 | bool isCalleeStructRet, |
| 1591 | bool isCallerStructRet, |
| 1592 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1593 | const SmallVectorImpl<SDValue> &OutVals, |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1594 | const SmallVectorImpl<ISD::InputArg> &Ins, |
| 1595 | SelectionDAG& DAG) const { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1596 | const Function *CallerF = DAG.getMachineFunction().getFunction(); |
| 1597 | CallingConv::ID CallerCC = CallerF->getCallingConv(); |
| 1598 | bool CCMatch = CallerCC == CalleeCC; |
| 1599 | |
| 1600 | // Look for obvious safe cases to perform tail call optimization that do not |
| 1601 | // require ABI changes. This is what gcc calls sibcall. |
| 1602 | |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 1603 | // Do not sibcall optimize vararg calls unless the call site is not passing |
| 1604 | // any arguments. |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1605 | if (isVarArg && !Outs.empty()) |
| 1606 | return false; |
| 1607 | |
| 1608 | // Also avoid sibcall optimization if either caller or callee uses struct |
| 1609 | // return semantics. |
| 1610 | if (isCalleeStructRet || isCallerStructRet) |
| 1611 | return false; |
| 1612 | |
Dale Johannesen | e39fdbe | 2010-06-23 18:52:34 +0000 | [diff] [blame] | 1613 | // FIXME: Completely disable sibcall for Thumb1 since Thumb1RegisterInfo:: |
Jim Grosbach | 8dc41f3 | 2011-07-08 20:18:11 +0000 | [diff] [blame] | 1614 | // emitEpilogue is not ready for them. Thumb tail calls also use t2B, as |
| 1615 | // the Thumb1 16-bit unconditional branch doesn't have sufficient relocation |
| 1616 | // support in the assembler and linker to be used. This would need to be |
| 1617 | // fixed to fully support tail calls in Thumb1. |
| 1618 | // |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1619 | // Doing this is tricky, since the LDM/POP instruction on Thumb doesn't take |
| 1620 | // LR. This means if we need to reload LR, it takes an extra instructions, |
| 1621 | // which outweighs the value of the tail call; but here we don't know yet |
| 1622 | // whether LR is going to be used. Probably the right approach is to |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1623 | // generate the tail call here and turn it back into CALL/RET in |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1624 | // emitEpilogue if LR is used. |
Dale Johannesen | 7835f1f | 2010-07-08 01:18:23 +0000 | [diff] [blame] | 1625 | |
| 1626 | // Thumb1 PIC calls to external symbols use BX, so they can be tail calls, |
| 1627 | // but we need to make sure there are enough registers; the only valid |
| 1628 | // registers are the 4 used for parameters. We don't currently do this |
| 1629 | // case. |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1630 | if (Subtarget->isThumb1Only()) |
| 1631 | return false; |
Dale Johannesen | df50d7e | 2010-06-18 18:13:11 +0000 | [diff] [blame] | 1632 | |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1633 | // If the calling conventions do not match, then we'd better make sure the |
| 1634 | // results are returned in the same way as what the caller expects. |
| 1635 | if (!CCMatch) { |
| 1636 | SmallVector<CCValAssign, 16> RVLocs1; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1637 | ARMCCState CCInfo1(CalleeCC, false, DAG.getMachineFunction(), |
| 1638 | getTargetMachine(), RVLocs1, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1639 | CCInfo1.AnalyzeCallResult(Ins, CCAssignFnForNode(CalleeCC, true, isVarArg)); |
| 1640 | |
| 1641 | SmallVector<CCValAssign, 16> RVLocs2; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1642 | ARMCCState CCInfo2(CallerCC, false, DAG.getMachineFunction(), |
| 1643 | getTargetMachine(), RVLocs2, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1644 | CCInfo2.AnalyzeCallResult(Ins, CCAssignFnForNode(CallerCC, true, isVarArg)); |
| 1645 | |
| 1646 | if (RVLocs1.size() != RVLocs2.size()) |
| 1647 | return false; |
| 1648 | for (unsigned i = 0, e = RVLocs1.size(); i != e; ++i) { |
| 1649 | if (RVLocs1[i].isRegLoc() != RVLocs2[i].isRegLoc()) |
| 1650 | return false; |
| 1651 | if (RVLocs1[i].getLocInfo() != RVLocs2[i].getLocInfo()) |
| 1652 | return false; |
| 1653 | if (RVLocs1[i].isRegLoc()) { |
| 1654 | if (RVLocs1[i].getLocReg() != RVLocs2[i].getLocReg()) |
| 1655 | return false; |
| 1656 | } else { |
| 1657 | if (RVLocs1[i].getLocMemOffset() != RVLocs2[i].getLocMemOffset()) |
| 1658 | return false; |
| 1659 | } |
| 1660 | } |
| 1661 | } |
| 1662 | |
| 1663 | // If the callee takes no arguments then go on to check the results of the |
| 1664 | // call. |
| 1665 | if (!Outs.empty()) { |
| 1666 | // Check if stack adjustment is needed. For now, do not do this if any |
| 1667 | // argument is passed on the stack. |
| 1668 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1669 | ARMCCState CCInfo(CalleeCC, isVarArg, DAG.getMachineFunction(), |
| 1670 | getTargetMachine(), ArgLocs, *DAG.getContext(), Call); |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1671 | CCInfo.AnalyzeCallOperands(Outs, |
| 1672 | CCAssignFnForNode(CalleeCC, false, isVarArg)); |
| 1673 | if (CCInfo.getNextStackOffset()) { |
| 1674 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1675 | |
| 1676 | // Check if the arguments are already laid out in the right way as |
| 1677 | // the caller's fixed stack objects. |
| 1678 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 1679 | const MachineRegisterInfo *MRI = &MF.getRegInfo(); |
| 1680 | const ARMInstrInfo *TII = |
| 1681 | ((ARMTargetMachine&)getTargetMachine()).getInstrInfo(); |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1682 | for (unsigned i = 0, realArgIdx = 0, e = ArgLocs.size(); |
| 1683 | i != e; |
| 1684 | ++i, ++realArgIdx) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1685 | CCValAssign &VA = ArgLocs[i]; |
| 1686 | EVT RegVT = VA.getLocVT(); |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1687 | SDValue Arg = OutVals[realArgIdx]; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1688 | ISD::ArgFlagsTy Flags = Outs[realArgIdx].Flags; |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1689 | if (VA.getLocInfo() == CCValAssign::Indirect) |
| 1690 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1691 | if (VA.needsCustom()) { |
| 1692 | // f64 and vector types are split into multiple registers or |
| 1693 | // register/stack-slot combinations. The types will not match |
| 1694 | // the registers; give up on memory f64 refs until we figure |
| 1695 | // out what to do about this. |
| 1696 | if (!VA.isRegLoc()) |
| 1697 | return false; |
| 1698 | if (!ArgLocs[++i].isRegLoc()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 1699 | return false; |
Dale Johannesen | cf296fa | 2010-06-05 00:51:39 +0000 | [diff] [blame] | 1700 | if (RegVT == MVT::v2f64) { |
| 1701 | if (!ArgLocs[++i].isRegLoc()) |
| 1702 | return false; |
| 1703 | if (!ArgLocs[++i].isRegLoc()) |
| 1704 | return false; |
| 1705 | } |
| 1706 | } else if (!VA.isRegLoc()) { |
Dale Johannesen | 51e28e6 | 2010-06-03 21:09:53 +0000 | [diff] [blame] | 1707 | if (!MatchingStackOffset(Arg, VA.getLocMemOffset(), Flags, |
| 1708 | MFI, MRI, TII)) |
| 1709 | return false; |
| 1710 | } |
| 1711 | } |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | return true; |
| 1716 | } |
| 1717 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1718 | SDValue |
| 1719 | ARMTargetLowering::LowerReturn(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 1720 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1721 | const SmallVectorImpl<ISD::OutputArg> &Outs, |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1722 | const SmallVectorImpl<SDValue> &OutVals, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1723 | DebugLoc dl, SelectionDAG &DAG) const { |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 1724 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1725 | // CCValAssign - represent the assignment of the return value to a location. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1726 | SmallVector<CCValAssign, 16> RVLocs; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1727 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1728 | // CCState - Info about the registers and stack slots. |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 1729 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 1730 | getTargetMachine(), RVLocs, *DAG.getContext(), Call); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1731 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1732 | // Analyze outgoing return values. |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 1733 | CCInfo.AnalyzeReturn(Outs, CCAssignFnForNode(CallConv, /* Return */ true, |
| 1734 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1735 | |
| 1736 | // If this is the first return lowered for this function, add |
| 1737 | // the regs to the liveout set for the function. |
| 1738 | if (DAG.getMachineFunction().getRegInfo().liveout_empty()) { |
| 1739 | for (unsigned i = 0; i != RVLocs.size(); ++i) |
| 1740 | if (RVLocs[i].isRegLoc()) |
| 1741 | DAG.getMachineFunction().getRegInfo().addLiveOut(RVLocs[i].getLocReg()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1742 | } |
| 1743 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1744 | SDValue Flag; |
| 1745 | |
| 1746 | // Copy the result values into the output registers. |
| 1747 | for (unsigned i = 0, realRVLocIdx = 0; |
| 1748 | i != RVLocs.size(); |
| 1749 | ++i, ++realRVLocIdx) { |
| 1750 | CCValAssign &VA = RVLocs[i]; |
| 1751 | assert(VA.isRegLoc() && "Can only return in registers!"); |
| 1752 | |
Dan Gohman | c940365 | 2010-07-07 15:54:55 +0000 | [diff] [blame] | 1753 | SDValue Arg = OutVals[realRVLocIdx]; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1754 | |
| 1755 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 1756 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1757 | case CCValAssign::Full: break; |
| 1758 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 1759 | Arg = DAG.getNode(ISD::BITCAST, dl, VA.getLocVT(), Arg); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1760 | break; |
| 1761 | } |
| 1762 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1763 | if (VA.needsCustom()) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1764 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1765 | // Extract the first half and return it in two registers. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1766 | SDValue Half = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1767 | DAG.getConstant(0, MVT::i32)); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1768 | SDValue HalfGPRs = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1769 | DAG.getVTList(MVT::i32, MVT::i32), Half); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1770 | |
| 1771 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), HalfGPRs, Flag); |
| 1772 | Flag = Chain.getValue(1); |
| 1773 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1774 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), |
| 1775 | HalfGPRs.getValue(1), Flag); |
| 1776 | Flag = Chain.getValue(1); |
| 1777 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1778 | |
| 1779 | // Extract the 2nd half and fall through to handle it as an f64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1780 | Arg = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, Arg, |
| 1781 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 1782 | } |
| 1783 | // Legalize ret f64 -> ret 2 x i32. We always have fmrrd if f64 is |
| 1784 | // available. |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 1785 | SDValue fmrrd = DAG.getNode(ARMISD::VMOVRRD, dl, |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1786 | DAG.getVTList(MVT::i32, MVT::i32), &Arg, 1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1787 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd, Flag); |
Bob Wilson | 4d59e1d | 2009-04-24 17:00:36 +0000 | [diff] [blame] | 1788 | Flag = Chain.getValue(1); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1789 | VA = RVLocs[++i]; // skip ahead to next loc |
| 1790 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), fmrrd.getValue(1), |
| 1791 | Flag); |
| 1792 | } else |
| 1793 | Chain = DAG.getCopyToReg(Chain, dl, VA.getLocReg(), Arg, Flag); |
| 1794 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 1795 | // Guarantee that all emitted copies are |
| 1796 | // stuck together, avoiding something bad. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1797 | Flag = Chain.getValue(1); |
| 1798 | } |
| 1799 | |
| 1800 | SDValue result; |
| 1801 | if (Flag.getNode()) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1802 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain, Flag); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1803 | else // Return Void |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1804 | result = DAG.getNode(ARMISD::RET_FLAG, dl, MVT::Other, Chain); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 1805 | |
| 1806 | return result; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1807 | } |
| 1808 | |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1809 | bool ARMTargetLowering::isUsedByReturnOnly(SDNode *N) const { |
| 1810 | if (N->getNumValues() != 1) |
| 1811 | return false; |
| 1812 | if (!N->hasNUsesOfValue(1, 0)) |
| 1813 | return false; |
| 1814 | |
| 1815 | unsigned NumCopies = 0; |
| 1816 | SDNode* Copies[2]; |
| 1817 | SDNode *Use = *N->use_begin(); |
| 1818 | if (Use->getOpcode() == ISD::CopyToReg) { |
| 1819 | Copies[NumCopies++] = Use; |
| 1820 | } else if (Use->getOpcode() == ARMISD::VMOVRRD) { |
| 1821 | // f64 returned in a pair of GPRs. |
| 1822 | for (SDNode::use_iterator UI = Use->use_begin(), UE = Use->use_end(); |
| 1823 | UI != UE; ++UI) { |
| 1824 | if (UI->getOpcode() != ISD::CopyToReg) |
| 1825 | return false; |
| 1826 | Copies[UI.getUse().getResNo()] = *UI; |
| 1827 | ++NumCopies; |
| 1828 | } |
| 1829 | } else if (Use->getOpcode() == ISD::BITCAST) { |
| 1830 | // f32 returned in a single GPR. |
| 1831 | if (!Use->hasNUsesOfValue(1, 0)) |
| 1832 | return false; |
| 1833 | Use = *Use->use_begin(); |
| 1834 | if (Use->getOpcode() != ISD::CopyToReg || !Use->hasNUsesOfValue(1, 0)) |
| 1835 | return false; |
| 1836 | Copies[NumCopies++] = Use; |
| 1837 | } else { |
| 1838 | return false; |
| 1839 | } |
| 1840 | |
| 1841 | if (NumCopies != 1 && NumCopies != 2) |
| 1842 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1843 | |
| 1844 | bool HasRet = false; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1845 | for (unsigned i = 0; i < NumCopies; ++i) { |
| 1846 | SDNode *Copy = Copies[i]; |
| 1847 | for (SDNode::use_iterator UI = Copy->use_begin(), UE = Copy->use_end(); |
| 1848 | UI != UE; ++UI) { |
| 1849 | if (UI->getOpcode() == ISD::CopyToReg) { |
| 1850 | SDNode *Use = *UI; |
| 1851 | if (Use == Copies[0] || Use == Copies[1]) |
| 1852 | continue; |
| 1853 | return false; |
| 1854 | } |
| 1855 | if (UI->getOpcode() != ARMISD::RET_FLAG) |
| 1856 | return false; |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1857 | HasRet = true; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1858 | } |
| 1859 | } |
| 1860 | |
Evan Cheng | 1bf891a | 2010-12-01 22:59:46 +0000 | [diff] [blame] | 1861 | return HasRet; |
Evan Cheng | 3d2125c | 2010-11-30 23:55:39 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
Evan Cheng | 485fafc | 2011-03-21 01:19:09 +0000 | [diff] [blame] | 1864 | bool ARMTargetLowering::mayBeEmittedAsTailCall(CallInst *CI) const { |
| 1865 | if (!EnableARMTailCalls) |
| 1866 | return false; |
| 1867 | |
| 1868 | if (!CI->isTailCall()) |
| 1869 | return false; |
| 1870 | |
| 1871 | return !Subtarget->isThumb1Only(); |
| 1872 | } |
| 1873 | |
Bob Wilson | b62d257 | 2009-11-03 00:02:05 +0000 | [diff] [blame] | 1874 | // ConstantPool, JumpTable, GlobalAddress, and ExternalSymbol are lowered as |
| 1875 | // their target counterpart wrapped in the ARMISD::Wrapper node. Suppose N is |
| 1876 | // one of the above mentioned nodes. It has to be wrapped because otherwise |
| 1877 | // Select(N) returns N. So the raw TargetGlobalAddress nodes, etc. can only |
| 1878 | // be used to form addressing mode. These wrapped nodes will be selected |
| 1879 | // into MOVi. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1880 | static SDValue LowerConstantPool(SDValue Op, SelectionDAG &DAG) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1881 | EVT PtrVT = Op.getValueType(); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 1882 | // FIXME there is no actual debug info here |
| 1883 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1884 | ConstantPoolSDNode *CP = cast<ConstantPoolSDNode>(Op); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1885 | SDValue Res; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1886 | if (CP->isMachineConstantPoolEntry()) |
| 1887 | Res = DAG.getTargetConstantPool(CP->getMachineCPVal(), PtrVT, |
| 1888 | CP->getAlignment()); |
| 1889 | else |
| 1890 | Res = DAG.getTargetConstantPool(CP->getConstVal(), PtrVT, |
| 1891 | CP->getAlignment()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1892 | return DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Res); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 1893 | } |
| 1894 | |
Jim Grosbach | e1102ca | 2010-07-19 17:20:38 +0000 | [diff] [blame] | 1895 | unsigned ARMTargetLowering::getJumpTableEncoding() const { |
| 1896 | return MachineJumpTableInfo::EK_Inline; |
| 1897 | } |
| 1898 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1899 | SDValue ARMTargetLowering::LowerBlockAddress(SDValue Op, |
| 1900 | SelectionDAG &DAG) const { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1901 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1902 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 1903 | unsigned ARMPCLabelIndex = 0; |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1904 | DebugLoc DL = Op.getDebugLoc(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1905 | EVT PtrVT = getPointerTy(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1906 | const BlockAddress *BA = cast<BlockAddressSDNode>(Op)->getBlockAddress(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1907 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 1908 | SDValue CPAddr; |
| 1909 | if (RelocM == Reloc::Static) { |
| 1910 | CPAddr = DAG.getTargetConstantPool(BA, PtrVT, 4); |
| 1911 | } else { |
| 1912 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1913 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1914 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(BA, ARMPCLabelIndex, |
| 1915 | ARMCP::CPBlockAddress, |
| 1916 | PCAdj); |
| 1917 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
| 1918 | } |
| 1919 | CPAddr = DAG.getNode(ARMISD::Wrapper, DL, PtrVT, CPAddr); |
| 1920 | SDValue Result = DAG.getLoad(PtrVT, DL, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1921 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1922 | false, false, 0); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1923 | if (RelocM == Reloc::Static) |
| 1924 | return Result; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1925 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Bob Wilson | 907eebd | 2009-11-02 20:59:23 +0000 | [diff] [blame] | 1926 | return DAG.getNode(ARMISD::PIC_ADD, DL, PtrVT, Result, PICLabel); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 1927 | } |
| 1928 | |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1929 | // Lower ISD::GlobalTLSAddress using the "general dynamic" model |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1930 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1931 | ARMTargetLowering::LowerToTLSGeneralDynamicModel(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1932 | SelectionDAG &DAG) const { |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1933 | DebugLoc dl = GA->getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1934 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1935 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1936 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1937 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1938 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1939 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1940 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1941 | ARMCP::CPValue, PCAdj, ARMCP::TLSGD, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1942 | SDValue Argument = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1943 | Argument = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Argument); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1944 | Argument = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Argument, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1945 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1946 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1947 | SDValue Chain = Argument.getValue(1); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1948 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1949 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1950 | Argument = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Argument, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1951 | |
| 1952 | // call __tls_get_addr. |
| 1953 | ArgListTy Args; |
| 1954 | ArgListEntry Entry; |
| 1955 | Entry.Node = Argument; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1956 | Entry.Ty = (Type *) Type::getInt32Ty(*DAG.getContext()); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1957 | Args.push_back(Entry); |
Dale Johannesen | 7d2ad62 | 2009-01-30 23:10:59 +0000 | [diff] [blame] | 1958 | // FIXME: is there useful debug info available here? |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1959 | std::pair<SDValue, SDValue> CallResult = |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 1960 | LowerCallTo(Chain, (Type *) Type::getInt32Ty(*DAG.getContext()), |
Evan Cheng | 59bc060 | 2009-08-14 19:11:20 +0000 | [diff] [blame] | 1961 | false, false, false, false, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 1962 | 0, CallingConv::C, false, /*isReturnValueUsed=*/true, |
Bill Wendling | 46ada19 | 2010-03-02 01:55:18 +0000 | [diff] [blame] | 1963 | DAG.getExternalSymbol("__tls_get_addr", PtrVT), Args, DAG, dl); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1964 | return CallResult.first; |
| 1965 | } |
| 1966 | |
| 1967 | // Lower ISD::GlobalTLSAddress using the "initial exec" or |
| 1968 | // "local exec" model. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1969 | SDValue |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1970 | ARMTargetLowering::LowerToTLSExecModels(GlobalAddressSDNode *GA, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 1971 | SelectionDAG &DAG) const { |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 1972 | const GlobalValue *GV = GA->getGlobal(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1973 | DebugLoc dl = GA->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 1974 | SDValue Offset; |
| 1975 | SDValue Chain = DAG.getEntryNode(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 1976 | EVT PtrVT = getPointerTy(); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1977 | // Get the Thread Pointer |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1978 | SDValue ThreadPointer = DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1979 | |
Chris Lattner | 4fb63d0 | 2009-07-15 04:12:33 +0000 | [diff] [blame] | 1980 | if (GV->isDeclaration()) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1981 | MachineFunction &MF = DAG.getMachineFunction(); |
| 1982 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 1983 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1984 | // Initial exec model. |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1985 | unsigned char PCAdj = Subtarget->isThumb() ? 4 : 8; |
| 1986 | ARMConstantPoolValue *CPV = |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 1987 | new ARMConstantPoolValue(GA->getGlobal(), ARMPCLabelIndex, |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 1988 | ARMCP::CPValue, PCAdj, ARMCP::GOTTPOFF, true); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 1989 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 1990 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1991 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 1992 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 1993 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1994 | Chain = Offset.getValue(1); |
| 1995 | |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 1996 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 1997 | Offset = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Offset, PICLabel); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 1998 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 1999 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2000 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2001 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2002 | } else { |
| 2003 | // local exec model |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 2004 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(GV, ARMCP::TPOFF); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2005 | Offset = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2006 | Offset = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, Offset); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2007 | Offset = DAG.getLoad(PtrVT, dl, Chain, Offset, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2008 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2009 | false, false, 0); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
| 2012 | // The address of the thread local variable is the add of the thread |
| 2013 | // pointer with the offset of the variable. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2014 | return DAG.getNode(ISD::ADD, dl, PtrVT, ThreadPointer, Offset); |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2015 | } |
| 2016 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2017 | SDValue |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2018 | ARMTargetLowering::LowerGlobalTLSAddress(SDValue Op, SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 64f4fa5 | 2007-04-27 13:54:47 +0000 | [diff] [blame] | 2019 | // TODO: implement the "local dynamic" model |
| 2020 | assert(Subtarget->isTargetELF() && |
| 2021 | "TLS not implemented for non-ELF targets"); |
| 2022 | GlobalAddressSDNode *GA = cast<GlobalAddressSDNode>(Op); |
| 2023 | // If the relocation model is PIC, use the "General Dynamic" TLS Model, |
| 2024 | // otherwise use the "Local Exec" TLS Model |
| 2025 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) |
| 2026 | return LowerToTLSGeneralDynamicModel(GA, DAG); |
| 2027 | else |
| 2028 | return LowerToTLSExecModels(GA, DAG); |
| 2029 | } |
| 2030 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2031 | SDValue ARMTargetLowering::LowerGlobalAddressELF(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2032 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2033 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2034 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2035 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2036 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2037 | if (RelocM == Reloc::PIC_) { |
Rafael Espindola | bb46f52 | 2009-01-15 20:18:42 +0000 | [diff] [blame] | 2038 | bool UseGOTOFF = GV->hasLocalLinkage() || GV->hasHiddenVisibility(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2039 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3a2429a | 2010-11-09 21:36:17 +0000 | [diff] [blame] | 2040 | new ARMConstantPoolValue(GV, UseGOTOFF ? ARMCP::GOTOFF : ARMCP::GOT); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2041 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2042 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2043 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2044 | CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2045 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2046 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2047 | SDValue Chain = Result.getValue(1); |
Dale Johannesen | b300d2a | 2009-02-07 00:55:49 +0000 | [diff] [blame] | 2048 | SDValue GOT = DAG.getGLOBAL_OFFSET_TABLE(PtrVT); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2049 | Result = DAG.getNode(ISD::ADD, dl, PtrVT, Result, GOT); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2050 | if (!UseGOTOFF) |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2051 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2052 | MachinePointerInfo::getGOT(), false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2053 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
| 2056 | // If we have T2 ops, we can materialize the address directly via movt/movw |
| 2057 | // pair. This is always cheaper. |
| 2058 | if (Subtarget->useMovt()) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2059 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2060 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2061 | // operands, expand this into two nodes. |
| 2062 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2063 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2064 | } else { |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2065 | SDValue CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
| 2066 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
| 2067 | return DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
| 2068 | MachinePointerInfo::getConstantPool(), |
| 2069 | false, false, 0); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2070 | } |
| 2071 | } |
| 2072 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2073 | SDValue ARMTargetLowering::LowerGlobalAddressDarwin(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2074 | SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2075 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2076 | DebugLoc dl = Op.getDebugLoc(); |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2077 | const GlobalValue *GV = cast<GlobalAddressSDNode>(Op)->getGlobal(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2078 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2079 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2080 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2081 | |
Evan Cheng | 4abce0c | 2011-05-27 20:11:27 +0000 | [diff] [blame] | 2082 | // FIXME: Enable this for static codegen when tool issues are fixed. |
| 2083 | if (Subtarget->useMovt() && RelocM != Reloc::Static) { |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2084 | ++NumMovwMovt; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2085 | // FIXME: Once remat is capable of dealing with instructions with register |
| 2086 | // operands, expand this into two nodes. |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2087 | if (RelocM == Reloc::Static) |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2088 | return DAG.getNode(ARMISD::Wrapper, dl, PtrVT, |
| 2089 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
| 2090 | |
Evan Cheng | 53519f0 | 2011-01-21 18:55:51 +0000 | [diff] [blame] | 2091 | unsigned Wrapper = (RelocM == Reloc::PIC_) |
| 2092 | ? ARMISD::WrapperPIC : ARMISD::WrapperDYN; |
| 2093 | SDValue Result = DAG.getNode(Wrapper, dl, PtrVT, |
Evan Cheng | 9fe2009 | 2011-01-20 08:34:58 +0000 | [diff] [blame] | 2094 | DAG.getTargetGlobalAddress(GV, dl, PtrVT)); |
Evan Cheng | fc8475b | 2011-01-19 02:16:49 +0000 | [diff] [blame] | 2095 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
| 2096 | Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Result, |
| 2097 | MachinePointerInfo::getGOT(), false, false, 0); |
| 2098 | return Result; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
| 2101 | unsigned ARMPCLabelIndex = 0; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2102 | SDValue CPAddr; |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2103 | if (RelocM == Reloc::Static) { |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2104 | CPAddr = DAG.getTargetConstantPool(GV, PtrVT, 4); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2105 | } else { |
| 2106 | ARMPCLabelIndex = AFI->createPICLabelUId(); |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2107 | unsigned PCAdj = (RelocM != Reloc::PIC_) ? 0 : (Subtarget->isThumb()?4:8); |
| 2108 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2109 | new ARMConstantPoolValue(GV, ARMPCLabelIndex, ARMCP::CPValue, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2110 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2111 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2112 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2113 | |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2114 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2115 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2116 | false, false, 0); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2117 | SDValue Chain = Result.getValue(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2118 | |
| 2119 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2120 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2121 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2122 | } |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2123 | |
Evan Cheng | 63476a8 | 2009-09-03 07:04:02 +0000 | [diff] [blame] | 2124 | if (Subtarget->GVIsIndirectSymbol(GV, RelocM)) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2125 | Result = DAG.getLoad(PtrVT, dl, Chain, Result, MachinePointerInfo::getGOT(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2126 | false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2127 | |
| 2128 | return Result; |
| 2129 | } |
| 2130 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2131 | SDValue ARMTargetLowering::LowerGLOBAL_OFFSET_TABLE(SDValue Op, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2132 | SelectionDAG &DAG) const { |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2133 | assert(Subtarget->isTargetELF() && |
| 2134 | "GLOBAL OFFSET TABLE not implemented for non-ELF targets"); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2135 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2136 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2137 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2138 | EVT PtrVT = getPointerTy(); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2139 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2140 | unsigned PCAdj = Subtarget->isThumb() ? 4 : 8; |
Owen Anderson | 1d0be15 | 2009-08-13 21:58:54 +0000 | [diff] [blame] | 2141 | ARMConstantPoolValue *CPV = new ARMConstantPoolValue(*DAG.getContext(), |
| 2142 | "_GLOBAL_OFFSET_TABLE_", |
Evan Cheng | e4e4ed3 | 2009-08-28 23:18:09 +0000 | [diff] [blame] | 2143 | ARMPCLabelIndex, PCAdj); |
Evan Cheng | 1606e8e | 2009-03-13 07:51:59 +0000 | [diff] [blame] | 2144 | SDValue CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2145 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Anton Korobeynikov | 249fb33 | 2009-10-07 00:06:35 +0000 | [diff] [blame] | 2146 | SDValue Result = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2147 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2148 | false, false, 0); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2149 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2150 | return DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2153 | SDValue |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2154 | ARMTargetLowering::LowerEH_SJLJ_DISPATCHSETUP(SDValue Op, SelectionDAG &DAG) |
| 2155 | const { |
| 2156 | DebugLoc dl = Op.getDebugLoc(); |
| 2157 | return DAG.getNode(ARMISD::EH_SJLJ_DISPATCHSETUP, dl, MVT::Other, |
Bill Wendling | 61512ba | 2011-05-11 01:11:55 +0000 | [diff] [blame] | 2158 | Op.getOperand(0), Op.getOperand(1)); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 2159 | } |
| 2160 | |
| 2161 | SDValue |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2162 | ARMTargetLowering::LowerEH_SJLJ_SETJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2163 | DebugLoc dl = Op.getDebugLoc(); |
Jim Grosbach | 0798edd | 2010-05-27 23:49:24 +0000 | [diff] [blame] | 2164 | SDValue Val = DAG.getConstant(0, MVT::i32); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 2165 | return DAG.getNode(ARMISD::EH_SJLJ_SETJMP, dl, MVT::i32, Op.getOperand(0), |
| 2166 | Op.getOperand(1), Val); |
| 2167 | } |
| 2168 | |
| 2169 | SDValue |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 2170 | ARMTargetLowering::LowerEH_SJLJ_LONGJMP(SDValue Op, SelectionDAG &DAG) const { |
| 2171 | DebugLoc dl = Op.getDebugLoc(); |
| 2172 | return DAG.getNode(ARMISD::EH_SJLJ_LONGJMP, dl, MVT::Other, Op.getOperand(0), |
| 2173 | Op.getOperand(1), DAG.getConstant(0, MVT::i32)); |
| 2174 | } |
| 2175 | |
| 2176 | SDValue |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 2177 | ARMTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2178 | const ARMSubtarget *Subtarget) const { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2179 | unsigned IntNo = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 2180 | DebugLoc dl = Op.getDebugLoc(); |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2181 | switch (IntNo) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2182 | default: return SDValue(); // Don't custom lower most intrinsics. |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2183 | case Intrinsic::arm_thread_pointer: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2184 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Bob Wilson | 916afdb | 2009-08-04 00:25:01 +0000 | [diff] [blame] | 2185 | return DAG.getNode(ARMISD::THREAD_POINTER, dl, PtrVT); |
| 2186 | } |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2187 | case Intrinsic::eh_sjlj_lsda: { |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2188 | MachineFunction &MF = DAG.getMachineFunction(); |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2189 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
Evan Cheng | 5de5d4b | 2011-01-17 08:03:18 +0000 | [diff] [blame] | 2190 | unsigned ARMPCLabelIndex = AFI->createPICLabelUId(); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2191 | EVT PtrVT = getPointerTy(); |
| 2192 | DebugLoc dl = Op.getDebugLoc(); |
| 2193 | Reloc::Model RelocM = getTargetMachine().getRelocationModel(); |
| 2194 | SDValue CPAddr; |
| 2195 | unsigned PCAdj = (RelocM != Reloc::PIC_) |
| 2196 | ? 0 : (Subtarget->isThumb() ? 4 : 8); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2197 | ARMConstantPoolValue *CPV = |
Jim Grosbach | 3fb2b1e | 2009-09-01 01:57:56 +0000 | [diff] [blame] | 2198 | new ARMConstantPoolValue(MF.getFunction(), ARMPCLabelIndex, |
| 2199 | ARMCP::CPLSDA, PCAdj); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2200 | CPAddr = DAG.getTargetConstantPool(CPV, PtrVT, 4); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2201 | CPAddr = DAG.getNode(ARMISD::Wrapper, dl, MVT::i32, CPAddr); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2202 | SDValue Result = |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2203 | DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), CPAddr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2204 | MachinePointerInfo::getConstantPool(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2205 | false, false, 0); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2206 | |
| 2207 | if (RelocM == Reloc::PIC_) { |
Evan Cheng | e7e0d62 | 2009-11-06 22:24:13 +0000 | [diff] [blame] | 2208 | SDValue PICLabel = DAG.getConstant(ARMPCLabelIndex, MVT::i32); |
Jim Grosbach | 1b747ad | 2009-08-11 00:09:57 +0000 | [diff] [blame] | 2209 | Result = DAG.getNode(ARMISD::PIC_ADD, dl, PtrVT, Result, PICLabel); |
| 2210 | } |
| 2211 | return Result; |
| 2212 | } |
Evan Cheng | 92e3916 | 2011-03-29 23:06:19 +0000 | [diff] [blame] | 2213 | case Intrinsic::arm_neon_vmulls: |
| 2214 | case Intrinsic::arm_neon_vmullu: { |
| 2215 | unsigned NewOpc = (IntNo == Intrinsic::arm_neon_vmulls) |
| 2216 | ? ARMISD::VMULLs : ARMISD::VMULLu; |
| 2217 | return DAG.getNode(NewOpc, Op.getDebugLoc(), Op.getValueType(), |
| 2218 | Op.getOperand(1), Op.getOperand(2)); |
| 2219 | } |
Lauro Ramos Venancio | e0cb36b | 2007-11-08 17:20:05 +0000 | [diff] [blame] | 2220 | } |
| 2221 | } |
| 2222 | |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 2223 | static SDValue LowerMEMBARRIER(SDValue Op, SelectionDAG &DAG, |
Jim Grosbach | 7616b64 | 2010-06-16 23:45:49 +0000 | [diff] [blame] | 2224 | const ARMSubtarget *Subtarget) { |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2225 | DebugLoc dl = Op.getDebugLoc(); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2226 | if (!Subtarget->hasDataBarrier()) { |
| 2227 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2228 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2229 | // here. |
Bob Wilson | 54f9256 | 2010-11-09 22:50:44 +0000 | [diff] [blame] | 2230 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2231 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2232 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Jim Grosbach | c73993b | 2010-06-17 01:37:00 +0000 | [diff] [blame] | 2233 | DAG.getConstant(0, MVT::i32)); |
Evan Cheng | 11db068 | 2010-08-11 06:22:01 +0000 | [diff] [blame] | 2234 | } |
Bob Wilson | f74a429 | 2010-10-30 00:54:37 +0000 | [diff] [blame] | 2235 | |
| 2236 | SDValue Op5 = Op.getOperand(5); |
| 2237 | bool isDeviceBarrier = cast<ConstantSDNode>(Op5)->getZExtValue() != 0; |
| 2238 | unsigned isLL = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue(); |
| 2239 | unsigned isLS = cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue(); |
| 2240 | bool isOnlyStoreBarrier = (isLL == 0 && isLS == 0); |
| 2241 | |
| 2242 | ARM_MB::MemBOpt DMBOpt; |
| 2243 | if (isDeviceBarrier) |
| 2244 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ST : ARM_MB::SY; |
| 2245 | else |
| 2246 | DMBOpt = isOnlyStoreBarrier ? ARM_MB::ISHST : ARM_MB::ISH; |
| 2247 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
| 2248 | DAG.getConstant(DMBOpt, MVT::i32)); |
Jim Grosbach | 3728e96 | 2009-12-10 00:11:09 +0000 | [diff] [blame] | 2249 | } |
| 2250 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2251 | |
| 2252 | static SDValue LowerATOMIC_FENCE(SDValue Op, SelectionDAG &DAG, |
| 2253 | const ARMSubtarget *Subtarget) { |
| 2254 | // FIXME: handle "fence singlethread" more efficiently. |
| 2255 | DebugLoc dl = Op.getDebugLoc(); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2256 | if (!Subtarget->hasDataBarrier()) { |
| 2257 | // Some ARMv6 cpus can support data barriers with an mcr instruction. |
| 2258 | // Thumb1 and pre-v6 ARM mode use a libcall instead and should never get |
| 2259 | // here. |
| 2260 | assert(Subtarget->hasV6Ops() && !Subtarget->isThumb() && |
| 2261 | "Unexpected ISD::MEMBARRIER encountered. Should be libcall!"); |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2262 | return DAG.getNode(ARMISD::MEMBARRIER_MCR, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2263 | DAG.getConstant(0, MVT::i32)); |
| 2264 | } |
| 2265 | |
Eli Friedman | 26689ac | 2011-08-03 21:06:02 +0000 | [diff] [blame] | 2266 | return DAG.getNode(ARMISD::MEMBARRIER, dl, MVT::Other, Op.getOperand(0), |
Eli Friedman | 989f61e | 2011-08-02 22:44:16 +0000 | [diff] [blame] | 2267 | DAG.getConstant(ARM_MB::ISH, MVT::i32)); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 2268 | } |
| 2269 | |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2270 | static SDValue LowerPREFETCH(SDValue Op, SelectionDAG &DAG, |
| 2271 | const ARMSubtarget *Subtarget) { |
| 2272 | // ARM pre v5TE and Thumb1 does not have preload instructions. |
| 2273 | if (!(Subtarget->isThumb2() || |
| 2274 | (!Subtarget->isThumb1Only() && Subtarget->hasV5TEOps()))) |
| 2275 | // Just preserve the chain. |
| 2276 | return Op.getOperand(0); |
| 2277 | |
| 2278 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2279 | unsigned isRead = ~cast<ConstantSDNode>(Op.getOperand(2))->getZExtValue() & 1; |
| 2280 | if (!isRead && |
| 2281 | (!Subtarget->hasV7Ops() || !Subtarget->hasMPExtension())) |
| 2282 | // ARMv7 with MP extension has PLDW. |
| 2283 | return Op.getOperand(0); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2284 | |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2285 | unsigned isData = cast<ConstantSDNode>(Op.getOperand(4))->getZExtValue(); |
| 2286 | if (Subtarget->isThumb()) { |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2287 | // Invert the bits. |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2288 | isRead = ~isRead & 1; |
Bruno Cardoso Lopes | 9a76733 | 2011-06-14 04:58:37 +0000 | [diff] [blame] | 2289 | isData = ~isData & 1; |
| 2290 | } |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2291 | |
| 2292 | return DAG.getNode(ARMISD::PRELOAD, dl, MVT::Other, Op.getOperand(0), |
Evan Cheng | 416941d | 2010-11-04 05:19:35 +0000 | [diff] [blame] | 2293 | Op.getOperand(1), DAG.getConstant(isRead, MVT::i32), |
| 2294 | DAG.getConstant(isData, MVT::i32)); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2297 | static SDValue LowerVASTART(SDValue Op, SelectionDAG &DAG) { |
| 2298 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2299 | ARMFunctionInfo *FuncInfo = MF.getInfo<ARMFunctionInfo>(); |
| 2300 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2301 | // vastart just stores the address of the VarArgsFrameIndex slot into the |
| 2302 | // memory location argument. |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2303 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2304 | EVT PtrVT = DAG.getTargetLoweringInfo().getPointerTy(); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 2305 | SDValue FR = DAG.getFrameIndex(FuncInfo->getVarArgsFrameIndex(), PtrVT); |
Dan Gohman | 69de193 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 2306 | const Value *SV = cast<SrcValueSDNode>(Op.getOperand(2))->getValue(); |
Chris Lattner | fc448ff | 2010-09-21 18:51:21 +0000 | [diff] [blame] | 2307 | return DAG.getStore(Op.getOperand(0), dl, FR, Op.getOperand(1), |
| 2308 | MachinePointerInfo(SV), false, false, 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2309 | } |
| 2310 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2311 | SDValue |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2312 | ARMTargetLowering::GetF64FormalArgument(CCValAssign &VA, CCValAssign &NextVA, |
| 2313 | SDValue &Root, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2314 | DebugLoc dl) const { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2315 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2316 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2317 | |
| 2318 | TargetRegisterClass *RC; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 2319 | if (AFI->isThumb1OnlyFunction()) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2320 | RC = ARM::tGPRRegisterClass; |
| 2321 | else |
| 2322 | RC = ARM::GPRRegisterClass; |
| 2323 | |
| 2324 | // Transform the arguments stored in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2325 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2326 | SDValue ArgValue = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2327 | |
| 2328 | SDValue ArgValue2; |
| 2329 | if (NextVA.isMemLoc()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2330 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2331 | int FI = MFI->CreateFixedObject(4, NextVA.getLocMemOffset(), true); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2332 | |
| 2333 | // Create load node to retrieve arguments from the stack. |
| 2334 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2335 | ArgValue2 = DAG.getLoad(MVT::i32, dl, Root, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2336 | MachinePointerInfo::getFixedStack(FI), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2337 | false, false, 0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2338 | } else { |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2339 | Reg = MF.addLiveIn(NextVA.getLocReg(), RC); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2340 | ArgValue2 = DAG.getCopyFromReg(Root, dl, Reg, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 2343 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, ArgValue, ArgValue2); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2344 | } |
| 2345 | |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2346 | void |
| 2347 | ARMTargetLowering::computeRegArea(CCState &CCInfo, MachineFunction &MF, |
| 2348 | unsigned &VARegSize, unsigned &VARegSaveSize) |
| 2349 | const { |
| 2350 | unsigned NumGPRs; |
| 2351 | if (CCInfo.isFirstByValRegValid()) |
| 2352 | NumGPRs = ARM::R4 - CCInfo.getFirstByValReg(); |
| 2353 | else { |
| 2354 | unsigned int firstUnalloced; |
| 2355 | firstUnalloced = CCInfo.getFirstUnallocated(GPRArgRegs, |
| 2356 | sizeof(GPRArgRegs) / |
| 2357 | sizeof(GPRArgRegs[0])); |
| 2358 | NumGPRs = (firstUnalloced <= 3) ? (4 - firstUnalloced) : 0; |
| 2359 | } |
| 2360 | |
| 2361 | unsigned Align = MF.getTarget().getFrameLowering()->getStackAlignment(); |
| 2362 | VARegSize = NumGPRs * 4; |
| 2363 | VARegSaveSize = (VARegSize + Align - 1) & ~(Align - 1); |
| 2364 | } |
| 2365 | |
| 2366 | // The remaining GPRs hold either the beginning of variable-argument |
| 2367 | // data, or the beginning of an aggregate passed by value (usuall |
| 2368 | // byval). Either way, we allocate stack slots adjacent to the data |
| 2369 | // provided by our caller, and store the unallocated registers there. |
| 2370 | // If this is a variadic function, the va_list pointer will begin with |
| 2371 | // these values; otherwise, this reassembles a (byval) structure that |
| 2372 | // was split between registers and memory. |
| 2373 | void |
| 2374 | ARMTargetLowering::VarArgStyleRegisters(CCState &CCInfo, SelectionDAG &DAG, |
| 2375 | DebugLoc dl, SDValue &Chain, |
| 2376 | unsigned ArgOffset) const { |
| 2377 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2378 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2379 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2380 | unsigned firstRegToSaveIndex; |
| 2381 | if (CCInfo.isFirstByValRegValid()) |
| 2382 | firstRegToSaveIndex = CCInfo.getFirstByValReg() - ARM::R0; |
| 2383 | else { |
| 2384 | firstRegToSaveIndex = CCInfo.getFirstUnallocated |
| 2385 | (GPRArgRegs, sizeof(GPRArgRegs) / sizeof(GPRArgRegs[0])); |
| 2386 | } |
| 2387 | |
| 2388 | unsigned VARegSize, VARegSaveSize; |
| 2389 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2390 | if (VARegSaveSize) { |
| 2391 | // If this function is vararg, store any remaining integer argument regs |
| 2392 | // to their spots on the stack so that they may be loaded by deferencing |
| 2393 | // the result of va_next. |
| 2394 | AFI->setVarArgsRegSaveSize(VARegSaveSize); |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2395 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(VARegSaveSize, |
| 2396 | ArgOffset + VARegSaveSize |
| 2397 | - VARegSize, |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2398 | false)); |
| 2399 | SDValue FIN = DAG.getFrameIndex(AFI->getVarArgsFrameIndex(), |
| 2400 | getPointerTy()); |
| 2401 | |
| 2402 | SmallVector<SDValue, 4> MemOps; |
| 2403 | for (; firstRegToSaveIndex < 4; ++firstRegToSaveIndex) { |
| 2404 | TargetRegisterClass *RC; |
| 2405 | if (AFI->isThumb1OnlyFunction()) |
| 2406 | RC = ARM::tGPRRegisterClass; |
| 2407 | else |
| 2408 | RC = ARM::GPRRegisterClass; |
| 2409 | |
| 2410 | unsigned VReg = MF.addLiveIn(GPRArgRegs[firstRegToSaveIndex], RC); |
| 2411 | SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, MVT::i32); |
| 2412 | SDValue Store = |
| 2413 | DAG.getStore(Val.getValue(1), dl, Val, FIN, |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2414 | MachinePointerInfo::getFixedStack(AFI->getVarArgsFrameIndex()), |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2415 | false, false, 0); |
| 2416 | MemOps.push_back(Store); |
| 2417 | FIN = DAG.getNode(ISD::ADD, dl, getPointerTy(), FIN, |
| 2418 | DAG.getConstant(4, getPointerTy())); |
| 2419 | } |
| 2420 | if (!MemOps.empty()) |
| 2421 | Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, |
| 2422 | &MemOps[0], MemOps.size()); |
| 2423 | } else |
| 2424 | // This will point to the next argument passed via stack. |
| 2425 | AFI->setVarArgsFrameIndex(MFI->CreateFixedObject(4, ArgOffset, true)); |
| 2426 | } |
| 2427 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2428 | SDValue |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2429 | ARMTargetLowering::LowerFormalArguments(SDValue Chain, |
Sandeep Patel | 65c3c8f | 2009-09-02 08:44:58 +0000 | [diff] [blame] | 2430 | CallingConv::ID CallConv, bool isVarArg, |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2431 | const SmallVectorImpl<ISD::InputArg> |
| 2432 | &Ins, |
| 2433 | DebugLoc dl, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2434 | SmallVectorImpl<SDValue> &InVals) |
| 2435 | const { |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2436 | MachineFunction &MF = DAG.getMachineFunction(); |
| 2437 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 2438 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2439 | ARMFunctionInfo *AFI = MF.getInfo<ARMFunctionInfo>(); |
| 2440 | |
| 2441 | // Assign locations to all of the incoming arguments. |
| 2442 | SmallVector<CCValAssign, 16> ArgLocs; |
Cameron Zwarich | a86686e | 2011-06-10 20:59:24 +0000 | [diff] [blame] | 2443 | ARMCCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), |
| 2444 | getTargetMachine(), ArgLocs, *DAG.getContext(), Prologue); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2445 | CCInfo.AnalyzeFormalArguments(Ins, |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2446 | CCAssignFnForNode(CallConv, /* Return*/ false, |
| 2447 | isVarArg)); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2448 | |
| 2449 | SmallVector<SDValue, 16> ArgValues; |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2450 | int lastInsIndex = -1; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2451 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2452 | SDValue ArgValue; |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2453 | for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) { |
| 2454 | CCValAssign &VA = ArgLocs[i]; |
| 2455 | |
Bob Wilson | dee46d7 | 2009-04-17 20:35:10 +0000 | [diff] [blame] | 2456 | // Arguments stored in registers. |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2457 | if (VA.isRegLoc()) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2458 | EVT RegVT = VA.getLocVT(); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2459 | |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2460 | if (VA.needsCustom()) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2461 | // f64 and vector types are split up into multiple registers or |
| 2462 | // combinations of registers and stack slots. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2463 | if (VA.getLocVT() == MVT::v2f64) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2464 | SDValue ArgValue1 = GetF64FormalArgument(VA, ArgLocs[++i], |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2465 | Chain, DAG, dl); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2466 | VA = ArgLocs[++i]; // skip ahead to next loc |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2467 | SDValue ArgValue2; |
| 2468 | if (VA.isMemLoc()) { |
Evan Cheng | ed2ae13 | 2010-07-03 00:40:23 +0000 | [diff] [blame] | 2469 | int FI = MFI->CreateFixedObject(8, VA.getLocMemOffset(), true); |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2470 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2471 | ArgValue2 = DAG.getLoad(MVT::f64, dl, Chain, FIN, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2472 | MachinePointerInfo::getFixedStack(FI), |
Bob Wilson | 6a234f0 | 2010-04-13 22:03:22 +0000 | [diff] [blame] | 2473 | false, false, 0); |
| 2474 | } else { |
| 2475 | ArgValue2 = GetF64FormalArgument(VA, ArgLocs[++i], |
| 2476 | Chain, DAG, dl); |
| 2477 | } |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2478 | ArgValue = DAG.getNode(ISD::UNDEF, dl, MVT::v2f64); |
| 2479 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2480 | ArgValue, ArgValue1, DAG.getIntPtrConstant(0)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2481 | ArgValue = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2482 | ArgValue, ArgValue2, DAG.getIntPtrConstant(1)); |
| 2483 | } else |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2484 | ArgValue = GetF64FormalArgument(VA, ArgLocs[++i], Chain, DAG, dl); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2485 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2486 | } else { |
| 2487 | TargetRegisterClass *RC; |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2488 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2489 | if (RegVT == MVT::f32) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2490 | RC = ARM::SPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2491 | else if (RegVT == MVT::f64) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2492 | RC = ARM::DPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2493 | else if (RegVT == MVT::v2f64) |
Anton Korobeynikov | 567d14f | 2009-08-05 19:04:42 +0000 | [diff] [blame] | 2494 | RC = ARM::QPRRegisterClass; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2495 | else if (RegVT == MVT::i32) |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2496 | RC = (AFI->isThumb1OnlyFunction() ? |
| 2497 | ARM::tGPRRegisterClass : ARM::GPRRegisterClass); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2498 | else |
Anton Korobeynikov | 058c251 | 2009-08-05 20:15:19 +0000 | [diff] [blame] | 2499 | llvm_unreachable("RegVT not supported by FORMAL_ARGUMENTS Lowering"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 2500 | |
| 2501 | // Transform the arguments in physical registers into virtual ones. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 2502 | unsigned Reg = MF.addLiveIn(VA.getLocReg(), RC); |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2503 | ArgValue = DAG.getCopyFromReg(Chain, dl, Reg, RegVT); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2504 | } |
| 2505 | |
| 2506 | // If this is an 8 or 16-bit value, it is really passed promoted |
| 2507 | // to 32 bits. Insert an assert[sz]ext to capture this, then |
| 2508 | // truncate to the right size. |
| 2509 | switch (VA.getLocInfo()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 2510 | default: llvm_unreachable("Unknown loc info!"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2511 | case CCValAssign::Full: break; |
| 2512 | case CCValAssign::BCvt: |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2513 | ArgValue = DAG.getNode(ISD::BITCAST, dl, VA.getValVT(), ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2514 | break; |
| 2515 | case CCValAssign::SExt: |
| 2516 | ArgValue = DAG.getNode(ISD::AssertSext, dl, RegVT, ArgValue, |
| 2517 | DAG.getValueType(VA.getValVT())); |
| 2518 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2519 | break; |
| 2520 | case CCValAssign::ZExt: |
| 2521 | ArgValue = DAG.getNode(ISD::AssertZext, dl, RegVT, ArgValue, |
| 2522 | DAG.getValueType(VA.getValVT())); |
| 2523 | ArgValue = DAG.getNode(ISD::TRUNCATE, dl, VA.getValVT(), ArgValue); |
| 2524 | break; |
| 2525 | } |
| 2526 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2527 | InVals.push_back(ArgValue); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2528 | |
| 2529 | } else { // VA.isRegLoc() |
| 2530 | |
| 2531 | // sanity check |
| 2532 | assert(VA.isMemLoc()); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2533 | assert(VA.getValVT() != MVT::i64 && "i64 should already be lowered"); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2534 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2535 | int index = ArgLocs[i].getValNo(); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 2536 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2537 | // Some Ins[] entries become multiple ArgLoc[] entries. |
| 2538 | // Process them only once. |
| 2539 | if (index != lastInsIndex) |
| 2540 | { |
| 2541 | ISD::ArgFlagsTy Flags = Ins[index].Flags; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 2542 | // FIXME: For now, all byval parameter objects are marked mutable. |
Eric Christopher | 5ac179c | 2011-04-29 23:12:01 +0000 | [diff] [blame] | 2543 | // This can be changed with more analysis. |
| 2544 | // In case of tail call optimization mark all arguments mutable. |
| 2545 | // Since they could be overwritten by lowering of arguments in case of |
| 2546 | // a tail call. |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2547 | if (Flags.isByVal()) { |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2548 | unsigned VARegSize, VARegSaveSize; |
| 2549 | computeRegArea(CCInfo, MF, VARegSize, VARegSaveSize); |
| 2550 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, 0); |
| 2551 | unsigned Bytes = Flags.getByValSize() - VARegSize; |
Evan Cheng | ee2e0e3 | 2011-03-30 23:44:13 +0000 | [diff] [blame] | 2552 | if (Bytes == 0) Bytes = 1; // Don't create zero-sized stack objects. |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2553 | int FI = MFI->CreateFixedObject(Bytes, |
| 2554 | VA.getLocMemOffset(), false); |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2555 | InVals.push_back(DAG.getFrameIndex(FI, getPointerTy())); |
| 2556 | } else { |
| 2557 | int FI = MFI->CreateFixedObject(VA.getLocVT().getSizeInBits()/8, |
| 2558 | VA.getLocMemOffset(), true); |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2559 | |
Stuart Hastings | f222e59 | 2011-02-28 17:17:53 +0000 | [diff] [blame] | 2560 | // Create load nodes to retrieve arguments from the stack. |
| 2561 | SDValue FIN = DAG.getFrameIndex(FI, getPointerTy()); |
| 2562 | InVals.push_back(DAG.getLoad(VA.getValVT(), dl, Chain, FIN, |
| 2563 | MachinePointerInfo::getFixedStack(FI), |
| 2564 | false, false, 0)); |
| 2565 | } |
| 2566 | lastInsIndex = index; |
| 2567 | } |
Bob Wilson | 1f595bb | 2009-04-17 19:07:39 +0000 | [diff] [blame] | 2568 | } |
| 2569 | } |
| 2570 | |
| 2571 | // varargs |
Stuart Hastings | c731587 | 2011-04-20 16:47:52 +0000 | [diff] [blame] | 2572 | if (isVarArg) |
| 2573 | VarArgStyleRegisters(CCInfo, DAG, dl, Chain, CCInfo.getNextStackOffset()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2574 | |
Dan Gohman | 98ca4f2 | 2009-08-05 01:29:28 +0000 | [diff] [blame] | 2575 | return Chain; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2576 | } |
| 2577 | |
| 2578 | /// isFloatingPointZero - Return true if this is +0.0. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2579 | static bool isFloatingPointZero(SDValue Op) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2580 | if (ConstantFPSDNode *CFP = dyn_cast<ConstantFPSDNode>(Op)) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2581 | return CFP->getValueAPF().isPosZero(); |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2582 | else if (ISD::isEXTLoad(Op.getNode()) || ISD::isNON_EXTLoad(Op.getNode())) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2583 | // Maybe this has already been legalized into the constant pool? |
| 2584 | if (Op.getOperand(1).getOpcode() == ARMISD::Wrapper) { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2585 | SDValue WrapperOp = Op.getOperand(1).getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2586 | if (ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(WrapperOp)) |
Dan Gohman | 46510a7 | 2010-04-15 01:51:59 +0000 | [diff] [blame] | 2587 | if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CP->getConstVal())) |
Dale Johannesen | eaf0894 | 2007-08-31 04:03:46 +0000 | [diff] [blame] | 2588 | return CFP->getValueAPF().isPosZero(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2589 | } |
| 2590 | } |
| 2591 | return false; |
| 2592 | } |
| 2593 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2594 | /// Returns appropriate ARM CMP (cmp) and corresponding condition code for |
| 2595 | /// the given operands. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2596 | SDValue |
| 2597 | ARMTargetLowering::getARMCmp(SDValue LHS, SDValue RHS, ISD::CondCode CC, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2598 | SDValue &ARMcc, SelectionDAG &DAG, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2599 | DebugLoc dl) const { |
Gabor Greif | ba36cb5 | 2008-08-28 21:40:38 +0000 | [diff] [blame] | 2600 | if (ConstantSDNode *RHSC = dyn_cast<ConstantSDNode>(RHS.getNode())) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 2601 | unsigned C = RHSC->getZExtValue(); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 2602 | if (!isLegalICmpImmediate(C)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2603 | // Constant does not fit, try adjusting it by one? |
| 2604 | switch (CC) { |
| 2605 | default: break; |
| 2606 | case ISD::SETLT: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2607 | case ISD::SETGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2608 | if (C != 0x80000000 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2609 | CC = (CC == ISD::SETLT) ? ISD::SETLE : ISD::SETGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2610 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2611 | } |
| 2612 | break; |
| 2613 | case ISD::SETULT: |
| 2614 | case ISD::SETUGE: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2615 | if (C != 0 && isLegalICmpImmediate(C-1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2616 | CC = (CC == ISD::SETULT) ? ISD::SETULE : ISD::SETUGT; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2617 | RHS = DAG.getConstant(C-1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2618 | } |
| 2619 | break; |
| 2620 | case ISD::SETLE: |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2621 | case ISD::SETGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2622 | if (C != 0x7fffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2623 | CC = (CC == ISD::SETLE) ? ISD::SETLT : ISD::SETGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2624 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2625 | } |
| 2626 | break; |
| 2627 | case ISD::SETULE: |
| 2628 | case ISD::SETUGT: |
Daniel Dunbar | 3cc3283 | 2010-08-25 16:58:05 +0000 | [diff] [blame] | 2629 | if (C != 0xffffffff && isLegalICmpImmediate(C+1)) { |
Evan Cheng | 9a2ef95 | 2007-02-02 01:53:26 +0000 | [diff] [blame] | 2630 | CC = (CC == ISD::SETULE) ? ISD::SETULT : ISD::SETUGE; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2631 | RHS = DAG.getConstant(C+1, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2632 | } |
| 2633 | break; |
| 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2639 | ARMISD::NodeType CompareType; |
| 2640 | switch (CondCode) { |
| 2641 | default: |
| 2642 | CompareType = ARMISD::CMP; |
| 2643 | break; |
| 2644 | case ARMCC::EQ: |
| 2645 | case ARMCC::NE: |
David Goodwin | c0309b4 | 2009-06-29 15:33:01 +0000 | [diff] [blame] | 2646 | // Uses only Z Flag |
| 2647 | CompareType = ARMISD::CMPZ; |
Lauro Ramos Venancio | 9996663 | 2007-04-02 01:30:03 +0000 | [diff] [blame] | 2648 | break; |
| 2649 | } |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2650 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2651 | return DAG.getNode(CompareType, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | /// Returns a appropriate VFP CMP (fcmp{s|d}+fmstat) for the given operands. |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2655 | SDValue |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2656 | ARMTargetLowering::getVFPCmp(SDValue LHS, SDValue RHS, SelectionDAG &DAG, |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 2657 | DebugLoc dl) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2658 | SDValue Cmp; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2659 | if (!isFloatingPointZero(RHS)) |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2660 | Cmp = DAG.getNode(ARMISD::CMPFP, dl, MVT::Glue, LHS, RHS); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2661 | else |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2662 | Cmp = DAG.getNode(ARMISD::CMPFPw0, dl, MVT::Glue, LHS); |
| 2663 | return DAG.getNode(ARMISD::FMSTAT, dl, MVT::Glue, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2664 | } |
| 2665 | |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2666 | /// duplicateCmp - Glue values can have only one use, so this function |
| 2667 | /// duplicates a comparison node. |
| 2668 | SDValue |
| 2669 | ARMTargetLowering::duplicateCmp(SDValue Cmp, SelectionDAG &DAG) const { |
| 2670 | unsigned Opc = Cmp.getOpcode(); |
| 2671 | DebugLoc DL = Cmp.getDebugLoc(); |
| 2672 | if (Opc == ARMISD::CMP || Opc == ARMISD::CMPZ) |
| 2673 | return DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2674 | |
| 2675 | assert(Opc == ARMISD::FMSTAT && "unexpected comparison operation"); |
| 2676 | Cmp = Cmp.getOperand(0); |
| 2677 | Opc = Cmp.getOpcode(); |
| 2678 | if (Opc == ARMISD::CMPFP) |
| 2679 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0),Cmp.getOperand(1)); |
| 2680 | else { |
| 2681 | assert(Opc == ARMISD::CMPFPw0 && "unexpected operand of FMSTAT"); |
| 2682 | Cmp = DAG.getNode(Opc, DL, MVT::Glue, Cmp.getOperand(0)); |
| 2683 | } |
| 2684 | return DAG.getNode(ARMISD::FMSTAT, DL, MVT::Glue, Cmp); |
| 2685 | } |
| 2686 | |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2687 | SDValue ARMTargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const { |
| 2688 | SDValue Cond = Op.getOperand(0); |
| 2689 | SDValue SelectTrue = Op.getOperand(1); |
| 2690 | SDValue SelectFalse = Op.getOperand(2); |
| 2691 | DebugLoc dl = Op.getDebugLoc(); |
| 2692 | |
| 2693 | // Convert: |
| 2694 | // |
| 2695 | // (select (cmov 1, 0, cond), t, f) -> (cmov t, f, cond) |
| 2696 | // (select (cmov 0, 1, cond), t, f) -> (cmov f, t, cond) |
| 2697 | // |
| 2698 | if (Cond.getOpcode() == ARMISD::CMOV && Cond.hasOneUse()) { |
| 2699 | const ConstantSDNode *CMOVTrue = |
| 2700 | dyn_cast<ConstantSDNode>(Cond.getOperand(0)); |
| 2701 | const ConstantSDNode *CMOVFalse = |
| 2702 | dyn_cast<ConstantSDNode>(Cond.getOperand(1)); |
| 2703 | |
| 2704 | if (CMOVTrue && CMOVFalse) { |
| 2705 | unsigned CMOVTrueVal = CMOVTrue->getZExtValue(); |
| 2706 | unsigned CMOVFalseVal = CMOVFalse->getZExtValue(); |
| 2707 | |
| 2708 | SDValue True; |
| 2709 | SDValue False; |
| 2710 | if (CMOVTrueVal == 1 && CMOVFalseVal == 0) { |
| 2711 | True = SelectTrue; |
| 2712 | False = SelectFalse; |
| 2713 | } else if (CMOVTrueVal == 0 && CMOVFalseVal == 1) { |
| 2714 | True = SelectFalse; |
| 2715 | False = SelectTrue; |
| 2716 | } |
| 2717 | |
| 2718 | if (True.getNode() && False.getNode()) { |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2719 | EVT VT = Op.getValueType(); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2720 | SDValue ARMcc = Cond.getOperand(2); |
| 2721 | SDValue CCR = Cond.getOperand(3); |
Bob Wilson | 79f56c9 | 2011-03-08 01:17:20 +0000 | [diff] [blame] | 2722 | SDValue Cmp = duplicateCmp(Cond.getOperand(4), DAG); |
Evan Cheng | b936e30 | 2011-05-18 18:59:17 +0000 | [diff] [blame] | 2723 | assert(True.getValueType() == VT); |
| 2724 | return DAG.getNode(ARMISD::CMOV, dl, VT, True, False, ARMcc, CCR, Cmp); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | } |
| 2728 | |
| 2729 | return DAG.getSelectCC(dl, Cond, |
| 2730 | DAG.getConstant(0, Cond.getValueType()), |
| 2731 | SelectTrue, SelectFalse, ISD::SETNE); |
| 2732 | } |
| 2733 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2734 | SDValue ARMTargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2735 | EVT VT = Op.getValueType(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2736 | SDValue LHS = Op.getOperand(0); |
| 2737 | SDValue RHS = Op.getOperand(1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2738 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(4))->get(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2739 | SDValue TrueVal = Op.getOperand(2); |
| 2740 | SDValue FalseVal = Op.getOperand(3); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2741 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2742 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2743 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2744 | SDValue ARMcc; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2745 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2746 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 2747 | return DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2751 | FPCCToARMCC(CC, CondCode, CondCode2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2752 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2753 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2754 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2755 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2756 | SDValue Result = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2757 | ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2758 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2759 | SDValue ARMcc2 = DAG.getConstant(CondCode2, MVT::i32); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2760 | // FIXME: Needs another CMP because flag can have but one use. |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2761 | SDValue Cmp2 = getVFPCmp(LHS, RHS, DAG, dl); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2762 | Result = DAG.getNode(ARMISD::CMOV, dl, VT, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2763 | Result, TrueVal, ARMcc2, CCR, Cmp2); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2764 | } |
| 2765 | return Result; |
| 2766 | } |
| 2767 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2768 | /// canChangeToInt - Given the fp compare operand, return true if it is suitable |
| 2769 | /// to morph to an integer compare sequence. |
| 2770 | static bool canChangeToInt(SDValue Op, bool &SeenZero, |
| 2771 | const ARMSubtarget *Subtarget) { |
| 2772 | SDNode *N = Op.getNode(); |
| 2773 | if (!N->hasOneUse()) |
| 2774 | // Otherwise it requires moving the value from fp to integer registers. |
| 2775 | return false; |
| 2776 | if (!N->getNumValues()) |
| 2777 | return false; |
| 2778 | EVT VT = Op.getValueType(); |
| 2779 | if (VT != MVT::f32 && !Subtarget->isFPBrccSlow()) |
| 2780 | // f32 case is generally profitable. f64 case only makes sense when vcmpe + |
| 2781 | // vmrs are very slow, e.g. cortex-a8. |
| 2782 | return false; |
| 2783 | |
| 2784 | if (isFloatingPointZero(Op)) { |
| 2785 | SeenZero = true; |
| 2786 | return true; |
| 2787 | } |
| 2788 | return ISD::isNormalLoad(N); |
| 2789 | } |
| 2790 | |
| 2791 | static SDValue bitcastf32Toi32(SDValue Op, SelectionDAG &DAG) { |
| 2792 | if (isFloatingPointZero(Op)) |
| 2793 | return DAG.getConstant(0, MVT::i32); |
| 2794 | |
| 2795 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) |
| 2796 | return DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2797 | Ld->getChain(), Ld->getBasePtr(), Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2798 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2799 | Ld->getAlignment()); |
| 2800 | |
| 2801 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2802 | } |
| 2803 | |
| 2804 | static void expandf64Toi32(SDValue Op, SelectionDAG &DAG, |
| 2805 | SDValue &RetVal1, SDValue &RetVal2) { |
| 2806 | if (isFloatingPointZero(Op)) { |
| 2807 | RetVal1 = DAG.getConstant(0, MVT::i32); |
| 2808 | RetVal2 = DAG.getConstant(0, MVT::i32); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
| 2812 | if (LoadSDNode *Ld = dyn_cast<LoadSDNode>(Op)) { |
| 2813 | SDValue Ptr = Ld->getBasePtr(); |
| 2814 | RetVal1 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2815 | Ld->getChain(), Ptr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2816 | Ld->getPointerInfo(), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2817 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2818 | Ld->getAlignment()); |
| 2819 | |
| 2820 | EVT PtrType = Ptr.getValueType(); |
| 2821 | unsigned NewAlign = MinAlign(Ld->getAlignment(), 4); |
| 2822 | SDValue NewPtr = DAG.getNode(ISD::ADD, Op.getDebugLoc(), |
| 2823 | PtrType, Ptr, DAG.getConstant(4, PtrType)); |
| 2824 | RetVal2 = DAG.getLoad(MVT::i32, Op.getDebugLoc(), |
| 2825 | Ld->getChain(), NewPtr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2826 | Ld->getPointerInfo().getWithOffset(4), |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2827 | Ld->isVolatile(), Ld->isNonTemporal(), |
| 2828 | NewAlign); |
| 2829 | return; |
| 2830 | } |
| 2831 | |
| 2832 | llvm_unreachable("Unknown VFP cmp argument!"); |
| 2833 | } |
| 2834 | |
| 2835 | /// OptimizeVFPBrcond - With -enable-unsafe-fp-math, it's legal to optimize some |
| 2836 | /// f32 and even f64 comparisons to integer ones. |
| 2837 | SDValue |
| 2838 | ARMTargetLowering::OptimizeVFPBrcond(SDValue Op, SelectionDAG &DAG) const { |
| 2839 | SDValue Chain = Op.getOperand(0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2840 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2841 | SDValue LHS = Op.getOperand(2); |
| 2842 | SDValue RHS = Op.getOperand(3); |
| 2843 | SDValue Dest = Op.getOperand(4); |
| 2844 | DebugLoc dl = Op.getDebugLoc(); |
| 2845 | |
| 2846 | bool SeenZero = false; |
| 2847 | if (canChangeToInt(LHS, SeenZero, Subtarget) && |
| 2848 | canChangeToInt(RHS, SeenZero, Subtarget) && |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 2849 | // If one of the operand is zero, it's safe to ignore the NaN case since |
| 2850 | // we only care about equality comparisons. |
| 2851 | (SeenZero || (DAG.isKnownNeverNaN(LHS) && DAG.isKnownNeverNaN(RHS)))) { |
Bob Wilson | 1b772f9 | 2011-03-08 01:17:16 +0000 | [diff] [blame] | 2852 | // If unsafe fp math optimization is enabled and there are no other uses of |
| 2853 | // the CMP operands, and the condition code is EQ or NE, we can optimize it |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2854 | // to an integer comparison. |
| 2855 | if (CC == ISD::SETOEQ) |
| 2856 | CC = ISD::SETEQ; |
| 2857 | else if (CC == ISD::SETUNE) |
| 2858 | CC = ISD::SETNE; |
| 2859 | |
| 2860 | SDValue ARMcc; |
| 2861 | if (LHS.getValueType() == MVT::f32) { |
| 2862 | LHS = bitcastf32Toi32(LHS, DAG); |
| 2863 | RHS = bitcastf32Toi32(RHS, DAG); |
| 2864 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
| 2865 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 2866 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
| 2867 | Chain, Dest, ARMcc, CCR, Cmp); |
| 2868 | } |
| 2869 | |
| 2870 | SDValue LHS1, LHS2; |
| 2871 | SDValue RHS1, RHS2; |
| 2872 | expandf64Toi32(LHS, DAG, LHS1, LHS2); |
| 2873 | expandf64Toi32(RHS, DAG, RHS1, RHS2); |
| 2874 | ARMCC::CondCodes CondCode = IntCCToARMCC(CC); |
| 2875 | ARMcc = DAG.getConstant(CondCode, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2876 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2877 | SDValue Ops[] = { Chain, ARMcc, LHS1, LHS2, RHS1, RHS2, Dest }; |
| 2878 | return DAG.getNode(ARMISD::BCC_i64, dl, VTList, Ops, 7); |
| 2879 | } |
| 2880 | |
| 2881 | return SDValue(); |
| 2882 | } |
| 2883 | |
| 2884 | SDValue ARMTargetLowering::LowerBR_CC(SDValue Op, SelectionDAG &DAG) const { |
| 2885 | SDValue Chain = Op.getOperand(0); |
| 2886 | ISD::CondCode CC = cast<CondCodeSDNode>(Op.getOperand(1))->get(); |
| 2887 | SDValue LHS = Op.getOperand(2); |
| 2888 | SDValue RHS = Op.getOperand(3); |
| 2889 | SDValue Dest = Op.getOperand(4); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2890 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2891 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2892 | if (LHS.getValueType() == MVT::i32) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2893 | SDValue ARMcc; |
| 2894 | SDValue Cmp = getARMCmp(LHS, RHS, CC, ARMcc, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2895 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2896 | return DAG.getNode(ARMISD::BRCOND, dl, MVT::Other, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2897 | Chain, Dest, ARMcc, CCR, Cmp); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2898 | } |
| 2899 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2900 | assert(LHS.getValueType() == MVT::f32 || LHS.getValueType() == MVT::f64); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2901 | |
| 2902 | if (UnsafeFPMath && |
| 2903 | (CC == ISD::SETEQ || CC == ISD::SETOEQ || |
| 2904 | CC == ISD::SETNE || CC == ISD::SETUNE)) { |
| 2905 | SDValue Result = OptimizeVFPBrcond(Op, DAG); |
| 2906 | if (Result.getNode()) |
| 2907 | return Result; |
| 2908 | } |
| 2909 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2910 | ARMCC::CondCodes CondCode, CondCode2; |
Bob Wilson | cd3b9a4 | 2009-09-09 23:14:54 +0000 | [diff] [blame] | 2911 | FPCCToARMCC(CC, CondCode, CondCode2); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 2912 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2913 | SDValue ARMcc = DAG.getConstant(CondCode, MVT::i32); |
| 2914 | SDValue Cmp = getVFPCmp(LHS, RHS, DAG, dl); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2915 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 2916 | SDVTList VTList = DAG.getVTList(MVT::Other, MVT::Glue); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2917 | SDValue Ops[] = { Chain, Dest, ARMcc, CCR, Cmp }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2918 | SDValue Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2919 | if (CondCode2 != ARMCC::AL) { |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 2920 | ARMcc = DAG.getConstant(CondCode2, MVT::i32); |
| 2921 | SDValue Ops[] = { Res, Dest, ARMcc, CCR, Res.getValue(1) }; |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 2922 | Res = DAG.getNode(ARMISD::BRCOND, dl, VTList, Ops, 5); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2923 | } |
| 2924 | return Res; |
| 2925 | } |
| 2926 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 2927 | SDValue ARMTargetLowering::LowerBR_JT(SDValue Op, SelectionDAG &DAG) const { |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2928 | SDValue Chain = Op.getOperand(0); |
| 2929 | SDValue Table = Op.getOperand(1); |
| 2930 | SDValue Index = Op.getOperand(2); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2931 | DebugLoc dl = Op.getDebugLoc(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2932 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 2933 | EVT PTy = getPointerTy(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2934 | JumpTableSDNode *JT = cast<JumpTableSDNode>(Table); |
| 2935 | ARMFunctionInfo *AFI = DAG.getMachineFunction().getInfo<ARMFunctionInfo>(); |
Bob Wilson | 3eadf00 | 2009-07-14 18:44:34 +0000 | [diff] [blame] | 2936 | SDValue UId = DAG.getConstant(AFI->createJumpTableUId(), PTy); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 2937 | SDValue JTI = DAG.getTargetJumpTable(JT->getIndex(), PTy); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2938 | Table = DAG.getNode(ARMISD::WrapperJT, dl, MVT::i32, JTI, UId); |
Evan Cheng | e7c329b | 2009-07-28 20:53:24 +0000 | [diff] [blame] | 2939 | Index = DAG.getNode(ISD::MUL, dl, PTy, Index, DAG.getConstant(4, PTy)); |
| 2940 | SDValue Addr = DAG.getNode(ISD::ADD, dl, PTy, Index, Table); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2941 | if (Subtarget->isThumb2()) { |
| 2942 | // Thumb2 uses a two-level jump. That is, it jumps into the jump table |
| 2943 | // which does another jump to the destination. This also makes it easier |
| 2944 | // to translate it to TBB / TBH later. |
| 2945 | // FIXME: This might not work if the function is extremely large. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2946 | return DAG.getNode(ARMISD::BR2_JT, dl, MVT::Other, Chain, |
Evan Cheng | 5657c01 | 2009-07-29 02:18:14 +0000 | [diff] [blame] | 2947 | Addr, Op.getOperand(2), JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2948 | } |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2949 | if (getTargetMachine().getRelocationModel() == Reloc::PIC_) { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2950 | Addr = DAG.getLoad((EVT)MVT::i32, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2951 | MachinePointerInfo::getJumpTable(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 2952 | false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2953 | Chain = Addr.getValue(1); |
Dale Johannesen | 33c960f | 2009-02-04 20:06:27 +0000 | [diff] [blame] | 2954 | Addr = DAG.getNode(ISD::ADD, dl, PTy, Addr, Table); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2955 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2956 | } else { |
Evan Cheng | 9eda689 | 2009-10-31 03:39:36 +0000 | [diff] [blame] | 2957 | Addr = DAG.getLoad(PTy, dl, Chain, Addr, |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 2958 | MachinePointerInfo::getJumpTable(), false, false, 0); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2959 | Chain = Addr.getValue(1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 2960 | return DAG.getNode(ARMISD::BR_JT, dl, MVT::Other, Chain, Addr, JTI, UId); |
Evan Cheng | 66ac531 | 2009-07-25 00:33:29 +0000 | [diff] [blame] | 2961 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2964 | static SDValue LowerFP_TO_INT(SDValue Op, SelectionDAG &DAG) { |
| 2965 | DebugLoc dl = Op.getDebugLoc(); |
| 2966 | unsigned Opc; |
| 2967 | |
| 2968 | switch (Op.getOpcode()) { |
| 2969 | default: |
| 2970 | assert(0 && "Invalid opcode!"); |
| 2971 | case ISD::FP_TO_SINT: |
| 2972 | Opc = ARMISD::FTOSI; |
| 2973 | break; |
| 2974 | case ISD::FP_TO_UINT: |
| 2975 | Opc = ARMISD::FTOUI; |
| 2976 | break; |
| 2977 | } |
| 2978 | Op = DAG.getNode(Opc, dl, MVT::f32, Op.getOperand(0)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 2979 | return DAG.getNode(ISD::BITCAST, dl, MVT::i32, Op); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2982 | static SDValue LowerVectorINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 2983 | EVT VT = Op.getValueType(); |
| 2984 | DebugLoc dl = Op.getDebugLoc(); |
| 2985 | |
Duncan Sands | 1f6a329 | 2011-08-12 14:54:45 +0000 | [diff] [blame^] | 2986 | assert(Op.getOperand(0).getValueType() == MVT::v4i16 && |
| 2987 | "Invalid type for custom lowering!"); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 2988 | if (VT != MVT::v4f32) |
| 2989 | return DAG.UnrollVectorOp(Op.getNode()); |
| 2990 | |
| 2991 | unsigned CastOpc; |
| 2992 | unsigned Opc; |
| 2993 | switch (Op.getOpcode()) { |
| 2994 | default: |
| 2995 | assert(0 && "Invalid opcode!"); |
| 2996 | case ISD::SINT_TO_FP: |
| 2997 | CastOpc = ISD::SIGN_EXTEND; |
| 2998 | Opc = ISD::SINT_TO_FP; |
| 2999 | break; |
| 3000 | case ISD::UINT_TO_FP: |
| 3001 | CastOpc = ISD::ZERO_EXTEND; |
| 3002 | Opc = ISD::UINT_TO_FP; |
| 3003 | break; |
| 3004 | } |
| 3005 | |
| 3006 | Op = DAG.getNode(CastOpc, dl, MVT::v4i32, Op.getOperand(0)); |
| 3007 | return DAG.getNode(Opc, dl, VT, Op); |
| 3008 | } |
| 3009 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3010 | static SDValue LowerINT_TO_FP(SDValue Op, SelectionDAG &DAG) { |
| 3011 | EVT VT = Op.getValueType(); |
Cameron Zwarich | 3007d33 | 2011-03-29 21:41:55 +0000 | [diff] [blame] | 3012 | if (VT.isVector()) |
| 3013 | return LowerVectorINT_TO_FP(Op, DAG); |
| 3014 | |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3015 | DebugLoc dl = Op.getDebugLoc(); |
| 3016 | unsigned Opc; |
| 3017 | |
| 3018 | switch (Op.getOpcode()) { |
| 3019 | default: |
| 3020 | assert(0 && "Invalid opcode!"); |
| 3021 | case ISD::SINT_TO_FP: |
| 3022 | Opc = ARMISD::SITOF; |
| 3023 | break; |
| 3024 | case ISD::UINT_TO_FP: |
| 3025 | Opc = ARMISD::UITOF; |
| 3026 | break; |
| 3027 | } |
| 3028 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3029 | Op = DAG.getNode(ISD::BITCAST, dl, MVT::f32, Op.getOperand(0)); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 3030 | return DAG.getNode(Opc, dl, VT, Op); |
| 3031 | } |
| 3032 | |
Evan Cheng | 515fe3a | 2010-07-08 02:08:50 +0000 | [diff] [blame] | 3033 | SDValue ARMTargetLowering::LowerFCOPYSIGN(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3034 | // Implement fcopysign with a fabs and a conditional fneg. |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3035 | SDValue Tmp0 = Op.getOperand(0); |
| 3036 | SDValue Tmp1 = Op.getOperand(1); |
Dale Johannesen | de06470 | 2009-02-06 21:50:26 +0000 | [diff] [blame] | 3037 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3038 | EVT VT = Op.getValueType(); |
| 3039 | EVT SrcVT = Tmp1.getValueType(); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3040 | bool InGPR = Tmp0.getOpcode() == ISD::BITCAST || |
| 3041 | Tmp0.getOpcode() == ARMISD::VMOVDRR; |
| 3042 | bool UseNEON = !InGPR && Subtarget->hasNEON(); |
| 3043 | |
| 3044 | if (UseNEON) { |
| 3045 | // Use VBSL to copy the sign bit. |
| 3046 | unsigned EncodedVal = ARM_AM::createNEONModImm(0x6, 0x80); |
| 3047 | SDValue Mask = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v2i32, |
| 3048 | DAG.getTargetConstant(EncodedVal, MVT::i32)); |
| 3049 | EVT OpVT = (VT == MVT::f32) ? MVT::v2i32 : MVT::v1i64; |
| 3050 | if (VT == MVT::f64) |
| 3051 | Mask = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3052 | DAG.getNode(ISD::BITCAST, dl, OpVT, Mask), |
| 3053 | DAG.getConstant(32, MVT::i32)); |
| 3054 | else /*if (VT == MVT::f32)*/ |
| 3055 | Tmp0 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp0); |
| 3056 | if (SrcVT == MVT::f32) { |
| 3057 | Tmp1 = DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, MVT::v2f32, Tmp1); |
| 3058 | if (VT == MVT::f64) |
| 3059 | Tmp1 = DAG.getNode(ARMISD::VSHL, dl, OpVT, |
| 3060 | DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1), |
| 3061 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | 9eec66e | 2011-04-15 01:31:00 +0000 | [diff] [blame] | 3062 | } else if (VT == MVT::f32) |
| 3063 | Tmp1 = DAG.getNode(ARMISD::VSHRu, dl, MVT::v1i64, |
| 3064 | DAG.getNode(ISD::BITCAST, dl, MVT::v1i64, Tmp1), |
| 3065 | DAG.getConstant(32, MVT::i32)); |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3066 | Tmp0 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp0); |
| 3067 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, OpVT, Tmp1); |
| 3068 | |
| 3069 | SDValue AllOnes = DAG.getTargetConstant(ARM_AM::createNEONModImm(0xe, 0xff), |
| 3070 | MVT::i32); |
| 3071 | AllOnes = DAG.getNode(ARMISD::VMOVIMM, dl, MVT::v8i8, AllOnes); |
| 3072 | SDValue MaskNot = DAG.getNode(ISD::XOR, dl, OpVT, Mask, |
| 3073 | DAG.getNode(ISD::BITCAST, dl, OpVT, AllOnes)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 3074 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3075 | SDValue Res = DAG.getNode(ISD::OR, dl, OpVT, |
| 3076 | DAG.getNode(ISD::AND, dl, OpVT, Tmp1, Mask), |
| 3077 | DAG.getNode(ISD::AND, dl, OpVT, Tmp0, MaskNot)); |
Evan Cheng | c24ab5c | 2011-02-28 18:45:27 +0000 | [diff] [blame] | 3078 | if (VT == MVT::f32) { |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3079 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::v2f32, Res); |
| 3080 | Res = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f32, Res, |
| 3081 | DAG.getConstant(0, MVT::i32)); |
| 3082 | } else { |
| 3083 | Res = DAG.getNode(ISD::BITCAST, dl, MVT::f64, Res); |
| 3084 | } |
| 3085 | |
| 3086 | return Res; |
| 3087 | } |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3088 | |
| 3089 | // Bitcast operand 1 to i32. |
| 3090 | if (SrcVT == MVT::f64) |
| 3091 | Tmp1 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3092 | &Tmp1, 1).getValue(1); |
| 3093 | Tmp1 = DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp1); |
| 3094 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3095 | // Or in the signbit with integer operations. |
| 3096 | SDValue Mask1 = DAG.getConstant(0x80000000, MVT::i32); |
| 3097 | SDValue Mask2 = DAG.getConstant(0x7fffffff, MVT::i32); |
| 3098 | Tmp1 = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp1, Mask1); |
| 3099 | if (VT == MVT::f32) { |
| 3100 | Tmp0 = DAG.getNode(ISD::AND, dl, MVT::i32, |
| 3101 | DAG.getNode(ISD::BITCAST, dl, MVT::i32, Tmp0), Mask2); |
| 3102 | return DAG.getNode(ISD::BITCAST, dl, MVT::f32, |
| 3103 | DAG.getNode(ISD::OR, dl, MVT::i32, Tmp0, Tmp1)); |
Evan Cheng | c143dd4 | 2011-02-11 02:28:55 +0000 | [diff] [blame] | 3104 | } |
| 3105 | |
Evan Cheng | e573fb3 | 2011-02-23 02:24:55 +0000 | [diff] [blame] | 3106 | // f64: Or the high part with signbit and then combine two parts. |
| 3107 | Tmp0 = DAG.getNode(ARMISD::VMOVRRD, dl, DAG.getVTList(MVT::i32, MVT::i32), |
| 3108 | &Tmp0, 1); |
| 3109 | SDValue Lo = Tmp0.getValue(0); |
| 3110 | SDValue Hi = DAG.getNode(ISD::AND, dl, MVT::i32, Tmp0.getValue(1), Mask2); |
| 3111 | Hi = DAG.getNode(ISD::OR, dl, MVT::i32, Hi, Tmp1); |
| 3112 | return DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 3113 | } |
| 3114 | |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3115 | SDValue ARMTargetLowering::LowerRETURNADDR(SDValue Op, SelectionDAG &DAG) const{ |
| 3116 | MachineFunction &MF = DAG.getMachineFunction(); |
| 3117 | MachineFrameInfo *MFI = MF.getFrameInfo(); |
| 3118 | MFI->setReturnAddressIsTaken(true); |
| 3119 | |
| 3120 | EVT VT = Op.getValueType(); |
| 3121 | DebugLoc dl = Op.getDebugLoc(); |
| 3122 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 3123 | if (Depth) { |
| 3124 | SDValue FrameAddr = LowerFRAMEADDR(Op, DAG); |
| 3125 | SDValue Offset = DAG.getConstant(4, MVT::i32); |
| 3126 | return DAG.getLoad(VT, dl, DAG.getEntryNode(), |
| 3127 | DAG.getNode(ISD::ADD, dl, VT, FrameAddr, Offset), |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3128 | MachinePointerInfo(), false, false, 0); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3129 | } |
| 3130 | |
| 3131 | // Return LR, which contains the return address. Mark it an implicit live-in. |
Devang Patel | 68e6bee | 2011-02-21 23:21:26 +0000 | [diff] [blame] | 3132 | unsigned Reg = MF.addLiveIn(ARM::LR, getRegClassFor(MVT::i32)); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3133 | return DAG.getCopyFromReg(DAG.getEntryNode(), dl, Reg, VT); |
| 3134 | } |
| 3135 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3136 | SDValue ARMTargetLowering::LowerFRAMEADDR(SDValue Op, SelectionDAG &DAG) const { |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3137 | MachineFrameInfo *MFI = DAG.getMachineFunction().getFrameInfo(); |
| 3138 | MFI->setFrameAddressIsTaken(true); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 3139 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3140 | EVT VT = Op.getValueType(); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3141 | DebugLoc dl = Op.getDebugLoc(); // FIXME probably not meaningful |
| 3142 | unsigned Depth = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
Evan Cheng | cd82861 | 2009-06-18 23:14:30 +0000 | [diff] [blame] | 3143 | unsigned FrameReg = (Subtarget->isThumb() || Subtarget->isTargetDarwin()) |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3144 | ? ARM::R7 : ARM::R11; |
| 3145 | SDValue FrameAddr = DAG.getCopyFromReg(DAG.getEntryNode(), dl, FrameReg, VT); |
| 3146 | while (Depth--) |
Chris Lattner | d1c24ed | 2010-09-21 06:44:06 +0000 | [diff] [blame] | 3147 | FrameAddr = DAG.getLoad(VT, dl, DAG.getEntryNode(), FrameAddr, |
| 3148 | MachinePointerInfo(), |
David Greene | 1b58cab | 2010-02-15 16:55:24 +0000 | [diff] [blame] | 3149 | false, false, 0); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 3150 | return FrameAddr; |
| 3151 | } |
| 3152 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3153 | /// ExpandBITCAST - If the target supports VFP, this function is called to |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3154 | /// expand a bit convert where either the source or destination type is i64 to |
| 3155 | /// use a VMOVDRR or VMOVRRD node. This should not be done when the non-i64 |
| 3156 | /// operand type is illegal (e.g., v2f32 for a target that doesn't support |
| 3157 | /// vectors), since the legalizer won't know what to do with that. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3158 | static SDValue ExpandBITCAST(SDNode *N, SelectionDAG &DAG) { |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3159 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 3160 | DebugLoc dl = N->getDebugLoc(); |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 3161 | SDValue Op = N->getOperand(0); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3162 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3163 | // This function is only supposed to be called for i64 types, either as the |
| 3164 | // source or destination of the bit convert. |
| 3165 | EVT SrcVT = Op.getValueType(); |
| 3166 | EVT DstVT = N->getValueType(0); |
| 3167 | assert((SrcVT == MVT::i64 || DstVT == MVT::i64) && |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3168 | "ExpandBITCAST called for non-i64 type"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 3169 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3170 | // Turn i64->f64 into VMOVDRR. |
| 3171 | if (SrcVT == MVT::i64 && TLI.isTypeLegal(DstVT)) { |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3172 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3173 | DAG.getConstant(0, MVT::i32)); |
| 3174 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, Op, |
| 3175 | DAG.getConstant(1, MVT::i32)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3176 | return DAG.getNode(ISD::BITCAST, dl, DstVT, |
Bob Wilson | 1114f56 | 2010-06-11 22:45:25 +0000 | [diff] [blame] | 3177 | DAG.getNode(ARMISD::VMOVDRR, dl, MVT::f64, Lo, Hi)); |
Evan Cheng | c7c7729 | 2008-11-04 19:57:48 +0000 | [diff] [blame] | 3178 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3179 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 3180 | // Turn f64->i64 into VMOVRRD. |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3181 | if (DstVT == MVT::i64 && TLI.isTypeLegal(SrcVT)) { |
| 3182 | SDValue Cvt = DAG.getNode(ARMISD::VMOVRRD, dl, |
| 3183 | DAG.getVTList(MVT::i32, MVT::i32), &Op, 1); |
| 3184 | // Merge the pieces into a single i64 value. |
| 3185 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Cvt, Cvt.getValue(1)); |
| 3186 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3187 | |
Bob Wilson | 9f3f061 | 2010-04-17 05:30:19 +0000 | [diff] [blame] | 3188 | return SDValue(); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3189 | } |
| 3190 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3191 | /// getZeroVector - Returns a vector of specified type with all zero elements. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3192 | /// Zero vectors are used to represent vector negation and in those cases |
| 3193 | /// will be implemented with the NEON VNEG instruction. However, VNEG does |
| 3194 | /// not support i64 elements, so sometimes the zero vectors will need to be |
| 3195 | /// explicitly constructed. Regardless, use a canonical VMOV to create the |
| 3196 | /// zero vector. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3197 | static SDValue getZeroVector(EVT VT, SelectionDAG &DAG, DebugLoc dl) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3198 | assert(VT.isVector() && "Expected a vector type"); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3199 | // The canonical modified immediate encoding of a zero vector is....0! |
| 3200 | SDValue EncodedVal = DAG.getTargetConstant(0, MVT::i32); |
| 3201 | EVT VmovVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 3202 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, EncodedVal); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3203 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3204 | } |
| 3205 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3206 | /// LowerShiftRightParts - Lower SRA_PARTS, which returns two |
| 3207 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3208 | SDValue ARMTargetLowering::LowerShiftRightParts(SDValue Op, |
| 3209 | SelectionDAG &DAG) const { |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3210 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3211 | EVT VT = Op.getValueType(); |
| 3212 | unsigned VTBits = VT.getSizeInBits(); |
| 3213 | DebugLoc dl = Op.getDebugLoc(); |
| 3214 | SDValue ShOpLo = Op.getOperand(0); |
| 3215 | SDValue ShOpHi = Op.getOperand(1); |
| 3216 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3217 | SDValue ARMcc; |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3218 | unsigned Opc = (Op.getOpcode() == ISD::SRA_PARTS) ? ISD::SRA : ISD::SRL; |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3219 | |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3220 | assert(Op.getOpcode() == ISD::SRA_PARTS || Op.getOpcode() == ISD::SRL_PARTS); |
| 3221 | |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3222 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3223 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3224 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, ShAmt); |
| 3225 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3226 | DAG.getConstant(VTBits, MVT::i32)); |
| 3227 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, RevShAmt); |
| 3228 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3229 | SDValue TrueVal = DAG.getNode(Opc, dl, VT, ShOpHi, ExtraShAmt); |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3230 | |
| 3231 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3232 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3233 | ARMcc, DAG, dl); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 3234 | SDValue Hi = DAG.getNode(Opc, dl, VT, ShOpHi, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3235 | SDValue Lo = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, TrueVal, ARMcc, |
Jim Grosbach | b4a976c | 2009-10-31 21:00:56 +0000 | [diff] [blame] | 3236 | CCR, Cmp); |
| 3237 | |
| 3238 | SDValue Ops[2] = { Lo, Hi }; |
| 3239 | return DAG.getMergeValues(Ops, 2, dl); |
| 3240 | } |
| 3241 | |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3242 | /// LowerShiftLeftParts - Lower SHL_PARTS, which returns two |
| 3243 | /// i32 values and take a 2 x i32 value to shift plus a shift amount. |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 3244 | SDValue ARMTargetLowering::LowerShiftLeftParts(SDValue Op, |
| 3245 | SelectionDAG &DAG) const { |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3246 | assert(Op.getNumOperands() == 3 && "Not a double-shift!"); |
| 3247 | EVT VT = Op.getValueType(); |
| 3248 | unsigned VTBits = VT.getSizeInBits(); |
| 3249 | DebugLoc dl = Op.getDebugLoc(); |
| 3250 | SDValue ShOpLo = Op.getOperand(0); |
| 3251 | SDValue ShOpHi = Op.getOperand(1); |
| 3252 | SDValue ShAmt = Op.getOperand(2); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3253 | SDValue ARMcc; |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3254 | |
| 3255 | assert(Op.getOpcode() == ISD::SHL_PARTS); |
| 3256 | SDValue RevShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, |
| 3257 | DAG.getConstant(VTBits, MVT::i32), ShAmt); |
| 3258 | SDValue Tmp1 = DAG.getNode(ISD::SRL, dl, VT, ShOpLo, RevShAmt); |
| 3259 | SDValue ExtraShAmt = DAG.getNode(ISD::SUB, dl, MVT::i32, ShAmt, |
| 3260 | DAG.getConstant(VTBits, MVT::i32)); |
| 3261 | SDValue Tmp2 = DAG.getNode(ISD::SHL, dl, VT, ShOpHi, ShAmt); |
| 3262 | SDValue Tmp3 = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ExtraShAmt); |
| 3263 | |
| 3264 | SDValue FalseVal = DAG.getNode(ISD::OR, dl, VT, Tmp1, Tmp2); |
| 3265 | SDValue CCR = DAG.getRegister(ARM::CPSR, MVT::i32); |
| 3266 | SDValue Cmp = getARMCmp(ExtraShAmt, DAG.getConstant(0, MVT::i32), ISD::SETGE, |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3267 | ARMcc, DAG, dl); |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3268 | SDValue Lo = DAG.getNode(ISD::SHL, dl, VT, ShOpLo, ShAmt); |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 3269 | SDValue Hi = DAG.getNode(ARMISD::CMOV, dl, VT, FalseVal, Tmp3, ARMcc, |
Jim Grosbach | c2b879f | 2009-10-31 19:38:01 +0000 | [diff] [blame] | 3270 | CCR, Cmp); |
| 3271 | |
| 3272 | SDValue Ops[2] = { Lo, Hi }; |
| 3273 | return DAG.getMergeValues(Ops, 2, dl); |
| 3274 | } |
| 3275 | |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3276 | SDValue ARMTargetLowering::LowerFLT_ROUNDS_(SDValue Op, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3277 | SelectionDAG &DAG) const { |
| 3278 | // The rounding mode is in bits 23:22 of the FPSCR. |
| 3279 | // The ARM rounding mode value to FLT_ROUNDS mapping is 0->1, 1->2, 2->3, 3->0 |
| 3280 | // The formula we use to implement this is (((FPSCR + 1 << 22) >> 22) & 3) |
| 3281 | // so that the shift + and get folded into a bitfield extract. |
| 3282 | DebugLoc dl = Op.getDebugLoc(); |
| 3283 | SDValue FPSCR = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::i32, |
| 3284 | DAG.getConstant(Intrinsic::arm_get_fpscr, |
| 3285 | MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3286 | SDValue FltRounds = DAG.getNode(ISD::ADD, dl, MVT::i32, FPSCR, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3287 | DAG.getConstant(1U << 22, MVT::i32)); |
| 3288 | SDValue RMODE = DAG.getNode(ISD::SRL, dl, MVT::i32, FltRounds, |
| 3289 | DAG.getConstant(22, MVT::i32)); |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 3290 | return DAG.getNode(ISD::AND, dl, MVT::i32, RMODE, |
Nate Begeman | d1fb583 | 2010-08-03 21:31:55 +0000 | [diff] [blame] | 3291 | DAG.getConstant(3, MVT::i32)); |
| 3292 | } |
| 3293 | |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 3294 | static SDValue LowerCTTZ(SDNode *N, SelectionDAG &DAG, |
| 3295 | const ARMSubtarget *ST) { |
| 3296 | EVT VT = N->getValueType(0); |
| 3297 | DebugLoc dl = N->getDebugLoc(); |
| 3298 | |
| 3299 | if (!ST->hasV6T2Ops()) |
| 3300 | return SDValue(); |
| 3301 | |
| 3302 | SDValue rbit = DAG.getNode(ARMISD::RBIT, dl, VT, N->getOperand(0)); |
| 3303 | return DAG.getNode(ISD::CTLZ, dl, VT, rbit); |
| 3304 | } |
| 3305 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3306 | static SDValue LowerShift(SDNode *N, SelectionDAG &DAG, |
| 3307 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3308 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3309 | DebugLoc dl = N->getDebugLoc(); |
| 3310 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3311 | if (!VT.isVector()) |
| 3312 | return SDValue(); |
| 3313 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3314 | // Lower vector shifts on NEON to use VSHL. |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3315 | assert(ST->hasNEON() && "unexpected vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3316 | |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3317 | // Left shifts translate directly to the vshiftu intrinsic. |
| 3318 | if (N->getOpcode() == ISD::SHL) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3319 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 3320 | DAG.getConstant(Intrinsic::arm_neon_vshiftu, MVT::i32), |
| 3321 | N->getOperand(0), N->getOperand(1)); |
| 3322 | |
| 3323 | assert((N->getOpcode() == ISD::SRA || |
| 3324 | N->getOpcode() == ISD::SRL) && "unexpected vector shift opcode"); |
| 3325 | |
| 3326 | // NEON uses the same intrinsics for both left and right shifts. For |
| 3327 | // right shifts, the shift amounts are negative, so negate the vector of |
| 3328 | // shift amounts. |
| 3329 | EVT ShiftVT = N->getOperand(1).getValueType(); |
| 3330 | SDValue NegatedCount = DAG.getNode(ISD::SUB, dl, ShiftVT, |
| 3331 | getZeroVector(ShiftVT, DAG, dl), |
| 3332 | N->getOperand(1)); |
| 3333 | Intrinsic::ID vshiftInt = (N->getOpcode() == ISD::SRA ? |
| 3334 | Intrinsic::arm_neon_vshifts : |
| 3335 | Intrinsic::arm_neon_vshiftu); |
| 3336 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, VT, |
| 3337 | DAG.getConstant(vshiftInt, MVT::i32), |
| 3338 | N->getOperand(0), NegatedCount); |
| 3339 | } |
| 3340 | |
| 3341 | static SDValue Expand64BitShift(SDNode *N, SelectionDAG &DAG, |
| 3342 | const ARMSubtarget *ST) { |
| 3343 | EVT VT = N->getValueType(0); |
| 3344 | DebugLoc dl = N->getDebugLoc(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3345 | |
Eli Friedman | ce392eb | 2009-08-22 03:13:10 +0000 | [diff] [blame] | 3346 | // We can get here for a node like i32 = ISD::SHL i32, i64 |
| 3347 | if (VT != MVT::i64) |
| 3348 | return SDValue(); |
| 3349 | |
| 3350 | assert((N->getOpcode() == ISD::SRL || N->getOpcode() == ISD::SRA) && |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3351 | "Unknown shift to lower!"); |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3352 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3353 | // We only lower SRA, SRL of 1 here, all others use generic lowering. |
| 3354 | if (!isa<ConstantSDNode>(N->getOperand(1)) || |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 3355 | cast<ConstantSDNode>(N->getOperand(1))->getZExtValue() != 1) |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 3356 | return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3357 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3358 | // If we are in thumb mode, we don't have RRX. |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 3359 | if (ST->isThumb1Only()) return SDValue(); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3360 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3361 | // Okay, we have a 64-bit SRA or SRL of 1. Lower this to an RRX expr. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3362 | SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3363 | DAG.getConstant(0, MVT::i32)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3364 | SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, dl, MVT::i32, N->getOperand(0), |
Bob Wilson | ab3912e | 2010-05-25 03:36:52 +0000 | [diff] [blame] | 3365 | DAG.getConstant(1, MVT::i32)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3366 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3367 | // First, build a SRA_FLAG/SRL_FLAG op, which shifts the top part by one and |
| 3368 | // captures the result into a carry flag. |
| 3369 | unsigned Opc = N->getOpcode() == ISD::SRL ? ARMISD::SRL_FLAG:ARMISD::SRA_FLAG; |
Chris Lattner | f1b4eaf | 2010-12-21 02:38:05 +0000 | [diff] [blame] | 3370 | Hi = DAG.getNode(Opc, dl, DAG.getVTList(MVT::i32, MVT::Glue), &Hi, 1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3371 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3372 | // The low part is an ARMISD::RRX operand, which shifts the carry in. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3373 | Lo = DAG.getNode(ARMISD::RRX, dl, MVT::i32, Lo, Hi.getValue(1)); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 3374 | |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3375 | // Merge the pieces into a single i64 value. |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 3376 | return DAG.getNode(ISD::BUILD_PAIR, dl, MVT::i64, Lo, Hi); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3379 | static SDValue LowerVSETCC(SDValue Op, SelectionDAG &DAG) { |
| 3380 | SDValue TmpOp0, TmpOp1; |
| 3381 | bool Invert = false; |
| 3382 | bool Swap = false; |
| 3383 | unsigned Opc = 0; |
| 3384 | |
| 3385 | SDValue Op0 = Op.getOperand(0); |
| 3386 | SDValue Op1 = Op.getOperand(1); |
| 3387 | SDValue CC = Op.getOperand(2); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3388 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3389 | ISD::CondCode SetCCOpcode = cast<CondCodeSDNode>(CC)->get(); |
| 3390 | DebugLoc dl = Op.getDebugLoc(); |
| 3391 | |
| 3392 | if (Op.getOperand(1).getValueType().isFloatingPoint()) { |
| 3393 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3394 | default: llvm_unreachable("Illegal FP comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3395 | case ISD::SETUNE: |
| 3396 | case ISD::SETNE: Invert = true; // Fallthrough |
| 3397 | case ISD::SETOEQ: |
| 3398 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3399 | case ISD::SETOLT: |
| 3400 | case ISD::SETLT: Swap = true; // Fallthrough |
| 3401 | case ISD::SETOGT: |
| 3402 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3403 | case ISD::SETOLE: |
| 3404 | case ISD::SETLE: Swap = true; // Fallthrough |
| 3405 | case ISD::SETOGE: |
| 3406 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3407 | case ISD::SETUGE: Swap = true; // Fallthrough |
| 3408 | case ISD::SETULE: Invert = true; Opc = ARMISD::VCGT; break; |
| 3409 | case ISD::SETUGT: Swap = true; // Fallthrough |
| 3410 | case ISD::SETULT: Invert = true; Opc = ARMISD::VCGE; break; |
| 3411 | case ISD::SETUEQ: Invert = true; // Fallthrough |
| 3412 | case ISD::SETONE: |
| 3413 | // Expand this to (OLT | OGT). |
| 3414 | TmpOp0 = Op0; |
| 3415 | TmpOp1 = Op1; |
| 3416 | Opc = ISD::OR; |
| 3417 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3418 | Op1 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp0, TmpOp1); |
| 3419 | break; |
| 3420 | case ISD::SETUO: Invert = true; // Fallthrough |
| 3421 | case ISD::SETO: |
| 3422 | // Expand this to (OLT | OGE). |
| 3423 | TmpOp0 = Op0; |
| 3424 | TmpOp1 = Op1; |
| 3425 | Opc = ISD::OR; |
| 3426 | Op0 = DAG.getNode(ARMISD::VCGT, dl, VT, TmpOp1, TmpOp0); |
| 3427 | Op1 = DAG.getNode(ARMISD::VCGE, dl, VT, TmpOp0, TmpOp1); |
| 3428 | break; |
| 3429 | } |
| 3430 | } else { |
| 3431 | // Integer comparisons. |
| 3432 | switch (SetCCOpcode) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 3433 | default: llvm_unreachable("Illegal integer comparison"); break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3434 | case ISD::SETNE: Invert = true; |
| 3435 | case ISD::SETEQ: Opc = ARMISD::VCEQ; break; |
| 3436 | case ISD::SETLT: Swap = true; |
| 3437 | case ISD::SETGT: Opc = ARMISD::VCGT; break; |
| 3438 | case ISD::SETLE: Swap = true; |
| 3439 | case ISD::SETGE: Opc = ARMISD::VCGE; break; |
| 3440 | case ISD::SETULT: Swap = true; |
| 3441 | case ISD::SETUGT: Opc = ARMISD::VCGTU; break; |
| 3442 | case ISD::SETULE: Swap = true; |
| 3443 | case ISD::SETUGE: Opc = ARMISD::VCGEU; break; |
| 3444 | } |
| 3445 | |
Nick Lewycky | 7f6aa2b | 2009-07-08 03:04:38 +0000 | [diff] [blame] | 3446 | // Detect VTST (Vector Test Bits) = icmp ne (and (op0, op1), zero). |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3447 | if (Opc == ARMISD::VCEQ) { |
| 3448 | |
| 3449 | SDValue AndOp; |
| 3450 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3451 | AndOp = Op0; |
| 3452 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) |
| 3453 | AndOp = Op1; |
| 3454 | |
| 3455 | // Ignore bitconvert. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3456 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3457 | AndOp = AndOp.getOperand(0); |
| 3458 | |
| 3459 | if (AndOp.getNode() && AndOp.getOpcode() == ISD::AND) { |
| 3460 | Opc = ARMISD::VTST; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3461 | Op0 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(0)); |
| 3462 | Op1 = DAG.getNode(ISD::BITCAST, dl, VT, AndOp.getOperand(1)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3463 | Invert = !Invert; |
| 3464 | } |
| 3465 | } |
| 3466 | } |
| 3467 | |
| 3468 | if (Swap) |
| 3469 | std::swap(Op0, Op1); |
| 3470 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3471 | // If one of the operands is a constant vector zero, attempt to fold the |
| 3472 | // comparison to a specialized compare-against-zero form. |
| 3473 | SDValue SingleOp; |
| 3474 | if (ISD::isBuildVectorAllZeros(Op1.getNode())) |
| 3475 | SingleOp = Op0; |
| 3476 | else if (ISD::isBuildVectorAllZeros(Op0.getNode())) { |
| 3477 | if (Opc == ARMISD::VCGE) |
| 3478 | Opc = ARMISD::VCLEZ; |
| 3479 | else if (Opc == ARMISD::VCGT) |
| 3480 | Opc = ARMISD::VCLTZ; |
| 3481 | SingleOp = Op1; |
| 3482 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3483 | |
Owen Anderson | c24cb35 | 2010-11-08 23:21:22 +0000 | [diff] [blame] | 3484 | SDValue Result; |
| 3485 | if (SingleOp.getNode()) { |
| 3486 | switch (Opc) { |
| 3487 | case ARMISD::VCEQ: |
| 3488 | Result = DAG.getNode(ARMISD::VCEQZ, dl, VT, SingleOp); break; |
| 3489 | case ARMISD::VCGE: |
| 3490 | Result = DAG.getNode(ARMISD::VCGEZ, dl, VT, SingleOp); break; |
| 3491 | case ARMISD::VCLEZ: |
| 3492 | Result = DAG.getNode(ARMISD::VCLEZ, dl, VT, SingleOp); break; |
| 3493 | case ARMISD::VCGT: |
| 3494 | Result = DAG.getNode(ARMISD::VCGTZ, dl, VT, SingleOp); break; |
| 3495 | case ARMISD::VCLTZ: |
| 3496 | Result = DAG.getNode(ARMISD::VCLTZ, dl, VT, SingleOp); break; |
| 3497 | default: |
| 3498 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3499 | } |
| 3500 | } else { |
| 3501 | Result = DAG.getNode(Opc, dl, VT, Op0, Op1); |
| 3502 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3503 | |
| 3504 | if (Invert) |
| 3505 | Result = DAG.getNOT(dl, Result, VT); |
| 3506 | |
| 3507 | return Result; |
| 3508 | } |
| 3509 | |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3510 | /// isNEONModifiedImm - Check if the specified splat value corresponds to a |
| 3511 | /// valid vector constant for a NEON instruction with a "modified immediate" |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3512 | /// operand (e.g., VMOV). If so, return the encoded value. |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3513 | static SDValue isNEONModifiedImm(uint64_t SplatBits, uint64_t SplatUndef, |
| 3514 | unsigned SplatBitSize, SelectionDAG &DAG, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3515 | EVT &VT, bool is128Bits, NEONModImmType type) { |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3516 | unsigned OpCmode, Imm; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3517 | |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3518 | // SplatBitSize is set to the smallest size that splats the vector, so a |
| 3519 | // zero vector will always have SplatBitSize == 8. However, NEON modified |
| 3520 | // immediate instructions others than VMOV do not support the 8-bit encoding |
| 3521 | // of a zero vector, and the default encoding of zero is supposed to be the |
| 3522 | // 32-bit version. |
| 3523 | if (SplatBits == 0) |
| 3524 | SplatBitSize = 32; |
| 3525 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3526 | switch (SplatBitSize) { |
| 3527 | case 8: |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3528 | if (type != VMOVModImm) |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3529 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3530 | // Any 1-byte value is OK. Op=0, Cmode=1110. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3531 | assert((SplatBits & ~0xff) == 0 && "one byte splat value is too big"); |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3532 | OpCmode = 0xe; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3533 | Imm = SplatBits; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3534 | VT = is128Bits ? MVT::v16i8 : MVT::v8i8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3535 | break; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3536 | |
| 3537 | case 16: |
| 3538 | // NEON's 16-bit VMOV supports splat values where only one byte is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3539 | VT = is128Bits ? MVT::v8i16 : MVT::v4i16; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3540 | if ((SplatBits & ~0xff) == 0) { |
| 3541 | // Value = 0x00nn: Op=x, Cmode=100x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3542 | OpCmode = 0x8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3543 | Imm = SplatBits; |
| 3544 | break; |
| 3545 | } |
| 3546 | if ((SplatBits & ~0xff00) == 0) { |
| 3547 | // Value = 0xnn00: Op=x, Cmode=101x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3548 | OpCmode = 0xa; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3549 | Imm = SplatBits >> 8; |
| 3550 | break; |
| 3551 | } |
| 3552 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3553 | |
| 3554 | case 32: |
| 3555 | // NEON's 32-bit VMOV supports splat values where: |
| 3556 | // * only one byte is nonzero, or |
| 3557 | // * the least significant byte is 0xff and the second byte is nonzero, or |
| 3558 | // * the least significant 2 bytes are 0xff and the third is nonzero. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3559 | VT = is128Bits ? MVT::v4i32 : MVT::v2i32; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3560 | if ((SplatBits & ~0xff) == 0) { |
| 3561 | // Value = 0x000000nn: Op=x, Cmode=000x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3562 | OpCmode = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3563 | Imm = SplatBits; |
| 3564 | break; |
| 3565 | } |
| 3566 | if ((SplatBits & ~0xff00) == 0) { |
| 3567 | // Value = 0x0000nn00: Op=x, Cmode=001x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3568 | OpCmode = 0x2; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3569 | Imm = SplatBits >> 8; |
| 3570 | break; |
| 3571 | } |
| 3572 | if ((SplatBits & ~0xff0000) == 0) { |
| 3573 | // Value = 0x00nn0000: Op=x, Cmode=010x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3574 | OpCmode = 0x4; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3575 | Imm = SplatBits >> 16; |
| 3576 | break; |
| 3577 | } |
| 3578 | if ((SplatBits & ~0xff000000) == 0) { |
| 3579 | // Value = 0xnn000000: Op=x, Cmode=011x. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3580 | OpCmode = 0x6; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3581 | Imm = SplatBits >> 24; |
| 3582 | break; |
| 3583 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3584 | |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3585 | // cmode == 0b1100 and cmode == 0b1101 are not supported for VORR or VBIC |
| 3586 | if (type == OtherModImm) return SDValue(); |
| 3587 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3588 | if ((SplatBits & ~0xffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3589 | ((SplatBits | SplatUndef) & 0xff) == 0xff) { |
| 3590 | // Value = 0x0000nnff: Op=x, Cmode=1100. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3591 | OpCmode = 0xc; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3592 | Imm = SplatBits >> 8; |
| 3593 | SplatBits |= 0xff; |
| 3594 | break; |
| 3595 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3596 | |
| 3597 | if ((SplatBits & ~0xffffff) == 0 && |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3598 | ((SplatBits | SplatUndef) & 0xffff) == 0xffff) { |
| 3599 | // Value = 0x00nnffff: Op=x, Cmode=1101. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3600 | OpCmode = 0xd; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3601 | Imm = SplatBits >> 16; |
| 3602 | SplatBits |= 0xffff; |
| 3603 | break; |
| 3604 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3605 | |
| 3606 | // Note: there are a few 32-bit splat values (specifically: 00ffff00, |
| 3607 | // ff000000, ff0000ff, and ffff00ff) that are valid for VMOV.I64 but not |
| 3608 | // VMOV.I32. A (very) minor optimization would be to replicate the value |
| 3609 | // and fall through here to test for a valid 64-bit splat. But, then the |
| 3610 | // caller would also need to check and handle the change in size. |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3611 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3612 | |
| 3613 | case 64: { |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3614 | if (type != VMOVModImm) |
Bob Wilson | 827b210 | 2010-06-15 19:05:35 +0000 | [diff] [blame] | 3615 | return SDValue(); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3616 | // NEON has a 64-bit VMOV splat where each byte is either 0 or 0xff. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3617 | uint64_t BitMask = 0xff; |
| 3618 | uint64_t Val = 0; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3619 | unsigned ImmMask = 1; |
| 3620 | Imm = 0; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3621 | for (int ByteNum = 0; ByteNum < 8; ++ByteNum) { |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3622 | if (((SplatBits | SplatUndef) & BitMask) == BitMask) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3623 | Val |= BitMask; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3624 | Imm |= ImmMask; |
| 3625 | } else if ((SplatBits & BitMask) != 0) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3626 | return SDValue(); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3627 | } |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3628 | BitMask <<= 8; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3629 | ImmMask <<= 1; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3630 | } |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3631 | // Op=1, Cmode=1110. |
Bob Wilson | 6dce00c | 2010-07-13 04:44:34 +0000 | [diff] [blame] | 3632 | OpCmode = 0x1e; |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3633 | SplatBits = Val; |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3634 | VT = is128Bits ? MVT::v2i64 : MVT::v1i64; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3635 | break; |
| 3636 | } |
| 3637 | |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3638 | default: |
Bob Wilson | dc076da | 2010-06-19 05:32:09 +0000 | [diff] [blame] | 3639 | llvm_unreachable("unexpected size for isNEONModifiedImm"); |
Bob Wilson | 1a913ed | 2010-06-11 21:34:50 +0000 | [diff] [blame] | 3640 | return SDValue(); |
| 3641 | } |
| 3642 | |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3643 | unsigned EncodedVal = ARM_AM::createNEONModImm(OpCmode, Imm); |
| 3644 | return DAG.getTargetConstant(EncodedVal, MVT::i32); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3645 | } |
| 3646 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3647 | static bool isVEXTMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3648 | bool &ReverseVEXT, unsigned &Imm) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3649 | unsigned NumElts = VT.getVectorNumElements(); |
| 3650 | ReverseVEXT = false; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3651 | |
| 3652 | // Assume that the first shuffle index is not UNDEF. Fail if it is. |
| 3653 | if (M[0] < 0) |
| 3654 | return false; |
| 3655 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3656 | Imm = M[0]; |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3657 | |
| 3658 | // If this is a VEXT shuffle, the immediate value is the index of the first |
| 3659 | // element. The other shuffle indices must be the successive elements after |
| 3660 | // the first one. |
| 3661 | unsigned ExpectedElt = Imm; |
| 3662 | for (unsigned i = 1; i < NumElts; ++i) { |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3663 | // Increment the expected index. If it wraps around, it may still be |
| 3664 | // a VEXT but the source vectors must be swapped. |
| 3665 | ExpectedElt += 1; |
| 3666 | if (ExpectedElt == NumElts * 2) { |
| 3667 | ExpectedElt = 0; |
| 3668 | ReverseVEXT = true; |
| 3669 | } |
| 3670 | |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3671 | if (M[i] < 0) continue; // ignore UNDEF indices |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3672 | if (ExpectedElt != static_cast<unsigned>(M[i])) |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3673 | return false; |
| 3674 | } |
| 3675 | |
| 3676 | // Adjust the index value if the source operands will be swapped. |
| 3677 | if (ReverseVEXT) |
| 3678 | Imm -= NumElts; |
| 3679 | |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 3680 | return true; |
| 3681 | } |
| 3682 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3683 | /// isVREVMask - Check if a vector shuffle corresponds to a VREV |
| 3684 | /// instruction with the specified blocksize. (The order of the elements |
| 3685 | /// within each block of the vector is reversed.) |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3686 | static bool isVREVMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3687 | unsigned BlockSize) { |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3688 | assert((BlockSize==16 || BlockSize==32 || BlockSize==64) && |
| 3689 | "Only possible block sizes for VREV are: 16, 32, 64"); |
| 3690 | |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3691 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3692 | if (EltSz == 64) |
| 3693 | return false; |
| 3694 | |
| 3695 | unsigned NumElts = VT.getVectorNumElements(); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 3696 | unsigned BlockElts = M[0] + 1; |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3697 | // If the first shuffle index is UNDEF, be optimistic. |
| 3698 | if (M[0] < 0) |
| 3699 | BlockElts = BlockSize / EltSz; |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3700 | |
| 3701 | if (BlockSize <= EltSz || BlockSize != BlockElts * EltSz) |
| 3702 | return false; |
| 3703 | |
| 3704 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3705 | if (M[i] < 0) continue; // ignore UNDEF indices |
| 3706 | if ((unsigned) M[i] != (i - i%BlockElts) + (BlockElts - 1 - i%BlockElts)) |
Bob Wilson | 8bb9e48 | 2009-07-26 00:39:34 +0000 | [diff] [blame] | 3707 | return false; |
| 3708 | } |
| 3709 | |
| 3710 | return true; |
| 3711 | } |
| 3712 | |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 3713 | static bool isVTBLMask(const SmallVectorImpl<int> &M, EVT VT) { |
| 3714 | // We can handle <8 x i8> vector shuffles. If the index in the mask is out of |
| 3715 | // range, then 0 is placed into the resulting vector. So pretty much any mask |
| 3716 | // of 8 elements can work here. |
| 3717 | return VT == MVT::v8i8 && M.size() == 8; |
| 3718 | } |
| 3719 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3720 | static bool isVTRNMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3721 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3722 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3723 | if (EltSz == 64) |
| 3724 | return false; |
| 3725 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3726 | unsigned NumElts = VT.getVectorNumElements(); |
| 3727 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3728 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3729 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3730 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + NumElts + WhichResult)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | return true; |
| 3734 | } |
| 3735 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3736 | /// isVTRN_v_undef_Mask - Special case of isVTRNMask for canonical form of |
| 3737 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3738 | /// Mask is e.g., <0, 0, 2, 2> instead of <0, 4, 2, 6>. |
| 3739 | static bool isVTRN_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3740 | unsigned &WhichResult) { |
| 3741 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3742 | if (EltSz == 64) |
| 3743 | return false; |
| 3744 | |
| 3745 | unsigned NumElts = VT.getVectorNumElements(); |
| 3746 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3747 | for (unsigned i = 0; i < NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3748 | if ((M[i] >= 0 && (unsigned) M[i] != i + WhichResult) || |
| 3749 | (M[i+1] >= 0 && (unsigned) M[i+1] != i + WhichResult)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3750 | return false; |
| 3751 | } |
| 3752 | return true; |
| 3753 | } |
| 3754 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3755 | static bool isVUZPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3756 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3757 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3758 | if (EltSz == 64) |
| 3759 | return false; |
| 3760 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3761 | unsigned NumElts = VT.getVectorNumElements(); |
| 3762 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3763 | for (unsigned i = 0; i != NumElts; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3764 | if (M[i] < 0) continue; // ignore UNDEF indices |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3765 | if ((unsigned) M[i] != 2 * i + WhichResult) |
| 3766 | return false; |
| 3767 | } |
| 3768 | |
| 3769 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3770 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3771 | return false; |
| 3772 | |
| 3773 | return true; |
| 3774 | } |
| 3775 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3776 | /// isVUZP_v_undef_Mask - Special case of isVUZPMask for canonical form of |
| 3777 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3778 | /// Mask is e.g., <0, 2, 0, 2> instead of <0, 2, 4, 6>, |
| 3779 | static bool isVUZP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3780 | unsigned &WhichResult) { |
| 3781 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3782 | if (EltSz == 64) |
| 3783 | return false; |
| 3784 | |
| 3785 | unsigned Half = VT.getVectorNumElements() / 2; |
| 3786 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3787 | for (unsigned j = 0; j != 2; ++j) { |
| 3788 | unsigned Idx = WhichResult; |
| 3789 | for (unsigned i = 0; i != Half; ++i) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3790 | int MIdx = M[i + j * Half]; |
| 3791 | if (MIdx >= 0 && (unsigned) MIdx != Idx) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3792 | return false; |
| 3793 | Idx += 2; |
| 3794 | } |
| 3795 | } |
| 3796 | |
| 3797 | // VUZP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3798 | if (VT.is64BitVector() && EltSz == 32) |
| 3799 | return false; |
| 3800 | |
| 3801 | return true; |
| 3802 | } |
| 3803 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3804 | static bool isVZIPMask(const SmallVectorImpl<int> &M, EVT VT, |
| 3805 | unsigned &WhichResult) { |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3806 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3807 | if (EltSz == 64) |
| 3808 | return false; |
| 3809 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3810 | unsigned NumElts = VT.getVectorNumElements(); |
| 3811 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3812 | unsigned Idx = WhichResult * NumElts / 2; |
| 3813 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3814 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3815 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx + NumElts)) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3816 | return false; |
| 3817 | Idx += 1; |
| 3818 | } |
| 3819 | |
| 3820 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
Bob Wilson | 20d1081 | 2009-10-21 21:36:27 +0000 | [diff] [blame] | 3821 | if (VT.is64BitVector() && EltSz == 32) |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 3822 | return false; |
| 3823 | |
| 3824 | return true; |
| 3825 | } |
| 3826 | |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3827 | /// isVZIP_v_undef_Mask - Special case of isVZIPMask for canonical form of |
| 3828 | /// "vector_shuffle v, v", i.e., "vector_shuffle v, undef". |
| 3829 | /// Mask is e.g., <0, 0, 1, 1> instead of <0, 4, 1, 5>. |
| 3830 | static bool isVZIP_v_undef_Mask(const SmallVectorImpl<int> &M, EVT VT, |
| 3831 | unsigned &WhichResult) { |
| 3832 | unsigned EltSz = VT.getVectorElementType().getSizeInBits(); |
| 3833 | if (EltSz == 64) |
| 3834 | return false; |
| 3835 | |
| 3836 | unsigned NumElts = VT.getVectorNumElements(); |
| 3837 | WhichResult = (M[0] == 0 ? 0 : 1); |
| 3838 | unsigned Idx = WhichResult * NumElts / 2; |
| 3839 | for (unsigned i = 0; i != NumElts; i += 2) { |
Bob Wilson | 7aaf5bf | 2010-08-17 05:54:34 +0000 | [diff] [blame] | 3840 | if ((M[i] >= 0 && (unsigned) M[i] != Idx) || |
| 3841 | (M[i+1] >= 0 && (unsigned) M[i+1] != Idx)) |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 3842 | return false; |
| 3843 | Idx += 1; |
| 3844 | } |
| 3845 | |
| 3846 | // VZIP.32 for 64-bit vectors is a pseudo-instruction alias for VTRN.32. |
| 3847 | if (VT.is64BitVector() && EltSz == 32) |
| 3848 | return false; |
| 3849 | |
| 3850 | return true; |
| 3851 | } |
| 3852 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3853 | // If N is an integer constant that can be moved into a register in one |
| 3854 | // instruction, return an SDValue of such a constant (will become a MOV |
| 3855 | // instruction). Otherwise return null. |
| 3856 | static SDValue IsSingleInstrConstant(SDValue N, SelectionDAG &DAG, |
| 3857 | const ARMSubtarget *ST, DebugLoc dl) { |
| 3858 | uint64_t Val; |
| 3859 | if (!isa<ConstantSDNode>(N)) |
| 3860 | return SDValue(); |
| 3861 | Val = cast<ConstantSDNode>(N)->getZExtValue(); |
| 3862 | |
| 3863 | if (ST->isThumb1Only()) { |
| 3864 | if (Val <= 255 || ~Val <= 255) |
| 3865 | return DAG.getConstant(Val, MVT::i32); |
| 3866 | } else { |
| 3867 | if (ARM_AM::getSOImmVal(Val) != -1 || ARM_AM::getSOImmVal(~Val) != -1) |
| 3868 | return DAG.getConstant(Val, MVT::i32); |
| 3869 | } |
| 3870 | return SDValue(); |
| 3871 | } |
| 3872 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3873 | // If this is a case we can't handle, return null and let the default |
| 3874 | // expansion code take care of it. |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3875 | SDValue ARMTargetLowering::LowerBUILD_VECTOR(SDValue Op, SelectionDAG &DAG, |
| 3876 | const ARMSubtarget *ST) const { |
Bob Wilson | d06791f | 2009-08-13 01:57:47 +0000 | [diff] [blame] | 3877 | BuildVectorSDNode *BVN = cast<BuildVectorSDNode>(Op.getNode()); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3878 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 3879 | EVT VT = Op.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3880 | |
| 3881 | APInt SplatBits, SplatUndef; |
| 3882 | unsigned SplatBitSize; |
| 3883 | bool HasAnyUndefs; |
| 3884 | if (BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3885 | if (SplatBitSize <= 64) { |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3886 | // Check if an immediate VMOV works. |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3887 | EVT VmovVT; |
Bob Wilson | d3c4284 | 2010-06-14 22:19:57 +0000 | [diff] [blame] | 3888 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3889 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3890 | DAG, VmovVT, VT.is128BitVector(), |
| 3891 | VMOVModImm); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3892 | if (Val.getNode()) { |
| 3893 | SDValue Vmov = DAG.getNode(ARMISD::VMOVIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3894 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | cba270d | 2010-07-13 21:16:48 +0000 | [diff] [blame] | 3895 | } |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3896 | |
| 3897 | // Try an immediate VMVN. |
| 3898 | uint64_t NegatedImm = (SplatBits.getZExtValue() ^ |
| 3899 | ((1LL << SplatBitSize) - 1)); |
| 3900 | Val = isNEONModifiedImm(NegatedImm, |
| 3901 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3902 | DAG, VmovVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 3903 | VMVNModImm); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3904 | if (Val.getNode()) { |
| 3905 | SDValue Vmov = DAG.getNode(ARMISD::VMVNIMM, dl, VmovVT, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3906 | return DAG.getNode(ISD::BITCAST, dl, VT, Vmov); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 3907 | } |
Anton Korobeynikov | 71624cc | 2009-08-29 00:08:18 +0000 | [diff] [blame] | 3908 | } |
Bob Wilson | cf661e2 | 2009-07-30 00:31:25 +0000 | [diff] [blame] | 3909 | } |
| 3910 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3911 | // Scan through the operands to see if only one value is used. |
| 3912 | unsigned NumElts = VT.getVectorNumElements(); |
| 3913 | bool isOnlyLowElement = true; |
| 3914 | bool usesOnlyOneValue = true; |
| 3915 | bool isConstant = true; |
| 3916 | SDValue Value; |
| 3917 | for (unsigned i = 0; i < NumElts; ++i) { |
| 3918 | SDValue V = Op.getOperand(i); |
| 3919 | if (V.getOpcode() == ISD::UNDEF) |
| 3920 | continue; |
| 3921 | if (i > 0) |
| 3922 | isOnlyLowElement = false; |
| 3923 | if (!isa<ConstantFPSDNode>(V) && !isa<ConstantSDNode>(V)) |
| 3924 | isConstant = false; |
| 3925 | |
| 3926 | if (!Value.getNode()) |
| 3927 | Value = V; |
| 3928 | else if (V != Value) |
| 3929 | usesOnlyOneValue = false; |
| 3930 | } |
| 3931 | |
| 3932 | if (!Value.getNode()) |
| 3933 | return DAG.getUNDEF(VT); |
| 3934 | |
| 3935 | if (isOnlyLowElement) |
| 3936 | return DAG.getNode(ISD::SCALAR_TO_VECTOR, dl, VT, Value); |
| 3937 | |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3938 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 3939 | |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3940 | // Use VDUP for non-constant splats. For f32 constant splats, reduce to |
| 3941 | // i32 and try again. |
| 3942 | if (usesOnlyOneValue && EltSize <= 32) { |
| 3943 | if (!isConstant) |
| 3944 | return DAG.getNode(ARMISD::VDUP, dl, VT, Value); |
| 3945 | if (VT.getVectorElementType().isFloatingPoint()) { |
| 3946 | SmallVector<SDValue, 8> Ops; |
| 3947 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3948 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, MVT::i32, |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3949 | Op.getOperand(i))); |
Nate Begeman | bf5be26 | 2010-11-10 21:35:41 +0000 | [diff] [blame] | 3950 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), MVT::i32, NumElts); |
| 3951 | SDValue Val = DAG.getNode(ISD::BUILD_VECTOR, dl, VecVT, &Ops[0], NumElts); |
Dale Johannesen | e4d3159 | 2010-10-20 22:03:37 +0000 | [diff] [blame] | 3952 | Val = LowerBUILD_VECTOR(Val, DAG, ST); |
| 3953 | if (Val.getNode()) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3954 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3955 | } |
Dale Johannesen | 575cd14 | 2010-10-19 20:00:17 +0000 | [diff] [blame] | 3956 | SDValue Val = IsSingleInstrConstant(Value, DAG, ST, dl); |
| 3957 | if (Val.getNode()) |
| 3958 | return DAG.getNode(ARMISD::VDUP, dl, VT, Val); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 3959 | } |
| 3960 | |
| 3961 | // If all elements are constants and the case above didn't get hit, fall back |
| 3962 | // to the default expansion, which will generate a load from the constant |
| 3963 | // pool. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3964 | if (isConstant) |
| 3965 | return SDValue(); |
| 3966 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3967 | // Empirical tests suggest this is rarely worth it for vectors of length <= 2. |
| 3968 | if (NumElts >= 4) { |
| 3969 | SDValue shuffle = ReconstructShuffle(Op, DAG); |
| 3970 | if (shuffle != SDValue()) |
| 3971 | return shuffle; |
| 3972 | } |
| 3973 | |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3974 | // Vectors with 32- or 64-bit elements can be built by directly assigning |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3975 | // the subregisters. Lower it to an ARMISD::BUILD_VECTOR so the operands |
| 3976 | // will be legalized. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 3977 | if (EltSize >= 32) { |
| 3978 | // Do the expansion with floating-point types, since that is what the VFP |
| 3979 | // registers are defined to use, and since i64 is not legal. |
| 3980 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 3981 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3982 | SmallVector<SDValue, 8> Ops; |
| 3983 | for (unsigned i = 0; i < NumElts; ++i) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3984 | Ops.push_back(DAG.getNode(ISD::BITCAST, dl, EltVT, Op.getOperand(i))); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 3985 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 3986 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 3987 | } |
| 3988 | |
| 3989 | return SDValue(); |
| 3990 | } |
| 3991 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3992 | // Gather data to see if the operation can be modelled as a |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 3993 | // shuffle in combination with VEXTs. |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 3994 | SDValue ARMTargetLowering::ReconstructShuffle(SDValue Op, |
| 3995 | SelectionDAG &DAG) const { |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 3996 | DebugLoc dl = Op.getDebugLoc(); |
| 3997 | EVT VT = Op.getValueType(); |
| 3998 | unsigned NumElts = VT.getVectorNumElements(); |
| 3999 | |
| 4000 | SmallVector<SDValue, 2> SourceVecs; |
| 4001 | SmallVector<unsigned, 2> MinElts; |
| 4002 | SmallVector<unsigned, 2> MaxElts; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4003 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4004 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4005 | SDValue V = Op.getOperand(i); |
| 4006 | if (V.getOpcode() == ISD::UNDEF) |
| 4007 | continue; |
| 4008 | else if (V.getOpcode() != ISD::EXTRACT_VECTOR_ELT) { |
| 4009 | // A shuffle can only come from building a vector from various |
| 4010 | // elements of other vectors. |
| 4011 | return SDValue(); |
| 4012 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4013 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4014 | // Record this extraction against the appropriate vector if possible... |
| 4015 | SDValue SourceVec = V.getOperand(0); |
| 4016 | unsigned EltNo = cast<ConstantSDNode>(V.getOperand(1))->getZExtValue(); |
| 4017 | bool FoundSource = false; |
| 4018 | for (unsigned j = 0; j < SourceVecs.size(); ++j) { |
| 4019 | if (SourceVecs[j] == SourceVec) { |
| 4020 | if (MinElts[j] > EltNo) |
| 4021 | MinElts[j] = EltNo; |
| 4022 | if (MaxElts[j] < EltNo) |
| 4023 | MaxElts[j] = EltNo; |
| 4024 | FoundSource = true; |
| 4025 | break; |
| 4026 | } |
| 4027 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4028 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4029 | // Or record a new source if not... |
| 4030 | if (!FoundSource) { |
| 4031 | SourceVecs.push_back(SourceVec); |
| 4032 | MinElts.push_back(EltNo); |
| 4033 | MaxElts.push_back(EltNo); |
| 4034 | } |
| 4035 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4036 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4037 | // Currently only do something sane when at most two source vectors |
| 4038 | // involved. |
| 4039 | if (SourceVecs.size() > 2) |
| 4040 | return SDValue(); |
| 4041 | |
| 4042 | SDValue ShuffleSrcs[2] = {DAG.getUNDEF(VT), DAG.getUNDEF(VT) }; |
| 4043 | int VEXTOffsets[2] = {0, 0}; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4044 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4045 | // This loop extracts the usage patterns of the source vectors |
| 4046 | // and prepares appropriate SDValues for a shuffle if possible. |
| 4047 | for (unsigned i = 0; i < SourceVecs.size(); ++i) { |
| 4048 | if (SourceVecs[i].getValueType() == VT) { |
| 4049 | // No VEXT necessary |
| 4050 | ShuffleSrcs[i] = SourceVecs[i]; |
| 4051 | VEXTOffsets[i] = 0; |
| 4052 | continue; |
| 4053 | } else if (SourceVecs[i].getValueType().getVectorNumElements() < NumElts) { |
| 4054 | // It probably isn't worth padding out a smaller vector just to |
| 4055 | // break it down again in a shuffle. |
| 4056 | return SDValue(); |
| 4057 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4058 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4059 | // Since only 64-bit and 128-bit vectors are legal on ARM and |
| 4060 | // we've eliminated the other cases... |
Bob Wilson | 70f8573 | 2011-01-07 23:40:46 +0000 | [diff] [blame] | 4061 | assert(SourceVecs[i].getValueType().getVectorNumElements() == 2*NumElts && |
| 4062 | "unexpected vector sizes in ReconstructShuffle"); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4063 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4064 | if (MaxElts[i] - MinElts[i] >= NumElts) { |
| 4065 | // Span too large for a VEXT to cope |
| 4066 | return SDValue(); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4067 | } |
| 4068 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4069 | if (MinElts[i] >= NumElts) { |
| 4070 | // The extraction can just take the second half |
| 4071 | VEXTOffsets[i] = NumElts; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4072 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4073 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4074 | DAG.getIntPtrConstant(NumElts)); |
| 4075 | } else if (MaxElts[i] < NumElts) { |
| 4076 | // The extraction can just take the first half |
| 4077 | VEXTOffsets[i] = 0; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4078 | ShuffleSrcs[i] = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4079 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4080 | DAG.getIntPtrConstant(0)); |
| 4081 | } else { |
| 4082 | // An actual VEXT is needed |
| 4083 | VEXTOffsets[i] = MinElts[i]; |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4084 | SDValue VEXTSrc1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4085 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4086 | DAG.getIntPtrConstant(0)); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4087 | SDValue VEXTSrc2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, VT, |
| 4088 | SourceVecs[i], |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4089 | DAG.getIntPtrConstant(NumElts)); |
| 4090 | ShuffleSrcs[i] = DAG.getNode(ARMISD::VEXT, dl, VT, VEXTSrc1, VEXTSrc2, |
| 4091 | DAG.getConstant(VEXTOffsets[i], MVT::i32)); |
| 4092 | } |
| 4093 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4094 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4095 | SmallVector<int, 8> Mask; |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4096 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4097 | for (unsigned i = 0; i < NumElts; ++i) { |
| 4098 | SDValue Entry = Op.getOperand(i); |
| 4099 | if (Entry.getOpcode() == ISD::UNDEF) { |
| 4100 | Mask.push_back(-1); |
| 4101 | continue; |
| 4102 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4103 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4104 | SDValue ExtractVec = Entry.getOperand(0); |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4105 | int ExtractElt = cast<ConstantSDNode>(Op.getOperand(i) |
| 4106 | .getOperand(1))->getSExtValue(); |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4107 | if (ExtractVec == SourceVecs[0]) { |
| 4108 | Mask.push_back(ExtractElt - VEXTOffsets[0]); |
| 4109 | } else { |
| 4110 | Mask.push_back(ExtractElt + NumElts - VEXTOffsets[1]); |
| 4111 | } |
| 4112 | } |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4113 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4114 | // Final check before we try to produce nonsense... |
| 4115 | if (isShuffleMaskLegal(Mask, VT)) |
Eric Christopher | 41262da | 2011-01-14 23:50:53 +0000 | [diff] [blame] | 4116 | return DAG.getVectorShuffle(VT, dl, ShuffleSrcs[0], ShuffleSrcs[1], |
| 4117 | &Mask[0]); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 4118 | |
Bob Wilson | 11a1dff | 2011-01-07 21:37:30 +0000 | [diff] [blame] | 4119 | return SDValue(); |
| 4120 | } |
| 4121 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4122 | /// isShuffleMaskLegal - Targets can use this to indicate that they only |
| 4123 | /// support *some* VECTOR_SHUFFLE operations, those with specific masks. |
| 4124 | /// By default, if a target supports the VECTOR_SHUFFLE node, all mask values |
| 4125 | /// are assumed to be legal. |
| 4126 | bool |
| 4127 | ARMTargetLowering::isShuffleMaskLegal(const SmallVectorImpl<int> &M, |
| 4128 | EVT VT) const { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4129 | if (VT.getVectorNumElements() == 4 && |
| 4130 | (VT.is128BitVector() || VT.is64BitVector())) { |
| 4131 | unsigned PFIndexes[4]; |
| 4132 | for (unsigned i = 0; i != 4; ++i) { |
| 4133 | if (M[i] < 0) |
| 4134 | PFIndexes[i] = 8; |
| 4135 | else |
| 4136 | PFIndexes[i] = M[i]; |
| 4137 | } |
| 4138 | |
| 4139 | // Compute the index in the perfect shuffle table. |
| 4140 | unsigned PFTableIndex = |
| 4141 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
| 4142 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4143 | unsigned Cost = (PFEntry >> 30); |
| 4144 | |
| 4145 | if (Cost <= 4) |
| 4146 | return true; |
| 4147 | } |
| 4148 | |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4149 | bool ReverseVEXT; |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4150 | unsigned Imm, WhichResult; |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4151 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4152 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4153 | return (EltSize >= 32 || |
| 4154 | ShuffleVectorSDNode::isSplatMask(&M[0], VT) || |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4155 | isVREVMask(M, VT, 64) || |
| 4156 | isVREVMask(M, VT, 32) || |
| 4157 | isVREVMask(M, VT, 16) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4158 | isVEXTMask(M, VT, ReverseVEXT, Imm) || |
Bill Wendling | 0d4c9d9 | 2011-03-15 21:15:20 +0000 | [diff] [blame] | 4159 | isVTBLMask(M, VT) || |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4160 | isVTRNMask(M, VT, WhichResult) || |
| 4161 | isVUZPMask(M, VT, WhichResult) || |
Bob Wilson | 324f4f1 | 2009-12-03 06:40:55 +0000 | [diff] [blame] | 4162 | isVZIPMask(M, VT, WhichResult) || |
| 4163 | isVTRN_v_undef_Mask(M, VT, WhichResult) || |
| 4164 | isVUZP_v_undef_Mask(M, VT, WhichResult) || |
| 4165 | isVZIP_v_undef_Mask(M, VT, WhichResult)); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4166 | } |
| 4167 | |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4168 | /// GeneratePerfectShuffle - Given an entry in the perfect-shuffle table, emit |
| 4169 | /// the specified operations to build the shuffle. |
| 4170 | static SDValue GeneratePerfectShuffle(unsigned PFEntry, SDValue LHS, |
| 4171 | SDValue RHS, SelectionDAG &DAG, |
| 4172 | DebugLoc dl) { |
| 4173 | unsigned OpNum = (PFEntry >> 26) & 0x0F; |
| 4174 | unsigned LHSID = (PFEntry >> 13) & ((1 << 13)-1); |
| 4175 | unsigned RHSID = (PFEntry >> 0) & ((1 << 13)-1); |
| 4176 | |
| 4177 | enum { |
| 4178 | OP_COPY = 0, // Copy, used for things like <u,u,u,3> to say it is <0,1,2,3> |
| 4179 | OP_VREV, |
| 4180 | OP_VDUP0, |
| 4181 | OP_VDUP1, |
| 4182 | OP_VDUP2, |
| 4183 | OP_VDUP3, |
| 4184 | OP_VEXT1, |
| 4185 | OP_VEXT2, |
| 4186 | OP_VEXT3, |
| 4187 | OP_VUZPL, // VUZP, left result |
| 4188 | OP_VUZPR, // VUZP, right result |
| 4189 | OP_VZIPL, // VZIP, left result |
| 4190 | OP_VZIPR, // VZIP, right result |
| 4191 | OP_VTRNL, // VTRN, left result |
| 4192 | OP_VTRNR // VTRN, right result |
| 4193 | }; |
| 4194 | |
| 4195 | if (OpNum == OP_COPY) { |
| 4196 | if (LHSID == (1*9+2)*9+3) return LHS; |
| 4197 | assert(LHSID == ((4*9+5)*9+6)*9+7 && "Illegal OP_COPY!"); |
| 4198 | return RHS; |
| 4199 | } |
| 4200 | |
| 4201 | SDValue OpLHS, OpRHS; |
| 4202 | OpLHS = GeneratePerfectShuffle(PerfectShuffleTable[LHSID], LHS, RHS, DAG, dl); |
| 4203 | OpRHS = GeneratePerfectShuffle(PerfectShuffleTable[RHSID], LHS, RHS, DAG, dl); |
| 4204 | EVT VT = OpLHS.getValueType(); |
| 4205 | |
| 4206 | switch (OpNum) { |
| 4207 | default: llvm_unreachable("Unknown shuffle opcode!"); |
| 4208 | case OP_VREV: |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4209 | // VREV divides the vector in half and swaps within the half. |
Tanya Lattner | db28247 | 2011-05-18 21:44:54 +0000 | [diff] [blame] | 4210 | if (VT.getVectorElementType() == MVT::i32 || |
| 4211 | VT.getVectorElementType() == MVT::f32) |
Tanya Lattner | 2a8eb72 | 2011-05-18 06:42:21 +0000 | [diff] [blame] | 4212 | return DAG.getNode(ARMISD::VREV64, dl, VT, OpLHS); |
| 4213 | // vrev <4 x i16> -> VREV32 |
| 4214 | if (VT.getVectorElementType() == MVT::i16) |
| 4215 | return DAG.getNode(ARMISD::VREV32, dl, VT, OpLHS); |
| 4216 | // vrev <4 x i8> -> VREV16 |
| 4217 | assert(VT.getVectorElementType() == MVT::i8); |
| 4218 | return DAG.getNode(ARMISD::VREV16, dl, VT, OpLHS); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4219 | case OP_VDUP0: |
| 4220 | case OP_VDUP1: |
| 4221 | case OP_VDUP2: |
| 4222 | case OP_VDUP3: |
| 4223 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4224 | OpLHS, DAG.getConstant(OpNum-OP_VDUP0, MVT::i32)); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4225 | case OP_VEXT1: |
| 4226 | case OP_VEXT2: |
| 4227 | case OP_VEXT3: |
| 4228 | return DAG.getNode(ARMISD::VEXT, dl, VT, |
| 4229 | OpLHS, OpRHS, |
| 4230 | DAG.getConstant(OpNum-OP_VEXT1+1, MVT::i32)); |
| 4231 | case OP_VUZPL: |
| 4232 | case OP_VUZPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4233 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4234 | OpLHS, OpRHS).getValue(OpNum-OP_VUZPL); |
| 4235 | case OP_VZIPL: |
| 4236 | case OP_VZIPR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4237 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4238 | OpLHS, OpRHS).getValue(OpNum-OP_VZIPL); |
| 4239 | case OP_VTRNL: |
| 4240 | case OP_VTRNR: |
Anton Korobeynikov | 051cfd6 | 2009-08-21 12:41:42 +0000 | [diff] [blame] | 4241 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4242 | OpLHS, OpRHS).getValue(OpNum-OP_VTRNL); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4243 | } |
| 4244 | } |
| 4245 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4246 | static SDValue LowerVECTOR_SHUFFLEv8i8(SDValue Op, |
| 4247 | SmallVectorImpl<int> &ShuffleMask, |
| 4248 | SelectionDAG &DAG) { |
| 4249 | // Check to see if we can use the VTBL instruction. |
| 4250 | SDValue V1 = Op.getOperand(0); |
| 4251 | SDValue V2 = Op.getOperand(1); |
| 4252 | DebugLoc DL = Op.getDebugLoc(); |
| 4253 | |
| 4254 | SmallVector<SDValue, 8> VTBLMask; |
| 4255 | for (SmallVectorImpl<int>::iterator |
| 4256 | I = ShuffleMask.begin(), E = ShuffleMask.end(); I != E; ++I) |
| 4257 | VTBLMask.push_back(DAG.getConstant(*I, MVT::i32)); |
| 4258 | |
| 4259 | if (V2.getNode()->getOpcode() == ISD::UNDEF) |
| 4260 | return DAG.getNode(ARMISD::VTBL1, DL, MVT::v8i8, V1, |
| 4261 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4262 | &VTBLMask[0], 8)); |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4263 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4264 | return DAG.getNode(ARMISD::VTBL2, DL, MVT::v8i8, V1, V2, |
Bill Wendling | a24cb40 | 2011-03-15 20:47:26 +0000 | [diff] [blame] | 4265 | DAG.getNode(ISD::BUILD_VECTOR, DL, MVT::v8i8, |
| 4266 | &VTBLMask[0], 8)); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4267 | } |
| 4268 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4269 | static SDValue LowerVECTOR_SHUFFLE(SDValue Op, SelectionDAG &DAG) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4270 | SDValue V1 = Op.getOperand(0); |
| 4271 | SDValue V2 = Op.getOperand(1); |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4272 | DebugLoc dl = Op.getDebugLoc(); |
| 4273 | EVT VT = Op.getValueType(); |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4274 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(Op.getNode()); |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4275 | SmallVector<int, 8> ShuffleMask; |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4276 | |
Bob Wilson | 2886506 | 2009-08-13 02:13:04 +0000 | [diff] [blame] | 4277 | // Convert shuffles that are directly supported on NEON to target-specific |
| 4278 | // DAG nodes, instead of keeping them as shuffles and matching them again |
| 4279 | // during code selection. This is more efficient and avoids the possibility |
| 4280 | // of inconsistencies between legalization and selection. |
Bob Wilson | bfcbb50 | 2009-08-13 06:01:30 +0000 | [diff] [blame] | 4281 | // FIXME: floating-point vectors should be canonicalized to integer vectors |
| 4282 | // of the same time so that they get CSEd properly. |
Anton Korobeynikov | d0ac234 | 2009-08-21 12:40:07 +0000 | [diff] [blame] | 4283 | SVN->getMask(ShuffleMask); |
| 4284 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4285 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4286 | if (EltSize <= 32) { |
| 4287 | if (ShuffleVectorSDNode::isSplatMask(&ShuffleMask[0], VT)) { |
| 4288 | int Lane = SVN->getSplatIndex(); |
| 4289 | // If this is undef splat, generate it via "just" vdup, if possible. |
| 4290 | if (Lane == -1) Lane = 0; |
Anton Korobeynikov | 2ae0eec | 2009-11-02 00:12:06 +0000 | [diff] [blame] | 4291 | |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4292 | if (Lane == 0 && V1.getOpcode() == ISD::SCALAR_TO_VECTOR) { |
| 4293 | return DAG.getNode(ARMISD::VDUP, dl, VT, V1.getOperand(0)); |
| 4294 | } |
| 4295 | return DAG.getNode(ARMISD::VDUPLANE, dl, VT, V1, |
| 4296 | DAG.getConstant(Lane, MVT::i32)); |
Bob Wilson | c1d287b | 2009-08-14 05:13:08 +0000 | [diff] [blame] | 4297 | } |
Bob Wilson | 53dd245 | 2010-06-07 23:53:38 +0000 | [diff] [blame] | 4298 | |
| 4299 | bool ReverseVEXT; |
| 4300 | unsigned Imm; |
| 4301 | if (isVEXTMask(ShuffleMask, VT, ReverseVEXT, Imm)) { |
| 4302 | if (ReverseVEXT) |
| 4303 | std::swap(V1, V2); |
| 4304 | return DAG.getNode(ARMISD::VEXT, dl, VT, V1, V2, |
| 4305 | DAG.getConstant(Imm, MVT::i32)); |
| 4306 | } |
| 4307 | |
| 4308 | if (isVREVMask(ShuffleMask, VT, 64)) |
| 4309 | return DAG.getNode(ARMISD::VREV64, dl, VT, V1); |
| 4310 | if (isVREVMask(ShuffleMask, VT, 32)) |
| 4311 | return DAG.getNode(ARMISD::VREV32, dl, VT, V1); |
| 4312 | if (isVREVMask(ShuffleMask, VT, 16)) |
| 4313 | return DAG.getNode(ARMISD::VREV16, dl, VT, V1); |
| 4314 | |
| 4315 | // Check for Neon shuffles that modify both input vectors in place. |
| 4316 | // If both results are used, i.e., if there are two shuffles with the same |
| 4317 | // source operands and with masks corresponding to both results of one of |
| 4318 | // these operations, DAG memoization will ensure that a single node is |
| 4319 | // used for both shuffles. |
| 4320 | unsigned WhichResult; |
| 4321 | if (isVTRNMask(ShuffleMask, VT, WhichResult)) |
| 4322 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4323 | V1, V2).getValue(WhichResult); |
| 4324 | if (isVUZPMask(ShuffleMask, VT, WhichResult)) |
| 4325 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4326 | V1, V2).getValue(WhichResult); |
| 4327 | if (isVZIPMask(ShuffleMask, VT, WhichResult)) |
| 4328 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4329 | V1, V2).getValue(WhichResult); |
| 4330 | |
| 4331 | if (isVTRN_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4332 | return DAG.getNode(ARMISD::VTRN, dl, DAG.getVTList(VT, VT), |
| 4333 | V1, V1).getValue(WhichResult); |
| 4334 | if (isVUZP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4335 | return DAG.getNode(ARMISD::VUZP, dl, DAG.getVTList(VT, VT), |
| 4336 | V1, V1).getValue(WhichResult); |
| 4337 | if (isVZIP_v_undef_Mask(ShuffleMask, VT, WhichResult)) |
| 4338 | return DAG.getNode(ARMISD::VZIP, dl, DAG.getVTList(VT, VT), |
| 4339 | V1, V1).getValue(WhichResult); |
Bob Wilson | 0ce3710 | 2009-08-14 05:08:32 +0000 | [diff] [blame] | 4340 | } |
Bob Wilson | de95c1b8 | 2009-08-19 17:03:43 +0000 | [diff] [blame] | 4341 | |
Bob Wilson | c692cb7 | 2009-08-21 20:54:19 +0000 | [diff] [blame] | 4342 | // If the shuffle is not directly supported and it has 4 elements, use |
| 4343 | // the PerfectShuffle-generated table to synthesize it from other shuffles. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4344 | unsigned NumElts = VT.getVectorNumElements(); |
| 4345 | if (NumElts == 4) { |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4346 | unsigned PFIndexes[4]; |
| 4347 | for (unsigned i = 0; i != 4; ++i) { |
| 4348 | if (ShuffleMask[i] < 0) |
| 4349 | PFIndexes[i] = 8; |
| 4350 | else |
| 4351 | PFIndexes[i] = ShuffleMask[i]; |
| 4352 | } |
| 4353 | |
| 4354 | // Compute the index in the perfect shuffle table. |
| 4355 | unsigned PFTableIndex = |
| 4356 | PFIndexes[0]*9*9*9+PFIndexes[1]*9*9+PFIndexes[2]*9+PFIndexes[3]; |
Anton Korobeynikov | 1c8e581 | 2009-08-21 12:41:24 +0000 | [diff] [blame] | 4357 | unsigned PFEntry = PerfectShuffleTable[PFTableIndex]; |
| 4358 | unsigned Cost = (PFEntry >> 30); |
| 4359 | |
| 4360 | if (Cost <= 4) |
| 4361 | return GeneratePerfectShuffle(PFEntry, V1, V2, DAG, dl); |
| 4362 | } |
Bob Wilson | d8e1757 | 2009-08-12 22:31:50 +0000 | [diff] [blame] | 4363 | |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4364 | // Implement shuffles with 32- or 64-bit elements as ARMISD::BUILD_VECTORs. |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4365 | if (EltSize >= 32) { |
| 4366 | // Do the expansion with floating-point types, since that is what the VFP |
| 4367 | // registers are defined to use, and since i64 is not legal. |
| 4368 | EVT EltVT = EVT::getFloatingPointVT(EltSize); |
| 4369 | EVT VecVT = EVT::getVectorVT(*DAG.getContext(), EltVT, NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4370 | V1 = DAG.getNode(ISD::BITCAST, dl, VecVT, V1); |
| 4371 | V2 = DAG.getNode(ISD::BITCAST, dl, VecVT, V2); |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4372 | SmallVector<SDValue, 8> Ops; |
Bob Wilson | be751cf | 2010-05-22 00:23:12 +0000 | [diff] [blame] | 4373 | for (unsigned i = 0; i < NumElts; ++i) { |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4374 | if (ShuffleMask[i] < 0) |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4375 | Ops.push_back(DAG.getUNDEF(EltVT)); |
| 4376 | else |
| 4377 | Ops.push_back(DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, EltVT, |
| 4378 | ShuffleMask[i] < (int)NumElts ? V1 : V2, |
| 4379 | DAG.getConstant(ShuffleMask[i] & (NumElts-1), |
| 4380 | MVT::i32))); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4381 | } |
Bob Wilson | 40cbe7d | 2010-06-04 00:04:02 +0000 | [diff] [blame] | 4382 | SDValue Val = DAG.getNode(ARMISD::BUILD_VECTOR, dl, VecVT, &Ops[0],NumElts); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4383 | return DAG.getNode(ISD::BITCAST, dl, VT, Val); |
Bob Wilson | 63b8845 | 2010-05-20 18:39:53 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4386 | if (VT == MVT::v8i8) { |
| 4387 | SDValue NewOp = LowerVECTOR_SHUFFLEv8i8(Op, ShuffleMask, DAG); |
| 4388 | if (NewOp.getNode()) |
| 4389 | return NewOp; |
| 4390 | } |
| 4391 | |
Bob Wilson | 22cac0d | 2009-08-14 05:16:33 +0000 | [diff] [blame] | 4392 | return SDValue(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4395 | static SDValue LowerEXTRACT_VECTOR_ELT(SDValue Op, SelectionDAG &DAG) { |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4396 | // EXTRACT_VECTOR_ELT is legal only for immediate indexes. |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4397 | SDValue Lane = Op.getOperand(1); |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 4398 | if (!isa<ConstantSDNode>(Lane)) |
| 4399 | return SDValue(); |
| 4400 | |
| 4401 | SDValue Vec = Op.getOperand(0); |
| 4402 | if (Op.getValueType() == MVT::i32 && |
| 4403 | Vec.getValueType().getVectorElementType().getSizeInBits() < 32) { |
| 4404 | DebugLoc dl = Op.getDebugLoc(); |
| 4405 | return DAG.getNode(ARMISD::VGETLANEu, dl, MVT::i32, Vec, Lane); |
| 4406 | } |
| 4407 | |
| 4408 | return Op; |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4409 | } |
| 4410 | |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4411 | static SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) { |
| 4412 | // The only time a CONCAT_VECTORS operation can have legal types is when |
| 4413 | // two 64-bit vectors are concatenated to a 128-bit vector. |
| 4414 | assert(Op.getValueType().is128BitVector() && Op.getNumOperands() == 2 && |
| 4415 | "unexpected CONCAT_VECTORS"); |
| 4416 | DebugLoc dl = Op.getDebugLoc(); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4417 | SDValue Val = DAG.getUNDEF(MVT::v2f64); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4418 | SDValue Op0 = Op.getOperand(0); |
| 4419 | SDValue Op1 = Op.getOperand(1); |
| 4420 | if (Op0.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4421 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4422 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op0), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4423 | DAG.getIntPtrConstant(0)); |
| 4424 | if (Op1.getOpcode() != ISD::UNDEF) |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 4425 | Val = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, MVT::v2f64, Val, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4426 | DAG.getNode(ISD::BITCAST, dl, MVT::f64, Op1), |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4427 | DAG.getIntPtrConstant(1)); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4428 | return DAG.getNode(ISD::BITCAST, dl, Op.getValueType(), Val); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4429 | } |
| 4430 | |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4431 | /// isExtendedBUILD_VECTOR - Check if N is a constant BUILD_VECTOR where each |
| 4432 | /// element has been zero/sign-extended, depending on the isSigned parameter, |
| 4433 | /// from an integer type half its size. |
| 4434 | static bool isExtendedBUILD_VECTOR(SDNode *N, SelectionDAG &DAG, |
| 4435 | bool isSigned) { |
| 4436 | // A v2i64 BUILD_VECTOR will have been legalized to a BITCAST from v4i32. |
| 4437 | EVT VT = N->getValueType(0); |
| 4438 | if (VT == MVT::v2i64 && N->getOpcode() == ISD::BITCAST) { |
| 4439 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4440 | if (BVN->getValueType(0) != MVT::v4i32 || |
| 4441 | BVN->getOpcode() != ISD::BUILD_VECTOR) |
| 4442 | return false; |
| 4443 | unsigned LoElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4444 | unsigned HiElt = 1 - LoElt; |
| 4445 | ConstantSDNode *Lo0 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt)); |
| 4446 | ConstantSDNode *Hi0 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt)); |
| 4447 | ConstantSDNode *Lo1 = dyn_cast<ConstantSDNode>(BVN->getOperand(LoElt+2)); |
| 4448 | ConstantSDNode *Hi1 = dyn_cast<ConstantSDNode>(BVN->getOperand(HiElt+2)); |
| 4449 | if (!Lo0 || !Hi0 || !Lo1 || !Hi1) |
| 4450 | return false; |
| 4451 | if (isSigned) { |
| 4452 | if (Hi0->getSExtValue() == Lo0->getSExtValue() >> 32 && |
| 4453 | Hi1->getSExtValue() == Lo1->getSExtValue() >> 32) |
| 4454 | return true; |
| 4455 | } else { |
| 4456 | if (Hi0->isNullValue() && Hi1->isNullValue()) |
| 4457 | return true; |
| 4458 | } |
| 4459 | return false; |
| 4460 | } |
| 4461 | |
| 4462 | if (N->getOpcode() != ISD::BUILD_VECTOR) |
| 4463 | return false; |
| 4464 | |
| 4465 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) { |
| 4466 | SDNode *Elt = N->getOperand(i).getNode(); |
| 4467 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Elt)) { |
| 4468 | unsigned EltSize = VT.getVectorElementType().getSizeInBits(); |
| 4469 | unsigned HalfSize = EltSize / 2; |
| 4470 | if (isSigned) { |
| 4471 | int64_t SExtVal = C->getSExtValue(); |
| 4472 | if ((SExtVal >> HalfSize) != (SExtVal >> EltSize)) |
| 4473 | return false; |
| 4474 | } else { |
| 4475 | if ((C->getZExtValue() >> HalfSize) != 0) |
| 4476 | return false; |
| 4477 | } |
| 4478 | continue; |
| 4479 | } |
| 4480 | return false; |
| 4481 | } |
| 4482 | |
| 4483 | return true; |
| 4484 | } |
| 4485 | |
| 4486 | /// isSignExtended - Check if a node is a vector value that is sign-extended |
| 4487 | /// or a constant BUILD_VECTOR with sign-extended elements. |
| 4488 | static bool isSignExtended(SDNode *N, SelectionDAG &DAG) { |
| 4489 | if (N->getOpcode() == ISD::SIGN_EXTEND || ISD::isSEXTLoad(N)) |
| 4490 | return true; |
| 4491 | if (isExtendedBUILD_VECTOR(N, DAG, true)) |
| 4492 | return true; |
| 4493 | return false; |
| 4494 | } |
| 4495 | |
| 4496 | /// isZeroExtended - Check if a node is a vector value that is zero-extended |
| 4497 | /// or a constant BUILD_VECTOR with zero-extended elements. |
| 4498 | static bool isZeroExtended(SDNode *N, SelectionDAG &DAG) { |
| 4499 | if (N->getOpcode() == ISD::ZERO_EXTEND || ISD::isZEXTLoad(N)) |
| 4500 | return true; |
| 4501 | if (isExtendedBUILD_VECTOR(N, DAG, false)) |
| 4502 | return true; |
| 4503 | return false; |
| 4504 | } |
| 4505 | |
| 4506 | /// SkipExtension - For a node that is a SIGN_EXTEND, ZERO_EXTEND, extending |
| 4507 | /// load, or BUILD_VECTOR with extended elements, return the unextended value. |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4508 | static SDValue SkipExtension(SDNode *N, SelectionDAG &DAG) { |
| 4509 | if (N->getOpcode() == ISD::SIGN_EXTEND || N->getOpcode() == ISD::ZERO_EXTEND) |
| 4510 | return N->getOperand(0); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4511 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) |
| 4512 | return DAG.getLoad(LD->getMemoryVT(), N->getDebugLoc(), LD->getChain(), |
| 4513 | LD->getBasePtr(), LD->getPointerInfo(), LD->isVolatile(), |
| 4514 | LD->isNonTemporal(), LD->getAlignment()); |
| 4515 | // Otherwise, the value must be a BUILD_VECTOR. For v2i64, it will |
| 4516 | // have been legalized as a BITCAST from v4i32. |
| 4517 | if (N->getOpcode() == ISD::BITCAST) { |
| 4518 | SDNode *BVN = N->getOperand(0).getNode(); |
| 4519 | assert(BVN->getOpcode() == ISD::BUILD_VECTOR && |
| 4520 | BVN->getValueType(0) == MVT::v4i32 && "expected v4i32 BUILD_VECTOR"); |
| 4521 | unsigned LowElt = DAG.getTargetLoweringInfo().isBigEndian() ? 1 : 0; |
| 4522 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), MVT::v2i32, |
| 4523 | BVN->getOperand(LowElt), BVN->getOperand(LowElt+2)); |
| 4524 | } |
| 4525 | // Construct a new BUILD_VECTOR with elements truncated to half the size. |
| 4526 | assert(N->getOpcode() == ISD::BUILD_VECTOR && "expected BUILD_VECTOR"); |
| 4527 | EVT VT = N->getValueType(0); |
| 4528 | unsigned EltSize = VT.getVectorElementType().getSizeInBits() / 2; |
| 4529 | unsigned NumElts = VT.getVectorNumElements(); |
| 4530 | MVT TruncVT = MVT::getIntegerVT(EltSize); |
| 4531 | SmallVector<SDValue, 8> Ops; |
| 4532 | for (unsigned i = 0; i != NumElts; ++i) { |
| 4533 | ConstantSDNode *C = cast<ConstantSDNode>(N->getOperand(i)); |
| 4534 | const APInt &CInt = C->getAPIntValue(); |
Jay Foad | 40f8f62 | 2010-12-07 08:25:19 +0000 | [diff] [blame] | 4535 | Ops.push_back(DAG.getConstant(CInt.trunc(EltSize), TruncVT)); |
Bob Wilson | 626613d | 2010-11-23 19:38:38 +0000 | [diff] [blame] | 4536 | } |
| 4537 | return DAG.getNode(ISD::BUILD_VECTOR, N->getDebugLoc(), |
| 4538 | MVT::getVectorVT(TruncVT, NumElts), Ops.data(), NumElts); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4539 | } |
| 4540 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4541 | static bool isAddSubSExt(SDNode *N, SelectionDAG &DAG) { |
| 4542 | unsigned Opcode = N->getOpcode(); |
| 4543 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4544 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4545 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4546 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4547 | isSignExtended(N0, DAG) && isSignExtended(N1, DAG); |
| 4548 | } |
| 4549 | return false; |
| 4550 | } |
| 4551 | |
| 4552 | static bool isAddSubZExt(SDNode *N, SelectionDAG &DAG) { |
| 4553 | unsigned Opcode = N->getOpcode(); |
| 4554 | if (Opcode == ISD::ADD || Opcode == ISD::SUB) { |
| 4555 | SDNode *N0 = N->getOperand(0).getNode(); |
| 4556 | SDNode *N1 = N->getOperand(1).getNode(); |
| 4557 | return N0->hasOneUse() && N1->hasOneUse() && |
| 4558 | isZeroExtended(N0, DAG) && isZeroExtended(N1, DAG); |
| 4559 | } |
| 4560 | return false; |
| 4561 | } |
| 4562 | |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4563 | static SDValue LowerMUL(SDValue Op, SelectionDAG &DAG) { |
| 4564 | // Multiplications are only custom-lowered for 128-bit vectors so that |
| 4565 | // VMULL can be detected. Otherwise v2i64 multiplications are not legal. |
| 4566 | EVT VT = Op.getValueType(); |
| 4567 | assert(VT.is128BitVector() && "unexpected type for custom-lowering ISD::MUL"); |
| 4568 | SDNode *N0 = Op.getOperand(0).getNode(); |
| 4569 | SDNode *N1 = Op.getOperand(1).getNode(); |
| 4570 | unsigned NewOpc = 0; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4571 | bool isMLA = false; |
| 4572 | bool isN0SExt = isSignExtended(N0, DAG); |
| 4573 | bool isN1SExt = isSignExtended(N1, DAG); |
| 4574 | if (isN0SExt && isN1SExt) |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4575 | NewOpc = ARMISD::VMULLs; |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4576 | else { |
| 4577 | bool isN0ZExt = isZeroExtended(N0, DAG); |
| 4578 | bool isN1ZExt = isZeroExtended(N1, DAG); |
| 4579 | if (isN0ZExt && isN1ZExt) |
| 4580 | NewOpc = ARMISD::VMULLu; |
| 4581 | else if (isN1SExt || isN1ZExt) { |
| 4582 | // Look for (s/zext A + s/zext B) * (s/zext C). We want to turn these |
| 4583 | // into (s/zext A * s/zext C) + (s/zext B * s/zext C) |
| 4584 | if (isN1SExt && isAddSubSExt(N0, DAG)) { |
| 4585 | NewOpc = ARMISD::VMULLs; |
| 4586 | isMLA = true; |
| 4587 | } else if (isN1ZExt && isAddSubZExt(N0, DAG)) { |
| 4588 | NewOpc = ARMISD::VMULLu; |
| 4589 | isMLA = true; |
| 4590 | } else if (isN0ZExt && isAddSubZExt(N1, DAG)) { |
| 4591 | std::swap(N0, N1); |
| 4592 | NewOpc = ARMISD::VMULLu; |
| 4593 | isMLA = true; |
| 4594 | } |
| 4595 | } |
| 4596 | |
| 4597 | if (!NewOpc) { |
| 4598 | if (VT == MVT::v2i64) |
| 4599 | // Fall through to expand this. It is not legal. |
| 4600 | return SDValue(); |
| 4601 | else |
| 4602 | // Other vector multiplications are legal. |
| 4603 | return Op; |
| 4604 | } |
| 4605 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4606 | |
| 4607 | // Legalize to a VMULL instruction. |
| 4608 | DebugLoc DL = Op.getDebugLoc(); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4609 | SDValue Op0; |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4610 | SDValue Op1 = SkipExtension(N1, DAG); |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4611 | if (!isMLA) { |
| 4612 | Op0 = SkipExtension(N0, DAG); |
| 4613 | assert(Op0.getValueType().is64BitVector() && |
| 4614 | Op1.getValueType().is64BitVector() && |
| 4615 | "unexpected types for extended operands to VMULL"); |
| 4616 | return DAG.getNode(NewOpc, DL, VT, Op0, Op1); |
| 4617 | } |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4618 | |
Evan Cheng | 78fe9ab | 2011-03-29 01:56:09 +0000 | [diff] [blame] | 4619 | // Optimizing (zext A + zext B) * C, to (VMULL A, C) + (VMULL B, C) during |
| 4620 | // isel lowering to take advantage of no-stall back to back vmul + vmla. |
| 4621 | // vmull q0, d4, d6 |
| 4622 | // vmlal q0, d5, d6 |
| 4623 | // is faster than |
| 4624 | // vaddl q0, d4, d5 |
| 4625 | // vmovl q1, d6 |
| 4626 | // vmul q0, q0, q1 |
| 4627 | SDValue N00 = SkipExtension(N0->getOperand(0).getNode(), DAG); |
| 4628 | SDValue N01 = SkipExtension(N0->getOperand(1).getNode(), DAG); |
| 4629 | EVT Op1VT = Op1.getValueType(); |
| 4630 | return DAG.getNode(N0->getOpcode(), DL, VT, |
| 4631 | DAG.getNode(NewOpc, DL, VT, |
| 4632 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N00), Op1), |
| 4633 | DAG.getNode(NewOpc, DL, VT, |
| 4634 | DAG.getNode(ISD::BITCAST, DL, Op1VT, N01), Op1)); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4635 | } |
| 4636 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4637 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4638 | LowerSDIV_v4i8(SDValue X, SDValue Y, DebugLoc dl, SelectionDAG &DAG) { |
| 4639 | // Convert to float |
| 4640 | // float4 xf = vcvt_f32_s32(vmovl_s16(a.lo)); |
| 4641 | // float4 yf = vcvt_f32_s32(vmovl_s16(b.lo)); |
| 4642 | X = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, X); |
| 4643 | Y = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, Y); |
| 4644 | X = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, X); |
| 4645 | Y = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, Y); |
| 4646 | // Get reciprocal estimate. |
| 4647 | // float4 recip = vrecpeq_f32(yf); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4648 | Y = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4649 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), Y); |
| 4650 | // Because char has a smaller range than uchar, we can actually get away |
| 4651 | // without any newton steps. This requires that we use a weird bias |
| 4652 | // of 0xb000, however (again, this has been exhaustively tested). |
| 4653 | // float4 result = as_float4(as_int4(xf*recip) + 0xb000); |
| 4654 | X = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, X, Y); |
| 4655 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, X); |
| 4656 | Y = DAG.getConstant(0xb000, MVT::i32); |
| 4657 | Y = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, Y, Y, Y, Y); |
| 4658 | X = DAG.getNode(ISD::ADD, dl, MVT::v4i32, X, Y); |
| 4659 | X = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, X); |
| 4660 | // Convert back to short. |
| 4661 | X = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, X); |
| 4662 | X = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, X); |
| 4663 | return X; |
| 4664 | } |
| 4665 | |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4666 | static SDValue |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4667 | LowerSDIV_v4i16(SDValue N0, SDValue N1, DebugLoc dl, SelectionDAG &DAG) { |
| 4668 | SDValue N2; |
| 4669 | // Convert to float. |
| 4670 | // float4 yf = vcvt_f32_s32(vmovl_s16(y)); |
| 4671 | // float4 xf = vcvt_f32_s32(vmovl_s16(x)); |
| 4672 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N0); |
| 4673 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v4i32, N1); |
| 4674 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
| 4675 | N1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4676 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4677 | // Use reciprocal estimate and one refinement step. |
| 4678 | // float4 recip = vrecpeq_f32(yf); |
| 4679 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4680 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4681 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4682 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4683 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
| 4684 | N1, N2); |
| 4685 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4686 | // Because short has a smaller range than ushort, we can actually get away |
| 4687 | // with only a single newton step. This requires that we use a weird bias |
| 4688 | // of 89, however (again, this has been exhaustively tested). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4689 | // float4 result = as_float4(as_int4(xf*recip) + 0x89); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4690 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4691 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4692 | N1 = DAG.getConstant(0x89, MVT::i32); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4693 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4694 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4695 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4696 | // Convert back to integer and return. |
| 4697 | // return vmovn_s32(vcvt_s32_f32(result)); |
| 4698 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4699 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4700 | return N0; |
| 4701 | } |
| 4702 | |
| 4703 | static SDValue LowerSDIV(SDValue Op, SelectionDAG &DAG) { |
| 4704 | EVT VT = Op.getValueType(); |
| 4705 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4706 | "unexpected type for custom-lowering ISD::SDIV"); |
| 4707 | |
| 4708 | DebugLoc dl = Op.getDebugLoc(); |
| 4709 | SDValue N0 = Op.getOperand(0); |
| 4710 | SDValue N1 = Op.getOperand(1); |
| 4711 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4712 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4713 | if (VT == MVT::v8i8) { |
| 4714 | N0 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N0); |
| 4715 | N1 = DAG.getNode(ISD::SIGN_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4716 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4717 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4718 | DAG.getIntPtrConstant(4)); |
| 4719 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4720 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4721 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4722 | DAG.getIntPtrConstant(0)); |
| 4723 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4724 | DAG.getIntPtrConstant(0)); |
| 4725 | |
| 4726 | N0 = LowerSDIV_v4i8(N0, N1, dl, DAG); // v4i16 |
| 4727 | N2 = LowerSDIV_v4i8(N2, N3, dl, DAG); // v4i16 |
| 4728 | |
| 4729 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4730 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4731 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4732 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v8i8, N0); |
| 4733 | return N0; |
| 4734 | } |
| 4735 | return LowerSDIV_v4i16(N0, N1, dl, DAG); |
| 4736 | } |
| 4737 | |
| 4738 | static SDValue LowerUDIV(SDValue Op, SelectionDAG &DAG) { |
| 4739 | EVT VT = Op.getValueType(); |
| 4740 | assert((VT == MVT::v4i16 || VT == MVT::v8i8) && |
| 4741 | "unexpected type for custom-lowering ISD::UDIV"); |
| 4742 | |
| 4743 | DebugLoc dl = Op.getDebugLoc(); |
| 4744 | SDValue N0 = Op.getOperand(0); |
| 4745 | SDValue N1 = Op.getOperand(1); |
| 4746 | SDValue N2, N3; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4747 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4748 | if (VT == MVT::v8i8) { |
| 4749 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N0); |
| 4750 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v8i16, N1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4751 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4752 | N2 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4753 | DAG.getIntPtrConstant(4)); |
| 4754 | N3 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4755 | DAG.getIntPtrConstant(4)); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4756 | N0 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N0, |
| 4757 | DAG.getIntPtrConstant(0)); |
| 4758 | N1 = DAG.getNode(ISD::EXTRACT_SUBVECTOR, dl, MVT::v4i16, N1, |
| 4759 | DAG.getIntPtrConstant(0)); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4760 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4761 | N0 = LowerSDIV_v4i16(N0, N1, dl, DAG); // v4i16 |
| 4762 | N2 = LowerSDIV_v4i16(N2, N3, dl, DAG); // v4i16 |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4763 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4764 | N0 = DAG.getNode(ISD::CONCAT_VECTORS, dl, MVT::v8i16, N0, N2); |
| 4765 | N0 = LowerCONCAT_VECTORS(N0, DAG); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4766 | |
| 4767 | N0 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v8i8, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4768 | DAG.getConstant(Intrinsic::arm_neon_vqmovnsu, MVT::i32), |
| 4769 | N0); |
| 4770 | return N0; |
| 4771 | } |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4772 | |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4773 | // v4i16 sdiv ... Convert to float. |
| 4774 | // float4 yf = vcvt_f32_s32(vmovl_u16(y)); |
| 4775 | // float4 xf = vcvt_f32_s32(vmovl_u16(x)); |
| 4776 | N0 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N0); |
| 4777 | N1 = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::v4i32, N1); |
| 4778 | N0 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N0); |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4779 | SDValue BN1 = DAG.getNode(ISD::SINT_TO_FP, dl, MVT::v4f32, N1); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4780 | |
| 4781 | // Use reciprocal estimate and two refinement steps. |
| 4782 | // float4 recip = vrecpeq_f32(yf); |
| 4783 | // recip *= vrecpsq_f32(yf, recip); |
| 4784 | // recip *= vrecpsq_f32(yf, recip); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4785 | N2 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4786 | DAG.getConstant(Intrinsic::arm_neon_vrecpe, MVT::i32), BN1); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4787 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4788 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4789 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4790 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 4791 | N1 = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, dl, MVT::v4f32, |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4792 | DAG.getConstant(Intrinsic::arm_neon_vrecps, MVT::i32), |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4793 | BN1, N2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4794 | N2 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N1, N2); |
| 4795 | // Simply multiplying by the reciprocal estimate can leave us a few ulps |
| 4796 | // too low, so we add 2 ulps (exhaustive testing shows that this is enough, |
| 4797 | // and that it will never cause us to return an answer too large). |
Mon P Wang | 28e2b1d | 2011-05-19 04:15:07 +0000 | [diff] [blame] | 4798 | // float4 result = as_float4(as_int4(xf*recip) + 2); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4799 | N0 = DAG.getNode(ISD::FMUL, dl, MVT::v4f32, N0, N2); |
| 4800 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4i32, N0); |
| 4801 | N1 = DAG.getConstant(2, MVT::i32); |
| 4802 | N1 = DAG.getNode(ISD::BUILD_VECTOR, dl, MVT::v4i32, N1, N1, N1, N1); |
| 4803 | N0 = DAG.getNode(ISD::ADD, dl, MVT::v4i32, N0, N1); |
| 4804 | N0 = DAG.getNode(ISD::BITCAST, dl, MVT::v4f32, N0); |
| 4805 | // Convert back to integer and return. |
| 4806 | // return vmovn_u32(vcvt_s32_f32(result)); |
| 4807 | N0 = DAG.getNode(ISD::FP_TO_SINT, dl, MVT::v4i32, N0); |
| 4808 | N0 = DAG.getNode(ISD::TRUNCATE, dl, MVT::v4i16, N0); |
| 4809 | return N0; |
| 4810 | } |
| 4811 | |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4812 | SDValue ARMTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4813 | switch (Op.getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4814 | default: llvm_unreachable("Don't know how to custom lower this!"); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4815 | case ISD::ConstantPool: return LowerConstantPool(Op, DAG); |
Bob Wilson | ddb16df | 2009-10-30 05:45:42 +0000 | [diff] [blame] | 4816 | case ISD::BlockAddress: return LowerBlockAddress(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4817 | case ISD::GlobalAddress: |
| 4818 | return Subtarget->isTargetDarwin() ? LowerGlobalAddressDarwin(Op, DAG) : |
| 4819 | LowerGlobalAddressELF(Op, DAG); |
Bill Wendling | 69a05a7 | 2011-03-14 23:02:38 +0000 | [diff] [blame] | 4820 | case ISD::GlobalTLSAddress: return LowerGlobalTLSAddress(Op, DAG); |
Bill Wendling | de2b151 | 2010-08-11 08:43:16 +0000 | [diff] [blame] | 4821 | case ISD::SELECT: return LowerSELECT(Op, DAG); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4822 | case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG); |
| 4823 | case ISD::BR_CC: return LowerBR_CC(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4824 | case ISD::BR_JT: return LowerBR_JT(Op, DAG); |
Dan Gohman | 1e93df6 | 2010-04-17 14:41:14 +0000 | [diff] [blame] | 4825 | case ISD::VASTART: return LowerVASTART(Op, DAG); |
Jim Grosbach | 7c03dbd | 2009-12-14 21:24:16 +0000 | [diff] [blame] | 4826 | case ISD::MEMBARRIER: return LowerMEMBARRIER(Op, DAG, Subtarget); |
Eli Friedman | 1464846 | 2011-07-27 22:21:52 +0000 | [diff] [blame] | 4827 | case ISD::ATOMIC_FENCE: return LowerATOMIC_FENCE(Op, DAG, Subtarget); |
Evan Cheng | dfed19f | 2010-11-03 06:34:55 +0000 | [diff] [blame] | 4828 | case ISD::PREFETCH: return LowerPREFETCH(Op, DAG, Subtarget); |
Bob Wilson | 76a312b | 2010-03-19 22:51:32 +0000 | [diff] [blame] | 4829 | case ISD::SINT_TO_FP: |
| 4830 | case ISD::UINT_TO_FP: return LowerINT_TO_FP(Op, DAG); |
| 4831 | case ISD::FP_TO_SINT: |
| 4832 | case ISD::FP_TO_UINT: return LowerFP_TO_INT(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4833 | case ISD::FCOPYSIGN: return LowerFCOPYSIGN(Op, DAG); |
Evan Cheng | 2457f2c | 2010-05-22 01:47:14 +0000 | [diff] [blame] | 4834 | case ISD::RETURNADDR: return LowerRETURNADDR(Op, DAG); |
Jim Grosbach | 0e0da73 | 2009-05-12 23:59:14 +0000 | [diff] [blame] | 4835 | case ISD::FRAMEADDR: return LowerFRAMEADDR(Op, DAG); |
Lauro Ramos Venancio | 0ae4a33 | 2007-04-22 00:04:12 +0000 | [diff] [blame] | 4836 | case ISD::GLOBAL_OFFSET_TABLE: return LowerGLOBAL_OFFSET_TABLE(Op, DAG); |
Jim Grosbach | 23ff7cf | 2010-05-26 20:22:18 +0000 | [diff] [blame] | 4837 | case ISD::EH_SJLJ_SETJMP: return LowerEH_SJLJ_SETJMP(Op, DAG); |
Jim Grosbach | 5eb1951 | 2010-05-22 01:06:18 +0000 | [diff] [blame] | 4838 | case ISD::EH_SJLJ_LONGJMP: return LowerEH_SJLJ_LONGJMP(Op, DAG); |
Jim Grosbach | e4ad387 | 2010-10-19 23:27:08 +0000 | [diff] [blame] | 4839 | case ISD::EH_SJLJ_DISPATCHSETUP: return LowerEH_SJLJ_DISPATCHSETUP(Op, DAG); |
Jim Grosbach | a87ded2 | 2010-02-08 23:22:00 +0000 | [diff] [blame] | 4840 | case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG, |
| 4841 | Subtarget); |
Evan Cheng | 21a6179 | 2011-03-14 18:02:30 +0000 | [diff] [blame] | 4842 | case ISD::BITCAST: return ExpandBITCAST(Op.getNode(), DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4843 | case ISD::SHL: |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4844 | case ISD::SRL: |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4845 | case ISD::SRA: return LowerShift(Op.getNode(), DAG, Subtarget); |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4846 | case ISD::SHL_PARTS: return LowerShiftLeftParts(Op, DAG); |
Jim Grosbach | bcf2f2c | 2009-10-31 21:42:19 +0000 | [diff] [blame] | 4847 | case ISD::SRL_PARTS: |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 4848 | case ISD::SRA_PARTS: return LowerShiftRightParts(Op, DAG); |
Jim Grosbach | 3482c80 | 2010-01-18 19:58:49 +0000 | [diff] [blame] | 4849 | case ISD::CTTZ: return LowerCTTZ(Op.getNode(), DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4850 | case ISD::VSETCC: return LowerVSETCC(Op, DAG); |
Dale Johannesen | f630c71 | 2010-07-29 20:10:08 +0000 | [diff] [blame] | 4851 | case ISD::BUILD_VECTOR: return LowerBUILD_VECTOR(Op, DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4852 | case ISD::VECTOR_SHUFFLE: return LowerVECTOR_SHUFFLE(Op, DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 4853 | case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG); |
Bob Wilson | a6d6586 | 2009-08-03 20:36:38 +0000 | [diff] [blame] | 4854 | case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG); |
Bob Wilson | b31a11b | 2010-08-20 04:54:02 +0000 | [diff] [blame] | 4855 | case ISD::FLT_ROUNDS_: return LowerFLT_ROUNDS_(Op, DAG); |
Bob Wilson | d0b69cf | 2010-09-01 23:50:19 +0000 | [diff] [blame] | 4856 | case ISD::MUL: return LowerMUL(Op, DAG); |
Nate Begeman | 7973f35 | 2011-02-11 20:53:29 +0000 | [diff] [blame] | 4857 | case ISD::SDIV: return LowerSDIV(Op, DAG); |
| 4858 | case ISD::UDIV: return LowerUDIV(Op, DAG); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4859 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 4860 | return SDValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4861 | } |
| 4862 | |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4863 | /// ReplaceNodeResults - Replace the results of node with an illegal result |
| 4864 | /// type with new values built out of custom code. |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4865 | void ARMTargetLowering::ReplaceNodeResults(SDNode *N, |
| 4866 | SmallVectorImpl<SDValue>&Results, |
Dan Gohman | d858e90 | 2010-04-17 15:26:15 +0000 | [diff] [blame] | 4867 | SelectionDAG &DAG) const { |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4868 | SDValue Res; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4869 | switch (N->getOpcode()) { |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4870 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 4871 | llvm_unreachable("Don't know how to custom expand this!"); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4872 | break; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 4873 | case ISD::BITCAST: |
| 4874 | Res = ExpandBITCAST(N, DAG); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4875 | break; |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4876 | case ISD::SRL: |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4877 | case ISD::SRA: |
Bob Wilson | d5448bb | 2010-11-18 21:16:28 +0000 | [diff] [blame] | 4878 | Res = Expand64BitShift(N, DAG, Subtarget); |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4879 | break; |
Duncan Sands | 1607f05 | 2008-12-01 11:39:25 +0000 | [diff] [blame] | 4880 | } |
Bob Wilson | 164cd8b | 2010-04-14 20:45:23 +0000 | [diff] [blame] | 4881 | if (Res.getNode()) |
| 4882 | Results.push_back(Res); |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4883 | } |
Chris Lattner | 27a6c73 | 2007-11-24 07:07:01 +0000 | [diff] [blame] | 4884 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 4885 | //===----------------------------------------------------------------------===// |
| 4886 | // ARM Scheduler Hooks |
| 4887 | //===----------------------------------------------------------------------===// |
| 4888 | |
| 4889 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4890 | ARMTargetLowering::EmitAtomicCmpSwap(MachineInstr *MI, |
| 4891 | MachineBasicBlock *BB, |
| 4892 | unsigned Size) const { |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4893 | unsigned dest = MI->getOperand(0).getReg(); |
| 4894 | unsigned ptr = MI->getOperand(1).getReg(); |
| 4895 | unsigned oldval = MI->getOperand(2).getReg(); |
| 4896 | unsigned newval = MI->getOperand(3).getReg(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4897 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4898 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4899 | bool isThumb2 = Subtarget->isThumb2(); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4900 | |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4901 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 4902 | unsigned scratch = |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 4903 | MRI.createVirtualRegister(isThumb2 ? ARM::rGPRRegisterClass |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4904 | : ARM::GPRRegisterClass); |
| 4905 | |
| 4906 | if (isThumb2) { |
Cameron Zwarich | 141ec63 | 2011-05-18 02:29:50 +0000 | [diff] [blame] | 4907 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 4908 | MRI.constrainRegClass(oldval, ARM::rGPRRegisterClass); |
| 4909 | MRI.constrainRegClass(newval, ARM::rGPRRegisterClass); |
Cameron Zwarich | 7d336c0 | 2011-05-18 02:20:07 +0000 | [diff] [blame] | 4910 | } |
| 4911 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4912 | unsigned ldrOpc, strOpc; |
| 4913 | switch (Size) { |
| 4914 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4915 | case 1: |
| 4916 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Evan Cheng | aa26102 | 2011-02-07 18:50:47 +0000 | [diff] [blame] | 4917 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4918 | break; |
| 4919 | case 2: |
| 4920 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 4921 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 4922 | break; |
| 4923 | case 4: |
| 4924 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 4925 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 4926 | break; |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | MachineFunction *MF = BB->getParent(); |
| 4930 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 4931 | MachineFunction::iterator It = BB; |
| 4932 | ++It; // insert the new blocks after the current block |
| 4933 | |
| 4934 | MachineBasicBlock *loop1MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4935 | MachineBasicBlock *loop2MBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4936 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 4937 | MF->insert(It, loop1MBB); |
| 4938 | MF->insert(It, loop2MBB); |
| 4939 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4940 | |
| 4941 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 4942 | exitMBB->splice(exitMBB->begin(), BB, |
| 4943 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 4944 | BB->end()); |
| 4945 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4946 | |
| 4947 | // thisMBB: |
| 4948 | // ... |
| 4949 | // fallthrough --> loop1MBB |
| 4950 | BB->addSuccessor(loop1MBB); |
| 4951 | |
| 4952 | // loop1MBB: |
| 4953 | // ldrex dest, [ptr] |
| 4954 | // cmp dest, oldval |
| 4955 | // bne exitMBB |
| 4956 | BB = loop1MBB; |
| 4957 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4958 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4959 | .addReg(dest).addReg(oldval)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4960 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4961 | .addMBB(exitMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4962 | BB->addSuccessor(loop2MBB); |
| 4963 | BB->addSuccessor(exitMBB); |
| 4964 | |
| 4965 | // loop2MBB: |
| 4966 | // strex scratch, newval, [ptr] |
| 4967 | // cmp scratch, #0 |
| 4968 | // bne loop1MBB |
| 4969 | BB = loop2MBB; |
| 4970 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(newval) |
| 4971 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4972 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4973 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 4974 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 4975 | .addMBB(loop1MBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4976 | BB->addSuccessor(loop1MBB); |
| 4977 | BB->addSuccessor(exitMBB); |
| 4978 | |
| 4979 | // exitMBB: |
| 4980 | // ... |
| 4981 | BB = exitMBB; |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4982 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 4983 | MI->eraseFromParent(); // The instruction is gone now. |
Jim Grosbach | 5efaed3 | 2010-01-15 00:18:34 +0000 | [diff] [blame] | 4984 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 4985 | return BB; |
| 4986 | } |
| 4987 | |
| 4988 | MachineBasicBlock * |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 4989 | ARMTargetLowering::EmitAtomicBinary(MachineInstr *MI, MachineBasicBlock *BB, |
| 4990 | unsigned Size, unsigned BinOpcode) const { |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4991 | // This also handles ATOMIC_SWAP, indicated by BinOpcode==0. |
| 4992 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 4993 | |
| 4994 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 4995 | MachineFunction *MF = BB->getParent(); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 4996 | MachineFunction::iterator It = BB; |
| 4997 | ++It; |
| 4998 | |
| 4999 | unsigned dest = MI->getOperand(0).getReg(); |
| 5000 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5001 | unsigned incr = MI->getOperand(2).getReg(); |
| 5002 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5003 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5004 | |
| 5005 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5006 | if (isThumb2) { |
| 5007 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5008 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5009 | } |
| 5010 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5011 | unsigned ldrOpc, strOpc; |
| 5012 | switch (Size) { |
| 5013 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5014 | case 1: |
| 5015 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
Jakob Stoklund Olesen | 15913c9 | 2010-01-13 19:54:39 +0000 | [diff] [blame] | 5016 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5017 | break; |
| 5018 | case 2: |
| 5019 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5020 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
| 5021 | break; |
| 5022 | case 4: |
| 5023 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5024 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5025 | break; |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5026 | } |
| 5027 | |
Jim Grosbach | 867bbbf | 2010-01-15 00:22:18 +0000 | [diff] [blame] | 5028 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5029 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5030 | MF->insert(It, loopMBB); |
| 5031 | MF->insert(It, exitMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5032 | |
| 5033 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5034 | exitMBB->splice(exitMBB->begin(), BB, |
| 5035 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5036 | BB->end()); |
| 5037 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5038 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5039 | TargetRegisterClass *TRC = |
| 5040 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5041 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5042 | unsigned scratch2 = (!BinOpcode) ? incr : MRI.createVirtualRegister(TRC); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5043 | |
| 5044 | // thisMBB: |
| 5045 | // ... |
| 5046 | // fallthrough --> loopMBB |
| 5047 | BB->addSuccessor(loopMBB); |
| 5048 | |
| 5049 | // loopMBB: |
| 5050 | // ldrex dest, ptr |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5051 | // <binop> scratch2, dest, incr |
| 5052 | // strex scratch, scratch2, ptr |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5053 | // cmp scratch, #0 |
| 5054 | // bne- loopMBB |
| 5055 | // fallthrough --> exitMBB |
| 5056 | BB = loopMBB; |
| 5057 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
Jim Grosbach | c67b556 | 2009-12-15 00:12:35 +0000 | [diff] [blame] | 5058 | if (BinOpcode) { |
| 5059 | // operand order needs to go the other way for NAND |
| 5060 | if (BinOpcode == ARM::BICrr || BinOpcode == ARM::t2BICrr) |
| 5061 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5062 | addReg(incr).addReg(dest)).addReg(0); |
| 5063 | else |
| 5064 | AddDefaultPred(BuildMI(BB, dl, TII->get(BinOpcode), scratch2). |
| 5065 | addReg(dest).addReg(incr)).addReg(0); |
| 5066 | } |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5067 | |
| 5068 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 5069 | .addReg(ptr)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5070 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5071 | .addReg(scratch).addImm(0)); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5072 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5073 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5074 | |
| 5075 | BB->addSuccessor(loopMBB); |
| 5076 | BB->addSuccessor(exitMBB); |
| 5077 | |
| 5078 | // exitMBB: |
| 5079 | // ... |
| 5080 | BB = exitMBB; |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5081 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5082 | MI->eraseFromParent(); // The instruction is gone now. |
Evan Cheng | 102ebf1 | 2009-12-21 19:53:39 +0000 | [diff] [blame] | 5083 | |
Jim Grosbach | c3c2354 | 2009-12-14 04:22:04 +0000 | [diff] [blame] | 5084 | return BB; |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5087 | MachineBasicBlock * |
| 5088 | ARMTargetLowering::EmitAtomicBinaryMinMax(MachineInstr *MI, |
| 5089 | MachineBasicBlock *BB, |
| 5090 | unsigned Size, |
| 5091 | bool signExtend, |
| 5092 | ARMCC::CondCodes Cond) const { |
| 5093 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5094 | |
| 5095 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
| 5096 | MachineFunction *MF = BB->getParent(); |
| 5097 | MachineFunction::iterator It = BB; |
| 5098 | ++It; |
| 5099 | |
| 5100 | unsigned dest = MI->getOperand(0).getReg(); |
| 5101 | unsigned ptr = MI->getOperand(1).getReg(); |
| 5102 | unsigned incr = MI->getOperand(2).getReg(); |
| 5103 | unsigned oldval = dest; |
| 5104 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5105 | bool isThumb2 = Subtarget->isThumb2(); |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5106 | |
| 5107 | MachineRegisterInfo &MRI = BB->getParent()->getRegInfo(); |
| 5108 | if (isThumb2) { |
| 5109 | MRI.constrainRegClass(dest, ARM::rGPRRegisterClass); |
| 5110 | MRI.constrainRegClass(ptr, ARM::rGPRRegisterClass); |
| 5111 | } |
| 5112 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5113 | unsigned ldrOpc, strOpc, extendOpc; |
| 5114 | switch (Size) { |
| 5115 | default: llvm_unreachable("unsupported size for AtomicCmpSwap!"); |
| 5116 | case 1: |
| 5117 | ldrOpc = isThumb2 ? ARM::t2LDREXB : ARM::LDREXB; |
| 5118 | strOpc = isThumb2 ? ARM::t2STREXB : ARM::STREXB; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5119 | extendOpc = isThumb2 ? ARM::t2SXTB : ARM::SXTB; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5120 | break; |
| 5121 | case 2: |
| 5122 | ldrOpc = isThumb2 ? ARM::t2LDREXH : ARM::LDREXH; |
| 5123 | strOpc = isThumb2 ? ARM::t2STREXH : ARM::STREXH; |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5124 | extendOpc = isThumb2 ? ARM::t2SXTH : ARM::SXTH; |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5125 | break; |
| 5126 | case 4: |
| 5127 | ldrOpc = isThumb2 ? ARM::t2LDREX : ARM::LDREX; |
| 5128 | strOpc = isThumb2 ? ARM::t2STREX : ARM::STREX; |
| 5129 | extendOpc = 0; |
| 5130 | break; |
| 5131 | } |
| 5132 | |
| 5133 | MachineBasicBlock *loopMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5134 | MachineBasicBlock *exitMBB = MF->CreateMachineBasicBlock(LLVM_BB); |
| 5135 | MF->insert(It, loopMBB); |
| 5136 | MF->insert(It, exitMBB); |
| 5137 | |
| 5138 | // Transfer the remainder of BB and its successor edges to exitMBB. |
| 5139 | exitMBB->splice(exitMBB->begin(), BB, |
| 5140 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5141 | BB->end()); |
| 5142 | exitMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5143 | |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5144 | TargetRegisterClass *TRC = |
| 5145 | isThumb2 ? ARM::tGPRRegisterClass : ARM::GPRRegisterClass; |
| 5146 | unsigned scratch = MRI.createVirtualRegister(TRC); |
| 5147 | unsigned scratch2 = MRI.createVirtualRegister(TRC); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5148 | |
| 5149 | // thisMBB: |
| 5150 | // ... |
| 5151 | // fallthrough --> loopMBB |
| 5152 | BB->addSuccessor(loopMBB); |
| 5153 | |
| 5154 | // loopMBB: |
| 5155 | // ldrex dest, ptr |
| 5156 | // (sign extend dest, if required) |
| 5157 | // cmp dest, incr |
| 5158 | // cmov.cond scratch2, dest, incr |
| 5159 | // strex scratch, scratch2, ptr |
| 5160 | // cmp scratch, #0 |
| 5161 | // bne- loopMBB |
| 5162 | // fallthrough --> exitMBB |
| 5163 | BB = loopMBB; |
| 5164 | AddDefaultPred(BuildMI(BB, dl, TII->get(ldrOpc), dest).addReg(ptr)); |
| 5165 | |
| 5166 | // Sign extend the value, if necessary. |
| 5167 | if (signExtend && extendOpc) { |
Cameron Zwarich | de64aaf | 2011-05-27 23:54:00 +0000 | [diff] [blame] | 5168 | oldval = MRI.createVirtualRegister(ARM::GPRRegisterClass); |
Jim Grosbach | c5a8c86 | 2011-07-27 16:47:19 +0000 | [diff] [blame] | 5169 | AddDefaultPred(BuildMI(BB, dl, TII->get(extendOpc), oldval) |
| 5170 | .addReg(dest) |
| 5171 | .addImm(0)); |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5172 | } |
| 5173 | |
| 5174 | // Build compare and cmov instructions. |
| 5175 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5176 | .addReg(oldval).addReg(incr)); |
| 5177 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2MOVCCr : ARM::MOVCCr), scratch2) |
| 5178 | .addReg(oldval).addReg(incr).addImm(Cond).addReg(ARM::CPSR); |
| 5179 | |
| 5180 | AddDefaultPred(BuildMI(BB, dl, TII->get(strOpc), scratch).addReg(scratch2) |
| 5181 | .addReg(ptr)); |
| 5182 | AddDefaultPred(BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5183 | .addReg(scratch).addImm(0)); |
| 5184 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5185 | .addMBB(loopMBB).addImm(ARMCC::NE).addReg(ARM::CPSR); |
| 5186 | |
| 5187 | BB->addSuccessor(loopMBB); |
| 5188 | BB->addSuccessor(exitMBB); |
| 5189 | |
| 5190 | // exitMBB: |
| 5191 | // ... |
| 5192 | BB = exitMBB; |
| 5193 | |
| 5194 | MI->eraseFromParent(); // The instruction is gone now. |
| 5195 | |
| 5196 | return BB; |
| 5197 | } |
| 5198 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5199 | static |
| 5200 | MachineBasicBlock *OtherSucc(MachineBasicBlock *MBB, MachineBasicBlock *Succ) { |
| 5201 | for (MachineBasicBlock::succ_iterator I = MBB->succ_begin(), |
| 5202 | E = MBB->succ_end(); I != E; ++I) |
| 5203 | if (*I != Succ) |
| 5204 | return *I; |
| 5205 | llvm_unreachable("Expecting a BB with two successors!"); |
| 5206 | } |
| 5207 | |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5208 | // FIXME: This opcode table should obviously be expressed in the target |
| 5209 | // description. We probably just need a "machine opcode" value in the pseudo |
| 5210 | // instruction. But the ideal solution maybe to simply remove the "S" version |
| 5211 | // of the opcode altogether. |
| 5212 | struct AddSubFlagsOpcodePair { |
| 5213 | unsigned PseudoOpc; |
| 5214 | unsigned MachineOpc; |
| 5215 | }; |
| 5216 | |
| 5217 | static AddSubFlagsOpcodePair AddSubFlagsOpcodeMap[] = { |
| 5218 | {ARM::ADCSri, ARM::ADCri}, |
| 5219 | {ARM::ADCSrr, ARM::ADCrr}, |
Owen Anderson | 92a2022 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 5220 | {ARM::ADCSrsi, ARM::ADCrsi}, |
| 5221 | {ARM::ADCSrsr, ARM::ADCrsr}, |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5222 | {ARM::SBCSri, ARM::SBCri}, |
| 5223 | {ARM::SBCSrr, ARM::SBCrr}, |
Owen Anderson | 92a2022 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 5224 | {ARM::SBCSrsi, ARM::SBCrsi}, |
| 5225 | {ARM::SBCSrsr, ARM::SBCrsr}, |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5226 | {ARM::RSBSri, ARM::RSBri}, |
| 5227 | {ARM::RSBSrr, ARM::RSBrr}, |
Owen Anderson | 92a2022 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 5228 | {ARM::RSBSrsi, ARM::RSBrsi}, |
| 5229 | {ARM::RSBSrsr, ARM::RSBrsr}, |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5230 | {ARM::RSCSri, ARM::RSCri}, |
Owen Anderson | 92a2022 | 2011-07-21 18:54:16 +0000 | [diff] [blame] | 5231 | {ARM::RSCSrsi, ARM::RSCrsi}, |
| 5232 | {ARM::RSCSrsr, ARM::RSCrsr}, |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5233 | {ARM::t2ADCSri, ARM::t2ADCri}, |
| 5234 | {ARM::t2ADCSrr, ARM::t2ADCrr}, |
| 5235 | {ARM::t2ADCSrs, ARM::t2ADCrs}, |
| 5236 | {ARM::t2SBCSri, ARM::t2SBCri}, |
| 5237 | {ARM::t2SBCSrr, ARM::t2SBCrr}, |
| 5238 | {ARM::t2SBCSrs, ARM::t2SBCrs}, |
| 5239 | {ARM::t2RSBSri, ARM::t2RSBri}, |
| 5240 | {ARM::t2RSBSrs, ARM::t2RSBrs}, |
| 5241 | }; |
| 5242 | |
| 5243 | // Convert and Add or Subtract with Carry and Flags to a generic opcode with |
| 5244 | // CPSR<def> operand. e.g. ADCS (...) -> ADC (... CPSR<def>). |
| 5245 | // |
| 5246 | // FIXME: Somewhere we should assert that CPSR<def> is in the correct |
| 5247 | // position to be recognized by the target descrition as the 'S' bit. |
| 5248 | bool ARMTargetLowering::RemapAddSubWithFlags(MachineInstr *MI, |
| 5249 | MachineBasicBlock *BB) const { |
| 5250 | unsigned OldOpc = MI->getOpcode(); |
| 5251 | unsigned NewOpc = 0; |
| 5252 | |
| 5253 | // This is only called for instructions that need remapping, so iterating over |
| 5254 | // the tiny opcode table is not costly. |
| 5255 | static const int NPairs = |
| 5256 | sizeof(AddSubFlagsOpcodeMap) / sizeof(AddSubFlagsOpcodePair); |
| 5257 | for (AddSubFlagsOpcodePair *Pair = &AddSubFlagsOpcodeMap[0], |
| 5258 | *End = &AddSubFlagsOpcodeMap[NPairs]; Pair != End; ++Pair) { |
| 5259 | if (OldOpc == Pair->PseudoOpc) { |
| 5260 | NewOpc = Pair->MachineOpc; |
| 5261 | break; |
| 5262 | } |
| 5263 | } |
| 5264 | if (!NewOpc) |
| 5265 | return false; |
| 5266 | |
| 5267 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
| 5268 | DebugLoc dl = MI->getDebugLoc(); |
| 5269 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 5270 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 5271 | MIB.addOperand(MI->getOperand(i)); |
| 5272 | AddDefaultPred(MIB); |
| 5273 | MIB.addReg(ARM::CPSR, RegState::Define); // S bit |
| 5274 | MI->eraseFromParent(); |
| 5275 | return true; |
| 5276 | } |
| 5277 | |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5278 | MachineBasicBlock * |
Evan Cheng | ff9b373 | 2008-01-30 18:18:23 +0000 | [diff] [blame] | 5279 | ARMTargetLowering::EmitInstrWithCustomInserter(MachineInstr *MI, |
Dan Gohman | af1d8ca | 2010-05-01 00:01:06 +0000 | [diff] [blame] | 5280 | MachineBasicBlock *BB) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5281 | const TargetInstrInfo *TII = getTargetMachine().getInstrInfo(); |
Dale Johannesen | b672840 | 2009-02-13 02:25:56 +0000 | [diff] [blame] | 5282 | DebugLoc dl = MI->getDebugLoc(); |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5283 | bool isThumb2 = Subtarget->isThumb2(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5284 | switch (MI->getOpcode()) { |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5285 | default: { |
| 5286 | if (RemapAddSubWithFlags(MI, BB)) |
| 5287 | return BB; |
| 5288 | |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5289 | MI->dump(); |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 5290 | llvm_unreachable("Unexpected instr type to insert"); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5291 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 5292 | case ARM::STRi_preidx: |
| 5293 | case ARM::STRBi_preidx: { |
Jim Grosbach | 6cd5716 | 2011-08-09 21:22:41 +0000 | [diff] [blame] | 5294 | unsigned NewOpc = MI->getOpcode() == ARM::STRi_preidx ? |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 5295 | ARM::STR_PRE_IMM : ARM::STRB_PRE_IMM; |
| 5296 | // Decode the offset. |
| 5297 | unsigned Offset = MI->getOperand(4).getImm(); |
| 5298 | bool isSub = ARM_AM::getAM2Op(Offset) == ARM_AM::sub; |
| 5299 | Offset = ARM_AM::getAM2Offset(Offset); |
| 5300 | if (isSub) |
| 5301 | Offset = -Offset; |
| 5302 | |
| 5303 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)) |
| 5304 | .addOperand(MI->getOperand(0)) // Rn_wb |
| 5305 | .addOperand(MI->getOperand(1)) // Rt |
| 5306 | .addOperand(MI->getOperand(2)) // Rn |
| 5307 | .addImm(Offset) // offset (skip GPR==zero_reg) |
| 5308 | .addOperand(MI->getOperand(5)) // pred |
| 5309 | .addOperand(MI->getOperand(6)); |
| 5310 | MI->eraseFromParent(); |
| 5311 | return BB; |
| 5312 | } |
| 5313 | case ARM::STRr_preidx: |
Jim Grosbach | 7b8f46c | 2011-08-11 21:17:22 +0000 | [diff] [blame] | 5314 | case ARM::STRBr_preidx: |
| 5315 | case ARM::STRH_preidx: { |
| 5316 | unsigned NewOpc; |
| 5317 | switch (MI->getOpcode()) { |
| 5318 | default: llvm_unreachable("unexpected opcode!"); |
| 5319 | case ARM::STRr_preidx: NewOpc = ARM::STR_PRE_REG; break; |
| 5320 | case ARM::STRBr_preidx: NewOpc = ARM::STRB_PRE_REG; break; |
| 5321 | case ARM::STRH_preidx: NewOpc = ARM::STRH_PRE; break; |
| 5322 | } |
Jim Grosbach | 19dec20 | 2011-08-05 20:35:44 +0000 | [diff] [blame] | 5323 | MachineInstrBuilder MIB = BuildMI(*BB, MI, dl, TII->get(NewOpc)); |
| 5324 | for (unsigned i = 0; i < MI->getNumOperands(); ++i) |
| 5325 | MIB.addOperand(MI->getOperand(i)); |
| 5326 | MI->eraseFromParent(); |
| 5327 | return BB; |
| 5328 | } |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5329 | case ARM::ATOMIC_LOAD_ADD_I8: |
| 5330 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 5331 | case ARM::ATOMIC_LOAD_ADD_I16: |
| 5332 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
| 5333 | case ARM::ATOMIC_LOAD_ADD_I32: |
| 5334 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ADDrr : ARM::ADDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5335 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5336 | case ARM::ATOMIC_LOAD_AND_I8: |
| 5337 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 5338 | case ARM::ATOMIC_LOAD_AND_I16: |
| 5339 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
| 5340 | case ARM::ATOMIC_LOAD_AND_I32: |
| 5341 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ANDrr : ARM::ANDrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5342 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5343 | case ARM::ATOMIC_LOAD_OR_I8: |
| 5344 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 5345 | case ARM::ATOMIC_LOAD_OR_I16: |
| 5346 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
| 5347 | case ARM::ATOMIC_LOAD_OR_I32: |
| 5348 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2ORRrr : ARM::ORRrr); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5349 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5350 | case ARM::ATOMIC_LOAD_XOR_I8: |
| 5351 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 5352 | case ARM::ATOMIC_LOAD_XOR_I16: |
| 5353 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
| 5354 | case ARM::ATOMIC_LOAD_XOR_I32: |
| 5355 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2EORrr : ARM::EORrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5356 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5357 | case ARM::ATOMIC_LOAD_NAND_I8: |
| 5358 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 5359 | case ARM::ATOMIC_LOAD_NAND_I16: |
| 5360 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
| 5361 | case ARM::ATOMIC_LOAD_NAND_I32: |
| 5362 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2BICrr : ARM::BICrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5363 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5364 | case ARM::ATOMIC_LOAD_SUB_I8: |
| 5365 | return EmitAtomicBinary(MI, BB, 1, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5366 | case ARM::ATOMIC_LOAD_SUB_I16: |
| 5367 | return EmitAtomicBinary(MI, BB, 2, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
| 5368 | case ARM::ATOMIC_LOAD_SUB_I32: |
| 5369 | return EmitAtomicBinary(MI, BB, 4, isThumb2 ? ARM::t2SUBrr : ARM::SUBrr); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5370 | |
Jim Grosbach | f7da882 | 2011-04-26 19:44:18 +0000 | [diff] [blame] | 5371 | case ARM::ATOMIC_LOAD_MIN_I8: |
| 5372 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::LT); |
| 5373 | case ARM::ATOMIC_LOAD_MIN_I16: |
| 5374 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::LT); |
| 5375 | case ARM::ATOMIC_LOAD_MIN_I32: |
| 5376 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::LT); |
| 5377 | |
| 5378 | case ARM::ATOMIC_LOAD_MAX_I8: |
| 5379 | return EmitAtomicBinaryMinMax(MI, BB, 1, true, ARMCC::GT); |
| 5380 | case ARM::ATOMIC_LOAD_MAX_I16: |
| 5381 | return EmitAtomicBinaryMinMax(MI, BB, 2, true, ARMCC::GT); |
| 5382 | case ARM::ATOMIC_LOAD_MAX_I32: |
| 5383 | return EmitAtomicBinaryMinMax(MI, BB, 4, true, ARMCC::GT); |
| 5384 | |
| 5385 | case ARM::ATOMIC_LOAD_UMIN_I8: |
| 5386 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::LO); |
| 5387 | case ARM::ATOMIC_LOAD_UMIN_I16: |
| 5388 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::LO); |
| 5389 | case ARM::ATOMIC_LOAD_UMIN_I32: |
| 5390 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::LO); |
| 5391 | |
| 5392 | case ARM::ATOMIC_LOAD_UMAX_I8: |
| 5393 | return EmitAtomicBinaryMinMax(MI, BB, 1, false, ARMCC::HI); |
| 5394 | case ARM::ATOMIC_LOAD_UMAX_I16: |
| 5395 | return EmitAtomicBinaryMinMax(MI, BB, 2, false, ARMCC::HI); |
| 5396 | case ARM::ATOMIC_LOAD_UMAX_I32: |
| 5397 | return EmitAtomicBinaryMinMax(MI, BB, 4, false, ARMCC::HI); |
| 5398 | |
Jim Grosbach | a36c8f2 | 2009-12-14 20:14:59 +0000 | [diff] [blame] | 5399 | case ARM::ATOMIC_SWAP_I8: return EmitAtomicBinary(MI, BB, 1, 0); |
| 5400 | case ARM::ATOMIC_SWAP_I16: return EmitAtomicBinary(MI, BB, 2, 0); |
| 5401 | case ARM::ATOMIC_SWAP_I32: return EmitAtomicBinary(MI, BB, 4, 0); |
Jim Grosbach | e801dc4 | 2009-12-12 01:40:06 +0000 | [diff] [blame] | 5402 | |
| 5403 | case ARM::ATOMIC_CMP_SWAP_I8: return EmitAtomicCmpSwap(MI, BB, 1); |
| 5404 | case ARM::ATOMIC_CMP_SWAP_I16: return EmitAtomicCmpSwap(MI, BB, 2); |
| 5405 | case ARM::ATOMIC_CMP_SWAP_I32: return EmitAtomicCmpSwap(MI, BB, 4); |
Jim Grosbach | 5278eb8 | 2009-12-11 01:42:04 +0000 | [diff] [blame] | 5406 | |
Evan Cheng | 007ea27 | 2009-08-12 05:17:19 +0000 | [diff] [blame] | 5407 | case ARM::tMOVCCr_pseudo: { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5408 | // To "insert" a SELECT_CC instruction, we actually have to insert the |
| 5409 | // diamond control-flow pattern. The incoming instruction knows the |
| 5410 | // destination vreg to set, the condition code register to branch on, the |
| 5411 | // true/false values to select between, and a branch opcode to use. |
| 5412 | const BasicBlock *LLVM_BB = BB->getBasicBlock(); |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5413 | MachineFunction::iterator It = BB; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5414 | ++It; |
| 5415 | |
| 5416 | // thisMBB: |
| 5417 | // ... |
| 5418 | // TrueVal = ... |
| 5419 | // cmpTY ccX, r1, r2 |
| 5420 | // bCC copy1MBB |
| 5421 | // fallthrough --> copy0MBB |
| 5422 | MachineBasicBlock *thisMBB = BB; |
Dan Gohman | 8e5f2c6 | 2008-07-07 23:14:23 +0000 | [diff] [blame] | 5423 | MachineFunction *F = BB->getParent(); |
| 5424 | MachineBasicBlock *copy0MBB = F->CreateMachineBasicBlock(LLVM_BB); |
| 5425 | MachineBasicBlock *sinkMBB = F->CreateMachineBasicBlock(LLVM_BB); |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5426 | F->insert(It, copy0MBB); |
| 5427 | F->insert(It, sinkMBB); |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5428 | |
| 5429 | // Transfer the remainder of BB and its successor edges to sinkMBB. |
| 5430 | sinkMBB->splice(sinkMBB->begin(), BB, |
| 5431 | llvm::next(MachineBasicBlock::iterator(MI)), |
| 5432 | BB->end()); |
| 5433 | sinkMBB->transferSuccessorsAndUpdatePHIs(BB); |
| 5434 | |
Dan Gohman | 258c58c | 2010-07-06 15:49:48 +0000 | [diff] [blame] | 5435 | BB->addSuccessor(copy0MBB); |
| 5436 | BB->addSuccessor(sinkMBB); |
Dan Gohman | b81c771 | 2010-07-06 15:18:19 +0000 | [diff] [blame] | 5437 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5438 | BuildMI(BB, dl, TII->get(ARM::tBcc)).addMBB(sinkMBB) |
| 5439 | .addImm(MI->getOperand(3).getImm()).addReg(MI->getOperand(4).getReg()); |
| 5440 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5441 | // copy0MBB: |
| 5442 | // %FalseValue = ... |
| 5443 | // # fallthrough to sinkMBB |
| 5444 | BB = copy0MBB; |
| 5445 | |
| 5446 | // Update machine-CFG edges |
| 5447 | BB->addSuccessor(sinkMBB); |
| 5448 | |
| 5449 | // sinkMBB: |
| 5450 | // %Result = phi [ %FalseValue, copy0MBB ], [ %TrueValue, thisMBB ] |
| 5451 | // ... |
| 5452 | BB = sinkMBB; |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5453 | BuildMI(*BB, BB->begin(), dl, |
| 5454 | TII->get(ARM::PHI), MI->getOperand(0).getReg()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5455 | .addReg(MI->getOperand(1).getReg()).addMBB(copy0MBB) |
| 5456 | .addReg(MI->getOperand(2).getReg()).addMBB(thisMBB); |
| 5457 | |
Dan Gohman | 14152b4 | 2010-07-06 20:24:04 +0000 | [diff] [blame] | 5458 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5459 | return BB; |
| 5460 | } |
Evan Cheng | 8619864 | 2009-08-07 00:34:42 +0000 | [diff] [blame] | 5461 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5462 | case ARM::BCCi64: |
| 5463 | case ARM::BCCZi64: { |
Bob Wilson | 3c90469 | 2010-12-23 22:45:49 +0000 | [diff] [blame] | 5464 | // If there is an unconditional branch to the other successor, remove it. |
| 5465 | BB->erase(llvm::next(MachineBasicBlock::iterator(MI)), BB->end()); |
Andrew Trick | 7fa75ce | 2011-01-19 02:26:13 +0000 | [diff] [blame] | 5466 | |
Evan Cheng | 218977b | 2010-07-13 19:27:42 +0000 | [diff] [blame] | 5467 | // Compare both parts that make up the double comparison separately for |
| 5468 | // equality. |
| 5469 | bool RHSisZero = MI->getOpcode() == ARM::BCCZi64; |
| 5470 | |
| 5471 | unsigned LHS1 = MI->getOperand(1).getReg(); |
| 5472 | unsigned LHS2 = MI->getOperand(2).getReg(); |
| 5473 | if (RHSisZero) { |
| 5474 | AddDefaultPred(BuildMI(BB, dl, |
| 5475 | TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5476 | .addReg(LHS1).addImm(0)); |
| 5477 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPri : ARM::CMPri)) |
| 5478 | .addReg(LHS2).addImm(0) |
| 5479 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5480 | } else { |
| 5481 | unsigned RHS1 = MI->getOperand(3).getReg(); |
| 5482 | unsigned RHS2 = MI->getOperand(4).getReg(); |
| 5483 | AddDefaultPred(BuildMI(BB, dl, |
| 5484 | TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5485 | .addReg(LHS1).addReg(RHS1)); |
| 5486 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2CMPrr : ARM::CMPrr)) |
| 5487 | .addReg(LHS2).addReg(RHS2) |
| 5488 | .addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5489 | } |
| 5490 | |
| 5491 | MachineBasicBlock *destMBB = MI->getOperand(RHSisZero ? 3 : 5).getMBB(); |
| 5492 | MachineBasicBlock *exitMBB = OtherSucc(BB, destMBB); |
| 5493 | if (MI->getOperand(0).getImm() == ARMCC::NE) |
| 5494 | std::swap(destMBB, exitMBB); |
| 5495 | |
| 5496 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2Bcc : ARM::Bcc)) |
| 5497 | .addMBB(destMBB).addImm(ARMCC::EQ).addReg(ARM::CPSR); |
| 5498 | BuildMI(BB, dl, TII->get(isThumb2 ? ARM::t2B : ARM::B)) |
| 5499 | .addMBB(exitMBB); |
| 5500 | |
| 5501 | MI->eraseFromParent(); // The pseudo instruction is gone now. |
| 5502 | return BB; |
| 5503 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 5504 | } |
| 5505 | } |
| 5506 | |
| 5507 | //===----------------------------------------------------------------------===// |
| 5508 | // ARM Optimization Hooks |
| 5509 | //===----------------------------------------------------------------------===// |
| 5510 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5511 | static |
| 5512 | SDValue combineSelectAndUse(SDNode *N, SDValue Slct, SDValue OtherOp, |
| 5513 | TargetLowering::DAGCombinerInfo &DCI) { |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5514 | SelectionDAG &DAG = DCI.DAG; |
| 5515 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5516 | EVT VT = N->getValueType(0); |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5517 | unsigned Opc = N->getOpcode(); |
| 5518 | bool isSlctCC = Slct.getOpcode() == ISD::SELECT_CC; |
| 5519 | SDValue LHS = isSlctCC ? Slct.getOperand(2) : Slct.getOperand(1); |
| 5520 | SDValue RHS = isSlctCC ? Slct.getOperand(3) : Slct.getOperand(2); |
| 5521 | ISD::CondCode CC = ISD::SETCC_INVALID; |
| 5522 | |
| 5523 | if (isSlctCC) { |
| 5524 | CC = cast<CondCodeSDNode>(Slct.getOperand(4))->get(); |
| 5525 | } else { |
| 5526 | SDValue CCOp = Slct.getOperand(0); |
| 5527 | if (CCOp.getOpcode() == ISD::SETCC) |
| 5528 | CC = cast<CondCodeSDNode>(CCOp.getOperand(2))->get(); |
| 5529 | } |
| 5530 | |
| 5531 | bool DoXform = false; |
| 5532 | bool InvCC = false; |
| 5533 | assert ((Opc == ISD::ADD || (Opc == ISD::SUB && Slct == N->getOperand(1))) && |
| 5534 | "Bad input!"); |
| 5535 | |
| 5536 | if (LHS.getOpcode() == ISD::Constant && |
| 5537 | cast<ConstantSDNode>(LHS)->isNullValue()) { |
| 5538 | DoXform = true; |
| 5539 | } else if (CC != ISD::SETCC_INVALID && |
| 5540 | RHS.getOpcode() == ISD::Constant && |
| 5541 | cast<ConstantSDNode>(RHS)->isNullValue()) { |
| 5542 | std::swap(LHS, RHS); |
| 5543 | SDValue Op0 = Slct.getOperand(0); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 5544 | EVT OpVT = isSlctCC ? Op0.getValueType() : |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5545 | Op0.getOperand(0).getValueType(); |
| 5546 | bool isInt = OpVT.isInteger(); |
| 5547 | CC = ISD::getSetCCInverse(CC, isInt); |
| 5548 | |
| 5549 | if (!TLI.isCondCodeLegal(CC, OpVT)) |
| 5550 | return SDValue(); // Inverse operator isn't legal. |
| 5551 | |
| 5552 | DoXform = true; |
| 5553 | InvCC = true; |
| 5554 | } |
| 5555 | |
| 5556 | if (DoXform) { |
| 5557 | SDValue Result = DAG.getNode(Opc, RHS.getDebugLoc(), VT, OtherOp, RHS); |
| 5558 | if (isSlctCC) |
| 5559 | return DAG.getSelectCC(N->getDebugLoc(), OtherOp, Result, |
| 5560 | Slct.getOperand(0), Slct.getOperand(1), CC); |
| 5561 | SDValue CCOp = Slct.getOperand(0); |
| 5562 | if (InvCC) |
| 5563 | CCOp = DAG.getSetCC(Slct.getDebugLoc(), CCOp.getValueType(), |
| 5564 | CCOp.getOperand(0), CCOp.getOperand(1), CC); |
| 5565 | return DAG.getNode(ISD::SELECT, N->getDebugLoc(), VT, |
| 5566 | CCOp, OtherOp, Result); |
| 5567 | } |
| 5568 | return SDValue(); |
| 5569 | } |
| 5570 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5571 | // AddCombineToVPADDL- For pair-wise add on neon, use the vpaddl instruction |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5572 | // (only after legalization). |
| 5573 | static SDValue AddCombineToVPADDL(SDNode *N, SDValue N0, SDValue N1, |
| 5574 | TargetLowering::DAGCombinerInfo &DCI, |
| 5575 | const ARMSubtarget *Subtarget) { |
| 5576 | |
| 5577 | // Only perform optimization if after legalize, and if NEON is available. We |
| 5578 | // also expected both operands to be BUILD_VECTORs. |
| 5579 | if (DCI.isBeforeLegalize() || !Subtarget->hasNEON() |
| 5580 | || N0.getOpcode() != ISD::BUILD_VECTOR |
| 5581 | || N1.getOpcode() != ISD::BUILD_VECTOR) |
| 5582 | return SDValue(); |
| 5583 | |
| 5584 | // Check output type since VPADDL operand elements can only be 8, 16, or 32. |
| 5585 | EVT VT = N->getValueType(0); |
| 5586 | if (!VT.isInteger() || VT.getVectorElementType() == MVT::i64) |
| 5587 | return SDValue(); |
| 5588 | |
| 5589 | // Check that the vector operands are of the right form. |
| 5590 | // N0 and N1 are BUILD_VECTOR nodes with N number of EXTRACT_VECTOR |
| 5591 | // operands, where N is the size of the formed vector. |
| 5592 | // Each EXTRACT_VECTOR should have the same input vector and odd or even |
| 5593 | // index such that we have a pair wise add pattern. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5594 | |
| 5595 | // Grab the vector that all EXTRACT_VECTOR nodes should be referencing. |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 5596 | if (N0->getOperand(0)->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5597 | return SDValue(); |
Bob Wilson | 7a10ab7 | 2011-06-15 06:04:34 +0000 | [diff] [blame] | 5598 | SDValue Vec = N0->getOperand(0)->getOperand(0); |
| 5599 | SDNode *V = Vec.getNode(); |
| 5600 | unsigned nextIndex = 0; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5601 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5602 | // For each operands to the ADD which are BUILD_VECTORs, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5603 | // check to see if each of their operands are an EXTRACT_VECTOR with |
| 5604 | // the same vector and appropriate index. |
| 5605 | for (unsigned i = 0, e = N0->getNumOperands(); i != e; ++i) { |
| 5606 | if (N0->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT |
| 5607 | && N1->getOperand(i)->getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5608 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5609 | SDValue ExtVec0 = N0->getOperand(i); |
| 5610 | SDValue ExtVec1 = N1->getOperand(i); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5611 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5612 | // First operand is the vector, verify its the same. |
| 5613 | if (V != ExtVec0->getOperand(0).getNode() || |
| 5614 | V != ExtVec1->getOperand(0).getNode()) |
| 5615 | return SDValue(); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5616 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5617 | // Second is the constant, verify its correct. |
| 5618 | ConstantSDNode *C0 = dyn_cast<ConstantSDNode>(ExtVec0->getOperand(1)); |
| 5619 | ConstantSDNode *C1 = dyn_cast<ConstantSDNode>(ExtVec1->getOperand(1)); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5620 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5621 | // For the constant, we want to see all the even or all the odd. |
| 5622 | if (!C0 || !C1 || C0->getZExtValue() != nextIndex |
| 5623 | || C1->getZExtValue() != nextIndex+1) |
| 5624 | return SDValue(); |
| 5625 | |
| 5626 | // Increment index. |
| 5627 | nextIndex+=2; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5628 | } else |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5629 | return SDValue(); |
| 5630 | } |
| 5631 | |
| 5632 | // Create VPADDL node. |
| 5633 | SelectionDAG &DAG = DCI.DAG; |
| 5634 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5635 | |
| 5636 | // Build operand list. |
| 5637 | SmallVector<SDValue, 8> Ops; |
| 5638 | Ops.push_back(DAG.getConstant(Intrinsic::arm_neon_vpaddls, |
| 5639 | TLI.getPointerTy())); |
| 5640 | |
| 5641 | // Input is the vector. |
| 5642 | Ops.push_back(Vec); |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5643 | |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5644 | // Get widened type and narrowed type. |
| 5645 | MVT widenType; |
| 5646 | unsigned numElem = VT.getVectorNumElements(); |
| 5647 | switch (VT.getVectorElementType().getSimpleVT().SimpleTy) { |
| 5648 | case MVT::i8: widenType = MVT::getVectorVT(MVT::i16, numElem); break; |
| 5649 | case MVT::i16: widenType = MVT::getVectorVT(MVT::i32, numElem); break; |
| 5650 | case MVT::i32: widenType = MVT::getVectorVT(MVT::i64, numElem); break; |
| 5651 | default: |
| 5652 | assert(0 && "Invalid vector element type for padd optimization."); |
| 5653 | } |
| 5654 | |
| 5655 | SDValue tmp = DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 5656 | widenType, &Ops[0], Ops.size()); |
| 5657 | return DAG.getNode(ISD::TRUNCATE, N->getDebugLoc(), VT, tmp); |
| 5658 | } |
| 5659 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5660 | /// PerformADDCombineWithOperands - Try DAG combinations for an ADD with |
| 5661 | /// operands N0 and N1. This is a helper for PerformADDCombine that is |
| 5662 | /// called with the default operands, and if that fails, with commuted |
| 5663 | /// operands. |
| 5664 | static SDValue PerformADDCombineWithOperands(SDNode *N, SDValue N0, SDValue N1, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5665 | TargetLowering::DAGCombinerInfo &DCI, |
| 5666 | const ARMSubtarget *Subtarget){ |
| 5667 | |
| 5668 | // Attempt to create vpaddl for this add. |
| 5669 | SDValue Result = AddCombineToVPADDL(N, N0, N1, DCI, Subtarget); |
| 5670 | if (Result.getNode()) |
| 5671 | return Result; |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 5672 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5673 | // fold (add (select cc, 0, c), x) -> (select cc, x, (add, x, c)) |
| 5674 | if (N0.getOpcode() == ISD::SELECT && N0.getNode()->hasOneUse()) { |
| 5675 | SDValue Result = combineSelectAndUse(N, N0, N1, DCI); |
| 5676 | if (Result.getNode()) return Result; |
| 5677 | } |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5678 | return SDValue(); |
| 5679 | } |
| 5680 | |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5681 | /// PerformADDCombine - Target-specific dag combine xforms for ISD::ADD. |
| 5682 | /// |
| 5683 | static SDValue PerformADDCombine(SDNode *N, |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5684 | TargetLowering::DAGCombinerInfo &DCI, |
| 5685 | const ARMSubtarget *Subtarget) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5686 | SDValue N0 = N->getOperand(0); |
| 5687 | SDValue N1 = N->getOperand(1); |
| 5688 | |
| 5689 | // First try with the default operand order. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5690 | SDValue Result = PerformADDCombineWithOperands(N, N0, N1, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5691 | if (Result.getNode()) |
| 5692 | return Result; |
| 5693 | |
| 5694 | // If that didn't work, try again with the operands commuted. |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 5695 | return PerformADDCombineWithOperands(N, N1, N0, DCI, Subtarget); |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5696 | } |
| 5697 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5698 | /// PerformSUBCombine - Target-specific dag combine xforms for ISD::SUB. |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5699 | /// |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5700 | static SDValue PerformSUBCombine(SDNode *N, |
| 5701 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 3d5792a | 2010-07-29 20:34:14 +0000 | [diff] [blame] | 5702 | SDValue N0 = N->getOperand(0); |
| 5703 | SDValue N1 = N->getOperand(1); |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5704 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5705 | // fold (sub x, (select cc, 0, c)) -> (select cc, x, (sub, x, c)) |
| 5706 | if (N1.getOpcode() == ISD::SELECT && N1.getNode()->hasOneUse()) { |
| 5707 | SDValue Result = combineSelectAndUse(N, N1, N0, DCI); |
| 5708 | if (Result.getNode()) return Result; |
| 5709 | } |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 5710 | |
Chris Lattner | d1980a5 | 2009-03-12 06:52:53 +0000 | [diff] [blame] | 5711 | return SDValue(); |
| 5712 | } |
| 5713 | |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 5714 | /// PerformVMULCombine |
| 5715 | /// Distribute (A + B) * C to (A * C) + (B * C) to take advantage of the |
| 5716 | /// special multiplier accumulator forwarding. |
| 5717 | /// vmul d3, d0, d2 |
| 5718 | /// vmla d3, d1, d2 |
| 5719 | /// is faster than |
| 5720 | /// vadd d3, d0, d1 |
| 5721 | /// vmul d3, d3, d2 |
| 5722 | static SDValue PerformVMULCombine(SDNode *N, |
| 5723 | TargetLowering::DAGCombinerInfo &DCI, |
| 5724 | const ARMSubtarget *Subtarget) { |
| 5725 | if (!Subtarget->hasVMLxForwarding()) |
| 5726 | return SDValue(); |
| 5727 | |
| 5728 | SelectionDAG &DAG = DCI.DAG; |
| 5729 | SDValue N0 = N->getOperand(0); |
| 5730 | SDValue N1 = N->getOperand(1); |
| 5731 | unsigned Opcode = N0.getOpcode(); |
| 5732 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5733 | Opcode != ISD::FADD && Opcode != ISD::FSUB) { |
Chad Rosier | 689edc8 | 2011-06-16 01:21:54 +0000 | [diff] [blame] | 5734 | Opcode = N1.getOpcode(); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 5735 | if (Opcode != ISD::ADD && Opcode != ISD::SUB && |
| 5736 | Opcode != ISD::FADD && Opcode != ISD::FSUB) |
| 5737 | return SDValue(); |
| 5738 | std::swap(N0, N1); |
| 5739 | } |
| 5740 | |
| 5741 | EVT VT = N->getValueType(0); |
| 5742 | DebugLoc DL = N->getDebugLoc(); |
| 5743 | SDValue N00 = N0->getOperand(0); |
| 5744 | SDValue N01 = N0->getOperand(1); |
| 5745 | return DAG.getNode(Opcode, DL, VT, |
| 5746 | DAG.getNode(ISD::MUL, DL, VT, N00, N1), |
| 5747 | DAG.getNode(ISD::MUL, DL, VT, N01, N1)); |
| 5748 | } |
| 5749 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5750 | static SDValue PerformMULCombine(SDNode *N, |
| 5751 | TargetLowering::DAGCombinerInfo &DCI, |
| 5752 | const ARMSubtarget *Subtarget) { |
| 5753 | SelectionDAG &DAG = DCI.DAG; |
| 5754 | |
| 5755 | if (Subtarget->isThumb1Only()) |
| 5756 | return SDValue(); |
| 5757 | |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5758 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 5759 | return SDValue(); |
| 5760 | |
| 5761 | EVT VT = N->getValueType(0); |
Evan Cheng | 463d358 | 2011-03-31 19:38:48 +0000 | [diff] [blame] | 5762 | if (VT.is64BitVector() || VT.is128BitVector()) |
| 5763 | return PerformVMULCombine(N, DCI, Subtarget); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5764 | if (VT != MVT::i32) |
| 5765 | return SDValue(); |
| 5766 | |
| 5767 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(N->getOperand(1)); |
| 5768 | if (!C) |
| 5769 | return SDValue(); |
| 5770 | |
| 5771 | uint64_t MulAmt = C->getZExtValue(); |
| 5772 | unsigned ShiftAmt = CountTrailingZeros_64(MulAmt); |
| 5773 | ShiftAmt = ShiftAmt & (32 - 1); |
| 5774 | SDValue V = N->getOperand(0); |
| 5775 | DebugLoc DL = N->getDebugLoc(); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5776 | |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5777 | SDValue Res; |
| 5778 | MulAmt >>= ShiftAmt; |
| 5779 | if (isPowerOf2_32(MulAmt - 1)) { |
| 5780 | // (mul x, 2^N + 1) => (add (shl x, N), x) |
| 5781 | Res = DAG.getNode(ISD::ADD, DL, VT, |
| 5782 | V, DAG.getNode(ISD::SHL, DL, VT, |
| 5783 | V, DAG.getConstant(Log2_32(MulAmt-1), |
| 5784 | MVT::i32))); |
| 5785 | } else if (isPowerOf2_32(MulAmt + 1)) { |
| 5786 | // (mul x, 2^N - 1) => (sub (shl x, N), x) |
| 5787 | Res = DAG.getNode(ISD::SUB, DL, VT, |
| 5788 | DAG.getNode(ISD::SHL, DL, VT, |
| 5789 | V, DAG.getConstant(Log2_32(MulAmt+1), |
| 5790 | MVT::i32)), |
| 5791 | V); |
| 5792 | } else |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5793 | return SDValue(); |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5794 | |
| 5795 | if (ShiftAmt != 0) |
| 5796 | Res = DAG.getNode(ISD::SHL, DL, VT, Res, |
| 5797 | DAG.getConstant(ShiftAmt, MVT::i32)); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5798 | |
| 5799 | // Do not add new nodes to DAG combiner worklist. |
Anton Korobeynikov | 4878b84 | 2010-05-16 08:54:20 +0000 | [diff] [blame] | 5800 | DCI.CombineTo(N, Res, false); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 5801 | return SDValue(); |
| 5802 | } |
| 5803 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5804 | static SDValue PerformANDCombine(SDNode *N, |
| 5805 | TargetLowering::DAGCombinerInfo &DCI) { |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 5806 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5807 | // Attempt to use immediate-form VBIC |
| 5808 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5809 | DebugLoc dl = N->getDebugLoc(); |
| 5810 | EVT VT = N->getValueType(0); |
| 5811 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5812 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 5813 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 5814 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5815 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5816 | APInt SplatBits, SplatUndef; |
| 5817 | unsigned SplatBitSize; |
| 5818 | bool HasAnyUndefs; |
| 5819 | if (BVN && |
| 5820 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5821 | if (SplatBitSize <= 64) { |
| 5822 | EVT VbicVT; |
| 5823 | SDValue Val = isNEONModifiedImm((~SplatBits).getZExtValue(), |
| 5824 | SplatUndef.getZExtValue(), SplatBitSize, |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5825 | DAG, VbicVT, VT.is128BitVector(), |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5826 | OtherModImm); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5827 | if (Val.getNode()) { |
| 5828 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5829 | DAG.getNode(ISD::BITCAST, dl, VbicVT, N->getOperand(0)); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5830 | SDValue Vbic = DAG.getNode(ARMISD::VBICIMM, dl, VbicVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5831 | return DAG.getNode(ISD::BITCAST, dl, VT, Vbic); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5832 | } |
| 5833 | } |
| 5834 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5835 | |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 5836 | return SDValue(); |
| 5837 | } |
| 5838 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5839 | /// PerformORCombine - Target-specific dag combine xforms for ISD::OR |
| 5840 | static SDValue PerformORCombine(SDNode *N, |
| 5841 | TargetLowering::DAGCombinerInfo &DCI, |
| 5842 | const ARMSubtarget *Subtarget) { |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5843 | // Attempt to use immediate-form VORR |
| 5844 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(N->getOperand(1)); |
| 5845 | DebugLoc dl = N->getDebugLoc(); |
| 5846 | EVT VT = N->getValueType(0); |
| 5847 | SelectionDAG &DAG = DCI.DAG; |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5848 | |
Tanya Lattner | 0433b21 | 2011-04-07 15:24:20 +0000 | [diff] [blame] | 5849 | if(!DAG.getTargetLoweringInfo().isTypeLegal(VT)) |
| 5850 | return SDValue(); |
Andrew Trick | 1c3af77 | 2011-04-23 03:55:32 +0000 | [diff] [blame] | 5851 | |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5852 | APInt SplatBits, SplatUndef; |
| 5853 | unsigned SplatBitSize; |
| 5854 | bool HasAnyUndefs; |
| 5855 | if (BVN && Subtarget->hasNEON() && |
| 5856 | BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, HasAnyUndefs)) { |
| 5857 | if (SplatBitSize <= 64) { |
| 5858 | EVT VorrVT; |
| 5859 | SDValue Val = isNEONModifiedImm(SplatBits.getZExtValue(), |
| 5860 | SplatUndef.getZExtValue(), SplatBitSize, |
Owen Anderson | 36fa3ea | 2010-11-05 21:57:54 +0000 | [diff] [blame] | 5861 | DAG, VorrVT, VT.is128BitVector(), |
| 5862 | OtherModImm); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5863 | if (Val.getNode()) { |
| 5864 | SDValue Input = |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5865 | DAG.getNode(ISD::BITCAST, dl, VorrVT, N->getOperand(0)); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5866 | SDValue Vorr = DAG.getNode(ARMISD::VORRIMM, dl, VorrVT, Input, Val); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5867 | return DAG.getNode(ISD::BITCAST, dl, VT, Vorr); |
Owen Anderson | 60f4870 | 2010-11-03 23:15:26 +0000 | [diff] [blame] | 5868 | } |
| 5869 | } |
| 5870 | } |
| 5871 | |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 5872 | SDValue N0 = N->getOperand(0); |
| 5873 | if (N0.getOpcode() != ISD::AND) |
| 5874 | return SDValue(); |
| 5875 | SDValue N1 = N->getOperand(1); |
| 5876 | |
| 5877 | // (or (and B, A), (and C, ~A)) => (VBSL A, B, C) when A is a constant. |
| 5878 | if (Subtarget->hasNEON() && N1.getOpcode() == ISD::AND && VT.isVector() && |
| 5879 | DAG.getTargetLoweringInfo().isTypeLegal(VT)) { |
| 5880 | APInt SplatUndef; |
| 5881 | unsigned SplatBitSize; |
| 5882 | bool HasAnyUndefs; |
| 5883 | |
| 5884 | BuildVectorSDNode *BVN0 = dyn_cast<BuildVectorSDNode>(N0->getOperand(1)); |
| 5885 | APInt SplatBits0; |
| 5886 | if (BVN0 && BVN0->isConstantSplat(SplatBits0, SplatUndef, SplatBitSize, |
| 5887 | HasAnyUndefs) && !HasAnyUndefs) { |
| 5888 | BuildVectorSDNode *BVN1 = dyn_cast<BuildVectorSDNode>(N1->getOperand(1)); |
| 5889 | APInt SplatBits1; |
| 5890 | if (BVN1 && BVN1->isConstantSplat(SplatBits1, SplatUndef, SplatBitSize, |
| 5891 | HasAnyUndefs) && !HasAnyUndefs && |
| 5892 | SplatBits0 == ~SplatBits1) { |
| 5893 | // Canonicalize the vector type to make instruction selection simpler. |
| 5894 | EVT CanonicalVT = VT.is128BitVector() ? MVT::v4i32 : MVT::v2i32; |
| 5895 | SDValue Result = DAG.getNode(ARMISD::VBSL, dl, CanonicalVT, |
| 5896 | N0->getOperand(1), N0->getOperand(0), |
Cameron Zwarich | 5af60ce | 2011-04-13 21:01:19 +0000 | [diff] [blame] | 5897 | N1->getOperand(0)); |
Cameron Zwarich | c0e6d78 | 2011-03-30 23:01:21 +0000 | [diff] [blame] | 5898 | return DAG.getNode(ISD::BITCAST, dl, VT, Result); |
| 5899 | } |
| 5900 | } |
| 5901 | } |
| 5902 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5903 | // Try to use the ARM/Thumb2 BFI (bitfield insert) instruction when |
| 5904 | // reasonable. |
| 5905 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5906 | // BFI is only available on V6T2+ |
| 5907 | if (Subtarget->isThumb1Only() || !Subtarget->hasV6T2Ops()) |
| 5908 | return SDValue(); |
| 5909 | |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5910 | DebugLoc DL = N->getDebugLoc(); |
| 5911 | // 1) or (and A, mask), val => ARMbfi A, val, mask |
| 5912 | // iff (val & mask) == val |
| 5913 | // |
| 5914 | // 2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
| 5915 | // 2a) iff isBitFieldInvertedMask(mask) && isBitFieldInvertedMask(~mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5916 | // && mask == ~mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5917 | // 2b) iff isBitFieldInvertedMask(~mask) && isBitFieldInvertedMask(mask2) |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5918 | // && ~mask == mask2 |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5919 | // (i.e., copy a bitfield value into another bitfield of the same width) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5920 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5921 | if (VT != MVT::i32) |
| 5922 | return SDValue(); |
| 5923 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5924 | SDValue N00 = N0.getOperand(0); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5925 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5926 | // The value and the mask need to be constants so we can verify this is |
| 5927 | // actually a bitfield set. If the mask is 0xffff, we can do better |
| 5928 | // via a movt instruction, so don't use BFI in that case. |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5929 | SDValue MaskOp = N0.getOperand(1); |
| 5930 | ConstantSDNode *MaskC = dyn_cast<ConstantSDNode>(MaskOp); |
| 5931 | if (!MaskC) |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5932 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5933 | unsigned Mask = MaskC->getZExtValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5934 | if (Mask == 0xffff) |
| 5935 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5936 | SDValue Res; |
| 5937 | // Case (1): or (and A, mask), val => ARMbfi A, val, mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5938 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1); |
| 5939 | if (N1C) { |
| 5940 | unsigned Val = N1C->getZExtValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5941 | if ((Val & ~Mask) != Val) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5942 | return SDValue(); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5943 | |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5944 | if (ARM::isBitFieldInvertedMask(Mask)) { |
| 5945 | Val >>= CountTrailingZeros_32(~Mask); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 5946 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5947 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5948 | DAG.getConstant(Val, MVT::i32), |
| 5949 | DAG.getConstant(Mask, MVT::i32)); |
| 5950 | |
| 5951 | // Do not add new nodes to DAG combiner worklist. |
| 5952 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5953 | return SDValue(); |
Evan Cheng | a9688c4 | 2010-12-11 04:11:38 +0000 | [diff] [blame] | 5954 | } |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5955 | } else if (N1.getOpcode() == ISD::AND) { |
| 5956 | // case (2) or (and A, mask), (and B, mask2) => ARMbfi A, (lsr B, amt), mask |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5957 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 5958 | if (!N11C) |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5959 | return SDValue(); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5960 | unsigned Mask2 = N11C->getZExtValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5961 | |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5962 | // Mask and ~Mask2 (or reverse) must be equivalent for the BFI pattern |
| 5963 | // as is to match. |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5964 | if (ARM::isBitFieldInvertedMask(Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5965 | (Mask == ~Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5966 | // The pack halfword instruction works better for masks that fit it, |
| 5967 | // so use that when it's available. |
| 5968 | if (Subtarget->hasT2ExtractPack() && |
| 5969 | (Mask == 0xffff || Mask == 0xffff0000)) |
| 5970 | return SDValue(); |
| 5971 | // 2a |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5972 | unsigned amt = CountTrailingZeros_32(Mask2); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5973 | Res = DAG.getNode(ISD::SRL, DL, VT, N1.getOperand(0), |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5974 | DAG.getConstant(amt, MVT::i32)); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5975 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N00, Res, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5976 | DAG.getConstant(Mask, MVT::i32)); |
| 5977 | // Do not add new nodes to DAG combiner worklist. |
| 5978 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5979 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5980 | } else if (ARM::isBitFieldInvertedMask(~Mask) && |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5981 | (~Mask == Mask2)) { |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5982 | // The pack halfword instruction works better for masks that fit it, |
| 5983 | // so use that when it's available. |
| 5984 | if (Subtarget->hasT2ExtractPack() && |
| 5985 | (Mask2 == 0xffff || Mask2 == 0xffff0000)) |
| 5986 | return SDValue(); |
| 5987 | // 2b |
| 5988 | unsigned lsb = CountTrailingZeros_32(Mask); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5989 | Res = DAG.getNode(ISD::SRL, DL, VT, N00, |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5990 | DAG.getConstant(lsb, MVT::i32)); |
| 5991 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1.getOperand(0), Res, |
Eric Christopher | 29aeed1 | 2011-03-26 01:21:03 +0000 | [diff] [blame] | 5992 | DAG.getConstant(Mask2, MVT::i32)); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5993 | // Do not add new nodes to DAG combiner worklist. |
| 5994 | DCI.CombineTo(N, Res, false); |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5995 | return SDValue(); |
Jim Grosbach | 5423856 | 2010-07-17 03:30:54 +0000 | [diff] [blame] | 5996 | } |
| 5997 | } |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 5998 | |
Evan Cheng | 30fb13f | 2010-12-13 20:32:54 +0000 | [diff] [blame] | 5999 | if (DAG.MaskedValueIsZero(N1, MaskC->getAPIntValue()) && |
| 6000 | N00.getOpcode() == ISD::SHL && isa<ConstantSDNode>(N00.getOperand(1)) && |
| 6001 | ARM::isBitFieldInvertedMask(~Mask)) { |
| 6002 | // Case (3): or (and (shl A, #shamt), mask), B => ARMbfi B, A, ~mask |
| 6003 | // where lsb(mask) == #shamt and masked bits of B are known zero. |
| 6004 | SDValue ShAmt = N00.getOperand(1); |
| 6005 | unsigned ShAmtC = cast<ConstantSDNode>(ShAmt)->getZExtValue(); |
| 6006 | unsigned LSB = CountTrailingZeros_32(Mask); |
| 6007 | if (ShAmtC != LSB) |
| 6008 | return SDValue(); |
| 6009 | |
| 6010 | Res = DAG.getNode(ARMISD::BFI, DL, VT, N1, N00.getOperand(0), |
| 6011 | DAG.getConstant(~Mask, MVT::i32)); |
| 6012 | |
| 6013 | // Do not add new nodes to DAG combiner worklist. |
| 6014 | DCI.CombineTo(N, Res, false); |
| 6015 | } |
| 6016 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 6017 | return SDValue(); |
| 6018 | } |
| 6019 | |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 6020 | /// PerformBFICombine - (bfi A, (and B, Mask1), Mask2) -> (bfi A, B, Mask2) iff |
| 6021 | /// the bits being cleared by the AND are not demanded by the BFI. |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 6022 | static SDValue PerformBFICombine(SDNode *N, |
| 6023 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6024 | SDValue N1 = N->getOperand(1); |
| 6025 | if (N1.getOpcode() == ISD::AND) { |
| 6026 | ConstantSDNode *N11C = dyn_cast<ConstantSDNode>(N1.getOperand(1)); |
| 6027 | if (!N11C) |
| 6028 | return SDValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 6029 | unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); |
| 6030 | unsigned LSB = CountTrailingZeros_32(~InvMask); |
| 6031 | unsigned Width = (32 - CountLeadingZeros_32(~InvMask)) - LSB; |
| 6032 | unsigned Mask = (1 << Width)-1; |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 6033 | unsigned Mask2 = N11C->getZExtValue(); |
Evan Cheng | bf188ae | 2011-06-15 01:12:31 +0000 | [diff] [blame] | 6034 | if ((Mask & (~Mask2)) == 0) |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 6035 | return DCI.DAG.getNode(ARMISD::BFI, N->getDebugLoc(), N->getValueType(0), |
| 6036 | N->getOperand(0), N1.getOperand(0), |
| 6037 | N->getOperand(2)); |
| 6038 | } |
| 6039 | return SDValue(); |
| 6040 | } |
| 6041 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6042 | /// PerformVMOVRRDCombine - Target-specific dag combine xforms for |
| 6043 | /// ARMISD::VMOVRRD. |
| 6044 | static SDValue PerformVMOVRRDCombine(SDNode *N, |
| 6045 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6046 | // vmovrrd(vmovdrr x, y) -> x,y |
| 6047 | SDValue InDouble = N->getOperand(0); |
| 6048 | if (InDouble.getOpcode() == ARMISD::VMOVDRR) |
| 6049 | return DCI.CombineTo(N, InDouble.getOperand(0), InDouble.getOperand(1)); |
Cameron Zwarich | 4071a71 | 2011-04-02 02:40:43 +0000 | [diff] [blame] | 6050 | |
| 6051 | // vmovrrd(load f64) -> (load i32), (load i32) |
| 6052 | SDNode *InNode = InDouble.getNode(); |
| 6053 | if (ISD::isNormalLoad(InNode) && InNode->hasOneUse() && |
| 6054 | InNode->getValueType(0) == MVT::f64 && |
| 6055 | InNode->getOperand(1).getOpcode() == ISD::FrameIndex && |
| 6056 | !cast<LoadSDNode>(InNode)->isVolatile()) { |
| 6057 | // TODO: Should this be done for non-FrameIndex operands? |
| 6058 | LoadSDNode *LD = cast<LoadSDNode>(InNode); |
| 6059 | |
| 6060 | SelectionDAG &DAG = DCI.DAG; |
| 6061 | DebugLoc DL = LD->getDebugLoc(); |
| 6062 | SDValue BasePtr = LD->getBasePtr(); |
| 6063 | SDValue NewLD1 = DAG.getLoad(MVT::i32, DL, LD->getChain(), BasePtr, |
| 6064 | LD->getPointerInfo(), LD->isVolatile(), |
| 6065 | LD->isNonTemporal(), LD->getAlignment()); |
| 6066 | |
| 6067 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 6068 | DAG.getConstant(4, MVT::i32)); |
| 6069 | SDValue NewLD2 = DAG.getLoad(MVT::i32, DL, NewLD1.getValue(1), OffsetPtr, |
| 6070 | LD->getPointerInfo(), LD->isVolatile(), |
| 6071 | LD->isNonTemporal(), |
| 6072 | std::min(4U, LD->getAlignment() / 2)); |
| 6073 | |
| 6074 | DAG.ReplaceAllUsesOfValueWith(SDValue(LD, 1), NewLD2.getValue(1)); |
| 6075 | SDValue Result = DCI.CombineTo(N, NewLD1, NewLD2); |
| 6076 | DCI.RemoveFromWorklist(LD); |
| 6077 | DAG.DeleteNode(LD); |
| 6078 | return Result; |
| 6079 | } |
| 6080 | |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6081 | return SDValue(); |
| 6082 | } |
| 6083 | |
| 6084 | /// PerformVMOVDRRCombine - Target-specific dag combine xforms for |
| 6085 | /// ARMISD::VMOVDRR. This is also used for BUILD_VECTORs with 2 operands. |
| 6086 | static SDValue PerformVMOVDRRCombine(SDNode *N, SelectionDAG &DAG) { |
| 6087 | // N=vmovrrd(X); vmovdrr(N:0, N:1) -> bit_convert(X) |
| 6088 | SDValue Op0 = N->getOperand(0); |
| 6089 | SDValue Op1 = N->getOperand(1); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6090 | if (Op0.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6091 | Op0 = Op0.getOperand(0); |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6092 | if (Op1.getOpcode() == ISD::BITCAST) |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6093 | Op1 = Op1.getOperand(0); |
| 6094 | if (Op0.getOpcode() == ARMISD::VMOVRRD && |
| 6095 | Op0.getNode() == Op1.getNode() && |
| 6096 | Op0.getResNo() == 0 && Op1.getResNo() == 1) |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6097 | return DAG.getNode(ISD::BITCAST, N->getDebugLoc(), |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 6098 | N->getValueType(0), Op0.getOperand(0)); |
| 6099 | return SDValue(); |
| 6100 | } |
| 6101 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6102 | /// PerformSTORECombine - Target-specific dag combine xforms for |
| 6103 | /// ISD::STORE. |
| 6104 | static SDValue PerformSTORECombine(SDNode *N, |
| 6105 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6106 | // Bitcast an i64 store extracted from a vector to f64. |
| 6107 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 6108 | StoreSDNode *St = cast<StoreSDNode>(N); |
| 6109 | SDValue StVal = St->getValue(); |
Cameron Zwarich | d0aacbc | 2011-04-12 02:24:17 +0000 | [diff] [blame] | 6110 | if (!ISD::isNormalStore(St) || St->isVolatile()) |
| 6111 | return SDValue(); |
| 6112 | |
| 6113 | if (StVal.getNode()->getOpcode() == ARMISD::VMOVDRR && |
| 6114 | StVal.getNode()->hasOneUse() && !St->isVolatile()) { |
| 6115 | SelectionDAG &DAG = DCI.DAG; |
| 6116 | DebugLoc DL = St->getDebugLoc(); |
| 6117 | SDValue BasePtr = St->getBasePtr(); |
| 6118 | SDValue NewST1 = DAG.getStore(St->getChain(), DL, |
| 6119 | StVal.getNode()->getOperand(0), BasePtr, |
| 6120 | St->getPointerInfo(), St->isVolatile(), |
| 6121 | St->isNonTemporal(), St->getAlignment()); |
| 6122 | |
| 6123 | SDValue OffsetPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, |
| 6124 | DAG.getConstant(4, MVT::i32)); |
| 6125 | return DAG.getStore(NewST1.getValue(0), DL, StVal.getNode()->getOperand(1), |
| 6126 | OffsetPtr, St->getPointerInfo(), St->isVolatile(), |
| 6127 | St->isNonTemporal(), |
| 6128 | std::min(4U, St->getAlignment() / 2)); |
| 6129 | } |
| 6130 | |
| 6131 | if (StVal.getValueType() != MVT::i64 || |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6132 | StVal.getNode()->getOpcode() != ISD::EXTRACT_VECTOR_ELT) |
| 6133 | return SDValue(); |
| 6134 | |
| 6135 | SelectionDAG &DAG = DCI.DAG; |
| 6136 | DebugLoc dl = StVal.getDebugLoc(); |
| 6137 | SDValue IntVec = StVal.getOperand(0); |
| 6138 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 6139 | IntVec.getValueType().getVectorNumElements()); |
| 6140 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, IntVec); |
| 6141 | SDValue ExtElt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, dl, MVT::f64, |
| 6142 | Vec, StVal.getOperand(1)); |
| 6143 | dl = N->getDebugLoc(); |
| 6144 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::i64, ExtElt); |
| 6145 | // Make the DAGCombiner fold the bitcasts. |
| 6146 | DCI.AddToWorklist(Vec.getNode()); |
| 6147 | DCI.AddToWorklist(ExtElt.getNode()); |
| 6148 | DCI.AddToWorklist(V.getNode()); |
| 6149 | return DAG.getStore(St->getChain(), dl, V, St->getBasePtr(), |
| 6150 | St->getPointerInfo(), St->isVolatile(), |
| 6151 | St->isNonTemporal(), St->getAlignment(), |
| 6152 | St->getTBAAInfo()); |
| 6153 | } |
| 6154 | |
| 6155 | /// hasNormalLoadOperand - Check if any of the operands of a BUILD_VECTOR node |
| 6156 | /// are normal, non-volatile loads. If so, it is profitable to bitcast an |
| 6157 | /// i64 vector to have f64 elements, since the value can then be loaded |
| 6158 | /// directly into a VFP register. |
| 6159 | static bool hasNormalLoadOperand(SDNode *N) { |
| 6160 | unsigned NumElts = N->getValueType(0).getVectorNumElements(); |
| 6161 | for (unsigned i = 0; i < NumElts; ++i) { |
| 6162 | SDNode *Elt = N->getOperand(i).getNode(); |
| 6163 | if (ISD::isNormalLoad(Elt) && !cast<LoadSDNode>(Elt)->isVolatile()) |
| 6164 | return true; |
| 6165 | } |
| 6166 | return false; |
| 6167 | } |
| 6168 | |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6169 | /// PerformBUILD_VECTORCombine - Target-specific dag combine xforms for |
| 6170 | /// ISD::BUILD_VECTOR. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6171 | static SDValue PerformBUILD_VECTORCombine(SDNode *N, |
| 6172 | TargetLowering::DAGCombinerInfo &DCI){ |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6173 | // build_vector(N=ARMISD::VMOVRRD(X), N:1) -> bit_convert(X): |
| 6174 | // VMOVRRD is introduced when legalizing i64 types. It forces the i64 value |
| 6175 | // into a pair of GPRs, which is fine when the value is used as a scalar, |
| 6176 | // but if the i64 value is converted to a vector, we need to undo the VMOVRRD. |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6177 | SelectionDAG &DAG = DCI.DAG; |
| 6178 | if (N->getNumOperands() == 2) { |
| 6179 | SDValue RV = PerformVMOVDRRCombine(N, DAG); |
| 6180 | if (RV.getNode()) |
| 6181 | return RV; |
| 6182 | } |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6183 | |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 6184 | // Load i64 elements as f64 values so that type legalization does not split |
| 6185 | // them up into i32 values. |
| 6186 | EVT VT = N->getValueType(0); |
| 6187 | if (VT.getVectorElementType() != MVT::i64 || !hasNormalLoadOperand(N)) |
| 6188 | return SDValue(); |
| 6189 | DebugLoc dl = N->getDebugLoc(); |
| 6190 | SmallVector<SDValue, 8> Ops; |
| 6191 | unsigned NumElts = VT.getVectorNumElements(); |
| 6192 | for (unsigned i = 0; i < NumElts; ++i) { |
| 6193 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(i)); |
| 6194 | Ops.push_back(V); |
| 6195 | // Make the DAGCombiner fold the bitcast. |
| 6196 | DCI.AddToWorklist(V.getNode()); |
| 6197 | } |
| 6198 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, NumElts); |
| 6199 | SDValue BV = DAG.getNode(ISD::BUILD_VECTOR, dl, FloatVT, Ops.data(), NumElts); |
| 6200 | return DAG.getNode(ISD::BITCAST, dl, VT, BV); |
| 6201 | } |
| 6202 | |
| 6203 | /// PerformInsertEltCombine - Target-specific dag combine xforms for |
| 6204 | /// ISD::INSERT_VECTOR_ELT. |
| 6205 | static SDValue PerformInsertEltCombine(SDNode *N, |
| 6206 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6207 | // Bitcast an i64 load inserted into a vector to f64. |
| 6208 | // Otherwise, the i64 value will be legalized to a pair of i32 values. |
| 6209 | EVT VT = N->getValueType(0); |
| 6210 | SDNode *Elt = N->getOperand(1).getNode(); |
| 6211 | if (VT.getVectorElementType() != MVT::i64 || |
| 6212 | !ISD::isNormalLoad(Elt) || cast<LoadSDNode>(Elt)->isVolatile()) |
| 6213 | return SDValue(); |
| 6214 | |
| 6215 | SelectionDAG &DAG = DCI.DAG; |
| 6216 | DebugLoc dl = N->getDebugLoc(); |
| 6217 | EVT FloatVT = EVT::getVectorVT(*DAG.getContext(), MVT::f64, |
| 6218 | VT.getVectorNumElements()); |
| 6219 | SDValue Vec = DAG.getNode(ISD::BITCAST, dl, FloatVT, N->getOperand(0)); |
| 6220 | SDValue V = DAG.getNode(ISD::BITCAST, dl, MVT::f64, N->getOperand(1)); |
| 6221 | // Make the DAGCombiner fold the bitcasts. |
| 6222 | DCI.AddToWorklist(Vec.getNode()); |
| 6223 | DCI.AddToWorklist(V.getNode()); |
| 6224 | SDValue InsElt = DAG.getNode(ISD::INSERT_VECTOR_ELT, dl, FloatVT, |
| 6225 | Vec, V, N->getOperand(2)); |
| 6226 | return DAG.getNode(ISD::BITCAST, dl, VT, InsElt); |
Bob Wilson | 75f0288 | 2010-09-17 22:59:05 +0000 | [diff] [blame] | 6227 | } |
| 6228 | |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6229 | /// PerformVECTOR_SHUFFLECombine - Target-specific dag combine xforms for |
| 6230 | /// ISD::VECTOR_SHUFFLE. |
| 6231 | static SDValue PerformVECTOR_SHUFFLECombine(SDNode *N, SelectionDAG &DAG) { |
| 6232 | // The LLVM shufflevector instruction does not require the shuffle mask |
| 6233 | // length to match the operand vector length, but ISD::VECTOR_SHUFFLE does |
| 6234 | // have that requirement. When translating to ISD::VECTOR_SHUFFLE, if the |
| 6235 | // operands do not match the mask length, they are extended by concatenating |
| 6236 | // them with undef vectors. That is probably the right thing for other |
| 6237 | // targets, but for NEON it is better to concatenate two double-register |
| 6238 | // size vector operands into a single quad-register size vector. Do that |
| 6239 | // transformation here: |
| 6240 | // shuffle(concat(v1, undef), concat(v2, undef)) -> |
| 6241 | // shuffle(concat(v1, v2), undef) |
| 6242 | SDValue Op0 = N->getOperand(0); |
| 6243 | SDValue Op1 = N->getOperand(1); |
| 6244 | if (Op0.getOpcode() != ISD::CONCAT_VECTORS || |
| 6245 | Op1.getOpcode() != ISD::CONCAT_VECTORS || |
| 6246 | Op0.getNumOperands() != 2 || |
| 6247 | Op1.getNumOperands() != 2) |
| 6248 | return SDValue(); |
| 6249 | SDValue Concat0Op1 = Op0.getOperand(1); |
| 6250 | SDValue Concat1Op1 = Op1.getOperand(1); |
| 6251 | if (Concat0Op1.getOpcode() != ISD::UNDEF || |
| 6252 | Concat1Op1.getOpcode() != ISD::UNDEF) |
| 6253 | return SDValue(); |
| 6254 | // Skip the transformation if any of the types are illegal. |
| 6255 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6256 | EVT VT = N->getValueType(0); |
| 6257 | if (!TLI.isTypeLegal(VT) || |
| 6258 | !TLI.isTypeLegal(Concat0Op1.getValueType()) || |
| 6259 | !TLI.isTypeLegal(Concat1Op1.getValueType())) |
| 6260 | return SDValue(); |
| 6261 | |
| 6262 | SDValue NewConcat = DAG.getNode(ISD::CONCAT_VECTORS, N->getDebugLoc(), VT, |
| 6263 | Op0.getOperand(0), Op1.getOperand(0)); |
| 6264 | // Translate the shuffle mask. |
| 6265 | SmallVector<int, 16> NewMask; |
| 6266 | unsigned NumElts = VT.getVectorNumElements(); |
| 6267 | unsigned HalfElts = NumElts/2; |
| 6268 | ShuffleVectorSDNode *SVN = cast<ShuffleVectorSDNode>(N); |
| 6269 | for (unsigned n = 0; n < NumElts; ++n) { |
| 6270 | int MaskElt = SVN->getMaskElt(n); |
| 6271 | int NewElt = -1; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 6272 | if (MaskElt < (int)HalfElts) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6273 | NewElt = MaskElt; |
Bob Wilson | 1fa9d30 | 2010-10-27 23:49:00 +0000 | [diff] [blame] | 6274 | else if (MaskElt >= (int)NumElts && MaskElt < (int)(NumElts + HalfElts)) |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 6275 | NewElt = HalfElts + MaskElt - NumElts; |
| 6276 | NewMask.push_back(NewElt); |
| 6277 | } |
| 6278 | return DAG.getVectorShuffle(VT, N->getDebugLoc(), NewConcat, |
| 6279 | DAG.getUNDEF(VT), NewMask.data()); |
| 6280 | } |
| 6281 | |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6282 | /// CombineBaseUpdate - Target-specific DAG combine function for VLDDUP and |
| 6283 | /// NEON load/store intrinsics to merge base address updates. |
| 6284 | static SDValue CombineBaseUpdate(SDNode *N, |
| 6285 | TargetLowering::DAGCombinerInfo &DCI) { |
| 6286 | if (DCI.isBeforeLegalize() || DCI.isCalledByLegalizer()) |
| 6287 | return SDValue(); |
| 6288 | |
| 6289 | SelectionDAG &DAG = DCI.DAG; |
| 6290 | bool isIntrinsic = (N->getOpcode() == ISD::INTRINSIC_VOID || |
| 6291 | N->getOpcode() == ISD::INTRINSIC_W_CHAIN); |
| 6292 | unsigned AddrOpIdx = (isIntrinsic ? 2 : 1); |
| 6293 | SDValue Addr = N->getOperand(AddrOpIdx); |
| 6294 | |
| 6295 | // Search for a use of the address operand that is an increment. |
| 6296 | for (SDNode::use_iterator UI = Addr.getNode()->use_begin(), |
| 6297 | UE = Addr.getNode()->use_end(); UI != UE; ++UI) { |
| 6298 | SDNode *User = *UI; |
| 6299 | if (User->getOpcode() != ISD::ADD || |
| 6300 | UI.getUse().getResNo() != Addr.getResNo()) |
| 6301 | continue; |
| 6302 | |
| 6303 | // Check that the add is independent of the load/store. Otherwise, folding |
| 6304 | // it would create a cycle. |
| 6305 | if (User->isPredecessorOf(N) || N->isPredecessorOf(User)) |
| 6306 | continue; |
| 6307 | |
| 6308 | // Find the new opcode for the updating load/store. |
| 6309 | bool isLoad = true; |
| 6310 | bool isLaneOp = false; |
| 6311 | unsigned NewOpc = 0; |
| 6312 | unsigned NumVecs = 0; |
| 6313 | if (isIntrinsic) { |
| 6314 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(1))->getZExtValue(); |
| 6315 | switch (IntNo) { |
| 6316 | default: assert(0 && "unexpected intrinsic for Neon base update"); |
| 6317 | case Intrinsic::arm_neon_vld1: NewOpc = ARMISD::VLD1_UPD; |
| 6318 | NumVecs = 1; break; |
| 6319 | case Intrinsic::arm_neon_vld2: NewOpc = ARMISD::VLD2_UPD; |
| 6320 | NumVecs = 2; break; |
| 6321 | case Intrinsic::arm_neon_vld3: NewOpc = ARMISD::VLD3_UPD; |
| 6322 | NumVecs = 3; break; |
| 6323 | case Intrinsic::arm_neon_vld4: NewOpc = ARMISD::VLD4_UPD; |
| 6324 | NumVecs = 4; break; |
| 6325 | case Intrinsic::arm_neon_vld2lane: NewOpc = ARMISD::VLD2LN_UPD; |
| 6326 | NumVecs = 2; isLaneOp = true; break; |
| 6327 | case Intrinsic::arm_neon_vld3lane: NewOpc = ARMISD::VLD3LN_UPD; |
| 6328 | NumVecs = 3; isLaneOp = true; break; |
| 6329 | case Intrinsic::arm_neon_vld4lane: NewOpc = ARMISD::VLD4LN_UPD; |
| 6330 | NumVecs = 4; isLaneOp = true; break; |
| 6331 | case Intrinsic::arm_neon_vst1: NewOpc = ARMISD::VST1_UPD; |
| 6332 | NumVecs = 1; isLoad = false; break; |
| 6333 | case Intrinsic::arm_neon_vst2: NewOpc = ARMISD::VST2_UPD; |
| 6334 | NumVecs = 2; isLoad = false; break; |
| 6335 | case Intrinsic::arm_neon_vst3: NewOpc = ARMISD::VST3_UPD; |
| 6336 | NumVecs = 3; isLoad = false; break; |
| 6337 | case Intrinsic::arm_neon_vst4: NewOpc = ARMISD::VST4_UPD; |
| 6338 | NumVecs = 4; isLoad = false; break; |
| 6339 | case Intrinsic::arm_neon_vst2lane: NewOpc = ARMISD::VST2LN_UPD; |
| 6340 | NumVecs = 2; isLoad = false; isLaneOp = true; break; |
| 6341 | case Intrinsic::arm_neon_vst3lane: NewOpc = ARMISD::VST3LN_UPD; |
| 6342 | NumVecs = 3; isLoad = false; isLaneOp = true; break; |
| 6343 | case Intrinsic::arm_neon_vst4lane: NewOpc = ARMISD::VST4LN_UPD; |
| 6344 | NumVecs = 4; isLoad = false; isLaneOp = true; break; |
| 6345 | } |
| 6346 | } else { |
| 6347 | isLaneOp = true; |
| 6348 | switch (N->getOpcode()) { |
| 6349 | default: assert(0 && "unexpected opcode for Neon base update"); |
| 6350 | case ARMISD::VLD2DUP: NewOpc = ARMISD::VLD2DUP_UPD; NumVecs = 2; break; |
| 6351 | case ARMISD::VLD3DUP: NewOpc = ARMISD::VLD3DUP_UPD; NumVecs = 3; break; |
| 6352 | case ARMISD::VLD4DUP: NewOpc = ARMISD::VLD4DUP_UPD; NumVecs = 4; break; |
| 6353 | } |
| 6354 | } |
| 6355 | |
| 6356 | // Find the size of memory referenced by the load/store. |
| 6357 | EVT VecTy; |
| 6358 | if (isLoad) |
| 6359 | VecTy = N->getValueType(0); |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6360 | else |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6361 | VecTy = N->getOperand(AddrOpIdx+1).getValueType(); |
| 6362 | unsigned NumBytes = NumVecs * VecTy.getSizeInBits() / 8; |
| 6363 | if (isLaneOp) |
| 6364 | NumBytes /= VecTy.getVectorNumElements(); |
| 6365 | |
| 6366 | // If the increment is a constant, it must match the memory ref size. |
| 6367 | SDValue Inc = User->getOperand(User->getOperand(0) == Addr ? 1 : 0); |
| 6368 | if (ConstantSDNode *CInc = dyn_cast<ConstantSDNode>(Inc.getNode())) { |
| 6369 | uint64_t IncVal = CInc->getZExtValue(); |
| 6370 | if (IncVal != NumBytes) |
| 6371 | continue; |
| 6372 | } else if (NumBytes >= 3 * 16) { |
| 6373 | // VLD3/4 and VST3/4 for 128-bit vectors are implemented with two |
| 6374 | // separate instructions that make it harder to use a non-constant update. |
| 6375 | continue; |
| 6376 | } |
| 6377 | |
| 6378 | // Create the new updating load/store node. |
| 6379 | EVT Tys[6]; |
| 6380 | unsigned NumResultVecs = (isLoad ? NumVecs : 0); |
| 6381 | unsigned n; |
| 6382 | for (n = 0; n < NumResultVecs; ++n) |
| 6383 | Tys[n] = VecTy; |
| 6384 | Tys[n++] = MVT::i32; |
| 6385 | Tys[n] = MVT::Other; |
| 6386 | SDVTList SDTys = DAG.getVTList(Tys, NumResultVecs+2); |
| 6387 | SmallVector<SDValue, 8> Ops; |
| 6388 | Ops.push_back(N->getOperand(0)); // incoming chain |
| 6389 | Ops.push_back(N->getOperand(AddrOpIdx)); |
| 6390 | Ops.push_back(Inc); |
| 6391 | for (unsigned i = AddrOpIdx + 1; i < N->getNumOperands(); ++i) { |
| 6392 | Ops.push_back(N->getOperand(i)); |
| 6393 | } |
| 6394 | MemIntrinsicSDNode *MemInt = cast<MemIntrinsicSDNode>(N); |
| 6395 | SDValue UpdN = DAG.getMemIntrinsicNode(NewOpc, N->getDebugLoc(), SDTys, |
| 6396 | Ops.data(), Ops.size(), |
| 6397 | MemInt->getMemoryVT(), |
| 6398 | MemInt->getMemOperand()); |
| 6399 | |
| 6400 | // Update the uses. |
| 6401 | std::vector<SDValue> NewResults; |
| 6402 | for (unsigned i = 0; i < NumResultVecs; ++i) { |
| 6403 | NewResults.push_back(SDValue(UpdN.getNode(), i)); |
| 6404 | } |
| 6405 | NewResults.push_back(SDValue(UpdN.getNode(), NumResultVecs+1)); // chain |
| 6406 | DCI.CombineTo(N, NewResults); |
| 6407 | DCI.CombineTo(User, SDValue(UpdN.getNode(), NumResultVecs)); |
| 6408 | |
| 6409 | break; |
Owen Anderson | 7670601 | 2011-04-05 21:48:57 +0000 | [diff] [blame] | 6410 | } |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 6411 | return SDValue(); |
| 6412 | } |
| 6413 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6414 | /// CombineVLDDUP - For a VDUPLANE node N, check if its source operand is a |
| 6415 | /// vldN-lane (N > 1) intrinsic, and if all the other uses of that intrinsic |
| 6416 | /// are also VDUPLANEs. If so, combine them to a vldN-dup operation and |
| 6417 | /// return true. |
| 6418 | static bool CombineVLDDUP(SDNode *N, TargetLowering::DAGCombinerInfo &DCI) { |
| 6419 | SelectionDAG &DAG = DCI.DAG; |
| 6420 | EVT VT = N->getValueType(0); |
| 6421 | // vldN-dup instructions only support 64-bit vectors for N > 1. |
| 6422 | if (!VT.is64BitVector()) |
| 6423 | return false; |
| 6424 | |
| 6425 | // Check if the VDUPLANE operand is a vldN-dup intrinsic. |
| 6426 | SDNode *VLD = N->getOperand(0).getNode(); |
| 6427 | if (VLD->getOpcode() != ISD::INTRINSIC_W_CHAIN) |
| 6428 | return false; |
| 6429 | unsigned NumVecs = 0; |
| 6430 | unsigned NewOpc = 0; |
| 6431 | unsigned IntNo = cast<ConstantSDNode>(VLD->getOperand(1))->getZExtValue(); |
| 6432 | if (IntNo == Intrinsic::arm_neon_vld2lane) { |
| 6433 | NumVecs = 2; |
| 6434 | NewOpc = ARMISD::VLD2DUP; |
| 6435 | } else if (IntNo == Intrinsic::arm_neon_vld3lane) { |
| 6436 | NumVecs = 3; |
| 6437 | NewOpc = ARMISD::VLD3DUP; |
| 6438 | } else if (IntNo == Intrinsic::arm_neon_vld4lane) { |
| 6439 | NumVecs = 4; |
| 6440 | NewOpc = ARMISD::VLD4DUP; |
| 6441 | } else { |
| 6442 | return false; |
| 6443 | } |
| 6444 | |
| 6445 | // First check that all the vldN-lane uses are VDUPLANEs and that the lane |
| 6446 | // numbers match the load. |
| 6447 | unsigned VLDLaneNo = |
| 6448 | cast<ConstantSDNode>(VLD->getOperand(NumVecs+3))->getZExtValue(); |
| 6449 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 6450 | UI != UE; ++UI) { |
| 6451 | // Ignore uses of the chain result. |
| 6452 | if (UI.getUse().getResNo() == NumVecs) |
| 6453 | continue; |
| 6454 | SDNode *User = *UI; |
| 6455 | if (User->getOpcode() != ARMISD::VDUPLANE || |
| 6456 | VLDLaneNo != cast<ConstantSDNode>(User->getOperand(1))->getZExtValue()) |
| 6457 | return false; |
| 6458 | } |
| 6459 | |
| 6460 | // Create the vldN-dup node. |
| 6461 | EVT Tys[5]; |
| 6462 | unsigned n; |
| 6463 | for (n = 0; n < NumVecs; ++n) |
| 6464 | Tys[n] = VT; |
| 6465 | Tys[n] = MVT::Other; |
| 6466 | SDVTList SDTys = DAG.getVTList(Tys, NumVecs+1); |
| 6467 | SDValue Ops[] = { VLD->getOperand(0), VLD->getOperand(2) }; |
| 6468 | MemIntrinsicSDNode *VLDMemInt = cast<MemIntrinsicSDNode>(VLD); |
| 6469 | SDValue VLDDup = DAG.getMemIntrinsicNode(NewOpc, VLD->getDebugLoc(), SDTys, |
| 6470 | Ops, 2, VLDMemInt->getMemoryVT(), |
| 6471 | VLDMemInt->getMemOperand()); |
| 6472 | |
| 6473 | // Update the uses. |
| 6474 | for (SDNode::use_iterator UI = VLD->use_begin(), UE = VLD->use_end(); |
| 6475 | UI != UE; ++UI) { |
| 6476 | unsigned ResNo = UI.getUse().getResNo(); |
| 6477 | // Ignore uses of the chain result. |
| 6478 | if (ResNo == NumVecs) |
| 6479 | continue; |
| 6480 | SDNode *User = *UI; |
| 6481 | DCI.CombineTo(User, SDValue(VLDDup.getNode(), ResNo)); |
| 6482 | } |
| 6483 | |
| 6484 | // Now the vldN-lane intrinsic is dead except for its chain result. |
| 6485 | // Update uses of the chain. |
| 6486 | std::vector<SDValue> VLDDupResults; |
| 6487 | for (unsigned n = 0; n < NumVecs; ++n) |
| 6488 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), n)); |
| 6489 | VLDDupResults.push_back(SDValue(VLDDup.getNode(), NumVecs)); |
| 6490 | DCI.CombineTo(VLD, VLDDupResults); |
| 6491 | |
| 6492 | return true; |
| 6493 | } |
| 6494 | |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6495 | /// PerformVDUPLANECombine - Target-specific dag combine xforms for |
| 6496 | /// ARMISD::VDUPLANE. |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6497 | static SDValue PerformVDUPLANECombine(SDNode *N, |
| 6498 | TargetLowering::DAGCombinerInfo &DCI) { |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6499 | SDValue Op = N->getOperand(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6500 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6501 | // If the source is a vldN-lane (N > 1) intrinsic, and all the other uses |
| 6502 | // of that intrinsic are also VDUPLANEs, combine them to a vldN-dup operation. |
| 6503 | if (CombineVLDDUP(N, DCI)) |
| 6504 | return SDValue(N, 0); |
| 6505 | |
| 6506 | // If the source is already a VMOVIMM or VMVNIMM splat, the VDUPLANE is |
| 6507 | // redundant. Ignore bit_converts for now; element sizes are checked below. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6508 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6509 | Op = Op.getOperand(0); |
Bob Wilson | 7e3f0d2 | 2010-07-14 06:31:50 +0000 | [diff] [blame] | 6510 | if (Op.getOpcode() != ARMISD::VMOVIMM && Op.getOpcode() != ARMISD::VMVNIMM) |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6511 | return SDValue(); |
| 6512 | |
| 6513 | // Make sure the VMOV element size is not bigger than the VDUPLANE elements. |
| 6514 | unsigned EltSize = Op.getValueType().getVectorElementType().getSizeInBits(); |
| 6515 | // The canonical VMOV for a zero vector uses a 32-bit element size. |
| 6516 | unsigned Imm = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue(); |
| 6517 | unsigned EltBits; |
| 6518 | if (ARM_AM::decodeNEONModImm(Imm, EltBits) == 0) |
| 6519 | EltSize = 8; |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6520 | EVT VT = N->getValueType(0); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6521 | if (EltSize > VT.getVectorElementType().getSizeInBits()) |
| 6522 | return SDValue(); |
| 6523 | |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 6524 | return DCI.DAG.getNode(ISD::BITCAST, N->getDebugLoc(), VT, Op); |
Bob Wilson | 9e82bf1 | 2010-07-14 01:22:12 +0000 | [diff] [blame] | 6525 | } |
| 6526 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6527 | // isConstVecPow2 - Return true if each vector element is a power of 2, all |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6528 | // elements are the same constant, C, and Log2(C) ranges from 1 to 32. |
| 6529 | static bool isConstVecPow2(SDValue ConstVec, bool isSigned, uint64_t &C) |
| 6530 | { |
Chad Rosier | 118c9a0 | 2011-06-28 17:26:57 +0000 | [diff] [blame] | 6531 | integerPart cN; |
| 6532 | integerPart c0 = 0; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6533 | for (unsigned I = 0, E = ConstVec.getValueType().getVectorNumElements(); |
| 6534 | I != E; I++) { |
| 6535 | ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(ConstVec.getOperand(I)); |
| 6536 | if (!C) |
| 6537 | return false; |
| 6538 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6539 | bool isExact; |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6540 | APFloat APF = C->getValueAPF(); |
| 6541 | if (APF.convertToInteger(&cN, 64, isSigned, APFloat::rmTowardZero, &isExact) |
| 6542 | != APFloat::opOK || !isExact) |
| 6543 | return false; |
| 6544 | |
| 6545 | c0 = (I == 0) ? cN : c0; |
| 6546 | if (!isPowerOf2_64(cN) || c0 != cN || Log2_64(c0) < 1 || Log2_64(c0) > 32) |
| 6547 | return false; |
| 6548 | } |
| 6549 | C = c0; |
| 6550 | return true; |
| 6551 | } |
| 6552 | |
| 6553 | /// PerformVCVTCombine - VCVT (floating-point to fixed-point, Advanced SIMD) |
| 6554 | /// can replace combinations of VMUL and VCVT (floating-point to integer) |
| 6555 | /// when the VMUL has a constant operand that is a power of 2. |
| 6556 | /// |
| 6557 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 6558 | /// vmul.f32 d16, d17, d16 |
| 6559 | /// vcvt.s32.f32 d16, d16 |
| 6560 | /// becomes: |
| 6561 | /// vcvt.s32.f32 d16, d16, #3 |
| 6562 | static SDValue PerformVCVTCombine(SDNode *N, |
| 6563 | TargetLowering::DAGCombinerInfo &DCI, |
| 6564 | const ARMSubtarget *Subtarget) { |
| 6565 | SelectionDAG &DAG = DCI.DAG; |
| 6566 | SDValue Op = N->getOperand(0); |
| 6567 | |
| 6568 | if (!Subtarget->hasNEON() || !Op.getValueType().isVector() || |
| 6569 | Op.getOpcode() != ISD::FMUL) |
| 6570 | return SDValue(); |
| 6571 | |
| 6572 | uint64_t C; |
| 6573 | SDValue N0 = Op->getOperand(0); |
| 6574 | SDValue ConstVec = Op->getOperand(1); |
| 6575 | bool isSigned = N->getOpcode() == ISD::FP_TO_SINT; |
| 6576 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6577 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6578 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 6579 | return SDValue(); |
| 6580 | |
| 6581 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfp2fxs : |
| 6582 | Intrinsic::arm_neon_vcvtfp2fxu; |
| 6583 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6584 | N->getValueType(0), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6585 | DAG.getConstant(IntrinsicOpcode, MVT::i32), N0, |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6586 | DAG.getConstant(Log2_64(C), MVT::i32)); |
| 6587 | } |
| 6588 | |
| 6589 | /// PerformVDIVCombine - VCVT (fixed-point to floating-point, Advanced SIMD) |
| 6590 | /// can replace combinations of VCVT (integer to floating-point) and VDIV |
| 6591 | /// when the VDIV has a constant operand that is a power of 2. |
| 6592 | /// |
| 6593 | /// Example (assume d17 = <float 8.000000e+00, float 8.000000e+00>): |
| 6594 | /// vcvt.f32.s32 d16, d16 |
| 6595 | /// vdiv.f32 d16, d17, d16 |
| 6596 | /// becomes: |
| 6597 | /// vcvt.f32.s32 d16, d16, #3 |
| 6598 | static SDValue PerformVDIVCombine(SDNode *N, |
| 6599 | TargetLowering::DAGCombinerInfo &DCI, |
| 6600 | const ARMSubtarget *Subtarget) { |
| 6601 | SelectionDAG &DAG = DCI.DAG; |
| 6602 | SDValue Op = N->getOperand(0); |
| 6603 | unsigned OpOpcode = Op.getNode()->getOpcode(); |
| 6604 | |
| 6605 | if (!Subtarget->hasNEON() || !N->getValueType(0).isVector() || |
| 6606 | (OpOpcode != ISD::SINT_TO_FP && OpOpcode != ISD::UINT_TO_FP)) |
| 6607 | return SDValue(); |
| 6608 | |
| 6609 | uint64_t C; |
| 6610 | SDValue ConstVec = N->getOperand(1); |
| 6611 | bool isSigned = OpOpcode == ISD::SINT_TO_FP; |
| 6612 | |
| 6613 | if (ConstVec.getOpcode() != ISD::BUILD_VECTOR || |
| 6614 | !isConstVecPow2(ConstVec, isSigned, C)) |
| 6615 | return SDValue(); |
| 6616 | |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6617 | unsigned IntrinsicOpcode = isSigned ? Intrinsic::arm_neon_vcvtfxs2fp : |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6618 | Intrinsic::arm_neon_vcvtfxu2fp; |
| 6619 | return DAG.getNode(ISD::INTRINSIC_WO_CHAIN, N->getDebugLoc(), |
| 6620 | Op.getValueType(), |
Eric Christopher | fa6f591 | 2011-06-29 21:10:36 +0000 | [diff] [blame] | 6621 | DAG.getConstant(IntrinsicOpcode, MVT::i32), |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 6622 | Op.getOperand(0), DAG.getConstant(Log2_64(C), MVT::i32)); |
| 6623 | } |
| 6624 | |
| 6625 | /// Getvshiftimm - Check if this is a valid build_vector for the immediate |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6626 | /// operand of a vector shift operation, where all the elements of the |
| 6627 | /// build_vector must have the same constant integer value. |
| 6628 | static bool getVShiftImm(SDValue Op, unsigned ElementBits, int64_t &Cnt) { |
| 6629 | // Ignore bit_converts. |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 6630 | while (Op.getOpcode() == ISD::BITCAST) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6631 | Op = Op.getOperand(0); |
| 6632 | BuildVectorSDNode *BVN = dyn_cast<BuildVectorSDNode>(Op.getNode()); |
| 6633 | APInt SplatBits, SplatUndef; |
| 6634 | unsigned SplatBitSize; |
| 6635 | bool HasAnyUndefs; |
| 6636 | if (! BVN || ! BVN->isConstantSplat(SplatBits, SplatUndef, SplatBitSize, |
| 6637 | HasAnyUndefs, ElementBits) || |
| 6638 | SplatBitSize > ElementBits) |
| 6639 | return false; |
| 6640 | Cnt = SplatBits.getSExtValue(); |
| 6641 | return true; |
| 6642 | } |
| 6643 | |
| 6644 | /// isVShiftLImm - Check if this is a valid build_vector for the immediate |
| 6645 | /// operand of a vector shift left operation. That value must be in the range: |
| 6646 | /// 0 <= Value < ElementBits for a left shift; or |
| 6647 | /// 0 <= Value <= ElementBits for a long left shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6648 | static bool isVShiftLImm(SDValue Op, EVT VT, bool isLong, int64_t &Cnt) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6649 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6650 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6651 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6652 | return false; |
| 6653 | return (Cnt >= 0 && (isLong ? Cnt-1 : Cnt) < ElementBits); |
| 6654 | } |
| 6655 | |
| 6656 | /// isVShiftRImm - Check if this is a valid build_vector for the immediate |
| 6657 | /// operand of a vector shift right operation. For a shift opcode, the value |
| 6658 | /// is positive, but for an intrinsic the value count must be negative. The |
| 6659 | /// absolute value must be in the range: |
| 6660 | /// 1 <= |Value| <= ElementBits for a right shift; or |
| 6661 | /// 1 <= |Value| <= ElementBits/2 for a narrow right shift. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6662 | static bool isVShiftRImm(SDValue Op, EVT VT, bool isNarrow, bool isIntrinsic, |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6663 | int64_t &Cnt) { |
| 6664 | assert(VT.isVector() && "vector shift count is not a vector type"); |
| 6665 | unsigned ElementBits = VT.getVectorElementType().getSizeInBits(); |
| 6666 | if (! getVShiftImm(Op, ElementBits, Cnt)) |
| 6667 | return false; |
| 6668 | if (isIntrinsic) |
| 6669 | Cnt = -Cnt; |
| 6670 | return (Cnt >= 1 && Cnt <= (isNarrow ? ElementBits/2 : ElementBits)); |
| 6671 | } |
| 6672 | |
| 6673 | /// PerformIntrinsicCombine - ARM-specific DAG combining for intrinsics. |
| 6674 | static SDValue PerformIntrinsicCombine(SDNode *N, SelectionDAG &DAG) { |
| 6675 | unsigned IntNo = cast<ConstantSDNode>(N->getOperand(0))->getZExtValue(); |
| 6676 | switch (IntNo) { |
| 6677 | default: |
| 6678 | // Don't do anything for most intrinsics. |
| 6679 | break; |
| 6680 | |
| 6681 | // Vector shifts: check for immediate versions and lower them. |
| 6682 | // Note: This is done during DAG combining instead of DAG legalizing because |
| 6683 | // the build_vectors for 64-bit vector element shift counts are generally |
| 6684 | // not legal, and it is hard to see their values after they get legalized to |
| 6685 | // loads from a constant pool. |
| 6686 | case Intrinsic::arm_neon_vshifts: |
| 6687 | case Intrinsic::arm_neon_vshiftu: |
| 6688 | case Intrinsic::arm_neon_vshiftls: |
| 6689 | case Intrinsic::arm_neon_vshiftlu: |
| 6690 | case Intrinsic::arm_neon_vshiftn: |
| 6691 | case Intrinsic::arm_neon_vrshifts: |
| 6692 | case Intrinsic::arm_neon_vrshiftu: |
| 6693 | case Intrinsic::arm_neon_vrshiftn: |
| 6694 | case Intrinsic::arm_neon_vqshifts: |
| 6695 | case Intrinsic::arm_neon_vqshiftu: |
| 6696 | case Intrinsic::arm_neon_vqshiftsu: |
| 6697 | case Intrinsic::arm_neon_vqshiftns: |
| 6698 | case Intrinsic::arm_neon_vqshiftnu: |
| 6699 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6700 | case Intrinsic::arm_neon_vqrshiftns: |
| 6701 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6702 | case Intrinsic::arm_neon_vqrshiftnsu: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6703 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6704 | int64_t Cnt; |
| 6705 | unsigned VShiftOpc = 0; |
| 6706 | |
| 6707 | switch (IntNo) { |
| 6708 | case Intrinsic::arm_neon_vshifts: |
| 6709 | case Intrinsic::arm_neon_vshiftu: |
| 6710 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) { |
| 6711 | VShiftOpc = ARMISD::VSHL; |
| 6712 | break; |
| 6713 | } |
| 6714 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) { |
| 6715 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshifts ? |
| 6716 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6717 | break; |
| 6718 | } |
| 6719 | return SDValue(); |
| 6720 | |
| 6721 | case Intrinsic::arm_neon_vshiftls: |
| 6722 | case Intrinsic::arm_neon_vshiftlu: |
| 6723 | if (isVShiftLImm(N->getOperand(2), VT, true, Cnt)) |
| 6724 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6725 | llvm_unreachable("invalid shift count for vshll intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6726 | |
| 6727 | case Intrinsic::arm_neon_vrshifts: |
| 6728 | case Intrinsic::arm_neon_vrshiftu: |
| 6729 | if (isVShiftRImm(N->getOperand(2), VT, false, true, Cnt)) |
| 6730 | break; |
| 6731 | return SDValue(); |
| 6732 | |
| 6733 | case Intrinsic::arm_neon_vqshifts: |
| 6734 | case Intrinsic::arm_neon_vqshiftu: |
| 6735 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6736 | break; |
| 6737 | return SDValue(); |
| 6738 | |
| 6739 | case Intrinsic::arm_neon_vqshiftsu: |
| 6740 | if (isVShiftLImm(N->getOperand(2), VT, false, Cnt)) |
| 6741 | break; |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6742 | llvm_unreachable("invalid shift count for vqshlu intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6743 | |
| 6744 | case Intrinsic::arm_neon_vshiftn: |
| 6745 | case Intrinsic::arm_neon_vrshiftn: |
| 6746 | case Intrinsic::arm_neon_vqshiftns: |
| 6747 | case Intrinsic::arm_neon_vqshiftnu: |
| 6748 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6749 | case Intrinsic::arm_neon_vqrshiftns: |
| 6750 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6751 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6752 | // Narrowing shifts require an immediate right shift. |
| 6753 | if (isVShiftRImm(N->getOperand(2), VT, true, true, Cnt)) |
| 6754 | break; |
Jim Grosbach | 18f30e6 | 2010-06-02 21:53:11 +0000 | [diff] [blame] | 6755 | llvm_unreachable("invalid shift count for narrowing vector shift " |
| 6756 | "intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6757 | |
| 6758 | default: |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6759 | llvm_unreachable("unhandled vector shift"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6760 | } |
| 6761 | |
| 6762 | switch (IntNo) { |
| 6763 | case Intrinsic::arm_neon_vshifts: |
| 6764 | case Intrinsic::arm_neon_vshiftu: |
| 6765 | // Opcode already set above. |
| 6766 | break; |
| 6767 | case Intrinsic::arm_neon_vshiftls: |
| 6768 | case Intrinsic::arm_neon_vshiftlu: |
| 6769 | if (Cnt == VT.getVectorElementType().getSizeInBits()) |
| 6770 | VShiftOpc = ARMISD::VSHLLi; |
| 6771 | else |
| 6772 | VShiftOpc = (IntNo == Intrinsic::arm_neon_vshiftls ? |
| 6773 | ARMISD::VSHLLs : ARMISD::VSHLLu); |
| 6774 | break; |
| 6775 | case Intrinsic::arm_neon_vshiftn: |
| 6776 | VShiftOpc = ARMISD::VSHRN; break; |
| 6777 | case Intrinsic::arm_neon_vrshifts: |
| 6778 | VShiftOpc = ARMISD::VRSHRs; break; |
| 6779 | case Intrinsic::arm_neon_vrshiftu: |
| 6780 | VShiftOpc = ARMISD::VRSHRu; break; |
| 6781 | case Intrinsic::arm_neon_vrshiftn: |
| 6782 | VShiftOpc = ARMISD::VRSHRN; break; |
| 6783 | case Intrinsic::arm_neon_vqshifts: |
| 6784 | VShiftOpc = ARMISD::VQSHLs; break; |
| 6785 | case Intrinsic::arm_neon_vqshiftu: |
| 6786 | VShiftOpc = ARMISD::VQSHLu; break; |
| 6787 | case Intrinsic::arm_neon_vqshiftsu: |
| 6788 | VShiftOpc = ARMISD::VQSHLsu; break; |
| 6789 | case Intrinsic::arm_neon_vqshiftns: |
| 6790 | VShiftOpc = ARMISD::VQSHRNs; break; |
| 6791 | case Intrinsic::arm_neon_vqshiftnu: |
| 6792 | VShiftOpc = ARMISD::VQSHRNu; break; |
| 6793 | case Intrinsic::arm_neon_vqshiftnsu: |
| 6794 | VShiftOpc = ARMISD::VQSHRNsu; break; |
| 6795 | case Intrinsic::arm_neon_vqrshiftns: |
| 6796 | VShiftOpc = ARMISD::VQRSHRNs; break; |
| 6797 | case Intrinsic::arm_neon_vqrshiftnu: |
| 6798 | VShiftOpc = ARMISD::VQRSHRNu; break; |
| 6799 | case Intrinsic::arm_neon_vqrshiftnsu: |
| 6800 | VShiftOpc = ARMISD::VQRSHRNsu; break; |
| 6801 | } |
| 6802 | |
| 6803 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6804 | N->getOperand(1), DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6805 | } |
| 6806 | |
| 6807 | case Intrinsic::arm_neon_vshiftins: { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6808 | EVT VT = N->getOperand(1).getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6809 | int64_t Cnt; |
| 6810 | unsigned VShiftOpc = 0; |
| 6811 | |
| 6812 | if (isVShiftLImm(N->getOperand(3), VT, false, Cnt)) |
| 6813 | VShiftOpc = ARMISD::VSLI; |
| 6814 | else if (isVShiftRImm(N->getOperand(3), VT, false, true, Cnt)) |
| 6815 | VShiftOpc = ARMISD::VSRI; |
| 6816 | else { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6817 | llvm_unreachable("invalid shift count for vsli/vsri intrinsic"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6818 | } |
| 6819 | |
| 6820 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), N->getValueType(0), |
| 6821 | N->getOperand(1), N->getOperand(2), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6822 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6823 | } |
| 6824 | |
| 6825 | case Intrinsic::arm_neon_vqrshifts: |
| 6826 | case Intrinsic::arm_neon_vqrshiftu: |
| 6827 | // No immediate versions of these to check for. |
| 6828 | break; |
| 6829 | } |
| 6830 | |
| 6831 | return SDValue(); |
| 6832 | } |
| 6833 | |
| 6834 | /// PerformShiftCombine - Checks for immediate versions of vector shifts and |
| 6835 | /// lowers them. As with the vector shift intrinsics, this is done during DAG |
| 6836 | /// combining instead of DAG legalizing because the build_vectors for 64-bit |
| 6837 | /// vector element shift counts are generally not legal, and it is hard to see |
| 6838 | /// their values after they get legalized to loads from a constant pool. |
| 6839 | static SDValue PerformShiftCombine(SDNode *N, SelectionDAG &DAG, |
| 6840 | const ARMSubtarget *ST) { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6841 | EVT VT = N->getValueType(0); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6842 | |
| 6843 | // Nothing to be done for scalar shifts. |
Tanya Lattner | 9684a7c | 2010-11-18 22:06:46 +0000 | [diff] [blame] | 6844 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6845 | if (!VT.isVector() || !TLI.isTypeLegal(VT)) |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6846 | return SDValue(); |
| 6847 | |
| 6848 | assert(ST->hasNEON() && "unexpected vector shift"); |
| 6849 | int64_t Cnt; |
| 6850 | |
| 6851 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6852 | default: llvm_unreachable("unexpected shift opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6853 | |
| 6854 | case ISD::SHL: |
| 6855 | if (isVShiftLImm(N->getOperand(1), VT, false, Cnt)) |
| 6856 | return DAG.getNode(ARMISD::VSHL, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6857 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6858 | break; |
| 6859 | |
| 6860 | case ISD::SRA: |
| 6861 | case ISD::SRL: |
| 6862 | if (isVShiftRImm(N->getOperand(1), VT, false, false, Cnt)) { |
| 6863 | unsigned VShiftOpc = (N->getOpcode() == ISD::SRA ? |
| 6864 | ARMISD::VSHRs : ARMISD::VSHRu); |
| 6865 | return DAG.getNode(VShiftOpc, N->getDebugLoc(), VT, N->getOperand(0), |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6866 | DAG.getConstant(Cnt, MVT::i32)); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6867 | } |
| 6868 | } |
| 6869 | return SDValue(); |
| 6870 | } |
| 6871 | |
| 6872 | /// PerformExtendCombine - Target-specific DAG combining for ISD::SIGN_EXTEND, |
| 6873 | /// ISD::ZERO_EXTEND, and ISD::ANY_EXTEND. |
| 6874 | static SDValue PerformExtendCombine(SDNode *N, SelectionDAG &DAG, |
| 6875 | const ARMSubtarget *ST) { |
| 6876 | SDValue N0 = N->getOperand(0); |
| 6877 | |
| 6878 | // Check for sign- and zero-extensions of vector extract operations of 8- |
| 6879 | // and 16-bit vector elements. NEON supports these directly. They are |
| 6880 | // handled during DAG combining because type legalization will promote them |
| 6881 | // to 32-bit types and it is messy to recognize the operations after that. |
| 6882 | if (ST->hasNEON() && N0.getOpcode() == ISD::EXTRACT_VECTOR_ELT) { |
| 6883 | SDValue Vec = N0.getOperand(0); |
| 6884 | SDValue Lane = N0.getOperand(1); |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 6885 | EVT VT = N->getValueType(0); |
| 6886 | EVT EltVT = N0.getValueType(); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6887 | const TargetLowering &TLI = DAG.getTargetLoweringInfo(); |
| 6888 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 6889 | if (VT == MVT::i32 && |
| 6890 | (EltVT == MVT::i8 || EltVT == MVT::i16) && |
Bob Wilson | 3468c2e | 2010-11-03 16:24:50 +0000 | [diff] [blame] | 6891 | TLI.isTypeLegal(Vec.getValueType()) && |
| 6892 | isa<ConstantSDNode>(Lane)) { |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6893 | |
| 6894 | unsigned Opc = 0; |
| 6895 | switch (N->getOpcode()) { |
Torok Edwin | c23197a | 2009-07-14 16:55:14 +0000 | [diff] [blame] | 6896 | default: llvm_unreachable("unexpected opcode"); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 6897 | case ISD::SIGN_EXTEND: |
| 6898 | Opc = ARMISD::VGETLANEs; |
| 6899 | break; |
| 6900 | case ISD::ZERO_EXTEND: |
| 6901 | case ISD::ANY_EXTEND: |
| 6902 | Opc = ARMISD::VGETLANEu; |
| 6903 | break; |
| 6904 | } |
| 6905 | return DAG.getNode(Opc, N->getDebugLoc(), VT, Vec, Lane); |
| 6906 | } |
| 6907 | } |
| 6908 | |
| 6909 | return SDValue(); |
| 6910 | } |
| 6911 | |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6912 | /// PerformSELECT_CCCombine - Target-specific DAG combining for ISD::SELECT_CC |
| 6913 | /// to match f32 max/min patterns to use NEON vmax/vmin instructions. |
| 6914 | static SDValue PerformSELECT_CCCombine(SDNode *N, SelectionDAG &DAG, |
| 6915 | const ARMSubtarget *ST) { |
| 6916 | // If the target supports NEON, try to use vmax/vmin instructions for f32 |
Evan Cheng | 60108e9 | 2010-07-15 22:07:12 +0000 | [diff] [blame] | 6917 | // selects like "x < y ? x : y". Unless the NoNaNsFPMath option is set, |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6918 | // be careful about NaNs: NEON's vmax/vmin return NaN if either operand is |
| 6919 | // a NaN; only do the transformation when it matches that behavior. |
| 6920 | |
| 6921 | // For now only do this when using NEON for FP operations; if using VFP, it |
| 6922 | // is not obvious that the benefit outweighs the cost of switching to the |
| 6923 | // NEON pipeline. |
| 6924 | if (!ST->hasNEON() || !ST->useNEONForSinglePrecisionFP() || |
| 6925 | N->getValueType(0) != MVT::f32) |
| 6926 | return SDValue(); |
| 6927 | |
| 6928 | SDValue CondLHS = N->getOperand(0); |
| 6929 | SDValue CondRHS = N->getOperand(1); |
| 6930 | SDValue LHS = N->getOperand(2); |
| 6931 | SDValue RHS = N->getOperand(3); |
| 6932 | ISD::CondCode CC = cast<CondCodeSDNode>(N->getOperand(4))->get(); |
| 6933 | |
| 6934 | unsigned Opcode = 0; |
| 6935 | bool IsReversed; |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6936 | if (DAG.isEqualTo(LHS, CondLHS) && DAG.isEqualTo(RHS, CondRHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6937 | IsReversed = false; // x CC y ? x : y |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6938 | } else if (DAG.isEqualTo(LHS, CondRHS) && DAG.isEqualTo(RHS, CondLHS)) { |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6939 | IsReversed = true ; // x CC y ? y : x |
| 6940 | } else { |
| 6941 | return SDValue(); |
| 6942 | } |
| 6943 | |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6944 | bool IsUnordered; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6945 | switch (CC) { |
| 6946 | default: break; |
| 6947 | case ISD::SETOLT: |
| 6948 | case ISD::SETOLE: |
| 6949 | case ISD::SETLT: |
| 6950 | case ISD::SETLE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6951 | case ISD::SETULT: |
| 6952 | case ISD::SETULE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6953 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6954 | // be the RHS, but vmin(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6955 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6956 | IsUnordered = (CC == ISD::SETULT || CC == ISD::SETULE); |
| 6957 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6958 | break; |
| 6959 | // For less-than-or-equal comparisons, "+0 <= -0" will be true but vmin |
| 6960 | // will return -0, so vmin can only be used for unsafe math or if one of |
| 6961 | // the operands is known to be nonzero. |
| 6962 | if ((CC == ISD::SETLE || CC == ISD::SETOLE || CC == ISD::SETULE) && |
| 6963 | !UnsafeFPMath && |
| 6964 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6965 | break; |
| 6966 | Opcode = IsReversed ? ARMISD::FMAX : ARMISD::FMIN; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6967 | break; |
| 6968 | |
| 6969 | case ISD::SETOGT: |
| 6970 | case ISD::SETOGE: |
| 6971 | case ISD::SETGT: |
| 6972 | case ISD::SETGE: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6973 | case ISD::SETUGT: |
| 6974 | case ISD::SETUGE: |
Bob Wilson | e742bb5 | 2010-02-24 22:15:53 +0000 | [diff] [blame] | 6975 | // If LHS is NaN, an ordered comparison will be false and the result will |
| 6976 | // be the RHS, but vmax(NaN, RHS) = NaN. Avoid this by checking that LHS |
| 6977 | // != NaN. Likewise, for unordered comparisons, check for RHS != NaN. |
| 6978 | IsUnordered = (CC == ISD::SETUGT || CC == ISD::SETUGE); |
| 6979 | if (!DAG.isKnownNeverNaN(IsUnordered ? RHS : LHS)) |
| 6980 | break; |
| 6981 | // For greater-than-or-equal comparisons, "-0 >= +0" will be true but vmax |
| 6982 | // will return +0, so vmax can only be used for unsafe math or if one of |
| 6983 | // the operands is known to be nonzero. |
| 6984 | if ((CC == ISD::SETGE || CC == ISD::SETOGE || CC == ISD::SETUGE) && |
| 6985 | !UnsafeFPMath && |
| 6986 | !(DAG.isKnownNeverZero(LHS) || DAG.isKnownNeverZero(RHS))) |
| 6987 | break; |
| 6988 | Opcode = IsReversed ? ARMISD::FMIN : ARMISD::FMAX; |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 6989 | break; |
| 6990 | } |
| 6991 | |
| 6992 | if (!Opcode) |
| 6993 | return SDValue(); |
| 6994 | return DAG.getNode(Opcode, N->getDebugLoc(), N->getValueType(0), LHS, RHS); |
| 6995 | } |
| 6996 | |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 6997 | /// PerformCMOVCombine - Target-specific DAG combining for ARMISD::CMOV. |
| 6998 | SDValue |
| 6999 | ARMTargetLowering::PerformCMOVCombine(SDNode *N, SelectionDAG &DAG) const { |
| 7000 | SDValue Cmp = N->getOperand(4); |
| 7001 | if (Cmp.getOpcode() != ARMISD::CMPZ) |
| 7002 | // Only looking at EQ and NE cases. |
| 7003 | return SDValue(); |
| 7004 | |
| 7005 | EVT VT = N->getValueType(0); |
| 7006 | DebugLoc dl = N->getDebugLoc(); |
| 7007 | SDValue LHS = Cmp.getOperand(0); |
| 7008 | SDValue RHS = Cmp.getOperand(1); |
| 7009 | SDValue FalseVal = N->getOperand(0); |
| 7010 | SDValue TrueVal = N->getOperand(1); |
| 7011 | SDValue ARMcc = N->getOperand(2); |
| 7012 | ARMCC::CondCodes CC = (ARMCC::CondCodes)cast<ConstantSDNode>(ARMcc)->getZExtValue(); |
| 7013 | |
| 7014 | // Simplify |
| 7015 | // mov r1, r0 |
| 7016 | // cmp r1, x |
| 7017 | // mov r0, y |
| 7018 | // moveq r0, x |
| 7019 | // to |
| 7020 | // cmp r0, x |
| 7021 | // movne r0, y |
| 7022 | // |
| 7023 | // mov r1, r0 |
| 7024 | // cmp r1, x |
| 7025 | // mov r0, x |
| 7026 | // movne r0, y |
| 7027 | // to |
| 7028 | // cmp r0, x |
| 7029 | // movne r0, y |
| 7030 | /// FIXME: Turn this into a target neutral optimization? |
| 7031 | SDValue Res; |
| 7032 | if (CC == ARMCC::NE && FalseVal == RHS) { |
| 7033 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, TrueVal, ARMcc, |
| 7034 | N->getOperand(3), Cmp); |
| 7035 | } else if (CC == ARMCC::EQ && TrueVal == RHS) { |
| 7036 | SDValue ARMcc; |
| 7037 | SDValue NewCmp = getARMCmp(LHS, RHS, ISD::SETNE, ARMcc, DAG, dl); |
| 7038 | Res = DAG.getNode(ARMISD::CMOV, dl, VT, LHS, FalseVal, ARMcc, |
| 7039 | N->getOperand(3), NewCmp); |
| 7040 | } |
| 7041 | |
| 7042 | if (Res.getNode()) { |
| 7043 | APInt KnownZero, KnownOne; |
| 7044 | APInt Mask = APInt::getAllOnesValue(VT.getScalarType().getSizeInBits()); |
| 7045 | DAG.ComputeMaskedBits(SDValue(N,0), Mask, KnownZero, KnownOne); |
| 7046 | // Capture demanded bits information that would be otherwise lost. |
| 7047 | if (KnownZero == 0xfffffffe) |
| 7048 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 7049 | DAG.getValueType(MVT::i1)); |
| 7050 | else if (KnownZero == 0xffffff00) |
| 7051 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 7052 | DAG.getValueType(MVT::i8)); |
| 7053 | else if (KnownZero == 0xffff0000) |
| 7054 | Res = DAG.getNode(ISD::AssertZext, dl, MVT::i32, Res, |
| 7055 | DAG.getValueType(MVT::i16)); |
| 7056 | } |
| 7057 | |
| 7058 | return Res; |
| 7059 | } |
| 7060 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7061 | SDValue ARMTargetLowering::PerformDAGCombine(SDNode *N, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7062 | DAGCombinerInfo &DCI) const { |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 7063 | switch (N->getOpcode()) { |
| 7064 | default: break; |
Tanya Lattner | 189531f | 2011-06-14 23:48:48 +0000 | [diff] [blame] | 7065 | case ISD::ADD: return PerformADDCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7066 | case ISD::SUB: return PerformSUBCombine(N, DCI); |
Anton Korobeynikov | a9790d7 | 2010-05-15 18:16:59 +0000 | [diff] [blame] | 7067 | case ISD::MUL: return PerformMULCombine(N, DCI, Subtarget); |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7068 | case ISD::OR: return PerformORCombine(N, DCI, Subtarget); |
Owen Anderson | 080c092 | 2010-11-05 19:27:46 +0000 | [diff] [blame] | 7069 | case ISD::AND: return PerformANDCombine(N, DCI); |
Evan Cheng | 0c1aec1 | 2010-12-14 03:22:07 +0000 | [diff] [blame] | 7070 | case ARMISD::BFI: return PerformBFICombine(N, DCI); |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 7071 | case ARMISD::VMOVRRD: return PerformVMOVRRDCombine(N, DCI); |
Bob Wilson | 0b8ccb8 | 2010-09-22 22:09:21 +0000 | [diff] [blame] | 7072 | case ARMISD::VMOVDRR: return PerformVMOVDRRCombine(N, DCI.DAG); |
Bob Wilson | 3160090 | 2010-12-21 06:43:19 +0000 | [diff] [blame] | 7073 | case ISD::STORE: return PerformSTORECombine(N, DCI); |
| 7074 | case ISD::BUILD_VECTOR: return PerformBUILD_VECTORCombine(N, DCI); |
| 7075 | case ISD::INSERT_VECTOR_ELT: return PerformInsertEltCombine(N, DCI); |
Bob Wilson | f20700c | 2010-10-27 20:38:28 +0000 | [diff] [blame] | 7076 | case ISD::VECTOR_SHUFFLE: return PerformVECTOR_SHUFFLECombine(N, DCI.DAG); |
Bob Wilson | b1dfa7a | 2010-11-28 06:51:26 +0000 | [diff] [blame] | 7077 | case ARMISD::VDUPLANE: return PerformVDUPLANECombine(N, DCI); |
Chad Rosier | ef01edf | 2011-06-24 19:23:04 +0000 | [diff] [blame] | 7078 | case ISD::FP_TO_SINT: |
| 7079 | case ISD::FP_TO_UINT: return PerformVCVTCombine(N, DCI, Subtarget); |
| 7080 | case ISD::FDIV: return PerformVDIVCombine(N, DCI, Subtarget); |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7081 | case ISD::INTRINSIC_WO_CHAIN: return PerformIntrinsicCombine(N, DCI.DAG); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7082 | case ISD::SHL: |
| 7083 | case ISD::SRA: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7084 | case ISD::SRL: return PerformShiftCombine(N, DCI.DAG, Subtarget); |
Bob Wilson | 5bafff3 | 2009-06-22 23:27:02 +0000 | [diff] [blame] | 7085 | case ISD::SIGN_EXTEND: |
| 7086 | case ISD::ZERO_EXTEND: |
Bob Wilson | 9f6c4c1 | 2010-02-18 06:05:53 +0000 | [diff] [blame] | 7087 | case ISD::ANY_EXTEND: return PerformExtendCombine(N, DCI.DAG, Subtarget); |
| 7088 | case ISD::SELECT_CC: return PerformSELECT_CCCombine(N, DCI.DAG, Subtarget); |
Evan Cheng | e721f5c | 2011-07-13 00:42:17 +0000 | [diff] [blame] | 7089 | case ARMISD::CMOV: return PerformCMOVCombine(N, DCI.DAG); |
Bob Wilson | 1c3ef90 | 2011-02-07 17:43:21 +0000 | [diff] [blame] | 7090 | case ARMISD::VLD2DUP: |
| 7091 | case ARMISD::VLD3DUP: |
| 7092 | case ARMISD::VLD4DUP: |
| 7093 | return CombineBaseUpdate(N, DCI); |
| 7094 | case ISD::INTRINSIC_VOID: |
| 7095 | case ISD::INTRINSIC_W_CHAIN: |
| 7096 | switch (cast<ConstantSDNode>(N->getOperand(1))->getZExtValue()) { |
| 7097 | case Intrinsic::arm_neon_vld1: |
| 7098 | case Intrinsic::arm_neon_vld2: |
| 7099 | case Intrinsic::arm_neon_vld3: |
| 7100 | case Intrinsic::arm_neon_vld4: |
| 7101 | case Intrinsic::arm_neon_vld2lane: |
| 7102 | case Intrinsic::arm_neon_vld3lane: |
| 7103 | case Intrinsic::arm_neon_vld4lane: |
| 7104 | case Intrinsic::arm_neon_vst1: |
| 7105 | case Intrinsic::arm_neon_vst2: |
| 7106 | case Intrinsic::arm_neon_vst3: |
| 7107 | case Intrinsic::arm_neon_vst4: |
| 7108 | case Intrinsic::arm_neon_vst2lane: |
| 7109 | case Intrinsic::arm_neon_vst3lane: |
| 7110 | case Intrinsic::arm_neon_vst4lane: |
| 7111 | return CombineBaseUpdate(N, DCI); |
| 7112 | default: break; |
| 7113 | } |
| 7114 | break; |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 7115 | } |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7116 | return SDValue(); |
Chris Lattner | f1b1c5e | 2007-11-27 22:36:16 +0000 | [diff] [blame] | 7117 | } |
| 7118 | |
Evan Cheng | 31959b1 | 2011-02-02 01:06:55 +0000 | [diff] [blame] | 7119 | bool ARMTargetLowering::isDesirableToTransformToIntegerOp(unsigned Opc, |
| 7120 | EVT VT) const { |
| 7121 | return (VT == MVT::f32) && (Opc == ISD::LOAD || Opc == ISD::STORE); |
| 7122 | } |
| 7123 | |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 7124 | bool ARMTargetLowering::allowsUnalignedMemoryAccesses(EVT VT) const { |
Bob Wilson | 02aba73 | 2010-09-28 04:09:35 +0000 | [diff] [blame] | 7125 | if (!Subtarget->allowsUnalignedMem()) |
Bob Wilson | 86fe66d | 2010-06-25 04:12:31 +0000 | [diff] [blame] | 7126 | return false; |
Bill Wendling | af56634 | 2009-08-15 21:21:19 +0000 | [diff] [blame] | 7127 | |
| 7128 | switch (VT.getSimpleVT().SimpleTy) { |
| 7129 | default: |
| 7130 | return false; |
| 7131 | case MVT::i8: |
| 7132 | case MVT::i16: |
| 7133 | case MVT::i32: |
| 7134 | return true; |
| 7135 | // FIXME: VLD1 etc with standard alignment is legal. |
| 7136 | } |
| 7137 | } |
| 7138 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7139 | static bool isLegalT1AddressImmediate(int64_t V, EVT VT) { |
| 7140 | if (V < 0) |
| 7141 | return false; |
| 7142 | |
| 7143 | unsigned Scale = 1; |
| 7144 | switch (VT.getSimpleVT().SimpleTy) { |
| 7145 | default: return false; |
| 7146 | case MVT::i1: |
| 7147 | case MVT::i8: |
| 7148 | // Scale == 1; |
| 7149 | break; |
| 7150 | case MVT::i16: |
| 7151 | // Scale == 2; |
| 7152 | Scale = 2; |
| 7153 | break; |
| 7154 | case MVT::i32: |
| 7155 | // Scale == 4; |
| 7156 | Scale = 4; |
| 7157 | break; |
| 7158 | } |
| 7159 | |
| 7160 | if ((V & (Scale - 1)) != 0) |
| 7161 | return false; |
| 7162 | V /= Scale; |
| 7163 | return V == (V & ((1LL << 5) - 1)); |
| 7164 | } |
| 7165 | |
| 7166 | static bool isLegalT2AddressImmediate(int64_t V, EVT VT, |
| 7167 | const ARMSubtarget *Subtarget) { |
| 7168 | bool isNeg = false; |
| 7169 | if (V < 0) { |
| 7170 | isNeg = true; |
| 7171 | V = - V; |
| 7172 | } |
| 7173 | |
| 7174 | switch (VT.getSimpleVT().SimpleTy) { |
| 7175 | default: return false; |
| 7176 | case MVT::i1: |
| 7177 | case MVT::i8: |
| 7178 | case MVT::i16: |
| 7179 | case MVT::i32: |
| 7180 | // + imm12 or - imm8 |
| 7181 | if (isNeg) |
| 7182 | return V == (V & ((1LL << 8) - 1)); |
| 7183 | return V == (V & ((1LL << 12) - 1)); |
| 7184 | case MVT::f32: |
| 7185 | case MVT::f64: |
| 7186 | // Same as ARM mode. FIXME: NEON? |
| 7187 | if (!Subtarget->hasVFP2()) |
| 7188 | return false; |
| 7189 | if ((V & 3) != 0) |
| 7190 | return false; |
| 7191 | V >>= 2; |
| 7192 | return V == (V & ((1LL << 8) - 1)); |
| 7193 | } |
| 7194 | } |
| 7195 | |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7196 | /// isLegalAddressImmediate - Return true if the integer value can be used |
| 7197 | /// as the offset of the target addressing mode for load / store of the |
| 7198 | /// given type. |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7199 | static bool isLegalAddressImmediate(int64_t V, EVT VT, |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7200 | const ARMSubtarget *Subtarget) { |
Evan Cheng | 961f879 | 2007-03-13 20:37:59 +0000 | [diff] [blame] | 7201 | if (V == 0) |
| 7202 | return true; |
| 7203 | |
Evan Cheng | 6501153 | 2009-03-09 19:15:00 +0000 | [diff] [blame] | 7204 | if (!VT.isSimple()) |
| 7205 | return false; |
| 7206 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7207 | if (Subtarget->isThumb1Only()) |
| 7208 | return isLegalT1AddressImmediate(V, VT); |
| 7209 | else if (Subtarget->isThumb2()) |
| 7210 | return isLegalT2AddressImmediate(V, VT, Subtarget); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7211 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7212 | // ARM mode. |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7213 | if (V < 0) |
| 7214 | V = - V; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7215 | switch (VT.getSimpleVT().SimpleTy) { |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7216 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7217 | case MVT::i1: |
| 7218 | case MVT::i8: |
| 7219 | case MVT::i32: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7220 | // +- imm12 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 7221 | return V == (V & ((1LL << 12) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7222 | case MVT::i16: |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7223 | // +- imm8 |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 7224 | return V == (V & ((1LL << 8) - 1)); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7225 | case MVT::f32: |
| 7226 | case MVT::f64: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7227 | if (!Subtarget->hasVFP2()) // FIXME: NEON? |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7228 | return false; |
Evan Cheng | 0b0a9a9 | 2007-05-03 02:00:18 +0000 | [diff] [blame] | 7229 | if ((V & 3) != 0) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7230 | return false; |
| 7231 | V >>= 2; |
Anton Korobeynikov | 7c1c261 | 2008-02-20 11:22:39 +0000 | [diff] [blame] | 7232 | return V == (V & ((1LL << 8) - 1)); |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7233 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7234 | } |
| 7235 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7236 | bool ARMTargetLowering::isLegalT2ScaledAddressingMode(const AddrMode &AM, |
| 7237 | EVT VT) const { |
| 7238 | int Scale = AM.Scale; |
| 7239 | if (Scale < 0) |
| 7240 | return false; |
| 7241 | |
| 7242 | switch (VT.getSimpleVT().SimpleTy) { |
| 7243 | default: return false; |
| 7244 | case MVT::i1: |
| 7245 | case MVT::i8: |
| 7246 | case MVT::i16: |
| 7247 | case MVT::i32: |
| 7248 | if (Scale == 1) |
| 7249 | return true; |
| 7250 | // r + r << imm |
| 7251 | Scale = Scale & ~1; |
| 7252 | return Scale == 2 || Scale == 4 || Scale == 8; |
| 7253 | case MVT::i64: |
| 7254 | // r + r |
| 7255 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
| 7256 | return true; |
| 7257 | return false; |
| 7258 | case MVT::isVoid: |
| 7259 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 7260 | // stores), because arm allows folding a scale into many arithmetic |
| 7261 | // operations. This should be made more precise and revisited later. |
| 7262 | |
| 7263 | // Allow r << imm, but the imm has to be a multiple of two. |
| 7264 | if (Scale & 1) return false; |
| 7265 | return isPowerOf2_32(Scale); |
| 7266 | } |
| 7267 | } |
| 7268 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7269 | /// isLegalAddressingMode - Return true if the addressing mode represented |
| 7270 | /// by AM is legal for this target, for a load/store of the specified type. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7271 | bool ARMTargetLowering::isLegalAddressingMode(const AddrMode &AM, |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 7272 | Type *Ty) const { |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7273 | EVT VT = getValueType(Ty, true); |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 7274 | if (!isLegalAddressImmediate(AM.BaseOffs, VT, Subtarget)) |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7275 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7276 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7277 | // Can never fold addr of global into load/store. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7278 | if (AM.BaseGV) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7279 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7280 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7281 | switch (AM.Scale) { |
| 7282 | case 0: // no scale reg, must be "r+i" or "r", or "i". |
| 7283 | break; |
| 7284 | case 1: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7285 | if (Subtarget->isThumb1Only()) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7286 | return false; |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 7287 | // FALL THROUGH. |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7288 | default: |
Chris Lattner | 5a3d40d | 2007-04-13 06:50:55 +0000 | [diff] [blame] | 7289 | // ARM doesn't support any R+R*scale+imm addr modes. |
| 7290 | if (AM.BaseOffs) |
| 7291 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7292 | |
Bob Wilson | 2c7dab1 | 2009-04-08 17:55:28 +0000 | [diff] [blame] | 7293 | if (!VT.isSimple()) |
| 7294 | return false; |
| 7295 | |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7296 | if (Subtarget->isThumb2()) |
| 7297 | return isLegalT2ScaledAddressingMode(AM, VT); |
| 7298 | |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 7299 | int Scale = AM.Scale; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7300 | switch (VT.getSimpleVT().SimpleTy) { |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7301 | default: return false; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7302 | case MVT::i1: |
| 7303 | case MVT::i8: |
| 7304 | case MVT::i32: |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 7305 | if (Scale < 0) Scale = -Scale; |
| 7306 | if (Scale == 1) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7307 | return true; |
| 7308 | // r + r << imm |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 7309 | return isPowerOf2_32(Scale & ~1); |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7310 | case MVT::i16: |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7311 | case MVT::i64: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7312 | // r + r |
Chris Lattner | eb13d1b | 2007-04-10 03:48:29 +0000 | [diff] [blame] | 7313 | if (((unsigned)AM.HasBaseReg + Scale) <= 2) |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7314 | return true; |
Chris Lattner | e115294 | 2007-04-11 16:17:12 +0000 | [diff] [blame] | 7315 | return false; |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7316 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7317 | case MVT::isVoid: |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7318 | // Note, we allow "void" uses (basically, uses that aren't loads or |
| 7319 | // stores), because arm allows folding a scale into many arithmetic |
| 7320 | // operations. This should be made more precise and revisited later. |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7321 | |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7322 | // Allow r << imm, but the imm has to be a multiple of two. |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7323 | if (Scale & 1) return false; |
| 7324 | return isPowerOf2_32(Scale); |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7325 | } |
| 7326 | break; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7327 | } |
Chris Lattner | 37caf8c | 2007-04-09 23:33:39 +0000 | [diff] [blame] | 7328 | return true; |
Evan Cheng | b01fad6 | 2007-03-12 23:30:29 +0000 | [diff] [blame] | 7329 | } |
| 7330 | |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7331 | /// isLegalICmpImmediate - Return true if the specified immediate is legal |
| 7332 | /// icmp immediate, that is the target has icmp instructions which can compare |
| 7333 | /// a register against the immediate without having to materialize the |
| 7334 | /// immediate into a register. |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 7335 | bool ARMTargetLowering::isLegalICmpImmediate(int64_t Imm) const { |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7336 | if (!Subtarget->isThumb()) |
| 7337 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 7338 | if (Subtarget->isThumb2()) |
Jim Grosbach | 4725ca7 | 2010-09-08 03:54:02 +0000 | [diff] [blame] | 7339 | return ARM_AM::getT2SOImmVal(Imm) != -1; |
Evan Cheng | 06b53c0 | 2009-11-12 07:13:11 +0000 | [diff] [blame] | 7340 | return Imm >= 0 && Imm <= 255; |
Evan Cheng | 77e4751 | 2009-11-11 19:05:52 +0000 | [diff] [blame] | 7341 | } |
| 7342 | |
Dan Gohman | cca8214 | 2011-05-03 00:46:49 +0000 | [diff] [blame] | 7343 | /// isLegalAddImmediate - Return true if the specified immediate is legal |
| 7344 | /// add immediate, that is the target has add instructions which can add |
| 7345 | /// a register with the immediate without having to materialize the |
| 7346 | /// immediate into a register. |
| 7347 | bool ARMTargetLowering::isLegalAddImmediate(int64_t Imm) const { |
| 7348 | return ARM_AM::getSOImmVal(Imm) != -1; |
| 7349 | } |
| 7350 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7351 | static bool getARMIndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7352 | bool isSEXTLoad, SDValue &Base, |
| 7353 | SDValue &Offset, bool &isInc, |
| 7354 | SelectionDAG &DAG) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7355 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 7356 | return false; |
| 7357 | |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7358 | if (VT == MVT::i16 || ((VT == MVT::i8 || VT == MVT::i1) && isSEXTLoad)) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7359 | // AddressingMode 3 |
| 7360 | Base = Ptr->getOperand(0); |
| 7361 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7362 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7363 | if (RHSC < 0 && RHSC > -256) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7364 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7365 | isInc = false; |
| 7366 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7367 | return true; |
| 7368 | } |
| 7369 | } |
| 7370 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 7371 | Offset = Ptr->getOperand(1); |
| 7372 | return true; |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7373 | } else if (VT == MVT::i32 || VT == MVT::i8 || VT == MVT::i1) { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7374 | // AddressingMode 2 |
| 7375 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
Dan Gohman | f5aeb1a | 2008-09-12 16:56:44 +0000 | [diff] [blame] | 7376 | int RHSC = (int)RHS->getZExtValue(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7377 | if (RHSC < 0 && RHSC > -0x1000) { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7378 | assert(Ptr->getOpcode() == ISD::ADD); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7379 | isInc = false; |
| 7380 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7381 | Base = Ptr->getOperand(0); |
| 7382 | return true; |
| 7383 | } |
| 7384 | } |
| 7385 | |
| 7386 | if (Ptr->getOpcode() == ISD::ADD) { |
| 7387 | isInc = true; |
Evan Cheng | ee04a6d | 2011-07-20 23:34:39 +0000 | [diff] [blame] | 7388 | ARM_AM::ShiftOpc ShOpcVal= |
| 7389 | ARM_AM::getShiftOpcForNode(Ptr->getOperand(0).getOpcode()); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7390 | if (ShOpcVal != ARM_AM::no_shift) { |
| 7391 | Base = Ptr->getOperand(1); |
| 7392 | Offset = Ptr->getOperand(0); |
| 7393 | } else { |
| 7394 | Base = Ptr->getOperand(0); |
| 7395 | Offset = Ptr->getOperand(1); |
| 7396 | } |
| 7397 | return true; |
| 7398 | } |
| 7399 | |
| 7400 | isInc = (Ptr->getOpcode() == ISD::ADD); |
| 7401 | Base = Ptr->getOperand(0); |
| 7402 | Offset = Ptr->getOperand(1); |
| 7403 | return true; |
| 7404 | } |
| 7405 | |
Jim Grosbach | e516549 | 2009-11-09 00:11:35 +0000 | [diff] [blame] | 7406 | // FIXME: Use VLDM / VSTM to emulate indexed FP load / store. |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7407 | return false; |
| 7408 | } |
| 7409 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7410 | static bool getT2IndexedAddressParts(SDNode *Ptr, EVT VT, |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7411 | bool isSEXTLoad, SDValue &Base, |
| 7412 | SDValue &Offset, bool &isInc, |
| 7413 | SelectionDAG &DAG) { |
| 7414 | if (Ptr->getOpcode() != ISD::ADD && Ptr->getOpcode() != ISD::SUB) |
| 7415 | return false; |
| 7416 | |
| 7417 | Base = Ptr->getOperand(0); |
| 7418 | if (ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(Ptr->getOperand(1))) { |
| 7419 | int RHSC = (int)RHS->getZExtValue(); |
| 7420 | if (RHSC < 0 && RHSC > -0x100) { // 8 bits. |
| 7421 | assert(Ptr->getOpcode() == ISD::ADD); |
| 7422 | isInc = false; |
| 7423 | Offset = DAG.getConstant(-RHSC, RHS->getValueType(0)); |
| 7424 | return true; |
| 7425 | } else if (RHSC > 0 && RHSC < 0x100) { // 8 bit, no zero. |
| 7426 | isInc = Ptr->getOpcode() == ISD::ADD; |
| 7427 | Offset = DAG.getConstant(RHSC, RHS->getValueType(0)); |
| 7428 | return true; |
| 7429 | } |
| 7430 | } |
| 7431 | |
| 7432 | return false; |
| 7433 | } |
| 7434 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7435 | /// getPreIndexedAddressParts - returns true by value, base pointer and |
| 7436 | /// offset pointer and addressing mode by reference if the node's address |
| 7437 | /// can be legally represented as pre-indexed load / store address. |
| 7438 | bool |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7439 | ARMTargetLowering::getPreIndexedAddressParts(SDNode *N, SDValue &Base, |
| 7440 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7441 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 7442 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7443 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7444 | return false; |
| 7445 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7446 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7447 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7448 | bool isSEXTLoad = false; |
| 7449 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
| 7450 | Ptr = LD->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7451 | VT = LD->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7452 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 7453 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
| 7454 | Ptr = ST->getBasePtr(); |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7455 | VT = ST->getMemoryVT(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7456 | } else |
| 7457 | return false; |
| 7458 | |
| 7459 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7460 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7461 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7462 | isLegal = getT2IndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
| 7463 | Offset, isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 7464 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7465 | isLegal = getARMIndexedAddressParts(Ptr.getNode(), VT, isSEXTLoad, Base, |
Evan Cheng | 0412957 | 2009-07-02 06:44:30 +0000 | [diff] [blame] | 7466 | Offset, isInc, DAG); |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7467 | if (!isLegal) |
| 7468 | return false; |
| 7469 | |
| 7470 | AM = isInc ? ISD::PRE_INC : ISD::PRE_DEC; |
| 7471 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7472 | } |
| 7473 | |
| 7474 | /// getPostIndexedAddressParts - returns true by value, base pointer and |
| 7475 | /// offset pointer and addressing mode by reference if this node can be |
| 7476 | /// combined with a load / store to form a post-indexed load / store. |
| 7477 | bool ARMTargetLowering::getPostIndexedAddressParts(SDNode *N, SDNode *Op, |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7478 | SDValue &Base, |
| 7479 | SDValue &Offset, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7480 | ISD::MemIndexedMode &AM, |
Dan Gohman | 73e0914 | 2009-01-15 16:29:45 +0000 | [diff] [blame] | 7481 | SelectionDAG &DAG) const { |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7482 | if (Subtarget->isThumb1Only()) |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7483 | return false; |
| 7484 | |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7485 | EVT VT; |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7486 | SDValue Ptr; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7487 | bool isSEXTLoad = false; |
| 7488 | if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7489 | VT = LD->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7490 | Ptr = LD->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7491 | isSEXTLoad = LD->getExtensionType() == ISD::SEXTLOAD; |
| 7492 | } else if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) { |
Dan Gohman | b625f2f | 2008-01-30 00:15:11 +0000 | [diff] [blame] | 7493 | VT = ST->getMemoryVT(); |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7494 | Ptr = ST->getBasePtr(); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7495 | } else |
| 7496 | return false; |
| 7497 | |
| 7498 | bool isInc; |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7499 | bool isLegal = false; |
Evan Cheng | e6c835f | 2009-08-14 20:09:37 +0000 | [diff] [blame] | 7500 | if (Subtarget->isThumb2()) |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7501 | isLegal = getT2IndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7502 | isInc, DAG); |
Jim Grosbach | 764ab52 | 2009-08-11 15:33:49 +0000 | [diff] [blame] | 7503 | else |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7504 | isLegal = getARMIndexedAddressParts(Op, VT, isSEXTLoad, Base, Offset, |
| 7505 | isInc, DAG); |
| 7506 | if (!isLegal) |
| 7507 | return false; |
| 7508 | |
Evan Cheng | 28dad2a | 2010-05-18 21:31:17 +0000 | [diff] [blame] | 7509 | if (Ptr != Base) { |
| 7510 | // Swap base ptr and offset to catch more post-index load / store when |
| 7511 | // it's legal. In Thumb2 mode, offset must be an immediate. |
| 7512 | if (Ptr == Offset && Op->getOpcode() == ISD::ADD && |
| 7513 | !Subtarget->isThumb2()) |
| 7514 | std::swap(Base, Offset); |
| 7515 | |
| 7516 | // Post-indexed load / store update the base pointer. |
| 7517 | if (Ptr != Base) |
| 7518 | return false; |
| 7519 | } |
| 7520 | |
Evan Cheng | e88d5ce | 2009-07-02 07:28:31 +0000 | [diff] [blame] | 7521 | AM = isInc ? ISD::POST_INC : ISD::POST_DEC; |
| 7522 | return true; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7523 | } |
| 7524 | |
Dan Gohman | 475871a | 2008-07-27 21:46:04 +0000 | [diff] [blame] | 7525 | void ARMTargetLowering::computeMaskedBitsForTargetNode(const SDValue Op, |
Dan Gohman | 977a76f | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 7526 | const APInt &Mask, |
Bob Wilson | 2dc4f54 | 2009-03-20 22:42:55 +0000 | [diff] [blame] | 7527 | APInt &KnownZero, |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7528 | APInt &KnownOne, |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7529 | const SelectionDAG &DAG, |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7530 | unsigned Depth) const { |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7531 | KnownZero = KnownOne = APInt(Mask.getBitWidth(), 0); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7532 | switch (Op.getOpcode()) { |
| 7533 | default: break; |
| 7534 | case ARMISD::CMOV: { |
| 7535 | // Bits are known zero/one if known on the LHS and RHS. |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7536 | DAG.ComputeMaskedBits(Op.getOperand(0), Mask, KnownZero, KnownOne, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7537 | if (KnownZero == 0 && KnownOne == 0) return; |
| 7538 | |
Dan Gohman | fd29e0e | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 7539 | APInt KnownZeroRHS, KnownOneRHS; |
Dan Gohman | ea859be | 2007-06-22 14:59:07 +0000 | [diff] [blame] | 7540 | DAG.ComputeMaskedBits(Op.getOperand(1), Mask, |
| 7541 | KnownZeroRHS, KnownOneRHS, Depth+1); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7542 | KnownZero &= KnownZeroRHS; |
| 7543 | KnownOne &= KnownOneRHS; |
| 7544 | return; |
| 7545 | } |
| 7546 | } |
| 7547 | } |
| 7548 | |
| 7549 | //===----------------------------------------------------------------------===// |
| 7550 | // ARM Inline Assembly Support |
| 7551 | //===----------------------------------------------------------------------===// |
| 7552 | |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 7553 | bool ARMTargetLowering::ExpandInlineAsm(CallInst *CI) const { |
| 7554 | // Looking for "rev" which is V6+. |
| 7555 | if (!Subtarget->hasV6Ops()) |
| 7556 | return false; |
| 7557 | |
| 7558 | InlineAsm *IA = cast<InlineAsm>(CI->getCalledValue()); |
| 7559 | std::string AsmStr = IA->getAsmString(); |
| 7560 | SmallVector<StringRef, 4> AsmPieces; |
| 7561 | SplitString(AsmStr, AsmPieces, ";\n"); |
| 7562 | |
| 7563 | switch (AsmPieces.size()) { |
| 7564 | default: return false; |
| 7565 | case 1: |
| 7566 | AsmStr = AsmPieces[0]; |
| 7567 | AsmPieces.clear(); |
| 7568 | SplitString(AsmStr, AsmPieces, " \t,"); |
| 7569 | |
| 7570 | // rev $0, $1 |
| 7571 | if (AsmPieces.size() == 3 && |
| 7572 | AsmPieces[0] == "rev" && AsmPieces[1] == "$0" && AsmPieces[2] == "$1" && |
| 7573 | IA->getConstraintString().compare(0, 4, "=l,l") == 0) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 7574 | IntegerType *Ty = dyn_cast<IntegerType>(CI->getType()); |
Evan Cheng | 55d4200 | 2011-01-08 01:24:27 +0000 | [diff] [blame] | 7575 | if (Ty && Ty->getBitWidth() == 32) |
| 7576 | return IntrinsicLowering::LowerToByteSwap(CI); |
| 7577 | } |
| 7578 | break; |
| 7579 | } |
| 7580 | |
| 7581 | return false; |
| 7582 | } |
| 7583 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7584 | /// getConstraintType - Given a constraint letter, return the type of |
| 7585 | /// constraint it is for this target. |
| 7586 | ARMTargetLowering::ConstraintType |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7587 | ARMTargetLowering::getConstraintType(const std::string &Constraint) const { |
| 7588 | if (Constraint.size() == 1) { |
| 7589 | switch (Constraint[0]) { |
| 7590 | default: break; |
| 7591 | case 'l': return C_RegisterClass; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7592 | case 'w': return C_RegisterClass; |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 7593 | case 'h': return C_RegisterClass; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 7594 | case 'x': return C_RegisterClass; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 7595 | case 't': return C_RegisterClass; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 7596 | case 'j': return C_Other; // Constant for movw. |
Eric Christopher | ef7f1e7 | 2011-07-29 21:18:58 +0000 | [diff] [blame] | 7597 | // An address with a single base register. Due to the way we |
| 7598 | // currently handle addresses it is the same as an 'r' memory constraint. |
| 7599 | case 'Q': return C_Memory; |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7600 | } |
Eric Christopher | 1312ca8 | 2011-06-21 22:10:57 +0000 | [diff] [blame] | 7601 | } else if (Constraint.size() == 2) { |
| 7602 | switch (Constraint[0]) { |
| 7603 | default: break; |
| 7604 | // All 'U+' constraints are addresses. |
| 7605 | case 'U': return C_Memory; |
| 7606 | } |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7607 | } |
Chris Lattner | 4234f57 | 2007-03-25 02:14:49 +0000 | [diff] [blame] | 7608 | return TargetLowering::getConstraintType(Constraint); |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7609 | } |
| 7610 | |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 7611 | /// Examine constraint type and operand type and determine a weight value. |
| 7612 | /// This object must already have been set up with the operand type |
| 7613 | /// and the current alternative constraint selected. |
| 7614 | TargetLowering::ConstraintWeight |
| 7615 | ARMTargetLowering::getSingleConstraintMatchWeight( |
| 7616 | AsmOperandInfo &info, const char *constraint) const { |
| 7617 | ConstraintWeight weight = CW_Invalid; |
| 7618 | Value *CallOperandVal = info.CallOperandVal; |
| 7619 | // If we don't have a value, we can't do a match, |
| 7620 | // but allow it at the lowest weight. |
| 7621 | if (CallOperandVal == NULL) |
| 7622 | return CW_Default; |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 7623 | Type *type = CallOperandVal->getType(); |
John Thompson | 44ab89e | 2010-10-29 17:29:13 +0000 | [diff] [blame] | 7624 | // Look at the constraint type. |
| 7625 | switch (*constraint) { |
| 7626 | default: |
| 7627 | weight = TargetLowering::getSingleConstraintMatchWeight(info, constraint); |
| 7628 | break; |
| 7629 | case 'l': |
| 7630 | if (type->isIntegerTy()) { |
| 7631 | if (Subtarget->isThumb()) |
| 7632 | weight = CW_SpecificReg; |
| 7633 | else |
| 7634 | weight = CW_Register; |
| 7635 | } |
| 7636 | break; |
| 7637 | case 'w': |
| 7638 | if (type->isFloatingPointTy()) |
| 7639 | weight = CW_Register; |
| 7640 | break; |
| 7641 | } |
| 7642 | return weight; |
| 7643 | } |
| 7644 | |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7645 | typedef std::pair<unsigned, const TargetRegisterClass*> RCPair; |
| 7646 | RCPair |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7647 | ARMTargetLowering::getRegForInlineAsmConstraint(const std::string &Constraint, |
Owen Anderson | e50ed30 | 2009-08-10 22:56:29 +0000 | [diff] [blame] | 7648 | EVT VT) const { |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7649 | if (Constraint.size() == 1) { |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 7650 | // GCC ARM Constraint Letters |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7651 | switch (Constraint[0]) { |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 7652 | case 'l': // Low regs or general regs. |
Jakob Stoklund Olesen | 09bf003 | 2010-01-14 18:19:56 +0000 | [diff] [blame] | 7653 | if (Subtarget->isThumb()) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7654 | return RCPair(0U, ARM::tGPRRegisterClass); |
Jim Grosbach | 30eae3c | 2009-04-07 20:34:09 +0000 | [diff] [blame] | 7655 | else |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7656 | return RCPair(0U, ARM::GPRRegisterClass); |
Eric Christopher | 73744df | 2011-06-30 23:23:01 +0000 | [diff] [blame] | 7657 | case 'h': // High regs or no regs. |
| 7658 | if (Subtarget->isThumb()) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7659 | return RCPair(0U, ARM::hGPRRegisterClass); |
Eric Christopher | 1070f82 | 2011-07-01 00:19:27 +0000 | [diff] [blame] | 7660 | break; |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7661 | case 'r': |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7662 | return RCPair(0U, ARM::GPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7663 | case 'w': |
Owen Anderson | 825b72b | 2009-08-11 20:47:22 +0000 | [diff] [blame] | 7664 | if (VT == MVT::f32) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7665 | return RCPair(0U, ARM::SPRRegisterClass); |
Bob Wilson | 5afffae | 2009-12-18 01:03:29 +0000 | [diff] [blame] | 7666 | if (VT.getSizeInBits() == 64) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7667 | return RCPair(0U, ARM::DPRRegisterClass); |
Evan Cheng | d831cda | 2009-12-08 23:06:22 +0000 | [diff] [blame] | 7668 | if (VT.getSizeInBits() == 128) |
Eric Christopher | 35e6d4d | 2011-06-30 23:50:52 +0000 | [diff] [blame] | 7669 | return RCPair(0U, ARM::QPRRegisterClass); |
Chris Lattner | c4e3f8e | 2007-04-02 17:24:08 +0000 | [diff] [blame] | 7670 | break; |
Eric Christopher | 89bd71f | 2011-07-01 00:14:47 +0000 | [diff] [blame] | 7671 | case 'x': |
| 7672 | if (VT == MVT::f32) |
| 7673 | return RCPair(0U, ARM::SPR_8RegisterClass); |
| 7674 | if (VT.getSizeInBits() == 64) |
| 7675 | return RCPair(0U, ARM::DPR_8RegisterClass); |
| 7676 | if (VT.getSizeInBits() == 128) |
| 7677 | return RCPair(0U, ARM::QPR_8RegisterClass); |
| 7678 | break; |
Eric Christopher | d5dc9ec | 2011-07-01 00:30:46 +0000 | [diff] [blame] | 7679 | case 't': |
| 7680 | if (VT == MVT::f32) |
| 7681 | return RCPair(0U, ARM::SPRRegisterClass); |
| 7682 | break; |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7683 | } |
| 7684 | } |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 7685 | if (StringRef("{cc}").equals_lower(Constraint)) |
Jakob Stoklund Olesen | 0d8ba33 | 2010-06-18 16:49:33 +0000 | [diff] [blame] | 7686 | return std::make_pair(unsigned(ARM::CPSR), ARM::CCRRegisterClass); |
Bob Wilson | 33cc5cb | 2010-03-15 23:09:18 +0000 | [diff] [blame] | 7687 | |
Evan Cheng | a8e2989 | 2007-01-19 07:51:42 +0000 | [diff] [blame] | 7688 | return TargetLowering::getRegForInlineAsmConstraint(Constraint, VT); |
| 7689 | } |
| 7690 | |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7691 | /// LowerAsmOperandForConstraint - Lower the specified operand into the Ops |
| 7692 | /// vector. If it is invalid, don't add anything to Ops. |
| 7693 | void ARMTargetLowering::LowerAsmOperandForConstraint(SDValue Op, |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 7694 | std::string &Constraint, |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7695 | std::vector<SDValue>&Ops, |
| 7696 | SelectionDAG &DAG) const { |
| 7697 | SDValue Result(0, 0); |
| 7698 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 7699 | // Currently only support length 1 constraints. |
| 7700 | if (Constraint.length() != 1) return; |
Eric Christopher | 471e422 | 2011-06-08 23:55:35 +0000 | [diff] [blame] | 7701 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 7702 | char ConstraintLetter = Constraint[0]; |
| 7703 | switch (ConstraintLetter) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7704 | default: break; |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 7705 | case 'j': |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7706 | case 'I': case 'J': case 'K': case 'L': |
| 7707 | case 'M': case 'N': case 'O': |
| 7708 | ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op); |
| 7709 | if (!C) |
| 7710 | return; |
| 7711 | |
| 7712 | int64_t CVal64 = C->getSExtValue(); |
| 7713 | int CVal = (int) CVal64; |
| 7714 | // None of these constraints allow values larger than 32 bits. Check |
| 7715 | // that the value fits in an int. |
| 7716 | if (CVal != CVal64) |
| 7717 | return; |
| 7718 | |
Eric Christopher | 100c833 | 2011-06-02 23:16:42 +0000 | [diff] [blame] | 7719 | switch (ConstraintLetter) { |
Eric Christopher | 5e653c9 | 2011-07-01 01:00:07 +0000 | [diff] [blame] | 7720 | case 'j': |
| 7721 | // Constant suitable for movw, must be between 0 and |
| 7722 | // 65535. |
| 7723 | if (Subtarget->hasV6T2Ops()) |
| 7724 | if (CVal >= 0 && CVal <= 65535) |
| 7725 | break; |
| 7726 | return; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7727 | case 'I': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7728 | if (Subtarget->isThumb1Only()) { |
| 7729 | // This must be a constant between 0 and 255, for ADD |
| 7730 | // immediates. |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7731 | if (CVal >= 0 && CVal <= 255) |
| 7732 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7733 | } else if (Subtarget->isThumb2()) { |
| 7734 | // A constant that can be used as an immediate value in a |
| 7735 | // data-processing instruction. |
| 7736 | if (ARM_AM::getT2SOImmVal(CVal) != -1) |
| 7737 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7738 | } else { |
| 7739 | // A constant that can be used as an immediate value in a |
| 7740 | // data-processing instruction. |
| 7741 | if (ARM_AM::getSOImmVal(CVal) != -1) |
| 7742 | break; |
| 7743 | } |
| 7744 | return; |
| 7745 | |
| 7746 | case 'J': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7747 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7748 | // This must be a constant between -255 and -1, for negated ADD |
| 7749 | // immediates. This can be used in GCC with an "n" modifier that |
| 7750 | // prints the negated value, for use with SUB instructions. It is |
| 7751 | // not useful otherwise but is implemented for compatibility. |
| 7752 | if (CVal >= -255 && CVal <= -1) |
| 7753 | break; |
| 7754 | } else { |
| 7755 | // This must be a constant between -4095 and 4095. It is not clear |
| 7756 | // what this constraint is intended for. Implemented for |
| 7757 | // compatibility with GCC. |
| 7758 | if (CVal >= -4095 && CVal <= 4095) |
| 7759 | break; |
| 7760 | } |
| 7761 | return; |
| 7762 | |
| 7763 | case 'K': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7764 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7765 | // A 32-bit value where only one byte has a nonzero value. Exclude |
| 7766 | // zero to match GCC. This constraint is used by GCC internally for |
| 7767 | // constants that can be loaded with a move/shift combination. |
| 7768 | // It is not useful otherwise but is implemented for compatibility. |
| 7769 | if (CVal != 0 && ARM_AM::isThumbImmShiftedVal(CVal)) |
| 7770 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7771 | } else if (Subtarget->isThumb2()) { |
| 7772 | // A constant whose bitwise inverse can be used as an immediate |
| 7773 | // value in a data-processing instruction. This can be used in GCC |
| 7774 | // with a "B" modifier that prints the inverted value, for use with |
| 7775 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7776 | // implemented for compatibility. |
| 7777 | if (ARM_AM::getT2SOImmVal(~CVal) != -1) |
| 7778 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7779 | } else { |
| 7780 | // A constant whose bitwise inverse can be used as an immediate |
| 7781 | // value in a data-processing instruction. This can be used in GCC |
| 7782 | // with a "B" modifier that prints the inverted value, for use with |
| 7783 | // BIC and MVN instructions. It is not useful otherwise but is |
| 7784 | // implemented for compatibility. |
| 7785 | if (ARM_AM::getSOImmVal(~CVal) != -1) |
| 7786 | break; |
| 7787 | } |
| 7788 | return; |
| 7789 | |
| 7790 | case 'L': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7791 | if (Subtarget->isThumb1Only()) { |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7792 | // This must be a constant between -7 and 7, |
| 7793 | // for 3-operand ADD/SUB immediate instructions. |
| 7794 | if (CVal >= -7 && CVal < 7) |
| 7795 | break; |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7796 | } else if (Subtarget->isThumb2()) { |
| 7797 | // A constant whose negation can be used as an immediate value in a |
| 7798 | // data-processing instruction. This can be used in GCC with an "n" |
| 7799 | // modifier that prints the negated value, for use with SUB |
| 7800 | // instructions. It is not useful otherwise but is implemented for |
| 7801 | // compatibility. |
| 7802 | if (ARM_AM::getT2SOImmVal(-CVal) != -1) |
| 7803 | break; |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7804 | } else { |
| 7805 | // A constant whose negation can be used as an immediate value in a |
| 7806 | // data-processing instruction. This can be used in GCC with an "n" |
| 7807 | // modifier that prints the negated value, for use with SUB |
| 7808 | // instructions. It is not useful otherwise but is implemented for |
| 7809 | // compatibility. |
| 7810 | if (ARM_AM::getSOImmVal(-CVal) != -1) |
| 7811 | break; |
| 7812 | } |
| 7813 | return; |
| 7814 | |
| 7815 | case 'M': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7816 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7817 | // This must be a multiple of 4 between 0 and 1020, for |
| 7818 | // ADD sp + immediate. |
| 7819 | if ((CVal >= 0 && CVal <= 1020) && ((CVal & 3) == 0)) |
| 7820 | break; |
| 7821 | } else { |
| 7822 | // A power of two or a constant between 0 and 32. This is used in |
| 7823 | // GCC for the shift amount on shifted register operands, but it is |
| 7824 | // useful in general for any shift amounts. |
| 7825 | if ((CVal >= 0 && CVal <= 32) || ((CVal & (CVal - 1)) == 0)) |
| 7826 | break; |
| 7827 | } |
| 7828 | return; |
| 7829 | |
| 7830 | case 'N': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7831 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7832 | // This must be a constant between 0 and 31, for shift amounts. |
| 7833 | if (CVal >= 0 && CVal <= 31) |
| 7834 | break; |
| 7835 | } |
| 7836 | return; |
| 7837 | |
| 7838 | case 'O': |
David Goodwin | f1daf7d | 2009-07-08 23:10:31 +0000 | [diff] [blame] | 7839 | if (Subtarget->isThumb()) { // FIXME thumb2 |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7840 | // This must be a multiple of 4 between -508 and 508, for |
| 7841 | // ADD/SUB sp = sp + immediate. |
| 7842 | if ((CVal >= -508 && CVal <= 508) && ((CVal & 3) == 0)) |
| 7843 | break; |
| 7844 | } |
| 7845 | return; |
| 7846 | } |
| 7847 | Result = DAG.getTargetConstant(CVal, Op.getValueType()); |
| 7848 | break; |
| 7849 | } |
| 7850 | |
| 7851 | if (Result.getNode()) { |
| 7852 | Ops.push_back(Result); |
| 7853 | return; |
| 7854 | } |
Dale Johannesen | 1784d16 | 2010-06-25 21:55:36 +0000 | [diff] [blame] | 7855 | return TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG); |
Bob Wilson | bf6396b | 2009-04-01 17:58:54 +0000 | [diff] [blame] | 7856 | } |
Anton Korobeynikov | 48e1935 | 2009-09-23 19:04:09 +0000 | [diff] [blame] | 7857 | |
| 7858 | bool |
| 7859 | ARMTargetLowering::isOffsetFoldingLegal(const GlobalAddressSDNode *GA) const { |
| 7860 | // The ARM target isn't yet aware of offsets. |
| 7861 | return false; |
| 7862 | } |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7863 | |
| 7864 | int ARM::getVFPf32Imm(const APFloat &FPImm) { |
| 7865 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7866 | uint32_t Sign = Imm.lshr(31).getZExtValue() & 1; |
| 7867 | int32_t Exp = (Imm.lshr(23).getSExtValue() & 0xff) - 127; // -126 to 127 |
| 7868 | int64_t Mantissa = Imm.getZExtValue() & 0x7fffff; // 23 bits |
| 7869 | |
| 7870 | // We can handle 4 bits of mantissa. |
| 7871 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7872 | if (Mantissa & 0x7ffff) |
| 7873 | return -1; |
| 7874 | Mantissa >>= 19; |
| 7875 | if ((Mantissa & 0xf) != Mantissa) |
| 7876 | return -1; |
| 7877 | |
| 7878 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7879 | if (Exp < -3 || Exp > 4) |
| 7880 | return -1; |
| 7881 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7882 | |
| 7883 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7884 | } |
| 7885 | |
| 7886 | int ARM::getVFPf64Imm(const APFloat &FPImm) { |
| 7887 | APInt Imm = FPImm.bitcastToAPInt(); |
| 7888 | uint64_t Sign = Imm.lshr(63).getZExtValue() & 1; |
| 7889 | int64_t Exp = (Imm.lshr(52).getSExtValue() & 0x7ff) - 1023; // -1022 to 1023 |
| 7890 | uint64_t Mantissa = Imm.getZExtValue() & 0xfffffffffffffLL; |
| 7891 | |
| 7892 | // We can handle 4 bits of mantissa. |
| 7893 | // mantissa = (16+UInt(e:f:g:h))/16. |
| 7894 | if (Mantissa & 0xffffffffffffLL) |
| 7895 | return -1; |
| 7896 | Mantissa >>= 48; |
| 7897 | if ((Mantissa & 0xf) != Mantissa) |
| 7898 | return -1; |
| 7899 | |
| 7900 | // We can handle 3 bits of exponent: exp == UInt(NOT(b):c:d)-3 |
| 7901 | if (Exp < -3 || Exp > 4) |
| 7902 | return -1; |
| 7903 | Exp = ((Exp+3) & 0x7) ^ 4; |
| 7904 | |
| 7905 | return ((int)Sign << 7) | (Exp << 4) | Mantissa; |
| 7906 | } |
| 7907 | |
Jim Grosbach | 469bbdb | 2010-07-16 23:05:05 +0000 | [diff] [blame] | 7908 | bool ARM::isBitFieldInvertedMask(unsigned v) { |
| 7909 | if (v == 0xffffffff) |
| 7910 | return 0; |
| 7911 | // there can be 1's on either or both "outsides", all the "inside" |
| 7912 | // bits must be 0's |
| 7913 | unsigned int lsb = 0, msb = 31; |
| 7914 | while (v & (1 << msb)) --msb; |
| 7915 | while (v & (1 << lsb)) ++lsb; |
| 7916 | for (unsigned int i = lsb; i <= msb; ++i) { |
| 7917 | if (v & (1 << i)) |
| 7918 | return 0; |
| 7919 | } |
| 7920 | return 1; |
| 7921 | } |
| 7922 | |
Evan Cheng | 3938242 | 2009-10-28 01:44:26 +0000 | [diff] [blame] | 7923 | /// isFPImmLegal - Returns true if the target can instruction select the |
| 7924 | /// specified FP immediate natively. If false, the legalizer will |
| 7925 | /// materialize the FP immediate as a load from a constant pool. |
| 7926 | bool ARMTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const { |
| 7927 | if (!Subtarget->hasVFP3()) |
| 7928 | return false; |
| 7929 | if (VT == MVT::f32) |
| 7930 | return ARM::getVFPf32Imm(Imm) != -1; |
| 7931 | if (VT == MVT::f64) |
| 7932 | return ARM::getVFPf64Imm(Imm) != -1; |
| 7933 | return false; |
| 7934 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7935 | |
Wesley Peck | bf17cfa | 2010-11-23 03:31:01 +0000 | [diff] [blame] | 7936 | /// getTgtMemIntrinsic - Represent NEON load and store intrinsics as |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7937 | /// MemIntrinsicNodes. The associated MachineMemOperands record the alignment |
| 7938 | /// specified in the intrinsic calls. |
| 7939 | bool ARMTargetLowering::getTgtMemIntrinsic(IntrinsicInfo &Info, |
| 7940 | const CallInst &I, |
| 7941 | unsigned Intrinsic) const { |
| 7942 | switch (Intrinsic) { |
| 7943 | case Intrinsic::arm_neon_vld1: |
| 7944 | case Intrinsic::arm_neon_vld2: |
| 7945 | case Intrinsic::arm_neon_vld3: |
| 7946 | case Intrinsic::arm_neon_vld4: |
| 7947 | case Intrinsic::arm_neon_vld2lane: |
| 7948 | case Intrinsic::arm_neon_vld3lane: |
| 7949 | case Intrinsic::arm_neon_vld4lane: { |
| 7950 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7951 | // Conservatively set memVT to the entire set of vectors loaded. |
| 7952 | uint64_t NumElts = getTargetData()->getTypeAllocSize(I.getType()) / 8; |
| 7953 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7954 | Info.ptrVal = I.getArgOperand(0); |
| 7955 | Info.offset = 0; |
| 7956 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7957 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7958 | Info.vol = false; // volatile loads with NEON intrinsics not supported |
| 7959 | Info.readMem = true; |
| 7960 | Info.writeMem = false; |
| 7961 | return true; |
| 7962 | } |
| 7963 | case Intrinsic::arm_neon_vst1: |
| 7964 | case Intrinsic::arm_neon_vst2: |
| 7965 | case Intrinsic::arm_neon_vst3: |
| 7966 | case Intrinsic::arm_neon_vst4: |
| 7967 | case Intrinsic::arm_neon_vst2lane: |
| 7968 | case Intrinsic::arm_neon_vst3lane: |
| 7969 | case Intrinsic::arm_neon_vst4lane: { |
| 7970 | Info.opc = ISD::INTRINSIC_VOID; |
| 7971 | // Conservatively set memVT to the entire set of vectors stored. |
| 7972 | unsigned NumElts = 0; |
| 7973 | for (unsigned ArgI = 1, ArgE = I.getNumArgOperands(); ArgI < ArgE; ++ArgI) { |
Chris Lattner | db125cf | 2011-07-18 04:54:35 +0000 | [diff] [blame] | 7974 | Type *ArgTy = I.getArgOperand(ArgI)->getType(); |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 7975 | if (!ArgTy->isVectorTy()) |
| 7976 | break; |
| 7977 | NumElts += getTargetData()->getTypeAllocSize(ArgTy) / 8; |
| 7978 | } |
| 7979 | Info.memVT = EVT::getVectorVT(I.getType()->getContext(), MVT::i64, NumElts); |
| 7980 | Info.ptrVal = I.getArgOperand(0); |
| 7981 | Info.offset = 0; |
| 7982 | Value *AlignArg = I.getArgOperand(I.getNumArgOperands() - 1); |
| 7983 | Info.align = cast<ConstantInt>(AlignArg)->getZExtValue(); |
| 7984 | Info.vol = false; // volatile stores with NEON intrinsics not supported |
| 7985 | Info.readMem = false; |
| 7986 | Info.writeMem = true; |
| 7987 | return true; |
| 7988 | } |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 7989 | case Intrinsic::arm_strexd: { |
| 7990 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 7991 | Info.memVT = MVT::i64; |
| 7992 | Info.ptrVal = I.getArgOperand(2); |
| 7993 | Info.offset = 0; |
| 7994 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 7995 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 7996 | Info.readMem = false; |
| 7997 | Info.writeMem = true; |
| 7998 | return true; |
| 7999 | } |
| 8000 | case Intrinsic::arm_ldrexd: { |
| 8001 | Info.opc = ISD::INTRINSIC_W_CHAIN; |
| 8002 | Info.memVT = MVT::i64; |
| 8003 | Info.ptrVal = I.getArgOperand(0); |
| 8004 | Info.offset = 0; |
| 8005 | Info.align = 8; |
Bruno Cardoso Lopes | c75448c | 2011-06-16 18:11:32 +0000 | [diff] [blame] | 8006 | Info.vol = true; |
Bruno Cardoso Lopes | a0112d0 | 2011-05-28 04:07:29 +0000 | [diff] [blame] | 8007 | Info.readMem = true; |
| 8008 | Info.writeMem = false; |
| 8009 | return true; |
| 8010 | } |
Bob Wilson | 65ffec4 | 2010-09-21 17:56:22 +0000 | [diff] [blame] | 8011 | default: |
| 8012 | break; |
| 8013 | } |
| 8014 | |
| 8015 | return false; |
| 8016 | } |