[llvm] 058a33d - [X86] Account for high uop/resource usage in BSF/BSR instructions

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 03:20:20 PDT 2022


Author: Simon Pilgrim
Date: 2022-04-11T11:20:09+01:00
New Revision: 058a33d3c9249e9475cf1e42b9721251e816cd47

URL: https://github.com/llvm/llvm-project/commit/058a33d3c9249e9475cf1e42b9721251e816cd47
DIFF: https://github.com/llvm/llvm-project/commit/058a33d3c9249e9475cf1e42b9721251e816cd47.diff

LOG: [X86] Account for high uop/resource usage in BSF/BSR instructions

znver1/2 models were incorrectly modelling these as single uop instructions, instead of the microcoded nightmares they really are.

Now matches AMD SoG, Agner and instlatx64 numbers.

Fixes #54811

Added: 
    

Modified: 
    llvm/lib/Target/X86/X86ScheduleZnver1.td
    llvm/lib/Target/X86/X86ScheduleZnver2.td
    llvm/test/tools/llvm-mca/X86/Znver1/resources-x86_64.s
    llvm/test/tools/llvm-mca/X86/Znver2/resources-x86_64.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/X86/X86ScheduleZnver1.td b/llvm/lib/Target/X86/X86ScheduleZnver1.td
index f0e9e6cb1bae2..45a6af4ad2d27 100644
--- a/llvm/lib/Target/X86/X86ScheduleZnver1.td
+++ b/llvm/lib/Target/X86/X86ScheduleZnver1.td
@@ -220,8 +220,8 @@ defm : X86WriteRes<WriteBitTestRegLd,    [ZnALU,ZnAGU], 5, [1,1], 2>;
 defm : X86WriteRes<WriteBitTestSet,      [ZnALU], 2, [1], 2>;
 
 // Bit counts.
-defm : ZnWriteResPair<WriteBSF, [ZnALU], 3>;
-defm : ZnWriteResPair<WriteBSR, [ZnALU], 3>;
+defm : ZnWriteResPair<WriteBSF, [ZnALU], 3, [12], 6, 4, 2>;
+defm : ZnWriteResPair<WriteBSR, [ZnALU], 4, [16], 6, 4, 2>;
 defm : ZnWriteResPair<WriteLZCNT,          [ZnALU], 2>;
 defm : ZnWriteResPair<WriteTZCNT,          [ZnALU], 2>;
 defm : ZnWriteResPair<WritePOPCNT,         [ZnALU], 1>;

diff  --git a/llvm/lib/Target/X86/X86ScheduleZnver2.td b/llvm/lib/Target/X86/X86ScheduleZnver2.td
index daa2e8634aa7c..9bb8e7c38fb1d 100644
--- a/llvm/lib/Target/X86/X86ScheduleZnver2.td
+++ b/llvm/lib/Target/X86/X86ScheduleZnver2.td
@@ -219,8 +219,8 @@ defm : X86WriteRes<WriteBitTestRegLd,    [Zn2ALU,Zn2AGU], 5, [1,1], 2>;
 defm : X86WriteRes<WriteBitTestSet,      [Zn2ALU], 2, [1], 2>;
 
 // Bit counts.
-defm : Zn2WriteResPair<WriteBSF, [Zn2ALU], 3>;
-defm : Zn2WriteResPair<WriteBSR, [Zn2ALU], 4>;
+defm : Zn2WriteResPair<WriteBSF, [Zn2ALU], 3, [12], 6, 4, 2>;
+defm : Zn2WriteResPair<WriteBSR, [Zn2ALU], 4, [16], 6, 4, 2>;
 defm : Zn2WriteResPair<WriteLZCNT,          [Zn2ALU], 1>;
 defm : Zn2WriteResPair<WriteTZCNT,          [Zn2ALU], 2>;
 defm : Zn2WriteResPair<WritePOPCNT,         [Zn2ALU], 1>;

