1 ; RUN: llc -mattr=avr6,sram < %s -march=avr -verify-machineinstrs | FileCheck %s
3 define i8 @load8(ptr %x) {
5 ; CHECK: ld r24, {{[XYZ]}}
10 define i16 @load16(ptr %x) {
11 ; CHECK-LABEL: load16:
12 ; CHECK: ld r24, [[PTR:[YZ]]]
13 ; CHECK: ldd r25, [[PTR]]+1
18 define i8 @load8disp(ptr %x) {
19 ; CHECK-LABEL: load8disp:
20 ; CHECK: ldd r24, {{[YZ]}}+63
21 %1 = getelementptr inbounds i8, ptr %x, i64 63
26 define i8 @load8nodisp(ptr %x) {
27 ; CHECK-LABEL: load8nodisp:
28 ; CHECK: movw r26, r24
29 ; CHECK: subi r26, 192
30 ; CHECK: sbci r27, 255
31 ; CHECK: ld r24, {{[XYZ]}}
32 %1 = getelementptr inbounds i8, ptr %x, i64 64
37 define i16 @load16disp(ptr %x) {
38 ; CHECK-LABEL: load16disp:
39 ; CHECK: ldd r24, [[PTR:[YZ]]]+62
40 ; CHECK: ldd r25, [[PTR]]+63
41 %1 = getelementptr inbounds i16, ptr %x, i64 31
46 define i16 @load16nodisp(ptr %x) {
47 ; CHECK-LABEL: load16nodisp:
48 ; CHECK: subi r24, 192
49 ; CHECK: sbci r25, 255
50 ; CHECK: movw r30, r24
51 ; CHECK: ld r24, [[PTR:[YZ]]]
52 ; CHECK: ldd r25, [[PTR]]+1
53 %1 = getelementptr inbounds i16, ptr %x, i64 32
58 define i8 @load8postinc(ptr %x, i8 %y) {
59 ; CHECK-LABEL: load8postinc:
60 ; CHECK: ld {{.*}}, {{[XYZ]}}+
62 %tobool6 = icmp eq i8 %y, 0
63 br i1 %tobool6, label %while.end, label %while.body
64 while.body: ; preds = %entry, %while.body
65 %r.09 = phi i8 [ %add, %while.body ], [ 0, %entry ]
66 %y.addr.08 = phi i8 [ %dec, %while.body ], [ %y, %entry ]
67 %x.addr.07 = phi ptr [ %incdec.ptr, %while.body ], [ %x, %entry ]
68 %dec = add i8 %y.addr.08, -1
69 %incdec.ptr = getelementptr inbounds i8, ptr %x.addr.07, i16 1
70 %0 = load i8, ptr %x.addr.07
71 %add = add i8 %0, %r.09
72 %tobool = icmp eq i8 %dec, 0
73 br i1 %tobool, label %while.end, label %while.body
74 while.end: ; preds = %while.body, %entry
75 %r.0.lcssa = phi i8 [ 0, %entry ], [ %add, %while.body ]
79 define i16 @load16postinc(ptr %x, i16 %y) {
80 ; CHECK-LABEL: load16postinc:
81 ; CHECK: ld {{.*}}, {{[XYZ]}}+
82 ; CHECK: ld {{.*}}, {{[XYZ]}}+
84 %tobool2 = icmp eq i16 %y, 0
85 br i1 %tobool2, label %while.end, label %while.body
86 while.body: ; preds = %entry, %while.body
87 %r.05 = phi i16 [ %add, %while.body ], [ 0, %entry ]
88 %y.addr.04 = phi i16 [ %dec, %while.body ], [ %y, %entry ]
89 %x.addr.03 = phi ptr [ %incdec.ptr, %while.body ], [ %x, %entry ]
90 %dec = add nsw i16 %y.addr.04, -1
91 %incdec.ptr = getelementptr inbounds i16, ptr %x.addr.03, i16 1
92 %0 = load i16, ptr %x.addr.03
93 %add = add nsw i16 %0, %r.05
94 %tobool = icmp eq i16 %dec, 0
95 br i1 %tobool, label %while.end, label %while.body
96 while.end: ; preds = %while.body, %entry
97 %r.0.lcssa = phi i16 [ 0, %entry ], [ %add, %while.body ]
101 define i8 @load8predec(ptr %x, i8 %y) {
102 ; CHECK-LABEL: load8predec:
103 ; CHECK: ld {{.*}}, -{{[XYZ]}}
105 %tobool6 = icmp eq i8 %y, 0
106 br i1 %tobool6, label %while.end, label %while.body
107 while.body: ; preds = %entry, %while.body
108 %r.09 = phi i8 [ %add, %while.body ], [ 0, %entry ]
109 %y.addr.08 = phi i8 [ %dec, %while.body ], [ %y, %entry ]
110 %x.addr.07 = phi ptr [ %incdec.ptr, %while.body ], [ %x, %entry ]
111 %dec = add i8 %y.addr.08, -1
112 %incdec.ptr = getelementptr inbounds i8, ptr %x.addr.07, i16 -1
113 %0 = load i8, ptr %incdec.ptr
114 %add = add i8 %0, %r.09
115 %tobool = icmp eq i8 %dec, 0
116 br i1 %tobool, label %while.end, label %while.body
117 while.end: ; preds = %while.body, %entry
118 %r.0.lcssa = phi i8 [ 0, %entry ], [ %add, %while.body ]
122 define i16 @load16predec(ptr %x, i16 %y) {
123 ; CHECK-LABEL: load16predec:
124 ; CHECK: ld {{.*}}, -{{[XYZ]}}
125 ; CHECK: ld {{.*}}, -{{[XYZ]}}
127 %tobool2 = icmp eq i16 %y, 0
128 br i1 %tobool2, label %while.end, label %while.body
129 while.body: ; preds = %entry, %while.body
130 %r.05 = phi i16 [ %add, %while.body ], [ 0, %entry ]
131 %y.addr.04 = phi i16 [ %dec, %while.body ], [ %y, %entry ]
132 %x.addr.03 = phi ptr [ %incdec.ptr, %while.body ], [ %x, %entry ]
133 %dec = add nsw i16 %y.addr.04, -1
134 %incdec.ptr = getelementptr inbounds i16, ptr %x.addr.03, i16 -1
135 %0 = load i16, ptr %incdec.ptr
136 %add = add nsw i16 %0, %r.05
137 %tobool = icmp eq i16 %dec, 0
138 br i1 %tobool, label %while.end, label %while.body
139 while.end: ; preds = %while.body, %entry
140 %r.0.lcssa = phi i16 [ 0, %entry ], [ %add, %while.body ]
144 define ptr addrspace(1) @load16_postinc_progmem(ptr addrspace(1) readonly %0) {
145 ; CHECK-LABEL: load16_postinc_progmem:
146 ; CHECK: movw r30, [[REG0:r[0-9]+]]
147 ; CHECK: lpm [[REG1:r[0-9]+]], Z+
148 ; CHECK: lpm [[REG1:r[0-9]+]], Z
150 ; CHECK: adiw [[REG0:r[0-9]+]], 2
151 %2 = load i16, ptr addrspace(1) %0, align 1
152 tail call addrspace(1) void @foo(i16 %2)
153 %3 = getelementptr inbounds i16, ptr addrspace(1) %0, i16 1
154 ret ptr addrspace(1) %3
157 declare void @foo(i16)