[llvm] 0303606 - [Alignment] Use 'previous()' method instead of scalar division
Guillaume Chatelet via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 20 04:01:54 PDT 2022
Author: Guillaume Chatelet
Date: 2022-06-20T11:01:43Z
New Revision: 03036061c7716f88cef32ebe16f2c10307383ef8
URL: https://github.com/llvm/llvm-project/commit/03036061c7716f88cef32ebe16f2c10307383ef8
DIFF: https://github.com/llvm/llvm-project/commit/03036061c7716f88cef32ebe16f2c10307383ef8.diff
LOG: [Alignment] Use 'previous()' method instead of scalar division
This is in preparation of integration with D128052.
Differential Revision: https://reviews.llvm.org/D128169
Added:
Modified:
llvm/include/llvm/Support/Alignment.h
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/unittests/Support/AlignmentTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/Alignment.h b/llvm/include/llvm/Support/Alignment.h
index 24a2f6244c895..f12d8ed074d80 100644
--- a/llvm/include/llvm/Support/Alignment.h
+++ b/llvm/include/llvm/Support/Alignment.h
@@ -84,6 +84,14 @@ struct Align {
/// Needed to interact with C for instance.
uint64_t value() const { return uint64_t(1) << ShiftValue; }
+ // Returns the previous alignment.
+ Align previous() const {
+ assert(ShiftValue != 0 && "Undefined operation");
+ Align Out;
+ Out.ShiftValue = ShiftValue - 1;
+ return Out;
+ }
+
/// Allow constructions of constexpr Align.
template <size_t kValue> constexpr static LogValue Constant() {
return LogValue{static_cast<uint8_t>(CTLog2<kValue>())};
@@ -314,13 +322,6 @@ bool operator>=(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
bool operator<(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
bool operator>(MaybeAlign Lhs, MaybeAlign Rhs) = delete;
-inline Align operator/(Align Lhs, uint64_t Divisor) {
- assert(llvm::isPowerOf2_64(Divisor) &&
- "Divisor must be positive and a power of 2");
- assert(Lhs != 1 && "Can't halve byte alignment");
- return Align(Lhs.value() / Divisor);
-}
-
#ifndef NDEBUG
// For usage in LLVM_DEBUG macros.
inline std::string DebugStr(const Align &A) {
diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
index e8030df899a0f..5226816defae2 100644
--- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -7662,7 +7662,7 @@ LegalizerHelper::lowerMemcpy(MachineInstr &MI, Register Dst, Register Src,
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->hasStackRealignment(MF))
while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign))
- NewAlign = NewAlign / 2;
+ NewAlign = NewAlign.previous();
if (NewAlign > Alignment) {
Alignment = NewAlign;
@@ -7770,7 +7770,7 @@ LegalizerHelper::lowerMemmove(MachineInstr &MI, Register Dst, Register Src,
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->hasStackRealignment(MF))
while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign))
- NewAlign = NewAlign / 2;
+ NewAlign = NewAlign.previous();
if (NewAlign > Alignment) {
Alignment = NewAlign;
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index 3b54916f80bf9..7a72999163aea 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6751,7 +6751,7 @@ static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, const SDLoc &dl,
const TargetRegisterInfo *TRI = MF.getSubtarget().getRegisterInfo();
if (!TRI->hasStackRealignment(MF))
while (NewAlign > Alignment && DL.exceedsNaturalStackAlignment(NewAlign))
- NewAlign = NewAlign / 2;
+ NewAlign = NewAlign.previous();
if (NewAlign > Alignment) {
// Give the stack frame object a larger alignment if needed.
diff --git a/llvm/unittests/Support/AlignmentTest.cpp b/llvm/unittests/Support/AlignmentTest.cpp
index 9841e0938a5a3..f5f0d5e31bee9 100644
--- a/llvm/unittests/Support/AlignmentTest.cpp
+++ b/llvm/unittests/Support/AlignmentTest.cpp
@@ -77,7 +77,7 @@ TEST(AlignmentTest, CheckMaybeAlignHasValue) {
TEST(AlignmentTest, Division) {
for (uint64_t Value : getValidAlignments()) {
if (Value > 1) {
- EXPECT_EQ(Align(Value) / 2, Value / 2);
+ EXPECT_EQ(Align(Value).previous(), Value / 2);
}
}
}
@@ -292,13 +292,6 @@ TEST(AlignmentDeathTest, CantConvertUnsetMaybe) {
EXPECT_DEATH((MaybeAlign(0).getValue()), ".*");
}
-TEST(AlignmentDeathTest, Division) {
- EXPECT_DEATH(Align(1) / 2, "Can't halve byte alignment");
-
- EXPECT_DEATH(Align(8) / 0, "Divisor must be positive and a power of 2");
- EXPECT_DEATH(Align(8) / 3, "Divisor must be positive and a power of 2");
-}
-
TEST(AlignmentDeathTest, InvalidCTors) {
EXPECT_DEATH((Align(0)), "Value must not be 0");
for (uint64_t Value : getNonPowerOfTwo()) {
More information about the llvm-commits
mailing list