Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.

Commit

Permalink
[LoopVectorize] Don't crash on zero-sized types in isInductionPHI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
majnemer committed Jun 5, 2015
1 parent 406e5ea commit 47dfcb7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Transforms/Utils/LoopUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ bool llvm::isInductionPHI(PHINode *Phi, ScalarEvolution *SE,

const DataLayout &DL = Phi->getModule()->getDataLayout();
int64_t Size = static_cast<int64_t>(DL.getTypeAllocSize(PointerElementType));
if (!Size)
return false;

int64_t CVSize = CV->getSExtValue();
if (CVSize % Size)
return false;
Expand Down
27 changes: 27 additions & 0 deletions test/Transforms/LoopVectorize/zero-sized-pointee-crash.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; RUN: opt -S -loop-vectorize < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; CHECK-LABEL: @fn1
define void @fn1() {
entry-block:
br label %middle

middle:
%0 = phi {}* [ %3, %middle ], [ inttoptr (i64 0 to {}*), %entry-block ]
%1 = bitcast {}* %0 to i8*
%2 = getelementptr i8, i8* %1, i64 1
%3 = bitcast i8* %2 to {}*
%4 = icmp eq i8* %2, undef
br i1 %4, label %exit, label %middle

; CHECK: %[[phi:.*]] = phi {}* [ %3, %middle ], [ null, %entry-block ]
; CHECK-NEXT: %[[bc1:.*]] = bitcast {}* %[[phi]] to i8*
; CHECK-NEXT: %[[gep:.*]] = getelementptr i8, i8* %[[bc1]], i64 1
; CHECK-NEXT: %[[bc2:.*]] = bitcast i8* %[[gep]] to {}*
; CHECK-NEXT: %[[cmp:.*]] = icmp eq i8* %[[gep]], undef
; CHECK-NEXT: br i1 %[[cmp]],

exit:
ret void
}

0 comments on commit 47dfcb7

Please sign in to comment.