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

Michael Maitland via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 08:58:41 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] [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();



More information about the llvm-commits mailing list