<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116697>116697</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[NVPTX] Lower `dynamic_stackallloc` in Instruction Selection instead of Operation Legalization
</td>
</tr>
<tr>
<th>Labels</th>
<td>
good first issue,
backend:NVPTX
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
justinfargnoli
</td>
</tr>
</table>
<pre>
Currently, we [lower `dynamic_stackalloc` during operation legalization](https://github.com/llvm/llvm-project/blob/e0b522dd94e48229d587a54a3103ba1c198b16a7/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp#L2275-L2304). However, if we are okay with losing the friendlier error message we could decare this operation as legal and handle is during [instruction selection](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td).
This would require declaring [`ISD::DYNAMIC_STACKALLOC`](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/CodeGen/ISDOpcodes.h#L1105-L1112) in [`TargetSelectionDAG.td`](https://github.com/llvm/llvm-project/blob/main/llvm/include/llvm/Target/TargetSelectionDAG.td) and lowering it in [NVPTXInstrInfo.td](https://github.com/llvm/llvm-project/blob/main/llvm/lib/Target/NVPTX/NVPTXInstrInfo.td)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVMFu4zYQ_RrqQsQgh5ZkHXRwLHhrVN0UcFC0pwUljiRuaNIlqRjp1xdU7CRAW6BFW-xFhIgZzntvZp4MQY8WsSb5PcmbTM5xcr7-Ooeo7SD9aJ3RWefUS72bvUcbzQuBHb0gJfm9cRf0lBRMvVh50v2XEGX_JI1xPSkYVbPXdqTujF5G7Sw1OEqjf1t-SN4Q2EwxngMRWwJ7AvtRx2nuVr07Edgb83w77s7efcU-Eth3xnUE9si6HECpao3rDUCl8k0p87UUnIlO8p5Xm44Xsvzwjk55j9KPmN75_NOPjz_fzsMRTZu4aDuu-vOZgGgByvyuBcHWBKoV_c5d8Bl94q6HRF96pO5JvtCLjhM1LiSqcUI6eI1WGY2eovfO0xOGIEdMSb2bjaIK-5QdJx0-iCPDqz5UWkUnaZVBqsNNRJLfaxuin_slOKDB_t_LeJLa_k2JUvGDHdwqqiQIYQ1h29fvYyJyWah5_HXWHhNFI2_AScEOxybBE9vml8_bHw67L8fH7e77bds-7EjB_ksS2vZmVvh-sXMKP2GKOBybh3PvFIbVlFrMOcvvWs45EKiotlesrwIcbwo320-J8_-M8k31P68O1TIW5jqkVMcr3j8259sMRKZqoSpRyQxrXgpeFaXIeTbVnSgEy_NyrXjRsaqsEBBFsRFlB1WBMtM1MFhzzjcADARfVR1HADHkalgiyJrhSWqzSqhWzo-ZDmHGmvOiqMrMyA5NWAwMYHRO0UH7EOkSRAAI7AhAJ_sntIqI7ZUFJLvz9SJDN4-BrJnRIYb3KlFHsxjja0be0Pav_O5qeNrSw4clfWsiTauLUlE30Ie3hW8_uGE2e1P_46YtFAOB_VWK5xp-DwAA___EAOPb">