[PATCH] D128169: [Alignment] Use 'previous()' method instead of scalar division
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 20 02:58:26 PDT 2022
gchatelet updated this revision to Diff 438316.
gchatelet added a comment.
- Address comments
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D128169/new/
https://reviews.llvm.org/D128169
Files:
llvm/include/llvm/Support/Alignment.h
llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/unittests/Support/AlignmentTest.cpp
Index: llvm/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/unittests/Support/AlignmentTest.cpp
+++ llvm/unittests/Support/AlignmentTest.cpp
@@ -77,7 +77,7 @@
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 @@
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()) {
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -6751,7 +6751,7 @@
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.
Index: llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
+++ llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
@@ -7662,7 +7662,7 @@
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 @@
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;
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ llvm/include/llvm/Support/Alignment.h
@@ -84,6 +84,14 @@
/// 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>())};
@@ -319,13 +327,6 @@
return Align(Lhs.value() * Rhs);
}
-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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128169.438316.patch
Type: text/x-patch
Size: 3594 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220620/e5e85546/attachment.bin>
More information about the llvm-commits
mailing list