[llvm] [LLVM][CodeGen][SVE] Don't combine shifts at the expense of addressing modes. (PR #149873)

Paul Walker via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 23 05:08:32 PDT 2025


================
@@ -18010,10 +18010,17 @@ bool AArch64TargetLowering::shouldFoldConstantShiftPairToMask(
       unsigned ShlAmt = C2->getZExtValue();
       if (auto ShouldADD = *N->user_begin();
           ShouldADD->getOpcode() == ISD::ADD && ShouldADD->hasOneUse()) {
-        if (auto ShouldLOAD = dyn_cast<LoadSDNode>(*ShouldADD->user_begin())) {
-          unsigned ByteVT = ShouldLOAD->getMemoryVT().getSizeInBits() / 8;
-          if ((1ULL << ShlAmt) == ByteVT &&
-              isIndexedLoadLegal(ISD::PRE_INC, ShouldLOAD->getMemoryVT()))
+        if (auto Load = dyn_cast<LoadSDNode>(*ShouldADD->user_begin())) {
+          TypeSize Size = Load->getMemoryVT().getSizeInBits();
+          // NOTE: +3 to account for bytes->bits transition.
+          if (TypeSize::getFixed(1ULL << (ShlAmt + 3)) == Size &&
+              isIndexedLoadLegal(ISD::PRE_INC, Load->getMemoryVT()))
+            return false;
+
+          unsigned ScalarSize = Load->getMemoryVT().getScalarSizeInBits();
+          // NOTE: +3 to account for bytes->bits transition.
+          if ((1ULL << (ShlAmt + 3)) == ScalarSize &&
+              Load->getValueType(0).isScalableVector())
----------------
paulwalker-arm wrote:

Thanks @rj-jesus, I've taken a run at restructuring to remove the need for TypeSize completely, including the implicit type conversion that one day (I know it's a pipe dream) we can remove.

Re: scalable vector check: Not using the MemVT was deliberate because I believe it should be possible to have a fixed length MemVT that loads into a scalable vector, where we would also want to use the scalar size.

https://github.com/llvm/llvm-project/pull/149873


More information about the llvm-commits mailing list