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

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 15 15:48:23 PDT 2018


Author: spatel
Date: Thu Mar 15 15:48:23 2018
New Revision: 327680

URL: http://llvm.org/viewvc/llvm-project?rev=327680&view=rev
Log:
[InstCombine] add tests for fcmp+select -> fabs; NFC

Modified:
    llvm/trunk/test/Transforms/InstCombine/fabs.ll

Modified: llvm/trunk/test/Transforms/InstCombine/fabs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fabs.ll?rev=327680&r1=327679&r2=327680&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fabs.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fabs.ll Thu Mar 15 15:48:23 2018
@@ -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, f
 
 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(floa
 
 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(dou
 
 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(fp1
 ; 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(
 
 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(
 
 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
 
 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
 
 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
 
 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(f
 
 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(f
 
 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_negat
 
 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_posit
 
 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(
 
 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_n
 
 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_
 
 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_intri
 
 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_intrin
 
 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_i
 
 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(floa
   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> <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
+}
+




More information about the llvm-commits mailing list