[llvm] [DAGCombiner] Avoid repeated calls to WideVT.getScalarSizeInBits() in DAGCombiner::mergeTruncStores. NFC (PR #152231)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 5 17:46:12 PDT 2025


https://github.com/topperc created https://github.com/llvm/llvm-project/pull/152231

We already have a variable, WideNumBits, that contains the same information. Use it and delay the creation of WideVT until we really need it.

>From c514d1d0a40f38256a3593a2a333b202c677c681 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Tue, 5 Aug 2025 17:43:54 -0700
Subject: [PATCH] [DAGCombiner] Avoid repeated calls to
 WideVT.getScalarSizeInBits() in DAGCombiner::mergeTruncStores. NFC

We already have a variable, WideNumBits, that contains the same
information. Use it and delay the creation of WideVT until we
really need it.
---
 llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index d70e96938ed9a..734191447d67f 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -9390,8 +9390,7 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
   LLVMContext &Context = *DAG.getContext();
   unsigned NumStores = Stores.size();
   unsigned WideNumBits = NumStores * NarrowNumBits;
-  EVT WideVT = EVT::getIntegerVT(Context, WideNumBits);
-  if (WideVT != MVT::i16 && WideVT != MVT::i32 && WideVT != MVT::i64)
+  if (WideNumBits != 16 && WideNumBits != 32 && WideNumBits != 64)
     return SDValue();
 
   // Check if all bytes of the source value that we are looking at are stored
@@ -9445,7 +9444,7 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
         SourceValue = WideVal;
 
       // Give up if the source value type is smaller than the store size.
-      if (SourceValue.getScalarValueSizeInBits() < WideVT.getScalarSizeInBits())
+      if (SourceValue.getScalarValueSizeInBits() < WideNumBits)
         return SDValue();
     }
 
@@ -9469,6 +9468,8 @@ SDValue DAGCombiner::mergeTruncStores(StoreSDNode *N) {
     OffsetMap[Offset] = ByteOffsetFromBase;
   }
 
+  EVT WideVT = EVT::getIntegerVT(Context, WideNumBits);
+
   assert(FirstOffset != INT64_MAX && "First byte offset must be set");
   assert(FirstStore && "First store must be set");
 



More information about the llvm-commits mailing list