Skip to content

Commit

Permalink
ValueTracking: Handle ConstantAggregateZero in computeKnownFPClass
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenm committed Apr 8, 2024
1 parent 0832b85 commit 2bc637b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
6 changes: 6 additions & 0 deletions llvm/lib/Analysis/ValueTracking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/Attributor/nofpclass.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
Expand All @@ -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
;
Expand Down
21 changes: 21 additions & 0 deletions llvm/unittests/Analysis/ValueTrackingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2bc637b

Please sign in to comment.