public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments.
@ 2009-01-09 21:40 daney at gcc dot gnu dot org
2009-01-09 21:45 ` [Bug tree-optimization/38789] " pinskia at gcc dot gnu dot org
` (13 more replies)
0 siblings, 14 replies; 15+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-01-09 21:40 UTC (permalink / raw)
To: gcc-bugs
gcc (GCC) 4.4.0 20090109 (experimental) [trunk revision 143212]
On x86_64-unknown-linux-gnu (FC9)
Configured as: ../trunk/configure --prefix=/home/ddaney/gccsvn/native-install
--disable-multilib --enable-languages=c
Consider the following program:
---foo.c--------8<----------------
void bar(int v)
{
unsigned a;
a = (v == 1) ? 1 : 2;
if (__builtin_constant_p(a)) {
asm volatile ("you lose. %0" : : "ir" (a));
} else {
asm volatile ("you win. %0" : : "ir" (a));
}
}
--------------8<----------------
$ gcc -O2 -S foo.c
$ cat foo.s
.file "foo.c"
.text
.p2align 4,,15
.globl bar
.type bar, @function
bar:
.LFB0:
.cfi_startproc
xorl %eax, %eax
cmpl $1, %edi
setne %al
addl $1, %eax
#APP
# 9 "foo.c" 1
you lose. %eax
# 0 "" 2
#NO_APP
ret
.cfi_endproc
.LFE0:
.size bar, .-bar
.ident "GCC: (GNU) 4.4.0 20090109 (experimental) [trunk revision
143212]"
.section .note.GNU-stack,"",@progbits
It emits the asm from the __builtin_constant_p branch of the if statement.
Initial analysis points to VRP as being the problem.
For the system gcc (gcc (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)) it work
correctly.
--
Summary: __builtin_constant_p appears to eveluate to true for
non-constant arguments.
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: daney at gcc dot gnu dot org
GCC build triplet: x86_64-unknown-linux-gnu
GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
@ 2009-01-09 21:45 ` pinskia at gcc dot gnu dot org
2009-01-09 21:51 ` [Bug tree-optimization/38789] [4.4 Regression] " rguenth at gcc dot gnu dot org
` (12 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-09 21:45 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2009-01-09 21:45 -------
Jump threading in VPR is causing this and not really fully VPR.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |law at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
2009-01-09 21:45 ` [Bug tree-optimization/38789] " pinskia at gcc dot gnu dot org
@ 2009-01-09 21:51 ` rguenth at gcc dot gnu dot org
2009-01-09 21:55 ` daney at gcc dot gnu dot org
` (11 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-09 21:51 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from rguenth at gcc dot gnu dot org 2009-01-09 21:51 -------
I wouldn't consider this a bug. It's similar to
inline void foo(int i) { if (__builtin_constant_p (i)) you_loose(); }
void bar()
{
foo (1);
foo (2);
}
where the code is duplicated twice and both cases are constant.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
2009-01-09 21:45 ` [Bug tree-optimization/38789] " pinskia at gcc dot gnu dot org
2009-01-09 21:51 ` [Bug tree-optimization/38789] [4.4 Regression] " rguenth at gcc dot gnu dot org
@ 2009-01-09 21:55 ` daney at gcc dot gnu dot org
2009-01-09 21:57 ` pinskia at gcc dot gnu dot org
` (10 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-01-09 21:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from daney at gcc dot gnu dot org 2009-01-09 21:55 -------
Good, this code comes from the Linux kernel:
mm/backing-dev.c (set_bdi_congested())
Is the kernel at fault? If so I am sure Linus would like to hear about it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (2 preceding siblings ...)
2009-01-09 21:55 ` daney at gcc dot gnu dot org
@ 2009-01-09 21:57 ` pinskia at gcc dot gnu dot org
2009-01-09 22:00 ` daney at gcc dot gnu dot org
` (9 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-01-09 21:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from pinskia at gcc dot gnu dot org 2009-01-09 21:56 -------
(In reply to comment #2)
> where the code is duplicated twice and both cases are constant.
Except it is not duplicated in jump threading. It would have been ok if it did
but it does not ...
Jump threading proved probability of edge 4->5 too small (it is 1528, should be
10000).
Threaded jump 3 --> 4 to 4
Threaded jump 2 --> 4 to 4
Pass statistics:
----------------
Jumps threaded: 2
void bar(int v)
{
unsigned a;
a = 0;
if (v == 2)
a = 1;
if (__builtin_constant_p(a)) {
asm volatile ("you lose. %0" : : "ir" (a));
} else {
asm volatile ("you win. %0" : : "ir" (a));
}
}
is another example.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (3 preceding siblings ...)
2009-01-09 21:57 ` pinskia at gcc dot gnu dot org
@ 2009-01-09 22:00 ` daney at gcc dot gnu dot org
2009-01-09 22:57 ` rguenth at gcc dot gnu dot org
` (8 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: daney at gcc dot gnu dot org @ 2009-01-09 22:00 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 643 bytes --]
------- Comment #5 from daney at gcc dot gnu dot org 2009-01-09 22:00 -------
You have to be able to do one of the original test case or this:
$ cat foo1.c
void baz(int v)
{
unsigned a;
a = (v == 1) ? 1 : 2;
if (__builtin_constant_p(a)) {
asm volatile ("you lose. %0" : : "i" (a));
} else {
asm volatile ("you win. %0" : : "i" (a));
}
}
$ gcc -O2 -S foo1.c
foo1.c: In function baz:
foo1.c:9: warning: asm operand 0 probably doesnt match constraints
foo1.c:9: error: impossible constraint in asm
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (4 preceding siblings ...)
2009-01-09 22:00 ` daney at gcc dot gnu dot org
@ 2009-01-09 22:57 ` rguenth at gcc dot gnu dot org
2009-01-09 23:50 ` rguenth at gcc dot gnu dot org
` (7 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-09 22:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from rguenth at gcc dot gnu dot org 2009-01-09 22:57 -------
Ok, I'm convinced. That jump-threading is really weird. But only because
__builtin_constant_p isn't a regular function that is executed on a path
of the CFG, it really is supposed to be evaluating all paths through the CFG
going through it. Which of course conflicts with what jump threading does.
OTOH
void foo (bool b)
{
if (__builtin_constant_p (b))
boo ();
else
yeah ();
}
is then not equivalent to
void foo (bool b)
{
if (b == true)
{
if (__builtin_constant_p (b))
...
}
else if (b == false)
{
if (__builtin_constant_p (b))
....
}
}
That makes exact definition of the behavior of __builtin_constant_p not
easier. That is, the manual states
"You can use the built-in function @code{__builtin_constant_p} to
determine if a value is known to be constant at compile-time and hence
that GCC can perform constant-folding on expressions involving that
value."
which is true for the second variant but not for the first. Still if
__builtin_constant_p were a regular function both programs would be
equivalent.
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Last reconfirmed|0000-00-00 00:00:00 |2009-01-09 22:57:03
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to eveluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (5 preceding siblings ...)
2009-01-09 22:57 ` rguenth at gcc dot gnu dot org
@ 2009-01-09 23:50 ` rguenth at gcc dot gnu dot org
2009-01-15 15:56 ` [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate " rguenth at gcc dot gnu dot org
` (6 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-09 23:50 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Summary|[4.4 Regression] |[4.4 Regression]
|__builtin_constant_p appears|__builtin_constant_p appears
|to evaluate to true for non-|to eveluate to true for non-
|constant arguments. |constant arguments.
Target Milestone|--- |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (6 preceding siblings ...)
2009-01-09 23:50 ` rguenth at gcc dot gnu dot org
@ 2009-01-15 15:56 ` rguenth at gcc dot gnu dot org
2009-01-16 12:43 ` jakub at gcc dot gnu dot org
` (5 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-15 15:56 UTC (permalink / raw)
To: gcc-bugs
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Priority|P3 |P1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (7 preceding siblings ...)
2009-01-15 15:56 ` [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate " rguenth at gcc dot gnu dot org
@ 2009-01-16 12:43 ` jakub at gcc dot gnu dot org
2009-01-16 12:49 ` jakub at gcc dot gnu dot org
` (4 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-01-16 12:43 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from jakub at gcc dot gnu dot org 2009-01-16 12:42 -------
The correct testcase is IMHO:
void
baz (int v)
{
unsigned a = (v == 1) ? 1 : 2;
if (__builtin_constant_p (a))
asm volatile ("# constant %0" :: "i" (a));
else
asm volatile ("# register %0" :: "r" (a));
}
For non-constant a using "i" constraint is wrong. This fails since
http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=134833
I guess handling BUILT_IN_CONSTANT_P the same as BUILT_IN_OBJECT_SIZE in
record_temporary_equivalences_from_stmts_at_dest
could do the trick.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (8 preceding siblings ...)
2009-01-16 12:43 ` jakub at gcc dot gnu dot org
@ 2009-01-16 12:49 ` jakub at gcc dot gnu dot org
2009-01-16 15:01 ` jakub at gcc dot gnu dot org
` (3 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-01-16 12:49 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from jakub at gcc dot gnu dot org 2009-01-16 12:49 -------
Yes, it does. Going to bootstrap/regtest it now.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|unassigned at gcc dot gnu |jakub at gcc dot gnu dot org
|dot org |
Status|NEW |ASSIGNED
Last reconfirmed|2009-01-09 22:57:03 |2009-01-16 12:49:03
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (9 preceding siblings ...)
2009-01-16 12:49 ` jakub at gcc dot gnu dot org
@ 2009-01-16 15:01 ` jakub at gcc dot gnu dot org
2009-01-16 15:03 ` jakub at gcc dot gnu dot org
` (2 subsequent siblings)
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-01-16 15:01 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from jakub at gcc dot gnu dot org 2009-01-16 15:01 -------
Subject: Bug 38789
Author: jakub
Date: Fri Jan 16 15:01:24 2009
New Revision: 143435
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143435
Log:
PR tree-optimization/38789
* tree-ssa-threadedge.c
(record_temporary_equivalences_from_stmts_at_dest): Ignore calls to
__builtin_constant_p.
* gcc.c-torture/compile/pr38789.c: New test.
Added:
trunk/gcc/testsuite/gcc.c-torture/compile/pr38789.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-threadedge.c
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (10 preceding siblings ...)
2009-01-16 15:01 ` jakub at gcc dot gnu dot org
@ 2009-01-16 15:03 ` jakub at gcc dot gnu dot org
2009-01-26 10:22 ` rguenth at gcc dot gnu dot org
2009-01-30 17:47 ` hjl at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-01-16 15:03 UTC (permalink / raw)
To: gcc-bugs
------- Comment #10 from jakub at gcc dot gnu dot org 2009-01-16 15:02 -------
Fixed.
--
jakub at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Resolution| |FIXED
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (11 preceding siblings ...)
2009-01-16 15:03 ` jakub at gcc dot gnu dot org
@ 2009-01-26 10:22 ` rguenth at gcc dot gnu dot org
2009-01-30 17:47 ` hjl at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-01-26 10:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #11 from rguenth at gcc dot gnu dot org 2009-01-26 10:22 -------
*** Bug 36359 has been marked as a duplicate of this bug. ***
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |mt-ml at gmx dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
* [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate to true for non-constant arguments.
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
` (12 preceding siblings ...)
2009-01-26 10:22 ` rguenth at gcc dot gnu dot org
@ 2009-01-30 17:47 ` hjl at gcc dot gnu dot org
13 siblings, 0 replies; 15+ messages in thread
From: hjl at gcc dot gnu dot org @ 2009-01-30 17:47 UTC (permalink / raw)
To: gcc-bugs
------- Comment #12 from hjl at gcc dot gnu dot org 2009-01-30 17:47 -------
Subject: Bug 38789
Author: hjl
Date: Fri Jan 30 17:46:24 2009
New Revision: 143799
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=143799
Log:
2009-01-30 H.J. Lu <hongjiu.lu@intel.com>
Backport from mainline:
2009-01-16 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/38789
* gcc.c-torture/compile/pr38789.c: New test.
Added:
branches/gcc-4_3-branch/gcc/testsuite/gcc.c-torture/compile/pr38789.c
- copied unchanged from r143798,
trunk/gcc/testsuite/gcc.c-torture/compile/pr38789.c
Modified:
branches/gcc-4_3-branch/gcc/testsuite/ChangeLog
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38789
^ permalink raw reply [flat|nested] 15+ messages in thread
end of thread, other threads:[~2009-01-30 17:47 UTC | newest]
Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-09 21:40 [Bug tree-optimization/38789] New: __builtin_constant_p appears to eveluate to true for non-constant arguments daney at gcc dot gnu dot org
2009-01-09 21:45 ` [Bug tree-optimization/38789] " pinskia at gcc dot gnu dot org
2009-01-09 21:51 ` [Bug tree-optimization/38789] [4.4 Regression] " rguenth at gcc dot gnu dot org
2009-01-09 21:55 ` daney at gcc dot gnu dot org
2009-01-09 21:57 ` pinskia at gcc dot gnu dot org
2009-01-09 22:00 ` daney at gcc dot gnu dot org
2009-01-09 22:57 ` rguenth at gcc dot gnu dot org
2009-01-09 23:50 ` rguenth at gcc dot gnu dot org
2009-01-15 15:56 ` [Bug tree-optimization/38789] [4.4 Regression] __builtin_constant_p appears to evaluate " rguenth at gcc dot gnu dot org
2009-01-16 12:43 ` jakub at gcc dot gnu dot org
2009-01-16 12:49 ` jakub at gcc dot gnu dot org
2009-01-16 15:01 ` jakub at gcc dot gnu dot org
2009-01-16 15:03 ` jakub at gcc dot gnu dot org
2009-01-26 10:22 ` rguenth at gcc dot gnu dot org
2009-01-30 17:47 ` hjl 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).