1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=avr -mcpu=atmega328 | FileCheck %s --check-prefix=AVR51
3 ; RUN: llc < %s -mtriple=avr -mcpu=at90s8515 | FileCheck %s --check-prefix=AVR2
5 ; Test for bug https://github.com/llvm/llvm-project/issues/56423
7 define i32 @foo(i32 %x, i32 %in_min, i32 %in_max, i32 %out_min, i32 %out_max) {
9 ; AVR51: ; %bb.0: ; %entry
14 ; AVR51-NEXT: push r14
15 ; AVR51-NEXT: push r15
16 ; AVR51-NEXT: push r16
17 ; AVR51-NEXT: push r17
18 ; AVR51-NEXT: push r28
19 ; AVR51-NEXT: push r29
20 ; AVR51-NEXT: in r28, 61
21 ; AVR51-NEXT: in r29, 62
22 ; AVR51-NEXT: movw r8, r20
23 ; AVR51-NEXT: movw r6, r18
24 ; AVR51-NEXT: movw r20, r24
25 ; AVR51-NEXT: movw r18, r22
26 ; AVR51-NEXT: ldd r22, Y+13
27 ; AVR51-NEXT: ldd r23, Y+14
28 ; AVR51-NEXT: ldd r24, Y+15
29 ; AVR51-NEXT: ldd r25, Y+16
30 ; AVR51-NEXT: sub r22, r10
31 ; AVR51-NEXT: sbc r23, r11
32 ; AVR51-NEXT: sbc r24, r12
33 ; AVR51-NEXT: sbc r25, r13
34 ; AVR51-NEXT: sub r18, r6
35 ; AVR51-NEXT: sbc r19, r7
36 ; AVR51-NEXT: sbc r20, r8
37 ; AVR51-NEXT: sbc r21, r9
38 ; AVR51-NEXT: call __mulsi3
39 ; AVR51-NEXT: sub r14, r6
40 ; AVR51-NEXT: sbc r15, r7
41 ; AVR51-NEXT: sbc r16, r8
42 ; AVR51-NEXT: sbc r17, r9
43 ; AVR51-NEXT: movw r18, r14
44 ; AVR51-NEXT: movw r20, r16
45 ; AVR51-NEXT: call __divmodsi4
46 ; AVR51-NEXT: add r18, r10
47 ; AVR51-NEXT: adc r19, r11
48 ; AVR51-NEXT: adc r20, r12
49 ; AVR51-NEXT: adc r21, r13
50 ; AVR51-NEXT: movw r22, r18
51 ; AVR51-NEXT: movw r24, r20
65 ; AVR2: ; %bb.0: ; %entry
76 ; AVR2-NEXT: in r28, 61
77 ; AVR2-NEXT: in r29, 62
78 ; AVR2-NEXT: mov r8, r20
79 ; AVR2-NEXT: mov r9, r21
80 ; AVR2-NEXT: mov r6, r18
81 ; AVR2-NEXT: mov r7, r19
82 ; AVR2-NEXT: mov r20, r24
83 ; AVR2-NEXT: mov r21, r25
84 ; AVR2-NEXT: mov r18, r22
85 ; AVR2-NEXT: mov r19, r23
86 ; AVR2-NEXT: ldd r22, Y+13
87 ; AVR2-NEXT: ldd r23, Y+14
88 ; AVR2-NEXT: ldd r24, Y+15
89 ; AVR2-NEXT: ldd r25, Y+16
90 ; AVR2-NEXT: sub r22, r10
91 ; AVR2-NEXT: sbc r23, r11
92 ; AVR2-NEXT: sbc r24, r12
93 ; AVR2-NEXT: sbc r25, r13
94 ; AVR2-NEXT: sub r18, r6
95 ; AVR2-NEXT: sbc r19, r7
96 ; AVR2-NEXT: sbc r20, r8
97 ; AVR2-NEXT: sbc r21, r9
98 ; AVR2-NEXT: rcall __mulsi3
99 ; AVR2-NEXT: sub r14, r6
100 ; AVR2-NEXT: sbc r15, r7
101 ; AVR2-NEXT: sbc r16, r8
102 ; AVR2-NEXT: sbc r17, r9
103 ; AVR2-NEXT: mov r18, r14
104 ; AVR2-NEXT: mov r19, r15
105 ; AVR2-NEXT: mov r20, r16
106 ; AVR2-NEXT: mov r21, r17
107 ; AVR2-NEXT: rcall __divmodsi4
108 ; AVR2-NEXT: add r18, r10
109 ; AVR2-NEXT: adc r19, r11
110 ; AVR2-NEXT: adc r20, r12
111 ; AVR2-NEXT: adc r21, r13
112 ; AVR2-NEXT: mov r22, r18
113 ; AVR2-NEXT: mov r23, r19
114 ; AVR2-NEXT: mov r24, r20
115 ; AVR2-NEXT: mov r25, r21
128 %sub = sub nsw i32 %x, %in_min
129 %sub1 = sub nsw i32 %out_max, %out_min
130 %mul = mul nsw i32 %sub1, %sub
131 %sub2 = sub nsw i32 %in_max, %in_min
132 %div = sdiv i32 %mul, %sub2
133 %add = add nsw i32 %div, %out_min