[clang] [lld] [llvm] [Alignment] Add a static function to construct an `Align` from power-of-2 values (PR #230920)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Oct 11 01:19:26 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lld-macho
@llvm/pr-subscribers-backend-x86
Author: Ömer Sinan Ağacan (osa1)
<details>
<summary>Changes</summary>
Many call sites of the `Align` constructor uses it as `Align(1ULL << n)`. Add a new static function to allow `Align::fromLog2(n)` and update old call sites.
---
Patch is 24.75 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/230920.diff
28 Files Affected:
- (modified) clang/lib/CodeGen/CodeGenModule.cpp (+1-1)
- (modified) lld/MachO/SyntheticSections.cpp (+1-1)
- (modified) lld/wasm/InputChunks.h (+2-2)
- (modified) llvm/include/llvm/IR/Instructions.h (+5-5)
- (modified) llvm/include/llvm/Support/Alignment.h (+9-4)
- (modified) llvm/lib/CodeGen/MachineBlockPlacement.cpp (+4-4)
- (modified) llvm/lib/CodeGen/MachineFunction.cpp (+1-1)
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp (+2-1)
- (modified) llvm/lib/MC/MCParser/AsmParser.cpp (+4-4)
- (modified) llvm/lib/MC/MCParser/DarwinAsmParser.cpp (+2-2)
- (modified) llvm/lib/MC/MCParser/MasmParser.cpp (+2-2)
- (modified) llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp (+1-1)
- (modified) llvm/lib/Target/ARM/ARMISelLowering.cpp (+3-2)
- (modified) llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp (+1-1)
- (modified) llvm/lib/Target/Hexagon/HexagonISelLowering.cpp (+1-1)
- (modified) llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp (+1-1)
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+1-1)
- (modified) llvm/lib/Target/X86/X86InstrInfo.cpp (+1-1)
- (modified) llvm/lib/Transforms/IPO/AttributorAttributes.cpp (+2-2)
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+1-1)
- (modified) llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp (+1-1)
- (modified) llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp (+1-1)
- (modified) llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp (+8-5)
- (modified) llvm/lib/Transforms/Scalar/InferAlignment.cpp (+1-1)
- (modified) llvm/lib/Transforms/Utils/Local.cpp (+1-1)
- (modified) llvm/unittests/CodeGen/GlobalISel/KnownBitsTest.cpp (+2-1)
- (modified) llvm/unittests/Support/AlignmentTest.cpp (+11)
- (modified) llvm/utils/TableGen/X86FoldTablesEmitter.cpp (+1-1)
``````````diff
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 62ef11a697b1c..f8268d0593806 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3306,7 +3306,7 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
if (unsigned alignment = D->getMaxAlignment() / Context.getCharWidth())
ExplicitAlignment = llvm::Align(alignment);
else if (LangOpts.FunctionAlignment)
- ExplicitAlignment = llvm::Align(1ull << LangOpts.FunctionAlignment);
+ ExplicitAlignment = llvm::Align::fromLog2(LangOpts.FunctionAlignment);
if (ExplicitAlignment) {
F->setAlignment(ExplicitAlignment);
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 808f32fb2b094..cc7aaa2c7ee9f 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -1731,7 +1731,7 @@ void CStringSection::writeTo(uint8_t *buf) const {
// `16 % A`.
static Align getStringPieceAlignment(const CStringInputSection &isec,
const StringPiece &piece) {
- return llvm::Align(1ULL << llvm::countr_zero(isec.align | piece.inSecOff));
+ return llvm::Align::fromLog2(llvm::countr_zero(isec.align | piece.inSecOff));
}
void CStringSection::finalizeContents() {
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index 0e4b8882c90a3..9c519a9c3dbe9 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -232,8 +232,8 @@ class SyntheticMergedChunk : public InputChunk {
public:
SyntheticMergedChunk(StringRef name, uint32_t alignment, uint32_t flags)
: InputChunk(nullptr, InputChunk::MergedChunk, name, alignment, flags),
- builder(llvm::StringTableBuilder::RAW, llvm::Align(1ULL << alignment)) {
- }
+ builder(llvm::StringTableBuilder::RAW,
+ llvm::Align::fromLog2(alignment)) {}
static bool classof(const InputChunk *c) {
return c->kind() == InputChunk::MergedChunk;
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index 47e9a79436e45..5d56e130eec5a 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -134,7 +134,7 @@ class AllocaInst : public UnaryInstruction {
/// Return the alignment of the memory that is being allocated by the
/// instruction.
Align getAlign() const {
- return Align(1ULL << getSubclassData<AlignmentField>());
+ return Align::fromLog2(getSubclassData<AlignmentField>());
}
void setAlignment(Align Align) {
@@ -240,7 +240,7 @@ class LoadInst : public UnaryInstruction {
/// Return the alignment of the access that is being performed.
Align getAlign() const {
- return Align(1ULL << (getSubclassData<AlignmentField>()));
+ return Align::fromLog2(getSubclassData<AlignmentField>());
}
void setAlignment(Align Align) {
@@ -388,7 +388,7 @@ class StoreInst : public Instruction {
DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value);
Align getAlign() const {
- return Align(1ULL << (getSubclassData<AlignmentField>()));
+ return Align::fromLog2(getSubclassData<AlignmentField>());
}
void setAlignment(Align Align) {
@@ -612,7 +612,7 @@ class AtomicCmpXchgInst : public Instruction {
/// Return the alignment of the memory that is being allocated by the
/// instruction.
Align getAlign() const {
- return Align(1ULL << getSubclassData<AlignmentField>());
+ return Align::fromLog2(getSubclassData<AlignmentField>());
}
void setAlignment(Align Align) {
@@ -918,7 +918,7 @@ class AtomicRMWInst : public Instruction {
/// Return the alignment of the memory that is being allocated by the
/// instruction.
Align getAlign() const {
- return Align(1ULL << getSubclassData<AlignmentField>());
+ return Align::fromLog2(getSubclassData<AlignmentField>());
}
void setAlignment(Align Align) {
diff --git a/llvm/include/llvm/Support/Alignment.h b/llvm/include/llvm/Support/Alignment.h
index 2345dbe62c346..a1d1384607880 100644
--- a/llvm/include/llvm/Support/Alignment.h
+++ b/llvm/include/llvm/Support/Alignment.h
@@ -52,9 +52,6 @@ struct Align {
friend unsigned encode(struct MaybeAlign A);
friend struct MaybeAlign decodeMaybeAlign(unsigned Value);
- struct FromShiftValue {};
- constexpr Align(FromShiftValue, uint8_t Shift) : ShiftValue(Shift) {}
-
public:
/// Default is byte-aligned.
constexpr Align() = default;
@@ -72,6 +69,14 @@ struct Align {
assert(ShiftValue < 64 && "Broken invariant");
}
+ /// Returns an alignment of `1 << Log2Value` bytes.
+ constexpr static Align fromLog2(unsigned Log2Value) {
+ assert(Log2Value < 64 && "Alignment exponent is too large");
+ Align Out;
+ Out.ShiftValue = Log2Value;
+ return Out;
+ }
+
/// This is a hole in the type system and should not be abused.
/// Needed to interact with C for instance.
constexpr uint64_t value() const { return uint64_t(1) << ShiftValue; }
@@ -86,7 +91,7 @@ struct Align {
/// Allow constructions of constexpr Align.
template <size_t kValue> constexpr static Align Constant() {
- return Align(FromShiftValue{}, ConstantLog2<kValue>());
+ return fromLog2(ConstantLog2<kValue>());
}
/// Allow constructions of constexpr Align from types.
diff --git a/llvm/lib/CodeGen/MachineBlockPlacement.cpp b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
index 9c9c482276999..276e1bc67f797 100644
--- a/llvm/lib/CodeGen/MachineBlockPlacement.cpp
+++ b/llvm/lib/CodeGen/MachineBlockPlacement.cpp
@@ -3118,10 +3118,10 @@ void MachineBlockPlacement::alignBlocks() {
// Align all of the blocks in the function to a specific alignment.
for (MachineBasicBlock &MBB : *F) {
if (HasMaxBytesOverride)
- MBB.setAlignment(Align(1ULL << AlignAllBlock),
+ MBB.setAlignment(Align::fromLog2(AlignAllBlock),
MaxBytesForAlignmentOverride);
else
- MBB.setAlignment(Align(1ULL << AlignAllBlock));
+ MBB.setAlignment(Align::fromLog2(AlignAllBlock));
}
else if (AlignAllNonFallThruBlocks) {
// Align all of the blocks that have no fall-through predecessors to a
@@ -3130,10 +3130,10 @@ void MachineBlockPlacement::alignBlocks() {
auto LayoutPred = std::prev(MBI);
if (!LayoutPred->isSuccessor(&*MBI)) {
if (HasMaxBytesOverride)
- MBI->setAlignment(Align(1ULL << AlignAllNonFallThruBlocks),
+ MBI->setAlignment(Align::fromLog2(AlignAllNonFallThruBlocks),
MaxBytesForAlignmentOverride);
else
- MBI->setAlignment(Align(1ULL << AlignAllNonFallThruBlocks));
+ MBI->setAlignment(Align::fromLog2(AlignAllNonFallThruBlocks));
}
}
}
diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp
index 282cce8667deb..4be10bc8b4202 100644
--- a/llvm/lib/CodeGen/MachineFunction.cpp
+++ b/llvm/lib/CodeGen/MachineFunction.cpp
@@ -237,7 +237,7 @@ void MachineFunction::init() {
Alignment = std::max(Alignment, Align(4));
if (AlignAllFunctions)
- Alignment = Align(1ULL << AlignAllFunctions);
+ Alignment = Align::fromLog2(AlignAllFunctions);
JumpTableInfo = nullptr;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 05398cb82f22a..7bd01594d394b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -14519,7 +14519,8 @@ MaybeAlign SelectionDAG::InferPtrAlign(SDValue Ptr) const {
llvm::computeKnownBits(GV, Known, getDataLayout());
unsigned AlignBits = Known.countMinTrailingZeros();
if (AlignBits)
- return commonAlignment(Align(1ull << std::min(31U, AlignBits)), GVOffset);
+ return commonAlignment(Align::fromLog2(std::min(31U, AlignBits)),
+ GVOffset);
}
// If this is a direct reference to a stack slot, use information about the
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 588cc8e3ffde3..b50f27cca1be9 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -3550,7 +3550,7 @@ bool AsmParser::parseDirectivePrefAlign() {
getStreamer().getCurrentSectionOnly()->getName() +
"'");
- getStreamer().emitPrefAlign(Align(1ULL << Log2Alignment), *End, EmitNops,
+ getStreamer().emitPrefAlign(Align::fromLog2(Log2Alignment), *End, EmitNops,
Fill, getTargetParser().getSTI());
return false;
}
@@ -5200,11 +5200,11 @@ bool AsmParser::parseDirectiveComm(bool IsLocal) {
// Create the Symbol as a common or local common with Size and Pow2Alignment
if (IsLocal) {
getStreamer().emitLocalCommonSymbol(Sym, Size,
- Align(1ULL << Pow2Alignment));
+ Align::fromLog2(Pow2Alignment));
return false;
}
- getStreamer().emitCommonSymbol(Sym, Size, Align(1ULL << Pow2Alignment));
+ getStreamer().emitCommonSymbol(Sym, Size, Align::fromLog2(Pow2Alignment));
return false;
}
@@ -6016,7 +6016,7 @@ bool AsmParser::parseDirectiveBundleAlignMode() {
"invalid bundle alignment size (expected between 1 and 30)"))
return true;
- getStreamer().emitBundleAlignMode(Align(1ULL << AlignSizePow2));
+ getStreamer().emitBundleAlignMode(Align::fromLog2(AlignSizePow2));
return false;
}
diff --git a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
index ba6813c142266..de394168abe10 100644
--- a/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
+++ b/llvm/lib/MC/MCParser/DarwinAsmParser.cpp
@@ -862,7 +862,7 @@ bool DarwinAsmParser::parseDirectiveTBSS(StringRef, SMLoc) {
getContext().getMachOSection("__DATA", "__thread_bss",
MachO::S_THREAD_LOCAL_ZEROFILL, 0,
SectionKind::getThreadBSS()),
- Sym, Size, Align(1ULL << Pow2Alignment));
+ Sym, Size, Align::fromLog2(Pow2Alignment));
return false;
}
@@ -948,7 +948,7 @@ bool DarwinAsmParser::parseDirectiveZerofill(StringRef, SMLoc) {
getStreamer().emitZerofill(
getContext().getMachOSection(Segment, Section, MachO::S_ZEROFILL, 0,
SectionKind::getBSS()),
- Sym, Size, Align(1ULL << Pow2Alignment), SectionLoc);
+ Sym, Size, Align::fromLog2(Pow2Alignment), SectionLoc);
return false;
}
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index 6b97f16aa6fcc..ac525f175fd54 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -4629,11 +4629,11 @@ bool MasmParser::parseDirectiveComm(bool IsLocal) {
// Create the Symbol as a common or local common with Size and Pow2Alignment.
if (IsLocal) {
getStreamer().emitLocalCommonSymbol(Sym, Size,
- Align(1ULL << Pow2Alignment));
+ Align::fromLog2(Pow2Alignment));
return false;
}
- getStreamer().emitCommonSymbol(Sym, Size, Align(1ULL << Pow2Alignment));
+ getStreamer().emitCommonSymbol(Sym, Size, Align::fromLog2(Pow2Alignment));
return false;
}
diff --git a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
index 8cd418276f851..af29762580600 100644
--- a/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
+++ b/llvm/lib/ObjCopy/MachO/MachOLayoutBuilder.cpp
@@ -159,7 +159,7 @@ uint64_t MachOLayoutBuilder::layoutSegments() {
Sec->Offset = 0;
} else {
uint64_t PaddingSize =
- offsetToAlignment(SegFileSize, Align(1ull << Sec->Align));
+ offsetToAlignment(SegFileSize, Align::fromLog2(Sec->Align));
Sec->Offset = SegOffset + SegFileSize + PaddingSize;
Sec->Size = Sec->Content.size();
SegFileSize += PaddingSize + Sec->Size;
diff --git a/llvm/lib/Target/ARM/ARMISelLowering.cpp b/llvm/lib/Target/ARM/ARMISelLowering.cpp
index 0652c231bc70c..1f94fec4a3f79 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMISelLowering.cpp
@@ -1440,9 +1440,10 @@ ARMTargetLowering::ARMTargetLowering(const TargetMachine &TM_,
// Prefer likely predicted branches to selects on out-of-order cores.
PredictableSelectIsExpensive = Subtarget->getSchedModel().isOutOfOrder();
- setPrefLoopAlignment(Align(1ULL << Subtarget->getPreferBranchLogAlignment()));
+ setPrefLoopAlignment(
+ Align::fromLog2(Subtarget->getPreferBranchLogAlignment()));
setPrefFunctionAlignment(
- Align(1ULL << Subtarget->getPreferBranchLogAlignment()));
+ Align::fromLog2(Subtarget->getPreferBranchLogAlignment()));
setMinFunctionAlignment(Subtarget->isThumb() ? Align(2) : Align(4));
diff --git a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
index ea9155c60d381..21fabe1d07e38 100644
--- a/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
+++ b/llvm/lib/Target/BPF/BPFPreserveStaticOffset.cpp
@@ -291,7 +291,7 @@ static void reconstructCommon(CallInst *Call, GetElementPtrInst *GEP, T *Insn,
Insn->setOrdering((AtomicOrdering)getOperandAsUnsigned(Call, 2 + Delta));
Insn->setSyncScopeID(getOperandAsUnsigned(Call, 3 + Delta));
unsigned AlignShiftValue = getOperandAsUnsigned(Call, 4 + Delta);
- Insn->setAlignment(Align(1ULL << AlignShiftValue));
+ Insn->setAlignment(Align::fromLog2(AlignShiftValue));
GEP->setDebugLoc(Call->getDebugLoc());
Insn->setDebugLoc(Call->getDebugLoc());
Insn->setAAMetadata(Call->getAAMetadata());
diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
index 41a6afa2f59ca..b6e16893bc134 100644
--- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
+++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp
@@ -1939,7 +1939,7 @@ HexagonTargetLowering::validateConstPtrAlignment(SDValue Ptr, Align NeedAlign,
return true;
unsigned Addr = CA->getZExtValue();
Align HaveAlign =
- Addr != 0 ? Align(1ull << llvm::countr_zero(Addr)) : NeedAlign;
+ Addr != 0 ? Align::fromLog2(llvm::countr_zero(Addr)) : NeedAlign;
if (HaveAlign >= NeedAlign)
return true;
diff --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
index 71490f3b7a37c..54a2260b8311c 100644
--- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -289,7 +289,7 @@ bool MipsSEDAGToDAGISel::selectAddrFrameIndexOffset(
Base = Addr.getOperand(0);
// If base is a FI, additional offset calculation is done in
// eliminateFrameIndex, otherwise we need to check the alignment
- const Align Alignment(1ULL << ShiftAmount);
+ const Align Alignment = Align::fromLog2(ShiftAmount);
if (!isAligned(Alignment, CN->getZExtValue()))
return false;
}
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index a265c163cf276..6304509e365a5 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -65673,6 +65673,6 @@ Align X86TargetLowering::getPrefLoopAlignment(
std::optional<int> InnermostAlign =
Subtarget.getCLOpts().experimental_pref_innermost_loop_alignment;
if (ML && ML->isInnermost() && InnermostAlign)
- return Align(1ULL << *InnermostAlign);
+ return Align::fromLog2(*InnermostAlign);
return TargetLowering::getPrefLoopAlignment();
}
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index 6dfebe1cc15cc..2567c569899de 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -7781,7 +7781,7 @@ MachineInstr *X86InstrInfo::foldMemoryOperandImpl(
if (I) {
unsigned Opcode = I->DstOp;
if (Alignment <
- Align(1ULL << ((I->Flags & TB_ALIGN_MASK) >> TB_ALIGN_SHIFT)))
+ Align::fromLog2((I->Flags & TB_ALIGN_MASK) >> TB_ALIGN_SHIFT))
return nullptr;
bool NarrowToMOV32rm = false;
if (Size) {
diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
index 9af51dedab174..baf2567d3e957 100644
--- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
+++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp
@@ -5270,7 +5270,7 @@ static unsigned getKnownAlignForUse(Attributor &A, AAAlign &QueryingAA,
if (ConstVals && ConstVals->isValidState() && ConstVals->isAtFixpoint()) {
unsigned ShiftValue = std::min(ConstVals->getAssumedMinTrailingZeros(),
Value::MaxAlignmentExponent);
- Align ConstAlign(UINT64_C(1) << ShiftValue);
+ Align ConstAlign = Align::fromLog2(ShiftValue);
if (ConstAlign >= AlignAA->getKnownAlign())
return Align(1).value();
}
@@ -5601,7 +5601,7 @@ struct AAAlignCallSiteReturned final
unsigned ShiftValue =
std::min(ConstVals->getAssumedMinTrailingZeros(),
Value::MaxAlignmentExponent);
- Alignment = Align(UINT64_C(1) << ShiftValue);
+ Alignment = Align::fromLog2(ShiftValue);
Valid = true;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 8c18d67db72db..6fb5f50244a46 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -2884,7 +2884,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
// the pointer argument.
if (NewAlignmentLog > Log2(CI.getRetAlign().valueOrOne())) {
CI.addRetAttr(Attribute::getWithAlignment(
- CI.getContext(), Align(uint64_t(1) << NewAlignmentLog)));
+ CI.getContext(), Align::fromLog2(NewAlignmentLog)));
Changed = true;
}
if (Changed)
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index c8acf6dd63130..5125584a5422b 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -2366,7 +2366,7 @@ void ModuleAddressSanitizer::InstrumentGlobalsWithMetadataArray(
M, ArrayOfGlobalStructTy, false, GlobalVariable::InternalLinkage,
ConstantArray::get(ArrayOfGlobalStructTy, MetadataInitializers), "");
if (Mapping.Scale > 3)
- AllGlobals->setAlignment(Align(1ULL << Mapping.Scale));
+ AllGlobals->setAlignment(Align::fromLog2(Mapping.Scale));
if (ConstructorKind == AsanCtorKind::Global)
IRB.CreateCall(AsanRegisterGlobals,
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index dfd6c3c0709f8..ea31e08a4661a 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -282,7 +282,7 @@ class HWAddressSanitizer {
public:
void init(const InstrumentationOptions &Opts, Triple &TargetTriple,
bool InstrumentWithCalls, bool CompileKernel);
- Align getObjectAlignment() const { return Align(1ULL << Scale); }
+ Align getObjectAlignment() const { return Align::fromLog2(Scale); }
bool isInGlobal() const { return Kind == OffsetKind::kGlobal; }
bool isInIfunc() const { return Kind == OffsetKind::kIfunc; }
bool isInTls() const { return Kind == OffsetKind::kTls; }
diff --git a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
index 42d42b8bae894..e2d9cc4450ff6 100644
--- a/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/TypeSanitizer.cpp
@@ -930,7 +930,8 @@ bool TypeSanitizer::instrumentMemInst(Value *V, Instruction *ShadowBase,
if (!Src) {
IRB.CreateMemSet(ShadowData, IRB.getInt8(0),
- IRB.CreateShl(Size, PtrShift), Align(1ull << PtrShift));
+ IRB.CreateShl(Size, PtrShift),
+ Align::fromLog2(PtrShift));
return true;
}
@@ -942,11 +943,13 @@ bool TypeSanitizer::instrumentMemInst(Valu...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/230920
More information about the cfe-commits
mailing list