This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/77820] New: A jump threading opportunity with conditionals


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77820

            Bug ID: 77820
           Summary: A jump threading opportunity with conditionals
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: segher at gcc dot gnu.org
  Target Milestone: ---

Consider the following code:

===
void g(void);

void f(long a, long b, long c, long d, int x)
{
        int t;
        if (x)
                t = a < b;
        else
                t = c < d;
        if (t)
                g();
}
===

On aarch64 we generate: (it is worse on PowerPC, but this is shorter code)

===
f:
        cbz     w4, .L2
        cmp     x0, x1
        cset    w0, lt
        cbnz    w0, .L6
.L1:
        ret
        .p2align 3
.L2:
        cmp     x2, x3
        cset    w0, lt
        cbz     w0, .L1
.L6:
        b       g
===

while if jump threading was a bit smarter we could generate:

===
f:
        cbz     w4, .L2
        cmp     x0, x1
        blt     .L3
.L1:
        ret
        .p2align 3
.L2:
        cmp     x2, x3
        bge     .L1
.L3:
        b       g
===

(i.e., do the "if (t)" in both branches of the first "if").

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]