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,33 @@ 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(); - } else if (const LoadInst *LI = dyn_cast(&I)) { - Alignment = LI->getAlignment(); - ValTy = LI->getType(); - } else if (const AtomicCmpXchgInst *AI = dyn_cast(&I)) { + Type *ValTy = SI->getValueOperand()->getType(); + return SI->getAlign().getValueOr(DL->getABITypeAlign(ValTy)); + } + if (const LoadInst *LI = dyn_cast(&I)) { + Type *ValTy = LI->getType(); + return LI->getAlign().getValueOr(DL->getABITypeAlign(ValTy)); + } + 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(); - } else if (const AtomicRMWInst *AI = dyn_cast(&I)) { + return Align(DL.getTypeStoreSize(AI->getCompareOperand()->getType())); + } + 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(); - } else { - OptimizationRemarkMissed R("gisel-irtranslator", "", &I); - R << "unable to translate memop: " << ore::NV("Opcode", &I); - reportTranslationError(*MF, *TPC, *ORE, R); - return 1; + return Align(DL.getTypeStoreSize(AI->getValOperand()->getType())); } - - return Alignment ? Alignment : DL->getABITypeAlignment(ValTy); + OptimizationRemarkMissed R("gisel-irtranslator", "", &I); + R << "unable to translate memop: " << ore::NV("Opcode", &I); + reportTranslationError(*MF, *TPC, *ORE, R); + return Align(1); } MachineBasicBlock &IRTranslator::getMBB(const BasicBlock &BB) {