[llvm] [LV] Explicitly disable in-loop reductions for AnyOf and FindIV. nfc (PR #163541)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 18 02:23:49 PST 2025


================
@@ -1248,6 +1243,13 @@ unsigned RecurrenceDescriptor::getOpcode(RecurKind Kind) {
   case RecurKind::FMaximumNum:
   case RecurKind::FMinimumNum:
     return Instruction::FCmp;
+  case RecurKind::AnyOf:
+  case RecurKind::FindFirstIVSMin:
+  case RecurKind::FindFirstIVUMin:
+  case RecurKind::FindLastIVSMax:
+  case RecurKind::FindLastIVUMax:
+    // TODO: Set AnyOf and FindIV to Instruction::Select once in-loop reductions
+    // are supported.
----------------
Mel-Chen wrote:

For the llvm_unreachable message: https://github.com/llvm/llvm-project/pull/168509

`getOpcode()` is also used in SLP, and the way SLP relies on it is a bit different. Renaming it to `getInLoopOpcode()` might require a discussion with @alexey-bataev .

But I have another idea: maybe we should introduce 
`bool isLegalOpcodeInChain(RecurKind Kind, unsigned Opcode)`

For example, a recurrence chain of `RecurKind::AddChainWithSubs` may contain both Add and Sub. With the current `getOpcode()`, this is not expressible—we need additional logic such as:
```
if (Cur->getOpcode() == Instruction::Sub &&
    Kind == RecurKind::AddChainWithSubs)
  return true;
```
Using `isLegalOpcodeInChain(Kind, Opcode)` would allow a chain to contain multiple valid opcodes.

BTW, this also gives us a chance to fold `RecurKind::AddChainWithSubs` into just `RecurKind::Add`.

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


More information about the llvm-commits mailing list