diff options
| author | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-08-06 15:16:26 +0000 |
|---|---|---|
| committer | Matt Arsenault <Matthew.Arsenault@amd.com> | 2018-08-06 15:16:26 +0000 |
| commit | 56b31d8d753a55209f19f2cb5bf19138e14d6548 (patch) | |
| tree | dbe8f4548e3ab89bbede49ac04f9a92f975a4209 | |
| parent | dbf77c5b418a523682506ea92ed8e683093a2d6c (diff) | |
| download | bcm5719-llvm-56b31d8d753a55209f19f2cb5bf19138e14d6548.tar.gz bcm5719-llvm-56b31d8d753a55209f19f2cb5bf19138e14d6548.zip | |
ValueTracking: Handle canonicalize in CannotBeNegativeZero
Also fix apparently missing test coverage for any of the
handling here.
llvm-svn: 339023
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 1 | ||||
| -rw-r--r-- | llvm/test/Transforms/InstSimplify/fast-math.ll | 50 |
2 files changed, 51 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index afaa800ede9..2aac19a49a5 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2745,6 +2745,7 @@ bool llvm::CannotBeNegativeZero(const Value *V, const TargetLibraryInfo *TLI, 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: diff --git a/llvm/test/Transforms/InstSimplify/fast-math.ll b/llvm/test/Transforms/InstSimplify/fast-math.ll index 67419048669..c129d19a4b1 100644 --- a/llvm/test/Transforms/InstSimplify/fast-math.ll +++ b/llvm/test/Transforms/InstSimplify/fast-math.ll @@ -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_enough3(double %f) { ret double %mul } +declare float @llvm.fabs.f32(float) +declare float @llvm.sqrt.f32(float) +declare float @llvm.canonicalize.f32(float) |

