[PATCH] D66923: GlobalISel: Add maskedValueIsZero and signBitIsZero to known bits
Matt Arsenault via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 28 19:03:47 PDT 2019
arsenm created this revision.
arsenm added reviewers: aditya_nandakumar, aemerson, paquette.
Herald added subscribers: Petar.Avramovic, volkan, rovka, wdng.
I dropped the DemandedElts since it seems to be missing from some of
the new interfaces, but not others.
https://reviews.llvm.org/D66923
Files:
include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
lib/CodeGen/GlobalISel/GISelKnownBits.cpp
unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
Index: unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
===================================================================
--- unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
+++ unittests/CodeGen/GlobalISel/KnownBitsTest.cpp
@@ -86,3 +86,19 @@
APInt Zeroes = Info.getKnownZeroes(SrcReg);
EXPECT_EQ(Known.Zero, Zeroes);
}
+
+TEST_F(GISelMITest, TestSignBitIsZero) {
+ if (!TM)
+ return;
+
+ const LLT S32 = LLT::scalar(32);
+ auto SignBit = B.buildConstant(S32, 0x8000000);
+ auto Zero = B.buildConstant(S32, 0);
+
+ GISelKnownBits KnownBits(*MF);
+
+ EXPECT_TRUE(KnownBits.signBitIsZero(Zero.getReg(0)));
+ EXPECT_FALSE(KnownBits.signBitIsZero(Zero.getReg(0)));
+ EXPECT_FALSE(KnownBits.signBitIsZero(SignBit.getReg(0)));
+ EXPECT_TRUE(KnownBits.signBitIsZero(SignBit.getReg(0)));
+}
Index: lib/CodeGen/GlobalISel/GISelKnownBits.cpp
===================================================================
--- lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -75,6 +75,12 @@
return Known;
}
+bool GISelKnownBits::signBitIsZero(Register R) {
+ LLT Ty = MRI.getType(R);
+ unsigned BitWidth = Ty.getScalarSizeInBits();
+ return maskedValueIsZero(R, APInt::getSignMask(BitWidth));
+}
+
APInt GISelKnownBits::getKnownZeroes(Register R) {
return getKnownBits(R).Zero;
}
Index: include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
===================================================================
--- include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
+++ include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
@@ -47,6 +47,17 @@
APInt getKnownZeroes(Register R);
APInt getKnownOnes(Register R);
+ /// \return true if 'V & Mask' is known to be zero in DemandedElts. We use
+ /// this predicate to simplify operations downstream.
+ /// Mask is known to be zero for bits that V cannot have.
+ bool maskedValueIsZero(Register Val, const APInt &Mask) {
+ return Mask.isSubsetOf(getKnownBits(Val).Zero);
+ }
+
+ /// \return true if the sign bit of Op is known to be zero. We use this
+ /// predicate to simplify operations downstream.
+ bool signBitIsZero(Register Op);
+
// FIXME: Is this the right place for G_FRAME_INDEX? Should it be in
// TargetLowering?
void computeKnownBitsForFrameIndex(Register R, KnownBits &Known,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66923.217760.patch
Type: text/x-patch
Size: 2301 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190829/e6a8c2d2/attachment.bin>
More information about the llvm-commits
mailing list