public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
@ 2024-03-28 7:24 652023330028 at smail dot nju.edu.cn
2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2024-03-28 7:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
Bug ID: 114511
Summary: [Regression] Missed optimization: x = -y; x = c + x +
y; ==> x=c;
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 y can be eliminated from the calculation of x in the
following code. (x = c)
https://godbolt.org/z/716814Eh5
int x, y;
void func(int a, int b, int c, int d){
y = d / a + (-b + a);
x = -y;
x = c + x + y;
}
But GCC -O3 -fwrapv:
<bb 2> [local count: 1073741824]:
# DEBUG BEGIN_STMT
_1 = d_7(D) / a_8(D);
_2 = a_8(D) - b_9(D);
_3 = _1 + _2;
y = _3;
# DEBUG BEGIN_STMT
_18 = b_9(D) + c_12(D);
_19 = _18 - a_8(D);
# DEBUG BEGIN_STMT
_20 = _3 + _19;
_6 = _20 - _1;
x = _6;
return;
Expected code:
GCC-7.5 -O3 -fwrapv
<bb 2> [100.00%]:
_1 = d_7(D) / a_8(D);
_2 = a_8(D) - b_9(D);
_3 = _1 + _2;
y = _3;
x = c_12(D);
return;
Thank you very much for your time and effort! We look forward to hearing from
you.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114511] [11/12/13/14 Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
2024-03-28 7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
@ 2024-03-28 12:49 ` xry111 at gcc dot gnu.org
2024-04-02 8:02 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-03-28 12:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
Xi Ruoyao <xry111 at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Keywords| |needs-bisection
Known to work| |7.1.0
Known to fail| |8.1.0
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-03-28
CC| |xry111 at gcc dot gnu.org
Summary|[Regression] Missed |[11/12/13/14 Regression]
|optimization: x = -y; x = c |Missed optimization: x =
|+ x + y; ==> x=c; |-y; x = c + x + y; ==> x=c;
--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114511] [11/12/13/14 Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
2024-03-28 7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
@ 2024-04-02 8:02 ` rguenth at gcc dot gnu.org
2024-04-05 2:32 ` law at gcc dot gnu.org
2024-04-05 9:34 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-02 8:02 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |11.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114511] [11/12/13/14 Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
2024-03-28 7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
2024-04-02 8:02 ` rguenth at gcc dot gnu.org
@ 2024-04-05 2:32 ` law at gcc dot gnu.org
2024-04-05 9:34 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: law at gcc dot gnu.org @ 2024-04-05 2:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
Jeffrey A. Law <law at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu.org
Priority|P3 |P2
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug tree-optimization/114511] [11/12/13/14 Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c;
2024-03-28 7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
` (2 preceding siblings ...)
2024-04-05 2:32 ` law at gcc dot gnu.org
@ 2024-04-05 9:34 ` rguenth at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-05 9:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114511
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.
_3 = _1 + _2;
y = _3;
_18 = b_9(D) + c_12(D);
_19 = _18 - a_8(D);
_20 = _3 + _19;
_6 = _20 - _1;
re-association doesn't associate the def of _3 because it has multiple uses
and there's no special handling of
((_1 + _2) + _19) - _1
what makes this work for -fno-wrapv is the fre1 difference (+ is -fwrapv)
Replaced y with _3 in all uses of y.0_4 = y;
+Matching expression match.pd:2030, gimple-match-6.cc:54
+Applying pattern match.pd:2057, gimple-match-2.cc:4362
+Applying pattern match.pd:2048, gimple-match-6.cc:2758
+gimple_simplified to _18 = b_12(D) - a_11(D);
+_5 = _18 - _1;
Replaced x with _5 in all uses of x.1_6 = x;
-Applying pattern match.pd:4682, gimple-match-6.cc:4679
-Applying pattern match.pd:3432, gimple-match-7.cc:531
-gimple_simplified to _18 = c_16(D) - _3;
-_7 = _18;
Replaced y with _3 in all uses of y.2_8 = y;
-Applying pattern match.pd:4682, gimple-match-7.cc:4394
-Applying pattern match.pd:3494, gimple-match-6.cc:508
-gimple_simplified to _9 = c_16(D);
Removing dead stmt y.2_8 = y;
Removing dead stmt x.1_6 = x;
Removing dead stmt y.0_4 = y;
@@ -77,12 +77,12 @@
_2 = a_11(D) - b_12(D);
_3 = _1 + _2;
y = _3;
- _5 = -_3;
+ _18 = b_12(D) - a_11(D);
+ _5 = _18 - _1;
x = _5;
- _18 = c_16(D) - _3;
- _7 = _18;
- _9 = c_16(D);
- x = c_16(D);
+ _7 = _5 + c_16(D);
+ _9 = _3 + _7;
+ x = _9;
return;
}
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-04-05 9:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 7:24 [Bug tree-optimization/114511] New: [Regression] Missed optimization: x = -y; x = c + x + y; ==> x=c; 652023330028 at smail dot nju.edu.cn
2024-03-28 12:49 ` [Bug tree-optimization/114511] [11/12/13/14 Regression] " xry111 at gcc dot gnu.org
2024-04-02 8:02 ` rguenth at gcc dot gnu.org
2024-04-05 2:32 ` law at gcc dot gnu.org
2024-04-05 9:34 ` rguenth 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).