mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-14 02:33:53 +00:00
LoopVectorize: Use a set to avoid longer cycles in the reduction chain too.
Fixes PR15748. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@179757 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d050e96133
commit
403fc14370
@ -2733,7 +2733,10 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
|
|||||||
// used as reduction variables (such as ADD). We may have a single
|
// used as reduction variables (such as ADD). We may have a single
|
||||||
// out-of-block user. The cycle must end with the original PHI.
|
// out-of-block user. The cycle must end with the original PHI.
|
||||||
Instruction *Iter = Phi;
|
Instruction *Iter = Phi;
|
||||||
while (true) {
|
|
||||||
|
// Avoid cycles in the chain.
|
||||||
|
SmallPtrSet<Instruction *, 8> VisitedInsts;
|
||||||
|
while (VisitedInsts.insert(Iter)) {
|
||||||
// If the instruction has no users then this is a broken
|
// If the instruction has no users then this is a broken
|
||||||
// chain and can't be a reduction variable.
|
// chain and can't be a reduction variable.
|
||||||
if (Iter->use_empty())
|
if (Iter->use_empty())
|
||||||
@ -2747,9 +2750,6 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
|
|||||||
// Is this a bin op ?
|
// Is this a bin op ?
|
||||||
FoundBinOp |= !isa<PHINode>(Iter);
|
FoundBinOp |= !isa<PHINode>(Iter);
|
||||||
|
|
||||||
// Remember the current instruction.
|
|
||||||
Instruction *OldIter = Iter;
|
|
||||||
|
|
||||||
// For each of the *users* of iter.
|
// For each of the *users* of iter.
|
||||||
for (Value::use_iterator it = Iter->use_begin(), e = Iter->use_end();
|
for (Value::use_iterator it = Iter->use_begin(), e = Iter->use_end();
|
||||||
it != e; ++it) {
|
it != e; ++it) {
|
||||||
@ -2795,10 +2795,6 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
|
|||||||
Iter = U;
|
Iter = U;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all uses were skipped this can't be a reduction variable.
|
|
||||||
if (Iter == OldIter)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// We found a reduction var if we have reached the original
|
// We found a reduction var if we have reached the original
|
||||||
// phi node and we only have a single instruction with out-of-loop
|
// phi node and we only have a single instruction with out-of-loop
|
||||||
// users.
|
// users.
|
||||||
@ -2814,6 +2810,8 @@ bool LoopVectorizationLegality::AddReductionVar(PHINode *Phi,
|
|||||||
return FoundBinOp && ExitInstruction;
|
return FoundBinOp && ExitInstruction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -27,3 +27,21 @@ bb5: ; preds = %bb4, %bb1
|
|||||||
bb11: ; preds = %bb5
|
bb11: ; preds = %bb5
|
||||||
ret void
|
ret void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; PR15748
|
||||||
|
define void @test2() {
|
||||||
|
bb:
|
||||||
|
br label %bb1
|
||||||
|
|
||||||
|
bb1: ; preds = %bb1, %bb
|
||||||
|
%tmp = phi i32 [ 0, %bb ], [ %tmp5, %bb1 ]
|
||||||
|
%tmp2 = phi i32 [ 0, %bb ], [ 1, %bb1 ]
|
||||||
|
%tmp3 = phi i32 [ 0, %bb ], [ %tmp4, %bb1 ]
|
||||||
|
%tmp4 = or i32 %tmp2, %tmp3
|
||||||
|
%tmp5 = add nsw i32 %tmp, 1
|
||||||
|
%tmp6 = icmp eq i32 %tmp5, 0
|
||||||
|
br i1 %tmp6, label %bb7, label %bb1
|
||||||
|
|
||||||
|
bb7: ; preds = %bb1
|
||||||
|
ret void
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user