blob: 66a081789003f82cbfd6b0c725d45561c8d23cc3 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Chris Lattnerf6f95d02002-08-02 19:27:58 +00004; RUN: if as < %s | opt -instcombine | dis | grep sh
Chris Lattner74e95472002-05-06 05:43:36 +00005; RUN: then exit 1
6; RUN: else exit 0
7; RUN: fi
8
9implementation
10
Chris Lattner87301bc2003-03-10 18:20:53 +000011int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000012 %B = shl int %A, ubyte 0
13 ret int %B
14}
15
Chris Lattner87301bc2003-03-10 18:20:53 +000016int %test2(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000017 %B = shl int 0, ubyte %A
18 ret int %B
19}
20
Chris Lattner87301bc2003-03-10 18:20:53 +000021int %test3(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000022 %B = shr int %A, ubyte 0
23 ret int %B
24}
25
Chris Lattner87301bc2003-03-10 18:20:53 +000026int %test4(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000027 %B = shr int 0, ubyte %A
28 ret int %B
29}
30
Chris Lattner87301bc2003-03-10 18:20:53 +000031uint %test5(uint %A) {
Chris Lattnerbcb81382002-05-06 16:11:31 +000032 %B = shr uint %A, ubyte 32 ;; shift all bits out
33 ret uint %B
Chris Lattner74e95472002-05-06 05:43:36 +000034}
35
Chris Lattnerd97f0542003-03-10 19:16:20 +000036uint %test5a(uint %A) {
37 %B = shl uint %A, ubyte 32 ;; shift all bits out
38 ret uint %B
39}
40
Chris Lattner025e58d2002-09-10 23:03:10 +000041uint %test6(uint %A) {
42 %B = shl uint %A, ubyte 1 ;; convert to an add instruction
43 ret uint %B
44}
Chris Lattneree5c8a92002-10-08 16:10:35 +000045
46int %test7(ubyte %A) {
47 %B = shr int -1, ubyte %A ;; Always equal to -1
48 ret int %B
49}
Chris Lattnerd97f0542003-03-10 19:16:20 +000050
51ubyte %test8(ubyte %A) { ;; (A << 5) << 3 === A << 8 == 0
52 %B = shl ubyte %A, ubyte 5
53 %C = shl ubyte %B, ubyte 3
54 ret ubyte %C
55}
56
57ubyte %test9(ubyte %A) { ;; (A << 7) >> 7 === A & 1
58 %B = shl ubyte %A, ubyte 7
59 %C = shr ubyte %B, ubyte 7
60 ret ubyte %C
61}
62
63ubyte %test10(ubyte %A) { ;; (A >> 7) << 7 === A & 128
64 %B = shr ubyte %A, ubyte 7
65 %C = shl ubyte %B, ubyte 7
66 ret ubyte %C
67}
68
69ubyte %test11(ubyte %A) { ;; (A >> 3) << 4 == (A & 0x1F) << 1
70 %B = shr ubyte %A, ubyte 3
71 %C = shl ubyte %B, ubyte 4
72 ret ubyte %C
73}
74