diff  --git a/llvm/test/tools/llvm-mca/X86/Znver1/resources-x86_64.s b/llvm/test/tools/llvm-mca/X86/Znver1/resources-x86_64.s
index 34c333633632b..b190803318a10 100644
--- a/llvm/test/tools/llvm-mca/X86/Znver1/resources-x86_64.s
+++ b/llvm/test/tools/llvm-mca/X86/Znver1/resources-x86_64.s
@@ -1169,18 +1169,18 @@ xorq (%rax), %rdi
 # CHECK-NEXT:  2      5     0.50    *      *            andq	%rsi, (%rax)
 # CHECK-NEXT:  2      5     0.50    *      *            lock		andq	%rsi, (%rax)
 # CHECK-NEXT:  2      5     0.50    *                   andq	(%rax), %rdi
-# CHECK-NEXT:  1      3     0.25                        bsfw	%si, %di
-# CHECK-NEXT:  1      3     0.25                        bsrw	%si, %di
-# CHECK-NEXT:  2      7     0.50    *                   bsfw	(%rax), %di
-# CHECK-NEXT:  2      7     0.50    *                   bsrw	(%rax), %di
-# CHECK-NEXT:  1      3     0.25                        bsfl	%esi, %edi
-# CHECK-NEXT:  1      3     0.25                        bsrl	%esi, %edi
-# CHECK-NEXT:  2      7     0.50    *                   bsfl	(%rax), %edi
-# CHECK-NEXT:  2      7     0.50    *                   bsrl	(%rax), %edi
-# CHECK-NEXT:  1      3     0.25                        bsfq	%rsi, %rdi
-# CHECK-NEXT:  1      3     0.25                        bsrq	%rsi, %rdi
-# CHECK-NEXT:  2      7     0.50    *                   bsfq	(%rax), %rdi
-# CHECK-NEXT:  2      7     0.50    *                   bsrq	(%rax), %rdi
+# CHECK-NEXT:  6      3     3.00                        bsfw	%si, %di
+# CHECK-NEXT:  6      4     4.00                        bsrw	%si, %di
+# CHECK-NEXT:  8      7     3.00    *                   bsfw	(%rax), %di
+# CHECK-NEXT:  8      8     4.00    *                   bsrw	(%rax), %di
+# CHECK-NEXT:  6      3     3.00                        bsfl	%esi, %edi
+# CHECK-NEXT:  6      4     4.00                        bsrl	%esi, %edi
+# CHECK-NEXT:  8      7     3.00    *                   bsfl	(%rax), %edi
+# CHECK-NEXT:  8      8     4.00    *                   bsrl	(%rax), %edi
+# CHECK-NEXT:  6      3     3.00                        bsfq	%rsi, %rdi
+# CHECK-NEXT:  6      4     4.00                        bsrq	%rsi, %rdi
+# CHECK-NEXT:  8      7     3.00    *                   bsfq	(%rax), %rdi
+# CHECK-NEXT:  8      8     4.00    *                   bsrq	(%rax), %rdi
 # CHECK-NEXT:  1      1     1.00                        bswapl	%eax
 # CHECK-NEXT:  1      1     1.00                        bswapq	%rax
 # CHECK-NEXT:  1      1     0.25                        btw	%si, %di
@@ -1957,7 +1957,7 @@ xorq (%rax), %rdi
 
 # CHECK:      Resource pressure per iteration:
 # CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]    [8]    [9]    [10]   [11]
-# CHECK-NEXT: 233.00 233.00 191.50 225.50 207.50 191.50 392.00  -      -      -      -     34.00
+# CHECK-NEXT: 233.00 233.00 230.50 264.50 246.50 230.50 392.00  -      -      -      -     34.00
 
 # CHECK:      Resource pressure by instruction:
 # CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]    [8]    [9]    [10]   [11]   Instructions:
