Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 1 | //===- AMDGPULegalizerInfo.cpp -----------------------------------*- C++ -*-==// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
| 9 | /// This file implements the targeting of the Machinelegalizer class for |
| 10 | /// AMDGPU. |
| 11 | /// \todo This should be generated by TableGen. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
David Blaikie | 36a0f22 | 2018-03-23 23:58:31 +0000 | [diff] [blame] | 14 | #include "AMDGPU.h" |
Craig Topper | 2fa1436 | 2018-03-29 17:21:10 +0000 | [diff] [blame] | 15 | #include "AMDGPULegalizerInfo.h" |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 16 | #include "AMDGPUTargetMachine.h" |
David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/TargetOpcodes.h" |
Craig Topper | 2fa1436 | 2018-03-29 17:21:10 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/ValueTypes.h" |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 19 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Type.h" |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 21 | #include "llvm/Support/Debug.h" |
| 22 | |
| 23 | using namespace llvm; |
Daniel Sanders | 9ade559 | 2018-01-29 17:37:29 +0000 | [diff] [blame] | 24 | using namespace LegalizeActions; |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 25 | using namespace LegalizeMutations; |
Matt Arsenault | 7ac79ed | 2019-01-20 19:45:18 +0000 | [diff] [blame] | 26 | using namespace LegalityPredicates; |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 27 | |
Matt Arsenault | d914189 | 2019-02-07 19:10:15 +0000 | [diff] [blame] | 28 | |
| 29 | static LegalityPredicate isMultiple32(unsigned TypeIdx, |
| 30 | unsigned MaxSize = 512) { |
| 31 | return [=](const LegalityQuery &Query) { |
| 32 | const LLT Ty = Query.Types[TypeIdx]; |
| 33 | const LLT EltTy = Ty.getScalarType(); |
| 34 | return Ty.getSizeInBits() <= MaxSize && EltTy.getSizeInBits() % 32 == 0; |
| 35 | }; |
| 36 | } |
| 37 | |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 38 | AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST, |
Matt Arsenault | c3fe46b | 2018-03-08 16:24:16 +0000 | [diff] [blame] | 39 | const GCNTargetMachine &TM) { |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 40 | using namespace TargetOpcode; |
| 41 | |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 42 | auto GetAddrSpacePtr = [&TM](unsigned AS) { |
| 43 | return LLT::pointer(AS, TM.getPointerSizeInBits(AS)); |
| 44 | }; |
| 45 | |
| 46 | const LLT S1 = LLT::scalar(1); |
Matt Arsenault | 888aa5d | 2019-02-03 00:07:33 +0000 | [diff] [blame] | 47 | const LLT S8 = LLT::scalar(8); |
Matt Arsenault | 4599159 | 2019-01-18 21:33:50 +0000 | [diff] [blame] | 48 | const LLT S16 = LLT::scalar(16); |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 49 | const LLT S32 = LLT::scalar(32); |
| 50 | const LLT S64 = LLT::scalar(64); |
Matt Arsenault | ca67634 | 2019-01-25 02:36:32 +0000 | [diff] [blame] | 51 | const LLT S128 = LLT::scalar(128); |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 52 | const LLT S256 = LLT::scalar(256); |
Tom Stellard | eebbfc2 | 2018-06-30 04:09:44 +0000 | [diff] [blame] | 53 | const LLT S512 = LLT::scalar(512); |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 54 | |
Matt Arsenault | bee2ad7 | 2018-12-21 03:03:11 +0000 | [diff] [blame] | 55 | const LLT V2S16 = LLT::vector(2, 16); |
Matt Arsenault | a1515d2 | 2019-01-08 01:30:02 +0000 | [diff] [blame] | 56 | const LLT V4S16 = LLT::vector(4, 16); |
| 57 | const LLT V8S16 = LLT::vector(8, 16); |
Matt Arsenault | bee2ad7 | 2018-12-21 03:03:11 +0000 | [diff] [blame] | 58 | |
| 59 | const LLT V2S32 = LLT::vector(2, 32); |
| 60 | const LLT V3S32 = LLT::vector(3, 32); |
| 61 | const LLT V4S32 = LLT::vector(4, 32); |
| 62 | const LLT V5S32 = LLT::vector(5, 32); |
| 63 | const LLT V6S32 = LLT::vector(6, 32); |
| 64 | const LLT V7S32 = LLT::vector(7, 32); |
| 65 | const LLT V8S32 = LLT::vector(8, 32); |
| 66 | const LLT V9S32 = LLT::vector(9, 32); |
| 67 | const LLT V10S32 = LLT::vector(10, 32); |
| 68 | const LLT V11S32 = LLT::vector(11, 32); |
| 69 | const LLT V12S32 = LLT::vector(12, 32); |
| 70 | const LLT V13S32 = LLT::vector(13, 32); |
| 71 | const LLT V14S32 = LLT::vector(14, 32); |
| 72 | const LLT V15S32 = LLT::vector(15, 32); |
| 73 | const LLT V16S32 = LLT::vector(16, 32); |
| 74 | |
| 75 | const LLT V2S64 = LLT::vector(2, 64); |
| 76 | const LLT V3S64 = LLT::vector(3, 64); |
| 77 | const LLT V4S64 = LLT::vector(4, 64); |
| 78 | const LLT V5S64 = LLT::vector(5, 64); |
| 79 | const LLT V6S64 = LLT::vector(6, 64); |
| 80 | const LLT V7S64 = LLT::vector(7, 64); |
| 81 | const LLT V8S64 = LLT::vector(8, 64); |
| 82 | |
| 83 | std::initializer_list<LLT> AllS32Vectors = |
| 84 | {V2S32, V3S32, V4S32, V5S32, V6S32, V7S32, V8S32, |
| 85 | V9S32, V10S32, V11S32, V12S32, V13S32, V14S32, V15S32, V16S32}; |
| 86 | std::initializer_list<LLT> AllS64Vectors = |
| 87 | {V2S64, V3S64, V4S64, V5S64, V6S64, V7S64, V8S64}; |
| 88 | |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 89 | const LLT GlobalPtr = GetAddrSpacePtr(AMDGPUAS::GLOBAL_ADDRESS); |
| 90 | const LLT ConstantPtr = GetAddrSpacePtr(AMDGPUAS::CONSTANT_ADDRESS); |
Matt Arsenault | 685d1e8 | 2018-03-17 15:17:45 +0000 | [diff] [blame] | 91 | const LLT LocalPtr = GetAddrSpacePtr(AMDGPUAS::LOCAL_ADDRESS); |
Matt Arsenault | 0da6350 | 2018-08-31 05:49:54 +0000 | [diff] [blame] | 92 | const LLT FlatPtr = GetAddrSpacePtr(AMDGPUAS::FLAT_ADDRESS); |
| 93 | const LLT PrivatePtr = GetAddrSpacePtr(AMDGPUAS::PRIVATE_ADDRESS); |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 94 | |
Matt Arsenault | 934e534 | 2018-12-13 20:34:15 +0000 | [diff] [blame] | 95 | const LLT CodePtr = FlatPtr; |
| 96 | |
Matt Arsenault | 685d1e8 | 2018-03-17 15:17:45 +0000 | [diff] [blame] | 97 | const LLT AddrSpaces[] = { |
| 98 | GlobalPtr, |
| 99 | ConstantPtr, |
| 100 | LocalPtr, |
| 101 | FlatPtr, |
| 102 | PrivatePtr |
| 103 | }; |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 104 | |
Matt Arsenault | adc40ba | 2019-01-08 01:22:47 +0000 | [diff] [blame] | 105 | setAction({G_BRCOND, S1}, Legal); |
| 106 | |
Matt Arsenault | 3e08b77 | 2019-01-25 04:53:57 +0000 | [diff] [blame] | 107 | getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_UMULH, G_SMULH}) |
Matt Arsenault | 5d622fb | 2019-01-25 03:23:04 +0000 | [diff] [blame] | 108 | .legalFor({S32}) |
Matt Arsenault | 211e89d | 2019-01-27 00:52:51 +0000 | [diff] [blame] | 109 | .clampScalar(0, S32, S32) |
Matt Arsenault | 5d622fb | 2019-01-25 03:23:04 +0000 | [diff] [blame] | 110 | .scalarize(0); |
Matt Arsenault | 4339883 | 2018-12-20 01:35:49 +0000 | [diff] [blame] | 111 | |
Matt Arsenault | 26a6c74 | 2019-01-26 23:47:07 +0000 | [diff] [blame] | 112 | // Report legal for any types we can handle anywhere. For the cases only legal |
| 113 | // on the SALU, RegBankSelect will be able to re-legalize. |
Matt Arsenault | 4339883 | 2018-12-20 01:35:49 +0000 | [diff] [blame] | 114 | getActionDefinitionsBuilder({G_AND, G_OR, G_XOR}) |
Matt Arsenault | 26a6c74 | 2019-01-26 23:47:07 +0000 | [diff] [blame] | 115 | .legalFor({S32, S1, S64, V2S32, V2S16, V4S16}) |
| 116 | .clampScalar(0, S32, S64) |
| 117 | .scalarize(0); |
Tom Stellard | ee6e645 | 2017-06-12 20:54:56 +0000 | [diff] [blame] | 118 | |
Matt Arsenault | 68c668a | 2019-01-08 01:09:09 +0000 | [diff] [blame] | 119 | getActionDefinitionsBuilder({G_UADDO, G_SADDO, G_USUBO, G_SSUBO, |
| 120 | G_UADDE, G_SADDE, G_USUBE, G_SSUBE}) |
Matt Arsenault | 4d47594 | 2019-01-26 23:44:51 +0000 | [diff] [blame] | 121 | .legalFor({{S32, S1}}) |
| 122 | .clampScalar(0, S32, S32); |
Matt Arsenault | 2cc15b6 | 2019-01-08 01:03:58 +0000 | [diff] [blame] | 123 | |
Matt Arsenault | 7ac79ed | 2019-01-20 19:45:18 +0000 | [diff] [blame] | 124 | getActionDefinitionsBuilder(G_BITCAST) |
| 125 | .legalForCartesianProduct({S32, V2S16}) |
| 126 | .legalForCartesianProduct({S64, V2S32, V4S16}) |
| 127 | .legalForCartesianProduct({V2S64, V4S32}) |
| 128 | // Don't worry about the size constraint. |
| 129 | .legalIf(all(isPointer(0), isPointer(1))); |
Tom Stellard | ff63ee0 | 2017-06-19 13:15:45 +0000 | [diff] [blame] | 130 | |
Matt Arsenault | abdc4f2 | 2018-03-17 15:17:48 +0000 | [diff] [blame] | 131 | getActionDefinitionsBuilder(G_FCONSTANT) |
Matt Arsenault | 4599159 | 2019-01-18 21:33:50 +0000 | [diff] [blame] | 132 | .legalFor({S32, S64, S16}); |
Tom Stellard | eebbfc2 | 2018-06-30 04:09:44 +0000 | [diff] [blame] | 133 | |
Matt Arsenault | b3feccd | 2018-06-25 15:42:12 +0000 | [diff] [blame] | 134 | getActionDefinitionsBuilder(G_IMPLICIT_DEF) |
Matt Arsenault | d914189 | 2019-02-07 19:10:15 +0000 | [diff] [blame] | 135 | .legalFor({S1, S32, S64, V2S32, V4S32, V2S16, V4S16, GlobalPtr, |
| 136 | ConstantPtr, LocalPtr, FlatPtr, PrivatePtr}) |
| 137 | .legalFor({LLT::vector(3, 16)})// FIXME: Hack |
| 138 | .clampScalarOrElt(0, S32, S512) |
| 139 | .legalIf(isMultiple32(0)); |
Matt Arsenault | b3feccd | 2018-06-25 15:42:12 +0000 | [diff] [blame] | 140 | |
Matt Arsenault | abdc4f2 | 2018-03-17 15:17:48 +0000 | [diff] [blame] | 141 | |
Tom Stellard | e042412 | 2017-06-03 01:13:33 +0000 | [diff] [blame] | 142 | // FIXME: i1 operands to intrinsics should always be legal, but other i1 |
| 143 | // values may not be legal. We need to figure out how to distinguish |
| 144 | // between these two scenarios. |
Matt Arsenault | 4599159 | 2019-01-18 21:33:50 +0000 | [diff] [blame] | 145 | getActionDefinitionsBuilder(G_CONSTANT) |
Matt Arsenault | 2065c94 | 2019-02-02 23:33:49 +0000 | [diff] [blame] | 146 | .legalFor({S1, S32, S64, GlobalPtr, |
| 147 | LocalPtr, ConstantPtr, PrivatePtr, FlatPtr }) |
Matt Arsenault | 4599159 | 2019-01-18 21:33:50 +0000 | [diff] [blame] | 148 | .clampScalar(0, S32, S64) |
Matt Arsenault | 2065c94 | 2019-02-02 23:33:49 +0000 | [diff] [blame] | 149 | .widenScalarToNextPow2(0) |
| 150 | .legalIf(isPointer(0)); |
Matt Arsenault | 06cbb27 | 2018-03-01 19:16:52 +0000 | [diff] [blame] | 151 | |
Matt Arsenault | c94e26c | 2018-12-18 09:46:13 +0000 | [diff] [blame] | 152 | setAction({G_FRAME_INDEX, PrivatePtr}, Legal); |
| 153 | |
Matt Arsenault | 93fdec7 | 2019-02-07 18:03:11 +0000 | [diff] [blame] | 154 | auto &FPOpActions = getActionDefinitionsBuilder( |
| 155 | { G_FADD, G_FMUL, G_FNEG, G_FABS, G_FMA}) |
| 156 | .legalFor({S32, S64}); |
| 157 | |
| 158 | if (ST.has16BitInsts()) { |
| 159 | if (ST.hasVOP3PInsts()) |
| 160 | FPOpActions.legalFor({S16, V2S16}); |
| 161 | else |
| 162 | FPOpActions.legalFor({S16}); |
| 163 | } |
| 164 | |
| 165 | if (ST.hasVOP3PInsts()) |
| 166 | FPOpActions.clampMaxNumElements(0, S16, 2); |
| 167 | FPOpActions |
| 168 | .scalarize(0) |
| 169 | .clampScalar(0, ST.has16BitInsts() ? S16 : S32, S64); |
Tom Stellard | d0c6cf2 | 2017-10-27 23:57:41 +0000 | [diff] [blame] | 170 | |
Matt Arsenault | c0f7569 | 2019-02-07 18:14:39 +0000 | [diff] [blame] | 171 | if (ST.has16BitInsts()) { |
| 172 | getActionDefinitionsBuilder(G_FSQRT) |
| 173 | .legalFor({S32, S64, S16}) |
| 174 | .scalarize(0) |
| 175 | .clampScalar(0, S16, S64); |
| 176 | } else { |
| 177 | getActionDefinitionsBuilder(G_FSQRT) |
| 178 | .legalFor({S32, S64}) |
| 179 | .scalarize(0) |
| 180 | .clampScalar(0, S32, S64); |
| 181 | } |
| 182 | |
Matt Arsenault | dff33c3 | 2018-12-20 00:37:02 +0000 | [diff] [blame] | 183 | getActionDefinitionsBuilder(G_FPTRUNC) |
Matt Arsenault | e6cebd0 | 2019-01-25 04:37:33 +0000 | [diff] [blame] | 184 | .legalFor({{S32, S64}, {S16, S32}}) |
| 185 | .scalarize(0); |
Matt Arsenault | dff33c3 | 2018-12-20 00:37:02 +0000 | [diff] [blame] | 186 | |
Matt Arsenault | 24563ef | 2019-01-20 18:34:24 +0000 | [diff] [blame] | 187 | getActionDefinitionsBuilder(G_FPEXT) |
| 188 | .legalFor({{S64, S32}, {S32, S16}}) |
Matt Arsenault | ca67634 | 2019-01-25 02:36:32 +0000 | [diff] [blame] | 189 | .lowerFor({{S64, S16}}) // FIXME: Implement |
| 190 | .scalarize(0); |
Matt Arsenault | 24563ef | 2019-01-20 18:34:24 +0000 | [diff] [blame] | 191 | |
Matt Arsenault | 745fd9f | 2019-01-20 19:10:31 +0000 | [diff] [blame] | 192 | getActionDefinitionsBuilder(G_FSUB) |
Matt Arsenault | aebb2ee | 2019-01-22 20:14:29 +0000 | [diff] [blame] | 193 | // Use actual fsub instruction |
| 194 | .legalFor({S32}) |
| 195 | // Must use fadd + fneg |
| 196 | .lowerFor({S64, S16, V2S16}) |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 197 | .scalarize(0) |
Matt Arsenault | aebb2ee | 2019-01-22 20:14:29 +0000 | [diff] [blame] | 198 | .clampScalar(0, S32, S64); |
Matt Arsenault | e01e7c8 | 2018-12-18 09:19:03 +0000 | [diff] [blame] | 199 | |
Matt Arsenault | 24563ef | 2019-01-20 18:34:24 +0000 | [diff] [blame] | 200 | getActionDefinitionsBuilder({G_SEXT, G_ZEXT, G_ANYEXT}) |
Matt Arsenault | 46ffe68 | 2019-01-20 19:28:20 +0000 | [diff] [blame] | 201 | .legalFor({{S64, S32}, {S32, S16}, {S64, S16}, |
Matt Arsenault | ca67634 | 2019-01-25 02:36:32 +0000 | [diff] [blame] | 202 | {S32, S1}, {S64, S1}, {S16, S1}, |
| 203 | // FIXME: Hack |
Matt Arsenault | 888aa5d | 2019-02-03 00:07:33 +0000 | [diff] [blame] | 204 | {S32, S8}, {S128, S32}, {S128, S64}, {S32, LLT::scalar(24)}}) |
Matt Arsenault | ca67634 | 2019-01-25 02:36:32 +0000 | [diff] [blame] | 205 | .scalarize(0); |
Matt Arsenault | f38f483 | 2018-12-13 08:23:51 +0000 | [diff] [blame] | 206 | |
Matt Arsenault | fb67164 | 2019-01-22 00:20:17 +0000 | [diff] [blame] | 207 | getActionDefinitionsBuilder({G_SITOFP, G_UITOFP}) |
Matt Arsenault | e6cebd0 | 2019-01-25 04:37:33 +0000 | [diff] [blame] | 208 | .legalFor({{S32, S32}, {S64, S32}}) |
| 209 | .scalarize(0); |
Matt Arsenault | dd022ce | 2018-03-01 19:04:25 +0000 | [diff] [blame] | 210 | |
Matt Arsenault | fb67164 | 2019-01-22 00:20:17 +0000 | [diff] [blame] | 211 | getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI}) |
Matt Arsenault | e6cebd0 | 2019-01-25 04:37:33 +0000 | [diff] [blame] | 212 | .legalFor({{S32, S32}, {S32, S64}}) |
| 213 | .scalarize(0); |
Tom Stellard | 3344576 | 2018-02-07 04:47:59 +0000 | [diff] [blame] | 214 | |
Matt Arsenault | f4c21c5 | 2018-12-21 03:14:45 +0000 | [diff] [blame] | 215 | getActionDefinitionsBuilder({G_INTRINSIC_TRUNC, G_INTRINSIC_ROUND}) |
Matt Arsenault | 2e5f900 | 2019-01-27 00:12:21 +0000 | [diff] [blame] | 216 | .legalFor({S32, S64}) |
| 217 | .scalarize(0); |
Matt Arsenault | f4c21c5 | 2018-12-21 03:14:45 +0000 | [diff] [blame] | 218 | |
Matt Arsenault | 685d1e8 | 2018-03-17 15:17:45 +0000 | [diff] [blame] | 219 | for (LLT PtrTy : AddrSpaces) { |
| 220 | LLT IdxTy = LLT::scalar(PtrTy.getSizeInBits()); |
| 221 | setAction({G_GEP, PtrTy}, Legal); |
| 222 | setAction({G_GEP, 1, IdxTy}, Legal); |
| 223 | } |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 224 | |
Matt Arsenault | 3b9a82f | 2019-01-25 04:54:00 +0000 | [diff] [blame] | 225 | // FIXME: When RegBankSelect inserts copies, it will only create new registers |
| 226 | // with scalar types. This means we can end up with G_LOAD/G_STORE/G_GEP |
| 227 | // instruction with scalar types for their pointer operands. In assert builds, |
| 228 | // the instruction selector will assert if it sees a generic instruction which |
| 229 | // isn't legal, so we need to tell it that scalar types are legal for pointer |
| 230 | // operands |
| 231 | setAction({G_GEP, S64}, Legal); |
| 232 | |
Matt Arsenault | 934e534 | 2018-12-13 20:34:15 +0000 | [diff] [blame] | 233 | setAction({G_BLOCK_ADDR, CodePtr}, Legal); |
| 234 | |
Matt Arsenault | 58f9d3d | 2019-02-02 23:35:15 +0000 | [diff] [blame] | 235 | getActionDefinitionsBuilder(G_ICMP) |
| 236 | .legalForCartesianProduct( |
| 237 | {S1}, {S32, S64, GlobalPtr, LocalPtr, ConstantPtr, PrivatePtr, FlatPtr}) |
| 238 | .legalFor({{S1, S32}, {S1, S64}}) |
| 239 | .widenScalarToNextPow2(1) |
| 240 | .clampScalar(1, S32, S64) |
| 241 | .scalarize(0) |
| 242 | .legalIf(all(typeIs(0, S1), isPointer(1))); |
| 243 | |
| 244 | getActionDefinitionsBuilder(G_FCMP) |
Matt Arsenault | 1b1e685 | 2019-01-25 02:59:34 +0000 | [diff] [blame] | 245 | .legalFor({{S1, S32}, {S1, S64}}) |
| 246 | .widenScalarToNextPow2(1) |
| 247 | .clampScalar(1, S32, S64) |
Matt Arsenault | ded2f82 | 2019-01-26 23:54:53 +0000 | [diff] [blame] | 248 | .scalarize(0); |
Matt Arsenault | 1b1e685 | 2019-01-25 02:59:34 +0000 | [diff] [blame] | 249 | |
Matt Arsenault | 95fd95c | 2019-01-25 04:03:38 +0000 | [diff] [blame] | 250 | // FIXME: fexp, flog2, flog10 needs to be custom lowered. |
| 251 | getActionDefinitionsBuilder({G_FPOW, G_FEXP, G_FEXP2, |
| 252 | G_FLOG, G_FLOG2, G_FLOG10}) |
| 253 | .legalFor({S32}) |
| 254 | .scalarize(0); |
Tom Stellard | 8cd60a5 | 2017-06-06 14:16:50 +0000 | [diff] [blame] | 255 | |
Matt Arsenault | d5684f7 | 2019-01-31 02:09:57 +0000 | [diff] [blame] | 256 | // The 64-bit versions produce 32-bit results, but only on the SALU. |
| 257 | getActionDefinitionsBuilder({G_CTLZ, G_CTLZ_ZERO_UNDEF, |
| 258 | G_CTTZ, G_CTTZ_ZERO_UNDEF, |
| 259 | G_CTPOP}) |
| 260 | .legalFor({{S32, S32}, {S32, S64}}) |
| 261 | .clampScalar(0, S32, S32) |
| 262 | .clampScalar(1, S32, S64); |
| 263 | // TODO: Scalarize |
| 264 | |
Matt Arsenault | d1bfc8d | 2019-01-31 02:34:03 +0000 | [diff] [blame] | 265 | // TODO: Expand for > s32 |
| 266 | getActionDefinitionsBuilder(G_BSWAP) |
| 267 | .legalFor({S32}) |
| 268 | .clampScalar(0, S32, S32) |
| 269 | .scalarize(0); |
Matt Arsenault | d5684f7 | 2019-01-31 02:09:57 +0000 | [diff] [blame] | 270 | |
Matt Arsenault | f38f483 | 2018-12-13 08:23:51 +0000 | [diff] [blame] | 271 | |
Matt Arsenault | cbaada6 | 2019-02-02 23:29:55 +0000 | [diff] [blame] | 272 | auto smallerThan = [](unsigned TypeIdx0, unsigned TypeIdx1) { |
| 273 | return [=](const LegalityQuery &Query) { |
| 274 | return Query.Types[TypeIdx0].getSizeInBits() < |
| 275 | Query.Types[TypeIdx1].getSizeInBits(); |
| 276 | }; |
| 277 | }; |
| 278 | |
| 279 | auto greaterThan = [](unsigned TypeIdx0, unsigned TypeIdx1) { |
| 280 | return [=](const LegalityQuery &Query) { |
| 281 | return Query.Types[TypeIdx0].getSizeInBits() > |
| 282 | Query.Types[TypeIdx1].getSizeInBits(); |
| 283 | }; |
| 284 | }; |
| 285 | |
Tom Stellard | 7c65078 | 2018-10-05 04:34:09 +0000 | [diff] [blame] | 286 | getActionDefinitionsBuilder(G_INTTOPTR) |
Matt Arsenault | cbaada6 | 2019-02-02 23:29:55 +0000 | [diff] [blame] | 287 | // List the common cases |
| 288 | .legalForCartesianProduct({GlobalPtr, ConstantPtr, FlatPtr}, {S64}) |
| 289 | .legalForCartesianProduct({LocalPtr, PrivatePtr}, {S32}) |
| 290 | .scalarize(0) |
| 291 | // Accept any address space as long as the size matches |
| 292 | .legalIf(sameSize(0, 1)) |
| 293 | .widenScalarIf(smallerThan(1, 0), |
| 294 | [](const LegalityQuery &Query) { |
| 295 | return std::make_pair(1, LLT::scalar(Query.Types[0].getSizeInBits())); |
| 296 | }) |
| 297 | .narrowScalarIf(greaterThan(1, 0), |
| 298 | [](const LegalityQuery &Query) { |
| 299 | return std::make_pair(1, LLT::scalar(Query.Types[0].getSizeInBits())); |
| 300 | }); |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 301 | |
Matt Arsenault | f38f483 | 2018-12-13 08:23:51 +0000 | [diff] [blame] | 302 | getActionDefinitionsBuilder(G_PTRTOINT) |
Matt Arsenault | cbaada6 | 2019-02-02 23:29:55 +0000 | [diff] [blame] | 303 | // List the common cases |
| 304 | .legalForCartesianProduct({GlobalPtr, ConstantPtr, FlatPtr}, {S64}) |
| 305 | .legalForCartesianProduct({LocalPtr, PrivatePtr}, {S32}) |
| 306 | .scalarize(0) |
| 307 | // Accept any address space as long as the size matches |
| 308 | .legalIf(sameSize(0, 1)) |
| 309 | .widenScalarIf(smallerThan(0, 1), |
| 310 | [](const LegalityQuery &Query) { |
| 311 | return std::make_pair(0, LLT::scalar(Query.Types[1].getSizeInBits())); |
| 312 | }) |
| 313 | .narrowScalarIf( |
| 314 | greaterThan(0, 1), |
| 315 | [](const LegalityQuery &Query) { |
| 316 | return std::make_pair(0, LLT::scalar(Query.Types[1].getSizeInBits())); |
| 317 | }); |
Matt Arsenault | f38f483 | 2018-12-13 08:23:51 +0000 | [diff] [blame] | 318 | |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 319 | getActionDefinitionsBuilder({G_LOAD, G_STORE}) |
Matt Arsenault | 18619af | 2019-01-29 18:13:02 +0000 | [diff] [blame] | 320 | .narrowScalarIf([](const LegalityQuery &Query) { |
| 321 | unsigned Size = Query.Types[0].getSizeInBits(); |
| 322 | unsigned MemSize = Query.MMODescrs[0].SizeInBits; |
| 323 | return (Size > 32 && MemSize < Size); |
| 324 | }, |
| 325 | [](const LegalityQuery &Query) { |
| 326 | return std::make_pair(0, LLT::scalar(32)); |
| 327 | }) |
Matt Arsenault | 045bc9a | 2019-01-30 02:35:38 +0000 | [diff] [blame] | 328 | .fewerElementsIf([=, &ST](const LegalityQuery &Query) { |
| 329 | unsigned MemSize = Query.MMODescrs[0].SizeInBits; |
Matt Arsenault | c7bce73 | 2019-01-31 02:46:05 +0000 | [diff] [blame] | 330 | return (MemSize == 96) && |
| 331 | Query.Types[0].isVector() && |
Matt Arsenault | 045bc9a | 2019-01-30 02:35:38 +0000 | [diff] [blame] | 332 | ST.getGeneration() < AMDGPUSubtarget::SEA_ISLANDS; |
| 333 | }, |
| 334 | [=](const LegalityQuery &Query) { |
| 335 | return std::make_pair(0, V2S32); |
| 336 | }) |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 337 | .legalIf([=, &ST](const LegalityQuery &Query) { |
| 338 | const LLT &Ty0 = Query.Types[0]; |
| 339 | |
Matt Arsenault | 18619af | 2019-01-29 18:13:02 +0000 | [diff] [blame] | 340 | unsigned Size = Ty0.getSizeInBits(); |
| 341 | unsigned MemSize = Query.MMODescrs[0].SizeInBits; |
Matt Arsenault | eb2603c | 2019-02-02 23:39:13 +0000 | [diff] [blame] | 342 | if (Size < 32 || (Size > 32 && MemSize < Size)) |
Matt Arsenault | 18619af | 2019-01-29 18:13:02 +0000 | [diff] [blame] | 343 | return false; |
| 344 | |
| 345 | if (Ty0.isVector() && Size != MemSize) |
| 346 | return false; |
| 347 | |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 348 | // TODO: Decompose private loads into 4-byte components. |
| 349 | // TODO: Illegal flat loads on SI |
Matt Arsenault | 18619af | 2019-01-29 18:13:02 +0000 | [diff] [blame] | 350 | switch (MemSize) { |
| 351 | case 8: |
| 352 | case 16: |
| 353 | return Size == 32; |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 354 | case 32: |
| 355 | case 64: |
| 356 | case 128: |
| 357 | return true; |
| 358 | |
| 359 | case 96: |
| 360 | // XXX hasLoadX3 |
| 361 | return (ST.getGeneration() >= AMDGPUSubtarget::SEA_ISLANDS); |
| 362 | |
| 363 | case 256: |
| 364 | case 512: |
| 365 | // TODO: constant loads |
| 366 | default: |
| 367 | return false; |
| 368 | } |
Matt Arsenault | 18619af | 2019-01-29 18:13:02 +0000 | [diff] [blame] | 369 | }) |
| 370 | .clampScalar(0, S32, S64); |
Matt Arsenault | 8580336 | 2018-03-17 15:17:41 +0000 | [diff] [blame] | 371 | |
| 372 | |
Matt Arsenault | 6614f85 | 2019-01-22 19:02:10 +0000 | [diff] [blame] | 373 | auto &ExtLoads = getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD}) |
| 374 | .legalForTypesWithMemSize({ |
| 375 | {S32, GlobalPtr, 8}, |
| 376 | {S32, GlobalPtr, 16}, |
| 377 | {S32, LocalPtr, 8}, |
| 378 | {S32, LocalPtr, 16}, |
| 379 | {S32, PrivatePtr, 8}, |
| 380 | {S32, PrivatePtr, 16}}); |
| 381 | if (ST.hasFlatAddressSpace()) { |
| 382 | ExtLoads.legalForTypesWithMemSize({{S32, FlatPtr, 8}, |
| 383 | {S32, FlatPtr, 16}}); |
| 384 | } |
| 385 | |
| 386 | ExtLoads.clampScalar(0, S32, S32) |
| 387 | .widenScalarToNextPow2(0) |
| 388 | .unsupportedIfMemSizeNotPow2() |
| 389 | .lower(); |
| 390 | |
Matt Arsenault | 36d4092 | 2018-12-20 00:33:49 +0000 | [diff] [blame] | 391 | auto &Atomics = getActionDefinitionsBuilder( |
| 392 | {G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB, |
| 393 | G_ATOMICRMW_AND, G_ATOMICRMW_OR, G_ATOMICRMW_XOR, |
| 394 | G_ATOMICRMW_MAX, G_ATOMICRMW_MIN, G_ATOMICRMW_UMAX, |
| 395 | G_ATOMICRMW_UMIN, G_ATOMIC_CMPXCHG}) |
| 396 | .legalFor({{S32, GlobalPtr}, {S32, LocalPtr}, |
| 397 | {S64, GlobalPtr}, {S64, LocalPtr}}); |
| 398 | if (ST.hasFlatAddressSpace()) { |
| 399 | Atomics.legalFor({{S32, FlatPtr}, {S64, FlatPtr}}); |
| 400 | } |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 401 | |
Matt Arsenault | 96e4701 | 2019-01-18 21:42:55 +0000 | [diff] [blame] | 402 | // TODO: Pointer types, any 32-bit or 64-bit vector |
| 403 | getActionDefinitionsBuilder(G_SELECT) |
Matt Arsenault | 1054723 | 2019-02-04 14:04:52 +0000 | [diff] [blame] | 404 | .legalForCartesianProduct({S32, S64, V2S32, V2S16, V4S16, |
| 405 | GlobalPtr, LocalPtr, FlatPtr, PrivatePtr, |
| 406 | LLT::vector(2, LocalPtr), LLT::vector(2, PrivatePtr)}, {S1}) |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 407 | .clampScalar(0, S32, S64) |
Matt Arsenault | dc6c785 | 2019-01-30 04:19:31 +0000 | [diff] [blame] | 408 | .fewerElementsIf( |
| 409 | [=](const LegalityQuery &Query) { |
| 410 | if (Query.Types[1].isVector()) |
| 411 | return true; |
| 412 | |
| 413 | LLT Ty = Query.Types[0]; |
| 414 | |
| 415 | // FIXME: Hack until odd splits handled |
| 416 | return Ty.isVector() && |
| 417 | (Ty.getScalarSizeInBits() > 32 || Ty.getNumElements() % 2 != 0); |
| 418 | }, |
| 419 | scalarize(0)) |
| 420 | // FIXME: Handle 16-bit vectors better |
| 421 | .fewerElementsIf( |
| 422 | [=](const LegalityQuery &Query) { |
| 423 | return Query.Types[0].isVector() && |
| 424 | Query.Types[0].getElementType().getSizeInBits() < 32;}, |
| 425 | scalarize(0)) |
| 426 | .scalarize(1) |
Matt Arsenault | 2491f82 | 2019-02-02 23:31:50 +0000 | [diff] [blame] | 427 | .clampMaxNumElements(0, S32, 2) |
| 428 | .clampMaxNumElements(0, LocalPtr, 2) |
| 429 | .clampMaxNumElements(0, PrivatePtr, 2) |
| 430 | .legalIf(all(isPointer(0), typeIs(1, S1))); |
Tom Stellard | 2860a42 | 2017-06-07 13:54:51 +0000 | [diff] [blame] | 431 | |
Matt Arsenault | 4c5e8f51 | 2019-01-22 22:00:19 +0000 | [diff] [blame] | 432 | // TODO: Only the low 4/5/6 bits of the shift amount are observed, so we can |
| 433 | // be more flexible with the shift amount type. |
| 434 | auto &Shifts = getActionDefinitionsBuilder({G_SHL, G_LSHR, G_ASHR}) |
| 435 | .legalFor({{S32, S32}, {S64, S32}}); |
Matt Arsenault | f6cab16 | 2019-01-30 03:36:25 +0000 | [diff] [blame] | 436 | if (ST.has16BitInsts()) { |
Matt Arsenault | c83b823 | 2019-02-07 17:38:00 +0000 | [diff] [blame] | 437 | if (ST.hasVOP3PInsts()) { |
| 438 | Shifts.legalFor({{S16, S32}, {S16, S16}, {V2S16, V2S16}}) |
| 439 | .clampMaxNumElements(0, S16, 2); |
| 440 | } else |
| 441 | Shifts.legalFor({{S16, S32}, {S16, S16}}); |
Matt Arsenault | fbec8fe | 2019-02-07 19:37:44 +0000 | [diff] [blame] | 442 | |
| 443 | Shifts.clampScalar(1, S16, S32); |
Matt Arsenault | f6cab16 | 2019-01-30 03:36:25 +0000 | [diff] [blame] | 444 | Shifts.clampScalar(0, S16, S64); |
Matt Arsenault | fbec8fe | 2019-02-07 19:37:44 +0000 | [diff] [blame] | 445 | } else { |
| 446 | // Make sure we legalize the shift amount type first, as the general |
| 447 | // expansion for the shifted type will produce much worse code if it hasn't |
| 448 | // been truncated already. |
| 449 | Shifts.clampScalar(1, S32, S32); |
Matt Arsenault | 4c5e8f51 | 2019-01-22 22:00:19 +0000 | [diff] [blame] | 450 | Shifts.clampScalar(0, S32, S64); |
Matt Arsenault | fbec8fe | 2019-02-07 19:37:44 +0000 | [diff] [blame] | 451 | } |
| 452 | Shifts.scalarize(0); |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 453 | |
Matt Arsenault | 7b9ed89 | 2018-03-12 13:35:53 +0000 | [diff] [blame] | 454 | for (unsigned Op : {G_EXTRACT_VECTOR_ELT, G_INSERT_VECTOR_ELT}) { |
Matt Arsenault | 6378629 | 2019-01-22 20:38:15 +0000 | [diff] [blame] | 455 | unsigned VecTypeIdx = Op == G_EXTRACT_VECTOR_ELT ? 1 : 0; |
| 456 | unsigned EltTypeIdx = Op == G_EXTRACT_VECTOR_ELT ? 0 : 1; |
| 457 | unsigned IdxTypeIdx = 2; |
| 458 | |
Matt Arsenault | 7b9ed89 | 2018-03-12 13:35:53 +0000 | [diff] [blame] | 459 | getActionDefinitionsBuilder(Op) |
| 460 | .legalIf([=](const LegalityQuery &Query) { |
Matt Arsenault | 6378629 | 2019-01-22 20:38:15 +0000 | [diff] [blame] | 461 | const LLT &VecTy = Query.Types[VecTypeIdx]; |
| 462 | const LLT &IdxTy = Query.Types[IdxTypeIdx]; |
Matt Arsenault | 7b9ed89 | 2018-03-12 13:35:53 +0000 | [diff] [blame] | 463 | return VecTy.getSizeInBits() % 32 == 0 && |
| 464 | VecTy.getSizeInBits() <= 512 && |
| 465 | IdxTy.getSizeInBits() == 32; |
Matt Arsenault | 6378629 | 2019-01-22 20:38:15 +0000 | [diff] [blame] | 466 | }) |
| 467 | .clampScalar(EltTypeIdx, S32, S64) |
| 468 | .clampScalar(VecTypeIdx, S32, S64) |
| 469 | .clampScalar(IdxTypeIdx, S32, S32); |
Matt Arsenault | 7b9ed89 | 2018-03-12 13:35:53 +0000 | [diff] [blame] | 470 | } |
| 471 | |
Matt Arsenault | 6378629 | 2019-01-22 20:38:15 +0000 | [diff] [blame] | 472 | getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT) |
| 473 | .unsupportedIf([=](const LegalityQuery &Query) { |
| 474 | const LLT &EltTy = Query.Types[1].getElementType(); |
| 475 | return Query.Types[0] != EltTy; |
| 476 | }); |
| 477 | |
Matt Arsenault | 71272e6 | 2018-03-05 16:25:15 +0000 | [diff] [blame] | 478 | // FIXME: Doesn't handle extract of illegal sizes. |
Tom Stellard | b7f19e6 | 2018-07-24 02:19:20 +0000 | [diff] [blame] | 479 | getActionDefinitionsBuilder({G_EXTRACT, G_INSERT}) |
Matt Arsenault | 91be65b | 2019-02-07 17:25:51 +0000 | [diff] [blame] | 480 | .legalIf([=](const LegalityQuery &Query) { |
Matt Arsenault | 71272e6 | 2018-03-05 16:25:15 +0000 | [diff] [blame] | 481 | const LLT &Ty0 = Query.Types[0]; |
| 482 | const LLT &Ty1 = Query.Types[1]; |
Matt Arsenault | 26a6c74 | 2019-01-26 23:47:07 +0000 | [diff] [blame] | 483 | return (Ty0.getSizeInBits() % 16 == 0) && |
| 484 | (Ty1.getSizeInBits() % 16 == 0); |
Matt Arsenault | 0e5d856 | 2019-02-02 23:56:00 +0000 | [diff] [blame] | 485 | }) |
Matt Arsenault | 91be65b | 2019-02-07 17:25:51 +0000 | [diff] [blame] | 486 | .widenScalarIf( |
| 487 | [=](const LegalityQuery &Query) { |
| 488 | const LLT Ty1 = Query.Types[1]; |
| 489 | return (Ty1.getScalarSizeInBits() < 16); |
| 490 | }, |
| 491 | LegalizeMutations::widenScalarOrEltToNextPow2(1, 16)); |
Matt Arsenault | 71272e6 | 2018-03-05 16:25:15 +0000 | [diff] [blame] | 492 | |
Matt Arsenault | cbaada6 | 2019-02-02 23:29:55 +0000 | [diff] [blame] | 493 | // TODO: vectors of pointers |
Amara Emerson | 5ec1460 | 2018-12-10 18:44:58 +0000 | [diff] [blame] | 494 | getActionDefinitionsBuilder(G_BUILD_VECTOR) |
Matt Arsenault | aebb2ee | 2019-01-22 20:14:29 +0000 | [diff] [blame] | 495 | .legalForCartesianProduct(AllS32Vectors, {S32}) |
| 496 | .legalForCartesianProduct(AllS64Vectors, {S64}) |
| 497 | .clampNumElements(0, V16S32, V16S32) |
| 498 | .clampNumElements(0, V2S64, V8S64) |
| 499 | .minScalarSameAs(1, 0) |
| 500 | // FIXME: Sort of a hack to make progress on other legalizations. |
| 501 | .legalIf([=](const LegalityQuery &Query) { |
Matt Arsenault | 2491f82 | 2019-02-02 23:31:50 +0000 | [diff] [blame] | 502 | return Query.Types[0].getScalarSizeInBits() <= 32 || |
| 503 | Query.Types[0].getScalarSizeInBits() == 64; |
Matt Arsenault | aebb2ee | 2019-01-22 20:14:29 +0000 | [diff] [blame] | 504 | }); |
Matt Arsenault | bee2ad7 | 2018-12-21 03:03:11 +0000 | [diff] [blame] | 505 | |
Matt Arsenault | a1515d2 | 2019-01-08 01:30:02 +0000 | [diff] [blame] | 506 | // TODO: Support any combination of v2s32 |
| 507 | getActionDefinitionsBuilder(G_CONCAT_VECTORS) |
| 508 | .legalFor({{V4S32, V2S32}, |
| 509 | {V8S32, V2S32}, |
| 510 | {V8S32, V4S32}, |
| 511 | {V4S64, V2S64}, |
| 512 | {V4S16, V2S16}, |
| 513 | {V8S16, V2S16}, |
Matt Arsenault | 2491f82 | 2019-02-02 23:31:50 +0000 | [diff] [blame] | 514 | {V8S16, V4S16}, |
| 515 | {LLT::vector(4, LocalPtr), LLT::vector(2, LocalPtr)}, |
| 516 | {LLT::vector(4, PrivatePtr), LLT::vector(2, PrivatePtr)}}); |
Matt Arsenault | a1515d2 | 2019-01-08 01:30:02 +0000 | [diff] [blame] | 517 | |
Matt Arsenault | 503afda | 2018-03-12 13:35:43 +0000 | [diff] [blame] | 518 | // Merge/Unmerge |
| 519 | for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) { |
| 520 | unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1; |
| 521 | unsigned LitTyIdx = Op == G_MERGE_VALUES ? 1 : 0; |
| 522 | |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 523 | auto notValidElt = [=](const LegalityQuery &Query, unsigned TypeIdx) { |
| 524 | const LLT &Ty = Query.Types[TypeIdx]; |
| 525 | if (Ty.isVector()) { |
| 526 | const LLT &EltTy = Ty.getElementType(); |
| 527 | if (EltTy.getSizeInBits() < 8 || EltTy.getSizeInBits() > 64) |
| 528 | return true; |
| 529 | if (!isPowerOf2_32(EltTy.getSizeInBits())) |
| 530 | return true; |
| 531 | } |
| 532 | return false; |
| 533 | }; |
| 534 | |
Matt Arsenault | 503afda | 2018-03-12 13:35:43 +0000 | [diff] [blame] | 535 | getActionDefinitionsBuilder(Op) |
Matt Arsenault | d8d193d | 2019-01-29 23:17:35 +0000 | [diff] [blame] | 536 | .widenScalarToNextPow2(LitTyIdx, /*Min*/ 16) |
| 537 | // Clamp the little scalar to s8-s256 and make it a power of 2. It's not |
| 538 | // worth considering the multiples of 64 since 2*192 and 2*384 are not |
| 539 | // valid. |
| 540 | .clampScalar(LitTyIdx, S16, S256) |
| 541 | .widenScalarToNextPow2(LitTyIdx, /*Min*/ 32) |
| 542 | |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 543 | // Break up vectors with weird elements into scalars |
| 544 | .fewerElementsIf( |
| 545 | [=](const LegalityQuery &Query) { return notValidElt(Query, 0); }, |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 546 | scalarize(0)) |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 547 | .fewerElementsIf( |
| 548 | [=](const LegalityQuery &Query) { return notValidElt(Query, 1); }, |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 549 | scalarize(1)) |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 550 | .clampScalar(BigTyIdx, S32, S512) |
| 551 | .widenScalarIf( |
| 552 | [=](const LegalityQuery &Query) { |
| 553 | const LLT &Ty = Query.Types[BigTyIdx]; |
| 554 | return !isPowerOf2_32(Ty.getSizeInBits()) && |
| 555 | Ty.getSizeInBits() % 16 != 0; |
| 556 | }, |
| 557 | [=](const LegalityQuery &Query) { |
| 558 | // Pick the next power of 2, or a multiple of 64 over 128. |
| 559 | // Whichever is smaller. |
| 560 | const LLT &Ty = Query.Types[BigTyIdx]; |
| 561 | unsigned NewSizeInBits = 1 << Log2_32_Ceil(Ty.getSizeInBits() + 1); |
| 562 | if (NewSizeInBits >= 256) { |
| 563 | unsigned RoundedTo = alignTo<64>(Ty.getSizeInBits() + 1); |
| 564 | if (RoundedTo < NewSizeInBits) |
| 565 | NewSizeInBits = RoundedTo; |
| 566 | } |
| 567 | return std::make_pair(BigTyIdx, LLT::scalar(NewSizeInBits)); |
| 568 | }) |
Matt Arsenault | 503afda | 2018-03-12 13:35:43 +0000 | [diff] [blame] | 569 | .legalIf([=](const LegalityQuery &Query) { |
| 570 | const LLT &BigTy = Query.Types[BigTyIdx]; |
| 571 | const LLT &LitTy = Query.Types[LitTyIdx]; |
Matt Arsenault | ff6a9a2 | 2019-01-20 18:40:36 +0000 | [diff] [blame] | 572 | |
| 573 | if (BigTy.isVector() && BigTy.getSizeInBits() < 32) |
| 574 | return false; |
| 575 | if (LitTy.isVector() && LitTy.getSizeInBits() < 32) |
| 576 | return false; |
| 577 | |
| 578 | return BigTy.getSizeInBits() % 16 == 0 && |
| 579 | LitTy.getSizeInBits() % 16 == 0 && |
Matt Arsenault | 503afda | 2018-03-12 13:35:43 +0000 | [diff] [blame] | 580 | BigTy.getSizeInBits() <= 512; |
| 581 | }) |
| 582 | // Any vectors left are the wrong size. Scalarize them. |
Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 583 | .scalarize(0) |
| 584 | .scalarize(1); |
Matt Arsenault | 503afda | 2018-03-12 13:35:43 +0000 | [diff] [blame] | 585 | } |
| 586 | |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 587 | computeTables(); |
Roman Tereshin | 76c29c6 | 2018-05-31 16:16:48 +0000 | [diff] [blame] | 588 | verify(*ST.getInstrInfo()); |
Tom Stellard | ca16621 | 2017-01-30 21:56:46 +0000 | [diff] [blame] | 589 | } |