Skip to content

Commit ae4c9f4

Browse files
committed
Add alignment to load
1 parent 5d8e74d commit ae4c9f4

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4585,14 +4585,16 @@ void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(SDNode *N, SDValue &Lo,
45854585
SDValue ShAmt = N->getOperand(1);
45864586
EVT ShAmtVT = ShAmt.getValueType();
45874587

4588-
EVT LoadStoreVT = VT;
4588+
EVT LoadVT = VT;
45894589
do {
4590-
LoadStoreVT = TLI.getTypeToTransformTo(*DAG.getContext(), LoadStoreVT);
4591-
} while (!TLI.isTypeLegal(LoadStoreVT));
4590+
LoadVT = TLI.getTypeToTransformTo(*DAG.getContext(), LoadVT);
4591+
} while (!TLI.isTypeLegal(LoadVT));
45924592

4593-
const unsigned ShiftUnitInBits = LoadStoreVT.getStoreSize() * 8;
4593+
const unsigned ShiftUnitInBits = LoadVT.getStoreSize() * 8;
4594+
assert(ShiftUnitInBits <= VT.getScalarSizeInBits());
45944595
assert(isPowerOf2_32(ShiftUnitInBits) &&
45954596
"Shifting unit is not a a power of two!");
4597+
45964598
const bool IsOneStepShift =
45974599
DAG.computeKnownBits(ShAmt).countMinTrailingZeros() >=
45984600
Log2_32(ShiftUnitInBits);
@@ -4613,7 +4615,11 @@ void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(SDNode *N, SDValue &Lo,
46134615

46144616
// Get a temporary stack slot 2x the width of our VT.
46154617
// FIXME: reuse stack slots?
4616-
SDValue StackPtr = DAG.CreateStackTemporary(StackSlotVT);
4618+
Align StackAlign = DAG.getReducedAlign(StackSlotVT, /*UseABI=*/false);
4619+
assert(DAG.getReducedAlign(LoadVT, /*UseABI=*/false) <= StackAlign);
4620+
4621+
SDValue StackPtr =
4622+
DAG.CreateStackTemporary(StackSlotVT.getStoreSize(), StackAlign);
46174623
EVT PtrTy = StackPtr.getValueType();
46184624
SDValue Ch = DAG.getEntryNode();
46194625

@@ -4679,9 +4685,10 @@ void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(SDNode *N, SDValue &Lo,
46794685
AdjStackPtr = DAG.getMemBasePlusOffset(AdjStackPtr, Offset, dl);
46804686

46814687
// And load it! While the load is not legal, legalizing it is obvious.
4682-
SDValue Res = DAG.getLoad(
4683-
VT, dl, Ch, AdjStackPtr,
4684-
MachinePointerInfo::getUnknownStack(DAG.getMachineFunction()));
4688+
SDValue Res =
4689+
DAG.getLoad(VT, dl, Ch, AdjStackPtr,
4690+
MachinePointerInfo::getUnknownStack(DAG.getMachineFunction()),
4691+
DAG.getReducedAlign(LoadVT, /*UseABI=*/false));
46854692

46864693
// If we may still have a remaining bits to shift by, do so now.
46874694
if (!IsOneStepShift) {

0 commit comments

Comments
 (0)