[llvm] f78b346 - ValueTracking: Treat poison more aggressively in computeKnownFPClass (#87990)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 15 03:51:32 PDT 2024
Author: Matt Arsenault
Date: 2024-04-15T12:51:29+02:00
New Revision: f78b3466caa9296b32ec235dee87ace2dea94507
URL: https://github.com/llvm/llvm-project/commit/f78b3466caa9296b32ec235dee87ace2dea94507
DIFF: https://github.com/llvm/llvm-project/commit/f78b3466caa9296b32ec235dee87ace2dea94507.diff
LOG: ValueTracking: Treat poison more aggressively in computeKnownFPClass (#87990)
Assume no valid values, and the sign bit is 0.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
llvm/test/CodeGen/AMDGPU/fold-fabs.ll
llvm/test/Transforms/Attributor/nofpclass.ll
llvm/unittests/Analysis/ValueTrackingTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 5beea614e332ee..b3abf016cfb93d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4664,6 +4664,12 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
return;
}
+ if (isa<PoisonValue>(V)) {
+ Known.KnownFPClasses = fcNone;
+ 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/CodeGen/AMDGPU/fold-fabs.ll b/llvm/test/CodeGen/AMDGPU/fold-fabs.ll
index bb2bad9d3521ad..a04bf445493253 100644
--- a/llvm/test/CodeGen/AMDGPU/fold-fabs.ll
+++ b/llvm/test/CodeGen/AMDGPU/fold-fabs.ll
@@ -99,12 +99,6 @@ define float @fold_abs_in_branch_poison(float %arg1, float %arg2) {
; GFX10-LABEL: fold_abs_in_branch_poison:
; GFX10: ; %bb.0: ; %entry
; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
-; GFX10-NEXT: v_add_f32_e64 v0, |s4|, |s4|
-; GFX10-NEXT: v_cmp_lt_f32_e32 vcc_lo, 1.0, v0
-; GFX10-NEXT: s_cbranch_vccnz .LBB3_2
-; GFX10-NEXT: ; %bb.1: ; %if
-; GFX10-NEXT: v_mul_f32_e64 v0, 0x3e4ccccd, |s4|
-; GFX10-NEXT: .LBB3_2: ; %exit
; GFX10-NEXT: s_setpc_b64 s[30:31]
entry:
%0 = fadd reassoc nnan nsz arcp contract afn float %arg1, %arg2
diff --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index 7828629f9fc010..d2d11e0276c4dc 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -54,6 +54,18 @@ define float @returned_poison() {
ret float poison
}
+; Know nothing
+define float @returned_freeze_poison() {
+; CHECK-LABEL: define noundef float @returned_freeze_poison() {
+; CHECK-NEXT: call void @unknown()
+; CHECK-NEXT: [[FREEZE_POISON:%.*]] = freeze float poison
+; CHECK-NEXT: ret float [[FREEZE_POISON]]
+;
+ call void @unknown()
+ %freeze.poison = freeze float poison
+ ret float %freeze.poison
+}
+
define double @returned_snan() {
; CHECK-LABEL: define noundef nofpclass(qnan inf zero sub norm) double @returned_snan() {
; CHECK-NEXT: call void @unknown()
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 6b1044876d366f..8ebd9b511f39fe 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -2035,6 +2035,61 @@ TEST_F(ComputeKnownFPClassTest, Constants) {
ASSERT_TRUE(ConstAggZero.SignBit);
EXPECT_FALSE(*ConstAggZero.SignBit);
}
+
+ {
+ KnownFPClass Undef =
+ computeKnownFPClass(UndefValue::get(F32), M->getDataLayout(),
+ fcAllFlags, 0, nullptr, nullptr, nullptr, nullptr);
+ EXPECT_EQ(fcAllFlags, Undef.KnownFPClasses);
+ EXPECT_FALSE(Undef.SignBit);
+ }
+
+ {
+ KnownFPClass Poison =
+ computeKnownFPClass(PoisonValue::get(F32), M->getDataLayout(),
+ fcAllFlags, 0, nullptr, nullptr, nullptr, nullptr);
+ EXPECT_EQ(fcNone, Poison.KnownFPClasses);
+ ASSERT_TRUE(Poison.SignBit);
+ EXPECT_FALSE(*Poison.SignBit);
+ }
+
+ {
+ // Assume the poison element should be 0.
+ Constant *ZeroF32 = ConstantFP::getZero(F32);
+ Constant *PoisonF32 = PoisonValue::get(F32);
+
+ KnownFPClass PartiallyPoison = computeKnownFPClass(
+ ConstantVector::get({ZeroF32, PoisonF32}), M->getDataLayout(),
+ fcAllFlags, 0, nullptr, nullptr, nullptr, nullptr);
+ EXPECT_EQ(fcPosZero, PartiallyPoison.KnownFPClasses);
+ ASSERT_TRUE(PartiallyPoison.SignBit);
+ EXPECT_FALSE(*PartiallyPoison.SignBit);
+ }
+
+ {
+ // Assume the poison element should be 1.
+ Constant *NegZeroF32 = ConstantFP::getZero(F32, true);
+ Constant *PoisonF32 = PoisonValue::get(F32);
+
+ KnownFPClass PartiallyPoison = computeKnownFPClass(
+ ConstantVector::get({NegZeroF32, PoisonF32}), M->getDataLayout(),
+ fcAllFlags, 0, nullptr, nullptr, nullptr, nullptr);
+ EXPECT_EQ(fcNegZero, PartiallyPoison.KnownFPClasses);
+ ASSERT_TRUE(PartiallyPoison.SignBit);
+ EXPECT_TRUE(*PartiallyPoison.SignBit);
+ }
+
+ {
+ // Assume the poison element should be 1.
+ Constant *NegZeroF32 = ConstantFP::getZero(F32, true);
+ Constant *PoisonF32 = PoisonValue::get(F32);
+
+ KnownFPClass PartiallyPoison = computeKnownFPClass(
+ ConstantVector::get({PoisonF32, NegZeroF32}), M->getDataLayout(),
+ fcAllFlags, 0, nullptr, nullptr, nullptr, nullptr);
+ EXPECT_EQ(fcNegZero, PartiallyPoison.KnownFPClasses);
+ EXPECT_TRUE(PartiallyPoison.SignBit);
+ }
}
TEST_F(ValueTrackingTest, isNonZeroRecurrence) {
More information about the llvm-commits
mailing list