diff --git a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h --- a/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/LegalizerInfo.h @@ -113,6 +113,14 @@ LLT MemoryTy; uint64_t AlignInBits; AtomicOrdering Ordering; + + MemDesc() = default; + MemDesc(LLT MemoryTy, uint64_t AlignInBits, AtomicOrdering Ordering) + : MemoryTy(MemoryTy), AlignInBits(AlignInBits), Ordering(Ordering) {} + constexpr MemDesc(const MachineMemOperand &MMO) + : MemoryTy(MMO.getMemoryType()), + AlignInBits(MMO.getAlign().value() * 8), + Ordering(MMO.getSuccessOrdering()) {} }; /// Operations which require memory can use this to place requirements on the diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -497,10 +497,7 @@ continue; // Check for legality. if (LI) { - LegalityQuery::MemDesc MMDesc; - MMDesc.MemoryTy = MMO.getMemoryType(); - MMDesc.AlignInBits = MMO.getAlign().value() * 8; - MMDesc.Ordering = MMO.getSuccessOrdering(); + LegalityQuery::MemDesc MMDesc(MMO); LLT UseTy = MRI.getType(UseMI.getOperand(0).getReg()); LLT SrcTy = MRI.getType(LoadMI->getPointerReg()); if (LI->getAction({LoadMI->getOpcode(), {UseTy, SrcTy}, {MMDesc}}) @@ -724,10 +721,8 @@ return false; const MachineMemOperand &MMO = LoadDef->getMMO(); - LegalityQuery::MemDesc MMDesc; + LegalityQuery::MemDesc MMDesc(MMO); MMDesc.MemoryTy = LLT::scalar(NewSizeBits); - MMDesc.AlignInBits = MMO.getAlign().value() * 8; - MMDesc.Ordering = MMO.getSuccessOrdering(); if (!isLegalOrBeforeLegalizer({TargetOpcode::G_SEXTLOAD, {MRI.getType(LoadDef->getDstReg()), MRI.getType(LoadDef->getPointerReg())}, @@ -3758,10 +3753,8 @@ // may not use index 0. Register Ptr = LowestIdxLoad->getPointerReg(); const MachineMemOperand &MMO = LowestIdxLoad->getMMO(); - LegalityQuery::MemDesc MMDesc; + LegalityQuery::MemDesc MMDesc(MMO); MMDesc.MemoryTy = Ty; - MMDesc.AlignInBits = MMO.getAlign().value() * 8; - MMDesc.Ordering = MMO.getSuccessOrdering(); if (!isLegalOrBeforeLegalizer( {TargetOpcode::G_LOAD, {Ty, MRI.getType(Ptr)}, {MMDesc}})) return false; diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp --- a/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerInfo.cpp @@ -352,8 +352,7 @@ SmallVector MemDescrs; for (const auto &MMO : MI.memoperands()) - MemDescrs.push_back({MMO->getMemoryType(), 8 * MMO->getAlign().value(), - MMO->getSuccessOrdering()}); + MemDescrs.push_back({*MMO}); return getAction({MI.getOpcode(), Types, MemDescrs}); }