Skip to content

Commit 1296c62

Browse files
committed
[X86] Add test case to show failure to combine away negates that may be created by mul by constant expansion.
Mul by constant can expand to a sequence that ends with a negate. If the next instruction is an add or sub we might be able to fold the negate away. We currently fail to do this because we explicitly don't add anything to the DAG combine worklist when we expand multiplies. This is primarily to keep the multipy from being reformed, but we should consider adding the users to worklist. llvm-svn: 337843
1 parent cb4d0cd commit 1296c62

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

llvm/test/CodeGen/X86/mul-constant-i32.ll

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,3 +1748,67 @@ define i32 @test_mul_spec(i32 %x) nounwind {
17481748
%mul3 = mul nsw i32 %add, %add2
17491749
ret i32 %mul3
17501750
}
1751+
1752+
; This makes sure we are able to fold the negate generated by the mul expansion
1753+
; into the next instruction.
1754+
; FIXME: We make this work.
1755+
define i32 @mul_neg_fold(i32 %a, i32 %b) {
1756+
; X86-LABEL: mul_neg_fold:
1757+
; X86: # %bb.0:
1758+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
1759+
; X86-NEXT: leal (%eax,%eax,8), %eax
1760+
; X86-NEXT: negl %eax
1761+
; X86-NEXT: addl {{[0-9]+}}(%esp), %eax
1762+
; X86-NEXT: retl
1763+
;
1764+
; X64-HSW-LABEL: mul_neg_fold:
1765+
; X64-HSW: # %bb.0:
1766+
; X64-HSW-NEXT: # kill: def $edi killed $edi def $rdi
1767+
; X64-HSW-NEXT: leal (%rdi,%rdi,8), %eax # sched: [1:0.50]
1768+
; X64-HSW-NEXT: negl %eax # sched: [1:0.25]
1769+
; X64-HSW-NEXT: addl %esi, %eax # sched: [1:0.25]
1770+
; X64-HSW-NEXT: retq # sched: [7:1.00]
1771+
;
1772+
; X64-JAG-LABEL: mul_neg_fold:
1773+
; X64-JAG: # %bb.0:
1774+
; X64-JAG-NEXT: # kill: def $edi killed $edi def $rdi
1775+
; X64-JAG-NEXT: leal (%rdi,%rdi,8), %eax # sched: [2:1.00]
1776+
; X64-JAG-NEXT: negl %eax # sched: [1:0.50]
1777+
; X64-JAG-NEXT: addl %esi, %eax # sched: [1:0.50]
1778+
; X64-JAG-NEXT: retq # sched: [4:1.00]
1779+
;
1780+
; X86-NOOPT-LABEL: mul_neg_fold:
1781+
; X86-NOOPT: # %bb.0:
1782+
; X86-NOOPT-NEXT: imull $-9, {{[0-9]+}}(%esp), %eax
1783+
; X86-NOOPT-NEXT: addl {{[0-9]+}}(%esp), %eax
1784+
; X86-NOOPT-NEXT: retl
1785+
;
1786+
; HSW-NOOPT-LABEL: mul_neg_fold:
1787+
; HSW-NOOPT: # %bb.0:
1788+
; HSW-NOOPT-NEXT: imull $-9, %edi, %eax # sched: [3:1.00]
1789+
; HSW-NOOPT-NEXT: addl %esi, %eax # sched: [1:0.25]
1790+
; HSW-NOOPT-NEXT: retq # sched: [7:1.00]
1791+
;
1792+
; JAG-NOOPT-LABEL: mul_neg_fold:
1793+
; JAG-NOOPT: # %bb.0:
1794+
; JAG-NOOPT-NEXT: imull $-9, %edi, %eax # sched: [3:1.00]
1795+
; JAG-NOOPT-NEXT: addl %esi, %eax # sched: [1:0.50]
1796+
; JAG-NOOPT-NEXT: retq # sched: [4:1.00]
1797+
;
1798+
; X64-SLM-LABEL: mul_neg_fold:
1799+
; X64-SLM: # %bb.0:
1800+
; X64-SLM-NEXT: # kill: def $edi killed $edi def $rdi
1801+
; X64-SLM-NEXT: leal (%rdi,%rdi,8), %eax # sched: [1:1.00]
1802+
; X64-SLM-NEXT: negl %eax # sched: [1:0.50]
1803+
; X64-SLM-NEXT: addl %esi, %eax # sched: [1:0.50]
1804+
; X64-SLM-NEXT: retq # sched: [4:1.00]
1805+
;
1806+
; SLM-NOOPT-LABEL: mul_neg_fold:
1807+
; SLM-NOOPT: # %bb.0:
1808+
; SLM-NOOPT-NEXT: imull $-9, %edi, %eax # sched: [3:1.00]
1809+
; SLM-NOOPT-NEXT: addl %esi, %eax # sched: [1:0.50]
1810+
; SLM-NOOPT-NEXT: retq # sched: [4:1.00]
1811+
%c = mul i32 %a, -9
1812+
%d = add i32 %b, %c
1813+
ret i32 %d
1814+
}

0 commit comments

Comments
 (0)