Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 47dfcb7

Browse files
committed
[LoopVectorize] Don't crash on zero-sized types in isInductionPHI
isInductionPHI wants to calculate the stride based on the pointee size. However, this is not possible when the pointee is zero sized. This fixes PR23763. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239143 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 406e5ea commit 47dfcb7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Transforms/Utils/LoopUtils.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ bool llvm::isInductionPHI(PHINode *Phi, ScalarEvolution *SE,
491491

492492
const DataLayout &DL = Phi->getModule()->getDataLayout();
493493
int64_t Size = static_cast<int64_t>(DL.getTypeAllocSize(PointerElementType));
494+
if (!Size)
495+
return false;
496+
494497
int64_t CVSize = CV->getSExtValue();
495498
if (CVSize % Size)
496499
return false;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
; RUN: opt -S -loop-vectorize < %s | FileCheck %s
2+
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3+
target triple = "x86_64-unknown-linux-gnu"
4+
5+
; CHECK-LABEL: @fn1
6+
define void @fn1() {
7+
entry-block:
8+
br label %middle
9+
10+
middle:
11+
%0 = phi {}* [ %3, %middle ], [ inttoptr (i64 0 to {}*), %entry-block ]
12+
%1 = bitcast {}* %0 to i8*
13+
%2 = getelementptr i8, i8* %1, i64 1
14+
%3 = bitcast i8* %2 to {}*
15+
%4 = icmp eq i8* %2, undef
16+
br i1 %4, label %exit, label %middle
17+
18+
; CHECK: %[[phi:.*]] = phi {}* [ %3, %middle ], [ null, %entry-block ]
19+
; CHECK-NEXT: %[[bc1:.*]] = bitcast {}* %[[phi]] to i8*
20+
; CHECK-NEXT: %[[gep:.*]] = getelementptr i8, i8* %[[bc1]], i64 1
21+
; CHECK-NEXT: %[[bc2:.*]] = bitcast i8* %[[gep]] to {}*
22+
; CHECK-NEXT: %[[cmp:.*]] = icmp eq i8* %[[gep]], undef
23+
; CHECK-NEXT: br i1 %[[cmp]],
24+
25+
exit:
26+
ret void
27+
}

0 commit comments

Comments
 (0)