[llvm] [SLPVectorizer][X86] Free load cost for stores with constant pointers (PR #118016)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 3 10:48:31 PST 2024


================
@@ -5157,8 +5157,9 @@ InstructionCost X86TTIImpl::getMemoryOpCost(unsigned Opcode, Type *Src,
 
   InstructionCost Cost = 0;
 
-  // Add a cost for constant load to vector.
-  if (Opcode == Instruction::Store && OpInfo.isConstant())
+  // Add a cost for constant load to vector, if pointer is not a constant.
+  if (auto *SI = dyn_cast_or_null<StoreInst>(I);
+      SI && !isa<Constant>(SI->getPointerOperand()) && OpInfo.isConstant())
----------------
RKSimon wrote:

That's only true for scalars - for vector constant it must be loaded from the constant pool unless rematerialized (which for x86 means 0 or -1 splats only). That is the issue in #111126 - the load from `LCPI0_0` is being overestimated (its just a <2 x i64> load that is reused in all 10 stores but we're treating it as a <20 x i64> load):
```
f():
        movaps  xmm0, xmmword ptr [rip + .LCPI0_0]
        movaps  xmmword ptr [rip + arr], xmm0
        movaps  xmmword ptr [rip + arr+16], xmm0
        movaps  xmmword ptr [rip + arr+32], xmm0
        movaps  xmmword ptr [rip + arr+48], xmm0
        movaps  xmmword ptr [rip + arr+64], xmm0
        movaps  xmmword ptr [rip + arr+80], xmm0
        movaps  xmmword ptr [rip + arr+96], xmm0
        movaps  xmmword ptr [rip + arr+112], xmm0
        movaps  xmmword ptr [rip + arr+128], xmm0
        movaps  xmmword ptr [rip + arr+144], xmm0
        ret
```
I'm investigating an alternative patch but have run out of time tonight :/

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


More information about the llvm-commits mailing list