Skip to content

Commit

Permalink
[DAG] Peek through zext/trunc in haveNoCommonBitsSet.
Browse files Browse the repository at this point in the history
This limitation was discovered thanks to some regression in D127115 .

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D147821
  • Loading branch information
deadalnix committed Apr 11, 2023
1 parent 25ed0c2 commit 9041e1f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
11 changes: 11 additions & 0 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
Expand Up @@ -5054,6 +5054,10 @@ static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B) {
SDValue Other) {
if (SDValue NotOperand =
getBitwiseNotOperand(Not, Mask, /* AllowUndefs */ true)) {
if (NotOperand->getOpcode() == ISD::ZERO_EXTEND ||
NotOperand->getOpcode() == ISD::TRUNCATE)
NotOperand = NotOperand->getOperand(0);

if (Other == NotOperand)
return true;
if (Other->getOpcode() == ISD::AND)
Expand All @@ -5062,6 +5066,13 @@ static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B) {
}
return false;
};

if (A->getOpcode() == ISD::ZERO_EXTEND || A->getOpcode() == ISD::TRUNCATE)
A = A->getOperand(0);

if (B->getOpcode() == ISD::ZERO_EXTEND || B->getOpcode() == ISD::TRUNCATE)
B = B->getOperand(0);

if (A->getOpcode() == ISD::AND)
return MatchNoCommonBitsPattern(A->getOperand(0), A->getOperand(1), B) ||
MatchNoCommonBitsPattern(A->getOperand(1), A->getOperand(0), B);
Expand Down
10 changes: 3 additions & 7 deletions llvm/test/CodeGen/X86/add-and-not.ll
Expand Up @@ -311,21 +311,17 @@ define ptr @gep_and_xor_const(ptr %a) {
define i64 @add_and_xor_const_ext_trunc(i64 %x) {
; X86-LABEL: add_and_xor_const_ext_trunc:
; X86: # %bb.0:
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-NEXT: movl %ecx, %eax
; X86-NEXT: notl %eax
; X86-NEXT: andl $1, %eax
; X86-NEXT: addl %ecx, %eax
; X86-NEXT: adcl $0, %edx
; X86-NEXT: orl $1, %eax
; X86-NEXT: retl
;
; X64-LABEL: add_and_xor_const_ext_trunc:
; X64: # %bb.0:
; X64-NEXT: movl %edi, %eax
; X64-NEXT: notl %eax
; X64-NEXT: andl $1, %eax
; X64-NEXT: addq %rdi, %rax
; X64-NEXT: orq %rdi, %rax
; X64-NEXT: retq
%t = trunc i64 %x to i32
%xor = xor i32 %t, -1
Expand Down

0 comments on commit 9041e1f

Please sign in to comment.