public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine
@ 2013-04-30 23:43 wmi at google dot com
2013-05-01 6:42 ` [Bug rtl-optimization/57130] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
` (6 more replies)
0 siblings, 7 replies; 8+ messages in thread
From: wmi at google dot com @ 2013-04-30 23:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
Bug #: 57130
Summary: Incorrect "and --> extract" conversion in combine
Classification: Unclassified
Product: gcc
Version: 4.9.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: wmi@google.com
Created attachment 29986
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29986
Testcase
For the smallcase 1.ii attached.
~/workarea/gcc-r198433/build/install/bin/g++ 1.ii -o a1.out
./a1.out --> correct output:
1
3
~/workarea/gcc-r198433/build/install/bin/g++ -fno-inline
-fno-omit-frame-pointer -O2 1.ii -o a2.out
./a2.out --> incorrect output:
1
-1
In 1.ii.196r.ud_dce:
(insn 7 2 84 2 (set (reg:DI 64)
(const_int -4294967296 [0xffffffff00000000])) 1.ii:26 84
{*movdi_internal}
(nil))
...
(insn 40 36 44 2 (parallel [
(set (reg:DI 88)
(and:DI (reg:DI 80)
(reg:DI 64)))
(clobber (reg:CC 17 flags))
]) 1.ii:32 386 {*anddi_1}
(expr_list:REG_DEAD (reg:DI 80)
(expr_list:REG_DEAD (reg:DI 64)
(expr_list:REG_UNUSED (reg:CC 17 flags)
(expr_list:REG_EQUAL (and:DI (reg:DI 80)
(const_int -4294967296 [0xffffffff00000000]))
(nil))))))
(insn 44 40 45 2 (set (reg:DI 92 [ mini_rect ])
(zero_extend:DI (subreg:SI (reg:DI 88) 0))) 1.ii:33 127
{*zero_extendsidi2}
(expr_list:REG_DEAD (reg:DI 88)
(nil)))
The value of r92 here should always be 0.
After try_combine with params (i3==insn44, i2==insn40, i1==insn7), insn44 is
transformed to:
(insn 44 40 45 2 (parallel [
(set (reg:DI 92 [ mini_rect ])
(ashiftrt:DI (reg:DI 88)
(const_int 63 [0x3f])))
(clobber (reg:CC 17 flags))
]) 1.ii:33 528 {ashrdi3_cvt}
(expr_list:REG_UNUSED (reg:CC 17 flags)
(expr_list:REG_DEAD (reg:DI 88)
(nil))))
The value of r92 now equals either 0 or -1 which depends on the highest bit of
r88.
Try to understand what happen in try_combine:
In try_combine, after subst(PATTERN (i3), i2dest, i2src, ...), insn 44 is
transformed to the following form. This step is correct.
(insn 44 40 45 2 (set (reg:DI 92 [ mini_rect ])
(neg:DI (ne:DI (subreg:SI (and:DI (reg:DI 80)
(reg:DI 64)) 0)
(const_int 0 [0])))) 1.ii:33 127 {*zero_extendsidi2}
(expr_list:REG_DEAD (reg:DI 88)
(nil)))
In subst(PATTERN (i3), i1dest, i1src, ...), insn 44 is firstly transformed to
the following in simplify_logical, which is correct:
(insn 44 40 45 2 (set (reg:DI 92 [ mini_rect ])
(neg:DI (ne:DI (subreg:SI ((and:DI (reg:DI 80)
(const_int 34359738368 [0x800000000]))) 0)
(const_int 0 [0])))) 1.ii:33 127 {*zero_extendsidi2}
(expr_list:REG_DEAD (reg:DI 88)
(nil)))
then it is transformed to the following in make_compound_operation, which is
incorrect:
(insn 44 40 45 2 (set (reg:DI 92 [ mini_rect ])
(sign_extract:DI (reg:DI 80)
(const_int 1 [0x1])
(const_int 35 [0x23]))) 1.ii:33 127 {*zero_extendsidi2}
(expr_list:REG_DEAD (reg:DI 88)
(nil)))
make_compound_operation transforms
(and:DI (reg:DI 80)
(const_int 34359738368 [0x800000000]))
to
(zero_extract:DI (reg:DI 80)
(const_int 1 [0x1])
(const_int 35 [0x23]))
because it thinks the "and expr" here is in a compare. But actually the "and
expr" is firstly the kid in a subreg:
subreg:SI ((and:DI (reg:DI 80)
(const_int 34359738368 [0x800000000])) ==> always 0
is not identical with
subreg:SI ((zero_extract:DI (reg:DI 80)
(const_int 1 [0x1])
(const_int 35 [0x23])) ==> 0 or 1
So it is the cause of the problem. The second actual of make_compound_operation
(combine.c:7701, r198433) should not be in_code.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
@ 2013-05-01 6:42 ` jakub at gcc dot gnu.org
2013-05-02 6:58 ` jakub at gcc dot gnu.org
` (5 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-01 6:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2013-05-01
CC| |jakub at gcc dot gnu.org
Target Milestone|--- |4.8.1
Summary|Incorrect "and --> extract" |[4.8/4.9 Regression]
|conversion in combine |Incorrect "and --> extract"
| |conversion in combine
Ever Confirmed|0 |1
--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-01 06:41:55 UTC ---
Started with http://gcc.gnu.org/r190492
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
2013-05-01 6:42 ` [Bug rtl-optimization/57130] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
@ 2013-05-02 6:58 ` jakub at gcc dot gnu.org
2013-05-02 9:07 ` jakub at gcc dot gnu.org
` (4 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-02 6:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-02 06:58:38 UTC ---
Slightly more reduced testcase:
struct S { int a, b, c, d; } s[2] = { { 6, 8, -8, -5 }, { 0, 2, -1, 2 } };
__attribute__((noinline, noclone)) void
foo (struct S r)
{
static int cnt;
if (__builtin_memcmp (&r, &s[cnt++], sizeof r) != 0)
__builtin_abort ();
}
int
main ()
{
struct S r = { 6, 8, -8, -5 };
foo (r);
r = (struct S) { 0, 2, -1, 2 };
foo (r);
return 0;
}
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
2013-05-01 6:42 ` [Bug rtl-optimization/57130] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
2013-05-02 6:58 ` jakub at gcc dot gnu.org
@ 2013-05-02 9:07 ` jakub at gcc dot gnu.org
2013-05-02 9:23 ` jakub at gcc dot gnu.org
` (3 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-02 9:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |ASSIGNED
AssignedTo|unassigned at gcc dot |jakub at gcc dot gnu.org
|gnu.org |
--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-02 09:07:31 UTC ---
Created attachment 29994
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29994
gcc49-pr57130.patch
Untested fix, though not sure if it won't pessimize too much. The in_code ==
COMPARE handling simply look safe to me when recursing into a SUBREG.
Sometimes it could, e.g. for (subreg:SI (and:DI (reg:DI) (const_int
0x08000000))) with in_code == COMPARE, but we'd probably have to pass the
SUBREG mode around and special case it everywhere.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
` (2 preceding siblings ...)
2013-05-02 9:07 ` jakub at gcc dot gnu.org
@ 2013-05-02 9:23 ` jakub at gcc dot gnu.org
2013-05-02 10:49 ` jakub at gcc dot gnu.org
` (2 subsequent siblings)
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-02 9:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-02 09:23:22 UTC ---
Created attachment 29995
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29995
simplify-truncate.patch
Another thing, it is weird we don't simplify that subreg much earlier, we know
that nonzero_bits on the inner operand has all zeros in the mode that it is
truncated to, therefore it must be zero.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
` (3 preceding siblings ...)
2013-05-02 9:23 ` jakub at gcc dot gnu.org
@ 2013-05-02 10:49 ` jakub at gcc dot gnu.org
2013-05-03 13:57 ` jakub at gcc dot gnu.org
2021-07-24 22:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-02 10:49 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-02 10:49:08 UTC ---
Created attachment 29996
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29996
gcc49-pr57130.patch
Alternative to the #c3 patch, using SET instead of COMPARE only when needed for
the recursive call for SUBREG.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
` (4 preceding siblings ...)
2013-05-02 10:49 ` jakub at gcc dot gnu.org
@ 2013-05-03 13:57 ` jakub at gcc dot gnu.org
2021-07-24 22:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-03 13:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
Jakub Jelinek <jakub at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-05-03 13:56:59 UTC ---
Author: jakub
Date: Fri May 3 12:56:12 2013
New Revision: 198579
URL: http://gcc.gnu.org/viewcvs?rev=198579&root=gcc&view=rev
Log:
PR rtl-optimization/57130
* combine.c (make_compound_operation) <case SUBREG>: Pass
SET instead of COMPARE as in_code to the recursive call
if needed.
* gcc.c-torture/execute/pr57130.c: New test.
Added:
trunk/gcc/testsuite/gcc.c-torture/execute/pr57130.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/combine.c
trunk/gcc/testsuite/ChangeLog
Author: jakub
Date: Fri May 3 13:19:51 2013
New Revision: 198581
URL: http://gcc.gnu.org/viewcvs?rev=198581&root=gcc&view=rev
Log:
PR rtl-optimization/57130
* combine.c (make_compound_operation) <case SUBREG>: Pass
SET instead of COMPARE as in_code to the recursive call
if needed.
* gcc.c-torture/execute/pr57130.c: New test.
Added:
branches/gcc-4_8-branch/gcc/testsuite/gcc.c-torture/execute/pr57130.c
Modified:
branches/gcc-4_8-branch/gcc/ChangeLog
branches/gcc-4_8-branch/gcc/combine.c
branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug rtl-optimization/57130] [4.8/4.9 Regression] Incorrect "and --> extract" conversion in combine
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
` (5 preceding siblings ...)
2013-05-03 13:57 ` jakub at gcc dot gnu.org
@ 2021-07-24 22:03 ` pinskia at gcc dot gnu.org
6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-24 22:03 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57130
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |yahemore at gmail dot com
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 50291 has been marked as a duplicate of this bug. ***
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-07-24 22:03 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-30 23:43 [Bug rtl-optimization/57130] New: Incorrect "and --> extract" conversion in combine wmi at google dot com
2013-05-01 6:42 ` [Bug rtl-optimization/57130] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
2013-05-02 6:58 ` jakub at gcc dot gnu.org
2013-05-02 9:07 ` jakub at gcc dot gnu.org
2013-05-02 9:23 ` jakub at gcc dot gnu.org
2013-05-02 10:49 ` jakub at gcc dot gnu.org
2013-05-03 13:57 ` jakub at gcc dot gnu.org
2021-07-24 22:03 ` 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).