mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-01 20:52:14 +00:00
[InstCombine] avoid crash on phi with unreachable incoming block (PR48369)
This commit is contained in:
parent
f6326736ba
commit
94f6d365e4
@ -1083,9 +1083,11 @@ Instruction *InstCombinerImpl::foldOpIntoPhi(Instruction &I, PHINode *PN) {
|
||||
// operation in that block. However, if this is a critical edge, we would be
|
||||
// inserting the computation on some other paths (e.g. inside a loop). Only
|
||||
// do this if the pred block is unconditionally branching into the phi block.
|
||||
// Also, make sure that the pred block is not dead code.
|
||||
if (NonConstBB != nullptr) {
|
||||
BranchInst *BI = dyn_cast<BranchInst>(NonConstBB->getTerminator());
|
||||
if (!BI || !BI->isUnconditional()) return nullptr;
|
||||
if (!BI || !BI->isUnconditional() || !DT.isReachableFromEntry(NonConstBB))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Okay, we can do the transformation: create the new PHI node.
|
||||
|
@ -77,16 +77,16 @@ final:
|
||||
define <2 x i8> @vec3(i1 %cond1, i1 %cond2, <2 x i1> %x, <2 x i8> %y, <2 x i8> %z) {
|
||||
; CHECK-LABEL: @vec3(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: [[PHITMP1:%.*]] = shufflevector <2 x i8> [[Z:%.*]], <2 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 3>
|
||||
; CHECK-NEXT: [[PHI_SEL1:%.*]] = shufflevector <2 x i8> [[Z:%.*]], <2 x i8> [[Y:%.*]], <2 x i32> <i32 0, i32 3>
|
||||
; CHECK-NEXT: br i1 [[COND1:%.*]], label [[IF1:%.*]], label [[ELSE:%.*]]
|
||||
; CHECK: if1:
|
||||
; CHECK-NEXT: [[PHITMP2:%.*]] = shufflevector <2 x i8> [[Y]], <2 x i8> [[Z]], <2 x i32> <i32 0, i32 3>
|
||||
; CHECK-NEXT: [[PHI_SEL2:%.*]] = shufflevector <2 x i8> [[Y]], <2 x i8> [[Z]], <2 x i32> <i32 0, i32 3>
|
||||
; CHECK-NEXT: br i1 [[COND2:%.*]], label [[IF2:%.*]], label [[ELSE]]
|
||||
; CHECK: if2:
|
||||
; CHECK-NEXT: [[PHITMP:%.*]] = select <2 x i1> [[X:%.*]], <2 x i8> [[Y]], <2 x i8> [[Z]]
|
||||
; CHECK-NEXT: [[PHI_SEL:%.*]] = select <2 x i1> [[X:%.*]], <2 x i8> [[Y]], <2 x i8> [[Z]]
|
||||
; CHECK-NEXT: br label [[ELSE]]
|
||||
; CHECK: else:
|
||||
; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i8> [ [[PHITMP]], [[IF2]] ], [ [[PHITMP1]], [[ENTRY:%.*]] ], [ [[PHITMP2]], [[IF1]] ]
|
||||
; CHECK-NEXT: [[PHI:%.*]] = phi <2 x i8> [ [[PHI_SEL]], [[IF2]] ], [ [[PHI_SEL1]], [[ENTRY:%.*]] ], [ [[PHI_SEL2]], [[IF1]] ]
|
||||
; CHECK-NEXT: ret <2 x i8> [[PHI]]
|
||||
;
|
||||
entry:
|
||||
@ -103,3 +103,37 @@ else:
|
||||
%sel = select <2 x i1> %phi, <2 x i8> %y, <2 x i8> %z
|
||||
ret <2 x i8> %sel
|
||||
}
|
||||
|
||||
; Don't crash on unreachable IR.
|
||||
|
||||
define void @PR48369(i32 %a, i32* %p) {
|
||||
; CHECK-LABEL: @PR48369(
|
||||
; CHECK-NEXT: entry:
|
||||
; CHECK-NEXT: [[PHI_CMP:%.*]] = icmp sgt i32 [[A:%.*]], 0
|
||||
; CHECK-NEXT: br label [[BB1:%.*]]
|
||||
; CHECK: bb1:
|
||||
; CHECK-NEXT: [[CMP:%.*]] = phi i1 [ [[PHI_CMP]], [[DEADBB:%.*]] ], [ true, [[ENTRY:%.*]] ]
|
||||
; CHECK-NEXT: [[SHL:%.*]] = select i1 [[CMP]], i32 256, i32 0
|
||||
; CHECK-NEXT: store i32 [[SHL]], i32* [[P:%.*]], align 4
|
||||
; CHECK-NEXT: br label [[END:%.*]]
|
||||
; CHECK: deadbb:
|
||||
; CHECK-NEXT: br label [[BB1]]
|
||||
; CHECK: end:
|
||||
; CHECK-NEXT: ret void
|
||||
;
|
||||
entry:
|
||||
%phi.cmp = icmp sgt i32 %a, 0
|
||||
br label %bb1
|
||||
|
||||
bb1:
|
||||
%cmp = phi i1 [ %phi.cmp, %deadbb ], [ true, %entry ]
|
||||
%shl = select i1 %cmp, i32 256, i32 0
|
||||
store i32 %shl, i32* %p
|
||||
br label %end
|
||||
|
||||
deadbb:
|
||||
br label %bb1
|
||||
|
||||
end:
|
||||
ret void
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user