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

Commit 2956373

Browse files
author
Haicheng Wu
committed
[ConstantFold] Fix a crash when folding a GEP that has vector index
LLVM crashes when factoring out an out-of-bound index into preceding dimension and the preceding dimension uses vector index. Simply bail out now when this case happens. Differential Revision: https://reviews.llvm.org/D38677 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316824 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f586389 commit 2956373

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/IR/ConstantFold.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2219,6 +2219,9 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C,
22192219
Unknown = true;
22202220
continue;
22212221
}
2222+
if (!isa<ConstantInt>(Idxs[i - 1]))
2223+
// FIXME: add the support of cosntant vector index.
2224+
continue;
22222225
if (InRangeIndex && i == *InRangeIndex + 1) {
22232226
// If an index is marked inrange, we cannot apply this canonicalization to
22242227
// the following index, as that will cause the inrange index to point to

test/Transforms/InstCombine/gep-vector.ll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ define <8 x i64*> @patatino2() {
1313
%el = getelementptr inbounds i64, i64* undef, <8 x i64> undef
1414
ret <8 x i64*> %el
1515
}
16+
17+
@block = global [64 x [8192 x i8]] zeroinitializer, align 1
18+
19+
; CHECK-LABEL:vectorindex
20+
; CHECK-NEXT: ret <2 x i8*> getelementptr inbounds ([64 x [8192 x i8]], [64 x [8192 x i8]]* @block, <2 x i64> zeroinitializer, <2 x i64> <i64 0, i64 1>, <2 x i64> <i64 8192, i64 8192>)
21+
define <2 x i8*> @vectorindex() {
22+
%1 = getelementptr inbounds [64 x [8192 x i8]], [64 x [8192 x i8]]* @block, i64 0, <2 x i64> <i64 0, i64 1>, i64 8192
23+
ret <2 x i8*> %1
24+
}

0 commit comments

Comments
 (0)