[X86] Fix AvoidStoreForwardingBlocks pass for negative displacements

Fixes https://bugs.llvm.org/show_bug.cgi?id=39926.

The size of the first copy was computed as
std::abs(std::abs(LdDisp2) - std::abs(LdDisp1)), which results in
skipped bytes if the signs of LdDisp2 and LdDisp1 differ. As far as
I can see, this should just be LdDisp2 - LdDisp1. The case where
LdDisp1 > LdDisp2 is already handled in the code above, in which case
LdDisp2 is set to LdDisp1 and this subtraction will evaluate to
Size1 = 0, which is the correct value to skip an overlapping copy.

Differential Revision: https://reviews.llvm.org/D55485

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@348750 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Nikita Popov
2018-12-10 10:16:50 +00:00
parent 6fb7d81b31
commit 7d9496dddc
2 changed files with 4 additions and 4 deletions
@@ -586,7 +586,7 @@ void X86AvoidSFBPass::breakBlockedCopies(
StDisp2 += OverlapDelta;
Size2 -= OverlapDelta;
}
Size1 = std::abs(std::abs(LdDisp2) - std::abs(LdDisp1));
Size1 = LdDisp2 - LdDisp1;
// Build a copy for the point until the current blocking store's
// displacement.
+3 -3
View File
@@ -8,9 +8,9 @@ define i8 @test_offset(i8* %base) {
; CHECK-NEXT: movb $0, 7(%rdi)
; CHECK-NEXT: movw $0, 5(%rdi)
; CHECK-NEXT: movl $0, 1(%rdi)
; CHECK-NEXT: movzwl -4(%rdi), %eax
; CHECK-NEXT: movw %ax, -{{[0-9]+}}(%rsp)
; CHECK-NEXT: movb -2(%rdi), %al
; CHECK-NEXT: movl -4(%rdi), %eax
; CHECK-NEXT: movl %eax, -{{[0-9]+}}(%rsp)
; CHECK-NEXT: movb (%rdi), %al
; CHECK-NEXT: movb %al, -{{[0-9]+}}(%rsp)
; CHECK-NEXT: movl 1(%rdi), %eax
; CHECK-NEXT: movl %eax, -{{[0-9]+}}(%rsp)