diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-08-11 15:44:14 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-08-11 15:44:14 +0000 |
commit | 169dae70a680cdfa1779148eb9cb643bb76c8b0e (patch) | |
tree | 83e08148cec571ed6f42847d9ccc7658a73a0f96 /llvm/test/CodeGen/X86/select.ll | |
parent | 1fb1ce0c87b1b2c78068488be3f624d3c0cbb19a (diff) | |
download | bcm5719-llvm-169dae70a680cdfa1779148eb9cb643bb76c8b0e.tar.gz bcm5719-llvm-169dae70a680cdfa1779148eb9cb643bb76c8b0e.zip |
[x86] use more shift or LEA for select-of-constants (2nd try)
The previous rev (r310208) failed to account for overflow when subtracting the
constants to see if they're suitable for shift/lea. This version add a check
for that and more test were added in r310490.
We can convert any select-of-constants to math ops:
http://rise4fun.com/Alive/d7d
For this patch, I'm enhancing an existing x86 transform that uses fake multiplies
(they always become shl/lea) to avoid cmov or branching. The current code misses
cases where we have a negative constant and a positive constant, so this is just
trying to plug that hole.
The DAGCombiner diff prevents us from hitting a terrible inefficiency: we can start
with a select in IR, create a select DAG node, convert it into a sext, convert it
back into a select, and then lower it to sext machine code.
Some notes about the test diffs:
1. 2010-08-04-MaskedSignedCompare.ll - We were creating control flow that didn't exist in the IR.
2. memcmp.ll - Choose -1 or 1 is the case that got me looking at this again. We could avoid the
push/pop in some cases if we used 'movzbl %al' instead of an xor on a different reg? That's a
post-DAG problem though.
3. mul-constant-result.ll - The trade-off between sbb+not vs. setne+neg could be addressed if
that's a regression, but those would always be nearly equivalent.
4. pr22338.ll and sext-i1.ll - These tests have undef operands, so we don't actually care about these diffs.
5. sbb.ll - This shows a win for what is likely a common case: choose -1 or 0.
6. select.ll - There's another borderline case here: cmp+sbb+or vs. test+set+lea? Also, sbb+not vs. setae+neg shows up again.
7. select_const.ll - These are motivating cases for the enhancement; replace cmov with cheaper ops.
Assembly differences between movzbl and xor to avoid a partial reg stall are caused later by the X86 Fixup SetCC pass.
Differential Revision: https://reviews.llvm.org/D35340
llvm-svn: 310717
Diffstat (limited to 'llvm/test/CodeGen/X86/select.ll')
-rw-r--r-- | llvm/test/CodeGen/X86/select.ll | 83 |
1 files changed, 34 insertions, 49 deletions
diff --git a/llvm/test/CodeGen/X86/select.ll b/llvm/test/CodeGen/X86/select.ll index ec15d1a9520..b37644e2291 100644 --- a/llvm/test/CodeGen/X86/select.ll +++ b/llvm/test/CodeGen/X86/select.ll @@ -545,12 +545,11 @@ define i64 @test9b(i64 %x, i64 %y) nounwind readnone ssp noredzone { ; ; MCU-LABEL: test9b: ; MCU: # BB#0: -; MCU-NEXT: orl %edx, %eax -; MCU-NEXT: movl $-1, %edx -; MCU-NEXT: je .LBB10_2 -; MCU-NEXT: # BB#1: +; MCU-NEXT: movl %edx, %ecx ; MCU-NEXT: xorl %edx, %edx -; MCU-NEXT: .LBB10_2: +; MCU-NEXT: orl %ecx, %eax +; MCU-NEXT: sete %dl +; MCU-NEXT: negl %edx ; MCU-NEXT: movl {{[0-9]+}}(%esp), %eax ; MCU-NEXT: orl %edx, %eax ; MCU-NEXT: orl {{[0-9]+}}(%esp), %edx @@ -563,23 +562,14 @@ define i64 @test9b(i64 %x, i64 %y) nounwind readnone ssp noredzone { ;; Select between -1 and 1. define i64 @test10(i64 %x, i64 %y) nounwind readnone ssp noredzone { -; GENERIC-LABEL: test10: -; GENERIC: ## BB#0: -; GENERIC-NEXT: cmpq $1, %rdi -; GENERIC-NEXT: sbbq %rax, %rax -; GENERIC-NEXT: orq $1, %rax -; GENERIC-NEXT: retq -; GENERIC-NEXT: ## -- End function -; -; ATOM-LABEL: test10: -; ATOM: ## BB#0: -; ATOM-NEXT: cmpq $1, %rdi -; ATOM-NEXT: sbbq %rax, %rax -; ATOM-NEXT: orq $1, %rax -; ATOM-NEXT: nop -; ATOM-NEXT: nop -; ATOM-NEXT: retq -; ATOM-NEXT: ## -- End function +; CHECK-LABEL: test10: +; CHECK: ## BB#0: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: testq %rdi, %rdi +; CHECK-NEXT: setne %al +; CHECK-NEXT: leaq -1(%rax,%rax), %rax +; CHECK-NEXT: retq +; CHECK-NEXT: ## -- End function ; ; MCU-LABEL: test10: ; MCU: # BB#0: @@ -747,29 +737,22 @@ define i32 @test13(i32 %a, i32 %b) nounwind { } define i32 @test14(i32 %a, i32 %b) nounwind { -; GENERIC-LABEL: test14: -; GENERIC: ## BB#0: -; GENERIC-NEXT: cmpl %esi, %edi -; GENERIC-NEXT: sbbl %eax, %eax -; GENERIC-NEXT: notl %eax -; GENERIC-NEXT: retq -; GENERIC-NEXT: ## -- End function -; -; ATOM-LABEL: test14: -; ATOM: ## BB#0: -; ATOM-NEXT: cmpl %esi, %edi -; ATOM-NEXT: sbbl %eax, %eax -; ATOM-NEXT: notl %eax -; ATOM-NEXT: nop -; ATOM-NEXT: nop -; ATOM-NEXT: retq -; ATOM-NEXT: ## -- End function +; CHECK-LABEL: test14: +; CHECK: ## BB#0: +; CHECK-NEXT: xorl %eax, %eax +; CHECK-NEXT: cmpl %esi, %edi +; CHECK-NEXT: setae %al +; CHECK-NEXT: negl %eax +; CHECK-NEXT: retq +; CHECK-NEXT: ## -- End function ; ; MCU-LABEL: test14: ; MCU: # BB#0: +; MCU-NEXT: xorl %ecx, %ecx ; MCU-NEXT: cmpl %edx, %eax -; MCU-NEXT: sbbl %eax, %eax -; MCU-NEXT: notl %eax +; MCU-NEXT: setae %cl +; MCU-NEXT: negl %ecx +; MCU-NEXT: movl %ecx, %eax ; MCU-NEXT: retl %c = icmp uge i32 %a, %b %d = sext i1 %c to i32 @@ -826,12 +809,11 @@ define i64 @test16(i64 %x) nounwind uwtable readnone ssp { ; ; MCU-LABEL: test16: ; MCU: # BB#0: # %entry -; MCU-NEXT: orl %edx, %eax -; MCU-NEXT: movl $-1, %eax -; MCU-NEXT: jne .LBB18_2 -; MCU-NEXT: # BB#1: # %entry +; MCU-NEXT: movl %eax, %ecx ; MCU-NEXT: xorl %eax, %eax -; MCU-NEXT: .LBB18_2: # %entry +; MCU-NEXT: orl %edx, %ecx +; MCU-NEXT: setne %al +; MCU-NEXT: negl %eax ; MCU-NEXT: movl %eax, %edx ; MCU-NEXT: retl entry: @@ -844,14 +826,16 @@ define i16 @test17(i16 %x) nounwind { ; GENERIC-LABEL: test17: ; GENERIC: ## BB#0: ## %entry ; GENERIC-NEXT: negw %di -; GENERIC-NEXT: sbbw %ax, %ax +; GENERIC-NEXT: sbbl %eax, %eax +; GENERIC-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> ; GENERIC-NEXT: retq ; GENERIC-NEXT: ## -- End function ; ; ATOM-LABEL: test17: ; ATOM: ## BB#0: ## %entry ; ATOM-NEXT: negw %di -; ATOM-NEXT: sbbw %ax, %ax +; ATOM-NEXT: sbbl %eax, %eax +; ATOM-NEXT: ## kill: %AX<def> %AX<kill> %EAX<kill> ; ATOM-NEXT: nop ; ATOM-NEXT: nop ; ATOM-NEXT: nop @@ -862,7 +846,8 @@ define i16 @test17(i16 %x) nounwind { ; MCU-LABEL: test17: ; MCU: # BB#0: # %entry ; MCU-NEXT: negw %ax -; MCU-NEXT: sbbw %ax, %ax +; MCU-NEXT: sbbl %eax, %eax +; MCU-NEXT: # kill: %AX<def> %AX<kill> %EAX<kill> ; MCU-NEXT: retl entry: %cmp = icmp ne i16 %x, 0 |