[llvm] [X86] Return more accurate getNumSupportedRegs() (NFC) (PR #71690)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 8 07:16:09 PST 2023


https://github.com/nikic created https://github.com/llvm/llvm-project/pull/71690

https://github.com/llvm/llvm-project/pull/70222 introduced a hook to return a more accurate number of registers supported for a specific subtarget (rather than target). However, while x86 registers were reordered to allow using this, the implementation currently still always returns NUM_TARGET_REGS.

Adjust it to return a smaller number of registers depending on availability of avx/avx512/amx.

The actual impact of this seems to be pretty small, on the order of 0.05% (http://llvm-compile-time-tracker.com/compare.php?from=d687057de8babc215d1cc883514085704ede5ab4&to=d218b6dece5d492e3a258524f4679b17c5d565d8&stat=instructions:u).

>From d218b6dece5d492e3a258524f4679b17c5d565d8 Mon Sep 17 00:00:00 2001
From: Nikita Popov <npopov at redhat.com>
Date: Wed, 8 Nov 2023 15:27:11 +0100
Subject: [PATCH] [X86] Return more accurate getNumSupportedRegs() (NFC)

https://github.com/llvm/llvm-project/pull/70222 introduces a hook
to return a more accurate number of registers supported for a
specific subtarget (rather than target). However, while x86 registers
were reordered to allow using this, the implementation still always
returned NUM_TARGET_REGS.

Adjust it to return a smaller number of registers depending on
availability of avx/avx512/amx.
---
 llvm/lib/Target/X86/X86RegisterInfo.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/X86/X86RegisterInfo.cpp b/llvm/lib/Target/X86/X86RegisterInfo.cpp
index 4fd8b6d17e862e0..b0bea42cafe11de 100644
--- a/llvm/lib/Target/X86/X86RegisterInfo.cpp
+++ b/llvm/lib/Target/X86/X86RegisterInfo.cpp
@@ -634,7 +634,15 @@ unsigned X86RegisterInfo::getNumSupportedRegs(const MachineFunction &MF) const {
          (X86::K6_K7 + 1 == X86::TMMCFG) &&
          (X86::TMM7 + 1 == X86::NUM_TARGET_REGS) &&
          "Register number may be incorrect");
-  return X86::NUM_TARGET_REGS;
+
+  const X86Subtarget &ST = MF.getSubtarget<X86Subtarget>();
+  if (ST.hasAMXTILE())
+    return X86::TMM7 + 1;
+  if (ST.hasAVX512())
+    return X86::K6_K7 + 1;
+  if (ST.hasAVX())
+    return X86::YMM15 + 1;
+  return X86::R15WH + 1;
 }
 
 bool X86RegisterInfo::isArgumentRegister(const MachineFunction &MF,



More information about the llvm-commits mailing list