[llvm] 0d44878 - ValueTracking: sitofp cannot return -0
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 19 05:18:49 PDT 2023
Author: Matt Arsenault
Date: 2023-04-19T08:18:37-04:00
New Revision: 0d448783c31d1b6d509ae3f783c8ace9afd6096e
URL: https://github.com/llvm/llvm-project/commit/0d448783c31d1b6d509ae3f783c8ace9afd6096e
DIFF: https://github.com/llvm/llvm-project/commit/0d448783c31d1b6d509ae3f783c8ace9afd6096e.diff
LOG: ValueTracking: sitofp cannot return -0
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
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 c25f02becc8dd..b8ca38d084e6d 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -4627,6 +4627,9 @@ void computeKnownFPClass(const Value *V, const APInt &DemandedElts,
case Instruction::UIToFP: {
// Cannot produce nan
Known.knownNot(fcNan);
+
+ // sitofp and uitofp turn into +0.0 for zero.
+ Known.knownNot(fcNegZero);
if (Op->getOpcode() == Instruction::UIToFP)
Known.signBitIsZero();
diff --git a/llvm/test/Transforms/Attributor/nofpclass.ll b/llvm/test/Transforms/Attributor/nofpclass.ll
index 52c9c2e12fdb0..0ae2de3b44105 100644
--- a/llvm/test/Transforms/Attributor/nofpclass.ll
+++ b/llvm/test/Transforms/Attributor/nofpclass.ll
@@ -694,7 +694,7 @@ define float @uitofp_i32_to_f32(i32 %arg) {
define float @sitofp_i32_to_f32(i32 %arg) {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define nofpclass(nan inf) float @sitofp_i32_to_f32
+; CHECK-LABEL: define nofpclass(nan inf nzero) float @sitofp_i32_to_f32
; CHECK-SAME: (i32 [[ARG:%.*]]) #[[ATTR2]] {
; CHECK-NEXT: [[CVT:%.*]] = sitofp i32 [[ARG]] to float
; CHECK-NEXT: ret float [[CVT]]
@@ -716,7 +716,7 @@ define <2 x float> @uitofp_v2i32_to_v2f32(<2 x i32> %arg) {
define <2 x float> @sitofp_v2i32_to_v2i32(<2 x i32> %arg) {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define nofpclass(nan inf) <2 x float> @sitofp_v2i32_to_v2i32
+; CHECK-LABEL: define nofpclass(nan inf nzero) <2 x float> @sitofp_v2i32_to_v2i32
; CHECK-SAME: (<2 x i32> [[ARG:%.*]]) #[[ATTR2]] {
; CHECK-NEXT: [[CVT:%.*]] = sitofp <2 x i32> [[ARG]] to <2 x float>
; CHECK-NEXT: ret <2 x float> [[CVT]]
@@ -738,7 +738,7 @@ define half @uitofp_i17_to_f16(i17 %arg) {
define half @sitofp_i17_to_f16(i17 %arg) {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define nofpclass(nan) half @sitofp_i17_to_f16
+; CHECK-LABEL: define nofpclass(nan nzero) half @sitofp_i17_to_f16
; CHECK-SAME: (i17 [[ARG:%.*]]) #[[ATTR2]] {
; CHECK-NEXT: [[CVT:%.*]] = sitofp i17 [[ARG]] to half
; CHECK-NEXT: ret half [[CVT]]
@@ -760,7 +760,7 @@ define <2 x half> @uitofp_v2i17_to_v2f16(<2 x i17> %arg) {
define <2 x half> @sitofp_v2i17_to_v2i17(<2 x i17> %arg) {
; CHECK: Function Attrs: nofree norecurse nosync nounwind willreturn memory(none)
-; CHECK-LABEL: define nofpclass(nan) <2 x half> @sitofp_v2i17_to_v2i17
+; CHECK-LABEL: define nofpclass(nan nzero) <2 x half> @sitofp_v2i17_to_v2i17
; CHECK-SAME: (<2 x i17> [[ARG:%.*]]) #[[ATTR2]] {
; CHECK-NEXT: [[CVT:%.*]] = sitofp <2 x i17> [[ARG]] to <2 x half>
; CHECK-NEXT: ret <2 x half> [[CVT]]
diff --git a/llvm/unittests/Analysis/ValueTrackingTest.cpp b/llvm/unittests/Analysis/ValueTrackingTest.cpp
index 9327315304c8d..284d799e11478 100644
--- a/llvm/unittests/Analysis/ValueTrackingTest.cpp
+++ b/llvm/unittests/Analysis/ValueTrackingTest.cpp
@@ -1539,9 +1539,9 @@ TEST_F(ComputeKnownFPClassTest, SIToFP) {
" %A3 = sitofp i17 %arg2 to half"
" ret float %A\n"
"}\n");
- expectKnownFPClass(fcFinite, std::nullopt, A);
- expectKnownFPClass(fcFinite, std::nullopt, A2);
- expectKnownFPClass(~fcNan, std::nullopt, A3);
+ expectKnownFPClass(fcFinite & ~fcNegZero, std::nullopt, A);
+ expectKnownFPClass(fcFinite & ~fcNegZero, std::nullopt, A2);
+ expectKnownFPClass(~(fcNan | fcNegZero), std::nullopt, A3);
}
TEST_F(ComputeKnownFPClassTest, FAdd) {
More information about the llvm-commits
mailing list