public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/41244]  New: "&data[i] - data" isn't converted to "i"
@ 2009-09-03 13:49 zsojka at seznam dot cz
  2009-09-03 13:51 ` [Bug tree-optimization/41244] " zsojka at seznam dot cz
  2009-09-03 14:12 ` rguenth at gcc dot gnu dot org
  0 siblings, 2 replies; 10+ messages in thread
From: zsojka at seznam dot cz @ 2009-09-03 13:49 UTC (permalink / raw)
  To: gcc-bugs

In attached code:
in find(), generated code computes offset using multiplication/division.
in set(), generated code computes &data[10] and compares &data[i] with that (to
verify find() fails to be optimised because of overflow rules)

tested gcc: 4.3.4, 4.4.1, 4.5.0-alpha20090827

command line:
gcc main.c -o main.o -c -O3
-f(no-)strict-overflow or -m32 doesn't have any effect on that behaviour

---------------------------------
static struct {
        int a, b, c;
        char pad[200]; /* padding so offset computation has to use expensive
div/mul */
} data[1000]; /* 1000 so loop isn't unrolled */

int find(int val)
{
        int i;
        for (i = 0; i < 1000; i++) {
                if (data[i].a == val) return &data[i] - data; /* does *212,
/212 */
        }
        return -1;
}

void set(int val)
{
        int i;
        for (i = 0; i < 1000; i++) {
                data[i].b = &data[i] - data < 10 || data[i].a == val; /*
compares with &data[10] */
        }
}
---------------------------------

Relevant generated ASM:
(eax is "i", sar+imul is converted division by 212)
---------------------------------
        cdqe
        imul    rax, rax, 212
        sar     rax, 2
        imul    eax, eax, -1944890851
        ret
---------------------------------


-- 
           Summary: "&data[i] - data" isn't converted to "i"
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: zsojka at seznam dot cz
  GCC host triplet: x86_64-pc-linux-gnu


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


^ permalink raw reply	[flat|nested] 10+ messages in thread
[parent not found: <bug-41244-4@http.gcc.gnu.org/bugzilla/>]

end of thread, other threads:[~2023-06-12  2:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-03 13:49 [Bug tree-optimization/41244] New: "&data[i] - data" isn't converted to "i" zsojka at seznam dot cz
2009-09-03 13:51 ` [Bug tree-optimization/41244] " zsojka at seznam dot cz
2009-09-03 14:12 ` rguenth at gcc dot gnu dot org
     [not found] <bug-41244-4@http.gcc.gnu.org/bugzilla/>
2021-09-14 22:03 ` pinskia at gcc dot gnu.org
2021-10-09 21:19 ` pinskia at gcc dot gnu.org
2023-06-11 19:44 ` pinskia at gcc dot gnu.org
2023-06-11 23:54 ` pinskia at gcc dot gnu.org
2023-06-12  0:30 ` pinskia at gcc dot gnu.org
2023-06-12  1:33 ` pinskia at gcc dot gnu.org
2023-06-12  2:12 ` 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).