[llvm] [AMDGPU] Avoid constraining RC based on folded into operand (NFC) (PR #160743)
Josh Hutton via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 25 21:19:49 PDT 2025
https://github.com/JoshHuttonCode updated https://github.com/llvm/llvm-project/pull/160743
>From e8f4fa21eeaa7a841444d8d321d515a94101cc60 Mon Sep 17 00:00:00 2001
From: Josh Hutton <joshhuttonemail at gmail.com>
Date: Mon, 22 Sep 2025 12:42:17 -0700
Subject: [PATCH 1/2] [AMDGPU] Avoid constraining RC based on folded into
operand (NFC)
---
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
index 38331b614bceb..8e97ed1ad4f36 100644
--- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -712,8 +712,13 @@ bool SIFoldOperandsImpl::updateOperand(FoldCandidate &Fold) const {
TII->getRegClass(MI->getDesc(), Fold.UseOpNo, TRI)) {
const TargetRegisterClass *NewRC =
TRI->getRegClassForReg(*MRI, New->getReg());
- const TargetRegisterClass *ConstrainRC =
- TRI->findCommonRegClass(OpRC, Old.getSubReg(), NewRC, New->getSubReg());
+
+ const TargetRegisterClass *ConstrainRC = OpRC;
+ if (New->getSubReg()) {
+ ConstrainRC =
+ TRI->getMatchingSuperRegClass(NewRC, OpRC, New->getSubReg());
+ }
+
if (!ConstrainRC)
return false;
>From 54306c09c20a9a68462c1a64ff4c00c5d46df6c8 Mon Sep 17 00:00:00 2001
From: Josh Hutton <joshhuttonemail at gmail.com>
Date: Thu, 25 Sep 2025 21:19:19 -0700
Subject: [PATCH 2/2] Move if (!ConstrainRC) inside the previous condition
---
llvm/lib/Target/AMDGPU/SIFoldOperands.cpp | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
index 8e97ed1ad4f36..51c56ecea2c96 100644
--- a/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFoldOperands.cpp
@@ -717,10 +717,10 @@ bool SIFoldOperandsImpl::updateOperand(FoldCandidate &Fold) const {
if (New->getSubReg()) {
ConstrainRC =
TRI->getMatchingSuperRegClass(NewRC, OpRC, New->getSubReg());
- }
- if (!ConstrainRC)
- return false;
+ if (!ConstrainRC)
+ return false;
+ }
if (!MRI->constrainRegClass(New->getReg(), ConstrainRC)) {
LLVM_DEBUG(dbgs() << "Cannot constrain " << printReg(New->getReg(), TRI)
More information about the llvm-commits
mailing list