[PATCH] D52324: [ValueTracking] Allow select patterns to work on vectors in more places
Thomas Lively via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 24 16:40:17 PDT 2018
tlively updated this revision to Diff 166784.
tlively added a comment.
- Test cases where functions should return false
- Fix functions
Repository:
rL LLVM
https://reviews.llvm.org/D52324
Files:
lib/Analysis/ValueTracking.cpp
unittests/Analysis/ValueTrackingTest.cpp
Index: unittests/Analysis/ValueTrackingTest.cpp
===================================================================
--- unittests/Analysis/ValueTrackingTest.cpp
+++ unittests/Analysis/ValueTrackingTest.cpp
@@ -77,6 +77,43 @@
expectPattern({SPF_FMINNUM, SPNB_RETURNS_NAN, false});
}
+TEST_F(MatchSelectPatternTest, VectorFMin) {
+ parseAssembly(
+ "define <4 x float> @test(<4 x float> %a) {\n"
+ " %1 = fcmp ule <4 x float> %a, \n"
+ " <float 5.0, float 5.0, float 5.0, float 5.0>\n"
+ " %A = select <4 x i1> %1, <4 x float> %a,\n"
+ " <4 x float> <float 5.0, float 5.0, float 5.0, float 5.0>\n"
+ " ret <4 x float> %A\n"
+ "}\n");
+ expectPattern({SPF_FMINNUM, SPNB_RETURNS_NAN, false});
+}
+
+TEST_F(MatchSelectPatternTest, VectorNotFMinNaN) {
+ parseAssembly(
+ "define <4 x float> @test(<4 x float> %a) {\n"
+ " %1 = fcmp ule <4 x float> %a, \n"
+ " <float 5.0, float 0x7ff8000000000000, float 5.0, float 5.0>\n"
+ " %A = select <4 x i1> %1, <4 x float> %a,\n"
+ " <4 x float> <float 5.0, float 0x7ff8000000000000, float 5.0, float "
+ "5.0>\n"
+ " ret <4 x float> %A\n"
+ "}\n");
+ expectPattern({SPF_UNKNOWN, SPNB_NA, false});
+}
+
+TEST_F(MatchSelectPatternTest, VectorNotFMinZero) {
+ parseAssembly(
+ "define <4 x float> @test(<4 x float> %a) {\n"
+ " %1 = fcmp ule <4 x float> %a, \n"
+ " <float 5.0, float -0.0, float 5.0, float 5.0>\n"
+ " %A = select <4 x i1> %1, <4 x float> %a,\n"
+ " <4 x float> <float 5.0, float -0.0, float 5.0, float 5.0>\n"
+ " ret <4 x float> %A\n"
+ "}\n");
+ expectPattern({SPF_UNKNOWN, SPNB_NA, false});
+}
+
TEST_F(MatchSelectPatternTest, SimpleFMax) {
parseAssembly(
"define float @test(float %a) {\n"
Index: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -4397,12 +4397,34 @@
if (auto *C = dyn_cast<ConstantFP>(V))
return !C->isNaN();
+
+ if (auto *C = dyn_cast<ConstantDataVector>(V)) {
+ if (!C->getElementType()->isFloatingPointTy())
+ return false;
+ for (unsigned I = 0, E = C->getNumElements(); I < E; ++I) {
+ if (C->getElementAsAPFloat(I).isNaN())
+ return false;
+ }
+ return true;
+ }
+
return false;
}
static bool isKnownNonZero(const Value *V) {
if (auto *C = dyn_cast<ConstantFP>(V))
return !C->isZero();
+
+ if (auto *C = dyn_cast<ConstantDataVector>(V)) {
+ if (!C->getElementType()->isFloatingPointTy())
+ return false;
+ for (unsigned I = 0, E = C->getNumElements(); I < E; ++I) {
+ if (C->getElementAsAPFloat(I).isZero())
+ return false;
+ }
+ return true;
+ }
+
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52324.166784.patch
Type: text/x-patch
Size: 2822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180924/b4df450c/attachment.bin>
More information about the llvm-commits
mailing list