public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40987] New: Wrong optimization with if-conversion
@ 2009-08-06 14:06 thomas at coware dot com
2009-08-07 12:10 ` [Bug rtl-optimization/40987] " rguenth at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: thomas at coware dot com @ 2009-08-06 14:06 UTC (permalink / raw)
To: gcc-bugs
The following test fails when I disable all optimizations but if-conversion:
#include <stdio.h>
long long func(long arg) {
long long val = 0;
if (arg < 0) {
val = 0xffffffff80000000ull;
}
return val;
}
int main() {
long long result = func(-1);
if (result != 0xffffffff80000000ull) {
printf("failed.\n");
return 1;
}
printf("passed.\n");
return 0;
}
The return value of func is 0x80000000ull where it should be
0xffffffff80000000ull. It works correctly when I don't do any optimization or
with more optimization (-O1, -O2, -O3).
The compile command line is the following:
gcc test.c -O1 -fno-defer-pop -fno-delayed-branch -fno-guess-branch-probability
-fno-cprop-registers -fno-loop-optimize -fno-if-conversion2 -fno-tree-ccp
-fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-ter
-fno-tree-lrs -fno-tree-sra -fno-tree-copyrename -fno-tree-fre -fno-tree-ch
-fno-unit-at-a-time -fno-merge-constants -fno-omit-frame-pointer -o test
there are no compiler warnings, even with -Wall
I use gcc 4.3.4, configure options:
../gcc-4.3.4/configure --disable-shared --disable-nls --enable-languages=c++
--with-gnu-as --with-gnu-ld --enable-__cxa_atexit
--
Summary: Wrong optimization with if-conversion
Product: gcc
Version: 4.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: thomas at coware dot com
GCC build triplet: i686
GCC host triplet: i686
GCC target triplet: i686
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/40987] Wrong optimization with if-conversion
2009-08-06 14:06 [Bug c/40987] New: Wrong optimization with if-conversion thomas at coware dot com
@ 2009-08-07 12:10 ` rguenth at gcc dot gnu dot org
2009-09-19 16:57 ` mikpe at it dot uu dot se
` (2 subsequent siblings)
3 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-08-07 12:10 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from rguenth at gcc dot gnu dot org 2009-08-07 12:10 -------
Seems to be a HWI32 issue as I cannot reproduce the fail on x86_64 with -m32.
Which would indeed hint at a RTL if-conversion problem (I guess it uses
scc in a wrong way).
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
Component|c |rtl-optimization
Keywords| |wrong-code
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/40987] Wrong optimization with if-conversion
2009-08-06 14:06 [Bug c/40987] New: Wrong optimization with if-conversion thomas at coware dot com
2009-08-07 12:10 ` [Bug rtl-optimization/40987] " rguenth at gcc dot gnu dot org
@ 2009-09-19 16:57 ` mikpe at it dot uu dot se
2009-09-24 14:39 ` mikpe at it dot uu dot se
2009-09-26 10:18 ` steven at gcc dot gnu dot org
3 siblings, 0 replies; 8+ messages in thread
From: mikpe at it dot uu dot se @ 2009-09-19 16:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from mikpe at it dot uu dot se 2009-09-19 16:57 -------
Seems like an if-conversion bug, in particular noce_try_store_flag_constants()
appears to break on HWI32 platforms when long long literals are involved.
In this test case, noce_t_s_f_c() is invoked with an IF where a (the false
value) and b (the true value) are both DImode CONST_INTs. a is zero. b is
stored as 0x80000000, which is truncated but sign-extends to the correct value.
noce_t_s_f_c() then computes a subtraction and some log2() on these truncated
values, and selects the second code generation template "x = (test != 0) <<
3;".
The code becomes (from the ce1 dump file):
(insn 27 8 28 2 pr40987.c:4 (parallel [
(set (reg:DI 62)
(sign_extend:DI (reg/v:SI 60 [ arg ])))
(clobber (reg:CC 17 flags))
(clobber (scratch:SI))
]) 90 {*extendsidi2_1} (nil))
(insn 28 27 29 2 pr40987.c:4 (parallel [
(set (reg/v:DI 58 [ val ])
(lshiftrt:DI (reg:DI 62)
(const_int 63 [0x3f])))
(clobber (reg:CC 17 flags))
]) 394 {*lshrdi3_1} (nil))
# since this is a logical downshift, it produces 0 or 1 from the sign bit
(insn 29 28 17 2 pr40987.c:4 (parallel [
(set (reg/v:DI 58 [ val ])
(ashift:DI (reg/v:DI 58 [ val ])
(const_int 31 [0x1f])))
(clobber (reg:CC 17 flags))
]) 356 {*ashldi3_1} (nil))
# which is shifted up to produce 0 or 0x80000000, the high 32 bits are lost
All gcc-4.x releases have this bug. It does not trigger in gcc-3.4.6. There it
seems that the true/false values are swapped compared to 4.x, and a test near
the top of noce_t_s_f_c() causes it to bail out and not perform the conversion.
(The test looks the same in 4.x, but the IF-operands are swapped so it does not
bail.)
I don't know if this code can be fixed to handle longer-than-HWI literals. The
simplest solution might be to just detect the situation and bail out.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/40987] Wrong optimization with if-conversion
2009-08-06 14:06 [Bug c/40987] New: Wrong optimization with if-conversion thomas at coware dot com
2009-08-07 12:10 ` [Bug rtl-optimization/40987] " rguenth at gcc dot gnu dot org
2009-09-19 16:57 ` mikpe at it dot uu dot se
@ 2009-09-24 14:39 ` mikpe at it dot uu dot se
2009-09-26 10:18 ` steven at gcc dot gnu dot org
3 siblings, 0 replies; 8+ messages in thread
From: mikpe at it dot uu dot se @ 2009-09-24 14:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from mikpe at it dot uu dot se 2009-09-24 14:38 -------
Patch posted for review:
http://gcc.gnu.org/ml/gcc-patches/2009-09/msg01655.html
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/40987] Wrong optimization with if-conversion
2009-08-06 14:06 [Bug c/40987] New: Wrong optimization with if-conversion thomas at coware dot com
` (2 preceding siblings ...)
2009-09-24 14:39 ` mikpe at it dot uu dot se
@ 2009-09-26 10:18 ` steven at gcc dot gnu dot org
3 siblings, 0 replies; 8+ messages in thread
From: steven at gcc dot gnu dot org @ 2009-09-26 10:18 UTC (permalink / raw)
To: gcc-bugs
--
steven at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
URL| |http://gcc.gnu.org/ml/gcc-
| |patches/2009-
| |09/msg01655.html
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |patch
Last reconfirmed|0000-00-00 00:00:00 |2009-09-26 10:18:29
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40987
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2023-06-02 1:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <bug-40987-4@http.gcc.gnu.org/bugzilla/>
2012-01-21 21:33 ` [Bug rtl-optimization/40987] Wrong optimization with if-conversion pinskia at gcc dot gnu.org
2021-07-19 23:50 ` [Bug rtl-optimization/40987] ifcvt sometimes goes wrong for integer modes > 64bit pinskia at gcc dot gnu.org
2023-06-02 0:56 ` pinskia at gcc dot gnu.org
2023-06-02 1:02 ` pinskia at gcc dot gnu.org
2009-08-06 14:06 [Bug c/40987] New: Wrong optimization with if-conversion thomas at coware dot com
2009-08-07 12:10 ` [Bug rtl-optimization/40987] " rguenth at gcc dot gnu dot org
2009-09-19 16:57 ` mikpe at it dot uu dot se
2009-09-24 14:39 ` mikpe at it dot uu dot se
2009-09-26 10:18 ` steven at gcc dot gnu dot 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).