[llvm] [DAGCombine] Fix alignment of store in replaceStoreOfInsertLoad. (PR #215895)
Eli Friedman via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 09:01:10 PDT 2026
================
@@ -24362,22 +24362,27 @@ SDValue DAGCombiner::replaceStoreOfInsertLoad(StoreSDNode *ST) {
return SDValue();
MachinePointerInfo PointerInfo(ST->getAddressSpace());
+ Align NewAlign;
// If the offset is a known constant then try to recover the pointer
// info
SDValue NewPtr;
if (auto *CIdx = dyn_cast<ConstantSDNode>(Idx)) {
- unsigned COffset = CIdx->getSExtValue() * EltVT.getSizeInBits() / 8;
+ unsigned COffset = CIdx->getSExtValue() * EltVT.getFixedSizeInBits() / 8;
NewPtr = DAG.getMemBasePlusOffset(Ptr, TypeSize::getFixed(COffset), DL);
PointerInfo = ST->getPointerInfo().getWithOffset(COffset);
+ NewAlign = ST->getAlign();
} else {
// The original DAG loaded the entire vector from memory, so arithmetic
// within it must be inbounds.
NewPtr = TLI.getInboundsVectorElementPointer(DAG, Ptr, Value.getValueType(),
Idx);
+ // MachinePointerInfo can't represent a variable offset, so use a generic
+ // MachinePointerInfo and recompute the alignment.
+ NewAlign = commonAlignment(ST->getAlign(), EltVT.getFixedSizeInBits() / 8);
}
- return DAG.getStore(Chain, DL, Elt, NewPtr, PointerInfo, ST->getAlign(),
+ return DAG.getStore(Chain, DL, Elt, NewPtr, PointerInfo, NewAlign,
----------------
efriedma-quic wrote:
The "Align" argument to getStore() here is directly passed to getMachineMemOperand(), which uses it as the value of getBaseAlign().
This doesn't really have any effect on the variable case. The new MachinePointerInfo doesn't have an offset, so the base align of the new store must be the same as real alignment of the operation. And for computing the alignment of the new store, we want the known alignment of the input store, i.e. getAlign(), not the base alignment.
For the constant case, we could use `NewAlign = ST->getBaseAlign();`. But that would just be an optimization.
https://github.com/llvm/llvm-project/pull/215895
More information about the llvm-commits
mailing list