[llvm] [X86] combineConstantPoolLoads - correctly merge constant pool loads by pointer and chain (PR #139575)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 2 23:56:38 PDT 2025


https://github.com/RKSimon updated https://github.com/llvm/llvm-project/pull/139575

>From 8d70bd2d51d7d762527f03312327684e00859069 Mon Sep 17 00:00:00 2001
From: Simon Pilgrim <llvm-dev at redking.me.uk>
Date: Mon, 12 May 2025 17:16:37 +0100
Subject: [PATCH] [X86] combineConstantPoolLoads - correctly merge constant
 pool loads by pointer and chain

We were merging with a larger constant pool load if it didn't have any chain dependencies (and implicitly assuming all uses were on the vector value), instead we should flip this, explicitly check for uses of the vector value and merge the memory chain dependencies with makeEquivalentMemoryOrdering.

As these are constant pool loads we shouldn't expect any changes here, but we should be consistent with how we merge/reuse loads - an upcoming patch for other loads will do the same as we will see changes there.
---
 llvm/lib/Target/X86/X86ISelLowering.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index ee295fd83670d..d7105270f3520 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -52880,7 +52880,7 @@ static SDValue combineConstantPoolLoads(SDNode *N, const SDLoc &dl,
         (User->getOpcode() == X86ISD::SUBV_BROADCAST_LOAD ||
          User->getOpcode() == X86ISD::VBROADCAST_LOAD ||
          ISD::isNormalLoad(User)) &&
-        UserLd->getChain() == Chain && !User->hasAnyUseOfValue(1) &&
+        UserLd->getChain() == Chain && User->hasAnyUseOfValue(0) &&
         User->getValueSizeInBits(0).getFixedValue() >
             RegVT.getFixedSizeInBits()) {
       EVT UserVT = User->getValueType(0);
@@ -52902,6 +52902,7 @@ static SDValue combineConstantPoolLoads(SDNode *N, const SDLoc &dl,
               getTargetConstantBitsFromNode(SDValue(User, 0), NumBits,
                                             UserUndefs, UserBits)) {
             if (MatchingBits(Undefs, UserUndefs, Bits, UserBits)) {
+              DAG.makeEquivalentMemoryOrdering(SDValue(N, 1), SDValue(User, 1));
               SDValue Extract = extractSubVector(SDValue(User, 0), 0, DAG, dl,
                                                  RegVT.getSizeInBits());
               Extract = DAG.getBitcast(RegVT, Extract);



More information about the llvm-commits mailing list