[llvm] 704b2e1 - [GlobalISel] Add isConstFalseVal helper to Utils
Jessica Paquette via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 15:44:42 PDT 2022
Author: Jessica Paquette
Date: 2022-09-28T15:44:26-07:00
New Revision: 704b2e162c53ab964225799106ba3a45ee888d9f
URL: https://github.com/llvm/llvm-project/commit/704b2e162c53ab964225799106ba3a45ee888d9f
DIFF: https://github.com/llvm/llvm-project/commit/704b2e162c53ab964225799106ba3a45ee888d9f.diff
LOG: [GlobalISel] Add isConstFalseVal helper to Utils
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.
Differential Revision: https://reviews.llvm.org/D91754
Added:
Modified:
llvm/include/llvm/CodeGen/GlobalISel/Utils.h
llvm/lib/CodeGen/GlobalISel/Utils.cpp
llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
index 68f5003710b96..75d2c6d1fdd9f 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -488,6 +488,10 @@ bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg,
/// 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.
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index a6a51f35ab7c9..4e61fd98f79dc 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -1278,6 +1278,18 @@ bool llvm::isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
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)) {
diff --git a/llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp b/llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
index ab174403c13c7..939195c1bc27d 100644
--- a/llvm/unittests/CodeGen/GlobalISel/GISelUtilsTest.cpp
+++ b/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 @@ TEST(GISelUtilsTest, getLCMType) {
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));
+ }
+ }
+}
}
More information about the llvm-commits
mailing list