Skip to content

Commit

Permalink
[VPlan] Properly update reduction live-out after placing select.
Browse files Browse the repository at this point in the history
After inserting a select for the final value, update the VPlan def-use
chains. At the moment, the incorrect live-out doesn't cause a
mis-compile, as computing the final reduction value is not yet modeled
in VPlan.
  • Loading branch information
fhahn committed Dec 2, 2023
1 parent db8b85a commit cbf7b52
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9271,6 +9271,9 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
? new VPInstruction(Instruction::Select, {Cond, Red, PhiR}, FMFs)
: new VPInstruction(Instruction::Select, {Cond, Red, PhiR});
Result->insertBefore(&*Builder.getInsertPoint());
Red->replaceUsesWithIf(
Result->getVPSingleValue(),
[](VPUser &U, unsigned) { return isa<VPLiveOut>(&U); });
if (PreferPredicatedReductionSelect ||
TTI.preferPredicatedReductionSelect(
PhiR->getRecurrenceDescriptor().getOpcode(), PhiTy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ define i32 @sink_replicate_region_3_reduction(i32 %x, i8 %y, ptr %ptr) optsize {
; CHECK-NEXT: middle.block:
; CHECK-NEXT: No successors
; CHECK-EMPTY:
; CHECK-NEXT: Live-out i32 %res = ir<%and.red.next>
; CHECK-NEXT: Live-out i32 %res = vp<[[SEL]]>
; CHECK-NEXT: }
;
entry:
Expand Down

0 comments on commit cbf7b52

Please sign in to comment.