1; RUN: llc < %s -mtriple=aarch64-linux-gnu -mattr=+lsl-fast | FileCheck %s
2
3%struct.a = type [256 x i16]
4%struct.b = type [256 x i32]
5%struct.c = type [256 x i64]
6
7declare void @foo()
8define i16 @halfword(%struct.a* %ctx, i32 %xor72) nounwind {
9; CHECK-LABEL: halfword:
10; CHECK: ubfx [[REG:x[0-9]+]], x1, #9, #8
11; CHECK: ldrh [[REG1:w[0-9]+]], [{{.*}}[[REG2:x[0-9]+]], [[REG]], lsl #1]
12; CHECK: mov [[REG3:x[0-9]+]], [[REG2]]
13; CHECK: strh [[REG1]], [{{.*}}[[REG3]], [[REG]], lsl #1]
14  %shr81 = lshr i32 %xor72, 9
15  %conv82 = zext i32 %shr81 to i64
16  %idxprom83 = and i64 %conv82, 255
17  %arrayidx86 = getelementptr inbounds %struct.a, %struct.a* %ctx, i64 0, i64 %idxprom83
18  %result = load i16, i16* %arrayidx86, align 2
19  call void @foo()
20  store i16 %result, i16* %arrayidx86, align 2
21  ret i16 %result
22}
23
24define i32 @word(%struct.b* %ctx, i32 %xor72) nounwind {
25; CHECK-LABEL: word:
26; CHECK: ubfx [[REG:x[0-9]+]], x1, #9, #8
27; CHECK: ldr [[REG1:w[0-9]+]], [{{.*}}[[REG2:x[0-9]+]], [[REG]], lsl #2]
28; CHECK: mov [[REG3:x[0-9]+]], [[REG2]]
29; CHECK: str [[REG1]], [{{.*}}[[REG3]], [[REG]], lsl #2]
30  %shr81 = lshr i32 %xor72, 9
31  %conv82 = zext i32 %shr81 to i64
32  %idxprom83 = and i64 %conv82, 255
33  %arrayidx86 = getelementptr inbounds %struct.b, %struct.b* %ctx, i64 0, i64 %idxprom83
34  %result = load i32, i32* %arrayidx86, align 4
35  call void @foo()
36  store i32 %result, i32* %arrayidx86, align 4
37  ret i32 %result
38}
39
40define i64 @doubleword(%struct.c* %ctx, i32 %xor72) nounwind {
41; CHECK-LABEL: doubleword:
42; CHECK: ubfx [[REG:x[0-9]+]], x1, #9, #8
43; CHECK: ldr [[REG1:x[0-9]+]], [{{.*}}[[REG2:x[0-9]+]], [[REG]], lsl #3]
44; CHECK: mov [[REG3:x[0-9]+]], [[REG2]]
45; CHECK: str [[REG1]], [{{.*}}[[REG3]], [[REG]], lsl #3]
46  %shr81 = lshr i32 %xor72, 9
47  %conv82 = zext i32 %shr81 to i64
48  %idxprom83 = and i64 %conv82, 255
49  %arrayidx86 = getelementptr inbounds %struct.c, %struct.c* %ctx, i64 0, i64 %idxprom83
50  %result = load i64, i64* %arrayidx86, align 8
51  call void @foo()
52  store i64 %result, i64* %arrayidx86, align 8
53  ret i64 %result
54}
55
56define i64 @multi_use_non_memory(i64 %a, i64 %b) {
57; CHECK-LABEL: multi_use_non_memory:
58; CHECK: lsl [[REG1:x[0-9]+]], x0, #3
59; CHECK-NOT: cmp [[REG1]], x1, lsl # 3
60; CHECK-NEXT: lsl [[REG2:x[0-9]+]], x1, #3
61; CHECK-NEXT: cmp [[REG1]], [[REG2]]
62entry:
63  %mul1 = shl i64 %a, 3
64  %mul2 = shl i64 %b, 3
65  %cmp = icmp slt i64 %mul1, %mul2
66  br i1 %cmp, label %truebb, label %falsebb
67truebb:
68  tail call void @foo()
69  unreachable
70falsebb:
71  %cmp2 = icmp sgt i64 %mul1, %mul2
72  br i1 %cmp2, label %exitbb, label %endbb
73exitbb:
74 ret i64 %mul1
75endbb:
76 ret i64 %mul2
77}
78