This is an archive of the discontinued LLVM Phabricator instance.

[SVE][CodeGen] Fix incorrect legalisation of zero-extended masked loads
ClosedPublic

Authored by kmclaughlin on Oct 22 2021, 8:26 AM.

Details

Summary

PromoteIntRes_MLOAD always sets the extension type to EXTLOAD, which
results in a sign-extended load. If the type returned by getExtensionType()
for the load being promoted is something other than NON_EXTLOAD, we
should instead pass this to getMaskedLoad() as the extension type.

Diff Detail

Event Timeline

kmclaughlin created this revision.Oct 22 2021, 8:26 AM
kmclaughlin requested review of this revision.Oct 22 2021, 8:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 22 2021, 8:26 AM

Hey @kmclaughlin,
Thank you for adding me as a reviewer of the patch.
Do we know what was the logic to set ExtType to ISD::EXTLOAD?
I don't see that on other parts of the legalisation for Masked load.

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
791

As we are replacing ExtType, do we need to pass isExpanding?
I can see in void DAGTypeLegalizer::SplitVecRes_MLOAD and DAGTypeLegalizer::WidenVecRes_MLOAD
they have a
XLD->isExpandingLoad()

kmclaughlin marked an inline comment as done.
  • Pass isExpandingLoad() to getMaskedLoad

Do we know what was the logic to set ExtType to ISD::EXTLOAD?
I don't see that on other parts of the legalisation for Masked load.

Hi @CarolineConcatto, thank you for taking a look at this. We are promoting the masked load by extending the return type, which is why we need to set ExtType when we create the new masked load with the promoted type. The original masked load which had an illegal return type may not have been extending, e.g.

nxv2i16,ch = masked_load<(load (s32) from %ir.in, align 2)> t0, t2, undef:i64, t4, undef:nxv2i16
->
nxv2i64,ch = masked_load<(load (s32) from %ir.in, align 2), anyext from nxv2i16> t0, t2, undef:i64, t4, undef:nxv2i64
llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
791

I think we should be passing isExpandingLoad here, I can see in PromoteIntOp_MSTORE we similarly pass N->isCompressingStore()

This revision is now accepted and ready to land.Oct 25 2021, 8:21 AM

LGTM, moi aussi!

llvm/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp
796

nit: Perhaps just address the formatting issue before merging? Thanks!

Matt added a subscriber: Matt.Oct 26 2021, 5:15 AM
This revision was landed with ongoing or failed builds.Oct 27 2021, 6:18 AM
This revision was automatically updated to reflect the committed changes.