From 74c232b75f3aa0b64ca287c5e0cb29dce1bd1ca8 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Sun, 3 Sep 2017 15:35:10 +0000 Subject: [PATCH] [InstCombine] add tests for fcmp ord/uno canonicalization; NFC Currently, we canonicalize some cases to use 0.0, but we miss others. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@312445 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/Transforms/InstCombine/and-fcmp.ll | 24 ++++ test/Transforms/InstCombine/fcmp-special.ll | 123 ++++++++++++++++++++ test/Transforms/InstCombine/or-fcmp.ll | 24 ++++ 3 files changed, 171 insertions(+) diff --git a/test/Transforms/InstCombine/and-fcmp.ll b/test/Transforms/InstCombine/and-fcmp.ll index 553533392c1..7bf300d9a14 100644 --- a/test/Transforms/InstCombine/and-fcmp.ll +++ b/test/Transforms/InstCombine/and-fcmp.ll @@ -28,6 +28,30 @@ define <2 x i1> @t9(<2 x float> %a, <2 x double> %b) { 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, +; CHECK-NEXT: [[CMP2:%.*]] = fcmp ord <3 x float> %y, +; CHECK-NEXT: [[AND:%.*]] = and <3 x i1> [[CMP1]], [[CMP2]] +; CHECK-NEXT: ret <3 x i1> [[AND]] +; + %cmp1 = fcmp ord <3 x float> %x, + %cmp2 = fcmp ord <3 x float> %y, + %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 diff --git a/test/Transforms/InstCombine/fcmp-special.ll b/test/Transforms/InstCombine/fcmp-special.ll index bef71ef67f3..dcb88832323 100644 --- a/test/Transforms/InstCombine/fcmp-special.ll +++ b/test/Transforms/InstCombine/fcmp-special.ll @@ -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, +; CHECK-NEXT: ret <2 x i1> [[F]] +; + %f = fcmp ord <2 x float> %x, + 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, +; CHECK-NEXT: ret <2 x i1> [[F]] +; + %f = fcmp uno <2 x double> %x, + 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, +; CHECK-NEXT: ret <2 x i1> [[F]] +; + %f = fcmp uno <2 x double> %x, + ret <2 x i1> %f +} + diff --git a/test/Transforms/InstCombine/or-fcmp.ll b/test/Transforms/InstCombine/or-fcmp.ll index 848e2c5d40f..ede6853b657 100644 --- a/test/Transforms/InstCombine/or-fcmp.ll +++ b/test/Transforms/InstCombine/or-fcmp.ll @@ -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, +; CHECK-NEXT: [[CMP2:%.*]] = fcmp uno <3 x float> %y, +; CHECK-NEXT: [[OR:%.*]] = or <3 x i1> [[CMP1]], [[CMP2]] +; CHECK-NEXT: ret <3 x i1> [[OR]] +; + %cmp1 = fcmp uno <3 x float> %x, + %cmp2 = fcmp uno <3 x float> %y, + %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 -- 2.50.1