[PATCH] D68201: [Alignment][NFC] Adding a max function.
Guillaume Chatelet via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 30 02:21:25 PDT 2019
gchatelet created this revision.
gchatelet added a reviewer: courbet.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This is patch is part of a series to introduce an Alignment type.
See this thread for context: http://lists.llvm.org/pipermail/llvm-dev/2019-July/133851.html
See this patch for the introduction of the type: https://reviews.llvm.org/D64790
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D68201
Files:
llvm/include/llvm/Support/Alignment.h
llvm/unittests/Support/AlignmentTest.cpp
Index: llvm/unittests/Support/AlignmentTest.cpp
===================================================================
--- llvm/unittests/Support/AlignmentTest.cpp
+++ llvm/unittests/Support/AlignmentTest.cpp
@@ -227,6 +227,20 @@
}
}
+TEST(AlignmentTest, Max) {
+ EXPECT_EQ(max(MaybeAlign(), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign()), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(1), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign(1)), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(2), Align(2)), Align(2));
+ EXPECT_EQ(max(Align(2), MaybeAlign(2)), Align(2));
+
+ EXPECT_EQ(max(MaybeAlign(4), Align(2)), Align(4));
+ EXPECT_EQ(max(Align(2), MaybeAlign(4)), Align(4));
+}
+
TEST(AlignmentTest, AssumeAligned) {
EXPECT_EQ(assumeAligned(0), Align(1));
EXPECT_EQ(assumeAligned(0), Align());
Index: llvm/include/llvm/Support/Alignment.h
===================================================================
--- llvm/include/llvm/Support/Alignment.h
+++ llvm/include/llvm/Support/Alignment.h
@@ -333,6 +333,14 @@
return Lhs ? Lhs.getValue() / Divisor : MaybeAlign();
}
+inline Align max(MaybeAlign Lhs, Align Rhs) {
+ return Lhs && *Lhs > Rhs ? *Lhs : Rhs;
+}
+
+inline Align max(Align Lhs, MaybeAlign Rhs) {
+ return Rhs && *Rhs > Lhs ? *Rhs : Lhs;
+}
+
#undef ALIGN_CHECK_ISPOSITIVE
#undef ALIGN_CHECK_ISSET
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68201.222378.patch
Type: text/x-patch
Size: 1354 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190930/6135cce7/attachment.bin>
More information about the llvm-commits
mailing list