summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-21 16:52:54 +0000
committerDan Gohman <gohman@apple.com>2009-08-21 16:52:54 +0000
commitcda9706cb74a65d2feb2175613cb0fe46acc5aa2 (patch)
treead4658de533a7d96ef1f9234f884c19507b4ba31 /test
parent3b83287c4ec1c29047176dac94e2b7e302aac6bf (diff)
downloadllvm-cda9706cb74a65d2feb2175613cb0fe46acc5aa2.tar.gz
llvm-cda9706cb74a65d2feb2175613cb0fe46acc5aa2.tar.bz2
llvm-cda9706cb74a65d2feb2175613cb0fe46acc5aa2.tar.xz
Change getelementptr folding to use APInt instead of uint64_t for
offset computations. This fixes a truncation bug on targets that don't have 64-bit pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79639 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Transforms/InstCombine/constant-fold-gep-overindex.ll22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/Transforms/InstCombine/constant-fold-gep-overindex.ll b/test/Transforms/InstCombine/constant-fold-gep-overindex.ll
index 15bdab49ee..954cccb01e 100644
--- a/test/Transforms/InstCombine/constant-fold-gep-overindex.ll
+++ b/test/Transforms/InstCombine/constant-fold-gep-overindex.ll
@@ -1,17 +1,33 @@
-; RUN: llvm-as < %s | opt -instcombine
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | FileCheck %s
+
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"
target triple = "i386-apple-darwin10.0"
%0 = type { i8*, [19 x i8] }
%1 = type { i8*, [0 x i8] }
+@array = external global [11 x i8]
+
@s = external global %0 ; <%0*> [#uses=1]
@"\01LC8" = external constant [17 x i8] ; <[17 x i8]*> [#uses=1]
+; Instcombine should be able to fold this getelementptr.
+
define i32 @main() nounwind {
-entry:
- %0 = 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]
+; 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
+
+ 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]
ret i32 0
}
+; Instcombine should constant-fold the GEP so that indices that have
+; static array extents are within bounds of those array extents.
+; In the below, -1 is not in the range [0,11). After the transformation,
+; the same address is computed, but 3 is in the range of [0,11).
+
+define i8* @foo() nounwind {
+; CHECK: ret i8* getelementptr ([11 x i8]* @array, i32 390451572, i32 3)
+ ret i8* getelementptr ([11 x i8]* @array, i32 0, i64 -1)
+}
+
declare i32 @printf(i8*, ...) nounwind