<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/153743>153743</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Support folding n-ary intrinsics in IRBuilderFolder/ConstantFolding
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            llvm:instcombine,
            constant-folding
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lukel97
      </td>
    </tr>
</table>

<pre>
    The motivation for this is https://github.com/llvm/llvm-project/pull/153069, where we would like to avoid regressions by being able to simplify unary and ternary intrinsics in IRBuilderFolder.

Currently we can only fold binary intrinsics. I presume we want to change the IRBuilderFolder interface from `FoldBinaryIntrinsic` -> `FoldIntrinsic`. I'm not sure what needs to change in ConstantFolder.cpp though. I see we have `ConstantFoldBinaryIntrinsic`, but we also seem to handle scalar intrinsics in `ConstantFoldCall`? 

Some relevant discussion in https://github.com/llvm/llvm-project/pull/150931#discussion_r2236338130
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycU82OmzAQfhpzGSUCGwIcOGSzRcq123tlzASma2zkn6zy9pXZXW2UHqr2ApbG8_3NWHpPk0HsWPXEqudMxjBb1-n4irqts8GOt-7HjLDYQFcZyBq4WAdhJg_kYQ5h9UwcGe8Z7ycKcxz2yi6M91pfP3-71dlfqALj_Rq1ZrwvKpEfWsZP8DajQ3hDeLNRj6DpFSFYkFdLIzicHHpP1ngYbjAgmQnkoLcrnpZV0-UG0Uh3A2lGCOi2M5ngyHhSHsjA-ftTJD2i62367ll-ZPnxFJ1DE_QtkStpwBp9g4vVIwz0gLKHM6wOfVzepUoTkgI1SzMhhBkfOVIvuotUCBdnF2CHPBWeNuDzJy475LBj4ttn-b6whzPj9QLGBvAxRTTLAAZx9HfUZOBkjQ_ShA9zal0hzDZOcxLtcRM8yysmkvu7f2pJ4xhiSA1Se5ual8Q1SzNqBK-klu4h2wfQk9Q6IYke3lN-sQuCQ43XlNlIXsVtnqn3_5cnb0XBuPiC--k4FwchmkLk2diJsRWtzLAr6qrigpdcZHOHed40OLSqVUVTt1ioRoq6xMNQYVUPPKOO57zKm6LKSyFKsRftIEsUFbaNLHmtWJnjIknvk7C9dVNG3kfsikrUpci0HFD77SlxvlkQRzI-KLsMZJBxzviJca4-EtulbSMzpUL1nLlu8zvEybMy1-SD_yIKFDR2L3FdrQvw0Qhm99d1Z7y_nxCZKYtOd_8c_ubUv7_dZPba8d8BAAD___EEb2Q">