Skip to content

Commit 5541f47

Browse files
author
esmeyi
committed
[PowerPC] Check if the latch block is in the value list for the PHI before get the incoming value.
Summary: Fixes llvm#60990. There is a crash reported during Running pass 'Prepare loop for ppc preferred instruction forms'. The crash occurs in 32bit PowerPC. Reviewed By: shchenz Differential Revision: https://reviews.llvm.org/D145350
1 parent be0ef4b commit 5541f47

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

llvm/lib/Target/PowerPC/PPCLoopInstrFormPrep.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,8 @@ Value *PPCLoopInstrFormPrep::getNodeForInc(Loop *L, Instruction *MemI,
11791179

11801180
// Get the incoming value from the loop latch and check if the value has
11811181
// the add form with the required increment.
1182+
if (CurrentPHINode->getBasicBlockIndex(LatchBB) < 0)
1183+
continue;
11821184
if (Instruction *I = dyn_cast<Instruction>(
11831185
CurrentPHINode->getIncomingValueForBlock(LatchBB))) {
11841186
Value *StrippedBaseI = I;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -verify-machineinstrs -mtriple=powerpc-unknown-linux-gnu \
3+
; RUN: -mcpu=pwr9 < %s | FileCheck %s
4+
5+
define dso_local void @test_no_inc(i32 signext %a) local_unnamed_addr nounwind align 2 {
6+
; CHECK-LABEL: test_no_inc:
7+
; CHECK: # %bb.0: # %entry
8+
; CHECK-NEXT: srawi 4, 3, 31
9+
; CHECK-NEXT: cmpwi 3, 0
10+
; CHECK-NEXT: li 6, 1
11+
; CHECK-NEXT: li 7, 0
12+
; CHECK-NEXT: andc 4, 3, 4
13+
; CHECK-NEXT: addi 5, 4, 1
14+
; CHECK-NEXT: .p2align 5
15+
; CHECK-NEXT: .LBB0_1: # %for.cond
16+
; CHECK-NEXT: #
17+
; CHECK-NEXT: add 8, 3, 6
18+
; CHECK-NEXT: stb 7, 0(5)
19+
; CHECK-NEXT: add 5, 5, 4
20+
; CHECK-NEXT: iselgt 6, 8, 6
21+
; CHECK-NEXT: b .LBB0_1
22+
entry:
23+
%cmp10 = icmp sgt i32 %a, 0
24+
br label %for.cond
25+
26+
for.cond: ; preds = %for.cond.cleanup, %entry
27+
%g.0 = phi i32 [ 1, %entry ], [ %g.1.lcssa, %for.cond.cleanup ]
28+
br i1 %cmp10, label %for.body.preheader, label %for.cond.cleanup
29+
30+
for.body.preheader: ; preds = %for.cond
31+
%0 = add i32 %a, %g.0
32+
br label %for.cond.cleanup
33+
34+
for.cond.cleanup: ; preds = %for.body.preheader, %for.cond
35+
%g.1.lcssa = phi i32 [ %g.0, %for.cond ], [ %0, %for.body.preheader ]
36+
%arrayidx5 = getelementptr inbounds i8, ptr null, i32 %g.1.lcssa
37+
store i8 0, ptr %arrayidx5, align 1
38+
br label %for.cond
39+
}

0 commit comments

Comments
 (0)