[llvm] [GlobalISel][LLT] Introduce FPInfo for LLT (Enable bfloat, ppc128float and others in GlobalISel) (PR #155107)
Serge Pavlov via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 2 08:58:57 PST 2025
spavloff wrote:
I enabled extended types for all targets, including the necessary TableGen changes, and ran `check-llvm`. The distribution of the observed errors by target is:
| Target |Errs |
|---------|-----|
| AArch64 | 189 |
| AMDGPU | 422 |
| ARM | 6 |
| Mips | 33 |
| PowerPC | 10 |
| RISCV | 51 |
| SPIRV | 2 |
| X86 | 53 |
Most errors occur because a specific type is used instead of a generic scalar. These failures could be fixed almost mechanically. However, in many cases, the chosen type seems arbitrary. This is often caused by the default constructor LLT(MVT VT, bool AllowExtendedLLT = false). When used without the second argument, it always uses the old behavior, even for targets that support the new types. As a solution, a global variable can store the new type support state. The attached patch implements this.
```
diff --git a/llvm/include/llvm/CodeGen/LowLevelTypeUtils.h b/llvm/include/llvm/CodeGen/LowLevelTypeUtils.h
index 4092509948ae..51a298eb8b24 100644
--- a/llvm/include/llvm/CodeGen/LowLevelTypeUtils.h
+++ b/llvm/include/llvm/CodeGen/LowLevelTypeUtils.h
@@ -27,8 +27,7 @@ class Type;
struct fltSemantics;
/// Construct a low-level type based on an LLVM type.
-LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL,
- bool AllowExtendedLLT = false);
+LLVM_ABI LLT getLLTForType(Type &Ty, const DataLayout &DL);
/// Get a rough equivalent of an MVT for a given LLT. MVT can't distinguish
/// pointers, so these will convert to a plain integer.
@@ -37,11 +36,11 @@ LLVM_ABI EVT getApproximateEVTForLLT(LLT Ty, LLVMContext &Ctx);
/// Get a rough equivalent of an LLT for a given MVT. LLT does not yet support
/// scalarable vector types, and will assert if used.
-LLVM_ABI LLT getLLTForMVT(MVT Ty, bool AllowExtendedLLT = false);
+LLVM_ABI LLT getLLTForMVT(MVT Ty);
/// Get the appropriate floating point arithmetic semantic based on the bit size
/// of the given scalar LLT.
LLVM_ABI const llvm::fltSemantics &getFltSemanticForLLT(LLT Ty);
-} // namespace llvm
+}
#endif // LLVM_CODEGEN_LOWLEVELTYPEUTILS_H
diff --git a/llvm/include/llvm/CodeGenTypes/LowLevelType.h b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
index 1456700ce0bb..95940ef6cbb3 100644
--- a/llvm/include/llvm/CodeGenTypes/LowLevelType.h
+++ b/llvm/include/llvm/CodeGenTypes/LowLevelType.h
@@ -230,7 +230,7 @@ public:
init(Info, EC, SizeInBits, AddressSpace, Sem);
}
- LLVM_ABI explicit LLT(MVT VT, bool AllowExtendedLLT = false);
+ LLVM_ABI explicit LLT(MVT VT);
explicit constexpr LLT() : RawData(0), Info(static_cast<Kind>(0)) {}
constexpr bool isToken() const {
@@ -602,6 +602,11 @@ public:
constexpr uint64_t getUniqueRAWLLTData() const {
return ((uint64_t)RawData) | ((uint64_t)Info) << 60;
}
+
+ static bool getUseExtended() { return ExtendedLLT; }
+ static void setUseExtended(bool Enable) { ExtendedLLT = Enable; }
+private:
+ static bool ExtendedLLT;
};
inline raw_ostream &operator<<(raw_ostream &OS, const LLT &Ty) {
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index f3c5f125c3e7..12253fa6065f 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -4150,6 +4150,10 @@ bool IRTranslator::runOnMachineFunction(MachineFunction &CurMF) {
return false;
}
+ // Enable globally extended LLT types.
+ if (TM.Options.EnableGlobalISelExtendedLLT)
+ LLT::setUseExtended(true);
+
// Release the per-function state when we return, whether we succeeded or not.
auto FinalizeOnReturn = make_scope_exit([this]() { finalizeFunction(); });
diff --git a/llvm/lib/CodeGen/LowLevelTypeUtils.cpp b/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
index b3f397610c71..d27e76daa146 100644
--- a/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
+++ b/llvm/lib/CodeGen/LowLevelTypeUtils.cpp
@@ -17,10 +17,10 @@
#include "llvm/IR/DerivedTypes.h"
using namespace llvm;
-LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL, bool AllowExtendedLLT) {
+LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL) {
if (auto *VTy = dyn_cast<VectorType>(&Ty)) {
auto EC = VTy->getElementCount();
- LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL, AllowExtendedLLT);
+ LLT ScalarTy = getLLTForType(*VTy->getElementType(), DL);
if (EC.isScalar())
return ScalarTy;
return LLT::vector(EC, ScalarTy);
@@ -38,7 +38,7 @@ LLT llvm::getLLTForType(Type &Ty, const DataLayout &DL, bool AllowExtendedLLT) {
assert(SizeInBits != 0 && "invalid zero-sized type");
// Return simple scalar
- if (!AllowExtendedLLT)
+ if (!LLT::getUseExtended())
return LLT::scalar(SizeInBits);
// Choose more precise LLT variant
@@ -109,8 +109,8 @@ EVT llvm::getApproximateEVTForLLT(LLT Ty, LLVMContext &Ctx) {
return EVT::getIntegerVT(Ctx, Ty.getSizeInBits());
}
-LLT llvm::getLLTForMVT(MVT VT, bool AllowExtendedLLT) {
- return LLT(VT, AllowExtendedLLT);
+LLT llvm::getLLTForMVT(MVT VT) {
+ return LLT(VT);
}
const llvm::fltSemantics &llvm::getFltSemanticForLLT(LLT Ty) {
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 0752427dff19..79c9bbc92f54 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1051,11 +1051,11 @@ EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy,
}
LLT TargetLoweringBase::getLLTForType(Type &Ty, const DataLayout &DL) const {
- return llvm::getLLTForType(Ty, DL, TM.Options.EnableGlobalISelExtendedLLT);
+ return llvm::getLLTForType(Ty, DL);
}
LLT TargetLoweringBase::getLLTForMVT(MVT Ty) const {
- return llvm::getLLTForMVT(Ty, TM.Options.EnableGlobalISelExtendedLLT);
+ return llvm::getLLTForMVT(Ty);
}
bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
diff --git a/llvm/lib/CodeGenTypes/LowLevelType.cpp b/llvm/lib/CodeGenTypes/LowLevelType.cpp
index 229c9d542fe9..9418d54058c4 100644
--- a/llvm/lib/CodeGenTypes/LowLevelType.cpp
+++ b/llvm/lib/CodeGenTypes/LowLevelType.cpp
@@ -16,6 +16,8 @@
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+bool LLT::ExtendedLLT = false;
+
// Repeat logic of MVT::getFltSemantics to exclude CodeGen dependency
static LLT::FpSemantics getFpSemanticsForMVT(MVT VT) {
switch (VT.getScalarType().SimpleTy) {
@@ -38,8 +40,8 @@ static LLT::FpSemantics getFpSemanticsForMVT(MVT VT) {
}
}
-LLT::LLT(MVT VT, bool AllowExtendedLLT) {
- if (!AllowExtendedLLT) {
+LLT::LLT(MVT VT) {
+ if (!ExtendedLLT) {
if (VT.isVector()) {
bool AsVector = VT.getVectorMinNumElements() > 1 || VT.isScalableVector();
Kind Info = AsVector ? Kind::VECTOR_ANY : Kind::ANY_SCALAR;
diff --git a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
index 5ef4ac65cde8..bc73c44e94c4 100644
--- a/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
+++ b/llvm/utils/TableGen/Common/GlobalISel/GlobalISelMatchTable.cpp
@@ -305,6 +305,8 @@ void MatchTable::emitDeclaration(raw_ostream &OS) const {
OS << " constexpr static uint8_t MatchTable" << ID << "[] = {";
LineBreak.emit(OS, true, *this);
+ LLT::setUseExtended(AllowExtendedLLT);
+
// We want to display the table index of each line in a consistent
// manner. It has to appear as a column on the left side of the table.
// To determine how wide the column needs to be, check how many characters
@@ -475,10 +477,10 @@ std::optional<LLTCodeGen> llvm::gi::MVTToLLT(MVT::SimpleValueType SVT) {
MVT VT(SVT);
if (VT.isVector() && !VT.getVectorElementCount().isScalar())
- return LLTCodeGen(LLT(VT, AllowExtendedLLT));
+ return LLTCodeGen(LLT(VT));
if (VT.isInteger() || VT.isFloatingPoint())
- return LLTCodeGen(LLT(VT, AllowExtendedLLT));
+ return LLTCodeGen(LLT(VT));
return std::nullopt;
}
```
https://github.com/llvm/llvm-project/pull/155107
More information about the llvm-commits
mailing list