[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:55:16 PDT 2023


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

…tVRegSExtVal

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.

>From c546e7d63f95a1d93feff79dca79d53382e54106 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 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 473c3f452f8b1d9..bc97acd9d76f07c 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) {
+                                               const MachineRegisterInfo &MRI,
+                                               bool LookThroughInstrs = false) {
   std::optional<ValueAndVReg> ValAndVReg = getIConstantVRegValWithLookThrough(
-      VReg, MRI, /*LookThroughInstrs*/ false);
+      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