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

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 30 04:01: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;
+  }
----------------
fhahn wrote:

The operands are always VPWidenRecipe's, correct?

Could we instead create adjust the input recipes to first negate the operand and  use Add instead of Sub for the partial reduction recipe?

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


More information about the llvm-commits mailing list