[llvm] [LV] Create in-loop sub reductions (PR #147026)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 30 08:08:29 PDT 2025


================
@@ -897,8 +898,9 @@ RecurrenceDescriptor::InstDesc RecurrenceDescriptor::isRecurrenceInstr(
   case Instruction::PHI:
     return InstDesc(I, Prev.getRecKind(), Prev.getExactFPMathInst());
   case Instruction::Sub:
+    return InstDesc(Kind == RecurKind::Sub, I);
   case Instruction::Add:
-    return InstDesc(Kind == RecurKind::Add, I);
+    return InstDesc(Kind == RecurKind::Add || Kind == RecurKind::Sub, I);
----------------
SamTebbs33 wrote:

We still need this so that we can recognise loops with mixed sub and add reductions. Without this we can't vectorise test_struct_load4 in interleaved-accesses.ll, lots in partial-reduce-chained.ll, test_struct_load6 in sve-interleaved-accesses.ll and some in gcc-examples.ll. I'm happy to fix this as a follow-up if you're OK with that since we can make it work for all loops with mixed reductions, not just those with subs and adds.

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


More information about the llvm-commits mailing list