[llvm] r312445 - [InstCombine] add tests for fcmp ord/uno canonicalization; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 3 08:35:10 PDT 2017
Author: spatel
Date: Sun Sep 3 08:35:10 2017
New Revision: 312445
URL: http://llvm.org/viewvc/llvm-project?rev=312445&view=rev
Log:
[InstCombine] add tests for fcmp ord/uno canonicalization; NFC
Currently, we canonicalize some cases to use 0.0, but we miss others.
Modified:
llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll
llvm/trunk/test/Transforms/InstCombine/fcmp-special.ll
llvm/trunk/test/Transforms/InstCombine/or-fcmp.ll
Modified: llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll?rev=312445&r1=312444&r2=312445&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/and-fcmp.ll Sun Sep 3 08:35:10 2017
@@ -28,6 +28,30 @@ define <2 x i1> @t9(<2 x float> %a, <2 x
ret <2 x i1> %and
}
+define i1 @fcmp_ord_nonzero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_ord_nonzero(
+; CHECK-NEXT: [[TMP1:%.*]] = fcmp ord float %x, %y
+; CHECK-NEXT: ret i1 [[TMP1]]
+;
+ %cmp1 = fcmp ord float %x, 1.0
+ %cmp2 = fcmp ord float %y, 2.0
+ %and = and i1 %cmp1, %cmp2
+ ret i1 %and
+}
+
+define <3 x i1> @fcmp_ord_nonzero_vec(<3 x float> %x, <3 x float> %y) {
+; CHECK-LABEL: @fcmp_ord_nonzero_vec(
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp ord <3 x float> %x, <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>
+; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <3 x float> %y, <float 3.000000e+00, float 2.000000e+00, float 1.000000e+00>
+; CHECK-NEXT: [[AND:%.*]] = and <3 x i1> [[CMP1]], [[CMP2]]
+; CHECK-NEXT: ret <3 x i1> [[AND]]
+;
+ %cmp1 = fcmp ord <3 x float> %x, <float 1.0, float 2.0, float 3.0>
+ %cmp2 = fcmp ord <3 x float> %y, <float 3.0, float 2.0, float 1.0>
+ %and = and <3 x i1> %cmp1, %cmp2
+ ret <3 x i1> %and
+}
+
define i1 @auto_gen_0(double %a, double %b) {
; CHECK-LABEL: @auto_gen_0(
; CHECK-NEXT: ret i1 false
Modified: llvm/trunk/test/Transforms/InstCombine/fcmp-special.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/fcmp-special.ll?rev=312445&r1=312444&r2=312445&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/fcmp-special.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/fcmp-special.ll Sun Sep 3 08:35:10 2017
@@ -21,3 +21,126 @@ define i1 @une_self(double %x) {
ret i1 %tmp
}
+; When just checking for a NaN (ORD/UNO), canonicalize constants.
+; Float/double are alternated for additional coverage.
+
+define i1 @ord_zero(float %x) {
+; CHECK-LABEL: @ord_zero(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord float %x, 0.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp ord float %x, 0.0
+ ret i1 %f
+}
+
+define i1 @ord_nonzero(double %x) {
+; CHECK-LABEL: @ord_nonzero(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord double %x, 3.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp ord double %x, 3.0
+ ret i1 %f
+}
+
+define i1 @ord_self(float %x) {
+; CHECK-LABEL: @ord_self(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord float %x, 0.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp ord float %x, %x
+ ret i1 %f
+}
+
+define i1 @uno_zero(double %x) {
+; CHECK-LABEL: @uno_zero(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno double %x, 0.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp uno double %x, 0.0
+ ret i1 %f
+}
+
+define i1 @uno_nonzero(float %x) {
+; CHECK-LABEL: @uno_nonzero(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno float %x, 3.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp uno float %x, 3.0
+ ret i1 %f
+}
+
+define i1 @uno_self(double %x) {
+; CHECK-LABEL: @uno_self(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno double %x, 0.000000e+00
+; CHECK-NEXT: ret i1 [[F]]
+;
+ %f = fcmp uno double %x, %x
+ ret i1 %f
+}
+
+define <2 x i1> @ord_zero_vec(<2 x double> %x) {
+; CHECK-LABEL: @ord_zero_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord <2 x double> %x, zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp ord <2 x double> %x, zeroinitializer
+ ret <2 x i1> %f
+}
+
+define <2 x i1> @ord_nonzero_vec(<2 x float> %x) {
+; CHECK-LABEL: @ord_nonzero_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord <2 x float> %x, <float 3.000000e+00, float 5.000000e+00>
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp ord <2 x float> %x, <float 3.0, float 5.0>
+ ret <2 x i1> %f
+}
+
+define <2 x i1> @ord_self_vec(<2 x double> %x) {
+; CHECK-LABEL: @ord_self_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp ord <2 x double> %x, zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp ord <2 x double> %x, %x
+ ret <2 x i1> %f
+}
+
+define <2 x i1> @uno_zero_vec(<2 x float> %x) {
+; CHECK-LABEL: @uno_zero_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno <2 x float> %x, zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp uno <2 x float> %x, zeroinitializer
+ ret <2 x i1> %f
+}
+
+define <2 x i1> @uno_nonzero_vec(<2 x double> %x) {
+; CHECK-LABEL: @uno_nonzero_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno <2 x double> %x, <double 3.000000e+00, double 5.000000e+00>
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp uno <2 x double> %x, <double 3.0, double 5.0>
+ ret <2 x i1> %f
+}
+
+define <2 x i1> @uno_self_vec(<2 x float> %x) {
+; CHECK-LABEL: @uno_self_vec(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno <2 x float> %x, zeroinitializer
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp uno <2 x float> %x, %x
+ ret <2 x i1> %f
+}
+
+; If a scalar constant is NaN in any of the above tests, it would have been eliminated by InstSimplify.
+; If a vector has a NaN element, we don't do anything with it.
+
+define <2 x i1> @uno_vec_with_nan(<2 x double> %x) {
+; CHECK-LABEL: @uno_vec_with_nan(
+; CHECK-NEXT: [[F:%.*]] = fcmp uno <2 x double> %x, <double 3.000000e+00, double 0x7FF00000FFFFFFFF>
+; CHECK-NEXT: ret <2 x i1> [[F]]
+;
+ %f = fcmp uno <2 x double> %x, <double 3.0, double 0x7FF00000FFFFFFFF>
+ ret <2 x i1> %f
+}
+
Modified: llvm/trunk/test/Transforms/InstCombine/or-fcmp.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/or-fcmp.ll?rev=312445&r1=312444&r2=312445&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/or-fcmp.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/or-fcmp.ll Sun Sep 3 08:35:10 2017
@@ -1,6 +1,30 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -instcombine -S | FileCheck %s
+define i1 @fcmp_uno_nonzero(float %x, float %y) {
+; CHECK-LABEL: @fcmp_uno_nonzero(
+; CHECK-NEXT: [[TMP1:%.*]] = fcmp uno float %x, %y
+; CHECK-NEXT: ret i1 [[TMP1]]
+;
+ %cmp1 = fcmp uno float %x, 1.0
+ %cmp2 = fcmp uno float %y, 2.0
+ %or = or i1 %cmp1, %cmp2
+ ret i1 %or
+}
+
+define <3 x i1> @fcmp_uno_nonzero_vec(<3 x float> %x, <3 x float> %y) {
+; CHECK-LABEL: @fcmp_uno_nonzero_vec(
+; CHECK-NEXT: [[CMP1:%.*]] = fcmp uno <3 x float> %x, <float 1.000000e+00, float 2.000000e+00, float 3.000000e+00>
+; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <3 x float> %y, <float 3.000000e+00, float 2.000000e+00, float 1.000000e+00>
+; CHECK-NEXT: [[OR:%.*]] = or <3 x i1> [[CMP1]], [[CMP2]]
+; CHECK-NEXT: ret <3 x i1> [[OR]]
+;
+ %cmp1 = fcmp uno <3 x float> %x, <float 1.0, float 2.0, float 3.0>
+ %cmp2 = fcmp uno <3 x float> %y, <float 3.0, float 2.0, float 1.0>
+ %or = or <3 x i1> %cmp1, %cmp2
+ ret <3 x i1> %or
+}
+
define i1 @auto_gen_0(double %a, double %b) {
; CHECK-LABEL: @auto_gen_0(
; CHECK-NEXT: ret i1 false
More information about the llvm-commits
mailing list