Added patterns in associate_pointerplus and associate_pointerplus_diff.
* genmatch.c (capture_max): Change value to 6.
(match-plusminus.pd): Add new patterns.
[gcc/testsuite/gcc.dg/tree-ssa]
* match-plusminus.c (plusminus_9): New test-case.
Thanks,
Prathamesh
Index: gcc/genmatch.c
===================================================================
--- gcc/genmatch.c (revision 213574)
+++ gcc/genmatch.c (working copy)
@@ -412,7 +412,7 @@ struct dt_operand: public dt_node
struct dt_simplify: public dt_node
{
static const unsigned level_max = UINT_MAX;
- static const unsigned capture_max = 4;
+ static const unsigned capture_max = 6;
simplify *s;
unsigned pattern_no;
dt_operand *indexes[capture_max];
Index: gcc/match-plusminus.pd
===================================================================
--- gcc/match-plusminus.pd (revision 213574)
+++ gcc/match-plusminus.pd (working copy)
@@ -106,3 +106,15 @@ along with GCC; see the file COPYING3.
(convert @0))
(convert @1))
+/* associate_pointerplus: (ptr p+ off1) p+ off2 -> ptr p+ (off1 + off2) */
+(match_and_simplify
+ (pointer_plus (pointer_plus @0 (convert@1 @2))
+ (convert@3 @4))
+ (pointer_plus @0 (plus @1 @3)))
+
+/* associate_pointerplus_diff: ptr1 p+ (ptr2 - ptr1) -> ptr2 */
+(match_and_simplify
+ (pointer_plus @0
+ (convert (minus (convert @1)
+ (convert @2))))
+ @1)
Index: gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c (revision 213574)
+++ gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c (working copy)
@@ -73,4 +73,14 @@ int plusminus_8(int x)
}
/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_8_val_\\d\+ = 7 - x_\\d\+\\(D\\)" "forwprop1" } } */
+/* ptr1 p+ (ptr2 - ptr1) -> ptr2 */
+unsigned char *
+plusminus_9(unsigned char *ptr1, unsigned char *ptr2)
+{
+ long t1 = ptr2 - ptr1;
+ unsigned char *plusminus_9_val = ptr1 + t1;
+ return plusminus_9_val;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_9_val_\\d\+ = ptr2" "forwprop1" } } */
+
/* { dg-final { cleanup-tree-dump "forwprop2" } } */