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

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 5 01:51:38 PDT 2025


================
@@ -1288,6 +1312,11 @@ RecurrenceDescriptor::getReductionOpChain(PHINode *Phi, Loop *L) const {
     if (isFMulAddIntrinsic(Cur))
       return true;
 
+    if (Cur->getOpcode() == Instruction::Sub && getOpcode() == Instruction::Add)
+      return true;
+    if (Cur->getOpcode() == Instruction::Add && getOpcode() == Instruction::Sub)
+      return true;
----------------
sdesmalen-arm wrote:

My understanding is that a sub-reduction can only have Sub instructions (otherwise it would have been an add-reduction, as per https://github.com/llvm/llvm-project/pull/147026/files#diff-465c225de5a29137ae4ba3526ceabe499fdd5869ad43687c055c8e85f61d2ef9R908), so this statement can be removed.

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


More information about the llvm-commits mailing list