Skip to content

Commit 2bc637b

Browse files
committed
ValueTracking: Handle ConstantAggregateZero in computeKnownFPClass
1 parent 0832b85 commit 2bc637b

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

llvm/lib/Analysis/ValueTracking.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4507,6 +4507,12 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
45074507
return;
45084508
}
45094509

4510+
if (isa<ConstantAggregateZero>(V)) {
4511+
Known.KnownFPClasses = fcPosZero;
4512+
Known.SignBit = false;
4513+
return;
4514+
}
4515+
45104516
// Try to handle fixed width vector constants
45114517
auto *VFVTy = dyn_cast<FixedVectorType>(V->getType());
45124518
const Constant *CV = dyn_cast<Constant>(V);

llvm/test/Transforms/Attributor/nofpclass.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2644,7 +2644,7 @@ bb:
26442644

26452645
define [4 x float] @constant_aggregate_zero() {
26462646
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2647-
; CHECK-LABEL: define [4 x float] @constant_aggregate_zero
2647+
; CHECK-LABEL: define nofpclass(nan inf nzero sub norm) [4 x float] @constant_aggregate_zero
26482648
; CHECK-SAME: () #[[ATTR3]] {
26492649
; CHECK-NEXT: ret [4 x float] zeroinitializer
26502650
;
@@ -2662,7 +2662,7 @@ define <vscale x 4 x float> @scalable_splat_pnorm() {
26622662

26632663
define <vscale x 4 x float> @scalable_splat_zero() {
26642664
; CHECK: Function Attrs: mustprogress nofree norecurse nosync nounwind willreturn memory(none)
2665-
; CHECK-LABEL: define noundef <vscale x 4 x float> @scalable_splat_zero
2665+
; CHECK-LABEL: define noundef nofpclass(nan inf nzero sub norm) <vscale x 4 x float> @scalable_splat_zero
26662666
; CHECK-SAME: () #[[ATTR3]] {
26672667
; CHECK-NEXT: ret <vscale x 4 x float> zeroinitializer
26682668
;

llvm/unittests/Analysis/ValueTrackingTest.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,27 @@ TEST_F(ComputeKnownFPClassTest, SqrtNszSignBit) {
20162016
}
20172017
}
20182018

2019+
TEST_F(ComputeKnownFPClassTest, Constants) {
2020+
parseAssembly("declare float @func()\n"
2021+
"define float @test() {\n"
2022+
" %A = call float @func()\n"
2023+
" ret float %A\n"
2024+
"}\n");
2025+
2026+
Type *F32 = Type::getFloatTy(Context);
2027+
Type *V4F32 = FixedVectorType::get(F32, 4);
2028+
2029+
{
2030+
KnownFPClass ConstAggZero = computeKnownFPClass(
2031+
ConstantAggregateZero::get(V4F32), M->getDataLayout(), fcAllFlags, 0,
2032+
nullptr, nullptr, nullptr, nullptr);
2033+
2034+
EXPECT_EQ(fcPosZero, ConstAggZero.KnownFPClasses);
2035+
ASSERT_TRUE(ConstAggZero.SignBit);
2036+
EXPECT_FALSE(*ConstAggZero.SignBit);
2037+
}
2038+
}
2039+
20192040
TEST_F(ValueTrackingTest, isNonZeroRecurrence) {
20202041
parseAssembly(R"(
20212042
define i1 @test(i8 %n, i8 %r) {

0 commit comments

Comments
 (0)