2009-08-31 04:48:15 +08:00
|
|
|
; RUN: llvm-as < %s | opt -instcombine | llvm-dis | FileCheck %s
|
2002-04-18 23:39:50 +08:00
|
|
|
|
2009-08-31 04:48:15 +08:00
|
|
|
%pair = type { i32, i32 }
|
|
|
|
@Global = constant [10 x i8] c"helloworld"
|
2002-08-17 05:18:21 +08:00
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
; Test noop elimination
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test1(i32* %I) {
|
|
|
|
%A = getelementptr i32* %I, i64 0
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32* %A
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test1
|
|
|
|
; CHECK: ret i32* %I
|
2002-08-03 02:47:11 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
; Test noop elimination
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test2(i32* %I) {
|
|
|
|
%A = getelementptr i32* %I
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32* %A
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test2
|
|
|
|
; CHECK: ret i32* %I
|
2002-08-03 02:47:11 +08:00
|
|
|
}
|
2008-03-25 12:26:08 +08:00
|
|
|
|
|
|
|
; Test that two array indexing geps fold
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test3(i32* %I) {
|
|
|
|
%A = getelementptr i32* %I, i64 17
|
|
|
|
%B = getelementptr i32* %A, i64 4
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32* %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test3
|
|
|
|
; CHECK: getelementptr i32* %I, i64 21
|
2002-08-03 02:47:11 +08:00
|
|
|
}
|
2002-05-02 23:24:40 +08:00
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
; Test that two getelementptr insts fold
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test4({ i32 }* %I) {
|
|
|
|
%A = getelementptr { i32 }* %I, i64 1
|
|
|
|
%B = getelementptr { i32 }* %A, i64 0, i32 0
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32* %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test4
|
|
|
|
; CHECK: getelementptr %0* %I, i64 1, i32 0
|
2002-08-03 02:47:11 +08:00
|
|
|
}
|
2002-08-17 05:18:21 +08:00
|
|
|
|
2009-08-31 04:48:15 +08:00
|
|
|
define void @test5(i8 %B) {
|
2008-03-25 12:26:08 +08:00
|
|
|
; This should be turned into a constexpr instead of being an instruction
|
2009-08-31 04:48:15 +08:00
|
|
|
%A = getelementptr [10 x i8]* @Global, i64 0, i64 4
|
2008-03-25 12:26:08 +08:00
|
|
|
store i8 %B, i8* %A
|
|
|
|
ret void
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test5
|
|
|
|
; CHECK: store i8 %B, i8* getelementptr inbounds ([10 x i8]* @Global, i64 0, i64 4)
|
2002-08-17 05:18:21 +08:00
|
|
|
}
|
2002-11-05 00:35:14 +08:00
|
|
|
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test6() {
|
|
|
|
%M = malloc [4 x i32]
|
|
|
|
%A = getelementptr [4 x i32]* %M, i64 0, i64 0
|
|
|
|
%B = getelementptr i32* %A, i64 2
|
2008-03-25 12:26:08 +08:00
|
|
|
ret i32* %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test6
|
|
|
|
; CHECK: getelementptr [4 x i32]* %M, i64 0, i64 2
|
2002-11-05 00:35:14 +08:00
|
|
|
}
|
2003-03-06 06:32:48 +08:00
|
|
|
|
2009-08-31 04:48:15 +08:00
|
|
|
define i32* @test7(i32* %I, i64 %C, i64 %D) {
|
2008-03-25 12:26:08 +08:00
|
|
|
%A = getelementptr i32* %I, i64 %C ; <i32*> [#uses=1]
|
|
|
|
%B = getelementptr i32* %A, i64 %D ; <i32*> [#uses=1]
|
|
|
|
ret i32* %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test7
|
|
|
|
; CHECK: %A.sum = add i64 %C, %D
|
|
|
|
; CHECK: getelementptr i32* %I, i64 %A.sum
|
2003-03-06 06:32:48 +08:00
|
|
|
}
|
2003-06-22 06:59:39 +08:00
|
|
|
|
2009-08-31 04:48:15 +08:00
|
|
|
define i8* @test8([10 x i32]* %X) {
|
2008-03-25 12:26:08 +08:00
|
|
|
;; Fold into the cast.
|
|
|
|
%A = getelementptr [10 x i32]* %X, i64 0, i64 0 ; <i32*> [#uses=1]
|
|
|
|
%B = bitcast i32* %A to i8* ; <i8*> [#uses=1]
|
|
|
|
ret i8* %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test8
|
|
|
|
; CHECK: bitcast [10 x i32]* %X to i8*
|
2003-06-22 06:59:39 +08:00
|
|
|
}
|
2004-10-17 03:44:23 +08:00
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
define i32 @test9() {
|
|
|
|
%A = getelementptr { i32, double }* null, i32 0, i32 1 ; <double*> [#uses=1]
|
|
|
|
%B = ptrtoint double* %A to i32 ; <i32> [#uses=1]
|
|
|
|
ret i32 %B
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test9
|
|
|
|
; CHECK: ret i32 8
|
2004-10-17 03:44:23 +08:00
|
|
|
}
|
2005-04-26 04:17:00 +08:00
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
define i1 @test10({ i32, i32 }* %x, { i32, i32 }* %y) {
|
|
|
|
%tmp.1 = getelementptr { i32, i32 }* %x, i32 0, i32 1 ; <i32*> [#uses=1]
|
|
|
|
%tmp.3 = getelementptr { i32, i32 }* %y, i32 0, i32 1 ; <i32*> [#uses=1]
|
|
|
|
;; seteq x, y
|
|
|
|
%tmp.4 = icmp eq i32* %tmp.1, %tmp.3 ; <i1> [#uses=1]
|
|
|
|
ret i1 %tmp.4
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test10
|
|
|
|
; CHECK: icmp eq %pair* %x, %y
|
2005-04-26 04:17:00 +08:00
|
|
|
}
|
|
|
|
|
2008-03-25 12:26:08 +08:00
|
|
|
define i1 @test11({ i32, i32 }* %X) {
|
|
|
|
%P = getelementptr { i32, i32 }* %X, i32 0, i32 0 ; <i32*> [#uses=1]
|
|
|
|
%Q = icmp eq i32* %P, null ; <i1> [#uses=1]
|
|
|
|
ret i1 %Q
|
2009-08-31 04:48:15 +08:00
|
|
|
; CHECK: @test11
|
|
|
|
; CHECK: icmp eq %pair* %X, null
|
2005-05-01 12:41:57 +08:00
|
|
|
}
|