blob: 7d438fb15701d7081cd3de9082d12d4b8e365a75 [file] [log] [blame]
Chris Lattner74e95472002-05-06 05:43:36 +00001; This test makes sure that these instructions are properly eliminated.
2;
3
Chris Lattner423909d2003-06-28 23:32:04 +00004; RUN: as < %s | opt -instcombine | dis | not grep sh
Chris Lattner74e95472002-05-06 05:43:36 +00005
6implementation
7
Chris Lattner87301bc2003-03-10 18:20:53 +00008int %test1(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +00009 %B = shl int %A, ubyte 0
10 ret int %B
11}
12
Chris Lattner87301bc2003-03-10 18:20:53 +000013int %test2(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000014 %B = shl int 0, ubyte %A
15 ret int %B
16}
17
Chris Lattner87301bc2003-03-10 18:20:53 +000018int %test3(int %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000019 %B = shr int %A, ubyte 0
20 ret int %B
21}
22
Chris Lattner87301bc2003-03-10 18:20:53 +000023int %test4(ubyte %A) {
Chris Lattner74e95472002-05-06 05:43:36 +000024 %B = shr int 0, ubyte %A
25 ret int %B
26}
27
Chris Lattner87301bc2003-03-10 18:20:53 +000028uint %test5(uint %A) {
Chris Lattnerbcb81382002-05-06 16:11:31 +000029 %B = shr uint %A, ubyte 32 ;; shift all bits out
30 ret uint %B
Chris Lattner74e95472002-05-06 05:43:36 +000031}
32
Chris Lattnerd97f0542003-03-10 19:16:20 +000033uint %test5a(uint %A) {
34 %B = shl uint %A, ubyte 32 ;; shift all bits out
35 ret uint %B
36}
37
Chris Lattner025e58d2002-09-10 23:03:10 +000038uint %test6(uint %A) {
39 %B = shl uint %A, ubyte 1 ;; convert to an add instruction
40 ret uint %B
41}
Chris Lattneree5c8a92002-10-08 16:10:35 +000042
43int %test7(ubyte %A) {
44 %B = shr int -1, ubyte %A ;; Always equal to -1
45 ret int %B
46}
Chris Lattnerd97f0542003-03-10 19:16:20 +000047
48ubyte %test8(ubyte %A) { ;; (A << 5) << 3 === A << 8 == 0
49 %B = shl ubyte %A, ubyte 5
50 %C = shl ubyte %B, ubyte 3
51 ret ubyte %C
52}
53
54ubyte %test9(ubyte %A) { ;; (A << 7) >> 7 === A & 1
55 %B = shl ubyte %A, ubyte 7
56 %C = shr ubyte %B, ubyte 7
57 ret ubyte %C
58}
59
60ubyte %test10(ubyte %A) { ;; (A >> 7) << 7 === A & 128
61 %B = shr ubyte %A, ubyte 7
62 %C = shl ubyte %B, ubyte 7
63 ret ubyte %C
64}
65
Chris Lattner9e2dc892003-07-24 18:38:09 +000066ubyte %test11(ubyte %A) { ;; (A >> 3) << 4 === (A & 0x1F) << 1
Chris Lattnerd97f0542003-03-10 19:16:20 +000067 %B = shr ubyte %A, ubyte 3
68 %C = shl ubyte %B, ubyte 4
69 ret ubyte %C
70}
71
Chris Lattner9e2dc892003-07-24 18:38:09 +000072int %test12(int %A) {
73 %B = shr int %A, ubyte 8 ;; (A >> 8) << 8 === A & -256
74 %C = shl int %B, ubyte 8
75 ret int %C
76}
77
78sbyte %test13(sbyte %A) { ;; (A >> 3) << 4 === (A & -8) * 2
79 %B = shr sbyte %A, ubyte 3
80 %C = shl sbyte %B, ubyte 4
81 ret sbyte %C
82}
Chris Lattner699b9522003-08-12 21:20:49 +000083
84uint %test14(uint %A) {
85 %B = shr uint %A, ubyte 4
86 %C = or uint %B, 1234
87 %D = shl uint %C, ubyte 4 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
88 ret uint %D
89}
90int %test14a(int %A) {
91 %B = shl int %A, ubyte 4
92 %C = and int %B, -1234
93 %D = shr int %C, ubyte 4 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
94 ret int %D
95}