summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Arsenault <Matthew.Arsenault@amd.com>2024-04-04 11:43:09 -0400
committerMatt Arsenault <arsenm2@gmail.com>2024-04-08 09:26:12 -0400
commit2bc637b1ce935550b6e09618c76474253943a7cc (patch)
tree467a2d59648c74bc794cd28ce8315f1cdda8679a
parent0832b85e0f5b684ad2e5eaf29911ca806eb0db3d (diff)
ValueTracking: Handle ConstantAggregateZero in computeKnownFPClass
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp6
-rw-r--r--llvm/test/Transforms/Attributor/nofpclass.ll4
-rw-r--r--llvm/unittests/Analysis/ValueTrackingTest.cpp21
3 files changed, 29 insertions, 2 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5279f03767ed..0c8ab4c66cd1 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4507,6 +4507,12 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
return;
}
+ if (isa<ConstantAggregateZero>(V)) {
+ Known.KnownFPClasses = fcPosZero;
+ Known.SignBit = false;
+ return;
+ }
+
// Try to handle fixed width vector constants
auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
const Constant *CV = dyn_cast<Constant>(V);
diff --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index 96052815c044..8f3e9d2fd96b 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -2644,7 +2644,7 @@ bb:
define [4 x float] @constant_aggregate_zero() {
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define [4 x float] @constant_aggregate_zero
+; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) [4 x float] @constant_aggregate_zero
; CHECK-SAME: () #[[ATTR3]] {
; CHECK-NEXT: ret [4 x float] zeroinitializer
;
@@ -2662,7 +2662,7 @@ define <vscale x 4 x float> @scalable_splat_pnorm() {
define <vscale x 4 x float> @scalable_splat_zero() {
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define noundef <vscale x 4 x float> @scalable_splat_zero
+; CHECK-LABEL: define noundef nofpclass(nan inf nzero sub norm) <vscale x 4 x float> @scalable_splat_zero
; CHECK-SAME: () #[[ATTR3]] {
; CHECK-NEXT: ret <vscale x 4 x float> zeroinitializer
;
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 6c6897d83a25..b4d2270d7070 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2016,6 +2016,27 @@ TEST_F(ComputeKnownFPClassTest, SqrtNszSignBit) {
}
}
+TEST_F(ComputeKnownFPClassTest, Constants) {
+ parseAssembly("declare float @func()\n"
+ "define float @test() {\n"
+ " %A = call float @func()\n"
+ " ret float %A\n"
+ "}\n");
+
+ Type *F32 = Type::getFloatTy(Context);
+ Type *V4F32 = FixedVectorType::get(F32, 4);
+
+ {
+ KnownFPClass ConstAggZero = computeKnownFPClass(
+ ConstantAggregateZero::get(V4F32), M->getDataLayout(), fcAllFlags, 0,
+ nullptr, nullptr, nullptr, nullptr);
+
+ EXPECT_EQ(fcPosZero, ConstAggZero.KnownFPClasses);
+ ASSERT_TRUE(ConstAggZero.SignBit);
+ EXPECT_FALSE(*ConstAggZero.SignBit);
+ }
+}
+
TEST_F(ValueTrackingTest, isNonZeroRecurrence) {
parseAssembly(R"(
define i1 @test(i8 %n, i8 %r) {