2002-04-18 23:39:50 +08:00
|
|
|
; The %A getelementptr instruction should be eliminated here
|
|
|
|
|
2007-04-15 04:13:02 +08:00
|
|
|
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
|
|
|
|
; RUN: grep -v %B | not grep getelementptr
|
2007-03-26 04:42:40 +08:00
|
|
|
; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep foo1
|
2007-04-15 15:38:21 +08:00
|
|
|
; END.
|
2002-04-18 23:39:50 +08:00
|
|
|
|
2002-08-17 05:18:21 +08:00
|
|
|
%Global = constant [10 x sbyte] c"helloworld"
|
|
|
|
|
2002-04-18 23:39:50 +08:00
|
|
|
implementation
|
|
|
|
|
2003-03-06 06:32:48 +08:00
|
|
|
int *%foo1(int* %I) { ; Test noop elimination
|
2002-09-18 04:47:46 +08:00
|
|
|
%A = getelementptr int* %I, long 0
|
2002-05-02 23:24:40 +08:00
|
|
|
ret int * %A
|
2002-08-03 02:47:11 +08: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-18 04:47:46 +08:00
|
|
|
%A = getelementptr int* %I, long 17
|
|
|
|
%B = getelementptr int* %A, long 4
|
2002-08-03 02:47:11 +08:00
|
|
|
ret int* %B
|
|
|
|
}
|
2002-05-02 23:24:40 +08:00
|
|
|
|
2002-08-03 02:47:11 +08:00
|
|
|
int* %foo4({int} *%I) { ; Test that two getelementptr insts fold
|
2002-09-18 04:47:46 +08:00
|
|
|
%A = getelementptr {int}* %I, long 1
|
2006-11-23 23:14:52 +08:00
|
|
|
%B = getelementptr {int}* %A, long 0, uint 0
|
2002-08-03 02:47:11 +08:00
|
|
|
ret int* %B
|
|
|
|
}
|
2002-08-17 05:18:21 +08:00
|
|
|
|
2004-10-17 03:44:23 +08:00
|
|
|
void %foo5(sbyte %B) {
|
2002-08-17 05:18:21 +08:00
|
|
|
; This should be turned into a constexpr instead of being an instruction
|
2002-09-18 04:47:46 +08:00
|
|
|
%A = getelementptr [10 x sbyte]* %Global, long 0, long 4
|
2004-10-17 03:44:23 +08:00
|
|
|
store sbyte %B, sbyte* %A
|
|
|
|
ret void
|
2002-08-17 05:18:21 +08:00
|
|
|
}
|
2002-11-05 00:35:14 +08: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-06 06:32:48 +08: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-22 06:59:39 +08: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
|
|
|
|
}
|
2004-10-17 03:44:23 +08:00
|
|
|
|
|
|
|
int %test9() {
|
|
|
|
%A = getelementptr {int, double}* null, int 0, uint 1
|
|
|
|
%B = cast double* %A to int
|
|
|
|
ret int %B
|
|
|
|
}
|
2005-04-26 04:17:00 +08:00
|
|
|
|
2005-04-26 04:17:16 +08:00
|
|
|
bool %test10({int, int} * %x, {int, int} * %y) {
|
2005-04-26 04:17:00 +08:00
|
|
|
%tmp.1 = getelementptr {int,int}* %x, int 0, uint 1
|
|
|
|
%tmp.3 = getelementptr {int,int}* %y, int 0, uint 1
|
|
|
|
%tmp.4 = seteq int* %tmp.1, %tmp.3 ;; seteq x, y
|
|
|
|
ret bool %tmp.4
|
|
|
|
}
|
|
|
|
|
2005-05-01 12:41:57 +08:00
|
|
|
bool %test11({int,int} *%X) {
|
|
|
|
%P = getelementptr {int,int}* %X, int 0, uint 0
|
|
|
|
%Q = seteq int* %P, null
|
|
|
|
ret bool %Q
|
|
|
|
}
|