[PATCH] D91754: [GlobalISel] Add isConstFalseVal helper to Utils
Jessica Paquette via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 18 16:31:38 PST 2020
paquette created this revision.
paquette added reviewers: arsenm, aemerson.
Herald added subscribers: hiraditya, rovka.
Herald added a project: LLVM.
paquette requested review of this revision.
Herald added a subscriber: wdng.
Add a utility function which returns true if the given value is a constant false value.
This is necessary to port one of the compare simplifications in `TargetLowering::SimplifySetCC`.
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
@@ -294,4 +294,24 @@
}
}
+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));
+ }
+ }
+}
+
} // namespace
Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -734,6 +734,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");
+}
+
bool llvm::isExtendedTrueVal(const TargetLowering &TLI, int64_t Val,
const LLT &ExtTy, const LLT &OrigTy, bool IsFP,
bool IsSignExtended) {
Index: llvm/include/llvm/CodeGen/GlobalISel/Utils.h
===================================================================
--- llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -258,6 +258,11 @@
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 true if \p Val is a true value extended from \p OrigTy to \p ExtTy.
/// \p IsFP is true if the value is floating point.
/// \p IsSignExtended is true if the extension should be signed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91754.306260.patch
Type: text/x-patch
Size: 2627 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201119/6ae003bc/attachment.bin>
More information about the llvm-commits
mailing list