blob: 8e03fc02d4c5c13faee634582279968c11db851d [file] [log] [blame]
Chris Lattner8170e8f2002-05-06 05:35:20 +00001; This test makes sure that div instructions are properly eliminated.
2;
3
Misha Brukmanedf4bab2003-09-16 15:29:54 +00004; RUN: llvm-as < %s | opt -instcombine | llvm-dis | not grep div
Chris Lattner8170e8f2002-05-06 05:35:20 +00005
6implementation
7
Chris Lattner2bf6c222003-02-18 19:16:45 +00008int %test1(int %A) {
Chris Lattner8170e8f2002-05-06 05:35:20 +00009 %B = div int %A, 1
10 ret int %B
Chris Lattner2bf6c222003-02-18 19:16:45 +000011}
Chris Lattnerc5fccf32003-02-18 19:28:47 +000012
13uint %test2(uint %A) {
14 %B = div uint %A, 8 ; => Shift
Chris Lattnere24003a2004-04-26 14:01:47 +000015 ret uint %B
Chris Lattnerc5fccf32003-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 Lattnere24003a2004-04-26 14:01:47 +000022
23int %test4(int %A) {
24 %B = div int %A, -1 ; 0-A
25 ret int %B
26}
Chris Lattnercbd7a982004-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 Lattnerd9d85382004-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