[llvm] [GISel] Add LookThroughInstrs for getIConstantVRegVal and getIConstan… (PR #68327)

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 09:01:26 PDT 2023


https://github.com/michaelmaitland updated https://github.com/llvm/llvm-project/pull/68327

>From d98b90950018c8663f64b481e82b32e55b1b02d6 Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Thu, 5 Oct 2023 08:48:13 -0700
Subject: [PATCH 1/2] [GISel] Add LookThroughInstrs for getIConstantVRegVal and
 getIConstantVRegSExtVal

The implementation of these methods uses getIConstantVRegValWithLookThrough
with LookThroughInstrs argument set to false. By adding the optional
argument to getIConstantVRegVal and getIConstantVRegSExtVal we can take
advantage of the already built look through functionality.
---
 llvm/lib/CodeGen/GlobalISel/Utils.cpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 473c3f452f8b1d9..59b3c6b758589de 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -290,9 +290,10 @@ void llvm::reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
 }
 
 std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
-                                               const MachineRegisterInfo &MRI) {
-  std::optional<ValueAndVReg> ValAndVReg = getIConstantVRegValWithLookThrough(
-      VReg, MRI, /*LookThroughInstrs*/ false);
+                                               const MachineRegisterInfo &MRI,
+                                               bool LookThroughInstrs = false) {
+  std::optional<ValueAndVReg> ValAndVReg =
+      getIConstantVRegValWithLookThrough(VReg, MRI, LookThroughInstrs);
   assert((!ValAndVReg || ValAndVReg->VReg == VReg) &&
          "Value found while looking through instrs");
   if (!ValAndVReg)
@@ -301,7 +302,8 @@ std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
 }
 
 std::optional<int64_t>
-llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI) {
+llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI,
+                              bool LookThroughInstrs = false) {
   std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI);
   if (Val && Val->getBitWidth() <= 64)
     return Val->getSExtValue();

>From 544b450a5381268794ef9a567e8d6b85893544cf Mon Sep 17 00:00:00 2001
From: Michael Maitland <michaeltmaitland at gmail.com>
Date: Thu, 5 Oct 2023 09:00:40 -0700
Subject: [PATCH 2/2] Pass LookThroughInstrs to getIConstantVRegVal

---
 llvm/lib/CodeGen/GlobalISel/Utils.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 59b3c6b758589de..2a7768ad75285ef 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -304,7 +304,7 @@ std::optional<APInt> llvm::getIConstantVRegVal(Register VReg,
 std::optional<int64_t>
 llvm::getIConstantVRegSExtVal(Register VReg, const MachineRegisterInfo &MRI,
                               bool LookThroughInstrs = false) {
-  std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI);
+  std::optional<APInt> Val = getIConstantVRegVal(VReg, MRI, LookThroughInstrs);
   if (Val && Val->getBitWidth() <= 64)
     return Val->getSExtValue();
   return std::nullopt;



More information about the llvm-commits mailing list