On Wed, May 14, 2014 at 4:40 PM, Richard Biener
<richard.guent...@gmail.com> wrote:
> On Tue, May 13, 2014 at 11:06 PM, Prathamesh Kulkarni
> <bilbotheelffri...@gmail.com> wrote:
>> On Tue, May 13, 2014 at 2:36 PM, Richard Biener
>> <richard.guent...@gmail.com> wrote:
>>> On Sun, May 11, 2014 at 5:00 PM, Prathamesh Kulkarni
>>> <bilbotheelffri...@gmail.com> wrote:
>>>> On Sun, May 11, 2014 at 8:10 PM, Andreas Schwab <sch...@linux-m68k.org> 
>>>> wrote:
>>>>> Prathamesh Kulkarni <bilbotheelffri...@gmail.com> writes:
>>>>>
>>>>>> a) I am not able to follow why 3 slashes are required here
>>>>>> in x_.\\\(D\\\) ? Why does x_.\(D\) not work ?
>>>>>
>>>>> Two of the three backslashes are eaten by the tcl parser.  But actually
>>>>> only two backslashes are needed, since the parens are not special to tcl
>>>>> (but are special to the regexp engine, so you want a single backslash
>>>>> surviving the tcl parser).
>>>>>
>>>>>> b) The expression after folding would be of the form:
>>>>>> t2_<digit> = x_<digit>(D) - y_<digit>(D)
>>>>>> I have used the operator "." in the pattern to match digit.
>>>>>> While that works in the above case, I think a better
>>>>>> idea would be to match using [0-9].
>>>>>> I tried the following but it does not work:
>>>>>> t_[0-9] = x_[0-9]\\\(D\\\) - y_[0-9]\\\(D\\\)
>>>>>> Neither does \\\[ and \\\] work.
>>>>>
>>>>> Brackets are special in tcl (including inside double quotes), so they
>>>>> need to be quoted.  But you want the brackets to appear unquoted to the
>>>>> regexp engine, so a single backslash will do the Right Thing.
>>>>>
>>>>> See tcl(n) for the tcl parsing rules.
>>>>>
>>>> Thanks. Now I get it, the double backslash \\ is an escape sequence
>>>> for \, and special characters like (, [
>>>> retain their meaning in quotes, so to match input text: (D), the
>>>> pattern has to be written as: "\\(D\\)".
>>>> I believe "\(D\)" would only match D in the input ?
>>>> I have modified the test-case. Is this version correct ?
>>>
>>> I usually verify that by running the testcase in isolation on a GCC version
>>> that should FAIL it and on one that should PASS it (tcl quoting is also
>>> try-and-error for me most of the time...).
>>>
>>> Thus I do
>>>
>>> gcc/> make check-gcc RUNTESTFLAGS="tree-ssa.exp=match-2.c"
>>> <test should FAIL>
>>> <patch source tree>
>>> gcc/> make cc1
>>> ... compiles cc1 ...
>>> gcc/> make check-gcc RUNTESTFLAGS="tree-ssa.exp=match-2.c"
>>> <test should PASS>
>>>
>>> A more complete matching for an SSA name would be (allowing
>>> for SSA name versions > 9) _\\d\+ with \\(D\\) appended if
>>> suitable (that's usually known from the testcase).  \\d\+ should match
>>> at least one decimal digit.
>> I thought that SSA name version wouldn't exceed 9 for that test-case,
>> so I decided for matching only one digit. I will change it to match
>> one or more digits.
>>
>> * I have written test-cases for patterns in match.pd (attached patch), which
>> result in PASS. Could you review them for me ?
>
> Sure.  It looks good to me, though you can look at the changed match-1.c
> testcase on the branch where I've changed the matching to look for the
> debug output the forwprop pass dumps with -fdump-tree-forwprop1-details,
> that makes sure no other pass before did the transform (you can also
> move the individual dg-final lines after the testcase function to more
> easily associate them with a function).
Thanks, modified the patch to scan for "gimple_match_and_simplified" instead.
>
> At some point the testcase should be split up as well.
>
> How do you manage your sources at the moment?  Just a svn
> checkout of the branch with local modifications?
Yes.
>
> Thanks,
> Richard.
Index: gcc/match.pd
===================================================================
--- gcc/match.pd	(revision 210434)
+++ gcc/match.pd	(working copy)
@@ -21,7 +21,6 @@ You should have received a copy of the G
 along with GCC; see the file COPYING3.  If not see
 <http://www.gnu.org/licenses/>.  */
 
-
 /* Transforms formerly done by tree-ssa-forwprop.c:associate_plusminus  */
 
 /* ???  Have match_and_simplify groups guarded with common
@@ -98,6 +97,32 @@ to (minus @1 @0)
    (T)(P + A) - (T)P  -> (T)A
  */
 
+/* ~A + A -> -1 */
+(match_and_simplify
+  (plus (bit_not @0) @0)
+  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+  { build_int_cst (TREE_TYPE (@0), -1); })
+
+/* ~A + 1 -> -A */
+(match_and_simplify
+  (plus (bit_not @0) integer_onep)
+  if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
+  (negate @0)) 
+
+/* A - (A +- B) -> -+ B */
+(match_and_simplify
+  (minus @0 (plus @0 @1))
+  (negate @0))
+
+(match_and_simplify
+  (minus @0 (minus @0 @1))
+  @1)
+
+/* (T)(P + A) - (T)P -> (T) A */
+(match_and_simplify
+  (minus (convert (pointer_plus @0 @1))
+	 (convert @0))
+  (convert @1)) 
 
 /* Patterns required to avoid SCCVN testsuite regressions.  */
 
Index: gcc/testsuite/gcc.dg/tree-ssa/match-2.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/match-2.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/match-2.c	(working copy)
@@ -0,0 +1,118 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-forwprop-details" }  */
+
+/* x + (-y) -> x - y */
+int f1(int x, int y)
+{
+  int t1 = -y;
+  return x + t1; 
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\) - y_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* x - (-y) -> y + x */
+int f2(int x, int y)
+{
+  int t1 = -y;
+  return x - t1; 
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= y_\\d\+\\(D\\) \\+ x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* (x + y) - x -> y */
+int f3(int x, int y)
+{
+  int t1 = x + y;
+  return t1 - x;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= y_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* (x - y) - x -> -y */
+int f4(int x, int y)
+{
+  int t1 = x - y;
+  return t1 - x;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= -y_\\d\+\\(D\\)" "forwprop1" } } */ 
+
+/* (x + y) - y -> x */
+int f5(int x, int y)
+{
+  int t1 = x + y;
+  return t1 - y;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* (x - y) + y -> x */
+int f6(int x, int y)
+{
+  int t1 = x - y;
+  return t1 + y;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* (x + cst1) + cst2 -> x + (cst1 + cst2) */
+int f7(int x)
+{
+  int t1 = x + 3;
+  return t1 + 4;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\) \\+ 7" "forwprop1" } } */ 
+
+/* (cst1 - x) + cst2 -> (cst1 + cst2) - x */
+int f8(int x)
+{
+  int t1 = 3 - x;
+  return t1 + 4;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= 7 - x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* (x >> 31) & 1 -> x >> 31 */
+int f9(int x)
+{
+  int t1 = x >> 31;
+  return t1 & 1;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= t1_\\d\+" "forwprop1" } } */
+
+/* -(~x) -> x + 1 */
+int f10(int x)
+{
+  int t1, t2;
+  t1 = ~x;
+  t2 = -t1;
+  return t2;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\) \\+ 1" "forwprop1" } } */
+
+/* x + ~x -> -1 */
+int f11(int x)
+{
+  int t1 = ~x;
+  return t1 + x;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= -1" "forwprop1" } } */
+
+/* ~x + 1 -> -x */
+int f12(int x)
+{
+  int t1 = ~x;
+  return t1 + 1;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= -x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* __real complex (__real x) = x */
+double f13(double x)
+{
+  _Complex double t1 = x;
+  return __real t1;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* __imag complex (__imag x) = x */
+double f14(double x)
+{
+  _Complex double t1 = x;
+  return __imag t1;
+}
+/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */
+
+/* { dg-final { cleanup-tree-dump "forwprop2" } } */

Reply via email to