From 79ed672fa331bc2d4c5438b572b0060c5c314eb6 Mon Sep 17 00:00:00 2001 From: Andrea Di Biagio Date: Sun, 10 May 2020 18:55:58 +0100 Subject: [PATCH] [MCA][InstrBuilder] Correctly mark reserved resources in initializeUsedResources. This fixes a bug reported by Alex Renda on LLVMDev where mca did not correctly mark a resource group as "reserved". (See http://lists.llvm.org/pipermail/llvm-dev/2020-May/141485.html). The issue was caused by a wrong check in function `initializeUsedResources`. As a consequence of this, a resource group was left unreserved, and its field `NumUnits` incorrectly reported an unrealistic number of consumed resource units. This patch fixes the issue with the handling of reserved resources in the InstrBuilder class, and adds a simple test for it. Ideally, as suggested by Andy Trick, most of these problems will disappear if in the future we will introduce a (optional) DelayCycles vector for SchedWriteRes. --- lib/MCA/InstrBuilder.cpp | 5 ++- .../llvm-mca/X86/Haswell/reserved-resources.s | 45 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/tools/llvm-mca/X86/Haswell/reserved-resources.s diff --git a/lib/MCA/InstrBuilder.cpp b/lib/MCA/InstrBuilder.cpp index b2503f348d6..24e2a9d2f0c 100644 --- a/lib/MCA/InstrBuilder.cpp +++ b/lib/MCA/InstrBuilder.cpp @@ -160,8 +160,11 @@ static void initializeUsedResources(InstrDesc &ID, if (countPopulation(RPC.first) > 1 && !RPC.second.isReserved()) { // Remove the leading 1 from the resource group mask. uint64_t Mask = RPC.first ^ PowerOf2Floor(RPC.first); - if ((Mask & UsedResourceUnits) == Mask) + uint64_t MaxResourceUnits = countPopulation(Mask); + if (RPC.second.NumUnits > countPopulation(Mask)) { RPC.second.setReserved(); + RPC.second.NumUnits = MaxResourceUnits; + } } } diff --git a/test/tools/llvm-mca/X86/Haswell/reserved-resources.s b/test/tools/llvm-mca/X86/Haswell/reserved-resources.s new file mode 100644 index 00000000000..18acd1ef686 --- /dev/null +++ b/test/tools/llvm-mca/X86/Haswell/reserved-resources.s @@ -0,0 +1,45 @@ +# NOTE: Assertions have been autogenerated by utils/update_mca_test_checks.py +# RUN: llvm-mca -mtriple=x86_64-unknown-unknown -mcpu=haswell -iterations=100 < %s | FileCheck %s + +fxrstor (%rsp) + +# CHECK: Iterations: 100 +# CHECK-NEXT: Instructions: 100 +# CHECK-NEXT: Total Cycles: 6403 +# CHECK-NEXT: Total uOps: 9000 + +# CHECK: Dispatch Width: 4 +# CHECK-NEXT: uOps Per Cycle: 1.41 +# CHECK-NEXT: IPC: 0.02 +# CHECK-NEXT: Block RThroughput: 22.5 + +# CHECK: Instruction Info: +# CHECK-NEXT: [1]: #uOps +# CHECK-NEXT: [2]: Latency +# CHECK-NEXT: [3]: RThroughput +# CHECK-NEXT: [4]: MayLoad +# CHECK-NEXT: [5]: MayStore +# CHECK-NEXT: [6]: HasSideEffects (U) + +# CHECK: [1] [2] [3] [4] [5] [6] Instructions: +# CHECK-NEXT: 90 64 16.50 * * U fxrstor (%rsp) + +# CHECK: Resources: +# CHECK-NEXT: [0] - HWDivider +# CHECK-NEXT: [1] - HWFPDivider +# CHECK-NEXT: [2] - HWPort0 +# CHECK-NEXT: [3] - HWPort1 +# CHECK-NEXT: [4] - HWPort2 +# CHECK-NEXT: [5] - HWPort3 +# CHECK-NEXT: [6] - HWPort4 +# CHECK-NEXT: [7] - HWPort5 +# CHECK-NEXT: [8] - HWPort6 +# CHECK-NEXT: [9] - HWPort7 + +# CHECK: Resource pressure per iteration: +# CHECK-NEXT: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] +# CHECK-NEXT: - - 4.00 1.00 16.50 16.50 - 1.00 2.00 - + +# CHECK: Resource pressure by instruction: +# CHECK-NEXT: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] Instructions: +# CHECK-NEXT: - - 4.00 1.00 16.50 16.50 - 1.00 2.00 - fxrstor (%rsp)