[llvm] r327689 - [InstCombine] add more tests for fcmp+select -> fabs; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 15 18:06:33 PDT 2018
Author: spatel
Date: Thu Mar 15 18:06:33 2018
New Revision: 327689
URL: http://llvm.org/viewvc/llvm-project?rev=327689&view=rev
Log:
[InstCombine] add more tests for fcmp+select -> fabs; NFC
This should correspond to the patterns in D44091 and might
make handling these in the DAG unnecessary.
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=327689&r1=327688&r2=327689&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fabs.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fabs.ll Thu Mar 15 18:06:33 2018
@@ -245,11 +245,71 @@ define double @multi_use_fabs_fpext(floa
store volatile double %fpext, double* undef
ret double %fabs
}
-
+
+; X <= 0.0 ? (0.0 - X) : X --> fabs(X)
+
+define double @select_fcmp_ole_zero(double %x) {
+; CHECK-LABEL: @select_fcmp_ole_zero(
+; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole double [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[NEGX:%.*]] = fsub double 0.000000e+00, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]]
+; CHECK-NEXT: ret double [[FABS]]
+;
+ %lezero = fcmp ole double %x, 0.0
+ %negx = fsub double 0.0, %x
+ %fabs = select i1 %lezero, double %negx, double %x
+ ret double %fabs
+}
+
+; X <= -0.0 ? (0.0 - X) : X --> fabs(X)
+
+define float @select_fcmp_ole_negzero(float %x) {
+; CHECK-LABEL: @select_fcmp_ole_negzero(
+; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ole float [[X:%.*]], -0.000000e+00
+; CHECK-NEXT: [[NEGX:%.*]] = fsub float 0.000000e+00, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]]
+; CHECK-NEXT: ret float [[FABS]]
+;
+ %lezero = fcmp ole float %x, -0.0
+ %negx = fsub float 0.0, %x
+ %fabs = select i1 %lezero, float %negx, float %x
+ ret float %fabs
+}
+
+; X > 0.0 ? X : (0.0 - X) --> fabs(X)
+
+define fp128 @select_fcmp_ogt_zero(fp128 %x) {
+; CHECK-LABEL: @select_fcmp_ogt_zero(
+; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ogt fp128 [[X:%.*]], 0xL00000000000000000000000000000000
+; CHECK-NEXT: [[NEGX:%.*]] = fsub fp128 0xL00000000000000000000000000000000, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], fp128 [[X]], fp128 [[NEGX]]
+; CHECK-NEXT: ret fp128 [[FABS]]
+;
+ %gtzero = fcmp ogt fp128 %x, zeroinitializer
+ %negx = fsub fp128 zeroinitializer, %x
+ %fabs = select i1 %gtzero, fp128 %x, fp128 %negx
+ ret fp128 %fabs
+}
+
+; X > -0.0 ? X : (0.0 - X) --> fabs(X)
+
+define half @select_fcmp_ogt_negzero(half %x) {
+; CHECK-LABEL: @select_fcmp_ogt_negzero(
+; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ogt half [[X:%.*]], 0xH8000
+; CHECK-NEXT: [[NEGX:%.*]] = fsub half 0xH0000, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]]
+; CHECK-NEXT: ret half [[FABS]]
+;
+ %gtzero = fcmp ogt half %x, -0.0
+ %negx = fsub half 0.0, %x
+ %fabs = select i1 %gtzero, half %x, half %negx
+ ret half %fabs
+}
+
; X < 0.0 ? -X : X --> fabs(X)
-define double @select_fcmp_nsz_olt(double %x) {
-; CHECK-LABEL: @select_fcmp_nsz_olt(
+define double @select_fcmp_nsz_olt_zero(double %x) {
+; CHECK-LABEL: @select_fcmp_nsz_olt_zero(
; 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]]
@@ -261,19 +321,108 @@ define double @select_fcmp_nsz_olt(doubl
ret double %fabs
}
-; X >= 0.0 ? X : -X --> fabs(X)
-; Also test for vector type and more FMF.
+; X < -0.0 ? -X : X --> fabs(X)
+
+define float @select_fcmp_nsz_olt_negzero(float %x) {
+; CHECK-LABEL: @select_fcmp_nsz_olt_negzero(
+; CHECK-NEXT: [[LTZERO:%.*]] = fcmp ninf nsz olt float [[X:%.*]], -0.000000e+00
+; CHECK-NEXT: [[NEGX:%.*]] = fsub float -0.000000e+00, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LTZERO]], float [[NEGX]], float [[X]]
+; CHECK-NEXT: ret float [[FABS]]
+;
+ %ltzero = fcmp nsz ninf olt float %x, -0.0
+ %negx = fsub float -0.0, %x
+ %fabs = select i1 %ltzero, float %negx, float %x
+ ret float %fabs
+}
+
+; X <= 0.0 ? -X : X --> fabs(X)
-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
+define double @select_fcmp_nsz_ole_zero(double %x) {
+; CHECK-LABEL: @select_fcmp_nsz_ole_zero(
+; CHECK-NEXT: [[LEZERO:%.*]] = fcmp fast ole double [[X:%.*]], 0.000000e+00
+; CHECK-NEXT: [[NEGX:%.*]] = fsub double -0.000000e+00, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]]
+; CHECK-NEXT: ret double [[FABS]]
+;
+ %lezero = fcmp fast ole double %x, 0.0
+ %negx = fsub double -0.0, %x
+ %fabs = select i1 %lezero, double %negx, double %x
+ ret double %fabs
+}
+
+; X <= -0.0 ? -X : X --> fabs(X)
+
+define float @select_fcmp_nsz_ole_negzero(float %x) {
+; CHECK-LABEL: @select_fcmp_nsz_ole_negzero(
+; CHECK-NEXT: [[LEZERO:%.*]] = fcmp nsz ole float [[X:%.*]], -0.000000e+00
+; CHECK-NEXT: [[NEGX:%.*]] = fsub float -0.000000e+00, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], float [[NEGX]], float [[X]]
+; CHECK-NEXT: ret float [[FABS]]
+;
+ %lezero = fcmp nsz ole float %x, -0.0
+ %negx = fsub float -0.0, %x
+ %fabs = select i1 %lezero, float %negx, float %x
+ ret float %fabs
+}
+
+; X > 0.0 ? X : (0.0 - X) --> fabs(X)
+
+define <2 x float> @select_fcmp_nsz_ogt_zero(<2 x float> %x) {
+; CHECK-LABEL: @select_fcmp_nsz_ogt_zero(
+; CHECK-NEXT: [[GTZERO:%.*]] = fcmp nsz arcp ogt <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: [[FABS:%.*]] = select <2 x i1> [[GTZERO]], <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
+ %gtzero = fcmp nsz arcp ogt <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
+ %fabs = select <2 x i1> %gtzero, <2 x float> %x, <2 x float> %negx
ret <2 x float> %fabs
}
+; X > -0.0 ? X : (0.0 - X) --> fabs(X)
+
+define half @select_fcmp_nsz_ogt_negzero(half %x) {
+; CHECK-LABEL: @select_fcmp_nsz_ogt_negzero(
+; CHECK-NEXT: [[GTZERO:%.*]] = fcmp fast ogt half [[X:%.*]], 0xH8000
+; CHECK-NEXT: [[NEGX:%.*]] = fsub half 0xH0000, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]]
+; CHECK-NEXT: ret half [[FABS]]
+;
+ %gtzero = fcmp fast ogt half %x, -0.0
+ %negx = fsub half 0.0, %x
+ %fabs = select i1 %gtzero, half %x, half %negx
+ ret half %fabs
+}
+
+; X > 0.0 ? X : (0.0 - X) --> fabs(X)
+
+define <2 x double> @select_fcmp_nsz_oge_zero(<2 x double> %x) {
+; CHECK-LABEL: @select_fcmp_nsz_oge_zero(
+; CHECK-NEXT: [[GEZERO:%.*]] = fcmp reassoc nsz oge <2 x double> [[X:%.*]], zeroinitializer
+; CHECK-NEXT: [[NEGX:%.*]] = fsub <2 x double> <double -0.000000e+00, double -0.000000e+00>, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select <2 x i1> [[GEZERO]], <2 x double> [[X]], <2 x double> [[NEGX]]
+; CHECK-NEXT: ret <2 x double> [[FABS]]
+;
+ %gezero = fcmp nsz reassoc oge <2 x double> %x, zeroinitializer
+ %negx = fsub <2 x double> <double -0.0, double -0.0>, %x
+ %fabs = select <2 x i1> %gezero, <2 x double> %x, <2 x double> %negx
+ ret <2 x double> %fabs
+}
+
+; X > -0.0 ? X : (0.0 - X) --> fabs(X)
+
+define half @select_fcmp_nsz_oge_negzero(half %x) {
+; CHECK-LABEL: @select_fcmp_nsz_oge_negzero(
+; CHECK-NEXT: [[GEZERO:%.*]] = fcmp nsz oge half [[X:%.*]], 0xH8000
+; CHECK-NEXT: [[NEGX:%.*]] = fsub half 0xH8000, [[X]]
+; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GEZERO]], half [[X]], half [[NEGX]]
+; CHECK-NEXT: ret half [[FABS]]
+;
+ %gezero = fcmp nsz oge half %x, -0.0
+ %negx = fsub half -0.0, %x
+ %fabs = select i1 %gezero, half %x, half %negx
+ ret half %fabs
+}
+
More information about the llvm-commits
mailing list