[llvm] [Codegen][LegalizeIntegerTypes] Improve shift through stack (PR #96151)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 08:23:52 PDT 2024
================
@@ -4530,14 +4530,35 @@ void DAGTypeLegalizer::ExpandIntRes_ShiftThroughStack(SDNode *N, SDValue &Lo,
SDValue ShAmt = N->getOperand(1);
EVT ShAmtVT = ShAmt.getValueType();
- // This legalization is optimal when the shift is by a multiple of byte width,
- // %x * 8 <-> %x << 3 so 3 low bits should be be known zero.
- bool ShiftByByteMultiple =
- DAG.computeKnownBits(ShAmt).countMinTrailingZeros() >= 3;
+ EVT LoadStoreVT = VT;
+ do {
+ LoadStoreVT = TLI.getTypeToTransformTo(*DAG.getContext(), LoadStoreVT);
+ } while (!TLI.isTypeLegal(LoadStoreVT));
+
+ const unsigned KnownTrailingZeros =
+ DAG.computeKnownBits(ShAmt).countMinTrailingZeros();
+
+ const Align LoadStoreAlign = [&]() -> Align {
+ unsigned IsFast = 0;
+ const bool AllowsFastMisalignedMemoryAccesses =
+ TLI.allowsMisalignedMemoryAccesses(
+ LoadStoreVT, /*AddrSpace=*/DAG.getDataLayout().getAllocaAddrSpace(),
+ /*Alignment=*/Align(LoadStoreVT.getStoreSize()),
----------------
arsenm wrote:
I mean I don't understand why you are considering unaligned access. This code is creating a temporary stack slot, that can be whatever alignment you choose. Deciding to under-align this stack slot is kind of going out of scope for what this code is doing. Can you just get rid of all this legal alignment checking business and just use the naturally aligned type slot?
If we wanted an optimization to under-align stack slots, it ideally would be a separate optimization checking the uses of the stack slot instead of just performing it in this one specific legalization step.
That is, delete all of this LoadStoreAlign code, call CreateStackTemproary as below and use the alignment of whatever it chose
https://github.com/llvm/llvm-project/pull/96151
More information about the llvm-commits
mailing list