| Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 1 | //===- AArch64LegalizerInfo.cpp ----------------------------------*- C++ -*-==// | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 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 | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
|  | 8 | /// \file | 
|  | 9 | /// This file implements the targeting of the Machinelegalizer class for | 
|  | 10 | /// AArch64. | 
|  | 11 | /// \todo This should be generated by TableGen. | 
|  | 12 | //===----------------------------------------------------------------------===// | 
|  | 13 |  | 
| Tim Northover | 69fa84a | 2016-10-14 22:18:18 +0000 | [diff] [blame] | 14 | #include "AArch64LegalizerInfo.h" | 
| Daniel Sanders | 7fe7acc | 2017-11-28 20:21:15 +0000 | [diff] [blame] | 15 | #include "AArch64Subtarget.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 16 | #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h" | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 17 | #include "llvm/CodeGen/MachineInstr.h" | 
|  | 18 | #include "llvm/CodeGen/MachineRegisterInfo.h" | 
| David Blaikie | b3bde2e | 2017-11-17 01:07:10 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/TargetOpcodes.h" | 
| Craig Topper | 2fa1436 | 2018-03-29 17:21:10 +0000 | [diff] [blame] | 20 | #include "llvm/CodeGen/ValueTypes.h" | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 21 | #include "llvm/IR/DerivedTypes.h" | 
| Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 22 | #include "llvm/IR/Type.h" | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 23 |  | 
|  | 24 | using namespace llvm; | 
| Daniel Sanders | 9ade559 | 2018-01-29 17:37:29 +0000 | [diff] [blame] | 25 | using namespace LegalizeActions; | 
| Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 26 | using namespace LegalizeMutations; | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 27 | using namespace LegalityPredicates; | 
| Kristof Beyls | af9814a | 2017-11-07 10:34:34 +0000 | [diff] [blame] | 28 |  | 
| Daniel Sanders | 7fe7acc | 2017-11-28 20:21:15 +0000 | [diff] [blame] | 29 | AArch64LegalizerInfo::AArch64LegalizerInfo(const AArch64Subtarget &ST) { | 
| Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 30 | using namespace TargetOpcode; | 
| Tim Northover | 5ae8350 | 2016-09-15 09:20:34 +0000 | [diff] [blame] | 31 | const LLT p0 = LLT::pointer(0, 64); | 
| Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 32 | const LLT s1 = LLT::scalar(1); | 
| Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 33 | const LLT s8 = LLT::scalar(8); | 
|  | 34 | const LLT s16 = LLT::scalar(16); | 
| Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 35 | const LLT s32 = LLT::scalar(32); | 
|  | 36 | const LLT s64 = LLT::scalar(64); | 
| Quentin Colombet | 7c114d3 | 2017-10-16 22:28:27 +0000 | [diff] [blame] | 37 | const LLT s128 = LLT::scalar(128); | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 38 | const LLT s256 = LLT::scalar(256); | 
|  | 39 | const LLT s512 = LLT::scalar(512); | 
|  | 40 | const LLT v16s8 = LLT::vector(16, 8); | 
|  | 41 | const LLT v8s8 = LLT::vector(8, 8); | 
|  | 42 | const LLT v4s8 = LLT::vector(4, 8); | 
|  | 43 | const LLT v8s16 = LLT::vector(8, 16); | 
|  | 44 | const LLT v4s16 = LLT::vector(4, 16); | 
|  | 45 | const LLT v2s16 = LLT::vector(2, 16); | 
| Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 46 | const LLT v2s32 = LLT::vector(2, 32); | 
|  | 47 | const LLT v4s32 = LLT::vector(4, 32); | 
|  | 48 | const LLT v2s64 = LLT::vector(2, 64); | 
|  | 49 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 50 | getActionDefinitionsBuilder(G_IMPLICIT_DEF) | 
| Matt Arsenault | 3dddb16 | 2019-01-09 07:51:52 +0000 | [diff] [blame] | 51 | .legalFor({p0, s1, s8, s16, s32, s64, v2s64}) | 
|  | 52 | .clampScalar(0, s1, s64) | 
|  | 53 | .widenScalarToNextPow2(0, 8) | 
|  | 54 | .fewerElementsIf( | 
|  | 55 | [=](const LegalityQuery &Query) { | 
|  | 56 | return Query.Types[0].isVector() && | 
|  | 57 | (Query.Types[0].getElementType() != s64 || | 
|  | 58 | Query.Types[0].getNumElements() != 2); | 
|  | 59 | }, | 
|  | 60 | [=](const LegalityQuery &Query) { | 
|  | 61 | LLT EltTy = Query.Types[0].getElementType(); | 
|  | 62 | if (EltTy == s64) | 
|  | 63 | return std::make_pair(0, LLT::vector(2, 64)); | 
|  | 64 | return std::make_pair(0, EltTy); | 
|  | 65 | }); | 
| Tim Northover | ff5e7e1 | 2017-06-30 20:27:36 +0000 | [diff] [blame] | 66 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 67 | getActionDefinitionsBuilder(G_PHI) | 
|  | 68 | .legalFor({p0, s16, s32, s64}) | 
|  | 69 | .clampScalar(0, s16, s64) | 
|  | 70 | .widenScalarToNextPow2(0); | 
| Aditya Nandakumar | efd8a84 | 2017-08-23 20:45:48 +0000 | [diff] [blame] | 71 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 72 | getActionDefinitionsBuilder(G_BSWAP) | 
|  | 73 | .legalFor({s32, s64}) | 
|  | 74 | .clampScalar(0, s16, s64) | 
|  | 75 | .widenScalarToNextPow2(0); | 
| Aditya Nandakumar | 892979e | 2017-08-25 04:57:27 +0000 | [diff] [blame] | 76 |  | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 77 | getActionDefinitionsBuilder({G_ADD, G_SUB, G_MUL, G_AND, G_OR, G_XOR}) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 78 | .legalFor({s32, s64, v2s32, v4s32, v2s64}) | 
|  | 79 | .clampScalar(0, s32, s64) | 
|  | 80 | .widenScalarToNextPow2(0) | 
|  | 81 | .clampNumElements(0, v2s32, v4s32) | 
|  | 82 | .clampNumElements(0, v2s64, v2s64) | 
|  | 83 | .moreElementsToNextPow2(0); | 
| Daniel Sanders | 83e23d1 | 2017-09-19 14:25:15 +0000 | [diff] [blame] | 84 |  | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 85 | getActionDefinitionsBuilder(G_SHL) | 
|  | 86 | .legalFor({{s32, s32}, {s64, s64}, | 
|  | 87 | {v2s32, v2s32}, {v4s32, v4s32}, {v2s64, v2s64}}) | 
| Matt Arsenault | fbec8fe | 2019-02-07 19:37:44 +0000 | [diff] [blame] | 88 | .clampScalar(1, s32, s64) | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 89 | .clampScalar(0, s32, s64) | 
|  | 90 | .widenScalarToNextPow2(0) | 
|  | 91 | .clampNumElements(0, v2s32, v4s32) | 
|  | 92 | .clampNumElements(0, v2s64, v2s64) | 
|  | 93 | .moreElementsToNextPow2(0) | 
|  | 94 | .minScalarSameAs(1, 0); | 
|  | 95 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 96 | getActionDefinitionsBuilder(G_GEP) | 
|  | 97 | .legalFor({{p0, s64}}) | 
|  | 98 | .clampScalar(1, s64, s64); | 
| Ahmed Bougacha | cfb384d | 2017-01-23 21:10:05 +0000 | [diff] [blame] | 99 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 100 | getActionDefinitionsBuilder(G_PTR_MASK).legalFor({p0}); | 
| Tim Northover | 9656f14 | 2016-08-04 20:54:13 +0000 | [diff] [blame] | 101 |  | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 102 | getActionDefinitionsBuilder({G_SDIV, G_UDIV}) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 103 | .legalFor({s32, s64}) | 
|  | 104 | .clampScalar(0, s32, s64) | 
|  | 105 | .widenScalarToNextPow2(0); | 
| Tim Northover | 7a753d9 | 2016-08-26 17:46:06 +0000 | [diff] [blame] | 106 |  | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 107 | getActionDefinitionsBuilder({G_LSHR, G_ASHR}) | 
|  | 108 | .legalFor({{s32, s32}, {s64, s64}}) | 
| Matt Arsenault | fbec8fe | 2019-02-07 19:37:44 +0000 | [diff] [blame] | 109 | .clampScalar(1, s32, s64) | 
| Matt Arsenault | 30989e4 | 2019-01-22 21:42:11 +0000 | [diff] [blame] | 110 | .clampScalar(0, s32, s64) | 
|  | 111 | .minScalarSameAs(1, 0); | 
|  | 112 |  | 
| Daniel Sanders | 5281b02 | 2018-04-09 21:10:09 +0000 | [diff] [blame] | 113 | getActionDefinitionsBuilder({G_SREM, G_UREM}) | 
|  | 114 | .lowerFor({s1, s8, s16, s32, s64}); | 
| Tim Northover | cecee56 | 2016-08-26 17:46:13 +0000 | [diff] [blame] | 115 |  | 
| Daniel Sanders | 5281b02 | 2018-04-09 21:10:09 +0000 | [diff] [blame] | 116 | getActionDefinitionsBuilder({G_SMULO, G_UMULO}) | 
|  | 117 | .lowerFor({{s64, s1}}); | 
| Tim Northover | 0a9b279 | 2017-02-08 21:22:15 +0000 | [diff] [blame] | 118 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 119 | getActionDefinitionsBuilder({G_SMULH, G_UMULH}).legalFor({s32, s64}); | 
| Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 120 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 121 | getActionDefinitionsBuilder({G_UADDE, G_USUBE, G_SADDO, G_SSUBO}) | 
|  | 122 | .legalFor({{s32, s1}, {s64, s1}}); | 
| Tim Northover | d8a6d7c | 2016-08-25 17:37:41 +0000 | [diff] [blame] | 123 |  | 
| Amara Emerson | 0bfa2fa | 2019-01-28 02:28:22 +0000 | [diff] [blame] | 124 | getActionDefinitionsBuilder({G_FADD, G_FSUB, G_FMA, G_FMUL, G_FDIV, G_FNEG}) | 
|  | 125 | .legalFor({s32, s64, v2s64, v4s32, v2s32}); | 
| Ahmed Bougacha | 33e19fe | 2016-08-18 16:05:11 +0000 | [diff] [blame] | 126 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 127 | getActionDefinitionsBuilder({G_FREM, G_FPOW}).libcallFor({s32, s64}); | 
| Tim Northover | edb3c8c | 2016-08-29 19:07:16 +0000 | [diff] [blame] | 128 |  | 
| Jessica Paquette | ebdb021 | 2019-02-11 17:22:58 +0000 | [diff] [blame] | 129 | getActionDefinitionsBuilder({G_FCEIL, G_FABS, G_FSQRT, G_FFLOOR}) | 
| Jessica Paquette | 245047d | 2019-01-24 22:00:41 +0000 | [diff] [blame] | 130 | // If we don't have full FP16 support, then scalarize the elements of | 
|  | 131 | // vectors containing fp16 types. | 
|  | 132 | .fewerElementsIf( | 
|  | 133 | [=, &ST](const LegalityQuery &Query) { | 
|  | 134 | const auto &Ty = Query.Types[0]; | 
|  | 135 | return Ty.isVector() && Ty.getElementType() == s16 && | 
|  | 136 | !ST.hasFullFP16(); | 
|  | 137 | }, | 
|  | 138 | [=](const LegalityQuery &Query) { return std::make_pair(0, s16); }) | 
| Jessica Paquette | 453ab1d | 2018-12-21 17:05:26 +0000 | [diff] [blame] | 139 | // If we don't have full FP16 support, then widen s16 to s32 if we | 
|  | 140 | // encounter it. | 
|  | 141 | .widenScalarIf( | 
|  | 142 | [=, &ST](const LegalityQuery &Query) { | 
|  | 143 | return Query.Types[0] == s16 && !ST.hasFullFP16(); | 
|  | 144 | }, | 
|  | 145 | [=](const LegalityQuery &Query) { return std::make_pair(0, s32); }) | 
| Jessica Paquette | 245047d | 2019-01-24 22:00:41 +0000 | [diff] [blame] | 146 | .legalFor({s16, s32, s64, v2s32, v4s32, v2s64, v2s16, v4s16, v8s16}); | 
| Jessica Paquette | 3560e93 | 2018-12-19 19:01:36 +0000 | [diff] [blame] | 147 |  | 
| Jessica Paquette | 84bedac | 2019-01-30 23:46:15 +0000 | [diff] [blame] | 148 | getActionDefinitionsBuilder( | 
|  | 149 | {G_FCOS, G_FSIN, G_FLOG10, G_FLOG, G_FLOG2, G_FEXP}) | 
| Jessica Paquette | 7db82d7 | 2019-01-28 18:34:18 +0000 | [diff] [blame] | 150 | // We need a call for these, so we always need to scalarize. | 
|  | 151 | .scalarize(0) | 
|  | 152 | // Regardless of FP16 support, widen 16-bit elements to 32-bits. | 
|  | 153 | .minScalar(0, s32) | 
|  | 154 | .libcallFor({s32, s64, v2s32, v4s32, v2s64}); | 
|  | 155 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 156 | getActionDefinitionsBuilder(G_INSERT) | 
|  | 157 | .unsupportedIf([=](const LegalityQuery &Query) { | 
|  | 158 | return Query.Types[0].getSizeInBits() <= Query.Types[1].getSizeInBits(); | 
|  | 159 | }) | 
|  | 160 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 161 | const LLT &Ty0 = Query.Types[0]; | 
|  | 162 | const LLT &Ty1 = Query.Types[1]; | 
|  | 163 | if (Ty0 != s32 && Ty0 != s64 && Ty0 != p0) | 
|  | 164 | return false; | 
|  | 165 | return isPowerOf2_32(Ty1.getSizeInBits()) && | 
|  | 166 | (Ty1.getSizeInBits() == 1 || Ty1.getSizeInBits() >= 8); | 
|  | 167 | }) | 
|  | 168 | .clampScalar(0, s32, s64) | 
|  | 169 | .widenScalarToNextPow2(0) | 
|  | 170 | .maxScalarIf(typeInSet(0, {s32}), 1, s16) | 
|  | 171 | .maxScalarIf(typeInSet(0, {s64}), 1, s32) | 
|  | 172 | .widenScalarToNextPow2(1); | 
| Tim Northover | 0e6afbd | 2017-02-06 21:56:47 +0000 | [diff] [blame] | 173 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 174 | getActionDefinitionsBuilder(G_EXTRACT) | 
|  | 175 | .unsupportedIf([=](const LegalityQuery &Query) { | 
|  | 176 | return Query.Types[0].getSizeInBits() >= Query.Types[1].getSizeInBits(); | 
|  | 177 | }) | 
|  | 178 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 179 | const LLT &Ty0 = Query.Types[0]; | 
|  | 180 | const LLT &Ty1 = Query.Types[1]; | 
|  | 181 | if (Ty1 != s32 && Ty1 != s64) | 
|  | 182 | return false; | 
|  | 183 | if (Ty1 == p0) | 
|  | 184 | return true; | 
|  | 185 | return isPowerOf2_32(Ty0.getSizeInBits()) && | 
|  | 186 | (Ty0.getSizeInBits() == 1 || Ty0.getSizeInBits() >= 8); | 
|  | 187 | }) | 
|  | 188 | .clampScalar(1, s32, s64) | 
|  | 189 | .widenScalarToNextPow2(1) | 
|  | 190 | .maxScalarIf(typeInSet(1, {s32}), 0, s16) | 
|  | 191 | .maxScalarIf(typeInSet(1, {s64}), 0, s32) | 
|  | 192 | .widenScalarToNextPow2(0); | 
| Tim Northover | c2d5e6d | 2017-06-26 20:34:13 +0000 | [diff] [blame] | 193 |  | 
| Daniel Sanders | 5eb9f58 | 2018-04-28 18:14:50 +0000 | [diff] [blame] | 194 | getActionDefinitionsBuilder({G_SEXTLOAD, G_ZEXTLOAD}) | 
| Matt Arsenault | 530d05e | 2019-02-14 22:41:09 +0000 | [diff] [blame] | 195 | .legalForTypesWithMemDesc({{s32, p0, 8, 8}, | 
|  | 196 | {s32, p0, 16, 8}, | 
|  | 197 | {s32, p0, 32, 8}, | 
|  | 198 | {s64, p0, 64, 8}, | 
|  | 199 | {p0, p0, 64, 8}, | 
|  | 200 | {v2s32, p0, 64, 8}}) | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 201 | .clampScalar(0, s32, s64) | 
|  | 202 | .widenScalarToNextPow2(0) | 
|  | 203 | // TODO: We could support sum-of-pow2's but the lowering code doesn't know | 
|  | 204 | //       how to do that yet. | 
|  | 205 | .unsupportedIfMemSizeNotPow2() | 
|  | 206 | // Lower anything left over into G_*EXT and G_LOAD | 
| Daniel Sanders | 5eb9f58 | 2018-04-28 18:14:50 +0000 | [diff] [blame] | 207 | .lower(); | 
|  | 208 |  | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 209 | getActionDefinitionsBuilder(G_LOAD) | 
| Matt Arsenault | 530d05e | 2019-02-14 22:41:09 +0000 | [diff] [blame] | 210 | .legalForTypesWithMemDesc({{s8, p0, 8, 8}, | 
|  | 211 | {s16, p0, 16, 8}, | 
|  | 212 | {s32, p0, 32, 8}, | 
|  | 213 | {s64, p0, 64, 8}, | 
|  | 214 | {p0, p0, 64, 8}, | 
|  | 215 | {v2s32, p0, 64, 8}}) | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 216 | // These extends are also legal | 
| Matt Arsenault | 530d05e | 2019-02-14 22:41:09 +0000 | [diff] [blame] | 217 | .legalForTypesWithMemDesc({{s32, p0, 8, 8}, | 
|  | 218 | {s32, p0, 16, 8}}) | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 219 | .clampScalar(0, s8, s64) | 
|  | 220 | .widenScalarToNextPow2(0) | 
| Daniel Sanders | 27fe8a5 | 2018-04-27 19:48:53 +0000 | [diff] [blame] | 221 | // TODO: We could support sum-of-pow2's but the lowering code doesn't know | 
|  | 222 | //       how to do that yet. | 
|  | 223 | .unsupportedIfMemSizeNotPow2() | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 224 | // Lower any any-extending loads left into G_ANYEXT and G_LOAD | 
|  | 225 | .lowerIf([=](const LegalityQuery &Query) { | 
| Volkan Keles | f87473f | 2018-10-25 17:37:07 +0000 | [diff] [blame] | 226 | return Query.Types[0].getSizeInBits() != Query.MMODescrs[0].SizeInBits; | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 227 | }) | 
| Matt Arsenault | 86504fb | 2019-02-05 16:57:18 +0000 | [diff] [blame] | 228 | .clampMaxNumElements(0, s32, 2) | 
| Volkan Keles | 0a8dc9e | 2018-11-01 19:01:53 +0000 | [diff] [blame] | 229 | .clampMaxNumElements(0, s64, 1); | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 230 |  | 
|  | 231 | getActionDefinitionsBuilder(G_STORE) | 
| Matt Arsenault | 530d05e | 2019-02-14 22:41:09 +0000 | [diff] [blame] | 232 | .legalForTypesWithMemDesc({{s8, p0, 8, 8}, | 
|  | 233 | {s16, p0, 16, 8}, | 
|  | 234 | {s32, p0, 32, 8}, | 
|  | 235 | {s64, p0, 64, 8}, | 
|  | 236 | {p0, p0, 64, 8}, | 
|  | 237 | {v2s32, p0, 64, 8}}) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 238 | .clampScalar(0, s8, s64) | 
|  | 239 | .widenScalarToNextPow2(0) | 
| Daniel Sanders | f84bc37 | 2018-05-05 20:53:24 +0000 | [diff] [blame] | 240 | // TODO: We could support sum-of-pow2's but the lowering code doesn't know | 
|  | 241 | //       how to do that yet. | 
|  | 242 | .unsupportedIfMemSizeNotPow2() | 
| Daniel Sanders | 5eb9f58 | 2018-04-28 18:14:50 +0000 | [diff] [blame] | 243 | .lowerIf([=](const LegalityQuery &Query) { | 
| Daniel Sanders | 2de9d4a | 2018-04-30 17:20:01 +0000 | [diff] [blame] | 244 | return Query.Types[0].isScalar() && | 
| Volkan Keles | f87473f | 2018-10-25 17:37:07 +0000 | [diff] [blame] | 245 | Query.Types[0].getSizeInBits() != Query.MMODescrs[0].SizeInBits; | 
| Daniel Sanders | 5eb9f58 | 2018-04-28 18:14:50 +0000 | [diff] [blame] | 246 | }) | 
| Matt Arsenault | 86504fb | 2019-02-05 16:57:18 +0000 | [diff] [blame] | 247 | .clampMaxNumElements(0, s32, 2) | 
| Volkan Keles | 0a8dc9e | 2018-11-01 19:01:53 +0000 | [diff] [blame] | 248 | .clampMaxNumElements(0, s64, 1); | 
| Tim Northover | 3c73e36 | 2016-08-23 18:20:09 +0000 | [diff] [blame] | 249 |  | 
| Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 250 | // Constants | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 251 | getActionDefinitionsBuilder(G_CONSTANT) | 
|  | 252 | .legalFor({p0, s32, s64}) | 
|  | 253 | .clampScalar(0, s32, s64) | 
|  | 254 | .widenScalarToNextPow2(0); | 
|  | 255 | getActionDefinitionsBuilder(G_FCONSTANT) | 
|  | 256 | .legalFor({s32, s64}) | 
|  | 257 | .clampScalar(0, s32, s64); | 
| Tim Northover | ea904f9 | 2016-08-19 22:40:00 +0000 | [diff] [blame] | 258 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 259 | getActionDefinitionsBuilder(G_ICMP) | 
|  | 260 | .legalFor({{s32, s32}, {s32, s64}, {s32, p0}}) | 
|  | 261 | .clampScalar(0, s32, s32) | 
|  | 262 | .clampScalar(1, s32, s64) | 
|  | 263 | .widenScalarToNextPow2(1); | 
| Tim Northover | 7a1ec01 | 2016-08-25 17:37:35 +0000 | [diff] [blame] | 264 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 265 | getActionDefinitionsBuilder(G_FCMP) | 
|  | 266 | .legalFor({{s32, s32}, {s32, s64}}) | 
|  | 267 | .clampScalar(0, s32, s32) | 
|  | 268 | .clampScalar(1, s32, s64) | 
|  | 269 | .widenScalarToNextPow2(1); | 
| Tim Northover | 30bd36e | 2016-08-26 17:46:19 +0000 | [diff] [blame] | 270 |  | 
| Tim Northover | 2c4a838 | 2016-08-25 17:37:25 +0000 | [diff] [blame] | 271 | // Extensions | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 272 | getActionDefinitionsBuilder({G_ZEXT, G_SEXT, G_ANYEXT}) | 
| Roman Tereshin | 5a65eb7 | 2018-05-31 01:56:05 +0000 | [diff] [blame] | 273 | .legalForCartesianProduct({s8, s16, s32, s64}, {s1, s8, s16, s32}); | 
| Tim Northover | 2c4a838 | 2016-08-25 17:37:25 +0000 | [diff] [blame] | 274 |  | 
| Ahmed Bougacha | 106dd03 | 2017-09-12 21:04:11 +0000 | [diff] [blame] | 275 | // FP conversions | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 276 | getActionDefinitionsBuilder(G_FPTRUNC).legalFor( | 
| Jessica Paquette | e57fe23 | 2019-02-11 18:56:39 +0000 | [diff] [blame] | 277 | {{s16, s32}, {s16, s64}, {s32, s64}, {v4s16, v4s32}, {v2s32, v2s64}}); | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 278 | getActionDefinitionsBuilder(G_FPEXT).legalFor( | 
| Jessica Paquette | e57fe23 | 2019-02-11 18:56:39 +0000 | [diff] [blame] | 279 | {{s32, s16}, {s64, s16}, {s64, s32}, {v4s32, v4s16}, {v2s64, v2s32}}); | 
| Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 280 |  | 
| Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 281 | // Conversions | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 282 | getActionDefinitionsBuilder({G_FPTOSI, G_FPTOUI}) | 
| Amara Emerson | 92ffb30 | 2019-01-28 02:27:59 +0000 | [diff] [blame] | 283 | .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32}) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 284 | .clampScalar(0, s32, s64) | 
|  | 285 | .widenScalarToNextPow2(0) | 
|  | 286 | .clampScalar(1, s32, s64) | 
|  | 287 | .widenScalarToNextPow2(1); | 
| Tim Northover | 5d0eaa4 | 2016-08-26 17:45:58 +0000 | [diff] [blame] | 288 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 289 | getActionDefinitionsBuilder({G_SITOFP, G_UITOFP}) | 
| Amara Emerson | 92ffb30 | 2019-01-28 02:27:59 +0000 | [diff] [blame] | 290 | .legalForCartesianProduct({s32, s64, v2s64, v4s32, v2s32}) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 291 | .clampScalar(1, s32, s64) | 
|  | 292 | .widenScalarToNextPow2(1) | 
|  | 293 | .clampScalar(0, s32, s64) | 
|  | 294 | .widenScalarToNextPow2(0); | 
| Tim Northover | 438c77c | 2016-08-25 17:37:32 +0000 | [diff] [blame] | 295 |  | 
| Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 296 | // Control-flow | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 297 | getActionDefinitionsBuilder(G_BRCOND).legalFor({s1, s8, s16, s32}); | 
|  | 298 | getActionDefinitionsBuilder(G_BRINDIRECT).legalFor({p0}); | 
| Ahmed Bougacha | ad30db3 | 2016-08-02 15:10:28 +0000 | [diff] [blame] | 299 |  | 
| Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 300 | // Select | 
| Jessica Paquette | 0632e12 | 2019-03-04 21:12:46 +0000 | [diff] [blame^] | 301 | // FIXME: We can probably do a bit better than just scalarizing vector | 
|  | 302 | // selects. | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 303 | getActionDefinitionsBuilder(G_SELECT) | 
|  | 304 | .legalFor({{s32, s1}, {s64, s1}, {p0, s1}}) | 
|  | 305 | .clampScalar(0, s32, s64) | 
| Jessica Paquette | 0632e12 | 2019-03-04 21:12:46 +0000 | [diff] [blame^] | 306 | .widenScalarToNextPow2(0) | 
|  | 307 | .scalarize(0); | 
| Tim Northover | 1d18a99 | 2016-08-26 17:46:03 +0000 | [diff] [blame] | 308 |  | 
| Tim Northover | b3a0be4 | 2016-08-23 21:01:20 +0000 | [diff] [blame] | 309 | // Pointer-handling | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 310 | getActionDefinitionsBuilder(G_FRAME_INDEX).legalFor({p0}); | 
|  | 311 | getActionDefinitionsBuilder(G_GLOBAL_VALUE).legalFor({p0}); | 
| Ahmed Bougacha | 0306b5e | 2016-08-16 14:02:42 +0000 | [diff] [blame] | 312 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 313 | getActionDefinitionsBuilder(G_PTRTOINT) | 
|  | 314 | .legalForCartesianProduct({s1, s8, s16, s32, s64}, {p0}) | 
|  | 315 | .maxScalar(0, s64) | 
|  | 316 | .widenScalarToNextPow2(0, /*Min*/ 8); | 
| Tim Northover | 037af52c | 2016-10-31 18:31:09 +0000 | [diff] [blame] | 317 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 318 | getActionDefinitionsBuilder(G_INTTOPTR) | 
|  | 319 | .unsupportedIf([&](const LegalityQuery &Query) { | 
|  | 320 | return Query.Types[0].getSizeInBits() != Query.Types[1].getSizeInBits(); | 
|  | 321 | }) | 
| Roman Tereshin | 5a65eb7 | 2018-05-31 01:56:05 +0000 | [diff] [blame] | 322 | .legalFor({{p0, s64}}); | 
| Tim Northover | 456a3c0 | 2016-08-23 19:30:38 +0000 | [diff] [blame] | 323 |  | 
| Quentin Colombet | 404e435 | 2016-10-12 03:57:43 +0000 | [diff] [blame] | 324 | // Casts for 32 and 64-bit width type are just copies. | 
| Quentin Colombet | 7c114d3 | 2017-10-16 22:28:27 +0000 | [diff] [blame] | 325 | // Same for 128-bit width type, except they are on the FPR bank. | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 326 | getActionDefinitionsBuilder(G_BITCAST) | 
|  | 327 | // FIXME: This is wrong since G_BITCAST is not allowed to change the | 
|  | 328 | // number of bits but it's what the previous code described and fixing | 
|  | 329 | // it breaks tests. | 
|  | 330 | .legalForCartesianProduct({s1, s8, s16, s32, s64, s128, v16s8, v8s8, v4s8, | 
|  | 331 | v8s16, v4s16, v2s16, v4s32, v2s32, v2s64}); | 
| Tim Northover | c1d8c2b | 2016-10-11 22:29:23 +0000 | [diff] [blame] | 332 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 333 | getActionDefinitionsBuilder(G_VASTART).legalFor({p0}); | 
| Tim Northover | e9600d8 | 2017-02-08 17:57:27 +0000 | [diff] [blame] | 334 |  | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 335 | // va_list must be a pointer, but most sized types are pretty easy to handle | 
|  | 336 | // as the destination. | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 337 | getActionDefinitionsBuilder(G_VAARG) | 
|  | 338 | .customForCartesianProduct({s8, s16, s32, s64, p0}, {p0}) | 
|  | 339 | .clampScalar(0, s8, s64) | 
|  | 340 | .widenScalarToNextPow2(0, /*Min*/ 8); | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 341 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 342 | if (ST.hasLSE()) { | 
| Daniel Sanders | 5281b02 | 2018-04-09 21:10:09 +0000 | [diff] [blame] | 343 | getActionDefinitionsBuilder(G_ATOMIC_CMPXCHG_WITH_SUCCESS) | 
| Daniel Sanders | bdeb880 | 2018-06-27 19:03:21 +0000 | [diff] [blame] | 344 | .lowerIf(all( | 
|  | 345 | typeInSet(0, {s8, s16, s32, s64}), typeIs(1, s1), typeIs(2, p0), | 
|  | 346 | atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Monotonic))); | 
| Daniel Sanders | 7fe7acc | 2017-11-28 20:21:15 +0000 | [diff] [blame] | 347 |  | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 348 | getActionDefinitionsBuilder( | 
|  | 349 | {G_ATOMICRMW_XCHG, G_ATOMICRMW_ADD, G_ATOMICRMW_SUB, G_ATOMICRMW_AND, | 
|  | 350 | G_ATOMICRMW_OR, G_ATOMICRMW_XOR, G_ATOMICRMW_MIN, G_ATOMICRMW_MAX, | 
| Roman Tereshin | 5a65eb7 | 2018-05-31 01:56:05 +0000 | [diff] [blame] | 351 | G_ATOMICRMW_UMIN, G_ATOMICRMW_UMAX, G_ATOMIC_CMPXCHG}) | 
| Daniel Sanders | bdeb880 | 2018-06-27 19:03:21 +0000 | [diff] [blame] | 352 | .legalIf(all( | 
|  | 353 | typeInSet(0, {s8, s16, s32, s64}), typeIs(1, p0), | 
|  | 354 | atomicOrderingAtLeastOrStrongerThan(0, AtomicOrdering::Monotonic))); | 
| Daniel Sanders | 7fe7acc | 2017-11-28 20:21:15 +0000 | [diff] [blame] | 355 | } | 
|  | 356 |  | 
| Amara Emerson | 0e86c07 | 2018-07-31 00:08:56 +0000 | [diff] [blame] | 357 | getActionDefinitionsBuilder(G_BLOCK_ADDR).legalFor({p0}); | 
|  | 358 |  | 
| Volkan Keles | a32ff00 | 2017-12-01 08:19:10 +0000 | [diff] [blame] | 359 | // Merge/Unmerge | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 360 | for (unsigned Op : {G_MERGE_VALUES, G_UNMERGE_VALUES}) { | 
|  | 361 | unsigned BigTyIdx = Op == G_MERGE_VALUES ? 0 : 1; | 
|  | 362 | unsigned LitTyIdx = Op == G_MERGE_VALUES ? 1 : 0; | 
|  | 363 |  | 
|  | 364 | auto notValidElt = [](const LegalityQuery &Query, unsigned TypeIdx) { | 
|  | 365 | const LLT &Ty = Query.Types[TypeIdx]; | 
|  | 366 | if (Ty.isVector()) { | 
|  | 367 | const LLT &EltTy = Ty.getElementType(); | 
|  | 368 | if (EltTy.getSizeInBits() < 8 || EltTy.getSizeInBits() > 64) | 
|  | 369 | return true; | 
|  | 370 | if (!isPowerOf2_32(EltTy.getSizeInBits())) | 
|  | 371 | return true; | 
| Volkan Keles | a32ff00 | 2017-12-01 08:19:10 +0000 | [diff] [blame] | 372 | } | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 373 | return false; | 
|  | 374 | }; | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 375 |  | 
|  | 376 | // FIXME: This rule is horrible, but specifies the same as what we had | 
|  | 377 | // before with the particularly strange definitions removed (e.g. | 
|  | 378 | // s8 = G_MERGE_VALUES s32, s32). | 
|  | 379 | // Part of the complexity comes from these ops being extremely flexible. For | 
|  | 380 | // example, you can build/decompose vectors with it, concatenate vectors, | 
|  | 381 | // etc. and in addition to this you can also bitcast with it at the same | 
|  | 382 | // time. We've been considering breaking it up into multiple ops to make it | 
|  | 383 | // more manageable throughout the backend. | 
|  | 384 | getActionDefinitionsBuilder(Op) | 
|  | 385 | // Break up vectors with weird elements into scalars | 
|  | 386 | .fewerElementsIf( | 
|  | 387 | [=](const LegalityQuery &Query) { return notValidElt(Query, 0); }, | 
| Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 388 | scalarize(0)) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 389 | .fewerElementsIf( | 
|  | 390 | [=](const LegalityQuery &Query) { return notValidElt(Query, 1); }, | 
| Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 391 | scalarize(1)) | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 392 | // Clamp the big scalar to s8-s512 and make it either a power of 2, 192, | 
|  | 393 | // or 384. | 
|  | 394 | .clampScalar(BigTyIdx, s8, s512) | 
|  | 395 | .widenScalarIf( | 
|  | 396 | [=](const LegalityQuery &Query) { | 
|  | 397 | const LLT &Ty = Query.Types[BigTyIdx]; | 
|  | 398 | return !isPowerOf2_32(Ty.getSizeInBits()) && | 
|  | 399 | Ty.getSizeInBits() % 64 != 0; | 
|  | 400 | }, | 
|  | 401 | [=](const LegalityQuery &Query) { | 
|  | 402 | // Pick the next power of 2, or a multiple of 64 over 128. | 
|  | 403 | // Whichever is smaller. | 
|  | 404 | const LLT &Ty = Query.Types[BigTyIdx]; | 
|  | 405 | unsigned NewSizeInBits = 1 | 
|  | 406 | << Log2_32_Ceil(Ty.getSizeInBits() + 1); | 
|  | 407 | if (NewSizeInBits >= 256) { | 
|  | 408 | unsigned RoundedTo = alignTo<64>(Ty.getSizeInBits() + 1); | 
|  | 409 | if (RoundedTo < NewSizeInBits) | 
|  | 410 | NewSizeInBits = RoundedTo; | 
|  | 411 | } | 
|  | 412 | return std::make_pair(BigTyIdx, LLT::scalar(NewSizeInBits)); | 
|  | 413 | }) | 
|  | 414 | // Clamp the little scalar to s8-s256 and make it a power of 2. It's not | 
|  | 415 | // worth considering the multiples of 64 since 2*192 and 2*384 are not | 
|  | 416 | // valid. | 
|  | 417 | .clampScalar(LitTyIdx, s8, s256) | 
|  | 418 | .widenScalarToNextPow2(LitTyIdx, /*Min*/ 8) | 
|  | 419 | // So at this point, we have s8, s16, s32, s64, s128, s192, s256, s384, | 
|  | 420 | // s512, <X x s8>, <X x s16>, <X x s32>, or <X x s64>. | 
|  | 421 | // At this point it's simple enough to accept the legal types. | 
|  | 422 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 423 | const LLT &BigTy = Query.Types[BigTyIdx]; | 
|  | 424 | const LLT &LitTy = Query.Types[LitTyIdx]; | 
|  | 425 | if (BigTy.isVector() && BigTy.getSizeInBits() < 32) | 
|  | 426 | return false; | 
|  | 427 | if (LitTy.isVector() && LitTy.getSizeInBits() < 32) | 
|  | 428 | return false; | 
|  | 429 | return BigTy.getSizeInBits() % LitTy.getSizeInBits() == 0; | 
|  | 430 | }) | 
|  | 431 | // Any vectors left are the wrong size. Scalarize them. | 
| Matt Arsenault | 990f507 | 2019-01-25 00:51:00 +0000 | [diff] [blame] | 432 | .scalarize(0) | 
|  | 433 | .scalarize(1); | 
| Daniel Sanders | 79cb839 | 2018-01-29 19:54:49 +0000 | [diff] [blame] | 434 | } | 
| Volkan Keles | a32ff00 | 2017-12-01 08:19:10 +0000 | [diff] [blame] | 435 |  | 
| Amara Emerson | cbd86d8 | 2018-10-25 14:04:54 +0000 | [diff] [blame] | 436 | getActionDefinitionsBuilder(G_EXTRACT_VECTOR_ELT) | 
|  | 437 | .unsupportedIf([=](const LegalityQuery &Query) { | 
|  | 438 | const LLT &EltTy = Query.Types[1].getElementType(); | 
|  | 439 | return Query.Types[0] != EltTy; | 
|  | 440 | }) | 
|  | 441 | .minScalar(2, s64) | 
|  | 442 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 443 | const LLT &VecTy = Query.Types[1]; | 
|  | 444 | return VecTy == v4s32 || VecTy == v2s64; | 
|  | 445 | }); | 
|  | 446 |  | 
| Amara Emerson | 5ec1460 | 2018-12-10 18:44:58 +0000 | [diff] [blame] | 447 | getActionDefinitionsBuilder(G_BUILD_VECTOR) | 
| Jessica Paquette | 7db82d7 | 2019-01-28 18:34:18 +0000 | [diff] [blame] | 448 | .legalFor({{v4s16, s16}, | 
|  | 449 | {v8s16, s16}, | 
|  | 450 | {v2s32, s32}, | 
|  | 451 | {v4s32, s32}, | 
|  | 452 | {v2s64, s64}}) | 
| Amara Emerson | 5ec1460 | 2018-12-10 18:44:58 +0000 | [diff] [blame] | 453 | .clampNumElements(0, v4s32, v4s32) | 
|  | 454 | .clampNumElements(0, v2s64, v2s64) | 
|  | 455 |  | 
|  | 456 | // Deal with larger scalar types, which will be implicitly truncated. | 
|  | 457 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 458 | return Query.Types[0].getScalarSizeInBits() < | 
|  | 459 | Query.Types[1].getSizeInBits(); | 
|  | 460 | }) | 
|  | 461 | .minScalarSameAs(1, 0); | 
|  | 462 |  | 
| Jessica Paquette | b53e0f4 | 2019-02-18 23:33:24 +0000 | [diff] [blame] | 463 | getActionDefinitionsBuilder(G_CTLZ).legalForCartesianProduct( | 
|  | 464 | {s32, s64, v8s8, v16s8, v4s16, v8s16, v2s32, v4s32}) | 
|  | 465 | .scalarize(1); | 
|  | 466 |  | 
| Amara Emerson | 1abe05c | 2019-02-21 20:20:16 +0000 | [diff] [blame] | 467 | getActionDefinitionsBuilder(G_SHUFFLE_VECTOR) | 
|  | 468 | .legalIf([=](const LegalityQuery &Query) { | 
|  | 469 | const LLT &DstTy = Query.Types[0]; | 
|  | 470 | const LLT &SrcTy = Query.Types[1]; | 
|  | 471 | // For now just support the TBL2 variant which needs the source vectors | 
|  | 472 | // to be the same size as the dest. | 
|  | 473 | if (DstTy != SrcTy) | 
|  | 474 | return false; | 
|  | 475 | for (auto &Ty : {v2s32, v4s32, v2s64}) { | 
|  | 476 | if (DstTy == Ty) | 
|  | 477 | return true; | 
|  | 478 | } | 
|  | 479 | return false; | 
|  | 480 | }) | 
|  | 481 | // G_SHUFFLE_VECTOR can have scalar sources (from 1 x s vectors), we | 
|  | 482 | // just want those lowered into G_BUILD_VECTOR | 
|  | 483 | .lowerIf([=](const LegalityQuery &Query) { | 
|  | 484 | return !Query.Types[1].isVector(); | 
|  | 485 | }) | 
|  | 486 | .clampNumElements(0, v4s32, v4s32) | 
|  | 487 | .clampNumElements(0, v2s64, v2s64); | 
|  | 488 |  | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 489 | computeTables(); | 
| Roman Tereshin | 8f1753e | 2018-05-30 22:10:04 +0000 | [diff] [blame] | 490 | verify(*ST.getInstrInfo()); | 
| Tim Northover | 33b07d6 | 2016-07-22 20:03:43 +0000 | [diff] [blame] | 491 | } | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 492 |  | 
|  | 493 | bool AArch64LegalizerInfo::legalizeCustom(MachineInstr &MI, | 
|  | 494 | MachineRegisterInfo &MRI, | 
| Aditya Nandakumar | f75d4f3 | 2018-12-05 20:14:52 +0000 | [diff] [blame] | 495 | MachineIRBuilder &MIRBuilder, | 
|  | 496 | GISelChangeObserver &Observer) const { | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 497 | switch (MI.getOpcode()) { | 
|  | 498 | default: | 
|  | 499 | // No idea what to do. | 
|  | 500 | return false; | 
|  | 501 | case TargetOpcode::G_VAARG: | 
|  | 502 | return legalizeVaArg(MI, MRI, MIRBuilder); | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | llvm_unreachable("expected switch to return"); | 
|  | 506 | } | 
|  | 507 |  | 
|  | 508 | bool AArch64LegalizerInfo::legalizeVaArg(MachineInstr &MI, | 
|  | 509 | MachineRegisterInfo &MRI, | 
|  | 510 | MachineIRBuilder &MIRBuilder) const { | 
|  | 511 | MIRBuilder.setInstr(MI); | 
|  | 512 | MachineFunction &MF = MIRBuilder.getMF(); | 
|  | 513 | unsigned Align = MI.getOperand(2).getImm(); | 
|  | 514 | unsigned Dst = MI.getOperand(0).getReg(); | 
|  | 515 | unsigned ListPtr = MI.getOperand(1).getReg(); | 
|  | 516 |  | 
|  | 517 | LLT PtrTy = MRI.getType(ListPtr); | 
|  | 518 | LLT IntPtrTy = LLT::scalar(PtrTy.getSizeInBits()); | 
|  | 519 |  | 
|  | 520 | const unsigned PtrSize = PtrTy.getSizeInBits() / 8; | 
|  | 521 | unsigned List = MRI.createGenericVirtualRegister(PtrTy); | 
|  | 522 | MIRBuilder.buildLoad( | 
|  | 523 | List, ListPtr, | 
|  | 524 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOLoad, | 
|  | 525 | PtrSize, /* Align = */ PtrSize)); | 
|  | 526 |  | 
|  | 527 | unsigned DstPtr; | 
|  | 528 | if (Align > PtrSize) { | 
|  | 529 | // Realign the list to the actual required alignment. | 
| Aditya Nandakumar | 1745121 | 2017-07-06 19:40:07 +0000 | [diff] [blame] | 530 | auto AlignMinus1 = MIRBuilder.buildConstant(IntPtrTy, Align - 1); | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 531 |  | 
|  | 532 | unsigned ListTmp = MRI.createGenericVirtualRegister(PtrTy); | 
| Aditya Nandakumar | fef7619 | 2019-02-05 22:14:40 +0000 | [diff] [blame] | 533 | MIRBuilder.buildGEP(ListTmp, List, AlignMinus1.getReg(0)); | 
| Tim Northover | 9136617 | 2017-02-15 23:22:50 +0000 | [diff] [blame] | 534 |  | 
|  | 535 | DstPtr = MRI.createGenericVirtualRegister(PtrTy); | 
|  | 536 | MIRBuilder.buildPtrMask(DstPtr, ListTmp, Log2_64(Align)); | 
|  | 537 | } else | 
|  | 538 | DstPtr = List; | 
|  | 539 |  | 
|  | 540 | uint64_t ValSize = MRI.getType(Dst).getSizeInBits() / 8; | 
|  | 541 | MIRBuilder.buildLoad( | 
|  | 542 | Dst, DstPtr, | 
|  | 543 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOLoad, | 
|  | 544 | ValSize, std::max(Align, PtrSize))); | 
|  | 545 |  | 
|  | 546 | unsigned SizeReg = MRI.createGenericVirtualRegister(IntPtrTy); | 
|  | 547 | MIRBuilder.buildConstant(SizeReg, alignTo(ValSize, PtrSize)); | 
|  | 548 |  | 
|  | 549 | unsigned NewList = MRI.createGenericVirtualRegister(PtrTy); | 
|  | 550 | MIRBuilder.buildGEP(NewList, DstPtr, SizeReg); | 
|  | 551 |  | 
|  | 552 | MIRBuilder.buildStore( | 
|  | 553 | NewList, ListPtr, | 
|  | 554 | *MF.getMachineMemOperand(MachinePointerInfo(), MachineMemOperand::MOStore, | 
|  | 555 | PtrSize, /* Align = */ PtrSize)); | 
|  | 556 |  | 
|  | 557 | MI.eraseFromParent(); | 
|  | 558 | return true; | 
|  | 559 | } |