<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138259>138259</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[X86] X86LegalizerInfo - use LegalFor instead if LegalIf for simple ISA/test pairs
</td>
</tr>
<tr>
<th>Labels</th>
<td>
good first issue,
backend:X86,
llvm:globalisel
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RKSimon
</td>
</tr>
</table>
<pre>
We have lots of arg/result common type cases like:
```cpp
getActionDefinitionsBuilder({G_ADD, G_SUB})
.legalIf([=](const LegalityQuery &Query) -> bool {
if (typeInSet(0, {s8, s16, s32})(Query))
return true;
if (Is64Bit && typeInSet(0, {s64})(Query))
return true;
if (HasSSE2 && typeInSet(0, {v16s8, v8s16, v4s32, v2s64})(Query))
return true;
if (HasAVX2 && typeInSet(0, {v32s8, v16s16, v8s32, v4s64})(Query))
return true;
if (HasAVX512 && typeInSet(0, {v16s32, v8s64})(Query))
return true;
if (HasBWI && typeInSet(0, {v64s8, v32s16})(Query))
return true;
return false;
})
```
which should be simplified to use the legalFor({Types}) or legalFor(Pred, {Types}) helpers:
```cpp
getActionDefinitionsBuilder({G_ADD, G_SUB})
.legalFor({s8, s16, s32})
.legalFor(Is64Bit, {s64})
.legalFor(HasSSE2, {v16s8, v8s16, v4s32, v2s64})
--- etc ---
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0VU2P4zYM_TX0hcjApr8PPjjNZht0Dm3Tdue2UGzaVlexDElOkf76Qo4nHWCn069dwYAIk-Z7T9CjhbWyH5krSLeQ7gIxu0Gb6sfvjvKsx-Ck22v1gXEQF0alnUXdoTA90N6wnZXDRp_PekR3nRgbYdmikp8Y4hrCGrLw9jTTBGGNPbu6cVKPO-7kKH1kt7NULRugAvLt-4_1bgf0Db7_ePx5C_kOqPQfLutBcS_UofOl6RbiHaQ7oKLRo3X46HPSXX-Y2VwRKFsCoBI3EL_Dk9YKId_emyHKDoEKz_swHtkBFaFHhnxrCx_YKFu2mFYeVDz3fMnKL8NuNiM6MzPEn2McbJZspfOsgDJ8FTJL_i_Kt8Iej-_oLZRLlN20XYpV3SXx-nxAX4ZC_cvT2xRiWilE2TOH4plD8gaHfwSdRn-rf4Uqvozc7YfDm4BZsqqNyav9z4BrohPKPmfu7ri7DML6t0E2A9pBz6rFE6OV50nJTnKLTuNsGd3AuBhpr1fT_XSd2N66oTYvk98bblclL4sGVhMb-_U8fqf2F058rXo12Wd-eq12tcq_c0VY42azQXaN318qD9oqbsu4FAFXUZ5kUVGUZRIMVZOmIsxF050EJXmRJILSnPKyDClpRdoFsqKQ0jANKSIq0-RBRJRHcZ7mUSFiKnNIQj4LqR6UupwftOkDae3MVRQXlJaBEidWdpndRL3WLXbSWIdLEZDXAEQn0XzisYW4fiqy-1vfEeK6V_oklLSsfCbdBabymc1p7i0koZLW2T_RnXRq-Vf4TukOn4rsNnl_Z3MYO42b5ZI9rmeNcrSOResN83ib3thpc7uWjIdjDbR3bB1OQhobzEZVg3PTcrdoD7TvpRvm00Ojz0D7hfJt20xG_8qNA9ovYi3Qfj2US0V_BAAA__8G4uvb">