2002-04-18 15:39:50 +00:00
|
|
|
; The %A getelementptr instruction should be eliminated here
|
|
|
|
|
2004-02-28 05:26:06 +00:00
|
|
|
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep getelementptr | not grep '%A '
|
2002-04-18 15:39:50 +00:00
|
|
|
|
2002-08-16 21:18:21 +00:00
|
|
|
%Global = constant [10 x sbyte] c"helloworld"
|
|
|
|
|
2002-04-18 15:39:50 +00:00
|
|
|
implementation
|
|
|
|
|
2003-03-05 22:32:48 +00:00
|
|
|
int *%foo1(int* %I) { ; Test noop elimination
|
2002-09-17 20:47:46 +00:00
|
|
|
%A = getelementptr int* %I, long 0
|
2002-05-02 15:24:40 +00:00
|
|
|
ret int * %A
|
2002-08-02 18:47:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int* %foo2(int* %I) { ; Test noop elimination
|
|
|
|
%A = getelementptr int* %I
|
|
|
|
ret int* %A
|
|
|
|
}
|
|
|
|
int* %foo3(int * %I) { ; Test that two array indexing geps fold
|
2002-09-17 20:47:46 +00:00
|
|
|
%A = getelementptr int* %I, long 17
|
|
|
|
%B = getelementptr int* %A, long 4
|
2002-08-02 18:47:11 +00:00
|
|
|
ret int* %B
|
|
|
|
}
|
2002-05-02 15:24:40 +00:00
|
|
|
|
2002-08-02 18:47:11 +00:00
|
|
|
int* %foo4({int} *%I) { ; Test that two getelementptr insts fold
|
2002-09-17 20:47:46 +00:00
|
|
|
%A = getelementptr {int}* %I, long 1
|
|
|
|
%B = getelementptr {int}* %A, long 0, ubyte 0
|
2002-08-02 18:47:11 +00:00
|
|
|
ret int* %B
|
|
|
|
}
|
2002-08-16 21:18:21 +00:00
|
|
|
|
|
|
|
sbyte * %foo5() {
|
|
|
|
; This should be turned into a constexpr instead of being an instruction
|
2002-09-17 20:47:46 +00:00
|
|
|
%A = getelementptr [10 x sbyte]* %Global, long 0, long 4
|
2002-08-16 21:18:21 +00:00
|
|
|
ret sbyte* %A
|
|
|
|
}
|
2002-11-04 16:35:14 +00:00
|
|
|
|
|
|
|
int* %foo6() {
|
|
|
|
%M = malloc [4 x int]
|
|
|
|
%A = getelementptr [4 x int]* %M, long 0, long 0
|
|
|
|
%B = getelementptr int* %A, long 2
|
|
|
|
ret int* %B
|
|
|
|
}
|
2003-03-05 22:32:48 +00:00
|
|
|
|
|
|
|
int* %foo7(int* %I, long %C, long %D) {
|
|
|
|
%A = getelementptr int* %I, long %C
|
|
|
|
%B = getelementptr int* %A, long %D
|
|
|
|
ret int* %B
|
|
|
|
}
|
2003-06-21 22:59:39 +00:00
|
|
|
|
|
|
|
sbyte* %foo8([10 x int]* %X) {
|
|
|
|
%A = getelementptr [10 x int]* %X, long 0, long 0 ;; Fold into the cast.
|
|
|
|
%B = cast int* %A to sbyte*
|
|
|
|
ret sbyte * %B
|
|
|
|
}
|