diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-02-24 17:17:33 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-02-24 17:17:33 +0000 |
commit | 832b1622d8b4a221f56d07e037e30129b1873a0e (patch) | |
tree | c334b9cd0528fd8fca296fcfa9a9d0689af69e85 /llvm/test/CodeGen/X86/select_const.ll | |
parent | 4987856fbcefbde45353b68250357e31d187ebc6 (diff) | |
download | bcm5719-llvm-832b1622d8b4a221f56d07e037e30129b1873a0e.tar.gz bcm5719-llvm-832b1622d8b4a221f56d07e037e30129b1873a0e.zip |
[DAGCombiner] add missing folds for scalar select of {-1,0,1}
The motivation for filling out these select-of-constants cases goes back to D24480,
where we discussed removing an IR fold from add(zext) --> select. And that goes back to:
https://reviews.llvm.org/rL75531
https://reviews.llvm.org/rL159230
The idea is that we should always canonicalize patterns like this to a select-of-constants
in IR because that's the smallest IR and the best for value tracking. Note that we currently
do the opposite in some cases (like the cases in *this* patch). Ie, the proposed folds in
this patch already exist in InstCombine today:
https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/InstCombine/InstCombineSelect.cpp#L1151
As this patch shows, most targets generate better machine code for simple ext/add/not ops
rather than a select of constants. So the follow-up steps to make this less of a patchwork
of special-case folds and missing IR canonicalization:
1. Have DAGCombiner convert any select of constants into ext/add/not ops.
2 Have InstCombine canonicalize in the other direction (create more selects).
Differential Revision: https://reviews.llvm.org/D30180
llvm-svn: 296137
Diffstat (limited to 'llvm/test/CodeGen/X86/select_const.ll')
-rw-r--r-- | llvm/test/CodeGen/X86/select_const.ll | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/llvm/test/CodeGen/X86/select_const.ll b/llvm/test/CodeGen/X86/select_const.ll index eb9abcbdcb8..82054a314a5 100644 --- a/llvm/test/CodeGen/X86/select_const.ll +++ b/llvm/test/CodeGen/X86/select_const.ll @@ -108,10 +108,9 @@ define i32 @select_0_or_neg1_signext(i1 signext %cond) { define i32 @select_neg1_or_0(i1 %cond) { ; CHECK-LABEL: select_neg1_or_0: ; CHECK: # BB#0: -; CHECK-NEXT: xorl %ecx, %ecx -; CHECK-NEXT: testb $1, %dil -; CHECK-NEXT: movl $-1, %eax -; CHECK-NEXT: cmovel %ecx, %eax +; CHECK-NEXT: andl $1, %edi +; CHECK-NEXT: negl %edi +; CHECK-NEXT: movl %edi, %eax ; CHECK-NEXT: retq %sel = select i1 %cond, i32 -1, i32 0 ret i32 %sel @@ -120,10 +119,8 @@ define i32 @select_neg1_or_0(i1 %cond) { define i32 @select_neg1_or_0_zeroext(i1 zeroext %cond) { ; CHECK-LABEL: select_neg1_or_0_zeroext: ; CHECK: # BB#0: -; CHECK-NEXT: xorl %ecx, %ecx -; CHECK-NEXT: testb %dil, %dil -; CHECK-NEXT: movl $-1, %eax -; CHECK-NEXT: cmovel %ecx, %eax +; CHECK-NEXT: movzbl %dil, %eax +; CHECK-NEXT: negl %eax ; CHECK-NEXT: retq %sel = select i1 %cond, i32 -1, i32 0 ret i32 %sel @@ -132,10 +129,7 @@ define i32 @select_neg1_or_0_zeroext(i1 zeroext %cond) { define i32 @select_neg1_or_0_signext(i1 signext %cond) { ; CHECK-LABEL: select_neg1_or_0_signext: ; CHECK: # BB#0: -; CHECK-NEXT: xorl %ecx, %ecx -; CHECK-NEXT: testb $1, %dil -; CHECK-NEXT: movl $-1, %eax -; CHECK-NEXT: cmovel %ecx, %eax +; CHECK-NEXT: movsbl %dil, %eax ; CHECK-NEXT: retq %sel = select i1 %cond, i32 -1, i32 0 ret i32 %sel |