Skip to content

[DAGCombiner][X86] Improve chain handling in fold (fshl ld1, ld0, c) -> (ld0[ofs]) combine. #124871

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 2 commits 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
9 changes: 4 additions & 5 deletions llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11005,8 +11005,8 @@ SDValue DAGCombiner::visitFunnelShift(SDNode *N) {
auto *RHS = dyn_cast<LoadSDNode>(N1);
if (LHS && RHS && LHS->isSimple() && RHS->isSimple() &&
LHS->getAddressSpace() == RHS->getAddressSpace() &&
(LHS->hasOneUse() || RHS->hasOneUse()) && ISD::isNON_EXTLoad(RHS) &&
ISD::isNON_EXTLoad(LHS)) {
(LHS->hasNUsesOfValue(1, 0) || RHS->hasNUsesOfValue(1, 0)) &&
ISD::isNON_EXTLoad(RHS) && ISD::isNON_EXTLoad(LHS)) {
if (DAG.areNonVolatileConsecutiveLoads(LHS, RHS, BitWidth / 8, 1)) {
SDLoc DL(RHS);
uint64_t PtrOff =
Expand All @@ -11024,9 +11024,8 @@ SDValue DAGCombiner::visitFunnelShift(SDNode *N) {
VT, DL, RHS->getChain(), NewPtr,
RHS->getPointerInfo().getWithOffset(PtrOff), NewAlign,
RHS->getMemOperand()->getFlags(), RHS->getAAInfo());
// Replace the old load's chain with the new load's chain.
WorklistRemover DeadNodes(*this);
DAG.ReplaceAllUsesOfValueWith(N1.getValue(1), Load.getValue(1));
DAG.makeEquivalentMemoryOrdering(LHS, Load.getValue(1));
DAG.makeEquivalentMemoryOrdering(RHS, Load.getValue(1));
return Load;
}
}
Expand Down
23 changes: 23 additions & 0 deletions llvm/test/CodeGen/X86/fshl.ll
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,29 @@ define i64 @combine_fshl_load_i64(ptr %p) nounwind {
ret i64 %res
}

define i16 @combine_fshl_load_i16_chain_use(ptr %p, ptr %q, i16 %r) nounwind {
; X86-LABEL: combine_fshl_load_i16_chain_use:
; X86: # %bb.0:
; X86-NEXT: movzwl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl {{[0-9]+}}(%esp), %edx
; X86-NEXT: movl {{[0-9]+}}(%esp), %eax
; X86-NEXT: movzwl 1(%eax), %eax
; X86-NEXT: movw %cx, (%edx)
; X86-NEXT: retl
;
; X64-LABEL: combine_fshl_load_i16_chain_use:
; X64: # %bb.0:
; X64-NEXT: movzwl 1(%rdi), %eax
; X64-NEXT: movw %dx, (%rsi)
; X64-NEXT: retq
%p1 = getelementptr i16, ptr %p, i32 1
%ld0 = load i16, ptr %p
%ld1 = load i16, ptr %p1
%res = call i16 @llvm.fshl.i16(i16 %ld1, i16 %ld0, i16 8)
store i16 %r, ptr %q
ret i16 %res
}

!llvm.module.flags = !{!0}
!0 = !{i32 1, !"ProfileSummary", !1}
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
Expand Down