Hi, This patch adds few test-cases for gimple match-and-simplfiy and removes match-2.c
[gcc/testsuite/gcc.dg/tree-ssa] * match-2.c: Remove. * match-plusminus.c: New test-case. * match-bitwise.c: Likewise. * match-realimag.c: Likewise. Thanks and Regards, Prathamesh
Index: gcc/testsuite/gcc.dg/tree-ssa/match-2.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/match-2.c (revision 212038) +++ gcc/testsuite/gcc.dg/tree-ssa/match-2.c (working copy) @@ -1,211 +0,0 @@ -/* { 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" } } */ - -/* x & x -> x */ -int f15(int x) -{ - int t1 = x; - return t1 & x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */ - -/* x & ~x -> 0 */ -int f16(int x) -{ - int t1 = ~x; - return t1 & x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= 0" "forwprop1" } } */ - -/* x ^ x -> 0 */ -int f17(int x) -{ - int t1 = x; - return t1 ^ x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= 0" "forwprop1" } } */ - -/* ~~x -> 0 */ -int f18(int x) -{ - int t1 = ~x; - return ~t1; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */ - -/* (x | y) & x -> x */ -int f19(int x, int y) -{ - int t1 = x | y; - return t1 & x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */ - -/* (x & y) | x -> x */ -int f20(int x, int y) -{ - int t1 = x & y; - return t1 | x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */ - -/* (~x & y) | x -> x & y */ -int f21(int x, int y) -{ - int t1 = ~x; - int t2 = t1 & y; - return t2 | x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\) & y_\\d\+\\(D\\)" "forwprop1" } } */ - -/* (~x | y) & x -> x & y */ -int f22(int x, int y) -{ - int t1 = ~x; - int t2 = t1 | y; - return t2 & x; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\) & y_\\d\+\\(D\\)" "forwprop1" } } */ - -/* ((x & y) & ~x) & ~y -> 0 */ -int f23(int x, int y) -{ - int t1 = x & y; - int t2 = ~x; - int t3 = t1 & t2; - int t4 = ~y; - return t3 & t4; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= 0" "forwprop1" } } */ - -/* x & 0 -> 0 */ -int f24(int x) -{ - int t1 = 0; - return x & t1; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= 0" "forwprop1" } } */ - -/* x & -1 -> x */ -int f25(int x) -{ - int t1 = -1; - return x & t1; -} -/* { dg-final { scan-tree-dump "gimple_match_and_simplified to \[^\n\r\]*= x_\\d\+\\(D\\)" "forwprop1" } } */ - -/* { dg-final { cleanup-tree-dump "forwprop2" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/match-plusminus.c (working copy) @@ -0,0 +1,76 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop-details" } */ + +/* x + (-y) -> x - y */ +int plusminus_1(int x, int y) +{ + int t1 = -y; + int plusminus_1_val = x + t1; + return plusminus_1_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_1_val_\\d\+ = x_\\d\+\\(D\\) - y_\\d\+\\(D\\)" "forwprop1" } } */ + +/* x - (-y) -> y + x */ +int plusminus_2(int x, int y) +{ + int t1 = -y; + int plusminus_2_val = x - t1; + return plusminus_2_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_2_val_\\d\+ = y_\\d\+\\(D\\) \\+ x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x + y) - x -> y */ +int plusminus_3(int x, int y) +{ + int t1 = x + y; + int plusminus_3_val = t1 - x; + return plusminus_3_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_3_val_\\d\+ = y_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x - y) - x -> -y */ +int plusminus_4(int x, int y) +{ + int t1 = x - y; + int plusminus_4_val = t1 - x; + return plusminus_4_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_4_val_\\d\+ = -y_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x + y) - y -> x */ +int plusminus_5(int x, int y) +{ + int t1 = x + y; + int plusminus_5_val = t1 - y; + return plusminus_5_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_5_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x - y) + y -> x */ +int plusminus_6(int x, int y) +{ + int t1 = x - y; + int plusminus_6_val = t1 + y; + return plusminus_6_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_6_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x + cst1) + cst2 -> x + (cst1 + cst2) */ +int plusminus_7(int x) +{ + int t1 = x + 3; + int plusminus_7_val = t1 + 4; + return plusminus_7_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_7_val_\\d\+ = x_\\d\+\\(D\\) \\+ 7" "forwprop1" } } */ + +/* (cst1 - x) + cst2 -> (cst1 + cst2) - x */ +int plusminus_8(int x) +{ + int t1 = 3 - x; + int plusminus_8_val = t1 + 4; + return plusminus_8_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to plusminus_8_val_\\d\+ = 7 - x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* { dg-final { cleanup-tree-dump "forwprop2" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/match-bitwise.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/match-bitwise.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/match-bitwise.c (working copy) @@ -0,0 +1,88 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop-details" } */ + +/* x & x -> x */ +int bitwise_1(int x) +{ + int t1 = x; + int bitwise_1_val = t1 & x; + return bitwise_1_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_1_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* x & ~x -> 0 */ +int bitwise_2(int x) +{ + int t1 = ~x; + int bitwise_2_val = t1 & x; + return bitwise_2_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_2_val_\\d\+ = 0" "forwprop1" } } */ + +/* x ^ x -> 0 */ +int bitwise_3(int x) +{ + int t1 = x; + int bitwise_3_val = t1 ^ x; + return bitwise_3_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_3_val_\\d\+ = 0" "forwprop1" } } */ + +/* ~~x -> 0 */ +int bitwise_4(int x) +{ + int t1 = ~x; + int bitwise_4_val = ~t1; + return bitwise_4_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_4_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x | y) & x -> x */ +int bitwise_5(int x, int y) +{ + int t1 = x | y; + int bitwise_5_val = t1 & x; + return bitwise_5_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_5_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (x & y) | x -> x */ +int bitwise_6(int x, int y) +{ + int t1 = x & y; + int bitwise_6_val = t1 | x; + return bitwise_6_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_6_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (~x & y) | x -> x | y */ +int bitwise_7(int x, int y) +{ + int t1 = ~x; + int t2 = t1 & y; + int bitwise_7_val = t2 | x; + return bitwise_7_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_7_val_\\d\+ = x_\\d\+\\(D\\) | y_\\d\+\\(D\\)" "forwprop1" } } */ + +/* (~x | y) & x -> x & y */ +int bitwise_8(int x, int y) +{ + int t1 = ~x; + int t2 = t1 | y; + int bitwise_8_val = t2 & x; + return bitwise_8_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_8_val_\\d\+ = x_\\d\+\\(D\\) & y_\\d\+\\(D\\)" "forwprop1" } } */ + +/* ((x & y) & ~x) & ~y -> 0 */ +int bitwise_9(int x, int y) +{ + int t1 = x & y; + int t2 = ~x; + int bitwise_9_val = t1 & t2; + return bitwise_9_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to bitwise_9_val_\\d\+ = 0" "forwprop1" } } */ + +/* { dg-final { cleanup-tree-dump "forwprop2" } } */ Index: gcc/testsuite/gcc.dg/tree-ssa/match-realimag.c =================================================================== --- gcc/testsuite/gcc.dg/tree-ssa/match-realimag.c (revision 0) +++ gcc/testsuite/gcc.dg/tree-ssa/match-realimag.c (working copy) @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-forwprop-details" } */ + +/* __real complex (__real x) = x */ +double realimag_1(double x) +{ + _Complex double t1 = x; + double realimag_1_val = __real t1; + return realimag_1_val; +} +/* { dg-final { scan-tree-dump "gimple_match_and_simplified to realimag_1_val_\\d\+ = x_\\d\+\\(D\\)" "forwprop1" } } */ + +/* { dg-final { cleanup-tree-dump "forwprop2" } } */