diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -9747,9 +9747,9 @@ void VPReductionRecipe::execute(VPTransformState &State) { assert(!State.Instance && "Reduction being replicated."); Value *PrevInChain = State.get(getChainOp(), 0); + RecurKind Kind = RdxDesc->getRecurrenceKind(); + bool IsOrdered = State.ILV->useOrderedReductions(*RdxDesc); for (unsigned Part = 0; Part < State.UF; ++Part) { - RecurKind Kind = RdxDesc->getRecurrenceKind(); - bool IsOrdered = State.ILV->useOrderedReductions(*RdxDesc); Value *NewVecOp = State.get(getVecOp(), Part); if (VPValue *Cond = getCondOp()) { Value *NewCond = State.get(Cond, Part); @@ -9769,8 +9769,8 @@ PrevInChain); else NewRed = State.Builder.CreateBinOp( - (Instruction::BinaryOps)getUnderlyingInstr()->getOpcode(), - PrevInChain, NewVecOp); + (Instruction::BinaryOps)RdxDesc->getOpcode(Kind), PrevInChain, + NewVecOp); PrevInChain = NewRed; } else { PrevInChain = State.get(getChainOp(), Part); @@ -9782,11 +9782,10 @@ NewRed, PrevInChain); } else if (IsOrdered) NextInChain = NewRed; - else { + else NextInChain = State.Builder.CreateBinOp( - (Instruction::BinaryOps)getUnderlyingInstr()->getOpcode(), NewRed, + (Instruction::BinaryOps)RdxDesc->getOpcode(Kind), NewRed, PrevInChain); - } State.set(this, NextInChain, Part); } }