public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26369]  New: value expectation attribute
@ 2006-02-19 20:49 acahalan at gmail dot com
  2006-02-19 23:08 ` [Bug c/26369] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: acahalan at gmail dot com @ 2006-02-19 20:49 UTC (permalink / raw)
  To: gcc-bugs

Something used roughly like this:

unsigned foo __attribute__((
  min(5),  // value will never be below this
  max(0x007fff04),  // value will never be above this
  set(0x00000004),  // these bits will always be set
  clear(0xff800002),  // these bits will never be set
  likely_min(100),  // the value is rarely below this
  likely_max(12345),  // the value is rarely above this
  likely_set(0x00000604),  // these bits are usually set
  likely_clear(0xfffff032)  // these bits are usually clear
)) = 100;

The idea is that I tell gcc that my variable (or type) is certain or likely to
have various values. This lets me avoid marking up lots and lots of code with
__builtin_expect. I can just mark the variable or type.

A bit of error checking can be done too. It would be invalid to pass a value
that never exceeds 1 to a function whose argument is marked as always having
bit 4 set. The compiler could catch this and halt with an error.


-- 
           Summary: value expectation attribute
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: acahalan at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26369] value expectation attribute
  2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
@ 2006-02-19 23:08 ` pinskia at gcc dot gnu dot org
  2006-02-20  2:09 ` pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-19 23:08 UTC (permalink / raw)
  To: gcc-bugs



-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26369] value expectation attribute
  2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
  2006-02-19 23:08 ` [Bug c/26369] " pinskia at gcc dot gnu dot org
@ 2006-02-20  2:09 ` pinskia at gcc dot gnu dot org
  2006-02-20  4:00 ` acahalan at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-02-20  2:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2006-02-20 02:09 -------
I don't understand why this is useful really as GCC now has VRP which will find
most of this information and remove code which is useless.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26369] value expectation attribute
  2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
  2006-02-19 23:08 ` [Bug c/26369] " pinskia at gcc dot gnu dot org
  2006-02-20  2:09 ` pinskia at gcc dot gnu dot org
@ 2006-02-20  4:00 ` acahalan at gmail dot com
  2006-02-21 10:06 ` rguenth at gcc dot gnu dot org
  2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: acahalan at gmail dot com @ 2006-02-20  4:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from acahalan at gmail dot com  2006-02-20 04:00 -------
VRP (value range propagation, if I guess right) doesn't always have the data it
needs. Commonly, people split projects into multiple files and do not use
-fwhole-program to compile the project. This seems to be the norm actually.

(Heck, are there _any_ projects using -fwhole-program? Perhaps gcc itself?)

VRP won't do very much to catch errors in the code. I'd like gcc to actually
block assignment of illegal values when it can determine that the problem
exists.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26369] value expectation attribute
  2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
                   ` (2 preceding siblings ...)
  2006-02-20  4:00 ` acahalan at gmail dot com
@ 2006-02-21 10:06 ` rguenth at gcc dot gnu dot org
  2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2006-02-21 10:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2006-02-21 10:06 -------
This doesn't really make any sense.  Trying to over-educate a compiler usually
leads to worse code.  Please rather try to isolate testcases where gcc does not
extract value range information it could extract.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug c/26369] value expectation attribute
  2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
                   ` (3 preceding siblings ...)
  2006-02-21 10:06 ` rguenth at gcc dot gnu dot org
@ 2006-04-22 20:52 ` pinskia at gcc dot gnu dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2006-04-22 20:52 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2006-04-22 20:52 -------
This is not really that useful, the problem comes down to if the user messes up
(which is 90% of the time anyways), they get a crash in their program and blame
GCC.  So exosing stuff like this is crazy to do really.

And getting a person to annotate their code with these attributes just get more
and crazy.  Instead it is just better to improve the optimizers instead of
adding attributes to work around the optimizers not working for your case.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WONTFIX


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26369


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-04-22 20:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-19 20:49 [Bug c/26369] New: value expectation attribute acahalan at gmail dot com
2006-02-19 23:08 ` [Bug c/26369] " pinskia at gcc dot gnu dot org
2006-02-20  2:09 ` pinskia at gcc dot gnu dot org
2006-02-20  4:00 ` acahalan at gmail dot com
2006-02-21 10:06 ` rguenth at gcc dot gnu dot org
2006-04-22 20:52 ` pinskia 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).