Skip to content

[X86] Improve transform for add-like nodes to add #83691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions llvm/lib/Target/X86/X86InstrFragments.td
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,7 @@ def def32 : PatLeaf<(i32 GR32:$src), [{

// Treat an 'or' node is as an 'add' if the or'ed bits are known to be zero.
def or_is_add : PatFrag<(ops node:$lhs, node:$rhs), (or node:$lhs, node:$rhs),[{
if (ConstantSDNode *CN = dyn_cast<ConstantSDNode>(N->getOperand(1)))
return CurDAG->MaskedValueIsZero(N->getOperand(0), CN->getAPIntValue());

KnownBits Known0 = CurDAG->computeKnownBits(N->getOperand(0), 0);
KnownBits Known1 = CurDAG->computeKnownBits(N->getOperand(1), 0);
return (~Known0.Zero & ~Known1.Zero) == 0;
return CurDAG->isADDLike(SDValue(N, 0));
}]>;

def shiftMask8 : PatFrag<(ops node:$lhs), (and node:$lhs, imm), [{
Expand Down
9 changes: 5 additions & 4 deletions llvm/test/CodeGen/X86/bitselect.ll
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ define i16 @bitselect_i16(i16 %a, i16 %b, i16 %m) nounwind {
;
; X64-NOBMI-LABEL: bitselect_i16:
; X64-NOBMI: # %bb.0:
; X64-NOBMI-NEXT: movl %edx, %eax
; X64-NOBMI-NEXT: # kill: def $edx killed $edx def $rdx
; X64-NOBMI-NEXT: # kill: def $esi killed $esi def $rsi
; X64-NOBMI-NEXT: andl %edx, %esi
; X64-NOBMI-NEXT: notl %eax
; X64-NOBMI-NEXT: andl %edi, %eax
; X64-NOBMI-NEXT: orl %esi, %eax
; X64-NOBMI-NEXT: notl %edx
; X64-NOBMI-NEXT: andl %edi, %edx
; X64-NOBMI-NEXT: leal (%rdx,%rsi), %eax
; X64-NOBMI-NEXT: # kill: def $ax killed $ax killed $eax
; X64-NOBMI-NEXT: retq
;
Expand Down
38 changes: 21 additions & 17 deletions llvm/test/CodeGen/X86/fold-masked-merge.ll
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ define i32 @masked_merge0(i32 %a0, i32 %a1, i32 %a2) {
define i16 @masked_merge1(i16 %a0, i16 %a1, i16 %a2) {
; NOBMI-LABEL: masked_merge1:
; NOBMI: # %bb.0:
; NOBMI-NEXT: movl %edi, %eax
; NOBMI-NEXT: # kill: def $esi killed $esi def $rsi
; NOBMI-NEXT: # kill: def $edi killed $edi def $rdi
; NOBMI-NEXT: andl %edi, %esi
; NOBMI-NEXT: notl %eax
; NOBMI-NEXT: andl %edx, %eax
; NOBMI-NEXT: orl %esi, %eax
; NOBMI-NEXT: notl %edi
; NOBMI-NEXT: andl %edx, %edi
; NOBMI-NEXT: leal (%rdi,%rsi), %eax
; NOBMI-NEXT: # kill: def $ax killed $ax killed $eax
; NOBMI-NEXT: retq
;
Expand Down Expand Up @@ -203,11 +204,12 @@ define i32 @not_a_masked_merge4(i32 %a0, i32 %a1, i32 %a2) {
define i32 @masked_merge_no_transform0(i32 %a0, i32 %a1, i32 %a2, ptr %p1) {
; NOBMI-LABEL: masked_merge_no_transform0:
; NOBMI: # %bb.0:
; NOBMI-NEXT: movl %edi, %eax
; NOBMI-NEXT: # kill: def $esi killed $esi def $rsi
; NOBMI-NEXT: # kill: def $edi killed $edi def $rdi
; NOBMI-NEXT: andl %edi, %esi
; NOBMI-NEXT: notl %eax
; NOBMI-NEXT: andl %edx, %eax
; NOBMI-NEXT: orl %esi, %eax
; NOBMI-NEXT: notl %edi
; NOBMI-NEXT: andl %edx, %edi
; NOBMI-NEXT: leal (%rdi,%rsi), %eax
; NOBMI-NEXT: movl %esi, (%rcx)
; NOBMI-NEXT: retq
;
Expand All @@ -230,11 +232,12 @@ define i32 @masked_merge_no_transform0(i32 %a0, i32 %a1, i32 %a2, ptr %p1) {
define i32 @masked_merge_no_transform1(i32 %a0, i32 %a1, i32 %a2, ptr %p1) {
; NOBMI-LABEL: masked_merge_no_transform1:
; NOBMI: # %bb.0:
; NOBMI-NEXT: movl %edx, %eax
; NOBMI-NEXT: # kill: def $edx killed $edx def $rdx
; NOBMI-NEXT: # kill: def $esi killed $esi def $rsi
; NOBMI-NEXT: andl %edi, %esi
; NOBMI-NEXT: notl %edi
; NOBMI-NEXT: andl %edi, %eax
; NOBMI-NEXT: orl %esi, %eax
; NOBMI-NEXT: andl %edi, %edx
; NOBMI-NEXT: leal (%rdx,%rsi), %eax
; NOBMI-NEXT: movl %edi, (%rcx)
; NOBMI-NEXT: retq
;
Expand All @@ -258,20 +261,21 @@ define i32 @masked_merge_no_transform1(i32 %a0, i32 %a1, i32 %a2, ptr %p1) {
define i32 @masked_merge_no_transform2(i32 %a0, i32 %a1, i32 %a2, ptr %p1) {
; NOBMI-LABEL: masked_merge_no_transform2:
; NOBMI: # %bb.0:
; NOBMI-NEXT: movl %esi, %eax
; NOBMI-NEXT: andl %edi, %eax
; NOBMI-NEXT: # kill: def $esi killed $esi def $rsi
; NOBMI-NEXT: # kill: def $edi killed $edi def $rdi
; NOBMI-NEXT: andl %edi, %esi
; NOBMI-NEXT: notl %edi
; NOBMI-NEXT: andl %edx, %edi
; NOBMI-NEXT: orl %edi, %eax
; NOBMI-NEXT: leal (%rsi,%rdi), %eax
; NOBMI-NEXT: movl %edi, (%rcx)
; NOBMI-NEXT: retq
;
; BMI-LABEL: masked_merge_no_transform2:
; BMI: # %bb.0:
; BMI-NEXT: movl %esi, %eax
; BMI-NEXT: andl %edi, %eax
; BMI-NEXT: # kill: def $esi killed $esi def $rsi
; BMI-NEXT: andl %edi, %esi
; BMI-NEXT: andnl %edx, %edi, %edx
; BMI-NEXT: orl %edx, %eax
; BMI-NEXT: leal (%rsi,%rdx), %eax
; BMI-NEXT: movl %edx, (%rcx)
; BMI-NEXT: retq
%and0 = and i32 %a0, %a1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ define i8 @out8(i8 %x, i8 %y, i8 %mask) {
define i16 @out16(i16 %x, i16 %y, i16 %mask) {
; CHECK-NOBMI-LABEL: out16:
; CHECK-NOBMI: # %bb.0:
; CHECK-NOBMI-NEXT: movl %edx, %eax
; CHECK-NOBMI-NEXT: # kill: def $edx killed $edx def $rdx
; CHECK-NOBMI-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NOBMI-NEXT: andl %edx, %edi
; CHECK-NOBMI-NEXT: notl %eax
; CHECK-NOBMI-NEXT: andl %esi, %eax
; CHECK-NOBMI-NEXT: orl %edi, %eax
; CHECK-NOBMI-NEXT: notl %edx
; CHECK-NOBMI-NEXT: andl %esi, %edx
; CHECK-NOBMI-NEXT: leal (%rdx,%rdi), %eax
; CHECK-NOBMI-NEXT: # kill: def $ax killed $ax killed $eax
; CHECK-NOBMI-NEXT: retq
;
Expand Down
39 changes: 23 additions & 16 deletions llvm/test/CodeGen/X86/unfold-masked-merge-vector-variablemask.ll
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ define <2 x i8> @out_v2i8(<2 x i8> %x, <2 x i8> %y, <2 x i8> %mask) nounwind {
define <1 x i16> @out_v1i16(<1 x i16> %x, <1 x i16> %y, <1 x i16> %mask) nounwind {
; CHECK-LABEL: out_v1i16:
; CHECK: # %bb.0:
; CHECK-NEXT: movl %edx, %eax
; CHECK-NEXT: # kill: def $edx killed $edx def $rdx
; CHECK-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-NEXT: andl %edx, %edi
; CHECK-NEXT: notl %eax
; CHECK-NEXT: andl %esi, %eax
; CHECK-NEXT: orl %edi, %eax
; CHECK-NEXT: notl %edx
; CHECK-NEXT: andl %esi, %edx
; CHECK-NEXT: leal (%rdx,%rdi), %eax
; CHECK-NEXT: # kill: def $ax killed $ax killed $eax
; CHECK-NEXT: retq
%mx = and <1 x i16> %x, %mask
Expand Down Expand Up @@ -235,32 +236,38 @@ define <4 x i8> @out_v4i8_undef(<4 x i8> %x, <4 x i8> %y, <4 x i8> %mask) nounwi
define <2 x i16> @out_v2i16(<2 x i16> %x, <2 x i16> %y, <2 x i16> %mask) nounwind {
; CHECK-BASELINE-LABEL: out_v2i16:
; CHECK-BASELINE: # %bb.0:
; CHECK-BASELINE-NEXT: movl %r8d, %eax
; CHECK-BASELINE-NEXT: # kill: def $r9d killed $r9d def $r9
; CHECK-BASELINE-NEXT: # kill: def $r8d killed $r8d def $r8
; CHECK-BASELINE-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-BASELINE-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-BASELINE-NEXT: andl %r9d, %esi
; CHECK-BASELINE-NEXT: andl %r8d, %edi
; CHECK-BASELINE-NEXT: notl %eax
; CHECK-BASELINE-NEXT: notl %r8d
; CHECK-BASELINE-NEXT: notl %r9d
; CHECK-BASELINE-NEXT: andl %ecx, %r9d
; CHECK-BASELINE-NEXT: orl %esi, %r9d
; CHECK-BASELINE-NEXT: andl %edx, %eax
; CHECK-BASELINE-NEXT: orl %edi, %eax
; CHECK-BASELINE-NEXT: leal (%r9,%rsi), %ecx
; CHECK-BASELINE-NEXT: andl %edx, %r8d
; CHECK-BASELINE-NEXT: leal (%r8,%rdi), %eax
; CHECK-BASELINE-NEXT: # kill: def $ax killed $ax killed $eax
; CHECK-BASELINE-NEXT: movl %r9d, %edx
; CHECK-BASELINE-NEXT: movl %ecx, %edx
; CHECK-BASELINE-NEXT: retq
;
; CHECK-SSE1-LABEL: out_v2i16:
; CHECK-SSE1: # %bb.0:
; CHECK-SSE1-NEXT: movl %r8d, %eax
; CHECK-SSE1-NEXT: # kill: def $r9d killed $r9d def $r9
; CHECK-SSE1-NEXT: # kill: def $r8d killed $r8d def $r8
; CHECK-SSE1-NEXT: # kill: def $esi killed $esi def $rsi
; CHECK-SSE1-NEXT: # kill: def $edi killed $edi def $rdi
; CHECK-SSE1-NEXT: andl %r9d, %esi
; CHECK-SSE1-NEXT: andl %r8d, %edi
; CHECK-SSE1-NEXT: notl %eax
; CHECK-SSE1-NEXT: notl %r8d
; CHECK-SSE1-NEXT: notl %r9d
; CHECK-SSE1-NEXT: andl %ecx, %r9d
; CHECK-SSE1-NEXT: orl %esi, %r9d
; CHECK-SSE1-NEXT: andl %edx, %eax
; CHECK-SSE1-NEXT: orl %edi, %eax
; CHECK-SSE1-NEXT: leal (%r9,%rsi), %ecx
; CHECK-SSE1-NEXT: andl %edx, %r8d
; CHECK-SSE1-NEXT: leal (%r8,%rdi), %eax
; CHECK-SSE1-NEXT: # kill: def $ax killed $ax killed $eax
; CHECK-SSE1-NEXT: movl %r9d, %edx
; CHECK-SSE1-NEXT: movl %ecx, %edx
; CHECK-SSE1-NEXT: retq
;
; CHECK-SSE2-LABEL: out_v2i16:
Expand Down