forked from OSchip/llvm-project
[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
This commit is contained in:
parent
8f8935139a
commit
704b2e162c
|
@ -488,6 +488,10 @@ bool matchUnaryPredicate(const MachineRegisterInfo &MRI, Register Reg,
|
||||||
/// the value \p Val contains a true value.
|
/// the value \p Val contains a true value.
|
||||||
bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
|
bool isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
|
||||||
bool IsFP);
|
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
|
/// Returns an integer representing true, as defined by the
|
||||||
/// TargetBooleanContents.
|
/// TargetBooleanContents.
|
||||||
|
|
|
@ -1278,6 +1278,18 @@ bool llvm::isConstTrueVal(const TargetLowering &TLI, int64_t Val, bool IsVector,
|
||||||
llvm_unreachable("Invalid boolean contents");
|
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,
|
int64_t llvm::getICmpTrueVal(const TargetLowering &TLI, bool IsVector,
|
||||||
bool IsFP) {
|
bool IsFP) {
|
||||||
switch (TLI.getBooleanContents(IsVector, IsFP)) {
|
switch (TLI.getBooleanContents(IsVector, IsFP)) {
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//
|
//
|
||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
#include "GISelMITest.h"
|
||||||
#include "llvm/CodeGen/GlobalISel/Utils.h"
|
#include "llvm/CodeGen/GlobalISel/Utils.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
@ -245,4 +246,23 @@ TEST(GISelUtilsTest, getLCMType) {
|
||||||
EXPECT_EQ(V4P1, getLCMType(P1, V2S64));
|
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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue