[llvm] [LoopVectorizer][AArch64] Add support for partial reduce subtraction (PR #123636)

Nicholas Guy via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 31 05:48:22 PST 2025


================
@@ -318,13 +332,20 @@ void VPPartialReductionRecipe::execute(VPTransformState &State) {
   State.setDebugLocFrom(getDebugLoc());
   auto &Builder = State.Builder;
 
-  assert(getOpcode() == Instruction::Add &&
-         "Unhandled partial reduction opcode");
-
   Value *BinOpVal = State.get(getOperand(0));
   Value *PhiVal = State.get(getOperand(1));
   assert(PhiVal && BinOpVal && "Phi and Mul must be set");
 
+  unsigned Opcode = getOpcode();
+
+  if (Opcode == Instruction::Sub) {
+    bool HasNSW = cast<Instruction>(BinOpVal)->hasNoSignedWrap();
+    BinOpVal = Builder.CreateNeg(BinOpVal, "", HasNSW);
+    Opcode = Instruction::Add;
+  }
----------------
NickGuy-Arm wrote:

They are always Widen recipes as far as I can tell, however the incoming IR doesn't always match the pattern `add(<a>, neg(<b>))`. In the case of complex dot products, the second sub is explicitly represented as a sub, we then transform that here to follow the aformentioned pattern.

Unless I'm missing something, there doesn't seem to be a method of creating multiple VPRecipes from a single source instruction, which would be required for this suggestion.

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


More information about the llvm-commits mailing list