1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 19:52:54 +01:00

[InstCombine] add tests for fcmp+select -> fabs; NFC

llvm-svn: 327680
This commit is contained in:
Sanjay Patel 2018-03-15 22:48:23 +00:00
parent 76f0bf1cd2
commit a53bda2953

View File

@ -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 ; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -instcombine -S | FileCheck %s
; Make sure libcalls are replaced with intrinsic calls. ; 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) { define float @replace_fabs_call_f32(float %x) {
; CHECK-LABEL: @replace_fabs_call_f32( ; CHECK-LABEL: @replace_fabs_call_f32(
; CHECK-NEXT: [[TMP1:%.*]] = call float @llvm.fabs.f32(float %x) ; CHECK-NEXT: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[X:%.*]])
; CHECK-NEXT: ret float [[TMP1]] ; CHECK-NEXT: ret float [[FABSF]]
; ;
%fabsf = tail call float @fabsf(float %x) %fabsf = tail call float @fabsf(float %x)
ret float %fabsf ret float %fabsf
@ -23,8 +24,8 @@ define float @replace_fabs_call_f32(float %x) {
define double @replace_fabs_call_f64(double %x) { define double @replace_fabs_call_f64(double %x) {
; CHECK-LABEL: @replace_fabs_call_f64( ; CHECK-LABEL: @replace_fabs_call_f64(
; CHECK-NEXT: [[TMP1:%.*]] = call double @llvm.fabs.f64(double %x) ; CHECK-NEXT: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[X:%.*]])
; CHECK-NEXT: ret double [[TMP1]] ; CHECK-NEXT: ret double [[FABS]]
; ;
%fabs = tail call double @fabs(double %x) %fabs = tail call double @fabs(double %x)
ret double %fabs ret double %fabs
@ -32,8 +33,8 @@ define double @replace_fabs_call_f64(double %x) {
define fp128 @replace_fabs_call_f128(fp128 %x) { define fp128 @replace_fabs_call_f128(fp128 %x) {
; CHECK-LABEL: @replace_fabs_call_f128( ; CHECK-LABEL: @replace_fabs_call_f128(
; CHECK-NEXT: [[TMP1:%.*]] = call fp128 @llvm.fabs.f128(fp128 %x) ; CHECK-NEXT: [[FABSL:%.*]] = call fp128 @llvm.fabs.f128(fp128 [[X:%.*]])
; CHECK-NEXT: ret fp128 [[TMP1]] ; CHECK-NEXT: ret fp128 [[FABSL]]
; ;
%fabsl = tail call fp128 @fabsl(fp128 %x) %fabsl = tail call fp128 @fabsl(fp128 %x)
ret fp128 %fabsl 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. ; Make sure fast math flags are preserved when replacing the libcall.
define float @fmf_replace_fabs_call_f32(float %x) { define float @fmf_replace_fabs_call_f32(float %x) {
; CHECK-LABEL: @fmf_replace_fabs_call_f32( ; CHECK-LABEL: @fmf_replace_fabs_call_f32(
; CHECK-NEXT: [[TMP1:%.*]] = call nnan float @llvm.fabs.f32(float %x) ; CHECK-NEXT: [[FABSF:%.*]] = call nnan float @llvm.fabs.f32(float [[X:%.*]])
; CHECK-NEXT: ret float [[TMP1]] ; CHECK-NEXT: ret float [[FABSF]]
; ;
%fabsf = tail call nnan float @fabsf(float %x) %fabsf = tail call nnan float @fabsf(float %x)
ret float %fabsf ret float %fabsf
@ -56,7 +57,7 @@ define float @fmf_replace_fabs_call_f32(float %x) {
define float @square_fabs_intrinsic_f32(float %x) { define float @square_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_fabs_intrinsic_f32( ; 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: [[FABSF:%.*]] = tail call float @llvm.fabs.f32(float [[MUL]])
; CHECK-NEXT: ret float [[FABSF]] ; 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) { define double @square_fabs_intrinsic_f64(double %x) {
; CHECK-LABEL: @square_fabs_intrinsic_f64( ; 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: [[FABS:%.*]] = tail call double @llvm.fabs.f64(double [[MUL]])
; CHECK-NEXT: ret double [[FABS]] ; 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) { define fp128 @square_fabs_intrinsic_f128(fp128 %x) {
; CHECK-LABEL: @square_fabs_intrinsic_f128( ; 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: [[FABSL:%.*]] = tail call fp128 @llvm.fabs.f128(fp128 [[MUL]])
; CHECK-NEXT: ret fp128 [[FABSL]] ; 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) { define float @square_nnan_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_nnan_fabs_intrinsic_f32( ; 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]] ; CHECK-NEXT: ret float [[MUL]]
; ;
%mul = fmul nnan float %x, %x %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) { define float @square_fabs_shrink_call1(float %x) {
; CHECK-LABEL: @square_fabs_shrink_call1( ; 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: [[TRUNC:%.*]] = call float @llvm.fabs.f32(float [[TMP1]])
; CHECK-NEXT: ret float [[TRUNC]] ; 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) { define float @square_fabs_shrink_call2(float %x) {
; CHECK-LABEL: @square_fabs_shrink_call2( ; 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: [[TRUNC:%.*]] = call float @llvm.fabs.f32(float [[SQ]])
; CHECK-NEXT: ret float [[TRUNC]] ; 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) { define float @fabs_select_constant_negative_positive(i32 %c) {
; CHECK-LABEL: @fabs_select_constant_negative_positive( ; 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: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float [[FABS]] ; 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) { define float @fabs_select_constant_positive_negative(i32 %c) {
; CHECK-LABEL: @fabs_select_constant_positive_negative( ; 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: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float [[FABS]] ; 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) { define float @fabs_select_constant_negative_negative(i32 %c) {
; CHECK-LABEL: @fabs_select_constant_negative_negative( ; 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: [[FABS:%.*]] = select i1 [[CMP]], float 1.000000e+00, float 2.000000e+00
; CHECK-NEXT: ret float [[FABS]] ; 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) { define float @fabs_select_var_constant_negative(i32 %c, float %x) {
; CHECK-LABEL: @fabs_select_var_constant_negative( ; CHECK-LABEL: @fabs_select_var_constant_negative(
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %c, 0 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[C:%.*]], 0
; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float %x, float -1.000000e+00 ; CHECK-NEXT: [[SELECT:%.*]] = select i1 [[CMP]], float [[X:%.*]], float -1.000000e+00
; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]]) ; CHECK-NEXT: [[FABS:%.*]] = call float @llvm.fabs.f32(float [[SELECT]])
; CHECK-NEXT: ret float [[FABS]] ; 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) { define float @square_fma_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_fma_fabs_intrinsic_f32( ; 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: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMA]])
; CHECK-NEXT: ret float [[FABSF]] ; 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) { define float @square_nnan_fma_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_nnan_fma_fabs_intrinsic_f32( ; 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]] ; CHECK-NEXT: ret float [[FMA]]
; ;
%fma = call nnan float @llvm.fma.f32(float %x, float %x, float 1.0) %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) { define float @square_fmuladd_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_fmuladd_fabs_intrinsic_f32( ; 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: [[FABSF:%.*]] = call float @llvm.fabs.f32(float [[FMULADD]])
; CHECK-NEXT: ret float [[FABSF]] ; 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) { define float @square_nnan_fmuladd_fabs_intrinsic_f32(float %x) {
; CHECK-LABEL: @square_nnan_fmuladd_fabs_intrinsic_f32( ; 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]] ; CHECK-NEXT: ret float [[FMULADD]]
; ;
%fmuladd = call nnan float @llvm.fmuladd.f32(float %x, float %x, float 1.0) %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) { define double @multi_use_fabs_fpext(float %x) {
; CHECK-LABEL: @multi_use_fabs_fpext( ; 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: [[FABS:%.*]] = call double @llvm.fabs.f64(double [[FPEXT]])
; CHECK-NEXT: store volatile double [[FPEXT]], double* undef, align 8 ; CHECK-NEXT: store volatile double [[FPEXT]], double* undef, align 8
; CHECK-NEXT: ret double [[FABS]] ; CHECK-NEXT: ret double [[FABS]]
@ -244,3 +245,35 @@ define double @multi_use_fabs_fpext(float %x) {
store volatile double %fpext, double* undef store volatile double %fpext, double* undef
ret double %fabs 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> <float -0.000000e+00, float -0.000000e+00>, [[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> <float -0.0, float -0.0>, %x
%fabs = select <2 x i1> %gezero, <2 x float> %x, <2 x float> %negx
ret <2 x float> %fabs
}