[llvm] [CodeGen] Change MachineInstr::isConstantValuePHI to return Register. NFC. (PR #112901)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 18 06:13:52 PDT 2024
https://github.com/jayfoad created https://github.com/llvm/llvm-project/pull/112901
None
>From dd2b53280e8230be9aceb109198f9ed1a5c83d3b Mon Sep 17 00:00:00 2001
From: Jay Foad <jay.foad at amd.com>
Date: Fri, 18 Oct 2024 14:12:56 +0100
Subject: [PATCH] [CodeGen] Change MachineInstr::isConstantValuePHI to return
Register. NFC.
---
llvm/include/llvm/CodeGen/MachineInstr.h | 4 ++--
llvm/lib/CodeGen/MachineInstr.cpp | 9 +++------
llvm/lib/CodeGen/MachineSSAUpdater.cpp | 2 +-
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/MachineInstr.h b/llvm/include/llvm/CodeGen/MachineInstr.h
index 76a7b8662bae66..36051732474634 100644
--- a/llvm/include/llvm/CodeGen/MachineInstr.h
+++ b/llvm/include/llvm/CodeGen/MachineInstr.h
@@ -1764,8 +1764,8 @@ class MachineInstr
bool isDereferenceableInvariantLoad() const;
/// If the specified instruction is a PHI that always merges together the
- /// same virtual register, return the register, otherwise return 0.
- unsigned isConstantValuePHI() const;
+ /// same virtual register, return the register, otherwise return Register().
+ Register isConstantValuePHI() const;
/// Return true if this instruction has side effects that are not modeled
/// by mayLoad / mayStore, etc.
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 0d78c2cafbaf63..c1bd0bb5b7162e 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -1535,19 +1535,16 @@ bool MachineInstr::isDereferenceableInvariantLoad() const {
return true;
}
-/// isConstantValuePHI - If the specified instruction is a PHI that always
-/// merges together the same virtual register, return the register, otherwise
-/// return 0.
-unsigned MachineInstr::isConstantValuePHI() const {
+Register MachineInstr::isConstantValuePHI() const {
if (!isPHI())
- return 0;
+ return {};
assert(getNumOperands() >= 3 &&
"It's illegal to have a PHI without source operands");
Register Reg = getOperand(1).getReg();
for (unsigned i = 3, e = getNumOperands(); i < e; i += 2)
if (getOperand(i).getReg() != Reg)
- return 0;
+ return {};
return Reg;
}
diff --git a/llvm/lib/CodeGen/MachineSSAUpdater.cpp b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
index 4cbb6ad3128bd9..d9011c5e135d35 100644
--- a/llvm/lib/CodeGen/MachineSSAUpdater.cpp
+++ b/llvm/lib/CodeGen/MachineSSAUpdater.cpp
@@ -201,7 +201,7 @@ Register MachineSSAUpdater::GetValueInMiddleOfBlock(MachineBasicBlock *BB,
// See if the PHI node can be merged to a single value. This can happen in
// loop cases when we get a PHI of itself and one other value.
- if (unsigned ConstVal = InsertedPHI->isConstantValuePHI()) {
+ if (Register ConstVal = InsertedPHI->isConstantValuePHI()) {
InsertedPHI->eraseFromParent();
return ConstVal;
}
More information about the llvm-commits
mailing list