Skip to content

Commit 9041e1f

Browse files
committed
[DAG] Peek through zext/trunc in haveNoCommonBitsSet.
This limitation was discovered thanks to some regression in D127115 . Reviewed By: RKSimon Differential Revision: https://reviews.llvm.org/D147821
1 parent 25ed0c2 commit 9041e1f

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5054,6 +5054,10 @@ static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B) {
50545054
SDValue Other) {
50555055
if (SDValue NotOperand =
50565056
getBitwiseNotOperand(Not, Mask, /* AllowUndefs */ true)) {
5057+
if (NotOperand->getOpcode() == ISD::ZERO_EXTEND ||
5058+
NotOperand->getOpcode() == ISD::TRUNCATE)
5059+
NotOperand = NotOperand->getOperand(0);
5060+
50575061
if (Other == NotOperand)
50585062
return true;
50595063
if (Other->getOpcode() == ISD::AND)
@@ -5062,6 +5066,13 @@ static bool haveNoCommonBitsSetCommutative(SDValue A, SDValue B) {
50625066
}
50635067
return false;
50645068
};
5069+
5070+
if (A->getOpcode() == ISD::ZERO_EXTEND || A->getOpcode() == ISD::TRUNCATE)
5071+
A = A->getOperand(0);
5072+
5073+
if (B->getOpcode() == ISD::ZERO_EXTEND || B->getOpcode() == ISD::TRUNCATE)
5074+
B = B->getOperand(0);
5075+
50655076
if (A->getOpcode() == ISD::AND)
50665077
return MatchNoCommonBitsPattern(A->getOperand(0), A->getOperand(1), B) ||
50675078
MatchNoCommonBitsPattern(A->getOperand(1), A->getOperand(0), B);

llvm/test/CodeGen/X86/add-and-not.ll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -311,21 +311,17 @@ define ptr @gep_and_xor_const(ptr %a) {
311311
define i64 @add_and_xor_const_ext_trunc(i64 %x) {
312312
; X86-LABEL: add_and_xor_const_ext_trunc:
313313
; X86: # %bb.0:
314-
; X86-NEXT: movl {{[0-9]+}}(%esp), %ecx
314+
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
315315
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
316-
; X86-NEXT: movl %ecx, %eax
317-
; X86-NEXT: notl %eax
318-
; X86-NEXT: andl $1, %eax
319-
; X86-NEXT: addl %ecx, %eax
320-
; X86-NEXT: adcl $0, %edx
316+
; X86-NEXT: orl $1, %eax
321317
; X86-NEXT: retl
322318
;
323319
; X64-LABEL: add_and_xor_const_ext_trunc:
324320
; X64: # %bb.0:
325321
; X64-NEXT: movl %edi, %eax
326322
; X64-NEXT: notl %eax
327323
; X64-NEXT: andl $1, %eax
328-
; X64-NEXT: addq %rdi, %rax
324+
; X64-NEXT: orq %rdi, %rax
329325
; X64-NEXT: retq
330326
%t = trunc i64 %x to i32
331327
%xor = xor i32 %t, -1

0 commit comments

Comments
 (0)