1 ; Test removal of AND operations that don't affect last 6 bits of shift amount
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu | FileCheck %s
6 ; Test that AND is not removed when some lower 6 bits are not set.
7 define i32 @f1(i32 %a, i32 %sh) {
9 ; CHECK: nil{{[lf]}} %r3, 31
10 ; CHECK: sll %r2, 0(%r3)
11 %and = and i32 %sh, 31
12 %shift = shl i32 %a, %and
16 ; Test removal of AND mask with only bottom 6 bits set.
17 define i32 @f2(i32 %a, i32 %sh) {
19 ; CHECK-NOT: nil{{[lf]}} %r3, 63
20 ; CHECK: sll %r2, 0(%r3)
21 %and = and i32 %sh, 63
22 %shift = shl i32 %a, %and
26 ; Test removal of AND mask including but not limited to bottom 6 bits.
27 define i32 @f3(i32 %a, i32 %sh) {
29 ; CHECK-NOT: nil{{[lf]}} %r3, 255
30 ; CHECK: sll %r2, 0(%r3)
31 %and = and i32 %sh, 255
32 %shift = shl i32 %a, %and
36 ; Test removal of AND mask from SRA.
37 define i32 @f4(i32 %a, i32 %sh) {
39 ; CHECK-NOT: nil{{[lf]}} %r3, 63
40 ; CHECK: sra %r2, 0(%r3)
41 %and = and i32 %sh, 63
42 %shift = ashr i32 %a, %and
46 ; Test removal of AND mask from SRL.
47 define i32 @f5(i32 %a, i32 %sh) {
49 ; CHECK-NOT: nil{{[lf]}} %r3, 63
50 ; CHECK: srl %r2, 0(%r3)
51 %and = and i32 %sh, 63
52 %shift = lshr i32 %a, %and
56 ; Test removal of AND mask from SLLG.
57 define i64 @f6(i64 %a, i64 %sh) {
59 ; CHECK-NOT: nil{{[lf]}} %r3, 63
60 ; CHECK: sllg %r2, %r2, 0(%r3)
61 %and = and i64 %sh, 63
62 %shift = shl i64 %a, %and
66 ; Test removal of AND mask from SRAG.
67 define i64 @f7(i64 %a, i64 %sh) {
69 ; CHECK-NOT: nil{{[lf]}} %r3, 63
70 ; CHECK: srag %r2, %r2, 0(%r3)
71 %and = and i64 %sh, 63
72 %shift = ashr i64 %a, %and
76 ; Test removal of AND mask from SRLG.
77 define i64 @f8(i64 %a, i64 %sh) {
79 ; CHECK-NOT: nil{{[lf]}} %r3, 63
80 ; CHECK: srlg %r2, %r2, 0(%r3)
81 %and = and i64 %sh, 63
82 %shift = lshr i64 %a, %and
86 ; Test that AND with two register operands is not affected.
87 define i32 @f9(i32 %a, i32 %b, i32 %sh) {
90 ; CHECK: sll %r2, 0(%r3)
91 %and = and i32 %sh, %b
92 %shift = shl i32 %a, %and
96 ; Test that AND is not entirely removed if the result is reused.
97 define i32 @f10(i32 %a, i32 %sh) {
99 ; CHECK: sll %r2, 0(%r3)
100 ; CHECK: nil{{[lf]}} %r3, 63
102 %and = and i32 %sh, 63
103 %shift = shl i32 %a, %and
104 %reuse = add i32 %and, %shift
108 ; Test that AND is not removed for i128 (which calls __ashlti3)
109 define i128 @f11(i128 %a, i32 %sh) {
111 ; CHECK: risbg %r4, %r4, 57, 191, 0
112 ; CHECK: brasl %r14, __ashlti3@PLT
113 %and = and i32 %sh, 127
114 %ext = zext i32 %and to i128
115 %shift = shl i128 %a, %ext