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