* [PR71408] - Fix wrong code at -Os and above
@ 2016-06-05 10:55 kugan
2016-06-06 8:57 ` Richard Biener
0 siblings, 1 reply; 2+ messages in thread
From: kugan @ 2016-06-05 10:55 UTC (permalink / raw)
To: gcc-patches, Richard Biener
[-- Attachment #1: Type: text/plain, Size: 1324 bytes --]
Hi All,
For the testcase in PR71408 zero_one_operation seems still broken. In
handling NEGATE_EXPR, as part of undistribute_ops_list, in
zero_one_operation, we are doing propagate_op_to_single_use (op, stmt, def);
This results in:
- _14 = _5 * _12;
_15 = (int) _11;
_16 = ~_15;
_17 = (unsigned int) _16;
- _18 = -_5;
- _19 = _17 * _18;
- _20 = _14 + _19;
- _24 = _5 & _20;
+ _19 = _5 * _17;
+ _35 = _19 + _12;
+ _34 = _35 * _5;
+ _20 = _34;
+ _24 = _20 & _5;
We should instead propagate (-1) as "op" is the one which gets factored
out. With the attached patch we now have:
- _14 = _5 * _12;
_15 = (int) _11;
_16 = ~_15;
_17 = (unsigned int) _16;
- _18 = -_5;
- _19 = _17 * _18;
- _20 = _14 + _19;
- _24 = _5 & _20;
+ _32 = _17;
+ _19 = -_32;
+ _34 = _19 + _12;
+ _33 = _34 * _5;
+ _20 = _33;
+ _24 = _20 & _5;
Regression tested and bootstrapped on x86-64-linux-gnu with no new
regression. Is this OK for trunk?
Thanks,
Kugan
gcc/ChangeLog:
2016-06-05 Kugan Vivekanandarajah <kuganv@linaro.org>
PR middle-end/71408
* tree-ssa-reassoc.c (zero_one_operation): Fix NEGATE_EXPR operand for
propagate_op_to_single_use.
gcc/testsuite/ChangeLog:
2016-06-05 Kugan Vivekanandarajah <kuganv@linaro.org>
PR middle-end/71408
* gcc.dg/tree-ssa/pr71408.c: New test.
[-- Attachment #2: pr71408.txt --]
[-- Type: text/plain, Size: 1531 bytes --]
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c b/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c
index e69de29..896a428 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr71408.c
@@ -0,0 +1,30 @@
+/* PR middle-end/71408 */
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+unsigned a, b;
+
+struct S0
+{
+ int f1:18;
+ unsigned f3:4;
+};
+
+void fn1 ()
+{
+ struct S0 c = { 7, 0 };
+ if (c.f1)
+ c.f3 = 3;
+ a = -~c.f3;
+ c.f3 = ~(c.f1 && c.f1);
+ c.f1 = c.f3 * (c.f1 - (c.f1 - a % c.f1)) + ~c.f3 * -a;
+ b = ~(c.f1 & a);
+ if (b >= 4294967295)
+ __builtin_abort ();
+}
+
+int
+main ()
+{
+ fn1 ();
+ return 0;
+}
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 1973077..7865df0 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -1203,7 +1203,8 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
{
if (gimple_assign_rhs1 (stmt) == op)
{
- propagate_op_to_single_use (op, stmt, def);
+ tree cst = build_minus_one_cst (TREE_TYPE (op));
+ propagate_op_to_single_use (cst, stmt, def);
return;
}
else if (integer_minus_onep (op)
@@ -1251,7 +1252,8 @@ zero_one_operation (tree *def, enum tree_code opcode, tree op)
{
if (gimple_assign_rhs1 (stmt2) == op)
{
- propagate_op_to_single_use (op, stmt2, def);
+ tree cst = build_minus_one_cst (TREE_TYPE (op));
+ propagate_op_to_single_use (cst, stmt2, def);
return;
}
else if (integer_minus_onep (op)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PR71408] - Fix wrong code at -Os and above
2016-06-05 10:55 [PR71408] - Fix wrong code at -Os and above kugan
@ 2016-06-06 8:57 ` Richard Biener
0 siblings, 0 replies; 2+ messages in thread
From: Richard Biener @ 2016-06-06 8:57 UTC (permalink / raw)
To: kugan; +Cc: gcc-patches
On Sun, Jun 5, 2016 at 12:54 PM, kugan
<kugan.vivekanandarajah@linaro.org> wrote:
> Hi All,
>
> For the testcase in PR71408 zero_one_operation seems still broken. In
> handling NEGATE_EXPR, as part of undistribute_ops_list, in
> zero_one_operation, we are doing propagate_op_to_single_use (op, stmt, def);
>
> This results in:
> - _14 = _5 * _12;
> _15 = (int) _11;
> _16 = ~_15;
> _17 = (unsigned int) _16;
> - _18 = -_5;
> - _19 = _17 * _18;
> - _20 = _14 + _19;
> - _24 = _5 & _20;
> + _19 = _5 * _17;
> + _35 = _19 + _12;
> + _34 = _35 * _5;
> + _20 = _34;
> + _24 = _20 & _5;
>
> We should instead propagate (-1) as "op" is the one which gets factored out.
> With the attached patch we now have:
> - _14 = _5 * _12;
> _15 = (int) _11;
> _16 = ~_15;
> _17 = (unsigned int) _16;
> - _18 = -_5;
> - _19 = _17 * _18;
> - _20 = _14 + _19;
> - _24 = _5 & _20;
> + _32 = _17;
> + _19 = -_32;
> + _34 = _19 + _12;
> + _33 = _34 * _5;
> + _20 = _33;
> + _24 = _20 & _5;
>
> Regression tested and bootstrapped on x86-64-linux-gnu with no new
> regression. Is this OK for trunk?
Ok.
Thanks,
Richard.
> Thanks,
> Kugan
>
> gcc/ChangeLog:
>
> 2016-06-05 Kugan Vivekanandarajah <kuganv@linaro.org>
>
> PR middle-end/71408
> * tree-ssa-reassoc.c (zero_one_operation): Fix NEGATE_EXPR operand
> for
> propagate_op_to_single_use.
>
>
> gcc/testsuite/ChangeLog:
>
> 2016-06-05 Kugan Vivekanandarajah <kuganv@linaro.org>
>
> PR middle-end/71408
> * gcc.dg/tree-ssa/pr71408.c: New test.
>
>
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-06-06 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-05 10:55 [PR71408] - Fix wrong code at -Os and above kugan
2016-06-06 8:57 ` Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).