[PATCH] D136999: [AArch64] Lower READCYCLECOUNTER using MRS CNTVCT_EL0
Salvatore Dipietro via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 28 16:54:29 PDT 2022
salvatoredipietro created this revision.
salvatoredipietro added a reviewer: llvm-commits.
salvatoredipietro added a project: LLVM.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
salvatoredipietro requested review of this revision.
As suggested in D12425 <https://reviews.llvm.org/D12425> it would be better for the readcyclecounter function on ARM architecture to use the CNTVCT_EL0 register (Counter-timer Virtual Count register) instead of the PMCCNTR_EL0 (Performance Monitors Cycle Count Register) because the PMCCNTR_EL0 is a PMU register which, depending on the configuration, it might always return zeroes and it doesn't guaranteed to always be increased.
https://reviews.llvm.org/D136999
Files:
llvm/lib/Target/AArch64/AArch64InstrInfo.td
llvm/test/CodeGen/AArch64/readcyclecounter.ll
Index: llvm/test/CodeGen/AArch64/readcyclecounter.ll
===================================================================
--- llvm/test/CodeGen/AArch64/readcyclecounter.ll
+++ llvm/test/CodeGen/AArch64/readcyclecounter.ll
@@ -37,7 +37,7 @@
define i64 @test_readcyclecounter() nounwind {
; CHECK-LABEL: test_readcyclecounter:
- ; PERFMON-NEXT: mrs x0, PMCCNTR_EL0
+ ; PERFMON-NEXT: mrs x0, CNTVCT_EL0
; NOPERFMON-NEXT: mov x0, xzr
; CHECK-NEXT: ret
%tmp0 = call i64 @llvm.readcyclecounter()
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.td
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.td
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.td
@@ -1487,9 +1487,9 @@
Sched<[]>;
}
-// The cycle counter PMC register is PMCCNTR_EL0.
+// The virtual cycle counter register is CNTVCT_EL0.
let Predicates = [HasPerfMon] in
-def : Pat<(readcyclecounter), (MRS 0xdce8)>;
+def : Pat<(readcyclecounter), (MRS 0xdf02)>;
// FPCR register
def : Pat<(i64 (int_aarch64_get_fpcr)), (MRS 0xda20)>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D136999.471687.patch
Type: text/x-patch
Size: 1079 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221028/99758c6d/attachment.bin>
More information about the llvm-commits
mailing list