1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=x86-64 < %s | FileCheck %s
4 ; This file checks the reassociation of ADD instruction.
5 ; The two ADD instructions add v0,v1,t2 together. t2 has a long dependence
6 ; chain, v0 and v1 has a short dependence chain, in order to get the shortest
7 ; latency, v0 and v1 should be added first, and its result is added to t2
10 define void @add8(i8 %x0, i8 %x1, i8 %x2, ptr %p) {
13 ; CHECK-NEXT: orb $16, %dil
14 ; CHECK-NEXT: orb $32, %sil
15 ; CHECK-NEXT: addb %dil, %sil
16 ; CHECK-NEXT: addb $-8, %dl
17 ; CHECK-NEXT: orb $7, %dl
18 ; CHECK-NEXT: movzbl %dl, %eax
19 ; CHECK-NEXT: imull $100, %eax, %eax
20 ; CHECK-NEXT: addb %sil, %al
21 ; CHECK-NEXT: movb %al, (%rcx)
30 store i8 %t4, ptr %p, align 4
34 define void @add16(i16 %x0, i16 %x1, i16 %x2, ptr %p) {
37 ; CHECK-NEXT: orl $16, %edi
38 ; CHECK-NEXT: orl $32, %esi
39 ; CHECK-NEXT: addl %edi, %esi
40 ; CHECK-NEXT: addl $-8, %edx
41 ; CHECK-NEXT: orl $7, %edx
42 ; CHECK-NEXT: imull $100, %edx, %eax
43 ; CHECK-NEXT: addl %esi, %eax
44 ; CHECK-NEXT: movw %ax, (%rcx)
50 %t2 = mul i16 %t1, 100
51 %t3 = add i16 %t2, %v1
52 %t4 = add i16 %t3, %v0
53 store i16 %t4, ptr %p, align 4
57 define void @add32(i32 %x0, i32 %x1, i32 %x2, ptr %p) {
60 ; CHECK-NEXT: orl $16, %edi
61 ; CHECK-NEXT: orl $32, %esi
62 ; CHECK-NEXT: addl %edi, %esi
63 ; CHECK-NEXT: addl $-8, %edx
64 ; CHECK-NEXT: orl $7, %edx
65 ; CHECK-NEXT: imull $100, %edx, %eax
66 ; CHECK-NEXT: addl %esi, %eax
67 ; CHECK-NEXT: movl %eax, (%rcx)
73 %t2 = mul i32 %t1, 100
74 %t3 = add i32 %t2, %v1
75 %t4 = add i32 %t3, %v0
76 store i32 %t4, ptr %p, align 4
80 define void @add64(i64 %x0, i64 %x1, i64 %x2, ptr %p) {
83 ; CHECK-NEXT: orq $16, %rdi
84 ; CHECK-NEXT: orq $32, %rsi
85 ; CHECK-NEXT: addq %rdi, %rsi
86 ; CHECK-NEXT: addq $-8, %rdx
87 ; CHECK-NEXT: orq $7, %rdx
88 ; CHECK-NEXT: imulq $100, %rdx, %rax
89 ; CHECK-NEXT: addq %rsi, %rax
90 ; CHECK-NEXT: movq %rax, (%rcx)
96 %t2 = mul i64 %t1, 100
97 %t3 = add i64 %t2, %v1
98 %t4 = add i64 %t3, %v0
99 store i64 %t4, ptr %p, align 4
103 ; Negative test. Original sequence has shorter latency, don't transform it.
104 define void @add64_negative(i64 %x0, i64 %x1, i64 %x2, ptr %p) {
105 ; CHECK-LABEL: add64_negative:
107 ; CHECK-NEXT: orq $16, %rdi
108 ; CHECK-NEXT: orq $32, %rsi
109 ; CHECK-NEXT: addq %rdi, %rsi
110 ; CHECK-NEXT: addq $-8, %rdx
111 ; CHECK-NEXT: orq $7, %rdx
112 ; CHECK-NEXT: imulq $100, %rdx, %rax
113 ; CHECK-NEXT: addq %rsi, %rax
114 ; CHECK-NEXT: movq %rax, (%rcx)
120 %t2 = mul i64 %t1, 100
121 %t3 = add i64 %v0, %v1
122 %t4 = add i64 %t3, %t2
123 store i64 %t4, ptr %p, align 4