1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2 ; RUN: llc -mtriple=arm64-apple-macosx -o - %s | FileCheck %s
4 %struct.zot = type { ptr, i32, ptr, ptr, i32, i32, i32, i32, i32, i32 }
6 ; FIXME: currently the AND is performed on 64 bit unnecessarily.
8 ; Test cases where an AND is extended from i32 -> i64 which is free. Make
9 ; sure the extends do not get moved to the arguments, which would perform the
10 ; AND on 64 bits unnecessarily.
12 define void @avoid_promotion_1_and(ptr nocapture noundef %arg, ptr %p) {
13 ; CHECK-LABEL: avoid_promotion_1_and:
14 ; CHECK: ; %bb.0: ; %bb
15 ; CHECK-NEXT: ldr w8, [x0, #52]
16 ; CHECK-NEXT: mov w9, #10 ; =0xa
17 ; CHECK-NEXT: LBB0_1: ; %bb8
18 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
19 ; CHECK-NEXT: cmp w8, #3
20 ; CHECK-NEXT: b.lo LBB0_1
21 ; CHECK-NEXT: ; %bb.2: ; %bb9
22 ; CHECK-NEXT: ; in Loop: Header=BB0_1 Depth=1
23 ; CHECK-NEXT: ldr w10, [x0, #32]
24 ; CHECK-NEXT: ldr w11, [x1, #76]
25 ; CHECK-NEXT: ldr w12, [x1]
26 ; CHECK-NEXT: eor w10, w10, w11
27 ; CHECK-NEXT: and w10, w10, w12
28 ; CHECK-NEXT: str w10, [x0, #32]
29 ; CHECK-NEXT: strh w9, [x1, w10, uxtw #1]
30 ; CHECK-NEXT: b LBB0_1
32 %gep = getelementptr inbounds %struct.zot, ptr %arg, i64 0, i32 9
33 %l = load i32, ptr %gep, align 4
34 %icmp = icmp ugt i32 %l, 2
35 %gep1 = getelementptr inbounds %struct.zot, ptr %arg, i64 0, i32 4
36 %gep2 = getelementptr inbounds %struct.zot, ptr %arg, i64 0, i32 7
39 bb8: ; preds = %bb27, %bb
40 br i1 %icmp, label %bb9, label %bb27
43 %l10 = load i32, ptr %gep1, align 8
44 %gep14 = getelementptr inbounds i32, ptr %p, i64 19
45 %l15 = load i32, ptr %gep14, align 1
46 %xor = xor i32 %l10, %l15
47 %l17 = load i32, ptr %p, align 8
48 %and = and i32 %xor, %l17
49 store i32 %and, ptr %gep1, align 8
50 %zext19 = zext i32 %and to i64
51 %gep20 = getelementptr inbounds i16, ptr %p, i64 %zext19
52 store i16 10, ptr %gep20, align 2
55 bb27: ; preds = %bb9, %bb8
59 define void @avoid_promotion_2_and(ptr nocapture noundef %arg) {
60 ; CHECK-LABEL: avoid_promotion_2_and:
61 ; CHECK: ; %bb.0: ; %entry
62 ; CHECK-NEXT: add x8, x0, #32
63 ; CHECK-NEXT: b LBB1_2
64 ; CHECK-NEXT: LBB1_1: ; %latch
65 ; CHECK-NEXT: ; in Loop: Header=BB1_2 Depth=1
66 ; CHECK-NEXT: cmp w9, #2
67 ; CHECK-NEXT: add x8, x8, #56
68 ; CHECK-NEXT: b.ls LBB1_4
69 ; CHECK-NEXT: LBB1_2: ; %loop
70 ; CHECK-NEXT: ; =>This Inner Loop Header: Depth=1
71 ; CHECK-NEXT: ldr w9, [x8, #20]
72 ; CHECK-NEXT: cmp w9, #3
73 ; CHECK-NEXT: b.lo LBB1_1
74 ; CHECK-NEXT: ; %bb.3: ; %then
75 ; CHECK-NEXT: ; in Loop: Header=BB1_2 Depth=1
76 ; CHECK-NEXT: ldp w13, w12, [x8, #12]
77 ; CHECK-NEXT: ldr w10, [x8]
78 ; CHECK-NEXT: ldr x11, [x0]
79 ; CHECK-NEXT: ldr w14, [x8, #8]
80 ; CHECK-NEXT: lsl w10, w10, w13
81 ; CHECK-NEXT: ldrb w11, [x11, x12]
82 ; CHECK-NEXT: eor w10, w10, w11
83 ; CHECK-NEXT: ldur w11, [x8, #-24]
84 ; CHECK-NEXT: and w10, w10, w14
85 ; CHECK-NEXT: ldp x14, x13, [x8, #-16]
86 ; CHECK-NEXT: str w10, [x8]
87 ; CHECK-NEXT: and w11, w11, w12
88 ; CHECK-NEXT: ldrh w15, [x13, w10, uxtw #1]
89 ; CHECK-NEXT: strh w15, [x14, w11, uxtw #1]
90 ; CHECK-NEXT: strh w12, [x13, w10, uxtw #1]
91 ; CHECK-NEXT: b LBB1_1
92 ; CHECK-NEXT: LBB1_4: ; %exit
98 %p = phi i64 [ 0, %entry ], [ %p.next, %latch ]
99 %gep = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 9
100 %l = load i32, ptr %gep, align 4
101 %icmp = icmp ugt i32 %l, 2
102 %gep1 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 4
103 %gep2 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 7
104 %gep3 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 8
105 %gep4 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 6
106 %gep5 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 3
107 %gep6 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 2
108 %gep7 = getelementptr inbounds %struct.zot, ptr %arg, i64 %p, i32 1
109 br i1 %icmp, label %then, label %latch
112 %l10 = load i32, ptr %gep1, align 8
113 %l11 = load i32, ptr %gep2, align 4
114 %shl = shl i32 %l10, %l11
115 %l12 = load ptr, ptr %arg, align 8
116 %l13 = load i32, ptr %gep3, align 8
117 %zext = zext i32 %l13 to i64
118 %gep14 = getelementptr inbounds i8, ptr %l12, i64 %zext
119 %l15 = load i8, ptr %gep14, align 1
120 %zext16 = zext i8 %l15 to i32
121 %xor = xor i32 %shl, %zext16
122 %l17 = load i32, ptr %gep4, align 8
123 %and = and i32 %xor, %l17
124 store i32 %and, ptr %gep1, align 8
125 %l18 = load ptr, ptr %gep5, align 8
126 %zext19 = zext i32 %and to i64
127 %gep20 = getelementptr inbounds i16, ptr %l18, i64 %zext19
128 %l21 = load i16, ptr %gep20, align 2
129 %l22 = load ptr, ptr %gep6, align 8
130 %l23 = load i32, ptr %gep7, align 8
131 %and24 = and i32 %l23, %l13
132 %zext25 = zext i32 %and24 to i64
133 %gep26 = getelementptr inbounds i16, ptr %l22, i64 %zext25
134 store i16 %l21, ptr %gep26, align 2
135 %trunc = trunc i32 %l13 to i16
136 store i16 %trunc, ptr %gep20, align 2
140 %p.next = add i64 %p, 1
141 br i1 %icmp, label %loop, label %exit