diff --git a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h --- a/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/IRTranslator.h @@ -582,7 +582,15 @@ /// Get the alignment of the given memory operation instruction. This will /// either be the explicitly specified value or the ABI-required alignment for /// the type being accessed (according to the Module's DataLayout). - unsigned getMemOpAlignment(const Instruction &I); + /// FIXME: Remove once transition to Align is over. + inline unsigned getMemOpAlignment(const Instruction &I) { + return getMemOpAlign(I).value(); + } + + /// Get the alignment of the given memory operation instruction. This will + /// either be the explicitly specified value or the ABI-required alignment for + /// the type being accessed (according to the Module's DataLayout). + Align getMemOpAlign(const Instruction &I); /// Get the MachineBasicBlock that represents \p BB. Specifically, the block /// returned will be the head of the translated block (suitable for branch diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp --- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -242,37 +242,31 @@ return FI; } -unsigned IRTranslator::getMemOpAlignment(const Instruction &I) { - unsigned Alignment = 0; - Type *ValTy = nullptr; +Align IRTranslator::getMemOpAlign(const Instruction &I) { if (const StoreInst *SI = dyn_cast(&I)) { - Alignment = SI->getAlignment(); - ValTy = SI->getValueOperand()->getType(); + Type *ValTy = SI->getValueOperand()->getType(); + return SI->getAlign().getValueOr(DL->getABITypeAlign(ValTy)); } else if (const LoadInst *LI = dyn_cast(&I)) { - Alignment = LI->getAlignment(); - ValTy = LI->getType(); + Type *ValTy = LI->getType(); + return LI->getAlign().getValueOr(DL->getABITypeAlign(ValTy)); } else if (const AtomicCmpXchgInst *AI = dyn_cast(&I)) { // TODO(PR27168): This instruction has no alignment attribute, but unlike // the default alignment for load/store, the default here is to assume // it has NATURAL alignment, not DataLayout-specified alignment. const DataLayout &DL = AI->getModule()->getDataLayout(); - Alignment = DL.getTypeStoreSize(AI->getCompareOperand()->getType()); - ValTy = AI->getCompareOperand()->getType(); + return Align(DL.getTypeStoreSize(AI->getCompareOperand()->getType())); } else if (const AtomicRMWInst *AI = dyn_cast(&I)) { // TODO(PR27168): This instruction has no alignment attribute, but unlike // the default alignment for load/store, the default here is to assume // it has NATURAL alignment, not DataLayout-specified alignment. const DataLayout &DL = AI->getModule()->getDataLayout(); - Alignment = DL.getTypeStoreSize(AI->getValOperand()->getType()); - ValTy = AI->getType(); + return Align(DL.getTypeStoreSize(AI->getValOperand()->getType())); } else { OptimizationRemarkMissed R("gisel-irtranslator", "", &I); R << "unable to translate memop: " << ore::NV("Opcode", &I); reportTranslationError(*MF, *TPC, *ORE, R); - return 1; + return Align(1); } - - return Alignment ? Alignment : DL->getABITypeAlignment(ValTy); } MachineBasicBlock &IRTranslator::getMBB(const BasicBlock &BB) {