forked from OSchip/llvm-project
[LegalizeDAG] Propagate alignment in ExpandExtractFromVectorThroughStack
Unlike the name suggests this can reuse any store as a base for a memory-based vector extract. If that store is underaligned the loads created to extract will have an invalid alignment. Since most CPUs are forgiving wrt alignment this is almost never an issue, on x86 this is only reproducible by extracting a 128 bit vector out of a wider vector. I tried making a test case in the context of https://reviews.llvm.org/D127982 but it's really really fragile, as the output pretty much looks like a missed optimization.
This commit is contained in:
parent
6cb9529001
commit
8aff88fd3a
|
@ -1404,17 +1404,21 @@ SDValue SelectionDAGLegalize::ExpandExtractFromVectorThroughStack(SDValue Op) {
|
|||
}
|
||||
|
||||
SDValue NewLoad;
|
||||
Align ElementAlignment =
|
||||
std::min(cast<StoreSDNode>(Ch)->getAlign(),
|
||||
DAG.getDataLayout().getPrefTypeAlign(
|
||||
Op.getValueType().getTypeForEVT(*DAG.getContext())));
|
||||
|
||||
if (Op.getValueType().isVector()) {
|
||||
StackPtr = TLI.getVectorSubVecPointer(DAG, StackPtr, VecVT,
|
||||
Op.getValueType(), Idx);
|
||||
NewLoad =
|
||||
DAG.getLoad(Op.getValueType(), dl, Ch, StackPtr, MachinePointerInfo());
|
||||
NewLoad = DAG.getLoad(Op.getValueType(), dl, Ch, StackPtr,
|
||||
MachinePointerInfo(), ElementAlignment);
|
||||
} else {
|
||||
StackPtr = TLI.getVectorElementPointer(DAG, StackPtr, VecVT, Idx);
|
||||
NewLoad = DAG.getExtLoad(ISD::EXTLOAD, dl, Op.getValueType(), Ch, StackPtr,
|
||||
MachinePointerInfo(),
|
||||
VecVT.getVectorElementType());
|
||||
MachinePointerInfo(), VecVT.getVectorElementType(),
|
||||
ElementAlignment);
|
||||
}
|
||||
|
||||
// Replace the chain going out of the store, by the one out of the load.
|
||||
|
|
Loading…
Reference in New Issue