From 07bba688895df837690e7016d6d5ae31ee34f4a1 Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Mon, 10 Jun 2019 15:08:22 +0000 Subject: [PATCH] [InstCombine] add tests for fabs() with unordered preds; NFC llvm-svn: 362949 --- llvm/test/Transforms/InstCombine/fabs.ll | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/llvm/test/Transforms/InstCombine/fabs.ll b/llvm/test/Transforms/InstCombine/fabs.ll index 1ee8989..afbb887 100644 --- a/llvm/test/Transforms/InstCombine/fabs.ll +++ b/llvm/test/Transforms/InstCombine/fabs.ll @@ -275,6 +275,21 @@ define double @select_fcmp_nnan_ole_zero(double %x) { ret double %fabs } +; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. + +define double @select_fcmp_nnan_ule_zero(double %x) { +; CHECK-LABEL: @select_fcmp_nnan_ule_zero( +; CHECK-NEXT: [[LEZERO:%.*]] = fcmp ule double [[X:%.*]], 0.000000e+00 +; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan double 0.000000e+00, [[X]] +; CHECK-NEXT: [[FABS:%.*]] = select i1 [[LEZERO]], double [[NEGX]], double [[X]] +; CHECK-NEXT: ret double [[FABS]] +; + %lezero = fcmp ule double %x, 0.0 + %negx = fsub nnan double 0.0, %x + %fabs = select i1 %lezero, double %negx, double %x + ret double %fabs +} + ; Negative test - wrong predicate. define double @select_fcmp_nnan_olt_zero(double %x) { @@ -329,6 +344,21 @@ define half @select_fcmp_nnan_ogt_negzero(half %x) { ret half %fabs } +; Repeat with unordered predicate - nnan allows us to treat ordered/unordered identically. + +define half @select_fcmp_nnan_ugt_negzero(half %x) { +; CHECK-LABEL: @select_fcmp_nnan_ugt_negzero( +; CHECK-NEXT: [[GTZERO:%.*]] = fcmp ugt half [[X:%.*]], 0xH0000 +; CHECK-NEXT: [[NEGX:%.*]] = fsub nnan half 0xH0000, [[X]] +; CHECK-NEXT: [[FABS:%.*]] = select i1 [[GTZERO]], half [[X]], half [[NEGX]] +; CHECK-NEXT: ret half [[FABS]] +; + %gtzero = fcmp ugt half %x, -0.0 + %negx = fsub nnan half 0.0, %x + %fabs = select i1 %gtzero, half %x, half %negx + ret half %fabs +} + ; Negative test - wrong predicate. define half @select_fcmp_nnan_oge_negzero(half %x) { -- 2.7.4