Skip to content

Commit

Permalink
[DAG] Recombine (binop (shift x y))
Browse files Browse the repository at this point in the history
This helps address regressions in D127115 .

Reviewed By: lebedev.ri

Differential Revision: https://reviews.llvm.org/D141809
  • Loading branch information
deadalnix committed Jan 16, 2023
1 parent 2d73295 commit 396ad40
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
21 changes: 14 additions & 7 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9923,16 +9923,23 @@ SDValue DAGCombiner::visitSRL(SDNode *N) {
// However when after the source operand of SRL is optimized into AND, the SRL
// itself may not be optimized further. Look for it and add the BRCOND into
// the worklist.
//
// The also tends to happen for binary operations when SimplifyDemandedBits
// is involved.
//
// FIXME: This is unecessary if we process the DAG in topological order,
// which we plan to do. This workaround can be removed once the DAG is
// processed in topological order.
if (N->hasOneUse()) {
SDNode *Use = *N->use_begin();
if (Use->getOpcode() == ISD::BRCOND)
AddToWorklist(Use);
else if (Use->getOpcode() == ISD::TRUNCATE && Use->hasOneUse()) {
// Also look pass the truncate.

// Look pass the truncate.
if (Use->getOpcode() == ISD::TRUNCATE && Use->hasOneUse())
Use = *Use->use_begin();
if (Use->getOpcode() == ISD::BRCOND)
AddToWorklist(Use);
}

if (Use->getOpcode() == ISD::BRCOND || Use->getOpcode() == ISD::AND ||
Use->getOpcode() == ISD::OR || Use->getOpcode() == ISD::XOR)
AddToWorklist(Use);
}

// Try to transform this shift into a multiply-high if
Expand Down
5 changes: 2 additions & 3 deletions llvm/test/CodeGen/X86/bool-math.ll
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ define i8 @low_bit_select_constants_bigger_true_narrower_result(i16 %x) {
define i1 @opaque_constant(i48 %x, i48 %y) {
; X64-LABEL: opaque_constant:
; X64: # %bb.0:
; X64-NEXT: movq %rsi, %rax
; X64-NEXT: shrq $32, %rdi
; X64-NEXT: movq %rdi, %rax
; X64-NEXT: xorq %rsi, %rax
; X64-NEXT: shrq $32, %rax
; X64-NEXT: xorl %edi, %eax
; X64-NEXT: andl $1, %eax
; X64-NEXT: # kill: def $al killed $al killed $rax
; X64-NEXT: retq
Expand Down

0 comments on commit 396ad40

Please sign in to comment.