[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-13 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Jakub Jelinek  ---
Fixed.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-13 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

--- Comment #8 from Jakub Jelinek  ---
Author: jakub
Date: Fri Apr 13 19:39:11 2018
New Revision: 259377

URL: https://gcc.gnu.org/viewcvs?rev=259377=gcc=rev
Log:
PR rtl-optimization/85376
* simplify-rtx.c (simplify_const_unary_operation): For CLZ and CTZ and
zero op0, if C?Z_DEFINED_VALUE_AT_ZERO is false, return NULL_RTX
instead of a specific value.

* gcc.dg/pr85376.c: New test.

Added:
trunk/gcc/testsuite/gcc.dg/pr85376.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/simplify-rtx.c
trunk/gcc/testsuite/ChangeLog

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

Jakub Jelinek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #7 from Jakub Jelinek  ---
Created attachment 43922
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43922=edit
gcc8-pr85376.patch

The problem is that cse.c (fold_rtx) uses simplify_unary_operation and that
contains stuff like:
  else if (! CLZ_DEFINED_VALUE_AT_ZERO (imode, int_value))
int_value = GET_MODE_PRECISION (imode);
That is fine in some optimization passes, where we just want some value for the
expression, but not in cse, where we want to record that some register has this
constant value and then optimize other uses of the same constant,
canonicalizing to that register.  Of course, when the value is not defined for
zero, the register contains some random value, not the constant we've computed.

So, either we can do what the patch does, or punt instead of returning
GET_MODE_PRECISION in simplify-rtx.c.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek  ---
The bug seems to be introduced during cse_local, before that we have:
(insn 28 26 31 2 (parallel [
(set (reg:CCZ 17 flags)
(compare:CCZ (reg:SI 188)
(const_int 0 [0])))
(set (reg:SI 93 [ _13 ])
(ctz:SI (reg:SI 188)))
]) "pr85376.c":12 735 {*bsfsi_1}
 (expr_list:REG_DEAD (reg:SI 188)
(expr_list:REG_UNUSED (reg:SI 93 [ _13 ])
(expr_list:REG_UNUSED (reg:CCZ 17 flags)
(nil)
...
(insn 55 54 56 2 (set (reg:SI 194 [ o ])
(const_int 32 [0x20])) "pr85376.c":14 86 {*movsi_internal}
 (expr_list:REG_DEAD (reg/v:HI 91 [ o ])
(nil)))
(insn 56 55 57 2 (set (reg:QI 108 [ _26+1 ])
(const_int 0 [0])) "pr85376.c":14 88 {*movqi_internal}
 (nil))
(insn 57 56 58 2 (parallel [
(set (reg:CC 17 flags)
(compare:CC (subreg:QI (reg:SI 194 [ o ]) 0)
(subreg:QI (reg:SI 104 [ _23 ]) 0)))
(set (reg:QI 195)
(minus:QI (subreg:QI (reg:SI 194 [ o ]) 0)
(subreg:QI (reg:SI 104 [ _23 ]) 0)))
]) "pr85376.c":14 294 {*subqi_3}
 (expr_list:REG_DEAD (reg:SI 194 [ o ])
(expr_list:REG_DEAD (reg:SI 104 [ _23 ])
(nil

But cse_local changes that to:
(insn 56 54 57 2 (set (reg:QI 108 [ _26+1 ])
(const_int 0 [0])) "pr85376.c":14 88 {*movqi_internal}
 (nil))
(insn 57 56 58 2 (parallel [
(set (reg:CC 17 flags)
(compare:CC (subreg:QI (reg:SI 93 [ _13 ]) 0)
(subreg:QI (reg:SI 104 [ _23 ]) 0)))
(set (reg:QI 195)
(minus:QI (subreg:QI (reg:SI 93 [ _13 ]) 0)
(subreg:QI (reg:SI 104 [ _23 ]) 0)))
]) "pr85376.c":14 294 {*subqi_3}
 (expr_list:REG_DEAD (reg:SI 194 [ o ])
(expr_list:REG_DEAD (reg:SI 104 [ _23 ])
(nil
but pseudo 93 certainly isn't known to contain (const_int 32).  I don't think
cse pass uses cselib though.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

--- Comment #5 from Jakub Jelinek  ---
There is nothing weird about what cprop1 does, __builtin_ffs (0) is known to be
0, with so many disabled optimizations we just don't optimize it away nor
simplify earlier.  So the
mov eax, 0  # tmp201,
bsf edx, eax# _28, tmp201
mov ecx, -16# tmp204,
add eax, ecx# tmp203, tmp204
part is just fine, we replaced the edx in the addition with eax which is known
to hold the same value, and because DCE is disabled nothing removes the dead
bsf.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

--- Comment #4 from Richard Biener  ---
Thus looks like a cselib issue to me.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

--- Comment #3 from Richard Biener  ---
-fdisable-rtl-cprop2 -fdisable-rtl-cprop1 fixes it, likewise
-fdisable-rtl-cse_local:

> diff -u t.c.245r.cprop2 t.c.247r.cse_local
...
-   41: r194:SI=0x20
-  REG_DEAD r91:HI
42: r108:QI=0
-   43: {flags:CC=cmp(r194:SI#0,r104:SI#0);r195:QI=r194:SI#0-r104:SI#0;}
+   43: {flags:CC=cmp(r93:SI#0,r104:SI#0);r195:QI=r93:SI#0-r104:SI#0;}

huh.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

--- Comment #2 from Jakub Jelinek  ---
Started with r257852.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P1
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-04-12
  Known to work||7.3.1
 Ever confirmed|0   |1

--- Comment #1 from Richard Biener  ---
Confirmed.

[Bug rtl-optimization/85376] [8 Regression] wrong code with -Og -fno-dce -fgcse -fno-tree-ccp -fno-tree-copy-prop

2018-04-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85376

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |8.0