diff options
author | Stephen Hines <srhines@google.com> | 2014-12-04 19:51:48 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-12-04 19:51:48 +0000 |
commit | a21bbdfad461e957fa42ac9d6860ddc9de2da3e9 (patch) | |
tree | 8d32ff2094b47e15a8def30d62fd7dee6e009de3 /test/Transforms/InstCombine/fabs.ll | |
parent | 6b8c6a5088c221af2b25065b8b6b8b0fec8a116f (diff) | |
parent | 876d6995443e99d13696f3941c3a789a4daa7c7a (diff) | |
download | external_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.zip external_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.tar.gz external_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.tar.bz2 |
am 876d6995: Merge "Update aosp/master LLVM for rebase to r222494."
* commit '876d6995443e99d13696f3941c3a789a4daa7c7a':
Update aosp/master LLVM for rebase to r222494.
Diffstat (limited to 'test/Transforms/InstCombine/fabs.ll')
-rw-r--r-- | test/Transforms/InstCombine/fabs.ll | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/test/Transforms/InstCombine/fabs.ll b/test/Transforms/InstCombine/fabs.ll new file mode 100644 index 0000000..0479549 --- /dev/null +++ b/test/Transforms/InstCombine/fabs.ll @@ -0,0 +1,100 @@ +; RUN: opt < %s -instcombine -S | FileCheck %s + +; Make sure all library calls are eliminated when the input is known positive. + +declare float @fabsf(float) +declare double @fabs(double) +declare fp128 @fabsl(fp128) + +define float @square_fabs_call_f32(float %x) { + %mul = fmul float %x, %x + %fabsf = tail call float @fabsf(float %mul) + ret float %fabsf + +; CHECK-LABEL: square_fabs_call_f32( +; CHECK-NEXT: %mul = fmul float %x, %x +; CHECK-NEXT: ret float %mul +} + +define double @square_fabs_call_f64(double %x) { + %mul = fmul double %x, %x + %fabs = tail call double @fabs(double %mul) + ret double %fabs + +; CHECK-LABEL: square_fabs_call_f64( +; CHECK-NEXT: %mul = fmul double %x, %x +; CHECK-NEXT: ret double %mul +} + +define fp128 @square_fabs_call_f128(fp128 %x) { + %mul = fmul fp128 %x, %x + %fabsl = tail call fp128 @fabsl(fp128 %mul) + ret fp128 %fabsl + +; CHECK-LABEL: square_fabs_call_f128( +; CHECK-NEXT: %mul = fmul fp128 %x, %x +; CHECK-NEXT: ret fp128 %mul +} + +; Make sure all intrinsic calls are eliminated when the input is known positive. + +declare float @llvm.fabs.f32(float) +declare double @llvm.fabs.f64(double) +declare fp128 @llvm.fabs.f128(fp128) + +define float @square_fabs_intrinsic_f32(float %x) { + %mul = fmul float %x, %x + %fabsf = tail call float @llvm.fabs.f32(float %mul) + ret float %fabsf + +; CHECK-LABEL: square_fabs_intrinsic_f32( +; CHECK-NEXT: %mul = fmul float %x, %x +; CHECK-NEXT: ret float %mul +} + +define double @square_fabs_intrinsic_f64(double %x) { + %mul = fmul double %x, %x + %fabs = tail call double @llvm.fabs.f64(double %mul) + ret double %fabs + +; CHECK-LABEL: square_fabs_intrinsic_f64( +; CHECK-NEXT: %mul = fmul double %x, %x +; CHECK-NEXT: ret double %mul +} + +define fp128 @square_fabs_intrinsic_f128(fp128 %x) { + %mul = fmul fp128 %x, %x + %fabsl = tail call fp128 @llvm.fabs.f128(fp128 %mul) + ret fp128 %fabsl + +; CHECK-LABEL: square_fabs_intrinsic_f128( +; CHECK-NEXT: %mul = fmul fp128 %x, %x +; CHECK-NEXT: ret fp128 %mul +} + +; Shrinking a library call to a smaller type should not be inhibited by nor inhibit the square optimization. + +define float @square_fabs_shrink_call1(float %x) { + %ext = fpext float %x to double + %sq = fmul double %ext, %ext + %fabs = call double @fabs(double %sq) + %trunc = fptrunc double %fabs to float + ret float %trunc + +; CHECK-LABEL: square_fabs_shrink_call1( +; CHECK-NEXT: %trunc = fmul float %x, %x +; CHECK-NEXT: ret float %trunc +} + +define float @square_fabs_shrink_call2(float %x) { + %sq = fmul float %x, %x + %ext = fpext float %sq to double + %fabs = call double @fabs(double %ext) + %trunc = fptrunc double %fabs to float + ret float %trunc + +; CHECK-LABEL: square_fabs_shrink_call2( +; CHECK-NEXT: %sq = fmul float %x, %x +; CHECK-NEXT: ret float %sq +} + |