Change getelementptr folding to use APInt instead of uint64_t for
[oota-llvm.git] / test / Transforms / InstCombine / constant-fold-gep-overindex.ll
1 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | FileCheck %s
2
3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4 target triple = "i386-apple-darwin10.0"
5
6 %0 = type { i8*, [19 x i8] }
7 %1 = type { i8*, [0 x i8] }
8
9 @array = external global [11 x i8]
10
11 @s = external global %0                           ; <%0*> [#uses=1]
12 @"\01LC8" = external constant [17 x i8]           ; <[17 x i8]*> [#uses=1]
13
14 ; Instcombine should be able to fold this getelementptr.
15
16 define i32 @main() nounwind {
17 ; CHECK: call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([17 x i8]* @"\01LC8", i32 0, i32 0), i8* undef, i8* bitcast (i8** getelementptr (%1* bitcast (%0* @s to %1*), i32 1, i32 0) to i8*)) nounwind
18
19   call i32 (i8*, ...)* @printf(i8* getelementptr ([17 x i8]* @"\01LC8", i32 0, i32 0), i8* undef, i8* getelementptr (%1* bitcast (%0* @s to %1*), i32 0, i32 1, i32 0)) nounwind ; <i32> [#uses=0]
20   ret i32 0
21 }
22
23 ; Instcombine should constant-fold the GEP so that indices that have
24 ; static array extents are within bounds of those array extents.
25 ; In the below, -1 is not in the range [0,11). After the transformation,
26 ; the same address is computed, but 3 is in the range of [0,11).
27
28 define i8* @foo() nounwind {
29 ; CHECK: ret i8* getelementptr ([11 x i8]* @array, i32 390451572, i32 3)
30   ret i8* getelementptr ([11 x i8]* @array, i32 0, i64 -1)
31 }
32
33 declare i32 @printf(i8*, ...) nounwind