[llvm] ValueTracking: Treat poison more aggressively in computeKnownFPClass (PR #87990)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 8 06:34:18 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-analysis
Author: Matt Arsenault (arsenm)
<details>
<summary>Changes</summary>
Assume no valid values, and the sign bit is 0.
---
Full diff: https://github.com/llvm/llvm-project/pull/87990.diff
3 Files Affected:
- (modified) llvm/lib/Analysis/ValueTracking.cpp (+6)
- (modified) llvm/test/CodeGen/AMDGPU/fold-fabs.ll (-6)
- (modified) llvm/unittests/Analysis/ValueTrackingTest.cpp (+55)
``````````diff
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index d50ccd8af287d8..ed44e9bc6ecc5f 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4513,6 +4513,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/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index b4d2270d70703f..65bde9fdcf3d06 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) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/87990
More information about the llvm-commits
mailing list