llvm.org GIT mirror llvm / 76806b6
Remove llvm-upgrade and update tests. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@48103 91177308-0d34-0410-b5e6-96231b3b80d8 Tanya Lattner 12 years ago
65 changed file(s) with 1003 addition(s) and 927 deletion(s). Raw diff Collapse all Expand all
33 ; RUN: llvm-as < %s | llc -march=alpha | grep gprel32
44 ; RUN: llvm-as < %s | llc -march=alpha | grep ldl
55 ; RUN: llvm-as < %s | llc -march=alpha | grep rodata
6 ; END.
67
78 target datalayout = "e-p:64:64"
89 target triple = "alphaev67-unknown-linux-gnu"
None ; RUN: llvm-upgrade < %s | llvm-as > %t.bc
0 ; RUN: llvm-as < %s > %t.bc
11 ; RUN: echo | llvm-as > %t.tmp.bc
22 ; RUN: llvm-link %t.tmp.bc %t.bc
33
4 %X = constant int 5
5 %Y = internal global [2 x int*] [ int* %X, int * %X]
4 @X = constant i32 5 ; [#uses=2]
5 @Y = internal global [2 x i32*] [ i32* @X, i32* @X ] ; <[2 x i32*]*> [#uses=0]
66
77
0 ; This fails linking when it is linked with an empty file as the first object file
11
22 ; RUN: llvm-as > %t1.bc < /dev/null
3 ; RUN: llvm-upgrade < %s | llvm-as > %t2.bc
3 ; RUN: llvm-as < %s > %t2.bc
44 ; RUN: llvm-link %t1.bc %t2.bc
55
6 %work = global int (int, int)* %zip
6 @work = global i32 (i32, i32)* @zip ; [#uses=0]
77
8 declare int %zip(int, int)
8 declare i32 @zip(i32, i32)
9
0 ; This fails linking when it is linked with an empty file as the first object file
11
22 ; RUN: llvm-as > %t.LinkTest.bc < /dev/null
3 ; RUN: llvm-upgrade < %s | llvm-as > %t.bc
3 ; RUN: llvm-as < %s > %t.bc
44 ; RUN: llvm-link %t.LinkTest.bc %t.bc
55
6 %work = global int 4
7 %test = global int* getelementptr( int* %work, long 1)
6 @work = global i32 4 ; [#uses=1]
7 @test = global i32* getelementptr (i32* @work, i64 1) ; [#uses=0]
88
0 ; This one fails because the LLVM runtime is allowing two null pointers of
11 ; the same type to be created!
22
3 ; RUN: echo {%T = type int} | llvm-upgrade | llvm-as > %t.2.bc
4 ; RUN: llvm-upgrade < %s | llvm-as -f > %t.1.bc
3 ; RUN: echo {%T = type i32} | llvm-as > %t.2.bc
4 ; RUN: llvm-as < %s -f > %t.1.bc
55 ; RUN: llvm-link %t.1.bc %t.2.bc
66
77 %T = type opaque
88
9 declare %T* %create()
9 declare %T* @create()
1010
11 implementation
12
13 void %test() {
14 %X = call %T* %create()
15 %v = seteq %T* %X, null
11 define void @test() {
12 %X = call %T* @create( ) ; <%T*> [#uses=1]
13 %v = icmp eq %T* %X, null ; [#uses=0]
1614 ret void
1715 }
1816
11 ; the same type to be created!
22
33 ; RUN: echo {%S = type \{ %T*\} %T = type opaque} | llvm-as > %t.2.bc
4 ; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
4 ; RUN: llvm-as < %s > %t.1.bc
55 ; RUN: llvm-link %t.1.bc %t.2.bc
66
7 %S = type { %T* }
8 %T = type int
7 %S = type { i32* }
8 %T = type i32
99
None ; RUN: echo {%T = type opaque} | llvm-upgrade | llvm-as > %t.2.bc
1 ; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
0 ; RUN: echo {%T = type opaque} | llvm-as > %t.2.bc
1 ; RUN: llvm-as < %s > %t.1.bc
22 ; RUN: llvm-link %t.1.bc %t.2.bc
33
44 %T = type opaque
5 %a = constant { %T* } { %T* null }
5 @a = constant { %T* } zeroinitializer ; <{ %T* }*> [#uses=0]
66
None ; RUN: echo {%T = type int} | llvm-upgrade | llvm-as > %t.1.bc
1 ; RUN: llvm-upgrade < %s | llvm-as > %t.2.bc
0 ; RUN: echo {%T = type i32} | llvm-as > %t.1.bc
1 ; RUN: llvm-as < %s > %t.2.bc
22 ; RUN: llvm-link %t.1.bc %t.2.bc
33
44 %T = type opaque
5 @X = constant { %T* } zeroinitializer ; <{ %T* }*> [#uses=0]
56
6 %X = constant {%T*} {%T* null }
7
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
1 ; RUN: echo {%S = type \{ int, int* \} } | llvm-upgrade | llvm-as > %t.out2.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
1 ; RUN: echo {%S = type \{ i32, i32* \} } | llvm-as > %t.out2.bc
22 ; RUN: llvm-link %t.out1.bc %t.out2.bc
33
4 %S = type { i32, %T* }
45 %T = type opaque
5 %S = type { int, %T* }
6
67 ;%X = global { int, %T* } { int 5, %T* null }
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
1 ; RUN: echo {%S = external global \{ int, opaque* \} declare void %F(opaque*)}\
2 ; RUN: | llvm-upgrade | llvm-as > %t.out2.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
1 ; RUN: echo {@S = external global \{ i32, opaque* \} declare void @F(opaque*)}\
2 ; RUN: | llvm-as > %t.out2.bc
33 ; RUN: llvm-link %t.out1.bc %t.out2.bc | llvm-dis | not grep opaque
44
55 ; After linking this testcase, there should be no opaque types left. The two
66 ; S's should cause the opaque type to be resolved to 'int'.
7 %S = global { int, int* } { int 5, int* null }
7 @S = global { i32, i32* } { i32 5, i32* null } ; <{ i32, i32* }*> [#uses=0]
88
9 declare void %F(int*)
9 declare void @F(i32*)
0 ; It's a bad idea to go recursively traipsing through types without a safety
11 ; net.
22
3 ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
4 ; RUN: echo "%S = type { %S*, int* }" | llvm-upgrade | llvm-as > %t.out2.bc
3 ; RUN: llvm-as < %s > %t.out1.bc
4 ; RUN: echo "%S = type { %S*, i32* }" | llvm-as > %t.out2.bc
55 ; RUN: llvm-link %t.out1.bc %t.out2.bc
66
77 %S = type { %S*, opaque* }
8
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
1 ; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
1 ; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
22 ; RUN: llvm-link %t.out2.bc %t.out1.bc
33
44 %S = type opaque
55
6 void %foo(int* %V) {
7 ret void
6 define void @foo(i32* %V) {
7 ret void
88 }
99
10 declare void %foo(%S*)
10 declare void @foo.upgrd.1(%S*)
1111
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
1 ; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
1 ; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
22 ; RUN: llvm-link %t.out2.bc %t.out1.bc
33
44 %S = type opaque
55
6 void %foo(int* %V) {
7 ret void
6 define void @foo(i32* %V) {
7 ret void
88 }
99
10 declare void %foo(%S*)
10 declare void @foo.upgrd.1(%S*)
1111
12 void %other() {
13 call void %foo(%S* null) ; Add a use of the unresolved proto
14 call void %foo(int* null) ; Add a use of the resolved function
12 define void @other() {
13 call void @foo.upgrd.1( %S* null )
14 call void @foo( i32* null )
1515 ret void
1616 }
17
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
1 ; RUN: echo "%S = type int" | llvm-upgrade | llvm-as > %t.out2.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
1 ; RUN: echo "%S = type i32" | llvm-as > %t.out2.bc
22 ; RUN: llvm-link %t.out2.bc %t.out1.bc
33
44 %S = type opaque
55
66 ; GLobal using the resolved function prototype
7 global void(%S*)* %foo
7 global void (%S*)* @foo ; :0 [#uses=0]
88
9 void %foo(int* %V) {
10 ret void
9 define void @foo.upgrd.1(i32* %V) {
10 ret void
1111 }
1212
13 declare void %foo(%S*)
13 declare void @foo(%S*)
1414
None ; RUN: llvm-upgrade < %s | llvm-as > %t.out1.bc
0 ; RUN: llvm-as < %s > %t.out1.bc
11 ; RUN: echo { %S = type \[8 x i32\] external global %S } | llvm-as > %t.out2.bc
22 ; RUN: llvm-link %t.out1.bc %t.out2.bc | llvm-dis | grep %S | grep \{
33
4 %S = type { int }
4 %S = type { i32 }
55
66
0 ; The linker should merge link-once globals into strong external globals,
11 ; just like it does for weak symbols!
22
3 ; RUN: echo "%X = global int 7" | llvm-upgrade | llvm-as > %t.2.bc
4 ; RUN: llvm-upgrade < %s | llvm-as > %t.1.bc
3 ; RUN: echo "@X = global i32 7" | llvm-as > %t.2.bc
4 ; RUN: llvm-as < %s > %t.1.bc
55 ; RUN: llvm-link %t.1.bc %t.2.bc
66
7 %X = linkonce global int 7
7 @X = linkonce global i32 7
22 ; Test that -indvars can reduce variable stride IVs. If it can reduce variable
33 ; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
44 ; cycles, allowing the tmp.21 subtraction to be eliminated.
5 ; END.
56
67 define void @vnum_test8(i32* %data) {
78 entry:
55 ;
66 ; RUN: llvm-as < %s | opt -instcombine
77 ;
8 ; END.
9
810 @.LC0 = internal global [21 x i8] c"hbMakeCodeLengths(1)\00" ; <[21 x i8]*> [#uses=1]
911 @.LC1 = internal global [21 x i8] c"hbMakeCodeLengths(2)\00" ; <[21 x i8]*> [#uses=1]
1012
1010 ;
1111 ; Extra code:
1212 ; RUN: llvm-as < %s | opt -instcombine
13 ;
13 ; END.
1414
1515 target datalayout = "e-p:32:32"
1616 @silly = external constant i32 ; [#uses=1]
1010 ;
1111 ; RUN: llvm-as < %s -o - | opt -instcombine | llvm-dis | \
1212 ; RUN: notcast .*int
13
13 ; END.
1414 define i1 @lt_signed_to_large_unsigned(i8 %SB) {
1515 %Y = sext i8 %SB to i32 ; [#uses=1]
1616 %C = icmp ult i32 %Y, 1024 ; [#uses=1]
0 ; RUN: llvm-as < %s | opt -instcombine -disable-output
1 ; END.
12 %struct.DecRefPicMarking_s = type { i32, i32, i32, i32, i32, %struct.DecRefPicMarking_s* }
23 %struct.datapartition = type { %typedef.Bitstream*, %typedef.DecodingEnvironment, i32 (%struct.syntaxelement*, %struct.img_par*, %struct.inp_par*, %struct.datapartition*)* }
34 %struct.img_par = type { i32, i32, i32, i32, i32*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [16 x [16 x i16]], [6 x [32 x i32]], [16 x [16 x i32]], [4 x [12 x [4 x [4 x i32]]]], [16 x i32], i32**, i32*, i32***, i32**, i32, i32, i32, i32, %typedef.Slice*, %struct.macroblock*, i32, i32, i32, i32, i32, i32, i32**, %struct.DecRefPicMarking_s*, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, [3 x i32], i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32***, i32***, i32****, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, %struct.timeb, %struct.timeb, i32, i32, i32, i32, i32, i32, i32, i32 }
0 ; RUN: llvm-as < %s | opt -instcombine -disable-output
1 ; END.
12
23 define void @test() {
34 bb38.i:
0 ; RUN: llvm-as < %s | opt -instcombine -disable-output
1 ; END.
12 %struct.gs_matrix = type { float, i32, float, i32, float, i32, float, i32, float, i32, float, i32 }
23 %struct.gx_bitmap = type { i8*, i32, i32, i32 }
34 %struct.gx_device = type { i32, %struct.gx_device_procs*, i8*, i32, i32, float, float, i32, i16, i32, i32 }
0 ; PR905
11 ; RUN: llvm-as < %s | opt -instcombine -disable-output
2 ; END.
23
34 %RPYTHON_EXCEPTION = type { %RPYTHON_EXCEPTION_VTABLE* }
45 %RPYTHON_EXCEPTION_VTABLE = type { %RPYTHON_EXCEPTION_VTABLE*, i32, i32, %RPyOpaque_RuntimeTypeInfo*, %arraytype_Char*, %functiontype_12* }
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep {icmp sgt}
2 ; END.
23 target datalayout = "e-p:32:32"
34 target triple = "i686-pc-linux-gnu"
45 %struct.point = type { i32, i32 }
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep select
1 ; END.
12
23 target datalayout = "e-p:32:32"
34 target triple = "i686-pc-linux-gnu"
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep -v {icmp ult i32}
2 ; END.
23
34 target datalayout = "e-p:32:32"
45 target triple = "i686-pc-linux-gnu"
11 ; RUN: grep icmp | count 1
22 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
33 ; RUN: grep {icmp ugt} | count 1
4 ; END.
45
56 target datalayout = "e-p:32:32"
67 target triple = "i686-pc-linux-gnu"
0 ; For PR1065. This causes an assertion in instcombine if a select with two cmp
11 ; operands is encountered.
22 ; RUN: llvm-as < %s | opt -instcombine -disable-output
3 ; END.
34
45 target datalayout = "e-p:32:32"
56 target triple = "i686-pc-linux-gnu"
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep select | not grep {i32\\*}
2 ; END.
32
43 ; This testcase corresponds to PR362, which notices that this horrible code
54 ; is generated by the C++ front-end and LLVM optimizers, which has lots of
87 ; Instcombine should propagate the load through the select instructions to
98 ; allow elimination of the extra stuff by the mem2reg pass.
109
11 implementation ; Functions:
12
13 void %_Z5test1RiS_(int* %x, int* %y) {
10 define void @_Z5test1RiS_(i32* %x, i32* %y) {
1411 entry:
15 %tmp.1.i = load int* %y ; [#uses=1]
16 %tmp.3.i = load int* %x ; [#uses=1]
17 %tmp.4.i = setlt int %tmp.1.i, %tmp.3.i ; [#uses=1]
18 %retval.i = select bool %tmp.4.i, int* %y, int* %x ; [#uses=1]
19 %tmp.4 = load int* %retval.i ; [#uses=1]
20 store int %tmp.4, int* %x
21 ret void
12 %tmp.1.i = load i32* %y ; [#uses=1]
13 %tmp.3.i = load i32* %x ; [#uses=1]
14 %tmp.4.i = icmp slt i32 %tmp.1.i, %tmp.3.i ; [#uses=1]
15 %retval.i = select i1 %tmp.4.i, i32* %y, i32* %x ; [#uses=1]
16 %tmp.4 = load i32* %retval.i ; [#uses=1]
17 store i32 %tmp.4, i32* %x
18 ret void
2219 }
2320
24 void %_Z5test2RiS_(int* %x, int* %y) {
21 define void @_Z5test2RiS_(i32* %x, i32* %y) {
2522 entry:
26 %tmp.0 = alloca int ; [#uses=2]
27 %tmp.2 = load int* %x ; [#uses=2]
28 store int %tmp.2, int* %tmp.0
29 %tmp.3.i = load int* %y ; [#uses=1]
30 %tmp.4.i = setlt int %tmp.2, %tmp.3.i ; [#uses=1]
31 %retval.i = select bool %tmp.4.i, int* %y, int* %tmp.0 ; [#uses=1]
32 %tmp.6 = load int* %retval.i ; [#uses=1]
33 store int %tmp.6, int* %y
34 ret void
23 %tmp.0 = alloca i32 ; [#uses=2]
24 %tmp.2 = load i32* %x ; [#uses=2]
25 store i32 %tmp.2, i32* %tmp.0
26 %tmp.3.i = load i32* %y ; [#uses=1]
27 %tmp.4.i = icmp slt i32 %tmp.2, %tmp.3.i ; [#uses=1]
28 %retval.i = select i1 %tmp.4.i, i32* %y, i32* %tmp.0 ; [#uses=1]
29 %tmp.6 = load i32* %retval.i ; [#uses=1]
30 store i32 %tmp.6, i32* %y
31 ret void
3532 }
33
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -gcse -instcombine | \
0 ; RUN: llvm-as < %s | opt -instcombine -gcse -instcombine | \
11 ; RUN: llvm-dis | not grep getelementptr
22
3 bool %test(int* %A) {
4 %B = getelementptr int* %A, int 1
5 %C = getelementptr int* %A, uint 1
6 %V = seteq int* %B, %C
7 ret bool %V
3 define i1 @test(i32* %A) {
4 %B = getelementptr i32* %A, i32 1 ; [#uses=1]
5 %C = getelementptr i32* %A, i64 1 ; [#uses=1]
6 %V = icmp eq i32* %B, %C ; [#uses=1]
7 ret i1 %V
88 }
9
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
1 target endian = little
2 target pointersize = 32
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
1 target datalayout = "e-p:32:32"
32
4 int *%test(int *%P) {
5 %V = cast int* %P to int
6 %P2 = cast int %V to int*
7 ret int* %P2
3 define i32* @test(i32* %P) {
4 %V = ptrtoint i32* %P to i32 ; [#uses=1]
5 %P2 = inttoptr i32 %V to i32* ; [#uses=1]
6 ret i32* %P2
87 }
8
0 ; This is the sequence of stuff that the Java front-end expands for a single
11 ; <= comparison. Check to make sure we turn it into a <= (only)
22
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
3 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
44 ; RUN: grep -v {icmp sle} | not grep #uses
55
6 bool %le(int %A, int %B) {
7 %c1 = setgt int %A, %B;
8 %tmp = select bool %c1, int 1, int 0;
9 %c2 = setlt int %A, %B;
10 %result = select bool %c2, int -1, int %tmp;
11 %c3 = setle int %result, 0;
12 ret bool %c3;
6 define i1 @le(i32 %A, i32 %B) {
7 %c1 = icmp sgt i32 %A, %B ; [#uses=1]
8 %tmp = select i1 %c1, i32 1, i32 0 ; [#uses=1]
9 %c2 = icmp slt i32 %A, %B ; [#uses=1]
10 %result = select i1 %c2, i32 -1, i32 %tmp ; [#uses=1]
11 %c3 = icmp sle i32 %result, 0 ; [#uses=1]
12 ret i1 %c3
1313 }
1414
0 ; This test makes sure that add instructions are properly eliminated.
11
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
2 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
33 ; RUN: grep -v OK | not grep add
4 ; END.
5
6 implementation
7
8 int %test1(int %A) {
9 %B = add int %A, 0
10 ret int %B
11 }
12
13 int %test2(int %A) {
14 %B = add int %A, 5
15 %C = add int %B, -5
16 ret int %C
17 }
18
19 int %test3(int %A) {
20 %B = add int %A, 5
21 %C = sub int %B, 5 ;; This should get converted to an add
22 ret int %C
23 }
24
25 int %test4(int %A, int %B) {
26 %C = sub int 0, %A
27 %D = add int %B, %C ; D = B + -A = B - A
28 ret int %D
29 }
30
31 int %test5(int %A, int %B) {
32 %C = sub int 0, %A
33 %D = add int %C, %B ; D = -A + B = B - A
34 ret int %D
35 }
36
37 int %test6(int %A) {
38 %B = mul int 7, %A
39 %C = add int %B, %A ; C = 7*A+A == 8*A == A << 3
40 ret int %C
41 }
42
43 int %test7(int %A) {
44 %B = mul int 7, %A
45 %C = add int %A, %B ; C = A+7*A == 8*A == A << 3
46 ret int %C
4
5 define i32 @test1(i32 %A) {
6 %B = add i32 %A, 0 ; [#uses=1]
7 ret i32 %B
8 }
9
10 define i32 @test2(i32 %A) {
11 %B = add i32 %A, 5 ; [#uses=1]
12 %C = add i32 %B, -5 ; [#uses=1]
13 ret i32 %C
14 }
15
16 define i32 @test3(i32 %A) {
17 %B = add i32 %A, 5 ; [#uses=1]
18 ;; This should get converted to an add
19 %C = sub i32 %B, 5 ; [#uses=1]
20 ret i32 %C
21 }
22
23 define i32 @test4(i32 %A, i32 %B) {
24 %C = sub i32 0, %A ; [#uses=1]
25 ; D = B + -A = B - A
26 %D = add i32 %B, %C ; [#uses=1]
27 ret i32 %D
28 }
29
30 define i32 @test5(i32 %A, i32 %B) {
31 %C = sub i32 0, %A ; [#uses=1]
32 ; D = -A + B = B - A
33 %D = add i32 %C, %B ; [#uses=1]
34 ret i32 %D
35 }
36
37 define i32 @test6(i32 %A) {
38 %B = mul i32 7, %A ; [#uses=1]
39 ; C = 7*A+A == 8*A == A << 3
40 %C = add i32 %B, %A ; [#uses=1]
41 ret i32 %C
42 }
43
44 define i32 @test7(i32 %A) {
45 %B = mul i32 7, %A ; [#uses=1]
46 ; C = A+7*A == 8*A == A << 3
47 %C = add i32 %A, %B ; [#uses=1]
48 ret i32 %C
4749 }
4850
4951 ; (A & C1)+(B & C2) -> (A & C1)|(B & C2) iff C1&C2 == 0
50 int %test8(int %A, int %B) {
51 %A1 = and int %A, 7
52 %B1 = and int %B, 128
53 %C = add int %A1, %B1
54 ret int %C
55 }
56
57 int %test9(int %A) {
58 %B = shl int %A, ubyte 4
59 %C = add int %B, %B ; === shl int %A, 5
60 ret int %C
61 }
62
63 bool %test10(ubyte %A, ubyte %b) {
64 %B = add ubyte %A, %b
65 %c = setne ubyte %B, 0 ; === A != -b
66 ret bool %c
67 }
68
69 bool %test11(ubyte %A) {
70 %B = add ubyte %A, 255
71 %c = setne ubyte %B, 0 ; === A != 1
72 ret bool %c
73 }
74
75 int %test12(int %A, int %B) {
76 %C_OK = add int %B, %A ; Should be transformed into shl A, 1
77 br label %X
78 X:
79 %D = add int %C_OK, %A
80 ret int %D
81 }
82
83 int %test13(int %A, int %B, int %C) {
84 %D_OK = add int %A, %B
85 %E_OK = add int %D_OK, %C
86 %F = add int %E_OK, %A ;; shl A, 1
87 ret int %F
88 }
89
90 uint %test14(uint %offset, uint %difference) {
91 %tmp.2 = and uint %difference, 3
92 %tmp.3_OK = add uint %tmp.2, %offset
93 %tmp.5.mask = and uint %difference, 4294967292
94 %tmp.8 = add uint %tmp.3_OK, %tmp.5.mask ; == add %offset, %difference
95 ret uint %tmp.8
96 }
97
98 ubyte %test15(ubyte %A) {
99 %B = add ubyte %A, 192 ; Does not effect result
100 %C = and ubyte %B, 16 ; Only one bit set
101 ret ubyte %C
102 }
103
104 ubyte %test16(ubyte %A) {
105 %B = add ubyte %A, 16 ; Turn this into a XOR
106 %C = and ubyte %B, 16 ; Only one bit set
107 ret ubyte %C
108 }
109
110 int %test17(int %A) {
111 %B = xor int %A, -1
112 %C = add int %B, 1 ; == sub int 0, %A
113 ret int %C
114 }
115
116 ubyte %test18(ubyte %A) {
117 %B = xor ubyte %A, 255
118 %C = add ubyte %B, 17 ; == sub ubyte 16, %A
119 ret ubyte %C
120 }
121
122 int %test19(bool %C) {
123 %A = select bool %C, int 1000, int 10
124 %V = add int %A, 123
125 ret int %V
126 }
127
128 int %test20(int %x) {
129 %tmp.2 = xor int %x, -2147483648
52 define i32 @test8(i32 %A, i32 %B) {
53 %A1 = and i32 %A, 7 ; [#uses=1]
54 %B1 = and i32 %B, 128 ; [#uses=1]
55 %C = add i32 %A1, %B1 ; [#uses=1]
56 ret i32 %C
57 }
58
59 define i32 @test9(i32 %A) {
60 %B = shl i32 %A, 4 ; [#uses=2]
61 ; === shl int %A, 5
62 %C = add i32 %B, %B ; [#uses=1]
63 ret i32 %C
64 }
65
66 define i1 @test10(i8 %A, i8 %b) {
67 %B = add i8 %A, %b ; [#uses=1]
68 ; === A != -b
69 %c = icmp ne i8 %B, 0 ; [#uses=1]
70 ret i1 %c
71 }
72
73 define i1 @test11(i8 %A) {
74 %B = add i8 %A, -1 ; [#uses=1]
75 ; === A != 1
76 %c = icmp ne i8 %B, 0 ; [#uses=1]
77 ret i1 %c
78 }
79
80 define i32 @test12(i32 %A, i32 %B) {
81 ; Should be transformed into shl A, 1
82 %C_OK = add i32 %B, %A ; [#uses=1]
83 br label %X
84
85 X: ; preds = %0
86 %D = add i32 %C_OK, %A ; [#uses=1]
87 ret i32 %D
88 }
89
90 define i32 @test13(i32 %A, i32 %B, i32 %C) {
91 %D_OK = add i32 %A, %B ; [#uses=1]
92 %E_OK = add i32 %D_OK, %C ; [#uses=1]
93 ;; shl A, 1
94 %F = add i32 %E_OK, %A ; [#uses=1]
95 ret i32 %F
96 }
97
98 define i32 @test14(i32 %offset, i32 %difference) {
99 %tmp.2 = and i32 %difference, 3 ; [#uses=1]
100 %tmp.3_OK = add i32 %tmp.2, %offset ; [#uses=1]
101 %tmp.5.mask = and i32 %difference, -4 ; [#uses=1]
102 ; == add %offset, %difference
103 %tmp.8 = add i32 %tmp.3_OK, %tmp.5.mask ; [#uses=1]
104 ret i32 %tmp.8
105 }
106
107 define i8 @test15(i8 %A) {
108 ; Does not effect result
109 %B = add i8 %A, -64 ; [#uses=1]
110 ; Only one bit set
111 %C = and i8 %B, 16 ; [#uses=1]
112 ret i8 %C
113 }
114
115 define i8 @test16(i8 %A) {
116 ; Turn this into a XOR
117 %B = add i8 %A, 16 ; [#uses=1]
118 ; Only one bit set
119 %C = and i8 %B, 16 ; [#uses=1]
120 ret i8 %C
121 }
122
123 define i32 @test17(i32 %A) {
124 %B = xor i32 %A, -1 ; [#uses=1]
125 ; == sub int 0, %A
126 %C = add i32 %B, 1 ; [#uses=1]
127 ret i32 %C
128 }
129
130 define i8 @test18(i8 %A) {
131 %B = xor i8 %A, -1 ; [#uses=1]
132 ; == sub ubyte 16, %A
133 %C = add i8 %B, 17 ; [#uses=1]
134 ret i8 %C
135 }
136
137 define i32 @test19(i1 %C) {
138 %A = select i1 %C, i32 1000, i32 10 ; [#uses=1]
139 %V = add i32 %A, 123 ; [#uses=1]
140 ret i32 %V
141 }
142
143 define i32 @test20(i32 %x) {
144 %tmp.2 = xor i32 %x, -2147483648 ; [#uses=1]
130145 ;; Add of sign bit -> xor of sign bit.
131 %tmp.4 = add int %tmp.2, -2147483648
132 ret int %tmp.4
133 }
134
135 bool %test21(uint %x) {
136 %t = add uint %x, 4
137 %y = seteq uint %t, 123
138 ret bool %y
139 }
140
141 int %test22(uint %V) {
142 %V2 = add uint %V, 10
143 switch uint %V2, label %Default [
144 uint 20, label %Lab1
145 uint 30, label %Lab2
146 ]
147 Default:
148 ret int 123
149 Lab1:
150 ret int 12312
151 Lab2:
152 ret int 1231231
153 }
154
155 int %test23(bool %C, int %a) {
146 %tmp.4 = add i32 %tmp.2, -2147483648 ; [#uses=1]
147 ret i32 %tmp.4
148 }
149
150 define i1 @test21(i32 %x) {
151 %t = add i32 %x, 4 ; [#uses=1]
152 %y = icmp eq i32 %t, 123 ; [#uses=1]
153 ret i1 %y
154 }
155
156 define i32 @test22(i32 %V) {
157 %V2 = add i32 %V, 10 ; [#uses=1]
158 switch i32 %V2, label %Default [
159 i32 20, label %Lab1
160 i32 30, label %Lab2
161 ]
162
163 Default: ; preds = %0
164 ret i32 123
165
166 Lab1: ; preds = %0
167 ret i32 12312
168
169 Lab2: ; preds = %0
170 ret i32 1231231
171 }
172
173 define i32 @test23(i1 %C, i32 %a) {
156174 entry:
157 br bool %C, label %endif, label %else
158
159 else:
175 br i1 %C, label %endif, label %else
176
177 else: ; preds = %entry
160178 br label %endif
161179
162 endif:
163 %b.0 = phi int [ 0, %entry ], [ 1, %else ]
164 %tmp.4 = add int %b.0, 1
165 ret int %tmp.4
166 }
167
168 int %test24(int %A) {
169 %B = add int %A, 1
170 %C = shl int %B, ubyte 1
171 %D = sub int %C, 2
172 ret int %D ;; A << 1
173 }
174
175 long %test25(long %Y) {
176 %tmp.4 = shl long %Y, ubyte 2
177 %tmp.12 = shl long %Y, ubyte 2
178 %tmp.8 = add long %tmp.4, %tmp.12 ;; Y << 3
179 ret long %tmp.8
180 }
181
182 int %test26(int %A, int %B) {
183 %C = add int %A, %B
184 %D = sub int %C, %B
185 ret int %D
186 }
187
188 int %test27(bool %C, int %X, int %Y) {
189 %A = add int %X, %Y
190 %B = add int %Y, 123
191 %C = select bool %C, int %A, int %B ;; Fold add through select.
192 %D = sub int %C, %Y
193 ret int %D
194 }
195
196 int %test28(int %X) {
197 %Y = add int %X, 1234
198 %Z = sub int 42, %Y
199 ret int %Z
200 }
201
202 uint %test29(uint %X, uint %x) {
203 %tmp.2 = sub uint %X, %x
204 %tmp.2.mask = and uint %tmp.2, 63 ; [#uses=1]
205 %tmp.6 = add uint %tmp.2.mask, %x ; [#uses=1]
206 %tmp.7 = and uint %tmp.6, 63 ; [#uses=1]
207 %tmp.9 = and uint %tmp.2, 4294967232 ; [#uses=1]
208 %tmp.10 = or uint %tmp.7, %tmp.9 ; [#uses=1]
209 ret uint %tmp.10
210 }
211
212 long %test30(long %x) {
213 %tmp.2 = xor long %x, -9223372036854775808
180 endif: ; preds = %else, %entry
181 %b.0 = phi i32 [ 0, %entry ], [ 1, %else ] ; [#uses=1]
182 %tmp.4 = add i32 %b.0, 1 ; [#uses=1]
183 ret i32 %tmp.4
184 }
185
186 define i32 @test24(i32 %A) {
187 %B = add i32 %A, 1 ; [#uses=1]
188 %C = shl i32 %B, 1 ; [#uses=1]
189 %D = sub i32 %C, 2 ; [#uses=1]
190 ret i32 %D
191 }
192
193 define i64 @test25(i64 %Y) {
194 %tmp.4 = shl i64 %Y, 2 ; [#uses=1]
195 %tmp.12 = shl i64 %Y, 2 ; [#uses=1]
196 %tmp.8 = add i64 %tmp.4, %tmp.12 ; [#uses=1]
197 ret i64 %tmp.8
198 }
199
200 define i32 @test26(i32 %A, i32 %B) {
201 %C = add i32 %A, %B ; [#uses=1]
202 %D = sub i32 %C, %B ; [#uses=1]
203 ret i32 %D
204 }
205
206 define i32 @test27(i1 %C, i32 %X, i32 %Y) {
207 %A = add i32 %X, %Y ; [#uses=1]
208 %B = add i32 %Y, 123 ; [#uses=1]
209 ;; Fold add through select.
210 %C.upgrd.1 = select i1 %C, i32 %A, i32 %B ; [#uses=1]
211 %D = sub i32 %C.upgrd.1, %Y ; [#uses=1]
212 ret i32 %D
213 }
214
215 define i32 @test28(i32 %X) {
216 %Y = add i32 %X, 1234 ; [#uses=1]
217 %Z = sub i32 42, %Y ; [#uses=1]
218 ret i32 %Z
219 }
220
221 define i32 @test29(i32 %X, i32 %x) {
222 %tmp.2 = sub i32 %X, %x ; [#uses=2]
223 %tmp.2.mask = and i32 %tmp.2, 63 ; [#uses=1]
224 %tmp.6 = add i32 %tmp.2.mask, %x ; [#uses=1]
225 %tmp.7 = and i32 %tmp.6, 63 ; [#uses=1]
226 %tmp.9 = and i32 %tmp.2, -64 ; [#uses=1]
227 %tmp.10 = or i32 %tmp.7, %tmp.9 ; [#uses=1]
228 ret i32 %tmp.10
229 }
230
231 define i64 @test30(i64 %x) {
232 %tmp.2 = xor i64 %x, -9223372036854775808 ; [#uses=1]
214233 ;; Add of sign bit -> xor of sign bit.
215 %tmp.4 = add long %tmp.2, -9223372036854775808
216 ret long %tmp.4
217 }
218
219 int %test31(int %A) {
220 %B = add int %A, 4
221 %C = mul int %B, 5
222 %D = sub int %C, 20
223 ret int %D
224 }
225
226 int %test32(int %A) {
227 %B = add int %A, 4
228 %C = shl int %B, ubyte 2
229 %D = sub int %C, 16
230 ret int %D
231 }
232
233 ubyte %test33(ubyte %A) { ;; OR A, 1
234 %B = and ubyte %A, 254
235 %C = add ubyte %B, 1
236 ret ubyte %C
237 }
238
239 ubyte %test34(ubyte %A) {
240 %B = add ubyte %A, 64 ;; dead
241 %C = and ubyte %B, 12
242 ret ubyte %C
243 }
244
245 int %test35(int %a) { ;; -> -1
246 %tmpnot = xor int %a, -1
247 %tmp2 = add int %tmpnot, %a
248 ret int %tmp2
249 }
250
234 %tmp.4 = add i64 %tmp.2, -9223372036854775808 ; [#uses=1]
235 ret i64 %tmp.4
236 }
237
238 define i32 @test31(i32 %A) {
239 %B = add i32 %A, 4 ; [#uses=1]
240 %C = mul i32 %B, 5 ; [#uses=1]
241 %D = sub i32 %C, 20 ; [#uses=1]
242 ret i32 %D
243 }
244
245 define i32 @test32(i32 %A) {
246 %B = add i32 %A, 4 ; [#uses=1]
247 %C = shl i32 %B, 2 ; [#uses=1]
248 %D = sub i32 %C, 16 ; [#uses=1]
249 ret i32 %D
250 }
251
252 define i8 @test33(i8 %A) {
253 %B = and i8 %A, -2 ; [#uses=1]
254 %C = add i8 %B, 1 ; [#uses=1]
255 ret i8 %C
256 }
257
258 define i8 @test34(i8 %A) {
259 %B = add i8 %A, 64 ; [#uses=1]
260 %C = and i8 %B, 12 ; [#uses=1]
261 ret i8 %C
262 }
263
264 define i32 @test35(i32 %a) {
265 %tmpnot = xor i32 %a, -1 ; [#uses=1]
266 %tmp2 = add i32 %tmpnot, %a ; [#uses=1]
267 ret i32 %tmp2
268 }
269
0 ; Zero byte allocas should be deleted.
11
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
2 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
33 ; RUN: not grep alloca
44 ; END.
55
6 declare void %use(...)
7 void %test() {
8 %X = alloca [0 x int]
9 call void(...)* %use([0 x int] *%X)
10 %Y = alloca int, uint 0
11 call void(...)* %use(int* %Y)
12 %Z = alloca {}
13 call void(...)* %use({}* %Z)
14 ret void
6 declare void @use(...)
7
8 define void @test() {
9 %X = alloca [0 x i32] ; <[0 x i32]*> [#uses=1]
10 call void (...)* @use( [0 x i32]* %X )
11 %Y = alloca i32, i32 0 ; [#uses=1]
12 call void (...)* @use( i32* %Y )
13 %Z = alloca { } ; <{ }*> [#uses=1]
14 call void (...)* @use( { }* %Z )
15 ret void
1516 }
1617
17 void %test2() {
18 %A = alloca int ;; dead.
19 store int 123, int* %A
20 ret void
18 define void @test2() {
19 %A = alloca i32 ; [#uses=1]
20 store i32 123, i32* %A
21 ret void
2122 }
2223
23 void %test3() {
24 %A = alloca {int} ;; dead.
25 %B = getelementptr {int}* %A, int 0, uint 0
26 store int 123, int* %B
27 ret void
24 define void @test3() {
25 %A = alloca { i32 } ; <{ i32 }*> [#uses=1]
26 %B = getelementptr { i32 }* %A, i32 0, i32 0 ; [#uses=1]
27 store i32 123, i32* %B
28 ret void
2829 }
30
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep and | count 1
22
33 ; Should be optimized to one and.
4 bool %test1(uint %a, uint %b) {
5 %tmp1 = and uint %a, 65280
6 %tmp3 = and uint %b, 65280
7 %tmp = setne uint %tmp1, %tmp3
8 ret bool %tmp
4 define i1 @test1(i32 %a, i32 %b) {
5 %tmp1 = and i32 %a, 65280 ; [#uses=1]
6 %tmp3 = and i32 %b, 65280 ; [#uses=1]
7 %tmp = icmp ne i32 %tmp1, %tmp3 ; [#uses=1]
8 ret i1 %tmp
99 }
1010
88 ;
99 ; Which corresponds to test1.
1010
11 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
11 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
1212 ; RUN: not grep {or }
13 ; END.
1413
15 int %test1(int %X, int %Y) {
16 %A = and int %X, 7
17 %B = and int %Y, 8
18 %C = or int %A, %B
19 %D = and int %C, 7 ;; This cannot include any bits from %Y!
20 ret int %D
14 define i32 @test1(i32 %X, i32 %Y) {
15 %A = and i32 %X, 7 ; [#uses=1]
16 %B = and i32 %Y, 8 ; [#uses=1]
17 %C = or i32 %A, %B ; [#uses=1]
18 ;; This cannot include any bits from %Y!
19 %D = and i32 %C, 7 ; [#uses=1]
20 ret i32 %D
2121 }
2222
23 int %test2(int %X, ubyte %Y) {
24 %B = cast ubyte %Y to int
25 %C = or int %X, %B
26 %D = and int %C, 65536 ;; This cannot include any bits from %Y!
27 ret int %D
23 define i32 @test2(i32 %X, i8 %Y) {
24 %B = zext i8 %Y to i32 ; [#uses=1]
25 %C = or i32 %X, %B ; [#uses=1]
26 ;; This cannot include any bits from %Y!
27 %D = and i32 %C, 65536 ; [#uses=1]
28 ret i32 %D
2829 }
2930
30 int %test3(int %X, int %Y) {
31 %B = shl int %Y, ubyte 1
32 %C = or int %X, %B
33 %D = and int %C, 1 ;; This cannot include any bits from %Y!
34 ret int %D
31 define i32 @test3(i32 %X, i32 %Y) {
32 %B = shl i32 %Y, 1 ; [#uses=1]
33 %C = or i32 %X, %B ; [#uses=1]
34 ;; This cannot include any bits from %Y!
35 %D = and i32 %C, 1 ; [#uses=1]
36 ret i32 %D
3537 }
3638
37 uint %test4(uint %X, uint %Y) {
38 %B = shr uint %Y, ubyte 31
39 %C = or uint %X, %B
40 %D = and uint %C, 2 ;; This cannot include any bits from %Y!
41 ret uint %D
39 define i32 @test4(i32 %X, i32 %Y) {
40 %B = lshr i32 %Y, 31 ; [#uses=1]
41 %C = or i32 %X, %B ; [#uses=1]
42 ;; This cannot include any bits from %Y!
43 %D = and i32 %C, 2 ; [#uses=1]
44 ret i32 %D
4245 }
4346
44 int %or_test1(int %X, int %Y) {
45 %A = and int %X, 1
46 %B = or int %A, 1 ;; This cannot include any bits from X!
47 ret int %B
47 define i32 @or_test1(i32 %X, i32 %Y) {
48 %A = and i32 %X, 1 ; [#uses=1]
49 ;; This cannot include any bits from X!
50 %B = or i32 %A, 1 ; [#uses=1]
51 ret i32 %B
4852 }
4953
50 ubyte %or_test2(ubyte %X, ubyte %Y) {
51 %A = shl ubyte %X, ubyte 7
52 %B = or ubyte %A, 128 ;; This cannot include any bits from X!
53 ret ubyte %B
54 define i8 @or_test2(i8 %X, i8 %Y) {
55 %A = shl i8 %X, 7 ; [#uses=1]
56 ;; This cannot include any bits from X!
57 %B = or i8 %A, -128 ; [#uses=1]
58 ret i8 %B
5459 }
5560
0 ; This test makes sure that these instructions are properly eliminated.
11 ;
22
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | not grep and
4 ; END.
5
6 implementation
7
8 int %test1(int %A) {
9 %B = and int %A, 0 ; zero result
10 ret int %B
11 }
12
13 int %test2(int %A) {
14 %B = and int %A, -1 ; noop
15 ret int %B
16 }
17
18 bool %test3(bool %A) {
19 %B = and bool %A, false ; always = false
20 ret bool %B
21 }
22
23 bool %test4(bool %A) {
24 %B = and bool %A, true ; noop
25 ret bool %B
26 }
27
28 int %test5(int %A) {
29 %B = and int %A, %A
30 ret int %B
31 }
32
33 bool %test6(bool %A) {
34 %B = and bool %A, %A
35 ret bool %B
36 }
37
38 int %test7(int %A) { ; A & ~A == 0
39 %NotA = xor int %A, -1
40 %B = and int %A, %NotA
41 ret int %B
42 }
43
44 ubyte %test8(ubyte %A) { ; AND associates
45 %B = and ubyte %A, 3
46 %C = and ubyte %B, 4
47 ret ubyte %C
48 }
49
50 bool %test9(int %A) {
51 %B = and int %A, -2147483648 ; Test of sign bit, convert to setle %A, 0
52 %C = setne int %B, 0
53 ret bool %C
54 }
55
56 bool %test9(uint %A) {
57 %B = and uint %A, 2147483648 ; Test of sign bit, convert to setle %A, 0
58 %C = setne uint %B, 0
59 ret bool %C
60 }
61
62 uint %test10(uint %A) {
63 %B = and uint %A, 12
64 %C = xor uint %B, 15
65 %D = and uint %C, 1 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
66 ret uint %D
67 }
68
69 uint %test11(uint %A, uint* %P) {
70 %B = or uint %A, 3
71 %C = xor uint %B, 12
72 store uint %C, uint* %P ; additional use of C
73 %D = and uint %C, 3 ; %C = and uint %B, 3 --> 3
74 ret uint %D
75 }
76
77 bool %test12(uint %A, uint %B) {
78 %C1 = setlt uint %A, %B
79 %C2 = setle uint %A, %B
80 %D = and bool %C1, %C2 ; (A < B) & (A <= B) === (A < B)
81 ret bool %D
82 }
83
84 bool %test13(uint %A, uint %B) {
85 %C1 = setlt uint %A, %B
86 %C2 = setgt uint %A, %B
87 %D = and bool %C1, %C2 ; (A < B) & (A > B) === false
88 ret bool %D
89 }
90
91 bool %test14(ubyte %A) {
92 %B = and ubyte %A, 128
93 %C = setne ubyte %B, 0
94 ret bool %C
95 }
96
97 ubyte %test15(ubyte %A) {
98 %B = shr ubyte %A, ubyte 7
99 %C = and ubyte %B, 2 ; Always equals zero
100 ret ubyte %C
101 }
102
103 ubyte %test16(ubyte %A) {
104 %B = shl ubyte %A, ubyte 2
105 %C = and ubyte %B, 3
106 ret ubyte %C
107 }
108
109 sbyte %test17(sbyte %X, sbyte %Y) { ;; ~(~X & Y) --> (X | ~Y)
110 %B = xor sbyte %X, -1
111 %C = and sbyte %B, %Y
112 %D = xor sbyte %C, -1
113 ret sbyte %D
114 }
115
116 bool %test18(int %A) {
117 %B = and int %A, -128
118 %C = setne int %B, 0 ;; C >= 128
119 ret bool %C
120 }
121
122 bool %test18a(ubyte %A) {
123 %B = and ubyte %A, 254
124 %C = seteq ubyte %B, 0
125 ret bool %C
126 }
127
128 int %test19(int %A) {
129 %B = shl int %A, ubyte 3
130 %C = and int %B, -2 ;; Clearing a zero bit
131 ret int %C
132 }
133
134 ubyte %test20(ubyte %A) {
135 %C = shr ubyte %A, ubyte 7
136 %D = and ubyte %C, 1 ;; Unneeded
137 ret ubyte %D
138 }
139
140 bool %test22(int %A) {
141 %B = seteq int %A, 1
142 %C = setge int %A, 3
143 %D = and bool %B, %C ;; False
144 ret bool %D
145 }
146
147 bool %test23(int %A) {
148 %B = setgt int %A, 1
149 %C = setle int %A, 2
150 %D = and bool %B, %C ;; A == 2
151 ret bool %D
152 }
153
154 bool %test24(int %A) {
155 %B = setgt int %A, 1
156 %C = setne int %A, 2
157 %D = and bool %B, %C ;; A > 2
158 ret bool %D
159 }
160
161 bool %test25(int %A) {
162 %B = setge int %A, 50
163 %C = setlt int %A, 100
164 %D = and bool %B, %C ;; (A-50)
165 ret bool %D
166 }
167
168 bool %test26(int %A) {
169 %B = setne int %A, 50
170 %C = setne int %A, 51
171 %D = and bool %B, %C ;; (A-50) > 1
172 ret bool %D
173 }
174
175 ubyte %test27(ubyte %A) {
176 %B = and ubyte %A, 4
177 %C = sub ubyte %B, 16
178 %D = and ubyte %C, 240 ;; 0xF0
179 %E = add ubyte %D, 16
180 ret ubyte %E
181 }
182
183 int %test28(int %X) { ;; This is juse a zero extending shr.
184 %Y = shr int %X, ubyte 24 ;; Sign extend
185 %Z = and int %Y, 255 ;; Mask out sign bits
186 ret int %Z
187 }
188
189 int %test29(ubyte %X) {
190 %Y = cast ubyte %X to int
191 %Z = and int %Y, 255 ;; Zero extend makes this unneeded.
192 ret int %Z
193 }
194
195 int %test30(bool %X) {
196 %Y = cast bool %X to int
197 %Z = and int %Y, 1
198 ret int %Z
199 }
200
201 uint %test31(bool %X) {
202 %Y = cast bool %X to uint
203 %Z = shl uint %Y, ubyte 4
204 %A = and uint %Z, 16
205 ret uint %A
206 }
207
208 uint %test32(uint %In) {
209 %Y = and uint %In, 16
210 %Z = shr uint %Y, ubyte 2
211 %A = and uint %Z, 1
212 ret uint %A
213 }
214
215 uint %test33(uint %b) { ;; Code corresponding to one-bit bitfield ^1.
216 %tmp.4.mask = and uint %b, 1
217 %tmp.10 = xor uint %tmp.4.mask, 1
218 %tmp.12 = and uint %b, 4294967294
219 %tmp.13 = or uint %tmp.12, %tmp.10
220 ret uint %tmp.13
221 }
222
223 int %test34(int %A, int %B) {
224 %tmp.2 = or int %B, %A
225 %tmp.4 = and int %tmp.2, %B
226 ret int %tmp.4
227 }
228
3 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep and
4
5 define i32 @test1(i32 %A) {
6 ; zero result
7 %B = and i32 %A, 0 ; [#uses=1]
8 ret i32 %B
9 }
10
11 define i32 @test2(i32 %A) {
12 ; noop
13 %B = and i32 %A, -1 ; [#uses=1]
14 ret i32 %B
15 }
16
17 define i1 @test3(i1 %A) {
18 ; always = false
19 %B = and i1 %A, false ; [#uses=1]
20 ret i1 %B
21 }
22
23 define i1 @test4(i1 %A) {
24 ; noop
25 %B = and i1 %A, true ; [#uses=1]
26 ret i1 %B
27 }
28
29 define i32 @test5(i32 %A) {
30 %B = and i32 %A, %A ; [#uses=1]
31 ret i32 %B
32 }
33
34 define i1 @test6(i1 %A) {
35 %B = and i1 %A, %A ; [#uses=1]
36 ret i1 %B
37 }
38
39 ; A & ~A == 0
40 define i32 @test7(i32 %A) {
41 %NotA = xor i32 %A, -1 ; [#uses=1]
42 %B = and i32 %A, %NotA ; [#uses=1]
43 ret i32 %B
44 }
45
46 ; AND associates
47 define i8 @test8(i8 %A) {
48 %B = and i8 %A, 3 ; [#uses=1]
49 %C = and i8 %B, 4 ; [#uses=1]
50 ret i8 %C
51 }
52
53 define i1 @test9(i32 %A) {
54 ; Test of sign bit, convert to setle %A, 0
55 %B = and i32 %A, -2147483648 ; [#uses=1]
56 %C = icmp ne i32 %B, 0 ; [#uses=1]
57 ret i1 %C
58 }
59
60 define i1 @test9a(i32 %A) {
61 ; Test of sign bit, convert to setle %A, 0
62 %B = and i32 %A, -2147483648 ; [#uses=1]
63 %C = icmp ne i32 %B, 0 ; [#uses=1]
64 ret i1 %C
65 }
66
67 define i32 @test10(i32 %A) {
68 %B = and i32 %A, 12 ; [#uses=1]
69 %C = xor i32 %B, 15 ; [#uses=1]
70 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
71 %D = and i32 %C, 1 ; [#uses=1]
72 ret i32 %D
73 }
74
75 define i32 @test11(i32 %A, i32* %P) {
76 %B = or i32 %A, 3 ; [#uses=1]
77 %C = xor i32 %B, 12 ; [#uses=2]
78 ; additional use of C
79 store i32 %C, i32* %P
80 ; %C = and uint %B, 3 --> 3
81 %D = and i32 %C, 3 ; [#uses=1]
82 ret i32 %D
83 }
84
85 define i1 @test12(i32 %A, i32 %B) {
86 %C1 = icmp ult i32 %A, %B ; [#uses=1]
87 %C2 = icmp ule i32 %A, %B ; [#uses=1]
88 ; (A < B) & (A <= B) === (A < B)
89 %D = and i1 %C1, %C2 ; [#uses=1]
90 ret i1 %D
91 }
92
93 define i1 @test13(i32 %A, i32 %B) {
94 %C1 = icmp ult i32 %A, %B ; [#uses=1]
95 %C2 = icmp ugt i32 %A, %B ; [#uses=1]
96 ; (A < B) & (A > B) === false
97 %D = and i1 %C1, %C2 ; [#uses=1]
98 ret i1 %D
99 }
100
101 define i1 @test14(i8 %A) {
102 %B = and i8 %A, -128 ; [#uses=1]
103 %C = icmp ne i8 %B, 0 ; [#uses=1]
104 ret i1 %C
105 }
106
107 define i8 @test15(i8 %A) {
108 %B = lshr i8 %A, 7 ; [#uses=1]
109 ; Always equals zero
110 %C = and i8 %B, 2 ; [#uses=1]
111 ret i8 %C
112 }
113
114 define i8 @test16(i8 %A) {
115 %B = shl i8 %A, 2 ; [#uses=1]
116 %C = and i8 %B, 3 ; [#uses=1]
117 ret i8 %C
118 }
119
120 ;; ~(~X & Y) --> (X | ~Y)
121 define i8 @test17(i8 %X, i8 %Y) {
122 %B = xor i8 %X, -1 ; [#uses=1]
123 %C = and i8 %B, %Y ; [#uses=1]
124 %D = xor i8 %C, -1 ; [#uses=1]
125 ret i8 %D
126 }
127
128 define i1 @test18(i32 %A) {
129 %B = and i32 %A, -128 ; [#uses=1]
130 ;; C >= 128
131 %C = icmp ne i32 %B, 0 ; [#uses=1]
132 ret i1 %C
133 }
134
135 define i1 @test18a(i8 %A) {
136 %B = and i8 %A, -2 ; [#uses=1]
137 %C = icmp eq i8 %B, 0 ; [#uses=1]
138 ret i1 %C
139 }
140
141 define i32 @test19(i32 %A) {
142 %B = shl i32 %A, 3 ; [#uses=1]
143 ;; Clearing a zero bit
144 %C = and i32 %B, -2 ; [#uses=1]
145 ret i32 %C
146 }
147
148 define i8 @test20(i8 %A) {
149 %C = lshr i8 %A, 7 ; [#uses=1]
150 ;; Unneeded
151 %D = and i8 %C, 1 ; [#uses=1]
152 ret i8 %D
153 }
154
155 define i1 @test22(i32 %A) {
156 %B = icmp eq i32 %A, 1 ; [#uses=1]
157 %C = icmp sge i32 %A, 3 ; [#uses=1]
158 ;; false
159 %D = and i1 %B, %C ; [#uses=1]
160 ret i1 %D
161 }
162
163 define i1 @test23(i32 %A) {
164 %B = icmp sgt i32 %A, 1 ; [#uses=1]
165 %C = icmp sle i32 %A, 2 ; [#uses=1]
166 ;; A == 2
167 %D = and i1 %B, %C ; [#uses=1]
168 ret i1 %D
169 }
170
171 define i1 @test24(i32 %A) {
172 %B = icmp sgt i32 %A, 1 ; [#uses=1]
173 %C = icmp ne i32 %A, 2 ; [#uses=1]
174 ;; A > 2
175 %D = and i1 %B, %C ; [#uses=1]
176 ret i1 %D
177 }
178
179 define i1 @test25(i32 %A) {
180 %B = icmp sge i32 %A, 50 ; [#uses=1]
181 %C = icmp slt i32 %A, 100 ; [#uses=1]
182 ;; (A-50)
183 %D = and i1 %B, %C ; [#uses=1]
184 ret i1 %D
185 }
186
187 define i1 @test26(i32 %A) {
188 %B = icmp ne i32 %A, 50 ; [#uses=1]
189 %C = icmp ne i32 %A, 51 ; [#uses=1]
190 ;; (A-50) > 1
191 %D = and i1 %B, %C ; [#uses=1]
192 ret i1 %D
193 }
194
195 define i8 @test27(i8 %A) {
196 %B = and i8 %A, 4 ; [#uses=1]
197 %C = sub i8 %B, 16 ; [#uses=1]
198 ;; 0xF0
199 %D = and i8 %C, -16 ; [#uses=1]
200 %E = add i8 %D, 16 ; [#uses=1]
201 ret i8 %E
202 }
203
204 ;; This is juse a zero extending shr.
205 define i32 @test28(i32 %X) {
206 ;; Sign extend
207 %Y = ashr i32 %X, 24 ; [#uses=1]
208 ;; Mask out sign bits
209 %Z = and i32 %Y, 255 ; [#uses=1]
210 ret i32 %Z
211 }
212
213 define i32 @test29(i8 %X) {
214 %Y = zext i8 %X to i32 ; [#uses=1]
215 ;; Zero extend makes this unneeded.
216 %Z = and i32 %Y, 255 ; [#uses=1]
217 ret i32 %Z
218 }
219
220 define i32 @test30(i1 %X) {
221 %Y = zext i1 %X to i32 ; [#uses=1]
222 %Z = and i32 %Y, 1 ; [#uses=1]
223 ret i32 %Z
224 }
225
226 define i32 @test31(i1 %X) {
227 %Y = zext i1 %X to i32 ; [#uses=1]
228 %Z = shl i32 %Y, 4 ; [#uses=1]
229 %A = and i32 %Z, 16 ; [#uses=1]
230 ret i32 %A
231 }
232
233 define i32 @test32(i32 %In) {
234 %Y = and i32 %In, 16 ; [#uses=1]
235 %Z = lshr i32 %Y, 2 ; [#uses=1]
236 %A = and i32 %Z, 1 ; [#uses=1]
237 ret i32 %A
238 }
239
240 ;; Code corresponding to one-bit bitfield ^1.
241 define i32 @test33(i32 %b) {
242 %tmp.4.mask = and i32 %b, 1 ; [#uses=1]
243 %tmp.10 = xor i32 %tmp.4.mask, 1 ; [#uses=1]
244 %tmp.12 = and i32 %b, -2 ; [#uses=1]
245 %tmp.13 = or i32 %tmp.12, %tmp.10 ; [#uses=1]
246 ret i32 %tmp.13
247 }
248
249 define i32 @test34(i32 %A, i32 %B) {
250 %tmp.2 = or i32 %B, %A ; [#uses=1]
251 %tmp.4 = and i32 %tmp.2, %B ; [#uses=1]
252 ret i32 %tmp.4
253 }
254
0 ; This file contains various testcases that require tracking whether bits are
11 ; set or cleared by various instructions.
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -instcombine | llvm-dis |\
2 ; RUN: llvm-as < %s | opt -instcombine -instcombine | llvm-dis |\
33 ; RUN: not grep %ELIM
44
55 ; Reduce down to a single XOR
6 int %test3(int %B) {
7 %ELIMinc = and int %B, 1
8 %tmp.5 = xor int %ELIMinc, 1
9 %ELIM7 = and int %B, -2
10 %tmp.8 = or int %tmp.5, %ELIM7
11 ret int %tmp.8
6 define i32 @test3(i32 %B) {
7 %ELIMinc = and i32 %B, 1 ; [#uses=1]
8 %tmp.5 = xor i32 %ELIMinc, 1 ; [#uses=1]
9 %ELIM7 = and i32 %B, -2 ; [#uses=1]
10 %tmp.8 = or i32 %tmp.5, %ELIM7 ; [#uses=1]
11 ret i32 %tmp.8
1212 }
1313
1414 ; Finally, a bigger case where we chain things together. This corresponds to
1515 ; incrementing a single-bit bitfield, which should become just an xor.
16 int %test4(int %B) {
17 %ELIM3 = shl int %B, ubyte 31
18 %ELIM4 = shr int %ELIM3, ubyte 31
19 %inc = add int %ELIM4, 1
20 %ELIM5 = and int %inc, 1
21 %ELIM7 = and int %B, -2
22 %tmp.8 = or int %ELIM5, %ELIM7
23 ret int %tmp.8
16 define i32 @test4(i32 %B) {
17 %ELIM3 = shl i32 %B, 31 ; [#uses=1]
18 %ELIM4 = ashr i32 %ELIM3, 31 ; [#uses=1]
19 %inc = add i32 %ELIM4, 1 ; [#uses=1]
20 %ELIM5 = and i32 %inc, 1 ; [#uses=1]
21 %ELIM7 = and i32 %B, -2 ; [#uses=1]
22 %tmp.8 = or i32 %ELIM5, %ELIM7 ; [#uses=1]
23 ret i32 %tmp.8
2424 }
2525
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -simplifycfg | llvm-dis |\
0 ; RUN: llvm-as < %s | opt -instcombine -simplifycfg | llvm-dis |\
11 ; RUN: not grep {call void %abort}
22
3 %b_rec.0 = external global int
3 @b_rec.0 = external global i32 ; [#uses=2]
44
5 void %_Z12h000007_testv(uint *%P) {
5 define void @_Z12h000007_testv(i32* %P) {
66 entry:
7 %tmp.2 = load int* %b_rec.0 ; [#uses=1]
8 %tmp.9 = or int %tmp.2, -989855744 ; [#uses=2]
9 %tmp.16 = and int %tmp.9, -805306369 ; [#uses=2]
10 %tmp.17 = and int %tmp.9, -973078529 ; [#uses=1]
11 store int %tmp.17, int* %b_rec.0
12 %tmp.17.shrunk = cast int %tmp.16 to uint ; [#uses=1]
13 %tmp.22 = and uint %tmp.17.shrunk, 3221225472 ; [#uses=1]
14 %tmp.23 = seteq uint %tmp.22, 3221225472 ; [#uses=1]
15 br bool %tmp.23, label %endif.0, label %then.0
7 %tmp.2 = load i32* @b_rec.0 ; [#uses=1]
8 %tmp.9 = or i32 %tmp.2, -989855744 ; [#uses=2]
9 %tmp.16 = and i32 %tmp.9, -805306369 ; [#uses=2]
10 %tmp.17 = and i32 %tmp.9, -973078529 ; [#uses=1]
11 store i32 %tmp.17, i32* @b_rec.0
12 %tmp.17.shrunk = bitcast i32 %tmp.16 to i32 ; [#uses=1]
13 %tmp.22 = and i32 %tmp.17.shrunk, -1073741824 ; [#uses=1]
14 %tmp.23 = icmp eq i32 %tmp.22, -1073741824 ; [#uses=1]
15 br i1 %tmp.23, label %endif.0, label %then.0
1616
1717 then.0: ; preds = %entry
18 tail call void %abort( )
18 tail call void @abort( )
1919 unreachable
2020
2121 endif.0: ; preds = %entry
22 %tmp.17.shrunk2 = cast int %tmp.16 to uint ; [#uses=1]
23 %tmp.27.mask = and uint %tmp.17.shrunk2, 100663295 ; [#uses=1]
24 store uint %tmp.27.mask, uint* %P
22 %tmp.17.shrunk2 = bitcast i32 %tmp.16 to i32 ; [#uses=1]
23 %tmp.27.mask = and i32 %tmp.17.shrunk2, 100663295 ; [#uses=1]
24 store i32 %tmp.27.mask, i32* %P
2525 ret void
2626 }
2727
28 declare void %abort()
28 declare void @abort()
29
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep ret | count 3
2 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
2 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
33 ; RUN: not grep call.*bswap
44
5 bool %test1(ushort %tmp2) {
6 %tmp10 = call ushort %llvm.bswap.i16( ushort %tmp2 )
7 %tmp = seteq ushort %tmp10, 1
8 ret bool %tmp
5 define i1 @test1(i16 %tmp2) {
6 %tmp10 = call i16 @llvm.bswap.i16( i16 %tmp2 ) ; [#uses=1]
7 %tmp = icmp eq i16 %tmp10, 1 ; [#uses=1]
8 ret i1 %tmp
99 }
1010
11 bool %test2(uint %tmp) {
12 %tmp34 = tail call uint %llvm.bswap.i32( uint %tmp )
13 %tmp = seteq uint %tmp34, 1
14 ret bool %tmp
11 define i1 @test2(i32 %tmp) {
12 %tmp34 = tail call i32 @llvm.bswap.i32( i32 %tmp ) ; [#uses=1]
13 %tmp.upgrd.1 = icmp eq i32 %tmp34, 1 ; [#uses=1]
14 ret i1 %tmp.upgrd.1
1515 }
1616
17 declare uint %llvm.bswap.i32(uint)
17 declare i32 @llvm.bswap.i32(i32)
1818
19 bool %test3(ulong %tmp) {
20 %tmp34 = tail call ulong %llvm.bswap.i64( ulong %tmp )
21 %tmp = seteq ulong %tmp34, 1
22 ret bool %tmp
19 define i1 @test3(i64 %tmp) {
20 %tmp34 = tail call i64 @llvm.bswap.i64( i64 %tmp ) ; [#uses=1]
21 %tmp.upgrd.2 = icmp eq i64 %tmp34, 1 ; [#uses=1]
22 ret i1 %tmp.upgrd.2
2323 }
2424
25 declare ulong %llvm.bswap.i64(ulong)
25 declare i64 @llvm.bswap.i64(i64)
2626
27 declare ushort %llvm.bswap.i16(ushort)
27 declare i16 @llvm.bswap.i16(i16)
28
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep {call.*llvm.bswap} | count 5
2 ; END.
32
4 uint %test1(uint %i) {
5 %tmp1 = shr uint %i, ubyte 24 ; [#uses=1]
6 %tmp3 = shr uint %i, ubyte 8 ; [#uses=1]
7 %tmp4 = and uint %tmp3, 65280 ; [#uses=1]
8 %tmp5 = or uint %tmp1, %tmp4 ; [#uses=1]
9 %tmp7 = shl uint %i, ubyte 8 ; [#uses=1]
10 %tmp8 = and uint %tmp7, 16711680 ; [#uses=1]
11 %tmp9 = or uint %tmp5, %tmp8 ; [#uses=1]
12 %tmp11 = shl uint %i, ubyte 24 ; [#uses=1]
13 %tmp12 = or uint %tmp9, %tmp11 ; [#uses=1]
14 ret uint %tmp12
3 define i32 @test1(i32 %i) {
4 %tmp1 = lshr i32 %i, 24 ; [#uses=1]
5 %tmp3 = lshr i32 %i, 8 ; [#uses=1]
6 %tmp4 = and i32 %tmp3, 65280 ; [#uses=1]
7 %tmp5 = or i32 %tmp1, %tmp4 ; [#uses=1]
8 %tmp7 = shl i32 %i, 8 ; [#uses=1]
9 %tmp8 = and i32 %tmp7, 16711680 ; [#uses=1]
10 %tmp9 = or i32 %tmp5, %tmp8 ; [#uses=1]
11 %tmp11 = shl i32 %i, 24 ; [#uses=1]
12 %tmp12 = or i32 %tmp9, %tmp11 ; [#uses=1]
13 ret i32 %tmp12
1514 }
1615
17 uint %test2(uint %arg) {
18 %tmp2 = shl uint %arg, ubyte 24 ; [#uses=1]
19 %tmp4 = shl uint %arg, ubyte 8 ; [#uses=1]
20 %tmp5 = and uint %tmp4, 16711680 ; [#uses=1]
21 %tmp6 = or uint %tmp2, %tmp5 ; [#uses=1]
22 %tmp8 = shr uint %arg, ubyte 8 ; [#uses=1]
23 %tmp9 = and uint %tmp8, 65280 ; [#uses=1]
24 %tmp10 = or uint %tmp6, %tmp9 ; [#uses=1]
25 %tmp12 = shr uint %arg, ubyte 24 ; [#uses=1]
26 %tmp14 = or uint %tmp10, %tmp12 ; [#uses=1]
27 ret uint %tmp14
16 define i32 @test2(i32 %arg) {
17 %tmp2 = shl i32 %arg, 24 ; [#uses=1]
18 %tmp4 = shl i32 %arg, 8 ; [#uses=1]
19 %tmp5 = and i32 %tmp4, 16711680 ; [#uses=1]
20 %tmp6 = or i32 %tmp2, %tmp5 ; [#uses=1]
21 %tmp8 = lshr i32 %arg, 8 ; [#uses=1]
22 %tmp9 = and i32 %tmp8, 65280 ; [#uses=1]
23 %tmp10 = or i32 %tmp6, %tmp9 ; [#uses=1]
24 %tmp12 = lshr i32 %arg, 24 ; [#uses=1]
25 %tmp14 = or i32 %tmp10, %tmp12 ; [#uses=1]
26 ret i32 %tmp14
2827 }
2928
30 ushort %test3(ushort %s) {
31 %tmp2 = shr ushort %s, ubyte 8
32 %tmp4 = shl ushort %s, ubyte 8
33 %tmp5 = or ushort %tmp2, %tmp4
34 ret ushort %tmp5
29 define i16 @test3(i16 %s) {
30 %tmp2 = lshr i16 %s, 8 ; [#uses=1]
31 %tmp4 = shl i16 %s, 8 ; [#uses=1]
32 %tmp5 = or i16 %tmp2, %tmp4 ; [#uses=1]
33 ret i16 %tmp5
3534 }
3635
37 ushort %test4(ushort %s) {
38 %tmp2 = shr ushort %s, ubyte 8
39 %tmp4 = shl ushort %s, ubyte 8
40 %tmp5 = or ushort %tmp4, %tmp2
41 ret ushort %tmp5
36 define i16 @test4(i16 %s) {
37 %tmp2 = lshr i16 %s, 8 ; [#uses=1]
38 %tmp4 = shl i16 %s, 8 ; [#uses=1]
39 %tmp5 = or i16 %tmp4, %tmp2 ; [#uses=1]
40 ret i16 %tmp5
4241 }
4342
44 ; unsigned short test5(unsigned short a) {
45 ; return ((a & 0xff00) >> 8 | (a & 0x00ff) << 8);
46 ;}
47 ushort %test5(ushort %a) {
48 %tmp = zext ushort %a to int
49 %tmp1 = and int %tmp, 65280
50 %tmp2 = ashr int %tmp1, ubyte 8
51 %tmp2 = trunc int %tmp2 to short
52 %tmp4 = and int %tmp, 255
53 %tmp5 = shl int %tmp4, ubyte 8
54 %tmp5 = trunc int %tmp5 to short
55 %tmp = or short %tmp2, %tmp5
56 %tmp6 = bitcast short %tmp to ushort
57 %tmp6 = zext ushort %tmp6 to int
58 %retval = trunc int %tmp6 to ushort
59 ret ushort %retval
43 define i16 @test5(i16 %a) {
44 %tmp = zext i16 %a to i32 ; [#uses=2]
45 %tmp1 = and i32 %tmp, 65280 ; [#uses=1]
46 %tmp2 = ashr i32 %tmp1, 8 ; [#uses=1]
47 %tmp2.upgrd.1 = trunc i32 %tmp2 to i16 ; [#uses=1]
48 %tmp4 = and i32 %tmp, 255 ; [#uses=1]
49 %tmp5 = shl i32 %tmp4, 8 ; [#uses=1]
50 %tmp5.upgrd.2 = trunc i32 %tmp5 to i16 ; [#uses=1]
51 %tmp.upgrd.3 = or i16 %tmp2.upgrd.1, %tmp5.upgrd.2 ; [#uses=1]
52 %tmp6 = bitcast i16 %tmp.upgrd.3 to i16 ; [#uses=1]
53 %tmp6.upgrd.4 = zext i16 %tmp6 to i32 ; [#uses=1]
54 %retval = trunc i32 %tmp6.upgrd.4 to i16 ; [#uses=1]
55 ret i16 %retval
6056 }
61
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: grep call | not grep bitcast
22
3 target endian = little
4 target pointersize = 32
3 target datalayout = "e-p:32:32"
54 target triple = "i686-pc-linux-gnu"
65
7 implementation ; Functions:
8
9 int %main() {
6 define i32 @main() {
107 entry:
11 %tmp = call int cast (sbyte* (int*)* %ctime to int (int*)*)( int* null )
12 ret int %tmp
8 %tmp = call i32 bitcast (i8* (i32*)* @ctime to i32 (i32*)*)( i32* null ) ; [#uses=1]
9 ret i32 %tmp
1310 }
1411
15 declare sbyte* %ctime(int*)
12 declare i8* @ctime(i32*)
13
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis
11
2 declare void %llvm.memmove.i32(sbyte*, sbyte*, uint, uint)
3 declare void %llvm.memcpy.i32(sbyte*, sbyte*, uint, uint)
4 declare void %llvm.memset.i32(sbyte*, ubyte, uint, uint)
2 @X = global i8 0 ; [#uses=3]
3 @Y = global i8 12 ; [#uses=2]
54
6 %X = global sbyte 0
7 %Y = global sbyte 12
5 declare void @llvm.memmove.i32(i8*, i8*, i32, i32)
86
9 void %zero_byte_test() {
10 ; These process zero bytes, so they are a noop.
11 call void %llvm.memmove.i32(sbyte* %X, sbyte* %Y, uint 0, uint 100)
12 call void %llvm.memcpy.i32(sbyte* %X, sbyte* %Y, uint 0, uint 100)
13 call void %llvm.memset.i32(sbyte* %X, ubyte 123, uint 0, uint 100)
14 ret void
7 declare void @llvm.memcpy.i32(i8*, i8*, i32, i32)
8
9 declare void @llvm.memset.i32(i8*, i8, i32, i32)
10
11 define void @zero_byte_test() {
12 ; These process zero bytes, so they are a noop.
13 call void @llvm.memmove.i32( i8* @X, i8* @Y, i32 0, i32 100 )
14 call void @llvm.memcpy.i32( i8* @X, i8* @Y, i32 0, i32 100 )
15 call void @llvm.memset.i32( i8* @X, i8 123, i32 0, i32 100 )
16 ret void
1517 }
1618
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
1 ; RUN: not grep {setne\|setle\|setge}
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
1 ; RUN: not grep {icmp ne\|icmp ule\|icmp uge}
22
3 int %test1(uint %X, uint %Y) {
4 %C = setne uint %X, %Y
5 br bool %C, label %T, label %F
6 T:
7 ret int 12
8 F:
9 ret int 123
3 define i32 @test1(i32 %X, i32 %Y) {
4 %C = icmp ne i32 %X, %Y ; [#uses=1]
5 br i1 %C, label %T, label %F
6
7 T: ; preds = %0
8 ret i32 12
9
10 F: ; preds = %0
11 ret i32 123
1012 }
1113
12 int %test2(uint %X, uint %Y) {
13 %C = setle uint %X, %Y
14 br bool %C, label %T, label %F
15 T:
16 ret int 12
17 F:
18 ret int 123
14 define i32 @test2(i32 %X, i32 %Y) {
15 %C = icmp ule i32 %X, %Y ; [#uses=1]
16 br i1 %C, label %T, label %F
17
18 T: ; preds = %0
19 ret i32 12
20
21 F: ; preds = %0
22 ret i32 123
1923 }
20 int %test3(uint %X, uint %Y) {
21 %C = setge uint %X, %Y
22 br bool %C, label %T, label %F
23 T:
24 ret int 12
25 F:
26 ret int 123
24
25 define i32 @test3(i32 %X, i32 %Y) {
26 %C = icmp uge i32 %X, %Y ; [#uses=1]
27 br i1 %C, label %T, label %F
28
29 T: ; preds = %0
30 ret i32 12
31
32 F: ; preds = %0
33 ret i32 123
2734 }
35
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: not grep bitcast
22
3 bool %test1(uint %val) {
4 %t1 = bitcast uint %val to int
5 %t2 = and int %t1, 1
6 %t3 = trunc int %t2 to bool
7 ret bool %t3
3 define i1 @test1(i32 %val) {
4 %t1 = bitcast i32 %val to i32 ; [#uses=1]
5 %t2 = and i32 %t1, 1 ; [#uses=1]
6 %t3 = trunc i32 %t2 to i1 ; [#uses=1]
7 ret i1 %t3
88 }
99
10 short %test1(uint %val) {
11 %t1 = bitcast uint %val to int
12 %t2 = and int %t1, 1
13 %t3 = trunc int %t2 to short
14 ret short %t3
10 define i16 @test1.upgrd.1(i32 %val) {
11 %t1 = bitcast i32 %val to i32 ; [#uses=1]
12 %t2 = and i32 %t1, 1 ; [#uses=1]
13 %t3 = trunc i32 %t2 to i16 ; [#uses=1]
14 ret i16 %t3
1515 }
16
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
1 ; RUN: not grep ubyte
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
1 ; RUN: not grep i8
22
3 int %test1(uint %X) {
4 %Y = cast uint %X to ubyte ;; Turn into an AND
5 %Z = cast ubyte %Y to int
6 ret int %Z
3 define i32 @test1(i32 %X) {
4 %Y = trunc i32 %X to i8 ; [#uses=1]
5 %Z = zext i8 %Y to i32 ; [#uses=1]
6 ret i32 %Z
77 }
88
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -globaldce | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine -globaldce | llvm-dis | \
11 ; RUN: not grep Array
22
33 ; Pulling the cast out of the load allows us to eliminate the load, and then
44 ; the whole array.
55
6 %unop = type {int }
7 %op = type {float}
6 %op = type { float }
7 %unop = type { i32 }
8 @Array = internal constant [1 x %op* (%op*)*] [ %op* (%op*)* @foo ] ; <[1 x %op* (%op*)*]*> [#uses=1]
89
9 %Array = internal constant [1 x %op* (%op*)*] [ %op* (%op*)* %foo ]
10
11 implementation
12
13 %op* %foo(%op* %X) {
14 ret %op* %X
10 define %op* @foo(%op* %X) {
11 ret %op* %X
1512 }
1613
17 %unop* %caller(%op* %O) {
18 %tmp = load %unop* (%op*)** cast ([1 x %op* (%op*)*]* %Array to %unop* (%op*)**)
19 %tmp.2 = call %unop* (%op*)* %tmp(%op* %O)
20 ret %unop* %tmp.2
14 define %unop* @caller(%op* %O) {
15 %tmp = load %unop* (%op*)** bitcast ([1 x %op* (%op*)*]* @Array to %unop* (%op*)**); <%unop* (%op*)*> [#uses=1]
16 %tmp.2 = call %unop* %tmp( %op* %O ) ; <%unop*> [#uses=1]
17 ret %unop* %tmp.2
2118 }
2219
0 ; test that casted mallocs get converted to malloc of the right type
1 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
1 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
22 ; RUN: not grep bitcast
33
44 ; The target datalayout is important for this test case. We have to tell
55 ; instcombine that the ABI alignment for a long is 4-bytes, not 8, otherwise
66 ; it won't do the transform.
77 target datalayout = "e-i64:32:64"
8 int* %test(uint %size) {
9 %X = malloc long, uint %size
10 %ret = bitcast long* %X to int*
11 ret int* %ret
8
9 define i32* @test(i32 %size) {
10 %X = malloc i64, i32 %size ; [#uses=1]
11 %ret = bitcast i64* %X to i32* ; [#uses=1]
12 ret i32* %ret
1213 }
14
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -mem2reg | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine -mem2reg | llvm-dis | \
11 ; RUN: not grep load
22
3 int %test1(uint* %P) {
4 %A = alloca uint
5 store uint 123, uint* %A
6 %Q = cast uint* %A to int* ; Cast the result of the load not the source
7 %V = load int* %Q
8 ret int %V
3 define i32 @test1(i32* %P) {
4 %A = alloca i32 ; [#uses=2]
5 store i32 123, i32* %A
6 ; Cast the result of the load not the source
7 %Q = bitcast i32* %A to i32* ; [#uses=1]
8 %V = load i32* %Q ; [#uses=1]
9 ret i32 %V
910 }
0 ; This tests for various complex cast elimination cases instcombine should
11 ; handle.
22
3 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
3 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
44
5 bool %test1(int %X) {
6 %A = cast int %X to uint
7 %c = setne uint %A, 12 ; Convert to setne int %X, 12
8 ret bool %c
5 define i1 @test1(i32 %X) {
6 %A = bitcast i32 %X to i32 ; [#uses=1]
7 ; Convert to setne int %X, 12
8 %c = icmp ne i32 %A, 12 ; [#uses=1]
9 ret i1 %c
910 }
1011
11 bool %test2(int %X, int %Y) {
12 %A = cast int %X to uint
13 %B = cast int %Y to uint
14 %c = setne uint %A, %B ; Convert to setne int %X, %Y
15 ret bool %c
12 define i1 @test2(i32 %X, i32 %Y) {
13 %A = bitcast i32 %X to i32 ; [#uses=1]
14 %B = bitcast i32 %Y to i32 ; [#uses=1]
15 ; Convert to setne int %X, %Y
16 %c = icmp ne i32 %A, %B ; [#uses=1]
17 ret i1 %c
1618 }
1719
18 int %test4(int %A) {
19 %B = cast int %A to uint
20 %C = shl uint %B, ubyte 2
21 %D = cast uint %C to int
22 ret int %D
20 define i32 @test4(i32 %A) {
21 %B = bitcast i32 %A to i32 ; [#uses=1]
22 %C = shl i32 %B, 2 ; [#uses=1]
23 %D = bitcast i32 %C to i32 ; [#uses=1]
24 ret i32 %D
2325 }
2426
25 short %test5(short %A) {
26 %B = cast short %A to uint
27 %C = and uint %B, 15
28 %D = cast uint %C to short
29 ret short %D
27 define i16 @test5(i16 %A) {
28 %B = sext i16 %A to i32 ; [#uses=1]
29 %C = and i32 %B, 15 ; [#uses=1]
30 %D = trunc i32 %C to i16 ; [#uses=1]
31 ret i16 %D
3032 }
3133
32 bool %test6(bool %A) {
33 %B = cast bool %A to int
34 %C = setne int %B, 0
35 ret bool %C
34 define i1 @test6(i1 %A) {
35 %B = zext i1 %A to i32 ; [#uses=1]
36 %C = icmp ne i32 %B, 0 ; [#uses=1]
37 ret i1 %C
3638 }
3739
38 bool %test6a(bool %A) {
39 %B = cast bool %A to int
40 %C = setne int %B, -1 ; Always true!
41 ret bool %C
40 define i1 @test6a(i1 %A) {
41 %B = zext i1 %A to i32 ; [#uses=1]
42 %C = icmp ne i32 %B, -1 ; [#uses=1]
43 ret i1 %C
4244 }
4345
44 bool %test7(sbyte* %A) {
45 %B = cast sbyte* %A to int*
46 %C = seteq int* %B, null
47 ret bool %C
46 define i1 @test7(i8* %A) {
47 %B = bitcast i8* %A to i32* ; [#uses=1]
48 %C = icmp eq i32* %B, null ; [#uses=1]
49 ret i1 %C
4850 }
0 ; Tests to make sure elimination of casts is working correctly
1 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | notcast
1 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | notcast
22
3 target pointersize = 32
3 target datalayout = "p:32:32"
44
5 implementation
6
7 sbyte* %test1(sbyte* %t) {
8 %tmpc = cast sbyte* %t to uint
9 %tmpa = add uint %tmpc, 32
10 %tv = cast uint %tmpa to sbyte*
11 ret sbyte* %tv
5 define i8* @test1(i8* %t) {
6 %tmpc = ptrtoint i8* %t to i32 ; [#uses=1]
7 %tmpa = add i32 %tmpc, 32 ; [#uses=1]
8 %tv = inttoptr i32 %tmpa to i8* ; [#uses=1]
9 ret i8* %tv
1210 }
1311
14 bool %test2(sbyte* %a, sbyte* %b) {
15 %tmpa = cast sbyte* %a to uint
16 %tmpb = cast sbyte* %b to uint
17 %r = seteq uint %tmpa, %tmpb
18 ret bool %r
12 define i1 @test2(i8* %a, i8* %b) {
13 %tmpa = ptrtoint i8* %a to i32 ; [#uses=1]
14 %tmpb = ptrtoint i8* %b to i32 ; [#uses=1]
15 %r = icmp eq i32 %tmpa, %tmpb ; [#uses=1]
16 ret i1 %r
1917 }
18
0 ; Test some floating point casting cases
1 ; RUN: llvm-upgrade %s -o - | llvm-as | opt -instcombine | llvm-dis | notcast
2 ; RUN: llvm-upgrade %s -o - | llvm-as | opt -instcombine | llvm-dis | \
1 ; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | notcast
2 ; RUN: llvm-as %s -o - | opt -instcombine | llvm-dis | \
33 ; RUN: egrep {ret i8 \(-1\)\|\(255\)}
44
5 sbyte %test1() {
6 %x = fptoui float 255.0 to sbyte
7 ret sbyte %x
5 define i8 @test1() {
6 %x = fptoui float 2.550000e+02 to i8 ; [#uses=1]
7 ret i8 %x
88 }
99
10 ubyte %test2() {
11 %x = fptosi float -1.0 to ubyte
12 ret ubyte %x
10 define i8 @test2() {
11 %x = fptosi float -1.000000e+00 to i8 ; [#uses=1]
12 ret i8 %x
1313 }
14
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: not grep getelementptr
2 ; END.
32
4 bool %test1(short* %P, int %I, int %J) {
5 %X = getelementptr short* %P, int %I
6 %Y = getelementptr short* %P, int %J
7
8 %C = setlt short* %X, %Y
9 ret bool %C
3 define i1 @test1(i16* %P, i32 %I, i32 %J) {
4 %X = getelementptr i16* %P, i32 %I ; [#uses=1]
5 %Y = getelementptr i16* %P, i32 %J ; [#uses=1]
6 %C = icmp ult i16* %X, %Y ; [#uses=1]
7 ret i1 %C
108 }
119
12 bool %test2(short* %P, int %I) {
13 %X = getelementptr short* %P, int %I
14
15 %C = setlt short* %X, %P
16 ret bool %C
10 define i1 @test2(i16* %P, i32 %I) {
11 %X = getelementptr i16* %P, i32 %I ; [#uses=1]
12 %C = icmp ult i16* %X, %P ; [#uses=1]
13 ret i1 %C
1714 }
1815
19 int %test3(int* %P, int %A, int %B) {
20 %tmp.4 = getelementptr int* %P, int %A ; [#uses=1]
21 %tmp.9 = getelementptr int* %P, int %B ; [#uses=1]
22 %tmp.10 = seteq int* %tmp.4, %tmp.9 ; [#uses=1]
23 %tmp.11 = cast bool %tmp.10 to int ; [#uses=1]
24 ret int %tmp.11
16 define i32 @test3(i32* %P, i32 %A, i32 %B) {
17 %tmp.4 = getelementptr i32* %P, i32 %A ; [#uses=1]
18 %tmp.9 = getelementptr i32* %P, i32 %B ; [#uses=1]
19 %tmp.10 = icmp eq i32* %tmp.4, %tmp.9 ; [#uses=1]
20 %tmp.11 = zext i1 %tmp.10 to i32 ; [#uses=1]
21 ret i32 %tmp.11
2522 }
2623
27 int %test4(int* %P, int %A, int %B) {
28 %tmp.4 = getelementptr int* %P, int %A ; [#uses=1]
29 %tmp.6 = seteq int* %tmp.4, %P ; [#uses=1]
30 %tmp.7 = cast bool %tmp.6 to int ; [#uses=1]
31 ret int %tmp.7
24 define i32 @test4(i32* %P, i32 %A, i32 %B) {
25 %tmp.4 = getelementptr i32* %P, i32 %A ; [#uses=1]
26 %tmp.6 = icmp eq i32* %tmp.4, %P ; [#uses=1]
27 %tmp.7 = zext i1 %tmp.6 to i32 ; [#uses=1]
28 ret i32 %tmp.7
3229 }
3330
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: notcast {} {getelementptr.*}
22
3 %G = external global [3 x sbyte]
3 @G = external global [3 x i8] ; <[3 x i8]*> [#uses=1]
44
5 implementation
5 define i8* @foo(i32 %Idx) {
6 %gep.upgrd.1 = zext i32 %Idx to i64 ; [#uses=1]
7 %tmp = getelementptr i8* getelementptr ([3 x i8]* @G, i32 0, i32 0), i64 %gep.upgrd.1 ; [#uses=1]
8 ret i8* %tmp
9 }
610
7 ubyte *%foo(uint %Idx) {
8 %tmp = getelementptr ubyte* cast ([3 x sbyte]* %G to ubyte*), uint %Idx
9 ret ubyte* %tmp
10 }
0 ; Test folding of constantexpr geps into normal geps.
1 ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine -gcse -instcombine | \
1 ; RUN: llvm-as < %s | opt -instcombine -gcse -instcombine | \
22 ; RUN: llvm-dis | not grep getelementptr
33
4 %Array = external global [40 x int]
4 @Array = external global [40 x i32] ; <[40 x i32]*> [#uses=2]
55
6 int %test(long %X) {
7 %A = getelementptr int* getelementptr ([40 x int]* %Array, long 0, long 0), long %X
8 %B = getelementptr [40 x int]* %Array, long 0, long %X
9 %a = cast int* %A to int
10 %b = cast int* %B to int
11 %c = sub int %a, %b
12 ret int %c
6 define i32 @test(i64 %X) {
7 %A = getelementptr i32* getelementptr ([40 x i32]* @Array, i64 0, i64 0), i64 %X ; [#uses=1]
8 %B = getelementptr [40 x i32]* @Array, i64 0, i64 %X ; [#uses=1]
9 %a = ptrtoint i32* %A to i32 ; [#uses=1]
10 %b = ptrtoint i32* %B to i32 ; [#uses=1]
11 %c = sub i32 %a, %b ; [#uses=1]
12 ret i32 %c
1313 }
14
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | grep trunc
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep trunc
11
2 target endian = little
3 target pointersize = 32
2 target datalayout = "e-p:32:32"
43
5 int* %test(int* %X, long %Idx) {
6 ; Should insert a cast to int on this target
7 %R = getelementptr int* %X, long %Idx
8 ret int* %R
4 define i32* @test(i32* %X, i64 %Idx) {
5 %R = getelementptr i32* %X, i64 %Idx ; [#uses=1]
6 ret i32* %R
97 }
8
None ; RUN: llvm-upgrade < %s | llvm-as | opt -instcombine | llvm-dis | \
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: %prcontext div 1 | grep then:
22
33 ;; This tests that the div is hoisted into the then block.
4 define i32 @foo(i1 %C, i32 %A, i32 %B) {
5 entry:
6 br i1 %C, label %then, label %endif
47
5 int %foo(bool %C, int %A, int %B) {
6 entry:
7 br bool %C, label %then, label %endif
8 then: ; preds = %entry
9 br label %endif
810
9 then:
10 br label %endif
11 endif: ; preds = %then, %entry
12 %X = phi i32 [ %A, %then ], [ 15, %entry ] ; [#uses=1]
13 %Y = sdiv i32 %X, 42 ; [#uses=1]
14 ret i32 %Y
15 }
1116
12 endif:
13 %X = phi int [%A, %then], [15, %entry]
14 %Y = div int %X, 42
15 ret int %Y
16 }
0 ; This test makes sure that these instructions are properly eliminated.
11 ;
22 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep icmp
3 ; END.
34
45 @X = external global i32 ; [#uses=2]
56
22 ; been when a setcc is used with two casts.
33 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
44 ; RUN: not grep {br bool false}
5 ; END.
56
67 define i32 @bug(i8 %inbuff) {
78 entry:
33 ;
44 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
55 ; RUN: grep -v {icmp eq} | grep -v {icmp ne} | not grep icmp
6
6 ; END.
77
88 define i1 @test1(i32 %A) {
99 ; setne %A, 0
0 ; This test makes sure that these instructions are properly eliminated.
11 ;
22 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep sh
3 ; END.
34
45 define i32 @test1(i32 %A) {
56 %B = shl i32 %A, 0 ; [#uses=1]
0 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
11 ; RUN: not grep {(and\|xor\|add\|shl\|shr)}
2 ; END.
23
34 define i32 @test1(i32 %x) {
45 %tmp.1 = and i32 %x, 65535 ; [#uses=1]
33 ; RUN: not grep insertelement
44 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
55 ; RUN: not grep extractelement
6 ; END.
67
78 define <4 x float> @test(<4 x float> %tmp, <4 x float> %tmp1) {
89 %tmp4 = extractelement <4 x float> %tmp, i32 1 ; [#uses=1]
11 ;
22 ; RUN: llvm-as < %s | opt -instcombine | llvm-dis | \
33 ; RUN: not grep {xor }
4 ; END.
45 @G1 = global i32 0 ; [#uses=1]
56 @G2 = global i32 0 ; [#uses=1]
67