1 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -machine-combiner-verify-pattern-order=true | FileCheck %s
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -stop-after machine-combiner -machine-combiner-verify-pattern-order=true -o - | FileCheck %s --check-prefix=DEAD
4 ; Verify that integer multiplies are reassociated. The first multiply in
5 ; each test should be independent of the result of the preceding add (lea).
7 ; TODO: This test does not actually test i16 machine instruction reassociation
8 ; because the operands are being promoted to i32 types.
10 define i16 @reassociate_muls_i16(i16 %x0, i16 %x1, i16 %x2, i16 %x3) {
11 ; CHECK-LABEL: reassociate_muls_i16:
15 ; CHECK-NEXT: leal (%rdi,%rsi), %eax
16 ; CHECK-NEXT: imull %ecx, %edx
17 ; CHECK-NEXT: imull %edx, %eax
20 %t0 = add i16 %x0, %x1
21 %t1 = mul i16 %x2, %t0
22 %t2 = mul i16 %x3, %t1
26 define i32 @reassociate_muls_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
27 ; CHECK-LABEL: reassociate_muls_i32:
31 ; CHECK-NEXT: leal (%rdi,%rsi), %eax
32 ; CHECK-NEXT: imull %ecx, %edx
33 ; CHECK-NEXT: imull %edx, %eax
37 ; DEAD-NEXT: IMUL32rr{{.*}}implicit-def dead $eflags
38 ; DEAD-NEXT: IMUL32rr{{.*}}implicit-def dead $eflags
40 %t0 = add i32 %x0, %x1
41 %t1 = mul i32 %x2, %t0
42 %t2 = mul i32 %x3, %t1
46 define i64 @reassociate_muls_i64(i64 %x0, i64 %x1, i64 %x2, i64 %x3) {
47 ; CHECK-LABEL: reassociate_muls_i64:
49 ; CHECK-NEXT: leaq (%rdi,%rsi), %rax
50 ; CHECK-NEXT: imulq %rcx, %rdx
51 ; CHECK-NEXT: imulq %rdx, %rax
53 %t0 = add i64 %x0, %x1
54 %t1 = mul i64 %x2, %t0
55 %t2 = mul i64 %x3, %t1
59 ; Verify that integer 'ands' are reassociated. The first 'and' in
60 ; each test should be independent of the result of the preceding sub.
62 define i8 @reassociate_ands_i8(i8 %x0, i8 %x1, i8 %x2, i8 %x3) {
63 ; CHECK-LABEL: reassociate_ands_i8:
65 ; CHECK-NEXT: movl %edx, %eax
66 ; CHECK-NEXT: subb %sil, %dil
67 ; CHECK-NEXT: andb %cl, %al
68 ; CHECK-NEXT: andb %dil, %al
77 ; TODO: No way to test i16? These appear to always get promoted to i32.
79 define i32 @reassociate_ands_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
80 ; CHECK-LABEL: reassociate_ands_i32:
82 ; CHECK-NEXT: movl %edx, %eax
83 ; CHECK-NEXT: subl %esi, %edi
84 ; CHECK-NEXT: andl %ecx, %eax
85 ; CHECK-NEXT: andl %edi, %eax
87 %t0 = sub i32 %x0, %x1
88 %t1 = and i32 %x2, %t0
89 %t2 = and i32 %x3, %t1
93 define i64 @reassociate_ands_i64(i64 %x0, i64 %x1, i64 %x2, i64 %x3) {
94 ; CHECK-LABEL: reassociate_ands_i64:
96 ; CHECK-NEXT: movq %rdx, %rax
97 ; CHECK-NEXT: subq %rsi, %rdi
98 ; CHECK-NEXT: andq %rcx, %rax
99 ; CHECK-NEXT: andq %rdi, %rax
101 %t0 = sub i64 %x0, %x1
102 %t1 = and i64 %x2, %t0
103 %t2 = and i64 %x3, %t1
107 ; Verify that integer 'ors' are reassociated. The first 'or' in
108 ; each test should be independent of the result of the preceding sub.
110 define i8 @reassociate_ors_i8(i8 %x0, i8 %x1, i8 %x2, i8 %x3) {
111 ; CHECK-LABEL: reassociate_ors_i8:
113 ; CHECK-NEXT: movl %edx, %eax
114 ; CHECK-NEXT: subb %sil, %dil
115 ; CHECK-NEXT: orb %cl, %al
116 ; CHECK-NEXT: orb %dil, %al
119 %t0 = sub i8 %x0, %x1
125 ; TODO: No way to test i16? These appear to always get promoted to i32.
127 define i32 @reassociate_ors_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
128 ; CHECK-LABEL: reassociate_ors_i32:
130 ; CHECK-NEXT: movl %edx, %eax
131 ; CHECK-NEXT: subl %esi, %edi
132 ; CHECK-NEXT: orl %ecx, %eax
133 ; CHECK-NEXT: orl %edi, %eax
135 %t0 = sub i32 %x0, %x1
136 %t1 = or i32 %x2, %t0
137 %t2 = or i32 %x3, %t1
141 define i64 @reassociate_ors_i64(i64 %x0, i64 %x1, i64 %x2, i64 %x3) {
142 ; CHECK-LABEL: reassociate_ors_i64:
144 ; CHECK-NEXT: movq %rdx, %rax
145 ; CHECK-NEXT: subq %rsi, %rdi
146 ; CHECK-NEXT: orq %rcx, %rax
147 ; CHECK-NEXT: orq %rdi, %rax
149 %t0 = sub i64 %x0, %x1
150 %t1 = or i64 %x2, %t0
151 %t2 = or i64 %x3, %t1
155 ; Verify that integer 'xors' are reassociated. The first 'xor' in
156 ; each test should be independent of the result of the preceding sub.
158 define i8 @reassociate_xors_i8(i8 %x0, i8 %x1, i8 %x2, i8 %x3) {
159 ; CHECK-LABEL: reassociate_xors_i8:
161 ; CHECK-NEXT: movl %edx, %eax
162 ; CHECK-NEXT: subb %sil, %dil
163 ; CHECK-NEXT: xorb %cl, %al
164 ; CHECK-NEXT: xorb %dil, %al
167 %t0 = sub i8 %x0, %x1
168 %t1 = xor i8 %x2, %t0
169 %t2 = xor i8 %x3, %t1
173 ; TODO: No way to test i16? These appear to always get promoted to i32.
175 define i32 @reassociate_xors_i32(i32 %x0, i32 %x1, i32 %x2, i32 %x3) {
176 ; CHECK-LABEL: reassociate_xors_i32:
178 ; CHECK-NEXT: movl %edx, %eax
179 ; CHECK-NEXT: subl %esi, %edi
180 ; CHECK-NEXT: xorl %ecx, %eax
181 ; CHECK-NEXT: xorl %edi, %eax
183 %t0 = sub i32 %x0, %x1
184 %t1 = xor i32 %x2, %t0
185 %t2 = xor i32 %x3, %t1
189 define i64 @reassociate_xors_i64(i64 %x0, i64 %x1, i64 %x2, i64 %x3) {
190 ; CHECK-LABEL: reassociate_xors_i64:
192 ; CHECK-NEXT: movq %rdx, %rax
193 ; CHECK-NEXT: subq %rsi, %rdi
194 ; CHECK-NEXT: xorq %rcx, %rax
195 ; CHECK-NEXT: xorq %rdi, %rax
197 %t0 = sub i64 %x0, %x1
198 %t1 = xor i64 %x2, %t0
199 %t2 = xor i64 %x3, %t1