Skip to content

Commit 3c126d5

Browse files
committed
[Alignment] Replace commonAlignment with std::min
`commonAlignment` is a shortcut to pick the smallest of two `Align` objects. As-is it doesn't bring much value compared to `std::min`. Differential Revision: https://reviews.llvm.org/D128345
1 parent 3f0578d commit 3c126d5

File tree

6 files changed

+9
-28
lines changed

6 files changed

+9
-28
lines changed

llvm/include/llvm/Support/Alignment.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,6 @@ inline uint64_t offsetToAlignedAddr(const void *Addr, Align Alignment) {
208208
/// Returns the log2 of the alignment.
209209
inline unsigned Log2(Align A) { return A.ShiftValue; }
210210

211-
/// Returns the alignment that satisfies both alignments.
212-
/// Same semantic as MinAlign.
213-
inline Align commonAlignment(Align A, Align B) { return std::min(A, B); }
214-
215211
/// Returns the alignment that satisfies both alignments.
216212
/// Same semantic as MinAlign.
217213
inline Align commonAlignment(Align A, uint64_t Offset) {

llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7627,7 +7627,7 @@ LegalizerHelper::lowerMemcpy(MachineInstr &MI, Register Dst, Register Src,
76277627

76287628
bool DstAlignCanChange = false;
76297629
MachineFrameInfo &MFI = MF.getFrameInfo();
7630-
Align Alignment = commonAlignment(DstAlign, SrcAlign);
7630+
Align Alignment = std::min(DstAlign, SrcAlign);
76317631

76327632
MachineInstr *FIDef = getOpcodeDef(TargetOpcode::G_FRAME_INDEX, Dst, MRI);
76337633
if (FIDef && !MFI.isFixedObjectIndex(FIDef->getOperand(1).getIndex()))
@@ -7735,7 +7735,7 @@ LegalizerHelper::lowerMemmove(MachineInstr &MI, Register Dst, Register Src,
77357735
bool DstAlignCanChange = false;
77367736
MachineFrameInfo &MFI = MF.getFrameInfo();
77377737
bool OptSize = shouldLowerMemFuncForSize(MF);
7738-
Align Alignment = commonAlignment(DstAlign, SrcAlign);
7738+
Align Alignment = std::min(DstAlign, SrcAlign);
77397739

77407740
MachineInstr *FIDef = getOpcodeDef(TargetOpcode::G_FRAME_INDEX, Dst, MRI);
77417741
if (FIDef && !MFI.isFixedObjectIndex(FIDef->getOperand(1).getIndex()))

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5861,7 +5861,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
58615861
// @llvm.memcpy defines 0 and 1 to both mean no alignment.
58625862
Align DstAlign = MCI.getDestAlign().valueOrOne();
58635863
Align SrcAlign = MCI.getSourceAlign().valueOrOne();
5864-
Align Alignment = commonAlignment(DstAlign, SrcAlign);
5864+
Align Alignment = std::min(DstAlign, SrcAlign);
58655865
bool isVol = MCI.isVolatile();
58665866
bool isTC = I.isTailCall() && isInTailCallPosition(I, DAG.getTarget());
58675867
// FIXME: Support passing different dest/src alignments to the memcpy DAG
@@ -5884,7 +5884,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
58845884
// @llvm.memcpy.inline defines 0 and 1 to both mean no alignment.
58855885
Align DstAlign = MCI.getDestAlign().valueOrOne();
58865886
Align SrcAlign = MCI.getSourceAlign().valueOrOne();
5887-
Align Alignment = commonAlignment(DstAlign, SrcAlign);
5887+
Align Alignment = std::min(DstAlign, SrcAlign);
58885888
bool isVol = MCI.isVolatile();
58895889
bool isTC = I.isTailCall() && isInTailCallPosition(I, DAG.getTarget());
58905890
// FIXME: Support passing different dest/src alignments to the memcpy DAG
@@ -5939,7 +5939,7 @@ void SelectionDAGBuilder::visitIntrinsicCall(const CallInst &I,
59395939
// @llvm.memmove defines 0 and 1 to both mean no alignment.
59405940
Align DstAlign = MMI.getDestAlign().valueOrOne();
59415941
Align SrcAlign = MMI.getSourceAlign().valueOrOne();
5942-
Align Alignment = commonAlignment(DstAlign, SrcAlign);
5942+
Align Alignment = std::min(DstAlign, SrcAlign);
59435943
bool isVol = MMI.isVolatile();
59445944
bool isTC = I.isTailCall() && isInTailCallPosition(I, DAG.getTarget());
59455945
// FIXME: Support passing different dest/src alignments to the memmove DAG

llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ bool MemCpyOptPass::processStore(StoreInst *SI, BasicBlock::iterator &BBI) {
773773
LI, SI, SI->getPointerOperand()->stripPointerCasts(),
774774
LI->getPointerOperand()->stripPointerCasts(),
775775
DL.getTypeStoreSize(SI->getOperand(0)->getType()),
776-
commonAlignment(SI->getAlign(), LI->getAlign()), GetCall);
776+
std::min(SI->getAlign(), LI->getAlign()), GetCall);
777777
if (changed) {
778778
eraseInstruction(SI);
779779
eraseInstruction(LI);

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3558,7 +3558,7 @@ static LoadsState canVectorizeLoads(ArrayRef<Value *> VL, const Value *VL0,
35583558
Align CommonAlignment = cast<LoadInst>(VL0)->getAlign();
35593559
for (Value *V : VL)
35603560
CommonAlignment =
3561-
commonAlignment(CommonAlignment, cast<LoadInst>(V)->getAlign());
3561+
std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
35623562
auto *VecTy = FixedVectorType::get(ScalarTy, VL.size());
35633563
if (TTI.isLegalMaskedGather(VecTy, CommonAlignment) &&
35643564
!TTI.forceScalarizeMaskedGather(VecTy, CommonAlignment))
@@ -6440,7 +6440,7 @@ InstructionCost BoUpSLP::getEntryCost(const TreeEntry *E,
64406440
Align CommonAlignment = Alignment;
64416441
for (Value *V : VL)
64426442
CommonAlignment =
6443-
commonAlignment(CommonAlignment, cast<LoadInst>(V)->getAlign());
6443+
std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
64446444
VecLdCost = TTI->getGatherScatterOpCost(
64456445
Instruction::Load, VecTy, cast<LoadInst>(VL0)->getPointerOperand(),
64466446
/*VariableMask=*/false, CommonAlignment, CostKind, VL0);
@@ -8157,7 +8157,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E) {
81578157
Align CommonAlignment = LI->getAlign();
81588158
for (Value *V : E->Scalars)
81598159
CommonAlignment =
8160-
commonAlignment(CommonAlignment, cast<LoadInst>(V)->getAlign());
8160+
std::min(CommonAlignment, cast<LoadInst>(V)->getAlign());
81618161
NewLI = Builder.CreateMaskedGather(VecTy, VecPtr, CommonAlignment);
81628162
}
81638163
Value *V = propagateMetadata(NewLI, E->Scalars);

llvm/unittests/Support/AlignmentTest.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,6 @@ TEST(AlignmentTest, Log2) {
113113
}
114114
}
115115

116-
TEST(AlignmentTest, MinAlign) {
117-
struct {
118-
uint64_t A;
119-
uint64_t B;
120-
uint64_t MinAlign;
121-
} kTests[] = {
122-
{1, 2, 1},
123-
{8, 4, 4},
124-
};
125-
for (const auto &T : kTests) {
126-
EXPECT_EQ(MinAlign(T.A, T.B), T.MinAlign);
127-
EXPECT_EQ(commonAlignment(Align(T.A), Align(T.B)), T.MinAlign);
128-
}
129-
}
130-
131116
TEST(AlignmentTest, Encode_Decode) {
132117
for (uint64_t Value : getValidAlignments()) {
133118
{

0 commit comments

Comments
 (0)