[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
https://github.com/arsenm ready_for_review https://github.com/llvm/llvm-project/pull/145197 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
https://github.com/arsenm updated
https://github.com/llvm/llvm-project/pull/145197
>From dfe7d53af6927c28dd0155c0c330013d466af495 Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Sun, 22 Jun 2025 09:12:19 +0900
Subject: [PATCH] DAG: Emit an error if trying to legalize read/write register
with illegal types
---
llvm/include/llvm/IR/DiagnosticInfo.h | 25 +
.../SelectionDAG/LegalizeIntegerTypes.cpp | 54 +++
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h | 4 ++
llvm/lib/IR/DiagnosticInfo.cpp| 4 ++
.../read-write-register-illegal-type.ll | 29 ++
5 files changed, 116 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/read-write-register-illegal-type.ll
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h
b/llvm/include/llvm/IR/DiagnosticInfo.h
index 862be04e0fc00..5f7225e878eb1 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -68,6 +68,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_Linker,
DK_Lowering,
+ DK_LegalizationFailure,
DK_DebugMetadataVersion,
DK_DebugMetadataInvalid,
DK_Instrumentation,
@@ -383,6 +384,30 @@ class LLVM_ABI DiagnosticInfoWithLocationBase : public
DiagnosticInfo {
DiagnosticLocation Loc;
};
+class LLVM_ABI DiagnosticInfoLegalizationFailure
+: public DiagnosticInfoWithLocationBase {
+private:
+ /// Message to be reported.
+ const Twine &MsgStr;
+
+public:
+ DiagnosticInfoLegalizationFailure(const Twine &MsgStr LLVM_LIFETIME_BOUND,
+const Function &Fn,
+const DiagnosticLocation &Loc,
+DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfoWithLocationBase(DK_LegalizationFailure, Severity, Fn,
+ Loc),
+MsgStr(MsgStr) {}
+
+ const Twine &getMsgStr() const { return MsgStr; }
+
+ void print(DiagnosticPrinter &DP) const override;
+
+ static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_LegalizationFailure;
+ }
+};
+
class LLVM_ABI DiagnosticInfoGenericWithLoc
: public DiagnosticInfoWithLocationBase {
private:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index dd64676222055..f5c467cbdeb1e 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
@@ -357,6 +358,9 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::PATCHPOINT:
Res = PromoteIntRes_PATCHPOINT(N);
break;
+ case ISD::READ_REGISTER:
+Res = PromoteIntRes_READ_REGISTER(N);
+break;
}
// If the result is null then the sub-method took care of registering it.
@@ -2076,6 +2080,9 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N,
unsigned OpNo) {
case ISD::PATCHPOINT:
Res = PromoteIntOp_PATCHPOINT(N, OpNo);
break;
+ case ISD::WRITE_REGISTER:
+Res = PromoteIntOp_WRITE_REGISTER(N, OpNo);
+break;
case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
Res = PromoteIntOp_VP_STRIDED(N, OpNo);
@@ -2840,6 +2847,15 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(SDNode
*N, unsigned OpNo) {
return SDValue(DAG.UpdateNodeOperands(N, NewOps), 0);
}
+SDValue DAGTypeLegalizer::PromoteIntOp_WRITE_REGISTER(SDNode *N,
+ unsigned OpNo) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.write_register with illegal type", Fn,
+ N->getDebugLoc()));
+ return N->getOperand(0);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(SDNode *N, unsigned OpNo) {
assert((N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
(N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
@@ -3114,6 +3130,10 @@ void DAGTypeLegalizer::ExpandIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::VSCALE:
ExpandIntRes_VSCALE(N, Lo, Hi);
break;
+
+ case ISD::READ_REGISTER:
+ExpandIntRes_READ_REGISTER(N, Lo, Hi);
+break;
}
// If Lo/Hi is null, the sub-method took care of registering results etc.
@@ -5453,6 +5473,18 @@ void DAGTypeLegalizer::ExpandIntRes_VSCALE(SDNode *N,
SDValue &Lo,
SplitInteger(Res, Lo, Hi);
}
+void DAGTypeLegalizer::ExpandIntRes_READ_REGISTER(SDNode *N, SDValue &Lo,
+ SDValue &Hi) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
llvmbot wrote:
@llvm/pr-subscribers-backend-aarch64
Author: Matt Arsenault (arsenm)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/145197.diff
5 Files Affected:
- (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+25)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (+26)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h (+2)
- (modified) llvm/lib/IR/DiagnosticInfo.cpp (+4)
- (added) llvm/test/CodeGen/AMDGPU/read-write-register-illegal-type.ll (+16)
``diff
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h
b/llvm/include/llvm/IR/DiagnosticInfo.h
index 862be04e0fc00..5f7225e878eb1 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -68,6 +68,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_Linker,
DK_Lowering,
+ DK_LegalizationFailure,
DK_DebugMetadataVersion,
DK_DebugMetadataInvalid,
DK_Instrumentation,
@@ -383,6 +384,30 @@ class LLVM_ABI DiagnosticInfoWithLocationBase : public
DiagnosticInfo {
DiagnosticLocation Loc;
};
+class LLVM_ABI DiagnosticInfoLegalizationFailure
+: public DiagnosticInfoWithLocationBase {
+private:
+ /// Message to be reported.
+ const Twine &MsgStr;
+
+public:
+ DiagnosticInfoLegalizationFailure(const Twine &MsgStr LLVM_LIFETIME_BOUND,
+const Function &Fn,
+const DiagnosticLocation &Loc,
+DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfoWithLocationBase(DK_LegalizationFailure, Severity, Fn,
+ Loc),
+MsgStr(MsgStr) {}
+
+ const Twine &getMsgStr() const { return MsgStr; }
+
+ void print(DiagnosticPrinter &DP) const override;
+
+ static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_LegalizationFailure;
+ }
+};
+
class LLVM_ABI DiagnosticInfoGenericWithLoc
: public DiagnosticInfoWithLocationBase {
private:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index dd64676222055..97199985ccd10 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
@@ -357,6 +358,9 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::PATCHPOINT:
Res = PromoteIntRes_PATCHPOINT(N);
break;
+ case ISD::READ_REGISTER:
+Res = PromoteIntRes_READ_REGISTER(N);
+break;
}
// If the result is null then the sub-method took care of registering it.
@@ -2076,6 +2080,9 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N,
unsigned OpNo) {
case ISD::PATCHPOINT:
Res = PromoteIntOp_PATCHPOINT(N, OpNo);
break;
+ case ISD::WRITE_REGISTER:
+Res = PromoteIntOp_WRITE_REGISTER(N, OpNo);
+break;
case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
Res = PromoteIntOp_VP_STRIDED(N, OpNo);
@@ -2840,6 +2847,15 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(SDNode
*N, unsigned OpNo) {
return SDValue(DAG.UpdateNodeOperands(N, NewOps), 0);
}
+SDValue DAGTypeLegalizer::PromoteIntOp_WRITE_REGISTER(SDNode *N,
+ unsigned OpNo) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.write_register with illegal type", Fn,
+ N->getDebugLoc()));
+ return N->getOperand(0);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(SDNode *N, unsigned OpNo) {
assert((N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
(N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
@@ -6314,6 +6330,16 @@ SDValue
DAGTypeLegalizer::PromoteIntRes_PATCHPOINT(SDNode *N) {
return Res.getValue(0);
}
+SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(SDNode *N) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
+
+ EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
+ ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+ return DAG.getPOISON(NVT);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N) {
SDLoc dl(N);
SDValue V0 = GetPromotedInteger(N->getOperand(0));
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index a541833684f38..453f89ee185b6 100644
--- a/llvm/lib/CodeGen/S
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
llvmbot wrote:
@llvm/pr-subscribers-llvm-globalisel
@llvm/pr-subscribers-backend-mips
Author: Matt Arsenault (arsenm)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/145197.diff
5 Files Affected:
- (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+25)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (+26)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h (+2)
- (modified) llvm/lib/IR/DiagnosticInfo.cpp (+4)
- (added) llvm/test/CodeGen/AMDGPU/read-write-register-illegal-type.ll (+16)
``diff
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h
b/llvm/include/llvm/IR/DiagnosticInfo.h
index 862be04e0fc00..5f7225e878eb1 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -68,6 +68,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_Linker,
DK_Lowering,
+ DK_LegalizationFailure,
DK_DebugMetadataVersion,
DK_DebugMetadataInvalid,
DK_Instrumentation,
@@ -383,6 +384,30 @@ class LLVM_ABI DiagnosticInfoWithLocationBase : public
DiagnosticInfo {
DiagnosticLocation Loc;
};
+class LLVM_ABI DiagnosticInfoLegalizationFailure
+: public DiagnosticInfoWithLocationBase {
+private:
+ /// Message to be reported.
+ const Twine &MsgStr;
+
+public:
+ DiagnosticInfoLegalizationFailure(const Twine &MsgStr LLVM_LIFETIME_BOUND,
+const Function &Fn,
+const DiagnosticLocation &Loc,
+DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfoWithLocationBase(DK_LegalizationFailure, Severity, Fn,
+ Loc),
+MsgStr(MsgStr) {}
+
+ const Twine &getMsgStr() const { return MsgStr; }
+
+ void print(DiagnosticPrinter &DP) const override;
+
+ static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_LegalizationFailure;
+ }
+};
+
class LLVM_ABI DiagnosticInfoGenericWithLoc
: public DiagnosticInfoWithLocationBase {
private:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index dd64676222055..97199985ccd10 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
@@ -357,6 +358,9 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::PATCHPOINT:
Res = PromoteIntRes_PATCHPOINT(N);
break;
+ case ISD::READ_REGISTER:
+Res = PromoteIntRes_READ_REGISTER(N);
+break;
}
// If the result is null then the sub-method took care of registering it.
@@ -2076,6 +2080,9 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N,
unsigned OpNo) {
case ISD::PATCHPOINT:
Res = PromoteIntOp_PATCHPOINT(N, OpNo);
break;
+ case ISD::WRITE_REGISTER:
+Res = PromoteIntOp_WRITE_REGISTER(N, OpNo);
+break;
case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
Res = PromoteIntOp_VP_STRIDED(N, OpNo);
@@ -2840,6 +2847,15 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(SDNode
*N, unsigned OpNo) {
return SDValue(DAG.UpdateNodeOperands(N, NewOps), 0);
}
+SDValue DAGTypeLegalizer::PromoteIntOp_WRITE_REGISTER(SDNode *N,
+ unsigned OpNo) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.write_register with illegal type", Fn,
+ N->getDebugLoc()));
+ return N->getOperand(0);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(SDNode *N, unsigned OpNo) {
assert((N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
(N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
@@ -6314,6 +6330,16 @@ SDValue
DAGTypeLegalizer::PromoteIntRes_PATCHPOINT(SDNode *N) {
return Res.getValue(0);
}
+SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(SDNode *N) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
+
+ EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
+ ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+ return DAG.getPOISON(NVT);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N) {
SDLoc dl(N);
SDValue V0 = GetPromotedInteger(N->getOperand(0));
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index a541833684f38..453f89ee185
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
llvmbot wrote:
@llvm/pr-subscribers-backend-powerpc
Author: Matt Arsenault (arsenm)
Changes
---
Full diff: https://github.com/llvm/llvm-project/pull/145197.diff
5 Files Affected:
- (modified) llvm/include/llvm/IR/DiagnosticInfo.h (+25)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp (+26)
- (modified) llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h (+2)
- (modified) llvm/lib/IR/DiagnosticInfo.cpp (+4)
- (added) llvm/test/CodeGen/AMDGPU/read-write-register-illegal-type.ll (+16)
``diff
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h
b/llvm/include/llvm/IR/DiagnosticInfo.h
index 862be04e0fc00..5f7225e878eb1 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -68,6 +68,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_Linker,
DK_Lowering,
+ DK_LegalizationFailure,
DK_DebugMetadataVersion,
DK_DebugMetadataInvalid,
DK_Instrumentation,
@@ -383,6 +384,30 @@ class LLVM_ABI DiagnosticInfoWithLocationBase : public
DiagnosticInfo {
DiagnosticLocation Loc;
};
+class LLVM_ABI DiagnosticInfoLegalizationFailure
+: public DiagnosticInfoWithLocationBase {
+private:
+ /// Message to be reported.
+ const Twine &MsgStr;
+
+public:
+ DiagnosticInfoLegalizationFailure(const Twine &MsgStr LLVM_LIFETIME_BOUND,
+const Function &Fn,
+const DiagnosticLocation &Loc,
+DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfoWithLocationBase(DK_LegalizationFailure, Severity, Fn,
+ Loc),
+MsgStr(MsgStr) {}
+
+ const Twine &getMsgStr() const { return MsgStr; }
+
+ void print(DiagnosticPrinter &DP) const override;
+
+ static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_LegalizationFailure;
+ }
+};
+
class LLVM_ABI DiagnosticInfoGenericWithLoc
: public DiagnosticInfoWithLocationBase {
private:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index dd64676222055..97199985ccd10 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
@@ -357,6 +358,9 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::PATCHPOINT:
Res = PromoteIntRes_PATCHPOINT(N);
break;
+ case ISD::READ_REGISTER:
+Res = PromoteIntRes_READ_REGISTER(N);
+break;
}
// If the result is null then the sub-method took care of registering it.
@@ -2076,6 +2080,9 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N,
unsigned OpNo) {
case ISD::PATCHPOINT:
Res = PromoteIntOp_PATCHPOINT(N, OpNo);
break;
+ case ISD::WRITE_REGISTER:
+Res = PromoteIntOp_WRITE_REGISTER(N, OpNo);
+break;
case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
Res = PromoteIntOp_VP_STRIDED(N, OpNo);
@@ -2840,6 +2847,15 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(SDNode
*N, unsigned OpNo) {
return SDValue(DAG.UpdateNodeOperands(N, NewOps), 0);
}
+SDValue DAGTypeLegalizer::PromoteIntOp_WRITE_REGISTER(SDNode *N,
+ unsigned OpNo) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.write_register with illegal type", Fn,
+ N->getDebugLoc()));
+ return N->getOperand(0);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(SDNode *N, unsigned OpNo) {
assert((N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
(N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
@@ -6314,6 +6330,16 @@ SDValue
DAGTypeLegalizer::PromoteIntRes_PATCHPOINT(SDNode *N) {
return Res.getValue(0);
}
+SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(SDNode *N) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
+
+ EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
+ ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+ return DAG.getPOISON(NVT);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N) {
SDLoc dl(N);
SDValue V0 = GetPromotedInteger(N->getOperand(0));
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
b/llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h
index a541833684f38..453f89ee185b6 100644
--- a/llvm/lib/CodeGen/S
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
arsenm wrote: > [!WARNING] > This pull request is not mergeable via GitHub because a downstack PR is > open. Once all requirements are satisfied, merge this PR as a stack href="https://app.graphite.dev/github/pr/llvm/llvm-project/145197?utm_source=stack-comment-downstack-mergeability-warning"; > >on Graphite. > https://graphite.dev/docs/merge-pull-requests";>Learn more * **#145197** https://app.graphite.dev/github/pr/llvm/llvm-project/145197?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/145197?utm_source=stack-comment-view-in-graphite"; target="_blank">(View in Graphite) * **#145194** https://app.graphite.dev/github/pr/llvm/llvm-project/145194?utm_source=stack-comment-icon"; target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" width="10px" height="10px"/> * `main` This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn more about https://stacking.dev/?utm_source=stack-comment";>stacking. https://github.com/llvm/llvm-project/pull/145197 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] DAG: Emit an error if trying to legalize read/write register with illegal types (PR #145197)
https://github.com/arsenm created
https://github.com/llvm/llvm-project/pull/145197
None
>From 4c1a7fc9c8a546b7d8d0eb52bbad4ddae85598ee Mon Sep 17 00:00:00 2001
From: Matt Arsenault
Date: Sun, 22 Jun 2025 09:12:19 +0900
Subject: [PATCH] DAG: Emit an error if trying to legalize read/write register
with illegal types
---
llvm/include/llvm/IR/DiagnosticInfo.h | 25 ++
.../SelectionDAG/LegalizeIntegerTypes.cpp | 26 +++
llvm/lib/CodeGen/SelectionDAG/LegalizeTypes.h | 2 ++
llvm/lib/IR/DiagnosticInfo.cpp| 4 +++
.../read-write-register-illegal-type.ll | 16
5 files changed, 73 insertions(+)
create mode 100644 llvm/test/CodeGen/AMDGPU/read-write-register-illegal-type.ll
diff --git a/llvm/include/llvm/IR/DiagnosticInfo.h
b/llvm/include/llvm/IR/DiagnosticInfo.h
index 862be04e0fc00..5f7225e878eb1 100644
--- a/llvm/include/llvm/IR/DiagnosticInfo.h
+++ b/llvm/include/llvm/IR/DiagnosticInfo.h
@@ -68,6 +68,7 @@ enum DiagnosticKind {
DK_StackSize,
DK_Linker,
DK_Lowering,
+ DK_LegalizationFailure,
DK_DebugMetadataVersion,
DK_DebugMetadataInvalid,
DK_Instrumentation,
@@ -383,6 +384,30 @@ class LLVM_ABI DiagnosticInfoWithLocationBase : public
DiagnosticInfo {
DiagnosticLocation Loc;
};
+class LLVM_ABI DiagnosticInfoLegalizationFailure
+: public DiagnosticInfoWithLocationBase {
+private:
+ /// Message to be reported.
+ const Twine &MsgStr;
+
+public:
+ DiagnosticInfoLegalizationFailure(const Twine &MsgStr LLVM_LIFETIME_BOUND,
+const Function &Fn,
+const DiagnosticLocation &Loc,
+DiagnosticSeverity Severity = DS_Error)
+ : DiagnosticInfoWithLocationBase(DK_LegalizationFailure, Severity, Fn,
+ Loc),
+MsgStr(MsgStr) {}
+
+ const Twine &getMsgStr() const { return MsgStr; }
+
+ void print(DiagnosticPrinter &DP) const override;
+
+ static bool classof(const DiagnosticInfo *DI) {
+return DI->getKind() == DK_LegalizationFailure;
+ }
+};
+
class LLVM_ABI DiagnosticInfoGenericWithLoc
: public DiagnosticInfoWithLocationBase {
private:
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
index dd64676222055..97199985ccd10 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
@@ -22,6 +22,7 @@
#include "llvm/CodeGen/StackMaps.h"
#include "llvm/CodeGen/TargetLowering.h"
#include "llvm/IR/DerivedTypes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
@@ -357,6 +358,9 @@ void DAGTypeLegalizer::PromoteIntegerResult(SDNode *N,
unsigned ResNo) {
case ISD::PATCHPOINT:
Res = PromoteIntRes_PATCHPOINT(N);
break;
+ case ISD::READ_REGISTER:
+Res = PromoteIntRes_READ_REGISTER(N);
+break;
}
// If the result is null then the sub-method took care of registering it.
@@ -2076,6 +2080,9 @@ bool DAGTypeLegalizer::PromoteIntegerOperand(SDNode *N,
unsigned OpNo) {
case ISD::PATCHPOINT:
Res = PromoteIntOp_PATCHPOINT(N, OpNo);
break;
+ case ISD::WRITE_REGISTER:
+Res = PromoteIntOp_WRITE_REGISTER(N, OpNo);
+break;
case ISD::EXPERIMENTAL_VP_STRIDED_LOAD:
case ISD::EXPERIMENTAL_VP_STRIDED_STORE:
Res = PromoteIntOp_VP_STRIDED(N, OpNo);
@@ -2840,6 +2847,15 @@ SDValue DAGTypeLegalizer::PromoteIntOp_PATCHPOINT(SDNode
*N, unsigned OpNo) {
return SDValue(DAG.UpdateNodeOperands(N, NewOps), 0);
}
+SDValue DAGTypeLegalizer::PromoteIntOp_WRITE_REGISTER(SDNode *N,
+ unsigned OpNo) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.write_register with illegal type", Fn,
+ N->getDebugLoc()));
+ return N->getOperand(0);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_VP_STRIDED(SDNode *N, unsigned OpNo) {
assert((N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_LOAD && OpNo == 3) ||
(N->getOpcode() == ISD::EXPERIMENTAL_VP_STRIDED_STORE && OpNo == 4));
@@ -6314,6 +6330,16 @@ SDValue
DAGTypeLegalizer::PromoteIntRes_PATCHPOINT(SDNode *N) {
return Res.getValue(0);
}
+SDValue DAGTypeLegalizer::PromoteIntRes_READ_REGISTER(SDNode *N) {
+ const Function &Fn = DAG.getMachineFunction().getFunction();
+ Fn.getContext().diagnose(DiagnosticInfoLegalizationFailure(
+ "cannot use llvm.read_register with illegal type", Fn,
N->getDebugLoc()));
+
+ EVT NVT = TLI.getTypeToTransformTo(*DAG.getContext(), N->getValueType(0));
+ ReplaceValueWith(SDValue(N, 1), N->getOperand(0));
+ return DAG.getPOISON(NVT);
+}
+
SDValue DAGTypeLegalizer::PromoteIntOp_EXTRACT_VECTOR_ELT(SDNode *N) {
SDLoc dl(N);
