* [Bug middle-end/114965] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
@ 2024-05-06 23:05 ` pinskia at gcc dot gnu.org
2024-05-06 23:07 ` [Bug tree-optimization/114965] [14/15 Regression] " pinskia at gcc dot gnu.org
` (16 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:05 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58112
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58112&action=edit
Slightly reduced
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
2024-05-06 23:05 ` [Bug middle-end/114965] " pinskia at gcc dot gnu.org
@ 2024-05-06 23:07 ` pinskia at gcc dot gnu.org
2024-05-06 23:08 ` pinskia at gcc dot gnu.org
` (15 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
Ever confirmed|0 |1
Summary|wrong code generated for |[14/15 Regression] wrong
|Emacs/Gnulib strftime |code generated for
|(regression from 13.2) |Emacs/Gnulib strftime
| |(regression from 13.2)
Keywords| |needs-bisection, wrong-code
Status|UNCONFIRMED |NEW
Last reconfirmed| |2024-05-06
Component|middle-end |tree-optimization
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
2024-05-06 23:05 ` [Bug middle-end/114965] " pinskia at gcc dot gnu.org
2024-05-06 23:07 ` [Bug tree-optimization/114965] [14/15 Regression] " pinskia at gcc dot gnu.org
@ 2024-05-06 23:08 ` pinskia at gcc dot gnu.org
2024-05-06 23:10 ` [Bug tree-optimization/114965] [13/14/15 " pinskia at gcc dot gnu.org
` (14 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:08 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #58112|0 |1
is obsolete| |
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58113
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58113&action=edit
Reduced all the way
here is a much simplier reduction. This passes at -O0 and fails at -O2.
It also fails for GCC 13.1.0 at -O1 and above.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (2 preceding siblings ...)
2024-05-06 23:08 ` pinskia at gcc dot gnu.org
@ 2024-05-06 23:10 ` pinskia at gcc dot gnu.org
2024-05-06 23:35 ` pinskia at gcc dot gnu.org
` (13 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:10 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[14/15 Regression] wrong |[13/14/15 Regression] wrong
|code generated for |code generated for
|Emacs/Gnulib strftime |Emacs/Gnulib strftime
|(regression from 13.2) |(regression from 13.2)
Target Milestone|14.0 |13.3
Known to fail| |13.1.0
Known to work| |12.3.0
--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note my reduction fails at -O1 and above while the original only failed at -O2
and above. Also the original only failed with GCC 14+ while my reduction fails
with GCC 13+.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (3 preceding siblings ...)
2024-05-06 23:10 ` [Bug tree-optimization/114965] [13/14/15 " pinskia at gcc dot gnu.org
@ 2024-05-06 23:35 ` pinskia at gcc dot gnu.org
2024-05-06 23:45 ` pinskia at gcc dot gnu.org
` (12 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh I see where the bug is coming from.
reassociation is turning:
_2 = pad_6 == 48;
_3 = pad_6 == 43;
_4 = _2 | _3;
Into:
_11 = (unsigned char) pad_6;
_12 = (int) _11;
_13 = 290271069732864 >> _12;
_14 = _13 & 1;
_15 = _14 == 0;
_16 = ~_15;
_4 = _16;
Which is invalid as pad_6 could be greater than 64.
Rank for pad_6 is 393216
Rank for _3 is 393217
Rank for _2 is 393217
Matching expression match.pd:179, gimple-match-8.cc:45
Matching expression match.pd:179, gimple-match-8.cc:45
Matching expression match.pd:2243, gimple-match-5.cc:20
Applying pattern match.pd:219, generic-match-1.cc:3159
Matching expression match.pd:2833, generic-match-4.cc:22
Matching expression match.pd:2840, generic-match-3.cc:38
Matching expression match.pd:2845, generic-match-2.cc:23
Matching expression match.pd:2833, generic-match-4.cc:22
Matching expression match.pd:2840, generic-match-3.cc:38
Matching expression match.pd:2845, generic-match-2.cc:23
Matching expression match.pd:2835, gimple-match-2.cc:35
Matching expression match.pd:2838, gimple-match-1.cc:66
Matching expression match.pd:2845, gimple-match-2.cc:96
Matching expression match.pd:2243, generic-match-7.cc:21
Matching expression match.pd:2835, generic-match-4.cc:36
Matching expression match.pd:2838, generic-match-3.cc:53
Matching expression match.pd:2845, generic-match-2.cc:23
Optimizing range tests pad_6 -[43, 43] and -[48, 48]
into _15
Transforming _4 = _2 | _3;
into _4 = _16;
Rank for _11 is 393217
Rank for _12 is 393218
Rank for _13 is 393219
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (4 preceding siblings ...)
2024-05-06 23:35 ` pinskia at gcc dot gnu.org
@ 2024-05-06 23:45 ` pinskia at gcc dot gnu.org
2024-05-07 4:45 ` sjames at gcc dot gnu.org
` (11 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-06 23:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduded testcase that fails at -O1 (but passes at -O2):
```
[[gnu::noipa]]
static void g(char pad1) {
if (pad1 != '0' && pad1 != '+' && pad1 != '_')
__builtin_unreachable();
if (pad1 == '0' || pad1 == '+')
__builtin_trap();
}
char buf[4000];
int main(void) { g('_'); }
```
But it definitely comes down to reassociation incorrectly thinking that (here)
that pad1 could only be 43 or 48. While it could be also 93 ('_').
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (5 preceding siblings ...)
2024-05-06 23:45 ` pinskia at gcc dot gnu.org
@ 2024-05-07 4:45 ` sjames at gcc dot gnu.org
2024-05-07 8:51 ` rguenth at gcc dot gnu.org
` (10 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-05-07 4:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |aldyh at gcc dot gnu.org
--- Comment #7 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #6)
> Reduded testcase that fails at -O1 (but passes at -O2):
> ```
>
> [[gnu::noipa]]
> static void g(char pad1) {
> if (pad1 != '0' && pad1 != '+' && pad1 != '_')
> __builtin_unreachable();
> if (pad1 == '0' || pad1 == '+')
> __builtin_trap();
> }
> char buf[4000];
> int main(void) { g('_'); }
>
> ```
>
Bisect for this testcase with releases/gcc-12 vs releases/gcc-13 gives
r13-2876-g2460f7cdef7ef9.
I will do the trunk one from Paul next.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (6 preceding siblings ...)
2024-05-07 4:45 ` sjames at gcc dot gnu.org
@ 2024-05-07 8:51 ` rguenth at gcc dot gnu.org
2024-05-07 9:49 ` sjames at gcc dot gnu.org
` (9 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-05-07 8:51 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu.org
Priority|P3 |P2
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (7 preceding siblings ...)
2024-05-07 8:51 ` rguenth at gcc dot gnu.org
@ 2024-05-07 9:49 ` sjames at gcc dot gnu.org
2024-05-07 11:25 ` jakub at gcc dot gnu.org
` (8 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-05-07 9:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Sam James <sjames at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amacleod at redhat dot com
--- Comment #8 from Sam James <sjames at gcc dot gnu.org> ---
For Paul's on 13 vs 14, I get r14-3414-g0cfc9c953d0221.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (8 preceding siblings ...)
2024-05-07 9:49 ` sjames at gcc dot gnu.org
@ 2024-05-07 11:25 ` jakub at gcc dot gnu.org
2024-05-07 11:49 ` jakub at gcc dot gnu.org
` (7 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-07 11:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org
--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
It is the PR63464 optimization gone wrong.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (9 preceding siblings ...)
2024-05-07 11:25 ` jakub at gcc dot gnu.org
@ 2024-05-07 11:49 ` jakub at gcc dot gnu.org
2024-05-07 16:24 ` jakub at gcc dot gnu.org
` (6 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-07 11:49 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org
--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Untested fix.
If entry_test_needed, earlier code ensures that exp is in [lowi, high] range,
so the optimization is ok. But without it, we need to ensure that if we lower
lowi we can still do the shifts safely.
r in this case is [43,43][48,48][95,95], so we don't need entry test if we
subtract the low bound (43), but 95 is too high for 64-bit prec.
--- gcc/tree-ssa-reassoc.cc.jj 2023-10-15 23:04:06.181422840 +0200
+++ gcc/tree-ssa-reassoc.cc 2024-05-07 13:46:42.722966813 +0200
@@ -3414,7 +3414,8 @@ optimize_range_tests_to_bit_test (enum t
We can avoid then subtraction of the minimum value, but the
mask constant could be perhaps more expensive. */
if (compare_tree_int (lowi, 0) > 0
- && compare_tree_int (high, prec) < 0)
+ && compare_tree_int (high, prec) < 0
+ && (entry_test_needed || wi::ltu_p (r.upper_bound (), prec)))
{
int cost_diff;
HOST_WIDE_INT m = tree_to_uhwi (lowi);
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (10 preceding siblings ...)
2024-05-07 11:49 ` jakub at gcc dot gnu.org
@ 2024-05-07 16:24 ` jakub at gcc dot gnu.org
2024-05-07 16:38 ` eggert at cs dot ucla.edu
` (5 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-07 16:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 58121
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58121&action=edit
gcc15-pr114965.patch
Full untested fix.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (11 preceding siblings ...)
2024-05-07 16:24 ` jakub at gcc dot gnu.org
@ 2024-05-07 16:38 ` eggert at cs dot ucla.edu
2024-05-08 8:18 ` cvs-commit at gcc dot gnu.org
` (4 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: eggert at cs dot ucla.edu @ 2024-05-07 16:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #12 from Paul Eggert <eggert at cs dot ucla.edu> ---
Thanks for fixing GCC.
I installed into Gnulib a patch that clarifies strftime's implementation, and
this also works around the GCC bug. It'll take some time for this to propagate
out, though, as Gnulib is a source code library and each package incorporates
Gnulib code when it sees fit. The patch is here:
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=4121ae7ad2859331447fe719d255e3d22953f327
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (12 preceding siblings ...)
2024-05-07 16:38 ` eggert at cs dot ucla.edu
@ 2024-05-08 8:18 ` cvs-commit at gcc dot gnu.org
2024-05-08 8:19 ` cvs-commit at gcc dot gnu.org
` (3 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-08 8:18 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:9adec2d91e62a479474ae79df5b455fd4b8463ba
commit r15-315-g9adec2d91e62a479474ae79df5b455fd4b8463ba
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed May 8 10:17:32 2024 +0200
reassoc: Fix up optimize_range_tests_to_bit_test [PR114965]
The optimize_range_tests_to_bit_test optimization normally emits a range
test first:
if (entry_test_needed)
{
tem = build_range_check (loc, optype, unshare_expr (exp),
false, lowi, high);
if (tem == NULL_TREE || is_gimple_val (tem))
continue;
}
so during the bit test we already know that exp is in the [lowi, high]
range, but skips it if we have range info which tells us this isn't
necessary.
Also, normally it emits shifts by exp - lowi counter, but has an
optimization to use just exp counter if the mask isn't a more expensive
constant in that case and lowi is > 0 and high is smaller than prec.
The following testcase is miscompiled because the two abnormal cases
are triggered. The range of exp is [43, 43][48, 48][95, 95], so we on
64-bit arch decide we don't need the entry test, because 95 - 43 < 64.
And we also decide to use just exp as counter, because the range test
tests just for exp == 43 || exp == 48, so high is smaller than 64 too.
Because 95 is in the exp range, we can't do that, we'd either need to
do a range test first, i.e.
if (exp - 43U <= 48U - 43U) if ((1UL << exp) & mask1))
or need to subtract lowi from the shift counter, i.e.
if ((1UL << (exp - 43)) & mask2)
but can't do both unless r.upper_bound () is < prec.
The following patch ensures that.
2024-05-08 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114965
* tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't try
to
optimize away exp - lowi subtraction from shift count unless entry
test is emitted or unless r.upper_bound () is smaller than prec.
* gcc.c-torture/execute/pr114965.c: New test.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13/14/15 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (13 preceding siblings ...)
2024-05-08 8:18 ` cvs-commit at gcc dot gnu.org
@ 2024-05-08 8:19 ` cvs-commit at gcc dot gnu.org
2024-05-08 8:20 ` [Bug tree-optimization/114965] [13 " jakub at gcc dot gnu.org
` (2 subsequent siblings)
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-08 8:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #14 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-14 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:d54151df3ba0ee3203e0b8cb8f8fcd168a766c51
commit r14-10184-gd54151df3ba0ee3203e0b8cb8f8fcd168a766c51
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed May 8 10:17:32 2024 +0200
reassoc: Fix up optimize_range_tests_to_bit_test [PR114965]
The optimize_range_tests_to_bit_test optimization normally emits a range
test first:
if (entry_test_needed)
{
tem = build_range_check (loc, optype, unshare_expr (exp),
false, lowi, high);
if (tem == NULL_TREE || is_gimple_val (tem))
continue;
}
so during the bit test we already know that exp is in the [lowi, high]
range, but skips it if we have range info which tells us this isn't
necessary.
Also, normally it emits shifts by exp - lowi counter, but has an
optimization to use just exp counter if the mask isn't a more expensive
constant in that case and lowi is > 0 and high is smaller than prec.
The following testcase is miscompiled because the two abnormal cases
are triggered. The range of exp is [43, 43][48, 48][95, 95], so we on
64-bit arch decide we don't need the entry test, because 95 - 43 < 64.
And we also decide to use just exp as counter, because the range test
tests just for exp == 43 || exp == 48, so high is smaller than 64 too.
Because 95 is in the exp range, we can't do that, we'd either need to
do a range test first, i.e.
if (exp - 43U <= 48U - 43U) if ((1UL << exp) & mask1))
or need to subtract lowi from the shift counter, i.e.
if ((1UL << (exp - 43)) & mask2)
but can't do both unless r.upper_bound () is < prec.
The following patch ensures that.
2024-05-08 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114965
* tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't try
to
optimize away exp - lowi subtraction from shift count unless entry
test is emitted or unless r.upper_bound () is smaller than prec.
* gcc.c-torture/execute/pr114965.c: New test.
(cherry picked from commit 9adec2d91e62a479474ae79df5b455fd4b8463ba)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (14 preceding siblings ...)
2024-05-08 8:19 ` cvs-commit at gcc dot gnu.org
@ 2024-05-08 8:20 ` jakub at gcc dot gnu.org
2024-05-09 4:27 ` cvs-commit at gcc dot gnu.org
2024-05-09 8:19 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-08 8:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[13/14/15 Regression] wrong |[13 Regression] wrong code
|code generated for |generated for Emacs/Gnulib
|Emacs/Gnulib strftime |strftime (regression from
|(regression from 13.2) |13.2)
--- Comment #15 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed for 14.2+ and 15.1+.
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (15 preceding siblings ...)
2024-05-08 8:20 ` [Bug tree-optimization/114965] [13 " jakub at gcc dot gnu.org
@ 2024-05-09 4:27 ` cvs-commit at gcc dot gnu.org
2024-05-09 8:19 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-09 4:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
--- Comment #16 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jakub Jelinek
<jakub@gcc.gnu.org>:
https://gcc.gnu.org/g:44d84db11ab724c34a8b1f8c0e06da1cc78439a2
commit r13-8735-g44d84db11ab724c34a8b1f8c0e06da1cc78439a2
Author: Jakub Jelinek <jakub@redhat.com>
Date: Wed May 8 10:17:32 2024 +0200
reassoc: Fix up optimize_range_tests_to_bit_test [PR114965]
The optimize_range_tests_to_bit_test optimization normally emits a range
test first:
if (entry_test_needed)
{
tem = build_range_check (loc, optype, unshare_expr (exp),
false, lowi, high);
if (tem == NULL_TREE || is_gimple_val (tem))
continue;
}
so during the bit test we already know that exp is in the [lowi, high]
range, but skips it if we have range info which tells us this isn't
necessary.
Also, normally it emits shifts by exp - lowi counter, but has an
optimization to use just exp counter if the mask isn't a more expensive
constant in that case and lowi is > 0 and high is smaller than prec.
The following testcase is miscompiled because the two abnormal cases
are triggered. The range of exp is [43, 43][48, 48][95, 95], so we on
64-bit arch decide we don't need the entry test, because 95 - 43 < 64.
And we also decide to use just exp as counter, because the range test
tests just for exp == 43 || exp == 48, so high is smaller than 64 too.
Because 95 is in the exp range, we can't do that, we'd either need to
do a range test first, i.e.
if (exp - 43U <= 48U - 43U) if ((1UL << exp) & mask1))
or need to subtract lowi from the shift counter, i.e.
if ((1UL << (exp - 43)) & mask2)
but can't do both unless r.upper_bound () is < prec.
The following patch ensures that.
2024-05-08 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114965
* tree-ssa-reassoc.cc (optimize_range_tests_to_bit_test): Don't try
to
optimize away exp - lowi subtraction from shift count unless entry
test is emitted or unless r.upper_bound () is smaller than prec.
* gcc.c-torture/execute/pr114965.c: New test.
(cherry picked from commit 9adec2d91e62a479474ae79df5b455fd4b8463ba)
^ permalink raw reply [flat|nested] 19+ messages in thread
* [Bug tree-optimization/114965] [13 Regression] wrong code generated for Emacs/Gnulib strftime (regression from 13.2)
2024-05-06 22:17 [Bug c/114965] New: wrong code generated for Emacs/Gnulib strftime (regression from 13.2) eggert at cs dot ucla.edu
` (16 preceding siblings ...)
2024-05-09 4:27 ` cvs-commit at gcc dot gnu.org
@ 2024-05-09 8:19 ` jakub at gcc dot gnu.org
17 siblings, 0 replies; 19+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-05-09 8:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114965
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #17 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed also for 13.3.
^ permalink raw reply [flat|nested] 19+ messages in thread