@@ -2100,18 +2100,18 @@ xorq (%rax), %rdi
 # CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     andq	%rsi, (%rax)
 # CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     lock		andq	%rsi, (%rax)
 # CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     andq	(%rax), %rdi
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfw	%si, %di
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrw	%si, %di
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfw	(%rax), %di
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrw	(%rax), %di
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfl	%esi, %edi
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrl	%esi, %edi
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfl	(%rax), %edi
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrl	(%rax), %edi
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfq	%rsi, %rdi
-# CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrq	%rsi, %rdi
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfq	(%rax), %rdi
-# CHECK-NEXT: 0.50   0.50   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrq	(%rax), %rdi
+# CHECK-NEXT:  -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfw	%si, %di
+# CHECK-NEXT:  -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrw	%si, %di
+# CHECK-NEXT: 0.50   0.50   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfw	(%rax), %di
+# CHECK-NEXT: 0.50   0.50   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrw	(%rax), %di
+# CHECK-NEXT:  -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfl	%esi, %edi
+# CHECK-NEXT:  -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrl	%esi, %edi
+# CHECK-NEXT: 0.50   0.50   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfl	(%rax), %edi
+# CHECK-NEXT: 0.50   0.50   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrl	(%rax), %edi
+# CHECK-NEXT:  -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfq	%rsi, %rdi
+# CHECK-NEXT:  -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrq	%rsi, %rdi
+# CHECK-NEXT: 0.50   0.50   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfq	(%rax), %rdi
+# CHECK-NEXT: 0.50   0.50   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrq	(%rax), %rdi
 # CHECK-NEXT:  -      -     1.00   1.00   1.00   1.00    -      -      -      -      -      -     bswapl	%eax
 # CHECK-NEXT:  -      -     1.00   1.00   1.00   1.00    -      -      -      -      -      -     bswapq	%rax
 # CHECK-NEXT:  -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     btw	%si, %di

diff  --git a/llvm/test/tools/llvm-mca/X86/Znver2/resources-x86_64.s b/llvm/test/tools/llvm-mca/X86/Znver2/resources-x86_64.s
index c2907297b26c5..7ccf6efb43e36 100644
--- a/llvm/test/tools/llvm-mca/X86/Znver2/resources-x86_64.s
+++ b/llvm/test/tools/llvm-mca/X86/Znver2/resources-x86_64.s
@@ -1001,18 +1001,18 @@ xorq (%rax), %rdi
 # CHECK-NEXT:  1      1     0.25                        andq	%rsi, %rdi
 # CHECK-NEXT:  2      5     0.33    *      *            andq	%rsi, (%rax)
 # CHECK-NEXT:  2      5     0.33    *                   andq	(%rax), %rdi
-# CHECK-NEXT:  1      3     0.25                        bsfw	%si, %di
-# CHECK-NEXT:  1      4     0.25                        bsrw	%si, %di
-# CHECK-NEXT:  2      7     0.33    *                   bsfw	(%rax), %di
-# CHECK-NEXT:  2      8     0.33    *                   bsrw	(%rax), %di
-# CHECK-NEXT:  1      3     0.25                        bsfl	%esi, %edi
-# CHECK-NEXT:  1      4     0.25                        bsrl	%esi, %edi
-# CHECK-NEXT:  2      7     0.33    *                   bsfl	(%rax), %edi
-# CHECK-NEXT:  2      8     0.33    *                   bsrl	(%rax), %edi
-# CHECK-NEXT:  1      3     0.25                        bsfq	%rsi, %rdi
-# CHECK-NEXT:  1      4     0.25                        bsrq	%rsi, %rdi
-# CHECK-NEXT:  2      7     0.33    *                   bsfq	(%rax), %rdi
-# CHECK-NEXT:  2      8     0.33    *                   bsrq	(%rax), %rdi
+# CHECK-NEXT:  6      3     3.00                        bsfw	%si, %di
+# CHECK-NEXT:  6      4     4.00                        bsrw	%si, %di
+# CHECK-NEXT:  8      7     3.00    *                   bsfw	(%rax), %di
+# CHECK-NEXT:  8      8     4.00    *                   bsrw	(%rax), %di
+# CHECK-NEXT:  6      3     3.00                        bsfl	%esi, %edi
+# CHECK-NEXT:  6      4     4.00                        bsrl	%esi, %edi
+# CHECK-NEXT:  8      7     3.00    *                   bsfl	(%rax), %edi
+# CHECK-NEXT:  8      8     4.00    *                   bsrl	(%rax), %edi
+# CHECK-NEXT:  6      3     3.00                        bsfq	%rsi, %rdi
+# CHECK-NEXT:  6      4     4.00                        bsrq	%rsi, %rdi
+# CHECK-NEXT:  8      7     3.00    *                   bsfq	(%rax), %rdi
+# CHECK-NEXT:  8      8     4.00    *                   bsrq	(%rax), %rdi
 # CHECK-NEXT:  1      1     1.00                        bswapl	%eax
 # CHECK-NEXT:  1      1     1.00                        bswapq	%rax
 # CHECK-NEXT:  1      1     0.25                        btw	%si, %di
