From: Andrea Di Biagio Date: Sun, 10 May 2020 17:55:58 +0000 (+0100) Subject: [MCA][InstrBuilder] Correctly mark reserved resources in initializeUsedResources. X-Git-Tag: llvmorg-12-init~6465 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=47b95d7cf462b824b2fbea1eb1a64e9c3eaa1a95;p=platform%2Fupstream%2Fllvm.git [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. --- diff --git a/llvm/lib/MCA/InstrBuilder.cpp b/llvm/lib/MCA/InstrBuilder.cpp index b2503f3..24e2a9d 100644 --- a/llvm/lib/MCA/InstrBuilder.cpp +++ b/llvm/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/llvm/test/tools/llvm-mca/X86/Haswell/reserved-resources.s b/llvm/test/tools/llvm-mca/X86/Haswell/reserved-resources.s new file mode 100644 index 0000000..18acd1e --- /dev/null +++ b/llvm/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)