llvm.org GIT mirror llvm / 6874a2a
Fix a bug that caused globalopt to miscompile tramp3d: don't miss unruly indices for arrays that are members of structs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79337 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 10 years ago
2 changed file(s) with 49 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
425425 // Scalar replacing *just* the outer index of the array is probably not
426426 // going to be a win anyway, so just give up.
427427 for (++GEPI; // Skip array index.
428 GEPI != E && (isa(*GEPI) || isa(*GEPI));
428 GEPI != E;
429429 ++GEPI) {
430430 uint64_t NumElements;
431431 if (const ArrayType *SubArrayTy = dyn_cast(*GEPI))
432432 NumElements = SubArrayTy->getNumElements();
433 else
434 NumElements = cast(*GEPI)->getNumElements();
433 else if (const VectorType *SubVectorTy = dyn_cast(*GEPI))
434 NumElements = SubVectorTy->getNumElements();
435 else {
436 assert(isa(*GEPI) &&
437 "Indexed GEP type is not array, vector, or struct!");
438 continue;
439 }
435440
436441 ConstantInt *IdxVal = dyn_cast(GEPI.getOperand());
437442 if (!IdxVal || IdxVal->getZExtValue() >= NumElements)
0 ; RUN: llvm-as < %s | opt -globalopt | llvm-dis > %t
1 ; RUN: grep {@Y = internal global \\\[3 x \[%\]struct.X\\\] zeroinitializer} %t
2 ; RUN: grep load %t | count 6
3 ; RUN: grep {add i32 \[%\]a, \[%\]b} %t | count 3
4
5 ; globalopt should not sra the global, because it can't see the index.
6
7 %struct.X = type { [3 x i32], [3 x i32] }
8
9 @Y = internal global [3 x %struct.X] zeroinitializer
10
11 @addr = external global i8
12
13 define void @frob() {
14 store i32 1, i32* getelementptr inbounds ([3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 ptrtoint (i8* @addr to i64)), align 4
15 ret void
16 }
17 define i32 @borf(i64 %i, i64 %j) {
18 %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 0, i32 0, i64 0
19 %a = load i32* %p
20 %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 0, i32 1, i64 0
21 %b = load i32* %q
22 %c = add i32 %a, %b
23 ret i32 %c
24 }
25 define i32 @borg(i64 %i, i64 %j) {
26 %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 1, i32 0, i64 1
27 %a = load i32* %p
28 %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 1, i32 1, i64 1
29 %b = load i32* %q
30 %c = add i32 %a, %b
31 ret i32 %c
32 }
33 define i32 @borh(i64 %i, i64 %j) {
34 %p = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 2, i32 0, i64 2
35 %a = load i32* %p
36 %q = getelementptr inbounds [3 x %struct.X]* @Y, i64 0, i64 2, i32 1, i64 2
37 %b = load i32* %q
38 %c = add i32 %a, %b
39 ret i32 %c
40 }