summaryrefslogtreecommitdiff
path: root/0046-Add-new-pattern-to-pass-the-maxmin-tests.patch
blob: 9ceba88090b58a20e5d3c4d2d6c70327cfbd9f47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
From dbcb2630c426c8dd2117b5ce625da8422dd8cd65 Mon Sep 17 00:00:00 2001
From: Diachkov Ilia <diachkov.ilia1@huawei-partners.com>
Date: Thu, 22 Feb 2024 17:20:17 +0800
Subject: [PATCH 14/18] Add new pattern to pass the maxmin tests

---
 gcc/match.pd                          | 24 ++++++++++++++++++++++++
 gcc/testsuite/gcc.dg/combine-maxmin.c |  2 +-
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 3a19e93b3..aee58e47b 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -8038,6 +8038,10 @@ and,
 (match (minmax_cmp_arg @0 @1)
  (bit_and @0 INTEGER_CST@1)
  (if (wi::popcount (~wi::to_widest (@1) + 1) == 1)))
+/* Match ((unsigned) a > 0b0..01..1) pattern.  */
+(match (minmax_cmp_arg1 @0 @1)
+ (gt @0 INTEGER_CST@1)
+ (if (wi::popcount (wi::to_widest (@1) + 1) == 1)))
 
 /* Match (inversed_sign_bit >> sign_bit_pos) pattern.
    This statement is blocking for the transformation of unsigned integers.
@@ -8095,6 +8099,26 @@ and,
     (convert (min (max @0 { integer_zero_node; })
 		  { mask; })))))
 
+ (simplify
+  (convert
+   (cond
+    (minmax_cmp_arg1 (convert? @0) INTEGER_CST@1)
+    (convert? (minmax_sat_arg @0))
+    (convert? @0)))
+  (if (wi::geu_p (wi::to_widest (@1) + 1, TYPE_PRECISION (type)))
+   (with { tree mask = build_int_cst (integer_type_node, tree_to_shwi (@1)); }
+    (convert (min (max (convert:integer_type_node @0) { integer_zero_node; })
+		  { mask; })))))
+ (simplify
+  (cond
+   (minmax_cmp_arg1 (convert? @0) INTEGER_CST@1)
+   (convert? (minmax_sat_arg @0))
+   (convert? @0))
+  (if (wi::geu_p (wi::to_widest (@1) + 1, TYPE_PRECISION (type)))
+   (with { tree mask = build_int_cst (integer_type_node, tree_to_shwi (@1)); }
+    (convert (min (max (convert:integer_type_node @0) { integer_zero_node; })
+		  { mask; })))))
+
  /* Truncation via bit_and with mask.  Same concerns on convert? here.  */
  (simplify
   (convert
diff --git a/gcc/testsuite/gcc.dg/combine-maxmin.c b/gcc/testsuite/gcc.dg/combine-maxmin.c
index a984fa560..5c0c9cc49 100755
--- a/gcc/testsuite/gcc.dg/combine-maxmin.c
+++ b/gcc/testsuite/gcc.dg/combine-maxmin.c
@@ -52,4 +52,4 @@ void hf (uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src,
 /* { dg-final { scan-assembler-times {[us]min\t} 6 } }  */
 /* All of the vectorized patterns are expected to be matched.  */
 /* { dg-final { scan-assembler-not {cmtst\t} } }  */
-/* { dg-final { scan-assembler-times {uzp1\t} 5 } }  */
+/* { dg-final { scan-assembler-times {uzp1\t} 2 } }  */
-- 
2.33.0