Skip to content

Commit 8b8443a

Browse files
committed
[LoopVectorizer][AArch64] Add support for partial reduce subtraction
1 parent e33f456 commit 8b8443a

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ class AArch64TTIImpl : public BasicTTIImplBase<AArch64TTIImpl> {
368368
InstructionCost Invalid = InstructionCost::getInvalid();
369369
InstructionCost Cost(TTI::TCC_Basic);
370370

371-
if (Opcode != Instruction::Add)
371+
if (Opcode != Instruction::Add && Opcode != Instruction::Sub)
372372
return Invalid;
373373

374374
if (InputTypeA != InputTypeB)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,13 +317,20 @@ void VPPartialReductionRecipe::execute(VPTransformState &State) {
317317
State.setDebugLocFrom(getDebugLoc());
318318
auto &Builder = State.Builder;
319319

320-
assert(getOpcode() == Instruction::Add &&
321-
"Unhandled partial reduction opcode");
322-
323320
Value *BinOpVal = State.get(getOperand(0));
324321
Value *PhiVal = State.get(getOperand(1));
325322
assert(PhiVal && BinOpVal && "Phi and Mul must be set");
326323

324+
unsigned Opcode = getOpcode();
325+
326+
if (Opcode == Instruction::Sub) {
327+
bool HasNSW = cast<Instruction>(BinOpVal)->hasNoSignedWrap();
328+
BinOpVal = Builder.CreateNeg(BinOpVal, "", HasNSW);
329+
Opcode = Instruction::Add;
330+
}
331+
332+
assert(Opcode == Instruction::Add && "Unhandled partial reduction opcode");
333+
327334
Type *RetTy = PhiVal->getType();
328335

329336
CallInst *V = Builder.CreateIntrinsic(

0 commit comments

Comments
 (0)