mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[SLP] avoid unreachable code crash/infloop
Example based on the post-commit comments for D88735.
This commit is contained in:
parent
8e1729917d
commit
1cf013898b
@ -7686,10 +7686,12 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
|
||||
// Try to vectorize the incoming values of the PHI, to catch reductions
|
||||
// that feed into PHIs.
|
||||
for (unsigned I = 0, E = P->getNumIncomingValues(); I != E; I++) {
|
||||
// Skip if the incoming block is the current BB for now.
|
||||
// Skip if the incoming block is the current BB for now. Also, bypass
|
||||
// unreachable IR for efficiency and to avoid crashing.
|
||||
// TODO: Collect the skipped incoming values and try to vectorize them
|
||||
// after processing BB.
|
||||
if (BB == P->getIncomingBlock(I))
|
||||
if (BB == P->getIncomingBlock(I) ||
|
||||
!DT->isReachableFromEntry(P->getIncomingBlock(I)))
|
||||
continue;
|
||||
|
||||
Changed |= vectorizeRootInstruction(nullptr, P->getIncomingValue(I),
|
||||
|
@ -1731,4 +1731,39 @@ exit:
|
||||
ret i32 %sum.1
|
||||
}
|
||||
|
||||
; Make sure we do not crash or infinite loop on ill-formed IR.
|
||||
|
||||
define void @unreachable_block() {
|
||||
; CHECK-LABEL: @unreachable_block(
|
||||
; CHECK-NEXT: bb.0:
|
||||
; CHECK-NEXT: br label [[BB_1:%.*]]
|
||||
; CHECK: dead:
|
||||
; CHECK-NEXT: [[T0:%.*]] = add i16 [[T0]], undef
|
||||
; CHECK-NEXT: br label [[BB_1]]
|
||||
; CHECK: bb.1:
|
||||
; CHECK-NEXT: [[T1:%.*]] = phi i16 [ undef, [[BB_0:%.*]] ], [ [[T0]], [[DEAD:%.*]] ]
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
; STORE-LABEL: @unreachable_block(
|
||||
; STORE-NEXT: bb.0:
|
||||
; STORE-NEXT: br label [[BB_1:%.*]]
|
||||
; STORE: dead:
|
||||
; STORE-NEXT: [[T0:%.*]] = add i16 [[T0]], undef
|
||||
; STORE-NEXT: br label [[BB_1]]
|
||||
; STORE: bb.1:
|
||||
; STORE-NEXT: [[T1:%.*]] = phi i16 [ undef, [[BB_0:%.*]] ], [ [[T0]], [[DEAD:%.*]] ]
|
||||
; STORE-NEXT: ret void
|
||||
;
|
||||
bb.0:
|
||||
br label %bb.1
|
||||
|
||||
dead:
|
||||
%t0 = add i16 %t0, undef ; unreachable IR may depend on itself
|
||||
br label %bb.1
|
||||
|
||||
bb.1:
|
||||
%t1 = phi i16 [ undef, %bb.0 ], [ %t0, %dead ]
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @__gxx_personality_v0(...)
|
||||
|
Loading…
Reference in New Issue
Block a user