[llvm] [IVDescriptors][NFC] Refactor getReductionOpChain to remove the dependency of non-arithmetic reductions on getOpcode. (PR #118777)

Mel Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 3 00:33:06 PST 2025


================
@@ -1081,15 +1086,15 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
   // more expensive than out-of-loop reductions, and need to be costed more
   // carefully.
   unsigned ExpectedUses = 1;
-  if (RedOp == Instruction::ICmp || RedOp == Instruction::FCmp)
+  if (IsNonArithmetic)
----------------
Mel-Chen wrote:

> I'm not sure this patch is really NFC because in theory `IsNonArithmetic` could be true when Kind is RecurKind::None. 

This is a great reminder, but I don't think `Kind` would normally be `None` in the function `getReductionOpChain`. I believe using an assertion here would be more appropriate.
8dd7cde1b09f75e8183dae738e8f86828da18072

> Also, even if you remove references to `getOpcode` for AnyOf recurrence kinds in this function there are still lots of places in LoopVectorize.cpp that call RecurrenceDescriptor::getOpcode(). 

Yes, also in SLP that need to be refined. #121549
This is just the first step in the cleanup.

> It's not obvious to me right now that you can avoid calling `getOpcode` for AnyOf types. Also, if you have to specialise the code everywhere to avoid calling `getOpcode` for AnyOf kinds wouldn't that make the code even more complicated?

The main purpose of avoiding to call `getOpcode` is to unify `AnyOf`.
This won't make things more complicated; the design and usage will be similar to `llvm::getRecurrenceIdentity`.
On the contrary, passing the type into `getOpcode` would make it more complex #118393 : when an `AnyOf` recurrence needs to call `getOpcode`, I would first have to determine whether it is a `select(icmp ixx)` or `select(fcmp float/double...)` before calling `getOpcode`.




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


More information about the llvm-commits mailing list