[llvm] [InstCombine] Match intrinsic recurrences when known to be hoisted (PR #149858)

Antonio Frighetto via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 29 02:31:31 PDT 2025


antoniofrighetto wrote:

> Hm, I'm curious whether we would get this optimization "for free" if we called foldOpIntoPhi for intrinsics.

Tried by pivoting the fold in the intrinsics visitor as follows:
```cpp
PHINode *PN;
Value *Init, *OtherOp;
if (matchSimpleBinaryIntrinsicRecurrence(II, PN, Init, OtherOp) &&
    DT.dominates(OtherOp, PN))
  if (auto *Res = foldOpIntoPhi(*II, PN, true))
    return Res;
```
We fold correctly the one-use phi case, however for the multiuse we bail out in: https://github.com/llvm/llvm-project/blob/c9ceb9b75fd547c7d2e79837075370f4c8db8faa/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp#L1947-L1948

May as well take a deeper look as a follow-up patch, if you say.

https://github.com/llvm/llvm-project/pull/149858


More information about the llvm-commits mailing list