https://bugs.llvm.org/show_bug.cgi?id=44703

            Bug ID: 44703
           Summary: Some remainder checks on loop IV can be simplified by
                    having another IV
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]

void reinit();
void work(int p);
void entry(int width) {
    for (int p = 0; p < 8; ++p) {
        if (p % 3 == 2)
            reinit();   
        work(p); 
    }
}

Depending on the loop (what is `work()`, is loop unrolled, etc),
this 'rem' operation can end up being measurably costly.
But this can be instead rewritten as

void reinit();
void work(int p);
void entry(int width) {
    int u = 0;
    for (int p = 0; p < 8; ++p, ++u) {
        if (u == 2) {
            reinit();
            u = -1;
        }
        work(p);
    }
}

.. at the cost of extra induction variable.

https://godbolt.org/z/EdiSHi

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to