From: Sanjay Patel Date: Thu, 15 Mar 2018 22:48:23 +0000 (+0000) Subject: [InstCombine] add tests for fcmp+select -> fabs; NFC X-Git-Tag: llvmorg-7.0.0-rc1~10452 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2d568ec0e49389b903fe3f04bbc6b6e9c3b7c13f;p=platform%2Fupstream%2Fllvm.git [InstCombine] add tests for fcmp+select -> fabs; NFC llvm-svn: 327680 --- diff --git a/llvm/test/Transforms/InstCombine/fabs.ll b/llvm/test/Transforms/InstCombine/fabs.ll index 18f7bc0..294b74b 100644 --- a/llvm/test/Transforms/InstCombine/fabs.ll +++ b/llvm/test/Transforms/InstCombine/fabs.ll @@ -1,3 +1,4 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -instcombine -S | FileCheck %s ; Make sure libcalls are replaced with intrinsic calls. @@ -14,8 +15,8 @@ declare float @llvm.fmuladd.f32(float, float, float) define float @replace_fabs_call_f32(float %x) { ; CHECK-LABEL: @replace_fabs_call_f32( -; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float %x) -; CHECK-NEXT: ret float [[TMP1]] +; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]]) +; CHECK-NEXT: ret float [[FABSF]] ; %fabsf = tail call float @fabsf(float %x) ret float %fabsf @@ -23,8 +24,8 @@ define float @replace_fabs_call_f32(float %x) { define double @replace_fabs_call_f64(double %x) { ; CHECK-LABEL: @replace_fabs_call_f64( -; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.fabs.f64(double %x) -; CHECK-NEXT: ret double [[TMP1]] +; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]]) +; CHECK-NEXT: ret double [[FABS]] ; %fabs = tail call double @fabs(double %x) ret double %fabs @@ -32,8 +33,8 @@ define double @replace_fabs_call_f64(double %x) { define fp128 @replace_fabs_call_f128(fp128 %x) { ; CHECK-LABEL: @replace_fabs_call_f128( -; CHECK-NEXT: [[TMP1:%.*]] = call fp128 @llvm.fabs.f128(fp128 %x) -; CHECK-NEXT: ret fp128 [[TMP1]] +; CHECK-NEXT: [[FABSL:%.*]] = call fp128 @llvm.fabs.f128(fp128 [[X:%.*]]) +; CHECK-NEXT: ret fp128 [[FABSL]] ; %fabsl = tail call fp128 @fabsl(fp128 %x) ret fp128 %fabsl @@ -42,8 +43,8 @@ define fp128 @replace_fabs_call_f128(fp128 %x) { ; Make sure fast math flags are preserved when replacing the libcall. define float @fmf_replace_fabs_call_f32(float %x) { ; CHECK-LABEL: @fmf_replace_fabs_call_f32( -; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.fabs.f32(float %x) -; CHECK-NEXT: ret float [[TMP1]] +; CHECK-NEXT: [[FABSF:%.*]] = call nnan float @llvm.fabs.f32(float [[X:%.*]]) +; CHECK-NEXT: ret float [[FABSF]] ; %fabsf = tail call nnan float @fabsf(float %x) ret float %fabsf @@ -56,7 +57,7 @@ define float @fmf_replace_fabs_call_f32(float %x) { define float @square_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_fabs_intrinsic_f32( -; CHECK-NEXT: [[MUL:%.*]] = fmul float %x, %x +; CHECK-NEXT: [[MUL:%.*]] = fmul float [[X:%.*]], [[X]] ; CHECK-NEXT: [[FABSF:%.*]] = tail call float @llvm.fabs.f32(float [[MUL]]) ; CHECK-NEXT: ret float [[FABSF]] ; @@ -67,7 +68,7 @@ define float @square_fabs_intrinsic_f32(float %x) { define double @square_fabs_intrinsic_f64(double %x) { ; CHECK-LABEL: @square_fabs_intrinsic_f64( -; CHECK-NEXT: [[MUL:%.*]] = fmul double %x, %x +; CHECK-NEXT: [[MUL:%.*]] = fmul double [[X:%.*]], [[X]] ; CHECK-NEXT: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[MUL]]) ; CHECK-NEXT: ret double [[FABS]] ; @@ -78,7 +79,7 @@ define double @square_fabs_intrinsic_f64(double %x) { define fp128 @square_fabs_intrinsic_f128(fp128 %x) { ; CHECK-LABEL: @square_fabs_intrinsic_f128( -; CHECK-NEXT: [[MUL:%.*]] = fmul fp128 %x, %x +; CHECK-NEXT: [[MUL:%.*]] = fmul fp128 [[X:%.*]], [[X]] ; CHECK-NEXT: [[FABSL:%.*]] = tail call fp128 @llvm.fabs.f128(fp128 [[MUL]]) ; CHECK-NEXT: ret fp128 [[FABSL]] ; @@ -89,7 +90,7 @@ define fp128 @square_fabs_intrinsic_f128(fp128 %x) { define float @square_nnan_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_nnan_fabs_intrinsic_f32( -; CHECK-NEXT: [[MUL:%.*]] = fmul nnan float %x, %x +; CHECK-NEXT: [[MUL:%.*]] = fmul nnan float [[X:%.*]], [[X]] ; CHECK-NEXT: ret float [[MUL]] ; %mul = fmul nnan float %x, %x @@ -101,7 +102,7 @@ define float @square_nnan_fabs_intrinsic_f32(float %x) { define float @square_fabs_shrink_call1(float %x) { ; CHECK-LABEL: @square_fabs_shrink_call1( -; CHECK-NEXT: [[TMP1:%.*]] = fmul float %x, %x +; CHECK-NEXT: [[TMP1:%.*]] = fmul float [[X:%.*]], [[X]] ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.fabs.f32(float [[TMP1]]) ; CHECK-NEXT: ret float [[TRUNC]] ; @@ -114,7 +115,7 @@ define float @square_fabs_shrink_call1(float %x) { define float @square_fabs_shrink_call2(float %x) { ; CHECK-LABEL: @square_fabs_shrink_call2( -; CHECK-NEXT: [[SQ:%.*]] = fmul float %x, %x +; CHECK-NEXT: [[SQ:%.*]] = fmul float [[X:%.*]], [[X]] ; CHECK-NEXT: [[TRUNC:%.*]] = call float @llvm.fabs.f32(float [[SQ]]) ; CHECK-NEXT: ret float [[TRUNC]] ; @@ -127,7 +128,7 @@ define float @square_fabs_shrink_call2(float %x) { define float @fabs_select_constant_negative_positive(i32 %c) { ; CHECK-LABEL: @fabs_select_constant_negative_positive( -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %c, 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 ; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 ; CHECK-NEXT: ret float [[FABS]] ; @@ -139,7 +140,7 @@ define float @fabs_select_constant_negative_positive(i32 %c) { define float @fabs_select_constant_positive_negative(i32 %c) { ; CHECK-LABEL: @fabs_select_constant_positive_negative( -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %c, 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 ; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 ; CHECK-NEXT: ret float [[FABS]] ; @@ -151,7 +152,7 @@ define float @fabs_select_constant_positive_negative(i32 %c) { define float @fabs_select_constant_negative_negative(i32 %c) { ; CHECK-LABEL: @fabs_select_constant_negative_negative( -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %c, 0 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 ; CHECK-NEXT: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00 ; CHECK-NEXT: ret float [[FABS]] ; @@ -173,8 +174,8 @@ define float @fabs_select_constant_neg0(i32 %c) { define float @fabs_select_var_constant_negative(i32 %c, float %x) { ; CHECK-LABEL: @fabs_select_var_constant_negative( -; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %c, 0 -; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float %x, float -1.000000e+00 +; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0 +; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float [[X:%.*]], float -1.000000e+00 ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) ; CHECK-NEXT: ret float [[FABS]] ; @@ -188,7 +189,7 @@ define float @fabs_select_var_constant_negative(i32 %c, float %x) { define float @square_fma_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_fma_fabs_intrinsic_f32( -; CHECK-NEXT: [[FMA:%.*]] = call float @llvm.fma.f32(float %x, float %x, float 1.000000e+00) +; CHECK-NEXT: [[FMA:%.*]] = call float @llvm.fma.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) ; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMA]]) ; CHECK-NEXT: ret float [[FABSF]] ; @@ -201,7 +202,7 @@ define float @square_fma_fabs_intrinsic_f32(float %x) { define float @square_nnan_fma_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_nnan_fma_fabs_intrinsic_f32( -; CHECK-NEXT: [[FMA:%.*]] = call nnan float @llvm.fma.f32(float %x, float %x, float 1.000000e+00) +; CHECK-NEXT: [[FMA:%.*]] = call nnan float @llvm.fma.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) ; CHECK-NEXT: ret float [[FMA]] ; %fma = call nnan float @llvm.fma.f32(float %x, float %x, float 1.0) @@ -211,7 +212,7 @@ define float @square_nnan_fma_fabs_intrinsic_f32(float %x) { define float @square_fmuladd_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_fmuladd_fabs_intrinsic_f32( -; CHECK-NEXT: [[FMULADD:%.*]] = call float @llvm.fmuladd.f32(float %x, float %x, float 1.000000e+00) +; CHECK-NEXT: [[FMULADD:%.*]] = call float @llvm.fmuladd.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) ; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMULADD]]) ; CHECK-NEXT: ret float [[FABSF]] ; @@ -222,7 +223,7 @@ define float @square_fmuladd_fabs_intrinsic_f32(float %x) { define float @square_nnan_fmuladd_fabs_intrinsic_f32(float %x) { ; CHECK-LABEL: @square_nnan_fmuladd_fabs_intrinsic_f32( -; CHECK-NEXT: [[FMULADD:%.*]] = call nnan float @llvm.fmuladd.f32(float %x, float %x, float 1.000000e+00) +; CHECK-NEXT: [[FMULADD:%.*]] = call nnan float @llvm.fmuladd.f32(float [[X:%.*]], float [[X]], float 1.000000e+00) ; CHECK-NEXT: ret float [[FMULADD]] ; %fmuladd = call nnan float @llvm.fmuladd.f32(float %x, float %x, float 1.0) @@ -234,7 +235,7 @@ define float @square_nnan_fmuladd_fabs_intrinsic_f32(float %x) { define double @multi_use_fabs_fpext(float %x) { ; CHECK-LABEL: @multi_use_fabs_fpext( -; CHECK-NEXT: [[FPEXT:%.*]] = fpext float %x to double +; CHECK-NEXT: [[FPEXT:%.*]] = fpext float [[X:%.*]] to double ; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[FPEXT]]) ; CHECK-NEXT: store volatile double [[FPEXT]], double* undef, align 8 ; CHECK-NEXT: ret double [[FABS]] @@ -244,3 +245,35 @@ define double @multi_use_fabs_fpext(float %x) { store volatile double %fpext, double* undef ret double %fabs } + +; X < 0.0 ? -X : X --> fabs(X) + +define double @select_fcmp_nsz_olt(double %x) { +; CHECK-LABEL: @select_fcmp_nsz_olt( +; CHECK-NEXT: [[LTZERO:%.*]] = fcmp nsz olt double [[X:%.*]], 0.000000e+00 +; CHECK-NEXT: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X]] +; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], double [[NEGX]], double [[X]] +; CHECK-NEXT: ret double [[FABS]] +; + %ltzero = fcmp nsz olt double %x, 0.0 + %negx = fsub double -0.0, %x + %fabs = select i1 %ltzero, double %negx, double %x + ret double %fabs +} + +; X >= 0.0 ? X : -X --> fabs(X) +; Also test for vector type and more FMF. + +define <2 x float> @select_fcmp_nsz_ogt(<2 x float> %x) { +; CHECK-LABEL: @select_fcmp_nsz_ogt( +; CHECK-NEXT: [[GEZERO:%.*]] = fcmp ninf nsz oge <2 x float> [[X:%.*]], zeroinitializer +; CHECK-NEXT: [[NEGX:%.*]] = fsub <2 x float> , [[X]] +; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x float> [[X]], <2 x float> [[NEGX]] +; CHECK-NEXT: ret <2 x float> [[FABS]] +; + %gezero = fcmp nsz ninf oge <2 x float> %x, zeroinitializer + %negx = fsub <2 x float> , %x + %fabs = select <2 x i1> %gezero, <2 x float> %x, <2 x float> %negx + ret <2 x float> %fabs +} +