blob: fdcbd02578050e98d4fbd972aee448b5bfbcbe89 [file] [log] [blame]
Chris Lattner97555b52002-05-06 05:35:20 +00001; This test makes sure that div instructions are properly eliminated.
2;
3
Misha Brukmane78760e2003-09-16 15:29:54 +00004; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep div
Chris Lattner97555b52002-05-06 05:35:20 +00005
6implementation
7
Chris Lattner07928ef2003-02-18 19:16:45 +00008int %test1(int %A) {
Chris Lattner97555b52002-05-06 05:35:20 +00009 %B = div int %A, 1
10 ret int %B
Chris Lattner07928ef2003-02-18 19:16:45 +000011}
Chris Lattner5640f332003-02-18 19:28:47 +000012
13uint %test2(uint %A) {
14 %B = div uint %A, 8 ; => Shift
Chris Lattnerdb058582004-04-26 14:01:47 +000015 ret uint %B
Chris Lattner5640f332003-02-18 19:28:47 +000016}
17
18int %test3(int %A) {
19 %B = div int 0, %A ; => 0, don't need to keep traps
20 ret int %B
21}
Chris Lattnerdb058582004-04-26 14:01:47 +000022
23int %test4(int %A) {
24 %B = div int %A, -1 ; 0-A
25 ret int %B
26}
Chris Lattner46c4dcd2004-09-28 18:21:01 +000027
28uint %test5(uint %A) {
29 %B = div uint %A, 4294967280
30 %C = div uint %B, 4294967292
31 ret uint %C
32}
Chris Lattnera2393502004-09-29 17:37:07 +000033
34bool %test6(uint %A) {
35 %B = div uint %A, 123
36 %C = seteq uint %B, 0 ; A < 123
37 ret bool %C
38}
39
40bool %test7(uint %A) {
41 %B = div uint %A, 10
42 %C = seteq uint %B, 2 ; A >= 20 && A < 30
43 ret bool %C
44}
45
46bool %test8(ubyte %A) {
47 %B = div ubyte %A, 123
48 %C = seteq ubyte %B, 2 ; A >= 246
49 ret bool %C
50}
51
52bool %test9(ubyte %A) {
53 %B = div ubyte %A, 123
54 %C = setne ubyte %B, 2 ; A < 246
55 ret bool %C
56}
57
Chris Lattnercb8e9c92004-12-12 21:40:22 +000058uint %test10(uint %X, bool %C) {
59 %V = select bool %C, uint 64, uint 8
Reid Spencer1628cec2006-10-26 06:15:43 +000060 %R = udiv uint %X, %V
Chris Lattnercb8e9c92004-12-12 21:40:22 +000061 ret uint %R
62}
63
Reid Spencer1628cec2006-10-26 06:15:43 +000064int %test11(int %X, bool %C) {
65 %A = select bool %C, int 1024, int 32
66 %B = udiv int %X, %A
67 ret int %B
Chris Lattnerfee906b2006-02-05 07:52:47 +000068}