@@ -1696,7 +1696,7 @@ xorq (%rax), %rdi
 
 # CHECK:      Resource pressure per iteration:
 # CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]    [8]    [9]    [10]   [11]   [12]
-# CHECK-NEXT: 116.00 116.00 116.00 158.00 192.00 174.00 158.00 392.00  -      -      -      -     34.00
+# CHECK-NEXT: 116.00 116.00 116.00 197.00 231.00 213.00 197.00 392.00  -      -      -      -     34.00
 
 # CHECK:      Resource pressure by instruction:
 # CHECK-NEXT: [0]    [1]    [2]    [3]    [4]    [5]    [6]    [7]    [8]    [9]    [10]   [11]   [12]   Instructions:
@@ -1802,18 +1802,18 @@ xorq (%rax), %rdi
 # CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     andq	%rsi, %rdi
 # CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     andq	%rsi, (%rax)
 # CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     andq	(%rax), %rdi
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfw	%si, %di
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrw	%si, %di
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfw	(%rax), %di
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrw	(%rax), %di
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfl	%esi, %edi
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrl	%esi, %edi
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfl	(%rax), %edi
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrl	(%rax), %edi
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfq	%rsi, %rdi
-# CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrq	%rsi, %rdi
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsfq	(%rax), %rdi
-# CHECK-NEXT: 0.33   0.33   0.33   0.25   0.25   0.25   0.25    -      -      -      -      -      -     bsrq	(%rax), %rdi
+# CHECK-NEXT:  -      -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfw	%si, %di
+# CHECK-NEXT:  -      -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrw	%si, %di
+# CHECK-NEXT: 0.33   0.33   0.33   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfw	(%rax), %di
+# CHECK-NEXT: 0.33   0.33   0.33   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrw	(%rax), %di
+# CHECK-NEXT:  -      -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfl	%esi, %edi
+# CHECK-NEXT:  -      -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrl	%esi, %edi
+# CHECK-NEXT: 0.33   0.33   0.33   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfl	(%rax), %edi
+# CHECK-NEXT: 0.33   0.33   0.33   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrl	(%rax), %edi
+# CHECK-NEXT:  -      -      -     3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfq	%rsi, %rdi
+# CHECK-NEXT:  -      -      -     4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrq	%rsi, %rdi
+# CHECK-NEXT: 0.33   0.33   0.33   3.00   3.00   3.00   3.00    -      -      -      -      -      -     bsfq	(%rax), %rdi
+# CHECK-NEXT: 0.33   0.33   0.33   4.00   4.00   4.00   4.00    -      -      -      -      -      -     bsrq	(%rax), %rdi
 # CHECK-NEXT:  -      -      -     1.00   1.00   1.00   1.00    -      -      -      -      -      -     bswapl	%eax
 # CHECK-NEXT:  -      -      -     1.00   1.00   1.00   1.00    -      -      -      -      -      -     bswapq	%rax
 # CHECK-NEXT:  -      -      -     0.25   0.25   0.25   0.25    -      -      -      -      -      -     btw	%si, %di


        


More information about the llvm-commits mailing list