Skip to content
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

Backport for rust#127286 and rust#127260 #175

Merged
merged 5 commits into from
Jul 5, 2024
Merged
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
2 changes: 1 addition & 1 deletion llvm/lib/Target/X86/X86ISelDAGToDAG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@ bool X86DAGToDAGISel::matchAddressRecursively(SDValue N, X86ISelAddressMode &AM,
Src = Src.getOperand(0);
}

if (Src.getOpcode() == ISD::SHL && Src.hasOneUse()) {
if (Src.getOpcode() == ISD::SHL && Src.hasOneUse() && N->hasOneUse()) {
// Give up if the shift is not a valid scale factor [1,2,3].
SDValue ShlSrc = Src.getOperand(0);
SDValue ShlAmt = Src.getOperand(1);
Expand Down
11 changes: 8 additions & 3 deletions llvm/lib/Transforms/Utils/PromoteMemoryToRegister.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,13 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
SmallSet<DbgAssignIntrinsic *, 8> *DbgAssignsToDelete,
SmallSet<DPValue *, 8> *DPVAssignsToDelete) {
StoreInst *OnlyStore = Info.OnlyStore;
bool StoringGlobalVal = !isa<Instruction>(OnlyStore->getOperand(0));
Value *ReplVal = OnlyStore->getOperand(0);
// Loads may either load the stored value or uninitialized memory (undef).
// If the stored value may be poison, then replacing an uninitialized memory
// load with it would be incorrect. If the store dominates the load, we know
// it is always initialized.
bool RequireDominatingStore =
isa<Instruction>(ReplVal) || !isGuaranteedNotToBePoison(ReplVal);
BasicBlock *StoreBB = OnlyStore->getParent();
int StoreIndex = -1;

Expand All @@ -528,7 +534,7 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
// only value stored to the alloca. We can do this if the value is
// dominated by the store. If not, we use the rest of the mem2reg machinery
// to insert the phi nodes as needed.
if (!StoringGlobalVal) { // Non-instructions are always dominated.
if (RequireDominatingStore) {
if (LI->getParent() == StoreBB) {
// If we have a use that is in the same block as the store, compare the
// indices of the two instructions to see which one came first. If the
Expand All @@ -551,7 +557,6 @@ rewriteSingleStoreAlloca(AllocaInst *AI, AllocaInfo &Info, LargeBlockInfo &LBI,
}

// Otherwise, we *can* safely rewrite this load.
Value *ReplVal = OnlyStore->getOperand(0);
// If the replacement value is the load, this must occur in unreachable
// code.
if (ReplVal == LI)
Expand Down
28 changes: 28 additions & 0 deletions llvm/test/CodeGen/X86/addr-mode-matcher-3.ll
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,31 @@ define i32 @mask_offset_scale_zext_i32_i64(ptr %base, i32 %i) {
%load = load i32, ptr %arrayidx, align 4
ret i32 %load
}

; PR97533 - multiple uses of shl node (add + gep) in the same dependency chain.
define i64 @add_shl_zext(ptr %ptr, i8 %arg) nounwind {
; X86-LABEL: add_shl_zext:
; X86: # %bb.0:
; X86-NEXT: pushl %esi
; X86-NEXT: movzbl {{[0-9]+}}(%esp), %ecx
; X86-NEXT: movl {{[0-9]+}}(%esp), %esi
; X86-NEXT: movl 4(%esi,%ecx,4), %edx
; X86-NEXT: leal (,%ecx,8), %eax
; X86-NEXT: addl (%esi,%ecx,4), %eax
; X86-NEXT: adcl $0, %edx
; X86-NEXT: popl %esi
; X86-NEXT: retl
;
; X64-LABEL: add_shl_zext:
; X64: # %bb.0:
; X64-NEXT: movzbl %sil, %eax
; X64-NEXT: shll $3, %eax
; X64-NEXT: addq (%rdi,%rax), %rax
; X64-NEXT: retq
%idx = zext i8 %arg to i64
%gep = getelementptr ptr, ptr %ptr, i64 %idx
%val = load i64, ptr %gep, align 8
%shl = shl i64 %idx, 3
%sum = add i64 %val, %shl
ret i64 %sum
}
20 changes: 12 additions & 8 deletions llvm/test/CodeGen/X86/sttni.ll
Original file line number Diff line number Diff line change
Expand Up @@ -341,9 +341,10 @@ define i32 @pcmpestri_reg_diff_i16(<8 x i16> %lhs, i32 %lhs_len, <8 x i16> %rhs,
; X64-NEXT: .LBB8_2: # %compare
; X64-NEXT: movdqa %xmm0, -{{[0-9]+}}(%rsp)
; X64-NEXT: andl $7, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx,2), %eax
; X64-NEXT: addl %ecx, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx), %eax
; X64-NEXT: movdqa %xmm1, -{{[0-9]+}}(%rsp)
; X64-NEXT: subw -40(%rsp,%rcx,2), %ax
; X64-NEXT: subw -40(%rsp,%rcx), %ax
; X64-NEXT: movzwl %ax, %eax
; X64-NEXT: retq
entry:
Expand Down Expand Up @@ -481,9 +482,10 @@ define i32 @pcmpestri_mem_diff_i16(ptr %lhs_ptr, i32 %lhs_len, ptr %rhs_ptr, i32
; X64-NEXT: .LBB11_2: # %compare
; X64-NEXT: movdqa %xmm1, -{{[0-9]+}}(%rsp)
; X64-NEXT: andl $7, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx,2), %eax
; X64-NEXT: addl %ecx, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx), %eax
; X64-NEXT: movdqa %xmm0, -{{[0-9]+}}(%rsp)
; X64-NEXT: subw -40(%rsp,%rcx,2), %ax
; X64-NEXT: subw -40(%rsp,%rcx), %ax
; X64-NEXT: movzwl %ax, %eax
; X64-NEXT: retq
entry:
Expand Down Expand Up @@ -795,9 +797,10 @@ define i32 @pcmpistri_reg_diff_i16(<8 x i16> %lhs, <8 x i16> %rhs) nounwind {
; X64-NEXT: .LBB20_2: # %compare
; X64-NEXT: movdqa %xmm0, -{{[0-9]+}}(%rsp)
; X64-NEXT: andl $7, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx,2), %eax
; X64-NEXT: addl %ecx, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx), %eax
; X64-NEXT: movdqa %xmm1, -{{[0-9]+}}(%rsp)
; X64-NEXT: subw -40(%rsp,%rcx,2), %ax
; X64-NEXT: subw -40(%rsp,%rcx), %ax
; X64-NEXT: movzwl %ax, %eax
; X64-NEXT: retq
entry:
Expand Down Expand Up @@ -915,9 +918,10 @@ define i32 @pcmpistri_mem_diff_i16(ptr %lhs_ptr, ptr %rhs_ptr) nounwind {
; X64-NEXT: .LBB23_2: # %compare
; X64-NEXT: movdqa %xmm1, -{{[0-9]+}}(%rsp)
; X64-NEXT: andl $7, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx,2), %eax
; X64-NEXT: addl %ecx, %ecx
; X64-NEXT: movzwl -24(%rsp,%rcx), %eax
; X64-NEXT: movdqa %xmm0, -{{[0-9]+}}(%rsp)
; X64-NEXT: subw -40(%rsp,%rcx,2), %ax
; X64-NEXT: subw -40(%rsp,%rcx), %ax
; X64-NEXT: movzwl %ax, %eax
; X64-NEXT: retq
entry:
Expand Down
Loading