[llvm] [NFC][CodeGen] Add helper function to check SubReg validity (PR #181489)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 17 06:51:10 PST 2026
================
@@ -442,6 +442,37 @@ const TargetRegisterClass *TargetRegisterInfo::findCommonRegClass(
return getCommonSubClass(DefRC, SrcRC);
}
+bool TargetRegisterInfo::isSubRegValidForRegClass(const TargetRegisterClass *RC,
+ unsigned Idx) const {
+ // NoSubRegister is always valid.
+ if (!Idx)
+ return true;
+
+ // `Idx` is valid if the largest subclass of `RC` that supports
+ // sub-register index `Idx` is same as `RC`. That is, every physical
+ // register in `RC` support sub-register index `Idx`.
+ return getSubClassWithSubReg(RC, Idx) == RC;
+}
+
+bool TargetRegisterInfo::isSubRegValidForRegClass(
+ const TargetRegisterClass *RC, const TargetRegisterClass *DRC,
+ unsigned Idx) const {
+ // If no sub-register index is used, return true if `DRC` is a super-class
----------------
jurahul wrote:
Right, but since `getSubRegisterClass` can return null, this check does not work. See https://github.com/llvm/llvm-project/pull/181423 for an earlier attempt for this, which fails. I debugged one case and that started the discussion on discourse.
https://github.com/llvm/llvm-project/pull/181489
More information about the llvm-commits
mailing list