Skip to content

Commit 1916a1c

Browse files
fhahntstellar
authored andcommitted
[VPlan] Fix crash caused by not updating all users properly.
Users of VPValues are managed in a vector, so we need to be more careful when iterating over users while updating them. For now, just copy them. Fixes 51798. (cherry picked from commit 368af75)
1 parent 2aa67b3 commit 1916a1c

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,15 @@ bool VPlanTransforms::mergeReplicateRegions(VPlan &Plan) {
234234
for (VPRecipeBase &Phi1ToMove : make_early_inc_range(reverse(*Merge1))) {
235235
VPValue *PredInst1 =
236236
cast<VPPredInstPHIRecipe>(&Phi1ToMove)->getOperand(0);
237-
for (VPUser *U : Phi1ToMove.getVPSingleValue()->users()) {
237+
VPValue *Phi1ToMoveV = Phi1ToMove.getVPSingleValue();
238+
SmallVector<VPUser *> Users(Phi1ToMoveV->user_begin(),
239+
Phi1ToMoveV->user_end());
240+
for (VPUser *U : Users) {
238241
auto *UI = dyn_cast<VPRecipeBase>(U);
239242
if (!UI || UI->getParent() != Then2)
240243
continue;
241244
for (unsigned I = 0, E = U->getNumOperands(); I != E; ++I) {
242-
if (Phi1ToMove.getVPSingleValue() != U->getOperand(I))
245+
if (Phi1ToMoveV != U->getOperand(I))
243246
continue;
244247
U->setOperand(I, PredInst1);
245248
}

llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge.ll

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,3 +836,69 @@ loop:
836836
exit:
837837
ret void
838838
}
839+
840+
define void @update_multiple_users(i16* noalias %src, i8* noalias %dst, i1 %c) {
841+
; CHECK-LABEL: LV: Checking a loop in "update_multiple_users"
842+
; CHECK: VPlan 'Initial VPlan for VF={2},UF>=1' {
843+
; CHECK-NEXT: loop.header:
844+
; CHECK-NEXT: WIDEN-INDUCTION %iv = phi 0, %iv.next
845+
; CHECK-NEXT: Successor(s): loop.then
846+
; CHECK-EMPTY:
847+
; CHECK-NEXT: loop.then:
848+
; CHECK-NEXT: Successor(s): loop.then.0
849+
; CHECK-EMPTY:
850+
; CHECK-NEXT: loop.then.0:
851+
; CHECK-NEXT: Successor(s): pred.store
852+
; CHECK-EMPTY:
853+
; CHECK-NEXT: <xVFxUF> pred.store: {
854+
; CHECK-NEXT: pred.store.entry:
855+
; CHECK-NEXT: BRANCH-ON-MASK ir<%c>
856+
; CHECK-NEXT: Successor(s): pred.store.if, pred.store.continue
857+
; CHECK-NEXT: CondBit: ir<%c>
858+
; CHECK-EMPTY:
859+
; CHECK-NEXT: pred.store.if:
860+
; CHECK-NEXT: REPLICATE ir<%l1> = load ir<%src>
861+
; CHECK-NEXT: REPLICATE ir<%cmp> = icmp ir<%l1>, ir<0>
862+
; CHECK-NEXT: REPLICATE ir<%l2> = trunc ir<%l1>
863+
; CHECK-NEXT: REPLICATE ir<%sel> = select ir<%cmp>, ir<5>, ir<%l2>
864+
; CHECK-NEXT: REPLICATE store ir<%sel>, ir<%dst>
865+
; CHECK-NEXT: Successor(s): pred.store.continue
866+
; CHECK-EMPTY:
867+
; CHECK-NEXT: pred.store.continue:
868+
; CHECK-NEXT: PHI-PREDICATED-INSTRUCTION vp<%6> = ir<%l1>
869+
; CHECK-NEXT: No successors
870+
; CHECK-NEXT: }
871+
; CHECK-NEXT: Successor(s): loop.then.1
872+
; CHECK-EMPTY:
873+
; CHECK-NEXT: loop.then.1:
874+
; CHECK-NEXT: WIDEN ir<%sext.l1> = sext vp<%6>
875+
; CHECK-NEXT: Successor(s): loop.latch
876+
; CHECK-EMPTY:
877+
; CHECK-NEXT: loop.latch:
878+
; CHECK-NEXT: No successors
879+
; CHECK-NEXT: }
880+
;
881+
entry:
882+
br label %loop.header
883+
884+
loop.header:
885+
%iv = phi i64 [ 0, %entry ], [ %iv.next, %loop.latch ]
886+
br i1 %c, label %loop.then, label %loop.latch
887+
888+
loop.then:
889+
%l1 = load i16, i16* %src, align 2
890+
%l2 = trunc i16 %l1 to i8
891+
%cmp = icmp eq i16 %l1, 0
892+
%sel = select i1 %cmp, i8 5, i8 %l2
893+
store i8 %sel, i8* %dst, align 1
894+
%sext.l1 = sext i16 %l1 to i32
895+
br label %loop.latch
896+
897+
loop.latch:
898+
%iv.next = add nsw i64 %iv, 1
899+
%ec = icmp eq i64 %iv.next, 999
900+
br i1 %ec, label %exit, label %loop.header
901+
902+
exit:
903+
ret void
904+
}

0 commit comments

Comments
 (0)