public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination
@ 2024-01-17 2:55 652023330028 at smail dot nju.edu.cn
2024-01-17 3:08 ` [Bug tree-optimization/113433] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-01-17 2:55 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
Bug ID: 113433
Summary: [12/13/14 Regression] Missed optimization for
redundancy computation elimination
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: 652023330028 at smail dot nju.edu.cn
Target Milestone: ---
Hello, we noticed that maybe there is a missed optimization for redundancy
computation elimination.
Different from PR 113265, This code worked as expected until GCC-12.
https://godbolt.org/z/nKh7zfsYn
int c,d,e;
void func(int y){
c=1-y;
d=0;
e=c/(d+(-c));
}
GCC (trunk):
func(int):
mov DWORD PTR d[rip], 0
mov eax, 1
sub eax, edi
sub edi, 1
cdq
mov DWORD PTR c[rip], eax
idiv edi
mov DWORD PTR e[rip], eax
ret
Expected code (GCC-11.4):
func(int):
mov DWORD PTR d[rip], 0
mov eax, 1
mov DWORD PTR e[rip], -1
sub eax, edi
mov DWORD PTR c[rip], eax
ret
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/113433] [12/13/14 Regression] Missed optimization for redundancy computation elimination
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
@ 2024-01-17 3:08 ` pinskia at gcc dot gnu.org
2024-01-17 8:09 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-17 3:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |missed-optimization
Ever confirmed|0 |1
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2024-01-17
Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
But it is a similar issue, we are left with:
_1 = 1 - y_7(D);
_5 = y_7(D) + -1;
_6 = _1 / _5;
Which is not folded as being as we don't know that `1 - x` and `x + -1` are
negative opposites.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/113433] [12/13/14 Regression] Missed optimization for redundancy computation elimination
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
2024-01-17 3:08 ` [Bug tree-optimization/113433] " pinskia at gcc dot gnu.org
@ 2024-01-17 8:09 ` rguenth at gcc dot gnu.org
2024-03-09 4:40 ` law at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-17 8:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P2
Target Milestone|--- |12.4
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/113433] [12/13/14 Regression] Missed optimization for redundancy computation elimination
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
2024-01-17 3:08 ` [Bug tree-optimization/113433] " pinskia at gcc dot gnu.org
2024-01-17 8:09 ` rguenth at gcc dot gnu.org
@ 2024-03-09 4:40 ` law at gcc dot gnu.org
2024-05-26 5:43 ` [Bug tree-optimization/113433] [12/13/14/15 " pinskia at gcc dot gnu.org
2024-05-26 5:43 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-09 4:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu.org
--- Comment #2 from Jeffrey A. Law <law at gcc dot gnu.org> ---
So we could attack this as a DOM problem. Not all the infrastructure is in
there. But the recognition of negated expressions isn't hard. Something like
this in tree-ssa-scopedtables will detect the negated expression in the hash
table.
/* We might be able to lookup the negated expression. */
case PLUS_EXPR:
{
tree x = gimple_assign_rhs_to_tree (stmt);
x = fold_unary (NEGATE_EXPR, TREE_TYPE (x), x);
struct hashable_expr expr;
expr.type = TREE_TYPE (x);
expr.kind = EXPR_BINARY;
expr.ops.binary.op = MINUS_EXPR;
expr.ops.binary.opnd0 = TREE_OPERAND (x, 0);
expr.ops.binary.opnd1 = TREE_OPERAND (x, 1);
class expr_hash_elt element2 (&expr, NULL_TREE);
expr_hash_elt **slot
= m_avail_exprs->find_slot (&element2, NO_INSERT);
if (slot && *slot)
return fold_build1 (NEGATE_EXPR, TREE_TYPE (x), (*slot)->lhs
());
return NULL_TREE;
}
Right now DOM isn't prepared for avail_expr_stack::simplify_binary_operation to
return anything other than a constant, ssa_name or NULL. But how hard could it
be to expand further :-)
Not sure if this happens enough to make the extra lookups worth the effort.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/113433] [12/13/14/15 Regression] Missed optimization for redundancy computation elimination
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
` (2 preceding siblings ...)
2024-03-09 4:40 ` law at gcc dot gnu.org
@ 2024-05-26 5:43 ` pinskia at gcc dot gnu.org
2024-05-26 5:43 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-26 5:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58288
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58288&action=edit
Patch which works
Just need to add testcases.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/113433] [12/13/14/15 Regression] Missed optimization for redundancy computation elimination
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
` (3 preceding siblings ...)
2024-05-26 5:43 ` [Bug tree-optimization/113433] [12/13/14/15 " pinskia at gcc dot gnu.org
@ 2024-05-26 5:43 ` pinskia at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-26 5:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113433
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |DUPLICATE
Status|ASSIGNED |RESOLVED
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup of bug 113265 really. No reason to keep both open.
*** This bug has been marked as a duplicate of bug 113265 ***
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2024-05-26 5:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-17 2:55 [Bug tree-optimization/113433] New: [12/13/14 Regression] Missed optimization for redundancy computation elimination 652023330028 at smail dot nju.edu.cn
2024-01-17 3:08 ` [Bug tree-optimization/113433] " pinskia at gcc dot gnu.org
2024-01-17 8:09 ` rguenth at gcc dot gnu.org
2024-03-09 4:40 ` law at gcc dot gnu.org
2024-05-26 5:43 ` [Bug tree-optimization/113433] [12/13/14/15 " pinskia at gcc dot gnu.org
2024-05-26 5:43 ` pinskia at gcc dot gnu.org
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).