[PATCH] D91754: [GlobalISel] Add isConstFalseVal helper to Utils
Jessica Paquette via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 15:44:54 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG704b2e162c53: [GlobalISel] Add isConstFalseVal helper to Utils (authored by paquette).
Changed prior to commit:
https://reviews.llvm.org/D91754?vs=306260&id=463691#toc
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91754/new/
https://reviews.llvm.org/D91754
Files:
llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
Index: llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
===================================================================
--- llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
+++ llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "GISelMITest.h"
#include "llvm/CodeGen/GlobalISel/Utils.h"
#include "gtest/gtest.h"
@@ -245,4 +246,23 @@
EXPECT_EQ(V4P1, getLCMType(P1, V2S64));
}
+TEST_F(AArch64GISelMITest, ConstFalseTest) {
+ setUp();
+ if (!TM)
+ return;
+ const auto &TLI = *B.getMF().getSubtarget().getTargetLowering();
+ bool BooleanChoices[2] = {true, false};
+
+ // AArch64 uses ZeroOrOneBooleanContent for scalars, and
+ // ZeroOrNegativeOneBooleanContent for vectors.
+ for (auto IsVec : BooleanChoices) {
+ for (auto IsFP : BooleanChoices) {
+ EXPECT_TRUE(isConstFalseVal(TLI, 0, IsVec, IsFP));
+ EXPECT_FALSE(isConstFalseVal(TLI, 1, IsVec, IsFP));
+
+ // This would be true with UndefinedBooleanContent.
+ EXPECT_FALSE(isConstFalseVal(TLI, 2, IsVec, IsFP));
+ }
+ }
+}
}
Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1278,6 +1278,18 @@
llvm_unreachable("Invalid boolean contents");
}
+bool llvm::isConstFalseVal(const TargetLowering &TLI, int64_t Val,
+ bool IsVector, bool IsFP) {
+ switch (TLI.getBooleanContents(IsVector, IsFP)) {
+ case TargetLowering::UndefinedBooleanContent:
+ return ~Val & 0x1;
+ case TargetLowering::ZeroOrOneBooleanContent:
+ case TargetLowering::ZeroOrNegativeOneBooleanContent:
+ return Val == 0;
+ }
+ llvm_unreachable("Invalid boolean contents");
+}
+
int64_t llvm::getICmpTrueVal(const TargetLowering &TLI, bool IsVector,
bool IsFP) {
switch (TLI.getBooleanContents(IsVector, IsFP)) {
Index: llvm/include/llvm/CodeGen/GlobalISel/Utils.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -488,6 +488,10 @@
/// the value \p Val contains a true value.
bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
bool IsFP);
+/// \returns true if given the TargetLowering's boolean contents information,
+/// the value \p Val contains a false value.
+bool isConstFalseVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
+ bool IsFP);
/// Returns an integer representing true, as defined by the
/// TargetBooleanContents.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91754.463691.patch
Type: text/x-patch
Size: 2752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220928/78419c83/attachment.bin>
More information about the llvm-commits
mailing list