[PATCH] D141809: [DAG] Recombine (binop (shift x y))
Amaury SECHET via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 15 15:35:42 PST 2023
deadalnix created this revision.
deadalnix added reviewers: RKSimon, craig.topper, efriedma, spatel, lebedev.ri.
Herald added subscribers: StephenFan, ecnelises, pengfei, hiraditya.
Herald added a project: All.
deadalnix requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This helps address regressions in D127115 <https://reviews.llvm.org/D127115> .
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D141809
Files:
llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
llvm/test/CodeGen/X86/bool-math.ll
Index: llvm/test/CodeGen/X86/bool-math.ll
===================================================================
--- llvm/test/CodeGen/X86/bool-math.ll
+++ llvm/test/CodeGen/X86/bool-math.ll
@@ -262,10 +262,9 @@
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
Index: llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9923,16 +9923,23 @@
// 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141809.489403.patch
Type: text/x-patch
Size: 2019 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230115/58a6b97d/attachment.bin>
More information about the llvm-commits
mailing list