Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion llvm/lib/Analysis/IVDescriptors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ bool RecurrenceDescriptor::AddReductionVar(

// Obtain the reduction start value from the value that comes from the loop
// preheader.
Value *RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());
Value *RdxStart;
if (TheLoop->getLoopPreheader())
RdxStart = Phi->getIncomingValueForBlock(TheLoop->getLoopPreheader());

// ExitInstruction is the single value which is used outside the loop.
// We only allow for a single reduction value to be used outside the loop.
Expand Down Expand Up @@ -587,6 +589,9 @@ bool RecurrenceDescriptor::AddReductionVar(
collectCastInstrs(TheLoop, ExitInstruction, RecurrenceType, CastInsts,
MinWidthCastToRecurrenceType);

if (!RdxStart)
return false;

// We found a reduction var if we have reached the original phi node and we
// only have a single instruction with out-of-loop users.

Expand Down Expand Up @@ -1536,6 +1541,11 @@ bool InductionDescriptor::isInductionPHI(
return false;
}

if (!AR->getLoop()->getLoopPreheader()) {
LLVM_DEBUG(dbgs() << "LV: Loop doesn't have a legal pre-header.\n");
return false;
}

// This function assumes that InductionPhi is called only on Phi nodes
// present inside loop headers. Check for the same, and throw an assert if
// the current Phi is not present inside the loop header.
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/Transforms/LoopVectorize/loop-legality-checks-remarks.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
; RUN: opt < %s -passes=loop-vectorize -pass-remarks=loop-vectorize -debug -disable-output 2>&1 | FileCheck %s
; REQUIRES: asserts

; Make sure LV legal bails out when the loop doesn't have a legal pre-header.
; CHECK-LABEL: 'not_exist_preheader'
; CHECK: LV: Not vectorizing: Loop doesn't have a legal pre-header.
define void @not_exist_preheader(ptr %currMB, i1 %arg, ptr %arg2) nounwind uwtable {

start.exit:
indirectbr ptr %arg2, [label %0, label %for.bodyprime]

0:
unreachable

for.bodyprime:
%i.057375 = phi i32 [0, %start.exit], [%1, %for.bodyprime]
%arrayidx8prime = getelementptr inbounds i32, ptr %currMB, i32 %i.057375
store i32 0, ptr %arrayidx8prime, align 4
%1 = add i32 %i.057375, 1
%cmp5prime = icmp slt i32 %1, 4
br i1 %cmp5prime, label %for.bodyprime, label %exit

exit:
ret void
}
Loading