[llvm] r339023 - ValueTracking: Handle canonicalize in CannotBeNegativeZero
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 6 08:16:26 PDT 2018
Author: arsenm
Date: Mon Aug 6 08:16:26 2018
New Revision: 339023
URL: http://llvm.org/viewvc/llvm-project?rev=339023&view=rev
Log:
ValueTracking: Handle canonicalize in CannotBeNegativeZero
Also fix apparently missing test coverage for any of the
handling here.
Modified:
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/test/Transforms/InstSimplify/fast-math.ll
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=339023&r1=339022&r2=339023&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Mon Aug 6 08:16:26 2018
@@ -2745,6 +2745,7 @@ bool llvm::CannotBeNegativeZero(const Va
break;
// sqrt(-0.0) = -0.0, no other negative results are possible.
case Intrinsic::sqrt:
+ case Intrinsic::canonicalize:
return CannotBeNegativeZero(Call->getArgOperand(0), TLI, Depth + 1);
// fabs(x) != -0.0
case Intrinsic::fabs:
Modified: llvm/trunk/test/Transforms/InstSimplify/fast-math.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstSimplify/fast-math.ll?rev=339023&r1=339022&r2=339023&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstSimplify/fast-math.ll (original)
+++ llvm/trunk/test/Transforms/InstSimplify/fast-math.ll Mon Aug 6 08:16:26 2018
@@ -226,6 +226,53 @@ define float @nofold_fadd_x_0(float %a)
ret float %no_zero
}
+; CHECK-LABEL: @fold_fadd_nsz_x_0(
+; CHECK-NEXT: ret float %a
+define float @fold_fadd_nsz_x_0(float %a) {
+ %add = fadd nsz float %a, 0.0
+ ret float %add
+}
+
+; CHECK-LABEL: @fold_fadd_cannot_be_neg0_nsz_src_x_0
+; CHECK-NEXT: %nsz = fmul nsz float %a, %b
+; CHECK-NEXT: ret float %nsz
+define float @fold_fadd_cannot_be_neg0_nsz_src_x_0(float %a, float %b) {
+ %nsz = fmul nsz float %a, %b
+ %add = fadd float %nsz, 0.0
+ ret float %add
+}
+
+; CHECK-LABEL: @fold_fadd_cannot_be_neg0_fabs_src_x_0(
+; CHECK-NEXT: @llvm.fabs.f32
+; CHECK-NEXT: ret float %fabs
+define float @fold_fadd_cannot_be_neg0_fabs_src_x_0(float %a) {
+ %fabs = call float @llvm.fabs.f32(float %a)
+ %add = fadd float %fabs, 0.0
+ ret float %add
+}
+
+; CHECK-LABEL: @fold_fadd_cannot_be_neg0_sqrt_nsz_src_x_0(
+; CHECK-NEXT: fmul
+; CHECK-NEXT: call float @llvm.sqrt.f32
+; CHECK-NEXT: ret float %sqrt
+define float @fold_fadd_cannot_be_neg0_sqrt_nsz_src_x_0(float %a, float %b) {
+ %nsz = fmul nsz float %a, %b
+ %sqrt = call float @llvm.sqrt.f32(float %nsz)
+ %add = fadd float %sqrt, 0.0
+ ret float %add
+}
+
+; CHECK-LABEL: @fold_fadd_cannot_be_neg0_canonicalize_nsz_src_x_0(
+; CHECK-NEXT: fmul nsz
+; CHECK-NEXT: call float @llvm.canonicalize.f32(
+; CHECK-NEXT: ret float %canon
+define float @fold_fadd_cannot_be_neg0_canonicalize_nsz_src_x_0(float %a, float %b) {
+ %nsz = fmul nsz float %a, %b
+ %canon = call float @llvm.canonicalize.f32(float %nsz)
+ %add = fadd float %canon, 0.0
+ ret float %add
+}
+
; fdiv nsz nnan 0, X ==> 0
; 0 / X -> 0
@@ -396,3 +443,6 @@ define double @sqrt_squared_not_fast_eno
ret double %mul
}
+declare float @llvm.fabs.f32(float)
+declare float @llvm.sqrt.f32(float)
+declare float @llvm.canonicalize.f32(float)
More information about the llvm-commits
mailing list